From b0af6ba42b6ce494748f18ecf3e054a400b8f45b Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Tue, 4 Jan 2022 02:17:19 +0100 Subject: [PATCH] Add delegate API methods to media clusters (#13259) * Update app/clusters with delegate methods * Update test and Content App * Update Linux TV app * Update android TV app * Run zap regen tool & update random other folders and references * Restyle fix * Fix TV app Linux build --- .../esp32/main/CMakeLists.txt | 1 + examples/all-clusters-app/linux/BUILD.gn | 1 + .../linux/include/tv-callbacks.cpp | 5 +- .../linux/include/tv-callbacks.h | 31 ++ examples/all-clusters-app/linux/main.cpp | 11 + examples/all-clusters-app/mbed/CMakeLists.txt | 1 + .../mbed/main/LowPowerManager.cpp | 5 +- .../mbed/main/include/LowPowerManager.h | 27 ++ .../include/low-power/LowPowerManager.cpp | 2 +- .../linux/include/low-power/LowPowerManager.h | 5 +- .../account-login/AccountLoginManager.cpp | 72 +-- .../account-login/AccountLoginManager.h | 24 +- .../ApplicationBasicManager.cpp | 148 ++---- .../ApplicationBasicManager.h | 29 +- .../ApplicationLauncherManager.cpp | 70 ++- .../ApplicationLauncherManager.h | 21 +- .../audio-output/AudioOutputManager.cpp | 55 +-- .../include/audio-output/AudioOutputManager.h | 12 +- .../tv-app/android/include/cluster-init.cpp | 85 +--- .../TargetNavigatorManager.cpp | 56 +-- .../target-navigator/TargetNavigatorManager.h | 14 +- .../tv-app/android/java/ChannelManager.cpp | 296 +++++------- examples/tv-app/android/java/ChannelManager.h | 26 +- .../android/java/ContentLauncherManager.cpp | 49 +- .../android/java/ContentLauncherManager.h | 12 +- .../android/java/KeypadInputManager.cpp | 32 +- .../tv-app/android/java/KeypadInputManager.h | 9 +- .../tv-app/android/java/LowPowerManager.cpp | 16 +- .../tv-app/android/java/LowPowerManager.h | 6 +- .../tv-app/android/java/MediaInputManager.cpp | 138 ++---- .../tv-app/android/java/MediaInputManager.h | 17 +- .../android/java/MediaPlaybackManager.cpp | 251 +++++------ .../android/java/MediaPlaybackManager.h | 48 +- .../tv-app/android/java/WakeOnLanManager.cpp | 65 ++- .../tv-app/android/java/WakeOnLanManager.h | 7 +- examples/tv-app/linux/AppImpl.cpp | 18 +- examples/tv-app/linux/AppImpl.h | 6 +- .../account-login/AccountLoginManager.cpp | 72 +-- .../account-login/AccountLoginManager.h | 24 +- .../ApplicationBasicManager.cpp | 152 ++----- .../ApplicationBasicManager.h | 29 +- .../ApplicationLauncherManager.cpp | 93 ++-- .../ApplicationLauncherManager.h | 21 +- .../audio-output/AudioOutputManager.cpp | 56 +-- .../include/audio-output/AudioOutputManager.h | 12 +- .../linux/include/channel/ChannelManager.cpp | 90 ++-- .../linux/include/channel/ChannelManager.h | 17 +- .../tv-app/linux/include/cluster-init.cpp | 185 -------- .../ContentLauncherManager.cpp | 35 +- .../content-launcher/ContentLauncherManager.h | 19 +- .../keypad-input/KeypadInputManager.cpp | 31 +- .../include/keypad-input/KeypadInputManager.h | 10 +- .../include/low-power/LowPowerManager.cpp | 2 +- .../linux/include/low-power/LowPowerManager.h | 5 +- .../include/media-input/MediaInputManager.cpp | 62 ++- .../include/media-input/MediaInputManager.h | 16 +- .../media-playback/MediaPlaybackManager.cpp | 143 ++++-- .../media-playback/MediaPlaybackManager.h | 34 +- .../TargetNavigatorManager.cpp | 87 +--- .../target-navigator/TargetNavigatorManager.h | 17 +- .../include/wake-on-lan/WakeOnLanManager.cpp | 52 +-- .../include/wake-on-lan/WakeOnLanManager.h | 20 +- examples/tv-app/linux/main.cpp | 123 +++-- .../account-login-delegate.h | 46 ++ .../account-login-server.cpp | 123 +++-- .../account-login-server.h | 32 ++ .../application-basic-delegate.h | 52 +++ .../application-basic-server.cpp | 201 ++++++++- .../application-basic-server.h | 20 +- .../application-launcher-delegate.h | 54 +++ .../application-launcher-server.cpp | 225 +++++++--- .../application-launcher-server.h | 19 +- .../audio-output-delegate.h | 49 ++ .../audio-output-server.cpp | 165 ++++++- .../audio-output-server/audio-output-server.h | 39 ++ .../channel-server/channel-delegate.h | 51 +++ .../channel-server/channel-server.cpp | 202 ++++++++- .../clusters/channel-server/channel-server.h | 39 ++ .../content-launch-delegate.h | 18 +- .../content-launch-server.cpp | 42 +- .../content-launch-server.h | 1 - .../keypad-input-delegate.h | 27 +- .../keypad-input-server.cpp | 86 +++- .../keypad-input-server/keypad-input-server.h | 39 ++ .../low-power-server/low-power-delegate.h | 42 ++ .../low-power-server/low-power-server.cpp | 69 ++- .../low-power-server/low-power-server.h | 38 ++ .../media-input-server/media-input-delegate.h | 50 +++ .../media-input-server/media-input-server.cpp | 200 ++++++++- .../media-input-server/media-input-server.h | 39 ++ .../media-playback-delegate.h | 63 +++ .../media-playback-server.cpp | 422 +++++++++++++++--- .../media-playback-server.h | 29 +- .../target-navigator-delegate.h | 47 ++ .../target-navigator-server.cpp | 166 ++++++- .../target-navigator-server.h | 19 +- .../wake-on-lan-server/wake-on-lan-delegate.h | 42 ++ .../wake-on-lan-server/wake-on-lan-server.cpp | 138 ++++++ .../wake-on-lan-server/wake-on-lan-server.h | 38 ++ .../tests/suites/TV_AccountLoginCluster.yaml | 10 +- .../tests/suites/TV_MediaPlaybackCluster.yaml | 2 +- src/app/util/ContentApp.cpp | 13 +- src/app/util/ContentApp.h | 8 +- src/app/util/util.cpp | 1 - .../chip/application-launcher-cluster.xml | 5 + .../data-model/chip/audio-output-cluster.xml | 5 + .../zcl/data-model/chip/channel-cluster.xml | 6 + .../chip/content-launch-cluster.xml | 6 + .../data-model/chip/keypad-input-cluster.xml | 7 +- .../data-model/chip/media-input-cluster.xml | 5 + .../chip/media-playback-cluster.xml | 2 +- src/app/zap_cluster_list.py | 2 +- .../zap-generated/endpoint_config.h | 14 +- .../zap-generated/attributes/Accessors.cpp | 2 +- .../zap-generated/attributes/Accessors.h | 2 +- .../zap-generated/cluster-objects.h | 40 ++ .../app-common/zap-generated/enums.h | 20 + .../chip-tool/zap-generated/test/Commands.h | 9 +- .../tv-app/zap-generated/endpoint_config.h | 6 +- 119 files changed, 3903 insertions(+), 2272 deletions(-) create mode 100644 examples/all-clusters-app/linux/include/tv-callbacks.h create mode 100644 examples/all-clusters-app/mbed/main/include/LowPowerManager.h create mode 100644 src/app/clusters/account-login-server/account-login-delegate.h create mode 100644 src/app/clusters/account-login-server/account-login-server.h create mode 100644 src/app/clusters/application-basic-server/application-basic-delegate.h rename examples/tv-app/android/include/application-basic/Application.h => src/app/clusters/application-basic-server/application-basic-server.h (61%) create mode 100644 src/app/clusters/application-launcher-server/application-launcher-delegate.h create mode 100644 src/app/clusters/audio-output-server/audio-output-delegate.h create mode 100644 src/app/clusters/audio-output-server/audio-output-server.h create mode 100644 src/app/clusters/channel-server/channel-delegate.h create mode 100644 src/app/clusters/channel-server/channel-server.h rename examples/tv-app/linux/include/application-basic/Application.h => src/app/clusters/keypad-input-server/keypad-input-delegate.h (59%) create mode 100644 src/app/clusters/keypad-input-server/keypad-input-server.h create mode 100644 src/app/clusters/low-power-server/low-power-delegate.h create mode 100644 src/app/clusters/low-power-server/low-power-server.h create mode 100644 src/app/clusters/media-input-server/media-input-delegate.h create mode 100644 src/app/clusters/media-input-server/media-input-server.h create mode 100644 src/app/clusters/media-playback-server/media-playback-delegate.h create mode 100644 src/app/clusters/target-navigator-server/target-navigator-delegate.h create mode 100644 src/app/clusters/wake-on-lan-server/wake-on-lan-delegate.h create mode 100644 src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp create mode 100644 src/app/clusters/wake-on-lan-server/wake-on-lan-server.h diff --git a/examples/all-clusters-app/esp32/main/CMakeLists.txt b/examples/all-clusters-app/esp32/main/CMakeLists.txt index 78a223a25b1090..f35386484bc48d 100644 --- a/examples/all-clusters-app/esp32/main/CMakeLists.txt +++ b/examples/all-clusters-app/esp32/main/CMakeLists.txt @@ -77,6 +77,7 @@ set(SRC_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ias-zone-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ethernet-network-diagnostics-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wifi-network-diagnostics-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wake-on-lan-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/pump-configuration-and-control-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-configuration-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/src" diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index f0558592bbde7d..9f2870d976d65b 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -21,6 +21,7 @@ executable("chip-all-clusters-app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/ota-requestor-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "include/tv-callbacks.cpp", + "include/tv-callbacks.h", "main.cpp", ] diff --git a/examples/all-clusters-app/linux/include/tv-callbacks.cpp b/examples/all-clusters-app/linux/include/tv-callbacks.cpp index 917c3f0548cf1a..33a8154e9be6d7 100644 --- a/examples/all-clusters-app/linux/include/tv-callbacks.cpp +++ b/examples/all-clusters-app/linux/include/tv-callbacks.cpp @@ -22,10 +22,9 @@ ******************************************************************************* ******************************************************************************/ -#include -#include +#include "tv-callbacks.h" -bool lowPowerClusterSleep() +bool LowPowerManager::HandleSleep() { return true; } diff --git a/examples/all-clusters-app/linux/include/tv-callbacks.h b/examples/all-clusters-app/linux/include/tv-callbacks.h new file mode 100644 index 00000000000000..1ee3f4264370af --- /dev/null +++ b/examples/all-clusters-app/linux/include/tv-callbacks.h @@ -0,0 +1,31 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** + * @file + * @brief Routines for TV stubs + *server stub implementation of TV cluster code. + ******************************************************************************* + ******************************************************************************/ + +#include + +class LowPowerManager : public chip::app::Clusters::LowPower::Delegate +{ +public: + bool HandleSleep() override; +}; diff --git a/examples/all-clusters-app/linux/main.cpp b/examples/all-clusters-app/linux/main.cpp index bfb174c2a811c2..f7a58ab4e5dcfc 100644 --- a/examples/all-clusters-app/linux/main.cpp +++ b/examples/all-clusters-app/linux/main.cpp @@ -16,6 +16,7 @@ * limitations under the License. */ +#include "include/tv-callbacks.h" #include #include #include @@ -28,6 +29,10 @@ using namespace chip; using namespace chip::app; using namespace chip::DeviceLayer; +namespace { +static LowPowerManager lowPowerManager; +} // namespace + bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::CommandHandler * commandObj) { emberAfSendDefaultResponse(emberAfCurrentCommand(), EMBER_ZCL_STATUS_SUCCESS); @@ -108,3 +113,9 @@ int main(int argc, char * argv[]) ChipLinuxAppMainLoop(); return 0; } + +void emberAfLowPowerClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: LowPower::SetDefaultDelegate"); + chip::app::Clusters::LowPower::SetDefaultDelegate(endpoint, &lowPowerManager); +} diff --git a/examples/all-clusters-app/mbed/CMakeLists.txt b/examples/all-clusters-app/mbed/CMakeLists.txt index fe62bb9e9a441c..03798b5d4d2258 100644 --- a/examples/all-clusters-app/mbed/CMakeLists.txt +++ b/examples/all-clusters-app/mbed/CMakeLists.txt @@ -131,6 +131,7 @@ target_sources(${APP_TARGET} PRIVATE ${APP_CLUSTERS}/ethernet-network-diagnostics-server/ethernet-network-diagnostics-server.cpp ${APP_CLUSTERS}/software-diagnostics-server/software-diagnostics-server.cpp ${APP_CLUSTERS}/thread-network-diagnostics-server/thread-network-diagnostics-server.cpp + ${APP_CLUSTERS}/wake-on-lan-server/wake-on-lan-server.cpp ${APP_CLUSTERS}/wifi-network-diagnostics-server/wifi-network-diagnostics-server.cpp ${APP_CLUSTERS}/pump-configuration-and-control-server/pump-configuration-and-control-server.cpp ${APP_CLUSTERS}/administrator-commissioning-server/administrator-commissioning-server.cpp diff --git a/examples/all-clusters-app/mbed/main/LowPowerManager.cpp b/examples/all-clusters-app/mbed/main/LowPowerManager.cpp index fc1a1f2b4dc950..57399c0ba1de5c 100644 --- a/examples/all-clusters-app/mbed/main/LowPowerManager.cpp +++ b/examples/all-clusters-app/mbed/main/LowPowerManager.cpp @@ -16,7 +16,10 @@ * limitations under the License. */ -bool lowPowerClusterSleep() +#include "LowPowerManager.h" + +bool LowPowerManager::HandleSleep() { + // TODO: Insert code here return true; } diff --git a/examples/all-clusters-app/mbed/main/include/LowPowerManager.h b/examples/all-clusters-app/mbed/main/include/LowPowerManager.h new file mode 100644 index 00000000000000..92bb1417be514d --- /dev/null +++ b/examples/all-clusters-app/mbed/main/include/LowPowerManager.h @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +class LowPowerManager : public chip::app::Clusters::LowPower::Delegate +{ +public: + bool HandleSleep() override; +}; diff --git a/examples/thermostat/linux/include/low-power/LowPowerManager.cpp b/examples/thermostat/linux/include/low-power/LowPowerManager.cpp index 97016d4b01a74f..57399c0ba1de5c 100644 --- a/examples/thermostat/linux/include/low-power/LowPowerManager.cpp +++ b/examples/thermostat/linux/include/low-power/LowPowerManager.cpp @@ -18,7 +18,7 @@ #include "LowPowerManager.h" -bool lowPowerClusterSleep() +bool LowPowerManager::HandleSleep() { // TODO: Insert code here return true; diff --git a/examples/thermostat/linux/include/low-power/LowPowerManager.h b/examples/thermostat/linux/include/low-power/LowPowerManager.h index 75d500ca12de74..92bb1417be514d 100644 --- a/examples/thermostat/linux/include/low-power/LowPowerManager.h +++ b/examples/thermostat/linux/include/low-power/LowPowerManager.h @@ -18,9 +18,10 @@ #pragma once -#include +#include -class LowPowerManager +class LowPowerManager : public chip::app::Clusters::LowPower::Delegate { public: + bool HandleSleep() override; }; diff --git a/examples/tv-app/android/include/account-login/AccountLoginManager.cpp b/examples/tv-app/android/include/account-login/AccountLoginManager.cpp index ed816f72f3648d..f391901e136e32 100644 --- a/examples/tv-app/android/include/account-login/AccountLoginManager.cpp +++ b/examples/tv-app/android/include/account-login/AccountLoginManager.cpp @@ -17,75 +17,35 @@ */ #include "AccountLoginManager.h" -#include -#include -#include -#include -#include #include #include using namespace std; +using namespace chip::app::Clusters::AccountLogin; -bool AccountLoginManager::isUserLoggedIn(string requestTempAccountIdentifier, string requestSetupPin) +bool AccountLoginManager::HandleLogin(const chip::CharSpan & tempAccountIdentifier, const chip::CharSpan & setupPin) { - // TODO: Fix hardcoding length of strings - requestTempAccountIdentifier = requestTempAccountIdentifier.substr(0, 4); - requestSetupPin = requestSetupPin.substr(0, 10); - for (auto it = accounts.cbegin(); it != accounts.cend(); ++it) - { - ChipLogProgress(Zcl, "temporary account id: %s", it->first.c_str()); - ChipLogProgress(Zcl, "setup pin %s", it->second.c_str()); - } + string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); + string setupPinString(setupPin.data(), setupPin.size()); + ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str()); + ChipLogProgress(Zcl, "setup pin %s", setupPinString.c_str()); - if (accounts.find(requestTempAccountIdentifier) != accounts.end()) - { - bool found = accounts[requestTempAccountIdentifier] == requestSetupPin; - if (!found) - { - ChipLogError(Zcl, "User is not logged in, failed to match request setup pin."); - } - return found; - } - else - { - ChipLogError(Zcl, "User is not logged in, failed to find temp account identifier."); - return false; - } -} - -void AccountLoginManager::setTempAccountIdentifierForPin(string tempAccountIdentifier, string setupPin) -{ - // TODO: Fix hardcoding length of strings - string tempId = tempAccountIdentifier.substr(0, 4); - accounts[tempId] = setupPin; -} - -string AccountLoginManager::proxySetupPinRequest(string requestTempAccountIdentifier, chip::EndpointId endpoint) -{ - // TODO: Insert your code here to send temp account identifier request - return "tempPin123"; + // TODO: Insert your code here to handle login request + return true; } -bool AccountLoginManager::proxyLogout() +bool AccountLoginManager::HandleLogout() { // TODO: Insert your code here to send logout request return true; } -bool accountLoginClusterIsUserLoggedIn(std::string requestTempAccountIdentifier, std::string requestSetupPin) -{ - return AccountLoginManager().GetInstance().isUserLoggedIn(requestTempAccountIdentifier, requestSetupPin); -} - -bool accountLoginClusterLogout() -{ - return AccountLoginManager().GetInstance().proxyLogout(); -} - -std::string accountLoginClusterGetSetupPin(std::string requestTempAccountIdentifier, chip::EndpointId endpoint) +Commands::GetSetupPINResponse::Type AccountLoginManager::HandleGetSetupPin(const chip::CharSpan & tempAccountIdentifier) { - string responseSetupPin = AccountLoginManager().proxySetupPinRequest(requestTempAccountIdentifier, endpoint); - AccountLoginManager().GetInstance().setTempAccountIdentifierForPin(requestTempAccountIdentifier, responseSetupPin); - return responseSetupPin; + string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); + ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str()); + // TODO: Insert your code here to handle get setup pin + Commands::GetSetupPINResponse::Type response; + response.setupPIN = chip::CharSpan("tempPin123", strlen("tempPin123")); + return response; } diff --git a/examples/tv-app/android/include/account-login/AccountLoginManager.h b/examples/tv-app/android/include/account-login/AccountLoginManager.h index 7377d95b18e0bf..68584ae6ec7bd5 100644 --- a/examples/tv-app/android/include/account-login/AccountLoginManager.h +++ b/examples/tv-app/android/include/account-login/AccountLoginManager.h @@ -18,25 +18,15 @@ #pragma once +#include + #include -#include -#include -#include -class AccountLoginManager +class AccountLoginManager : public chip::app::Clusters::AccountLogin::Delegate { public: - bool isUserLoggedIn(std::string requestTempAccountIdentifier, std::string requestSetupPin); - bool proxyLogout(); - std::string proxySetupPinRequest(std::string requestTempAccountIdentifier, chip::EndpointId endpoint); - void setTempAccountIdentifierForPin(std::string requestTempAccountIdentifier, std::string requestSetupPin); - - static AccountLoginManager & GetInstance() - { - static AccountLoginManager instance; - return instance; - } - -private: - std::map accounts; + bool HandleLogin(const chip::CharSpan & tempAccountIdentifierString, const chip::CharSpan & setupPinString) override; + bool HandleLogout() override; + chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::Type + HandleGetSetupPin(const chip::CharSpan & tempAccountIdentifierString) override; }; diff --git a/examples/tv-app/android/include/application-basic/ApplicationBasicManager.cpp b/examples/tv-app/android/include/application-basic/ApplicationBasicManager.cpp index 46cb642b9a8984..1a979da92efcc7 100644 --- a/examples/tv-app/android/include/application-basic/ApplicationBasicManager.cpp +++ b/examples/tv-app/android/include/application-basic/ApplicationBasicManager.cpp @@ -17,139 +17,49 @@ */ #include "ApplicationBasicManager.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +using namespace std; +using namespace chip::app::Clusters::ApplicationBasic; -using namespace chip; - -CHIP_ERROR ApplicationBasicManager::Init() +chip::CharSpan ApplicationBasicManager::HandleGetVendorName() { - CHIP_ERROR err = CHIP_NO_ERROR; - EndpointConfigurationStorage & endpointConfiguration = EndpointConfigurationStorage::GetInstance(); - err = endpointConfiguration.Init(); - SuccessOrExit(err); - es = &endpointConfiguration; -exit: - return err; + return chip::CharSpan("exampleVendorName1", strlen("exampleVendorName1")); } -void ApplicationBasicManager::store(chip::EndpointId endpoint, chip::app::Clusters::ApplicationBasic::Application * application) +uint16_t ApplicationBasicManager::HandleGetVendorId() { - uint8_t bufferMemory[64]; - MutableByteSpan zclString(bufferMemory); - - MakeZclCharString(zclString, application->vendorName); - EmberAfStatus vendorNameStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_VENDOR_NAME_ATTRIBUTE_ID, - zclString.data(), ZCL_CHAR_STRING_ATTRIBUTE_TYPE); - if (vendorNameStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store vendor name attribute."); - } - - EmberAfStatus vendorIdStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_VENDOR_ID_ATTRIBUTE_ID, - (uint8_t *) &application->vendorId, ZCL_INT16U_ATTRIBUTE_TYPE); - if (vendorIdStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store vendor id attribute."); - } - - MakeZclCharString(zclString, application->name); - EmberAfStatus nameStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_NAME_ATTRIBUTE_ID, zclString.data(), - ZCL_CHAR_STRING_ATTRIBUTE_TYPE); - if (nameStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store name attribute."); - } - - MakeZclCharString(zclString, application->version); - EmberAfStatus versionStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_VERSION_ATTRIBUTE_ID, - zclString.data(), ZCL_CHAR_STRING_ATTRIBUTE_TYPE); - if (versionStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store version attribute."); - } - - EmberAfStatus productIdStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_PRODUCT_ID_ATTRIBUTE_ID, - (uint8_t *) &application->productId, ZCL_INT16U_ATTRIBUTE_TYPE); - if (productIdStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store product id attribute."); - } - - EmberAfStatus applicationStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_STATUS_ATTRIBUTE_ID, - (uint8_t *) &application->status, ZCL_ENUM8_ATTRIBUTE_TYPE); - if (applicationStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store status attribute."); - } + return 1; } -chip::app::Clusters::ApplicationBasic::Application ApplicationBasicManager::getApplicationForEndpoint(chip::EndpointId endpoint) +chip::CharSpan ApplicationBasicManager::HandleGetApplicationName() { - chip::app::Clusters::ApplicationBasic::Application app = {}; - uint16_t size = static_cast(sizeof(app.name)); - - std::string section = "endpoint" + std::to_string(endpoint); - - CHIP_ERROR err = es->get(section, "name", app.name, size); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app name. Error:%s", chip::ErrorStr(err)); - } - - err = es->get(section, "vendorName", app.vendorName, size); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app vendor name. Error:%s", chip::ErrorStr(err)); - } - - err = es->get(section, "id", app.id, size); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app id. Error:%s", chip::ErrorStr(err)); - } + return chip::CharSpan("exampleName1", strlen("exampleName1")); +} - err = es->get(section, "catalogVendorId", app.catalogVendorId); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app catalog vendor id. Error:%s", chip::ErrorStr(err)); - } +uint16_t ApplicationBasicManager::HandleGetProductId() +{ + return 1; +} - err = es->get(section, "productId", app.productId); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app product id. Error:%s", chip::ErrorStr(err)); - } +chip::app::Clusters::ApplicationBasic::Structs::Application::Type ApplicationBasicManager::HandleGetApplication() +{ + chip::app::Clusters::ApplicationBasic::Structs::Application::Type application; + application.catalogVendorId = 123; + application.applicationId = chip::CharSpan("applicationId", strlen("applicationId")); + return application; +} - err = es->get(section, "vendorId", app.vendorId); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app vendor id. Error:%s", chip::ErrorStr(err)); - } +ApplicationStatusEnum ApplicationBasicManager::HandleGetStatus() +{ + return ApplicationStatusEnum::kStopped; +} - return app; +chip::CharSpan ApplicationBasicManager::HandleGetApplicationVersion() +{ + return chip::CharSpan("exampleVersion", strlen("exampleVersion")); } -bool applicationBasicClusterChangeApplicationStatus(chip::EndpointId endpoint, - app::Clusters::ApplicationBasic::ApplicationStatusEnum status) +std::list ApplicationBasicManager::HandleGetAllowedVendorList() { - // TODO: Insert code here - ChipLogProgress(Zcl, "Sent an application status change request %d for endpoint %d", to_underlying(status), endpoint); - return true; + return { 123, 456 }; } diff --git a/examples/tv-app/android/include/application-basic/ApplicationBasicManager.h b/examples/tv-app/android/include/application-basic/ApplicationBasicManager.h index 3395247400d6ef..e907fc8891861e 100644 --- a/examples/tv-app/android/include/application-basic/ApplicationBasicManager.h +++ b/examples/tv-app/android/include/application-basic/ApplicationBasicManager.h @@ -18,26 +18,17 @@ #pragma once -#include -#include +#include -#include "../endpoint-configuration/EndpointConfigurationStorage.h" -#include "Application.h" -#include - -class ApplicationBasicManager +class ApplicationBasicManager : public chip::app::Clusters::ApplicationBasic::Delegate { public: - CHIP_ERROR Init(); - void store(chip::EndpointId endpoint, chip::app::Clusters::ApplicationBasic::Application * application); - chip::app::Clusters::ApplicationBasic::Application getApplicationForEndpoint(chip::EndpointId endpoint); - - static ApplicationBasicManager & GetInstance() - { - static ApplicationBasicManager instance; - return instance; - } - -private: - EndpointConfigurationStorage * es = nullptr; + chip::CharSpan HandleGetVendorName() override; + uint16_t HandleGetVendorId() override; + chip::CharSpan HandleGetApplicationName() override; + uint16_t HandleGetProductId() override; + chip::app::Clusters::ApplicationBasic::Structs::Application::Type HandleGetApplication() override; + chip::app::Clusters::ApplicationBasic::ApplicationStatusEnum HandleGetStatus() override; + chip::CharSpan HandleGetApplicationVersion() override; + std::list HandleGetAllowedVendorList() override; }; diff --git a/examples/tv-app/android/include/application-launcher/ApplicationLauncherManager.cpp b/examples/tv-app/android/include/application-launcher/ApplicationLauncherManager.cpp index 783ef51189be1b..f6a8afc0ae8ee7 100644 --- a/examples/tv-app/android/include/application-launcher/ApplicationLauncherManager.cpp +++ b/examples/tv-app/android/include/application-launcher/ApplicationLauncherManager.cpp @@ -17,66 +17,50 @@ */ #include "ApplicationLauncherManager.h" -#include -#include -#include -#include -#include -#include using namespace std; +using namespace chip::app::Clusters::ApplicationLauncher; -CHIP_ERROR ApplicationLauncherManager::Init() +Structs::ApplicationEP::Type ApplicationLauncherManager::HandleGetCurrentApp() { - CHIP_ERROR err = CHIP_NO_ERROR; - - SuccessOrExit(err); -exit: - return err; + Structs::ApplicationEP::Type currentApp; + currentApp.application.catalogVendorId = 123; + currentApp.application.applicationId = chip::CharSpan("applicationId", strlen("applicationId")); + currentApp.endpoint = chip::CharSpan("endpointId", strlen("endpointId")); + return currentApp; } -CHIP_ERROR ApplicationLauncherManager::proxyGetApplicationList(chip::app::AttributeValueEncoder & aEncoder) +std::list ApplicationLauncherManager::HandleGetCatalogList() { - return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { - ReturnErrorOnFailure(encoder.Encode(123u)); - ReturnErrorOnFailure(encoder.Encode(456u)); - return CHIP_NO_ERROR; - }); + return { 123, 456 }; } -ApplicationLauncherResponse applicationLauncherClusterLaunchApp(chip::EndpointId endpoint, Application application, - std::string data) +Commands::LauncherResponse::Type ApplicationLauncherManager::HandleLaunchApp( + const chip::CharSpan & data, const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) { - // TODO: Insert your code - ApplicationLauncherResponse response; - const char * testData = "data"; - response.data = (uint8_t *) testData; - response.status = chip::to_underlying(chip::app::Clusters::ApplicationLauncher::StatusEnum::kSuccess); - // TODO: Update once storing a structure attribute is supported - // emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_LAUNCH_CLUSTER_ID, ZCL_APPLICATION_LAUNCHER_CURRENT_APP_APPLICATION_ID, - // (uint8_t *) &application, ZCL_STRUCT_ATTRIBUTE_TYPE); - + // TODO: Insert code here + Commands::LauncherResponse::Type response; + response.data = chip::CharSpan("data", strlen("data")); + response.status = StatusEnum::kSuccess; return response; } -ApplicationLauncherResponse applicationLauncherClusterStopApp(chip::EndpointId endpoint, Application application, std::string data) +Commands::LauncherResponse::Type +ApplicationLauncherManager::HandleStopApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) { - ChipLogProgress(Zcl, "ApplicationLauncherManager::applicationLauncherClusterStopApp"); - - ApplicationLauncherResponse response; - const char * testData = "data"; - response.data = (uint8_t *) testData; - response.status = chip::to_underlying(chip::app::Clusters::ApplicationLauncher::StatusEnum::kSuccess); + // TODO: Insert code here + Commands::LauncherResponse::Type response; + response.data = chip::CharSpan("data", strlen("data")); + response.status = StatusEnum::kSuccess; return response; } -ApplicationLauncherResponse applicationLauncherClusterHideApp(chip::EndpointId endpoint, Application application, std::string data) +Commands::LauncherResponse::Type +ApplicationLauncherManager::HandleHideApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) { - ChipLogProgress(Zcl, "ApplicationLauncherManager::applicationLauncherClusterHideApp"); - - ApplicationLauncherResponse response; - const char * testData = "data"; - response.data = (uint8_t *) testData; - response.status = chip::to_underlying(chip::app::Clusters::ApplicationLauncher::StatusEnum::kSuccess); + // TODO: Insert code here + Commands::LauncherResponse::Type response; + response.data = chip::CharSpan("data", strlen("data")); + response.status = StatusEnum::kSuccess; return response; } diff --git a/examples/tv-app/android/include/application-launcher/ApplicationLauncherManager.h b/examples/tv-app/android/include/application-launcher/ApplicationLauncherManager.h index 718321e16b5ce0..c01c3e243d66d1 100644 --- a/examples/tv-app/android/include/application-launcher/ApplicationLauncherManager.h +++ b/examples/tv-app/android/include/application-launcher/ApplicationLauncherManager.h @@ -18,15 +18,20 @@ #pragma once -#include -#include +#include +#include -#include -#include - -class ApplicationLauncherManager +class ApplicationLauncherManager : public chip::app::Clusters::ApplicationLauncher::Delegate { public: - CHIP_ERROR Init(); - CHIP_ERROR proxyGetApplicationList(chip::app::AttributeValueEncoder & aEncoder); + chip::app::Clusters::ApplicationLauncher::Structs::ApplicationEP::Type HandleGetCurrentApp() override; + std::list HandleGetCatalogList() override; + + chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type + HandleLaunchApp(const chip::CharSpan & data, + const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) override; + chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type + HandleStopApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) override; + chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type + HandleHideApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) override; }; diff --git a/examples/tv-app/android/include/audio-output/AudioOutputManager.cpp b/examples/tv-app/android/include/audio-output/AudioOutputManager.cpp index 90b953330a6c5d..e3eccf8afa2232 100644 --- a/examples/tv-app/android/include/audio-output/AudioOutputManager.cpp +++ b/examples/tv-app/android/include/audio-output/AudioOutputManager.cpp @@ -18,53 +18,38 @@ #include "AudioOutputManager.h" -#include -#include -#include -#include -#include - -#include -#include - using namespace std; +using namespace chip::app::Clusters::AudioOutput; -CHIP_ERROR AudioOutputManager::Init() +uint8_t AudioOutputManager::HandleGetCurrentOutput() { - CHIP_ERROR err = CHIP_NO_ERROR; - - // TODO: Store feature map once it is supported - map featureMap; - featureMap["NU"] = true; - - return err; + return 0; } -CHIP_ERROR AudioOutputManager::proxyGetListOfAudioOutputInfo(chip::app::AttributeValueEncoder & aEncoder) +std::list AudioOutputManager::HandleGetOutputList() { - return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { - // TODO: Insert code here - int maximumVectorSize = 3; - char name[] = "exampleName"; - - for (int i = 0; i < maximumVectorSize; ++i) - { - chip::app::Clusters::AudioOutput::Structs::OutputInfo::Type outputInfo; - outputInfo.outputType = chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi; - outputInfo.name = chip::CharSpan(name, sizeof(name) - 1); - outputInfo.index = static_cast(1 + i); - ReturnErrorOnFailure(encoder.Encode(outputInfo)); - } - return CHIP_NO_ERROR; - }); + std::list list; + // TODO: Insert code here + int maximumVectorSize = 3; + + for (int i = 0; i < maximumVectorSize; ++i) + { + chip::app::Clusters::AudioOutput::Structs::OutputInfo::Type outputInfo; + outputInfo.outputType = chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi; + outputInfo.name = chip::CharSpan("exampleName", strlen("exampleName")); + outputInfo.index = static_cast(1 + i); + list.push_back(outputInfo); + } + return list; } -bool audioOutputClusterSelectOutput(uint8_t index) +bool AudioOutputManager::HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name) { // TODO: Insert code here return true; } -bool audioOutputClusterRenameOutput(uint8_t index, const chip::CharSpan & name) + +bool AudioOutputManager::HandleSelectOutput(const uint8_t & index) { // TODO: Insert code here return true; diff --git a/examples/tv-app/android/include/audio-output/AudioOutputManager.h b/examples/tv-app/android/include/audio-output/AudioOutputManager.h index 63d455427e68ae..8dcd3ed344fc9a 100644 --- a/examples/tv-app/android/include/audio-output/AudioOutputManager.h +++ b/examples/tv-app/android/include/audio-output/AudioOutputManager.h @@ -18,13 +18,13 @@ #pragma once -#include +#include -#include -#include -class AudioOutputManager +class AudioOutputManager : public chip::app::Clusters::AudioOutput::Delegate { public: - CHIP_ERROR Init(); - CHIP_ERROR proxyGetListOfAudioOutputInfo(chip::app::AttributeValueEncoder & aEncoder); + uint8_t HandleGetCurrentOutput() override; + std::list HandleGetOutputList() override; + bool HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name) override; + bool HandleSelectOutput(const uint8_t & index) override; }; diff --git a/examples/tv-app/android/include/cluster-init.cpp b/examples/tv-app/android/include/cluster-init.cpp index 9acc2ee37aa084..87eff6e1928a8a 100644 --- a/examples/tv-app/android/include/cluster-init.cpp +++ b/examples/tv-app/android/include/cluster-init.cpp @@ -32,24 +32,11 @@ using namespace chip; namespace { -template -class TvAttrAccess : public app::AttributeAccessInterface -{ -public: - TvAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), AttrTypeInfo::GetClusterId()) {} - - CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override - { - if (aPath.mAttributeId == AttrTypeInfo::GetAttributeId()) - { - return (Manager().*Getter)(aEncoder); - } - - return CHIP_NO_ERROR; - } -}; - -} // anonymous namespace +static ApplicationBasicManager applicationBasicManager; +static ApplicationLauncherManager applicationLauncherManager; +static AudioOutputManager audioOutputManager; +static TargetNavigatorManager targetNavigatorManager; +} // namespace /** @brief Application Basic Cluster Init * @@ -62,28 +49,10 @@ class TvAttrAccess : public app::AttributeAccessInterface */ void emberAfApplicationBasicClusterInitCallback(chip::EndpointId endpoint) { - CHIP_ERROR err = CHIP_NO_ERROR; - ApplicationBasicManager & aManager = ApplicationBasicManager::GetInstance(); - err = aManager.Init(); - if (CHIP_NO_ERROR == err) - { - chip::app::Clusters::ApplicationBasic::Application application = aManager.getApplicationForEndpoint(endpoint); - aManager.store(endpoint, &application); - } - else - { - ChipLogError(Zcl, "Failed to store application for endpoint: %d. Error:%s", endpoint, chip::ErrorStr(err)); - } + ChipLogProgress(Zcl, "TV Linux App: ApplicationBasic::SetDefaultDelegate"); + chip::app::Clusters::ApplicationBasic::SetDefaultDelegate(endpoint, &applicationBasicManager); } -namespace { - -TvAttrAccess - gApplicationLauncherAttrAccess; - -} // anonymous namespace - /** @brief Application Launcher Cluster Init * * This function is called when a specific cluster is initialized. It gives the @@ -95,22 +64,10 @@ TvAttrAccess - gAudioOutputAttrAccess; - -} // anonymous namespace - /** @brief Audio Output Cluster Init * * This function is called when a specific cluster is initialized. It gives the @@ -122,22 +79,10 @@ TvAttrAccess - gTargetNavigatorAttrAccess; - -} // anonymous namespace - /** @brief Target Navigator Cluster Init * * This function is called when a specific cluster is initialized. It gives the @@ -149,10 +94,6 @@ TvAttrAccess -#include -#include -#include -#include -#include - -#include -#include using namespace std; +using namespace chip::app::Clusters::TargetNavigator; -CHIP_ERROR TargetNavigatorManager::Init() +std::list TargetNavigatorManager::HandleGetTargetList() { - CHIP_ERROR err = CHIP_NO_ERROR; - - SuccessOrExit(err); -exit: - return err; + std::list list; + // TODO: Insert code here + int maximumVectorSize = 2; + + for (int i = 0; i < maximumVectorSize; ++i) + { + Structs::TargetInfo::Type outputInfo; + outputInfo.identifier = static_cast(i + 1); + outputInfo.name = chip::CharSpan("exampleName", strlen("exampleName")); + list.push_back(outputInfo); + } + return list; } -CHIP_ERROR TargetNavigatorManager::proxyGetTargetInfoList(chip::app::AttributeValueEncoder & aEncoder) +uint8_t TargetNavigatorManager::HandleGetCurrentTarget() { - return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { - // TODO: Insert code here - int maximumVectorSize = 2; - char name[] = "exampleName"; - - for (int i = 0; i < maximumVectorSize; ++i) - { - chip::app::Clusters::TargetNavigator::Structs::TargetInfo::Type targetInfo; - targetInfo.name = chip::CharSpan(name, sizeof(name) - 1); - targetInfo.identifier = static_cast(1 + i); - ReturnErrorOnFailure(encoder.Encode(targetInfo)); - } - return CHIP_NO_ERROR; - }); + return 0; } -TargetNavigatorResponse targetNavigatorClusterNavigateTarget(chip::EndpointId endpointId, uint8_t target, std::string data) +Commands::NavigateTargetResponse::Type TargetNavigatorManager::HandleNavigateTarget(const uint64_t & target, + const chip::CharSpan & data) { // TODO: Insert code here - TargetNavigatorResponse response; - const char * testData = "data response"; - response.data = (uint8_t *) testData; - response.status = chip::to_underlying(chip::app::Clusters::TargetNavigator::StatusEnum::kSuccess); + Commands::NavigateTargetResponse::Type response; + response.data = chip::CharSpan("data response", strlen("data response")); + response.status = chip::app::Clusters::TargetNavigator::StatusEnum::kSuccess; return response; } diff --git a/examples/tv-app/android/include/target-navigator/TargetNavigatorManager.h b/examples/tv-app/android/include/target-navigator/TargetNavigatorManager.h index 2aa604611f740d..7da10ea51448f5 100644 --- a/examples/tv-app/android/include/target-navigator/TargetNavigatorManager.h +++ b/examples/tv-app/android/include/target-navigator/TargetNavigatorManager.h @@ -17,15 +17,13 @@ #pragma once -#include +#include -#include -#include -#include - -class TargetNavigatorManager +class TargetNavigatorManager : public chip::app::Clusters::TargetNavigator::Delegate { public: - CHIP_ERROR Init(); - CHIP_ERROR proxyGetTargetInfoList(chip::app::AttributeValueEncoder & aEncoder); + std::list HandleGetTargetList() override; + uint8_t HandleGetCurrentTarget() override; + chip::app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::Type + HandleNavigateTarget(const uint64_t & target, const chip::CharSpan & data) override; }; diff --git a/examples/tv-app/android/java/ChannelManager.cpp b/examples/tv-app/android/java/ChannelManager.cpp index 9a8a80d48544d5..cd0b2f79fd4a0c 100644 --- a/examples/tv-app/android/java/ChannelManager.cpp +++ b/examples/tv-app/android/java/ChannelManager.cpp @@ -16,152 +16,33 @@ */ #include "ChannelManager.h" -#include -#include -#include -#include -#include #include #include -#include #include #include -#include - -#include -#include -#include using namespace chip; +using namespace chip::app::Clusters::Channel; -ChannelManager ChannelManager::sInstance; - -class ChannelInfoAttrAccess : public app::AttributeAccessInterface -{ -public: - ChannelInfoAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), app::Clusters::Channel::Id) {} - CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override - { - if (aPath.mAttributeId == app::Clusters::Channel::Attributes::ChannelList::Id) - { - return ChannelMgr().getChannelList(aEncoder); - } - else if (aPath.mAttributeId == app::Clusters::Channel::Attributes::ChannelLineup::Id) - { - return ChannelMgr().getChannelLineup(aEncoder); - } - else if (aPath.mAttributeId == app::Clusters::Channel::Attributes::CurrentChannel::Id) - { - return ChannelMgr().getCurrentChannel(aEncoder); - } - - return CHIP_NO_ERROR; - } -}; - -ChannelInfoAttrAccess gChannelAttrAccess; - -/** @brief Channel Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfChannelClusterInitCallback(EndpointId endpoint) -{ - static bool attrAccessRegistered = false; - if (!attrAccessRegistered) - { - registerAttributeAccessOverride(&gChannelAttrAccess); - attrAccessRegistered = true; - } -} - -ChannelInfo ChannelClusterChangeChannel(std::string match) -{ - return ChannelMgr().ChangeChannelByMatch(match); -} - -bool ChannelClusterChangeChannelByNumber(uint16_t majorNumber, uint16_t minorNumber) -{ - return ChannelMgr().changeChannelByNumber(majorNumber, minorNumber); -} - -bool ChannelClusterSkipChannel(uint16_t count) -{ - return ChannelMgr().skipChannnel(count); -} - -void ChannelManager::InitializeWithObjects(jobject managerObject) -{ - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ChannelManager")); - - mChannelManagerObject = env->NewGlobalRef(managerObject); - VerifyOrReturn(mChannelManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef ChannelManager")); - - jclass managerClass = env->GetObjectClass(mChannelManagerObject); - VerifyOrReturn(managerClass != nullptr, ChipLogError(Zcl, "Failed to get ChannelManager Java class")); - - mGetChannelListMethod = env->GetMethodID(managerClass, "getChannelList", "()[Lcom/tcl/chip/tvapp/ChannelInfo;"); - if (mGetChannelListMethod == nullptr) - { - ChipLogError(Zcl, "Failed to access ChannelManager 'getChannelList' method"); - env->ExceptionClear(); - } - - mGetLineupMethod = env->GetMethodID(managerClass, "getLineup", "()Lcom/tcl/chip/tvapp/ChannelLineupInfo;"); - if (mGetLineupMethod == nullptr) - { - ChipLogError(Zcl, "Failed to access ChannelManager 'getLineup' method"); - env->ExceptionClear(); - } - - mGetCurrentChannelMethod = env->GetMethodID(managerClass, "getCurrentChannel", "()Lcom/tcl/chip/tvapp/ChannelInfo;"); - if (mGetCurrentChannelMethod == nullptr) - { - ChipLogError(Zcl, "Failed to access ChannelManager 'getCurrentChannel' method"); - env->ExceptionClear(); - } - - mChangeChannelMethod = env->GetMethodID(managerClass, "changeChannel", "(Ljava/lang/String;)Lcom/tcl/chip/tvapp/ChannelInfo;"); - if (mChangeChannelMethod == nullptr) - { - ChipLogError(Zcl, "Failed to access ChannelManager 'changeChannel' method"); - env->ExceptionClear(); - } - - mchangeChannelByNumberMethod = env->GetMethodID(managerClass, "changeChannelByNumber", "(II)Z"); - if (mchangeChannelByNumberMethod == nullptr) - { - ChipLogError(Zcl, "Failed to access ChannelManager 'changeChannelByNumber' method"); - env->ExceptionClear(); - } - - mskipChannelMethod = env->GetMethodID(managerClass, "skipChannel", "(I)Z"); - if (mskipChannelMethod == nullptr) - { - ChipLogError(Zcl, "Failed to access ChannelManager 'skipChannel' method"); - env->ExceptionClear(); - } -} +namespace { +static ChannelManager channelManager; +} // namespace -CHIP_ERROR ChannelManager::getChannelList(chip::app::AttributeValueEncoder & aEncoder) +std::list ChannelManager::HandleGetChannelList() { + std::list list; CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received ChannelManager::getChannelList"); + ChipLogProgress(Zcl, "Received ChannelManager::HandleGetChannelList"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(mGetChannelListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); - return aEncoder.EncodeList([env, this](const auto & encoder) -> CHIP_ERROR { + { jobjectArray channelInfoList = (jobjectArray) env->CallObjectMethod(mChannelManagerObject, mGetChannelListMethod); jint length = env->GetArrayLength(channelInfoList); + for (jint i = 0; i < length; i++) { chip::app::Clusters::Channel::Structs::ChannelInfo::Type channelInfo; @@ -199,32 +80,31 @@ CHIP_ERROR ChannelManager::getChannelList(chip::app::AttributeValueEncoder & aEn jfieldID minorNumField = env->GetFieldID(channelClass, "minorNumber", "I"); jint jminorNum = env->GetIntField(channelObject, minorNumField); channelInfo.majorNumber = static_cast(jminorNum); - ReturnErrorOnFailure(encoder.Encode(channelInfo)); + list.push_back(channelInfo); } - return CHIP_NO_ERROR; - }); + } + exit: if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "ChannelManager::getChannelList status error: %s", err.AsString()); } - return err; + return list; } -CHIP_ERROR ChannelManager::getChannelLineup(chip::app::AttributeValueEncoder & aEncoder) +chip::app::Clusters::Channel::Structs::LineupInfo::Type ChannelManager::HandleGetLineup() { + chip::app::Clusters::Channel::Structs::LineupInfo::Type lineupInfo; CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received ChannelManager::getChannelLineup"); + ChipLogProgress(Zcl, "Received ChannelManager::HandleGetLineup"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(mGetLineupMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); { - chip::app::Clusters::Channel::Structs::LineupInfo::Type lineupInfo; - jobject channelLineupObject = env->CallObjectMethod(mChannelManagerObject, mGetLineupMethod); jclass channelLineupClazz = env->GetObjectClass(channelLineupObject); @@ -255,10 +135,6 @@ CHIP_ERROR ChannelManager::getChannelLineup(chip::app::AttributeValueEncoder & a jfieldID lineupInfoTypeFild = env->GetFieldID(channelLineupClazz, "lineupInfoTypeEnum", "I"); jint jlineupInfoType = (env->GetIntField(channelLineupObject, lineupInfoTypeFild)); lineupInfo.lineupInfoType = static_cast(jlineupInfoType); - - ReturnErrorOnFailure(aEncoder.Encode(lineupInfo)); - - return CHIP_NO_ERROR; } exit: @@ -267,21 +143,20 @@ CHIP_ERROR ChannelManager::getChannelLineup(chip::app::AttributeValueEncoder & a ChipLogError(Zcl, "ChannelManager::getChannelLineup status error: %s", err.AsString()); } - return err; + return lineupInfo; } -CHIP_ERROR ChannelManager::getCurrentChannel(chip::app::AttributeValueEncoder & aEncoder) +chip::app::Clusters::Channel::Structs::ChannelInfo::Type ChannelManager::HandleGetCurrentChannel() { + chip::app::Clusters::Channel::Structs::ChannelInfo::Type channelInfo; CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received ChannelManager::getCurrentChannel"); + ChipLogProgress(Zcl, "Received ChannelManager::HandleGetCurrentChannel"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(mGetCurrentChannelMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); { - chip::app::Clusters::Channel::Structs::ChannelInfo::Type channelInfo; - jobject channelInfoObject = env->CallObjectMethod(mChannelManagerObject, mGetCurrentChannelMethod); jclass channelClass = env->GetObjectClass(channelInfoObject); @@ -316,26 +191,27 @@ CHIP_ERROR ChannelManager::getCurrentChannel(chip::app::AttributeValueEncoder & jfieldID minorNumField = env->GetFieldID(channelClass, "minorNumber", "I"); jint jminorNum = env->GetIntField(channelInfoObject, minorNumField); channelInfo.majorNumber = static_cast(jminorNum); - - ReturnErrorOnFailure(aEncoder.Encode(channelInfo)); - return CHIP_NO_ERROR; } exit: if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "ChannelManager::getChannel status error: %s", err.AsString()); + ChipLogError(Zcl, "ChannelManager::HandleGetCurrentChannel status error: %s", err.AsString()); } - return err; + return channelInfo; } -ChannelInfo ChannelManager::ChangeChannelByMatch(std::string name) +Commands::ChangeChannelResponse::Type ChannelManager::HandleChangeChannel(const chip::CharSpan & match) { + std::string name(match.data(), match.size()); JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChannelInfo channelInfo{ 0, 0 }; - ChipLogProgress(Zcl, "Received ChannelManager::ChangeChannelByMatch name %s", name.c_str()); + Commands::ChangeChannelResponse::Type response; + response.channelMatch.majorNumber = 0; + response.channelMatch.minorNumber = 0; + + ChipLogProgress(Zcl, "Received ChannelManager::HandleChangeChannel name %s", name.c_str()); VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null")); VerifyOrExit(mChangeChannelMethod != nullptr, ChipLogError(Zcl, "mChangeChannelMethod null")); VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null")); @@ -346,10 +222,10 @@ ChannelInfo ChannelManager::ChangeChannelByMatch(std::string name) jobject channelObject = env->CallObjectMethod(mChannelManagerObject, mChangeChannelMethod, jniname.jniValue()); if (env->ExceptionCheck()) { - ChipLogError(DeviceLayer, "Java exception in ChannelManager::ChangeChannelByMatch"); + ChipLogError(DeviceLayer, "Java exception in ChannelManager::HandleChangeChannel"); env->ExceptionDescribe(); env->ExceptionClear(); - return channelInfo; + return response; } jclass channelClass = env->GetObjectClass(channelObject); @@ -359,7 +235,7 @@ ChannelInfo ChannelManager::ChangeChannelByMatch(std::string name) if (jcallSign != NULL) { JniUtfString callsign(env, jcallSign); - channelInfo.callSign = callsign.charSpan(); + response.channelMatch.callSign = callsign.charSpan(); } jfieldID getNameField = env->GetFieldID(channelClass, "name", "Ljava/lang/String;"); @@ -367,43 +243,44 @@ ChannelInfo ChannelManager::ChangeChannelByMatch(std::string name) if (jname != NULL) { JniUtfString junitname(env, jname); - channelInfo.callSign = junitname.charSpan(); + response.channelMatch.callSign = junitname.charSpan(); } jfieldID getJaffiliateCallSignField = env->GetFieldID(channelClass, "affiliateCallSign", "Ljava/lang/String;"); jstring jaffiliateCallSign = static_cast(env->GetObjectField(channelObject, getJaffiliateCallSignField)); if (jaffiliateCallSign != NULL) { JniUtfString affiliateCallSign(env, jaffiliateCallSign); - channelInfo.callSign = affiliateCallSign.charSpan(); + response.channelMatch.callSign = affiliateCallSign.charSpan(); } - jfieldID majorNumField = env->GetFieldID(channelClass, "majorNumber", "I"); - jint jmajorNum = env->GetIntField(channelObject, majorNumField); - channelInfo.majorNumber = static_cast(jmajorNum); + jfieldID majorNumField = env->GetFieldID(channelClass, "majorNumber", "I"); + jint jmajorNum = env->GetIntField(channelObject, majorNumField); + response.channelMatch.majorNumber = static_cast(jmajorNum); - jfieldID minorNumField = env->GetFieldID(channelClass, "minorNumber", "I"); - jint jminorNum = env->GetIntField(channelObject, minorNumField); - channelInfo.majorNumber = static_cast(jminorNum); + jfieldID minorNumField = env->GetFieldID(channelClass, "minorNumber", "I"); + jint jminorNum = env->GetIntField(channelObject, minorNumField); + response.channelMatch.majorNumber = static_cast(jminorNum); } exit: - return channelInfo; + + return response; } -bool ChannelManager::changeChannelByNumber(uint16_t majorNumber, uint16_t minorNumber) +bool ChannelManager::HandleChangeChannelByNumber(const uint16_t & majorNumber, const uint16_t & minorNumber) { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received ChannelManager::ChannelClusterChangeChannelByNumber majorNumber %d, minorNumber %d", majorNumber, + ChipLogProgress(Zcl, "Received ChannelManager::HandleChangeChannelByNumber majorNumber %d, minorNumber %d", majorNumber, minorNumber); VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null")); - VerifyOrExit(mchangeChannelByNumberMethod != nullptr, ChipLogError(Zcl, "mchangeChannelByNumberMethod null")); + VerifyOrExit(mChangeChannelByNumberMethod != nullptr, ChipLogError(Zcl, "mChangeChannelByNumberMethod null")); VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null")); env->ExceptionClear(); - ret = env->CallBooleanMethod(mChannelManagerObject, mchangeChannelByNumberMethod, static_cast(majorNumber), + ret = env->CallBooleanMethod(mChannelManagerObject, mChangeChannelByNumberMethod, static_cast(majorNumber), static_cast(minorNumber)); if (env->ExceptionCheck()) { @@ -417,22 +294,22 @@ bool ChannelManager::changeChannelByNumber(uint16_t majorNumber, uint16_t minorN return static_cast(ret); } -bool ChannelManager::skipChannnel(uint16_t count) +bool ChannelManager::HandleSkipChannel(const uint16_t & count) { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received ChannelManager::skipChannnel count %d", count); + ChipLogProgress(Zcl, "Received ChannelManager::HandleSkipChannel count %d", count); VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null")); - VerifyOrExit(mskipChannelMethod != nullptr, ChipLogError(Zcl, "mskipChannelMethod null")); + VerifyOrExit(mSkipChannelMethod != nullptr, ChipLogError(Zcl, "mSkipChannelMethod null")); VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null")); env->ExceptionClear(); - ret = env->CallBooleanMethod(mChannelManagerObject, mskipChannelMethod, static_cast(count)); + ret = env->CallBooleanMethod(mChannelManagerObject, mSkipChannelMethod, static_cast(count)); if (env->ExceptionCheck()) { - ChipLogError(DeviceLayer, "Java exception in ChannelManager::SkipChannel"); + ChipLogError(DeviceLayer, "Java exception in ChannelManager::HandleSkipChannel"); env->ExceptionDescribe(); env->ExceptionClear(); return false; @@ -441,3 +318,74 @@ bool ChannelManager::skipChannnel(uint16_t count) exit: return static_cast(ret); } + +void ChannelManager::InitializeWithObjects(jobject managerObject) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ChannelManager")); + + mChannelManagerObject = env->NewGlobalRef(managerObject); + VerifyOrReturn(mChannelManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef ChannelManager")); + + jclass managerClass = env->GetObjectClass(mChannelManagerObject); + VerifyOrReturn(managerClass != nullptr, ChipLogError(Zcl, "Failed to get ChannelManager Java class")); + + mGetChannelListMethod = env->GetMethodID(managerClass, "getChannelList", "()[Lcom/tcl/chip/tvapp/ChannelInfo;"); + if (mGetChannelListMethod == nullptr) + { + ChipLogError(Zcl, "Failed to access ChannelManager 'getChannelList' method"); + env->ExceptionClear(); + } + + mGetLineupMethod = env->GetMethodID(managerClass, "getLineup", "()Lcom/tcl/chip/tvapp/ChannelLineupInfo;"); + if (mGetLineupMethod == nullptr) + { + ChipLogError(Zcl, "Failed to access ChannelManager 'getLineup' method"); + env->ExceptionClear(); + } + + mGetCurrentChannelMethod = env->GetMethodID(managerClass, "getCurrentChannel", "()Lcom/tcl/chip/tvapp/ChannelInfo;"); + if (mGetCurrentChannelMethod == nullptr) + { + ChipLogError(Zcl, "Failed to access ChannelManager 'getCurrentChannel' method"); + env->ExceptionClear(); + } + + mChangeChannelMethod = env->GetMethodID(managerClass, "changeChannel", "(Ljava/lang/String;)Lcom/tcl/chip/tvapp/ChannelInfo;"); + if (mChangeChannelMethod == nullptr) + { + ChipLogError(Zcl, "Failed to access ChannelManager 'changeChannel' method"); + env->ExceptionClear(); + } + + mChangeChannelByNumberMethod = env->GetMethodID(managerClass, "changeChannelByNumber", "(II)Z"); + if (mChangeChannelByNumberMethod == nullptr) + { + ChipLogError(Zcl, "Failed to access ChannelManager 'changeChannelByNumber' method"); + env->ExceptionClear(); + } + + mSkipChannelMethod = env->GetMethodID(managerClass, "skipChannel", "(I)Z"); + if (mSkipChannelMethod == nullptr) + { + ChipLogError(Zcl, "Failed to access ChannelManager 'skipChannel' method"); + env->ExceptionClear(); + } +} + +ChannelManager ChannelManager::sInstance; + +/** @brief Channel Cluster Init + * + * This function is called when a specific cluster is initialized. It gives the + * application an opportunity to take care of cluster initialization procedures. + * It is called exactly once for each endpoint where cluster is present. + * + * @param endpoint Ver.: always + * + */ +void emberAfChannelClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Android App: Channel::SetDefaultDelegate"); + chip::app::Clusters::Channel::SetDefaultDelegate(endpoint, &channelManager); +} diff --git a/examples/tv-app/android/java/ChannelManager.h b/examples/tv-app/android/java/ChannelManager.h index a097bb17488297..0ed1659d7e51e8 100644 --- a/examples/tv-app/android/java/ChannelManager.h +++ b/examples/tv-app/android/java/ChannelManager.h @@ -17,25 +17,21 @@ #pragma once -#include -#include - +#include #include -#include -#include -#include -class ChannelManager +class ChannelManager : public chip::app::Clusters::Channel::Delegate { public: void InitializeWithObjects(jobject managerObject); - CHIP_ERROR getChannelList(chip::app::AttributeValueEncoder & aEncoder); - CHIP_ERROR getChannelLineup(chip::app::AttributeValueEncoder & aEncoder); - CHIP_ERROR getCurrentChannel(chip::app::AttributeValueEncoder & aEncoder); - ChannelInfo ChangeChannelByMatch(std::string name); - bool changeChannelByNumber(uint16_t majorNumber, uint16_t minorNumber); - bool skipChannnel(uint16_t count); + std::list HandleGetChannelList() override; + chip::app::Clusters::Channel::Structs::LineupInfo::Type HandleGetLineup() override; + chip::app::Clusters::Channel::Structs::ChannelInfo::Type HandleGetCurrentChannel() override; + + chip::app::Clusters::Channel::Commands::ChangeChannelResponse::Type HandleChangeChannel(const chip::CharSpan & match) override; + bool HandleChangeChannelByNumber(const uint16_t & majorNumber, const uint16_t & minorNumber) override; + bool HandleSkipChannel(const uint16_t & count) override; private: friend ChannelManager & ChannelMgr(); @@ -47,8 +43,8 @@ class ChannelManager jmethodID mGetCurrentChannelMethod = nullptr; jmethodID mChangeChannelMethod = nullptr; - jmethodID mchangeChannelByNumberMethod = nullptr; - jmethodID mskipChannelMethod = nullptr; + jmethodID mChangeChannelByNumberMethod = nullptr; + jmethodID mSkipChannelMethod = nullptr; }; inline class ChannelManager & ChannelMgr() diff --git a/examples/tv-app/android/java/ContentLauncherManager.cpp b/examples/tv-app/android/java/ContentLauncherManager.cpp index 57afcc4b304ef6..4298fe24c1d364 100644 --- a/examples/tv-app/android/java/ContentLauncherManager.cpp +++ b/examples/tv-app/android/java/ContentLauncherManager.cpp @@ -18,37 +18,33 @@ #include "ContentLauncherManager.h" -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include #include #include #include -#include -#include #include #include -#include using namespace std; using namespace chip; +using namespace chip::app::Clusters::ContentLauncher; ContentLauncherManager ContentLauncherManager::sInstance; -LaunchResponse ContentLauncherManager::HandleLaunchContent(chip::EndpointId endpointId, const std::list & parameterList, - bool autoplay, const chip::CharSpan & data) +namespace { +static ContentLauncherManager contentLauncherManager; +} // namespace + +void emberAfContentLauncherClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: ContentLauncher::SetDelegate"); + chip::app::Clusters::ContentLauncher::SetDelegate(endpoint, &contentLauncherManager); +} + +Commands::LaunchResponse::Type ContentLauncherManager::HandleLaunchContent(chip::EndpointId endpointId, + const std::list & parameterList, + bool autoplay, const chip::CharSpan & data) { - LaunchResponse response; + Commands::LaunchResponse::Type response; CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); @@ -90,7 +86,6 @@ LaunchResponse ContentLauncherManager::HandleLaunchContent(chip::EndpointId endp } exit: - response.err = err; if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "ContentLauncherManager::LaunchContent status error: %s", err.AsString()); @@ -99,10 +94,11 @@ LaunchResponse ContentLauncherManager::HandleLaunchContent(chip::EndpointId endp return response; } -LaunchResponse ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString, - const std::list & brandingInformation) +Commands::LaunchResponse::Type ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & contentUrl, + const chip::CharSpan & displayString, + const std::list & brandingInformation) { - LaunchResponse response; + Commands::LaunchResponse::Type response; CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); @@ -145,7 +141,6 @@ LaunchResponse ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & co } exit: - response.err = err; if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "ContentLauncherManager::LaunchUrl status error: %s", err.AsString()); @@ -245,14 +240,14 @@ void ContentLauncherManager::InitializeWithObjects(jobject managerObject) mGetAcceptHeaderMethod = env->GetMethodID(ContentLauncherClass, "getAcceptHeader", "()[Ljava/lang/String;"); if (mGetAcceptHeaderMethod == nullptr) { - ChipLogError(Zcl, "Failed to access MediaInputManager 'getInputList' method"); + ChipLogError(Zcl, "Failed to access ContentLauncherManager 'getInputList' method"); env->ExceptionClear(); } mGetSupportedStreamingProtocolsMethod = env->GetMethodID(ContentLauncherClass, "getSupportedStreamingProtocols", "()[I"); if (mGetSupportedStreamingProtocolsMethod == nullptr) { - ChipLogError(Zcl, "Failed to access MediaInputManager 'getSupportedStreamingProtocols' method"); + ChipLogError(Zcl, "Failed to access ContentLauncherManager 'getSupportedStreamingProtocols' method"); env->ExceptionClear(); } @@ -261,7 +256,7 @@ void ContentLauncherManager::InitializeWithObjects(jobject managerObject) "([Lcom/tcl/chip/tvapp/ContentLaunchSearchParameter;ZLjava/lang/String;)Lcom/tcl/chip/tvapp/LaunchResponse;"); if (mLaunchContentMethod == nullptr) { - ChipLogError(Zcl, "Failed to access MediaInputManager 'launchContent' method"); + ChipLogError(Zcl, "Failed to access ContentLauncherManager 'launchContent' method"); env->ExceptionClear(); } diff --git a/examples/tv-app/android/java/ContentLauncherManager.h b/examples/tv-app/android/java/ContentLauncherManager.h index 1e82e9234b29a1..8ef2bc0fa8287d 100644 --- a/examples/tv-app/android/java/ContentLauncherManager.h +++ b/examples/tv-app/android/java/ContentLauncherManager.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -31,10 +31,12 @@ class ContentLauncherManager : public chip::app::Clusters::ContentLauncher::Dele public: void InitializeWithObjects(jobject managerObject); - LaunchResponse HandleLaunchContent(chip::EndpointId endpointId, const std::list & parameterList, bool autoplay, - const chip::CharSpan & data) override; - LaunchResponse HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString, - const std::list & brandingInformation) override; + chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type + HandleLaunchContent(chip::EndpointId endpointId, const std::list & parameterList, bool autoplay, + const chip::CharSpan & data) override; + chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type + HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString, + const std::list & brandingInformation) override; std::list HandleGetAcceptHeaderList() override; uint32_t HandleGetSupportedStreamingProtocols() override; diff --git a/examples/tv-app/android/java/KeypadInputManager.cpp b/examples/tv-app/android/java/KeypadInputManager.cpp index 1bdc3594bb089c..40dc3a31132ad2 100644 --- a/examples/tv-app/android/java/KeypadInputManager.cpp +++ b/examples/tv-app/android/java/KeypadInputManager.cpp @@ -17,24 +17,23 @@ */ #include "KeypadInputManager.h" -#include -#include -#include + #include -#include #include using namespace chip; +using namespace chip::app::Clusters::KeypadInput; KeypadInputManager KeypadInputManager::sInstance; -chip::app::Clusters::KeypadInput::StatusEnum keypadInputClusterSendKey(chip::app::Clusters::KeypadInput::CecKeyCode keyCode) -{ - return KeypadInputMgr().SendKey(keyCode); -} +namespace { +static KeypadInputManager keypadInputManager; +} // namespace -chip::app::Clusters::KeypadInput::StatusEnum KeypadInputManager::SendKey(chip::app::Clusters::KeypadInput::CecKeyCode keyCode) +Commands::SendKeyResponse::Type KeypadInputManager::HandleSendKey(const CecKeyCode & keyCode) { + Commands::SendKeyResponse::Type response; + jint ret = -1; CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); @@ -51,10 +50,13 @@ chip::app::Clusters::KeypadInput::StatusEnum KeypadInputManager::SendKey(chip::a exit: if (err != CHIP_NO_ERROR) { - return chip::app::Clusters::KeypadInput::StatusEnum::kSuccess; + response.status = chip::app::Clusters::KeypadInput::StatusEnum::kSuccess; } - - return static_cast(ret); + else + { + response.status = static_cast(ret); + } + return response; } void KeypadInputManager::InitializeWithObjects(jobject managerObject) @@ -75,3 +77,9 @@ void KeypadInputManager::InitializeWithObjects(jobject managerObject) env->ExceptionClear(); } } + +void emberAfKeypadInputClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Android App: KeypadInput::SetDefaultDelegate"); + chip::app::Clusters::KeypadInput::SetDefaultDelegate(endpoint, &keypadInputManager); +} diff --git a/examples/tv-app/android/java/KeypadInputManager.h b/examples/tv-app/android/java/KeypadInputManager.h index fbddb56e4fc1b1..cb90df01c04e28 100644 --- a/examples/tv-app/android/java/KeypadInputManager.h +++ b/examples/tv-app/android/java/KeypadInputManager.h @@ -18,16 +18,15 @@ #pragma once -#include -#include +#include #include -#include -class KeypadInputManager +class KeypadInputManager : public chip::app::Clusters::KeypadInput::Delegate { public: void InitializeWithObjects(jobject managerObject); - chip::app::Clusters::KeypadInput::StatusEnum SendKey(chip::app::Clusters::KeypadInput::CecKeyCode keyCode); + chip::app::Clusters::KeypadInput::Commands::SendKeyResponse::Type + HandleSendKey(const chip::app::Clusters::KeypadInput::CecKeyCode & keyCode) override; private: friend KeypadInputManager & KeypadInputMgr(); diff --git a/examples/tv-app/android/java/LowPowerManager.cpp b/examples/tv-app/android/java/LowPowerManager.cpp index 52dd0b7586d5a8..741c0e6437d82e 100644 --- a/examples/tv-app/android/java/LowPowerManager.cpp +++ b/examples/tv-app/android/java/LowPowerManager.cpp @@ -24,13 +24,13 @@ #include using namespace chip; +using namespace chip::app::Clusters::LowPower; LowPowerManager LowPowerManager::sInstance; -bool lowPowerClusterSleep() -{ - return LowPowerMgr().Sleep(); -} +namespace { +static LowPowerManager lowPowerManager; +} // namespace void LowPowerManager::InitializeWithObjects(jobject managerObject) { @@ -51,7 +51,7 @@ void LowPowerManager::InitializeWithObjects(jobject managerObject) } } -bool LowPowerManager::Sleep() +bool LowPowerManager::HandleSleep() { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); @@ -74,3 +74,9 @@ bool LowPowerManager::Sleep() exit: return static_cast(ret); } + +void emberAfLowPowerClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Android App: LowPower::SetDefaultDelegate"); + chip::app::Clusters::LowPower::SetDefaultDelegate(endpoint, &lowPowerManager); +} diff --git a/examples/tv-app/android/java/LowPowerManager.h b/examples/tv-app/android/java/LowPowerManager.h index 6602136b914428..24e00fe8f2bd54 100644 --- a/examples/tv-app/android/java/LowPowerManager.h +++ b/examples/tv-app/android/java/LowPowerManager.h @@ -18,14 +18,16 @@ #pragma once +#include + #include #include -class LowPowerManager +class LowPowerManager : public chip::app::Clusters::LowPower::Delegate { public: void InitializeWithObjects(jobject managerObject); - bool Sleep(); + bool HandleSleep() override; private: friend LowPowerManager & LowPowerMgr(); diff --git a/examples/tv-app/android/java/MediaInputManager.cpp b/examples/tv-app/android/java/MediaInputManager.cpp index 6b64afa6bd4059..6ee85c2e259074 100644 --- a/examples/tv-app/android/java/MediaInputManager.cpp +++ b/examples/tv-app/android/java/MediaInputManager.cpp @@ -16,43 +16,20 @@ */ #include "MediaInputManager.h" -#include -#include -#include -#include + +#include #include -#include #include #include -#include -#include -#include using namespace chip; +using namespace chip::app::Clusters::MediaInput; MediaInputManager MediaInputManager::sInstance; -class MediaInputAttrAccess : public app::AttributeAccessInterface -{ -public: - MediaInputAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), app::Clusters::MediaInput::Id) {} - - CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override - { - if (aPath.mAttributeId == app::Clusters::MediaInput::Attributes::MediaInputList::Id) - { - return MediaInputMgr().GetInputList(aEncoder); - } - else if (aPath.mAttributeId == app::Clusters::MediaInput::Attributes::CurrentMediaInput::Id) - { - return MediaInputMgr().GetCurrentInput(aEncoder); - } - - return CHIP_NO_ERROR; - } -}; - -MediaInputAttrAccess gMediaInputAttrAccess; +namespace { +static MediaInputManager mediaInputManager; +} // namespace /** @brief Media Input Cluster Init * @@ -65,52 +42,29 @@ MediaInputAttrAccess gMediaInputAttrAccess; */ void emberAfMediaInputClusterInitCallback(EndpointId endpoint) { - static bool attrAccessRegistered = false; - if (!attrAccessRegistered) - { - registerAttributeAccessOverride(&gMediaInputAttrAccess); - attrAccessRegistered = true; - } -} - -bool mediaInputClusterSelectInput(uint8_t input) -{ - return MediaInputMgr().SelectInput(input); + ChipLogProgress(Zcl, "TV Android App: MediaInput::SetDefaultDelegate"); + chip::app::Clusters::MediaInput::SetDefaultDelegate(endpoint, &mediaInputManager); } -bool mediaInputClusterShowInputStatus() -{ - return MediaInputMgr().ShowInputStatus(); -} - -bool mediaInputClusterHideInputStatus() -{ - return MediaInputMgr().HideInputStatus(); -} - -bool mediaInputClusterRenameInput(uint8_t input, std::string name) -{ - return MediaInputMgr().RenameInput(input, name); -} - -CHIP_ERROR MediaInputManager::GetInputList(app::AttributeValueEncoder & aEncoder) +std::list MediaInputManager::HandleGetInputList() { + std::list list; CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received MediaInputManager::GetInputList"); + ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetInputList"); VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(mGetInputListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); - return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR { + { jobjectArray inputArray = (jobjectArray) env->CallObjectMethod(mMediaInputManagerObject, mGetInputListMethod); if (env->ExceptionCheck()) { - ChipLogError(AppServer, "Java exception in MediaInputManager::GetInputList"); + ChipLogError(AppServer, "Java exception in MediaInputManager::HandleGetInputList"); env->ExceptionDescribe(); env->ExceptionClear(); - return CHIP_ERROR_INCORRECT_STATE; + return list; } jint size = env->GetArrayLength(inputArray); @@ -147,62 +101,56 @@ CHIP_ERROR MediaInputManager::GetInputList(app::AttributeValueEncoder & aEncoder mediaInput.description = description.charSpan(); } - ReturnErrorOnFailure(encoder.Encode(mediaInput)); + list.push_back(mediaInput); } - - return CHIP_NO_ERROR; - }); + } exit: if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "MediaInputManager::GetInputList status error: %s", err.AsString()); + ChipLogError(Zcl, "MediaInputManager::HandleGetInputList status error: %s", err.AsString()); } - return err; + return list; } -CHIP_ERROR MediaInputManager::GetCurrentInput(chip::app::AttributeValueEncoder & aEncoder) +uint8_t MediaInputManager::HandleGetCurrentInput() { CHIP_ERROR err = CHIP_NO_ERROR; jint index = -1; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received MediaInputManager::GetInputList"); + ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetCurrentInput"); VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(mGetCurrentInputMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); - index = env->CallIntMethod(mMediaInputManagerObject, mGetCurrentInputMethod); - if (env->ExceptionCheck()) { - ChipLogError(AppServer, "Java exception in MediaInputManager::GetCurrentInput"); - env->ExceptionDescribe(); - env->ExceptionClear(); - return CHIP_ERROR_INCORRECT_STATE; - } - - ChipLogProgress(Zcl, "GetCurrentInput = %d", index); - if (index >= 0) - { - err = aEncoder.Encode(uint8_t(index)); + index = env->CallIntMethod(mMediaInputManagerObject, mGetCurrentInputMethod); + if (env->ExceptionCheck()) + { + ChipLogError(AppServer, "Java exception in MediaInputManager::HandleGetCurrentInput"); + env->ExceptionDescribe(); + env->ExceptionClear(); + err = CHIP_ERROR_INCORRECT_STATE; + } } exit: if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "MediaInputManager::GetCurrentInput status error: %s", err.AsString()); + ChipLogError(Zcl, "MediaInputManager::HandleGetCurrentInput status error: %s", err.AsString()); } - return err; + return uint8_t(index); } -bool MediaInputManager::SelectInput(uint8_t index) +bool MediaInputManager::HandleSelectInput(const uint8_t index) { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received MediaInputManager::SelectInput %d", index); + ChipLogProgress(Zcl, "Received MediaInputManager::HandleSelectInput %d", index); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); VerifyOrExit(mSelectInputMethod != nullptr, ChipLogError(Zcl, "mSelectInputMethod null")); VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null")); @@ -211,7 +159,7 @@ bool MediaInputManager::SelectInput(uint8_t index) ret = env->CallBooleanMethod(mMediaInputManagerObject, mSelectInputMethod, static_cast(index)); if (env->ExceptionCheck()) { - ChipLogError(DeviceLayer, "Java exception in MediaInputManager::selectInput"); + ChipLogError(DeviceLayer, "Java exception in MediaInputManager::HandleSelectInput"); env->ExceptionDescribe(); env->ExceptionClear(); return false; @@ -221,12 +169,12 @@ bool MediaInputManager::SelectInput(uint8_t index) return static_cast(ret); } -bool MediaInputManager::ShowInputStatus() +bool MediaInputManager::HandleShowInputStatus() { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received MediaInputManager::ShowInputStatus"); + ChipLogProgress(Zcl, "Received MediaInputManager::HandleShowInputStatus"); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); VerifyOrExit(mShowInputStatusMethod != nullptr, ChipLogError(Zcl, "mShowInputStatusMethod null")); VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null")); @@ -235,7 +183,7 @@ bool MediaInputManager::ShowInputStatus() ret = env->CallBooleanMethod(mMediaInputManagerObject, mShowInputStatusMethod); if (env->ExceptionCheck()) { - ChipLogError(DeviceLayer, "Java exception in MediaInputManager::showInputStatus"); + ChipLogError(DeviceLayer, "Java exception in MediaInputManager::HandleShowInputStatus"); env->ExceptionDescribe(); env->ExceptionClear(); return false; @@ -245,12 +193,12 @@ bool MediaInputManager::ShowInputStatus() return static_cast(ret); } -bool MediaInputManager::HideInputStatus() +bool MediaInputManager::HandleHideInputStatus() { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received MediaInputManager::HideInputStatus"); + ChipLogProgress(Zcl, "Received MediaInputManager::HandleHideInputStatus"); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); VerifyOrExit(mHideInputStatusMethod != nullptr, ChipLogError(Zcl, "mHideInputStatusMethod null")); VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null")); @@ -259,7 +207,7 @@ bool MediaInputManager::HideInputStatus() ret = env->CallBooleanMethod(mMediaInputManagerObject, mHideInputStatusMethod); if (env->ExceptionCheck()) { - ChipLogError(DeviceLayer, "Java exception in MediaInputManager::HideInputStatus"); + ChipLogError(DeviceLayer, "Java exception in MediaInputManager::HandleHideInputStatus"); env->ExceptionDescribe(); env->ExceptionClear(); return false; @@ -269,24 +217,24 @@ bool MediaInputManager::HideInputStatus() return static_cast(ret); } -bool MediaInputManager::RenameInput(uint8_t index, std::string name) +bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharSpan & name) { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received MediaInputManager::RenameInput %d to %s", index, name.c_str()); + ChipLogProgress(Zcl, "Received MediaInputManager::HandleRenameInput %d to %s", index, name.data()); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); VerifyOrExit(mRenameInputMethod != nullptr, ChipLogError(Zcl, "mHideInputStatusMethod null")); VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null")); { - UtfString jniInputname(env, name.c_str()); + UtfString jniInputname(env, name.data()); env->ExceptionClear(); ret = env->CallBooleanMethod(mMediaInputManagerObject, mRenameInputMethod, static_cast(index), jniInputname.jniValue()); if (env->ExceptionCheck()) { - ChipLogError(DeviceLayer, "Java exception in MediaInputManager::RenameInput"); + ChipLogError(DeviceLayer, "Java exception in MediaInputManager::HandleRenameInput"); env->ExceptionDescribe(); env->ExceptionClear(); return false; diff --git a/examples/tv-app/android/java/MediaInputManager.h b/examples/tv-app/android/java/MediaInputManager.h index 8a031fa0efcd57..8651e3321cecc6 100644 --- a/examples/tv-app/android/java/MediaInputManager.h +++ b/examples/tv-app/android/java/MediaInputManager.h @@ -18,20 +18,19 @@ #pragma once -#include +#include #include -#include -class MediaInputManager +class MediaInputManager : public chip::app::Clusters::MediaInput::Delegate { public: void InitializeWithObjects(jobject managerObject); - CHIP_ERROR GetInputList(chip::app::AttributeValueEncoder & aEncoder); - CHIP_ERROR GetCurrentInput(chip::app::AttributeValueEncoder & aEncoder); - bool SelectInput(uint8_t index); - bool ShowInputStatus(); - bool HideInputStatus(); - bool RenameInput(uint8_t index, std::string name); + std::list HandleGetInputList() override; + uint8_t HandleGetCurrentInput() override; + bool HandleSelectInput(const uint8_t index) override; + bool HandleShowInputStatus() override; + bool HandleHideInputStatus() override; + bool HandleRenameInput(const uint8_t index, const chip::CharSpan & name) override; private: friend MediaInputManager & MediaInputMgr(); diff --git a/examples/tv-app/android/java/MediaPlaybackManager.cpp b/examples/tv-app/android/java/MediaPlaybackManager.cpp index e11ec6f5b989f0..70aa77a1bf28c3 100644 --- a/examples/tv-app/android/java/MediaPlaybackManager.cpp +++ b/examples/tv-app/android/java/MediaPlaybackManager.cpp @@ -16,68 +16,20 @@ */ #include "MediaPlaybackManager.h" -#include -#include -#include #include -#include #include +#include + +#include "MediaPlaybackManager.h" using namespace chip; +using namespace chip::app::Clusters::MediaPlayback; MediaPlaybackManager MediaPlaybackManager::sInstance; -class MediaPlayBackAttrAccess : public app::AttributeAccessInterface -{ -public: - MediaPlayBackAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), app::Clusters::MediaPlayback::Id) {} - - CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override - { - int attrId = -1; - - switch (aPath.mAttributeId) - { - case app::Clusters::MediaPlayback::Attributes::PlaybackState::Id: { - attrId = ZCL_MEDIA_PLAYBACK_STATE_ATTRIBUTE_ID; - break; - } - case app::Clusters::MediaPlayback::Attributes::StartTime::Id: { - attrId = ZCL_MEDIA_PLAYBACK_START_TIME_ATTRIBUTE_ID; - break; - } - case app::Clusters::MediaPlayback::Attributes::Duration::Id: { - attrId = ZCL_MEDIA_PLAYBACK_DURATION_ATTRIBUTE_ID; - break; - } - case app::Clusters::MediaPlayback::Attributes::Position::Id: { - attrId = ZCL_MEDIA_PLAYBACK_PLAYBACK_POSITION_ATTRIBUTE_ID; - break; - } - case app::Clusters::MediaPlayback::Attributes::PlaybackSpeed::Id: { - attrId = ZCL_MEDIA_PLAYBACK_PLAYBACK_SPEED_ATTRIBUTE_ID; - break; - } - case app::Clusters::MediaPlayback::Attributes::SeekRangeEnd::Id: { - attrId = ZCL_MEDIA_PLAYBACK_PLAYBACK_SEEK_RANGE_END_ATTRIBUTE_ID; - break; - } - case app::Clusters::MediaPlayback::Attributes::SeekRangeStart::Id: { - attrId = ZCL_MEDIA_PLAYBACK_PLAYBACK_SEEK_RANGE_START_ATTRIBUTE_ID; - break; - } - } - - if (attrId >= 0) - { - return MediaPlaybackMgr().GetAttribute(aEncoder, attrId); - } - - return CHIP_NO_ERROR; - } -}; - -MediaPlayBackAttrAccess gMediaPlayBackAttrAccess; +namespace { +static MediaPlaybackManager mediaPlaybackManager; +} // namespace /** @brief Media PlayBack Cluster Init * @@ -88,101 +40,110 @@ MediaPlayBackAttrAccess gMediaPlayBackAttrAccess; * @param endpoint Ver.: always * */ -void emberAfMediaPlaybackClusterInitCallback(EndpointId endpoint) +void emberAfMediaPlaybackClusterInitCallback(chip::EndpointId endpoint) { - static bool attrAccessRegistered = false; - if (!attrAccessRegistered) - { - registerAttributeAccessOverride(&gMediaPlayBackAttrAccess); - attrAccessRegistered = true; - } + ChipLogProgress(Zcl, "TV Android App: MediaPlayback::SetDefaultDelegate"); + chip::app::Clusters::MediaPlayback::SetDefaultDelegate(endpoint, &mediaPlaybackManager); } -chip::app::Clusters::MediaPlayback::StatusEnum -mediaPlaybackClusterSendMediaPlaybackRequest(MediaPlaybackRequest mediaPlaybackRequest, uint64_t deltaPositionMilliseconds) +PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState() { - return MediaPlaybackMgr().Request(mediaPlaybackRequest, deltaPositionMilliseconds); + return PlaybackStateEnum::kPlaying; } -void MediaPlaybackManager::InitializeWithObjects(jobject managerObject) +uint64_t MediaPlaybackManager::HandleGetStartTime() { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for MediaPlaybackManager")); + return 0; +} - mMediaPlaybackManagerObject = env->NewGlobalRef(managerObject); - VerifyOrReturn(mMediaPlaybackManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef MediaPlaybackManager")); +uint64_t MediaPlaybackManager::HandleGetDuration() +{ + return 0; +} - jclass mMediaPlaybackManagerClass = env->GetObjectClass(managerObject); - VerifyOrReturn(mMediaPlaybackManagerClass != nullptr, ChipLogError(Zcl, "Failed to get MediaPlaybackManager Java class")); +Structs::PlaybackPosition::Type MediaPlaybackManager::HandleGetSampledPosition() +{ + Structs::PlaybackPosition::Type sampledPosition; + sampledPosition.updatedAt = 0; + sampledPosition.position = 0; + return sampledPosition; +} - mGetAttributeMethod = env->GetMethodID(mMediaPlaybackManagerClass, "getAttributes", "(I)J"); - if (mGetAttributeMethod == nullptr) - { - ChipLogError(Zcl, "Failed to access MediaPlaybackManager 'getMediaPlaybackAttribute' method"); - env->ExceptionClear(); - } +float MediaPlaybackManager::HandleGetPlaybackSpeed() +{ + return 0; +} - mRequestMethod = env->GetMethodID(mMediaPlaybackManagerClass, "request", "(IJ)I"); - if (mRequestMethod == nullptr) - { - ChipLogError(Zcl, "Failed to access MediaPlaybackManager 'proxyMediaPlaybackRequest' method"); - env->ExceptionClear(); - } +uint64_t MediaPlaybackManager::HandleGetSeekRangeStart() +{ + return 0; } -CHIP_ERROR MediaPlaybackManager::GetAttribute(chip::app::AttributeValueEncoder & aEncoder, int attributeId) +uint64_t MediaPlaybackManager::HandleGetSeekRangeEnd() { - jlong jAttributeValue = -1; - CHIP_ERROR err = CHIP_NO_ERROR; - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + return 0; +} - ChipLogProgress(Zcl, "Received MediaPlaybackManager::GetAttribute:%d", attributeId); - VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(mGetAttributeMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); +Commands::PlaybackResponse::Type MediaPlaybackManager::HandlePlay() +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_PLAY, 0); +} - jAttributeValue = env->CallLongMethod(mMediaPlaybackManagerObject, mGetAttributeMethod, static_cast(attributeId)); - if (env->ExceptionCheck()) - { - ChipLogError(AppServer, "Java exception in MediaPlaybackManager::GetAttribute"); - env->ExceptionDescribe(); - env->ExceptionClear(); - return CHIP_ERROR_INCORRECT_STATE; - } +Commands::PlaybackResponse::Type MediaPlaybackManager::HandlePause() +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_PAUSE, 0); +} - if (jAttributeValue >= 0) - { - switch (attributeId) - { - case ZCL_MEDIA_PLAYBACK_PLAYBACK_SPEED_ATTRIBUTE_ID: { - // TODO: Convert to single once it is supported - // float speed = static_cast(jAttributeValue) / 10000.0f; - err = aEncoder.Encode(static_cast(jAttributeValue)); - break; - } - - default: { - err = aEncoder.Encode(static_cast(jAttributeValue)); - } - } - } - else - { - err = CHIP_ERROR_INCORRECT_STATE; - } +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleStop() +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_STOP, 0); +} -exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "MediaPlaybackManager::GetAttribute status error: %s", err.AsString()); - } +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleFastForward() +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_FAST_FORWARD, 0); +} - return err; +Commands::PlaybackResponse::Type MediaPlaybackManager::HandlePrevious() +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_PREVIOUS, 0); +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleRewind() +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_REWIND, 0); +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleSkipBackward(const uint64_t & deltaPositionMilliseconds) +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_SKIP_BACKWARD, deltaPositionMilliseconds); } -chip::app::Clusters::MediaPlayback::StatusEnum MediaPlaybackManager::Request(MediaPlaybackRequest mediaPlaybackRequest, - uint64_t deltaPositionMilliseconds) +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleSkipForward(const uint64_t & deltaPositionMilliseconds) { + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_SKIP_FORWARD, deltaPositionMilliseconds); +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleSeekRequest(const uint64_t & positionMilliseconds) +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_SEEK, positionMilliseconds); +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleNext() +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_NEXT, 0); +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleStartOverRequest() +{ + return MediaPlaybackMgr().HandleMediaRequest(MEDIA_PLAYBACK_REQUEST_START_OVER, 0); +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleMediaRequest(MediaPlaybackRequest mediaPlaybackRequest, + uint64_t deltaPositionMilliseconds) +{ + Commands::PlaybackResponse::Type response; + jint ret = -1; CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); @@ -198,17 +159,43 @@ chip::app::Clusters::MediaPlayback::StatusEnum MediaPlaybackManager::Request(Med static_cast(deltaPositionMilliseconds)); if (env->ExceptionCheck()) { - ChipLogError(AppServer, "Java exception in MediaPlaybackManager::GetAttribute"); + ChipLogError(AppServer, "Java exception in MediaPlaybackManager::Request %d", mediaPlaybackRequest); env->ExceptionDescribe(); env->ExceptionClear(); - return chip::app::Clusters::MediaPlayback::StatusEnum::kInvalidStateForCommand; + response.status = StatusEnum::kInvalidStateForCommand; } exit: if (err != CHIP_NO_ERROR) { - return chip::app::Clusters::MediaPlayback::StatusEnum::kInvalidStateForCommand; + response.status = StatusEnum::kInvalidStateForCommand; } - return static_cast(ret); + return response; +} + +void MediaPlaybackManager::InitializeWithObjects(jobject managerObject) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for MediaPlaybackManager")); + + mMediaPlaybackManagerObject = env->NewGlobalRef(managerObject); + VerifyOrReturn(mMediaPlaybackManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef MediaPlaybackManager")); + + jclass mMediaPlaybackManagerClass = env->GetObjectClass(managerObject); + VerifyOrReturn(mMediaPlaybackManagerClass != nullptr, ChipLogError(Zcl, "Failed to get MediaPlaybackManager Java class")); + + mGetAttributeMethod = env->GetMethodID(mMediaPlaybackManagerClass, "getAttributes", "(I)J"); + if (mGetAttributeMethod == nullptr) + { + ChipLogError(Zcl, "Failed to access MediaPlaybackManager 'getMediaPlaybackAttribute' method"); + env->ExceptionClear(); + } + + mRequestMethod = env->GetMethodID(mMediaPlaybackManagerClass, "request", "(IJ)I"); + if (mRequestMethod == nullptr) + { + ChipLogError(Zcl, "Failed to access MediaPlaybackManager 'proxyMediaPlaybackRequest' method"); + env->ExceptionClear(); + } } diff --git a/examples/tv-app/android/java/MediaPlaybackManager.h b/examples/tv-app/android/java/MediaPlaybackManager.h index 48b3b957109986..12aaeab077bfa0 100644 --- a/examples/tv-app/android/java/MediaPlaybackManager.h +++ b/examples/tv-app/android/java/MediaPlaybackManager.h @@ -18,20 +18,52 @@ #pragma once -#include #include -#include -#include #include -#include -class MediaPlaybackManager +enum MediaPlaybackRequest : uint8_t +{ + MEDIA_PLAYBACK_REQUEST_PLAY = 0, + MEDIA_PLAYBACK_REQUEST_PAUSE = 1, + MEDIA_PLAYBACK_REQUEST_STOP = 2, + MEDIA_PLAYBACK_REQUEST_START_OVER = 3, + MEDIA_PLAYBACK_REQUEST_PREVIOUS = 4, + MEDIA_PLAYBACK_REQUEST_NEXT = 5, + MEDIA_PLAYBACK_REQUEST_REWIND = 6, + MEDIA_PLAYBACK_REQUEST_FAST_FORWARD = 7, + MEDIA_PLAYBACK_REQUEST_SKIP_FORWARD = 8, + MEDIA_PLAYBACK_REQUEST_SKIP_BACKWARD = 9, + MEDIA_PLAYBACK_REQUEST_SEEK = 10, +}; + +class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate { public: void InitializeWithObjects(jobject managerObject); - CHIP_ERROR GetAttribute(chip::app::AttributeValueEncoder & aEncoder, int attributeId); - chip::app::Clusters::MediaPlayback::StatusEnum Request(MediaPlaybackRequest mediaPlaybackRequest, - uint64_t deltaPositionMilliseconds); + chip::app::Clusters::MediaPlayback::PlaybackStateEnum HandleGetCurrentState() override; + uint64_t HandleGetStartTime() override; + uint64_t HandleGetDuration() override; + chip::app::Clusters::MediaPlayback::Structs::PlaybackPosition::Type HandleGetSampledPosition() override; + float HandleGetPlaybackSpeed() override; + uint64_t HandleGetSeekRangeStart() override; + uint64_t HandleGetSeekRangeEnd() override; + + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandlePlay() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandlePause() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleStop() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleFastForward() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandlePrevious() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleRewind() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type + HandleSkipBackward(const uint64_t & deltaPositionMilliseconds) override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type + HandleSkipForward(const uint64_t & deltaPositionMilliseconds) override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type + HandleSeekRequest(const uint64_t & positionMilliseconds) override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleNext() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleStartOverRequest() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type + HandleMediaRequest(MediaPlaybackRequest mediaPlaybackRequest, uint64_t deltaPositionMilliseconds); private: friend MediaPlaybackManager & MediaPlaybackMgr(); diff --git a/examples/tv-app/android/java/WakeOnLanManager.cpp b/examples/tv-app/android/java/WakeOnLanManager.cpp index 60b59c957b134d..8c9c7f26bbace1 100644 --- a/examples/tv-app/android/java/WakeOnLanManager.cpp +++ b/examples/tv-app/android/java/WakeOnLanManager.cpp @@ -18,26 +18,19 @@ #include "WakeOnLanManager.h" -#include -#include -#include -#include -#include -#include -#include - -#include - #include -#include #include #include using namespace chip; -using namespace chip::app::Clusters; +using namespace chip::app::Clusters::WakeOnLan; WakeOnLanManager WakeOnLanManager::sInstance; +namespace { +static WakeOnLanManager wakeOnLanManager; +} // namespace + /** @brief Wake On LAN Cluster Init * * This function is called when a specific cluster is initialized. It gives the @@ -49,39 +42,43 @@ WakeOnLanManager WakeOnLanManager::sInstance; */ void emberAfWakeOnLanClusterInitCallback(chip::EndpointId endpoint) { - WakeOnLanMgr().InitWakeOnLanCluster(endpoint); + ChipLogProgress(Zcl, "TV Android App: WakeOnLan::SetDefaultDelegate"); + chip::app::Clusters::WakeOnLan::SetDefaultDelegate(endpoint, &wakeOnLanManager); } -void WakeOnLanManager::InitWakeOnLanCluster(chip::EndpointId endpoint) +chip::CharSpan WakeOnLanManager::HandleGetMacAddress() { - JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - ChipLogProgress(Zcl, "Received WakeOnLanManager::InitWakeOnLanCluster %d", endpoint); - VerifyOrReturn(mWakeOnLanManagerObject != nullptr, ChipLogError(Zcl, "mWakeOnLanManagerObject null")); - VerifyOrReturn(mGetMacMethod != nullptr, ChipLogError(Zcl, "mGetMacMethod null")); - VerifyOrReturn(env != NULL, ChipLogError(Zcl, "env null")); + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + chip::CharSpan macValue; + + ChipLogProgress(Zcl, "Received WakeOnLanManager::HandleGetMacAddress"); + VerifyOrExit(mWakeOnLanManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrExit(mGetMacMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); + VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV); - env->ExceptionClear(); - jobject javaMac = env->CallObjectMethod(mWakeOnLanManagerObject, mGetMacMethod, static_cast(endpoint)); - if (env->ExceptionCheck()) { - ChipLogError(DeviceLayer, "Java exception in WakeOnLanManager::getMac"); - env->ExceptionDescribe(); env->ExceptionClear(); - return; + jobject javaMac = env->CallObjectMethod(mWakeOnLanManagerObject, mGetMacMethod, static_cast(1)); + if (env->ExceptionCheck()) + { + ChipLogError(DeviceLayer, "Java exception in WakeOnLanManager::getMac"); + env->ExceptionDescribe(); + env->ExceptionClear(); + return macValue; + } + + macValue = chip::JniUtfString(env, static_cast(javaMac)).charSpan(); } - chip::JniUtfString macValue(env, static_cast(javaMac)); - - uint8_t bufferMemory[32]; - MutableByteSpan zclString(bufferMemory); - MakeZclCharString(zclString, macValue.c_str()); - EmberAfStatus macAddressStatus = emberAfWriteServerAttribute( - endpoint, WakeOnLan::Id, WakeOnLan::Attributes::WakeOnLanMacAddress::Id, zclString.data(), ZCL_CHAR_STRING_ATTRIBUTE_TYPE); - if (macAddressStatus != EMBER_ZCL_STATUS_SUCCESS) +exit: + if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "Failed to store mac address attribute."); + ChipLogError(Zcl, "WakeOnLanManager::HandleGetMacAddress status error: %s", err.AsString()); } + + return macValue; } void WakeOnLanManager::InitializeWithObjects(jobject managerObject) diff --git a/examples/tv-app/android/java/WakeOnLanManager.h b/examples/tv-app/android/java/WakeOnLanManager.h index da622a8f54e873..69327737a45335 100644 --- a/examples/tv-app/android/java/WakeOnLanManager.h +++ b/examples/tv-app/android/java/WakeOnLanManager.h @@ -18,15 +18,14 @@ #pragma once -#include +#include #include -#include -class WakeOnLanManager +class WakeOnLanManager : public chip::app::Clusters::WakeOnLan::Delegate { public: void InitializeWithObjects(jobject managerObject); - void InitWakeOnLanCluster(chip::EndpointId endpoint); + chip::CharSpan HandleGetMacAddress() override; private: friend WakeOnLanManager & WakeOnLanMgr(); diff --git a/examples/tv-app/linux/AppImpl.cpp b/examples/tv-app/linux/AppImpl.cpp index 74a3cf8b0e1c6e..dd2d2569ef641e 100644 --- a/examples/tv-app/linux/AppImpl.cpp +++ b/examples/tv-app/linux/AppImpl.cpp @@ -190,7 +190,8 @@ uint32_t AccountLoginImpl::GetSetupPIN(const char * tempAccountId) return mSetupPIN; } -ApplicationLauncherResponse ApplicationLauncherImpl::LaunchApp(Application application, std::string data) +chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type +ApplicationLauncherImpl::LaunchApp(Application application, std::string data) { std::string appId(application.applicationId.data(), application.applicationId.size()); ChipLogProgress(DeviceLayer, @@ -198,21 +199,20 @@ ApplicationLauncherResponse ApplicationLauncherImpl::LaunchApp(Application appli "application.applicationId=%s data=%s", application.catalogVendorId, appId.c_str(), data.c_str()); - ApplicationLauncherResponse response; - const char * testData = "data"; - response.data = (uint8_t *) testData; - response.status = to_underlying(chip::app::Clusters::ApplicationLauncher::StatusEnum::kSuccess); + chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type response; + response.data = chip::CharSpan("data", strlen("data")); + response.status = chip::app::Clusters::ApplicationLauncher::StatusEnum::kSuccess; return response; } -LaunchResponse ContentLauncherImpl::LaunchContent(std::list parameterList, bool autoplay, std::string data) +chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type +ContentLauncherImpl::LaunchContent(std::list parameterList, bool autoplay, std::string data) { ChipLogProgress(DeviceLayer, "ContentLauncherImpl: LaunchContent autoplay=%d data=\"%s\"", autoplay ? 1 : 0, data.c_str()); - LaunchResponse response; - response.err = CHIP_NO_ERROR; - response.data = "Example app data"; + chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type response; + response.data = chip::CharSpan("data", strlen("data")); response.status = chip::app::Clusters::ContentLauncher::StatusEnum::kSuccess; return response; } diff --git a/examples/tv-app/linux/AppImpl.h b/examples/tv-app/linux/AppImpl.h index c188b0b37bcccd..4512c514156409 100644 --- a/examples/tv-app/linux/AppImpl.h +++ b/examples/tv-app/linux/AppImpl.h @@ -98,7 +98,8 @@ class DLL_EXPORT ApplicationLauncherImpl : public ApplicationLauncher public: virtual ~ApplicationLauncherImpl() {} - ApplicationLauncherResponse LaunchApp(Application application, std::string data) override; + chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type LaunchApp(Application application, + std::string data) override; protected: }; @@ -108,7 +109,8 @@ class DLL_EXPORT ContentLauncherImpl : public ContentLauncher public: virtual ~ContentLauncherImpl() {} - LaunchResponse LaunchContent(std::list parameterList, bool autoplay, std::string data) override; + chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type LaunchContent(std::list parameterList, + bool autoplay, std::string data) override; protected: }; diff --git a/examples/tv-app/linux/include/account-login/AccountLoginManager.cpp b/examples/tv-app/linux/include/account-login/AccountLoginManager.cpp index ed816f72f3648d..f391901e136e32 100644 --- a/examples/tv-app/linux/include/account-login/AccountLoginManager.cpp +++ b/examples/tv-app/linux/include/account-login/AccountLoginManager.cpp @@ -17,75 +17,35 @@ */ #include "AccountLoginManager.h" -#include -#include -#include -#include -#include #include #include using namespace std; +using namespace chip::app::Clusters::AccountLogin; -bool AccountLoginManager::isUserLoggedIn(string requestTempAccountIdentifier, string requestSetupPin) +bool AccountLoginManager::HandleLogin(const chip::CharSpan & tempAccountIdentifier, const chip::CharSpan & setupPin) { - // TODO: Fix hardcoding length of strings - requestTempAccountIdentifier = requestTempAccountIdentifier.substr(0, 4); - requestSetupPin = requestSetupPin.substr(0, 10); - for (auto it = accounts.cbegin(); it != accounts.cend(); ++it) - { - ChipLogProgress(Zcl, "temporary account id: %s", it->first.c_str()); - ChipLogProgress(Zcl, "setup pin %s", it->second.c_str()); - } + string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); + string setupPinString(setupPin.data(), setupPin.size()); + ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str()); + ChipLogProgress(Zcl, "setup pin %s", setupPinString.c_str()); - if (accounts.find(requestTempAccountIdentifier) != accounts.end()) - { - bool found = accounts[requestTempAccountIdentifier] == requestSetupPin; - if (!found) - { - ChipLogError(Zcl, "User is not logged in, failed to match request setup pin."); - } - return found; - } - else - { - ChipLogError(Zcl, "User is not logged in, failed to find temp account identifier."); - return false; - } -} - -void AccountLoginManager::setTempAccountIdentifierForPin(string tempAccountIdentifier, string setupPin) -{ - // TODO: Fix hardcoding length of strings - string tempId = tempAccountIdentifier.substr(0, 4); - accounts[tempId] = setupPin; -} - -string AccountLoginManager::proxySetupPinRequest(string requestTempAccountIdentifier, chip::EndpointId endpoint) -{ - // TODO: Insert your code here to send temp account identifier request - return "tempPin123"; + // TODO: Insert your code here to handle login request + return true; } -bool AccountLoginManager::proxyLogout() +bool AccountLoginManager::HandleLogout() { // TODO: Insert your code here to send logout request return true; } -bool accountLoginClusterIsUserLoggedIn(std::string requestTempAccountIdentifier, std::string requestSetupPin) -{ - return AccountLoginManager().GetInstance().isUserLoggedIn(requestTempAccountIdentifier, requestSetupPin); -} - -bool accountLoginClusterLogout() -{ - return AccountLoginManager().GetInstance().proxyLogout(); -} - -std::string accountLoginClusterGetSetupPin(std::string requestTempAccountIdentifier, chip::EndpointId endpoint) +Commands::GetSetupPINResponse::Type AccountLoginManager::HandleGetSetupPin(const chip::CharSpan & tempAccountIdentifier) { - string responseSetupPin = AccountLoginManager().proxySetupPinRequest(requestTempAccountIdentifier, endpoint); - AccountLoginManager().GetInstance().setTempAccountIdentifierForPin(requestTempAccountIdentifier, responseSetupPin); - return responseSetupPin; + string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); + ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str()); + // TODO: Insert your code here to handle get setup pin + Commands::GetSetupPINResponse::Type response; + response.setupPIN = chip::CharSpan("tempPin123", strlen("tempPin123")); + return response; } diff --git a/examples/tv-app/linux/include/account-login/AccountLoginManager.h b/examples/tv-app/linux/include/account-login/AccountLoginManager.h index 7377d95b18e0bf..68584ae6ec7bd5 100644 --- a/examples/tv-app/linux/include/account-login/AccountLoginManager.h +++ b/examples/tv-app/linux/include/account-login/AccountLoginManager.h @@ -18,25 +18,15 @@ #pragma once +#include + #include -#include -#include -#include -class AccountLoginManager +class AccountLoginManager : public chip::app::Clusters::AccountLogin::Delegate { public: - bool isUserLoggedIn(std::string requestTempAccountIdentifier, std::string requestSetupPin); - bool proxyLogout(); - std::string proxySetupPinRequest(std::string requestTempAccountIdentifier, chip::EndpointId endpoint); - void setTempAccountIdentifierForPin(std::string requestTempAccountIdentifier, std::string requestSetupPin); - - static AccountLoginManager & GetInstance() - { - static AccountLoginManager instance; - return instance; - } - -private: - std::map accounts; + bool HandleLogin(const chip::CharSpan & tempAccountIdentifierString, const chip::CharSpan & setupPinString) override; + bool HandleLogout() override; + chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::Type + HandleGetSetupPin(const chip::CharSpan & tempAccountIdentifierString) override; }; diff --git a/examples/tv-app/linux/include/application-basic/ApplicationBasicManager.cpp b/examples/tv-app/linux/include/application-basic/ApplicationBasicManager.cpp index 29555ac7290a9e..1a979da92efcc7 100644 --- a/examples/tv-app/linux/include/application-basic/ApplicationBasicManager.cpp +++ b/examples/tv-app/linux/include/application-basic/ApplicationBasicManager.cpp @@ -17,139 +17,49 @@ */ #include "ApplicationBasicManager.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +using namespace std; +using namespace chip::app::Clusters::ApplicationBasic; -using namespace chip; -using namespace chip::AppPlatform; - -CHIP_ERROR ApplicationBasicManager::Init() +chip::CharSpan ApplicationBasicManager::HandleGetVendorName() { - CHIP_ERROR err = CHIP_NO_ERROR; - EndpointConfigurationStorage & endpointConfiguration = EndpointConfigurationStorage::GetInstance(); - err = endpointConfiguration.Init(); - SuccessOrExit(err); - es = &endpointConfiguration; -exit: - return err; + return chip::CharSpan("exampleVendorName1", strlen("exampleVendorName1")); } -void ApplicationBasicManager::store(chip::EndpointId endpoint, chip::app::Clusters::ApplicationBasic::Application * application) +uint16_t ApplicationBasicManager::HandleGetVendorId() { - uint8_t bufferMemory[64]; - MutableByteSpan zclString(bufferMemory); - - MakeZclCharString(zclString, application->vendorName); - EmberAfStatus vendorNameStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_VENDOR_NAME_ATTRIBUTE_ID, - zclString.data(), ZCL_CHAR_STRING_ATTRIBUTE_TYPE); - if (vendorNameStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store vendor name attribute."); - } - - EmberAfStatus vendorIdStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_VENDOR_ID_ATTRIBUTE_ID, - (uint8_t *) &application->vendorId, ZCL_INT16U_ATTRIBUTE_TYPE); - if (vendorIdStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store vendor id attribute."); - } - - MakeZclCharString(zclString, application->name); - EmberAfStatus nameStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_NAME_ATTRIBUTE_ID, zclString.data(), - ZCL_CHAR_STRING_ATTRIBUTE_TYPE); - if (nameStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store name attribute."); - } - - MakeZclCharString(zclString, application->version); - EmberAfStatus versionStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_VERSION_ATTRIBUTE_ID, - zclString.data(), ZCL_CHAR_STRING_ATTRIBUTE_TYPE); - if (versionStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store version attribute."); - } - - EmberAfStatus productIdStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_PRODUCT_ID_ATTRIBUTE_ID, - (uint8_t *) &application->productId, ZCL_INT16U_ATTRIBUTE_TYPE); - if (productIdStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store product id attribute."); - } - - EmberAfStatus applicationStatus = - emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_BASIC_CLUSTER_ID, ZCL_APPLICATION_STATUS_ATTRIBUTE_ID, - (uint8_t *) &application->status, ZCL_ENUM8_ATTRIBUTE_TYPE); - if (applicationStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store status attribute."); - } + return 1; } -chip::app::Clusters::ApplicationBasic::Application ApplicationBasicManager::getApplicationForEndpoint(chip::EndpointId endpoint) +chip::CharSpan ApplicationBasicManager::HandleGetApplicationName() { - chip::app::Clusters::ApplicationBasic::Application app = {}; - uint16_t size = static_cast(sizeof(app.name)); - - std::string section = "endpoint" + std::to_string(endpoint); - - CHIP_ERROR err = es->get(section, "name", app.name, size); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app name. Error:%s", chip::ErrorStr(err)); - } - - err = es->get(section, "vendorName", app.vendorName, size); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app vendor name. Error:%s", chip::ErrorStr(err)); - } - - err = es->get(section, "version", app.version, size); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get application version. Error:%s", chip::ErrorStr(err)); - } + return chip::CharSpan("exampleName1", strlen("exampleName1")); +} - err = es->get(section, "id", app.id, size); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app id. Error:%s", chip::ErrorStr(err)); - } +uint16_t ApplicationBasicManager::HandleGetProductId() +{ + return 1; +} - err = es->get(section, "catalogVendorId", app.catalogVendorId); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app catalog vendor id. Error:%s", chip::ErrorStr(err)); - } +chip::app::Clusters::ApplicationBasic::Structs::Application::Type ApplicationBasicManager::HandleGetApplication() +{ + chip::app::Clusters::ApplicationBasic::Structs::Application::Type application; + application.catalogVendorId = 123; + application.applicationId = chip::CharSpan("applicationId", strlen("applicationId")); + return application; +} - err = es->get(section, "productId", app.productId); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app product id. Error:%s", chip::ErrorStr(err)); - } +ApplicationStatusEnum ApplicationBasicManager::HandleGetStatus() +{ + return ApplicationStatusEnum::kStopped; +} - err = es->get(section, "vendorId", app.vendorId); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get app vendor id. Error:%s", chip::ErrorStr(err)); - } +chip::CharSpan ApplicationBasicManager::HandleGetApplicationVersion() +{ + return chip::CharSpan("exampleVersion", strlen("exampleVersion")); +} - return app; +std::list ApplicationBasicManager::HandleGetAllowedVendorList() +{ + return { 123, 456 }; } diff --git a/examples/tv-app/linux/include/application-basic/ApplicationBasicManager.h b/examples/tv-app/linux/include/application-basic/ApplicationBasicManager.h index 3395247400d6ef..e907fc8891861e 100644 --- a/examples/tv-app/linux/include/application-basic/ApplicationBasicManager.h +++ b/examples/tv-app/linux/include/application-basic/ApplicationBasicManager.h @@ -18,26 +18,17 @@ #pragma once -#include -#include +#include -#include "../endpoint-configuration/EndpointConfigurationStorage.h" -#include "Application.h" -#include - -class ApplicationBasicManager +class ApplicationBasicManager : public chip::app::Clusters::ApplicationBasic::Delegate { public: - CHIP_ERROR Init(); - void store(chip::EndpointId endpoint, chip::app::Clusters::ApplicationBasic::Application * application); - chip::app::Clusters::ApplicationBasic::Application getApplicationForEndpoint(chip::EndpointId endpoint); - - static ApplicationBasicManager & GetInstance() - { - static ApplicationBasicManager instance; - return instance; - } - -private: - EndpointConfigurationStorage * es = nullptr; + chip::CharSpan HandleGetVendorName() override; + uint16_t HandleGetVendorId() override; + chip::CharSpan HandleGetApplicationName() override; + uint16_t HandleGetProductId() override; + chip::app::Clusters::ApplicationBasic::Structs::Application::Type HandleGetApplication() override; + chip::app::Clusters::ApplicationBasic::ApplicationStatusEnum HandleGetStatus() override; + chip::CharSpan HandleGetApplicationVersion() override; + std::list HandleGetAllowedVendorList() override; }; diff --git a/examples/tv-app/linux/include/application-launcher/ApplicationLauncherManager.cpp b/examples/tv-app/linux/include/application-launcher/ApplicationLauncherManager.cpp index 6b7d24e7d9adb3..f6a8afc0ae8ee7 100644 --- a/examples/tv-app/linux/include/application-launcher/ApplicationLauncherManager.cpp +++ b/examples/tv-app/linux/include/application-launcher/ApplicationLauncherManager.cpp @@ -17,89 +17,50 @@ */ #include "ApplicationLauncherManager.h" -#include -#include -#include -#include -#include -#include using namespace std; -using namespace chip::AppPlatform; +using namespace chip::app::Clusters::ApplicationLauncher; -CHIP_ERROR ApplicationLauncherManager::Init() +Structs::ApplicationEP::Type ApplicationLauncherManager::HandleGetCurrentApp() { - CHIP_ERROR err = CHIP_NO_ERROR; - - SuccessOrExit(err); -exit: - return err; + Structs::ApplicationEP::Type currentApp; + currentApp.application.catalogVendorId = 123; + currentApp.application.applicationId = chip::CharSpan("applicationId", strlen("applicationId")); + currentApp.endpoint = chip::CharSpan("endpointId", strlen("endpointId")); + return currentApp; } -CHIP_ERROR ApplicationLauncherManager::proxyGetApplicationList(chip::EndpointId mEndpointId, - chip::app::AttributeValueEncoder & aEncoder) +std::list ApplicationLauncherManager::HandleGetCatalogList() { - ChipLogProgress(Zcl, "ApplicationLauncherManager::proxyGetApplicationList endpoint=%d", mEndpointId); - return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { - ReturnErrorOnFailure(encoder.Encode(123u)); - ReturnErrorOnFailure(encoder.Encode(456u)); - return CHIP_NO_ERROR; - }); + return { 123, 456 }; } -ApplicationLauncherResponse applicationLauncherClusterLaunchApp(chip::EndpointId endpoint, Application application, - std::string data) +Commands::LauncherResponse::Type ApplicationLauncherManager::HandleLaunchApp( + const chip::CharSpan & data, const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) { - ChipLogProgress(Zcl, "ApplicationLauncherManager::applicationLauncherClusterLaunchApp endpoint=%d", emberAfCurrentEndpoint()); - -#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - ContentApp * app = chip::AppPlatform::AppPlatform::GetInstance().GetContentAppByEndpointId(endpoint); - if (app != NULL) - { - return app->GetApplicationLauncher()->LaunchApp(application, data); - } - - app = chip::AppPlatform::AppPlatform::GetInstance().GetLoadContentAppByAppId(application); - if (app != NULL) - { - return app->GetApplicationLauncher()->LaunchApp(application, data); - } -#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - - ChipLogProgress(Zcl, "ApplicationLauncherManager::applicationLauncherClusterLaunchApp app not found"); - - // TODO: Insert your code - ApplicationLauncherResponse response; - const char * testData = "data"; - response.data = (uint8_t *) testData; - // must return success for tests to pass - // response.status = EMBER_ZCL_APPLICATION_LAUNCHER_STATUS_APP_NOT_AVAILABLE; - response.status = chip::to_underlying(chip::app::Clusters::ApplicationLauncher::StatusEnum::kSuccess); - // TODO: Update once storing a structure attribute is supported - // emberAfWriteServerAttribute(endpoint, ZCL_APPLICATION_LAUNCH_CLUSTER_ID, ZCL_APPLICATION_LAUNCHER_CURRENT_APP_APPLICATION_ID, - // (uint8_t *) &application, ZCL_STRUCT_ATTRIBUTE_TYPE); - + // TODO: Insert code here + Commands::LauncherResponse::Type response; + response.data = chip::CharSpan("data", strlen("data")); + response.status = StatusEnum::kSuccess; return response; } -ApplicationLauncherResponse applicationLauncherClusterStopApp(chip::EndpointId endpoint, Application application, std::string data) +Commands::LauncherResponse::Type +ApplicationLauncherManager::HandleStopApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) { - ChipLogProgress(Zcl, "ApplicationLauncherManager::applicationLauncherClusterStopApp"); - - ApplicationLauncherResponse response; - const char * testData = "data"; - response.data = (uint8_t *) testData; - response.status = chip::to_underlying(chip::app::Clusters::ApplicationLauncher::StatusEnum::kSuccess); + // TODO: Insert code here + Commands::LauncherResponse::Type response; + response.data = chip::CharSpan("data", strlen("data")); + response.status = StatusEnum::kSuccess; return response; } -ApplicationLauncherResponse applicationLauncherClusterHideApp(chip::EndpointId endpoint, Application application, std::string data) +Commands::LauncherResponse::Type +ApplicationLauncherManager::HandleHideApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) { - ChipLogProgress(Zcl, "ApplicationLauncherManager::applicationLauncherClusterHideApp"); - - ApplicationLauncherResponse response; - const char * testData = "data"; - response.data = (uint8_t *) testData; - response.status = chip::to_underlying(chip::app::Clusters::ApplicationLauncher::StatusEnum::kSuccess); + // TODO: Insert code here + Commands::LauncherResponse::Type response; + response.data = chip::CharSpan("data", strlen("data")); + response.status = StatusEnum::kSuccess; return response; } diff --git a/examples/tv-app/linux/include/application-launcher/ApplicationLauncherManager.h b/examples/tv-app/linux/include/application-launcher/ApplicationLauncherManager.h index c3944bcfa0740c..ece3bd36d69523 100644 --- a/examples/tv-app/linux/include/application-launcher/ApplicationLauncherManager.h +++ b/examples/tv-app/linux/include/application-launcher/ApplicationLauncherManager.h @@ -18,15 +18,20 @@ #pragma once -#include -#include +#include +#include -#include -#include - -class ApplicationLauncherManager +class ApplicationLauncherManager : public chip::app::Clusters::ApplicationLauncher::Delegate { public: - CHIP_ERROR Init(); - CHIP_ERROR proxyGetApplicationList(chip::EndpointId mEndpointId, chip::app::AttributeValueEncoder & aEncoder); + chip::app::Clusters::ApplicationLauncher::Structs::ApplicationEP::Type HandleGetCurrentApp() override; + std::list HandleGetCatalogList() override; + + chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type + HandleLaunchApp(const chip::CharSpan & data, + const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) override; + chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type + HandleStopApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) override; + chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type + HandleHideApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) override; }; diff --git a/examples/tv-app/linux/include/audio-output/AudioOutputManager.cpp b/examples/tv-app/linux/include/audio-output/AudioOutputManager.cpp index 4ec01918b5222b..e3eccf8afa2232 100644 --- a/examples/tv-app/linux/include/audio-output/AudioOutputManager.cpp +++ b/examples/tv-app/linux/include/audio-output/AudioOutputManager.cpp @@ -18,54 +18,38 @@ #include "AudioOutputManager.h" -#include -#include -#include -#include -#include - -#include -#include - using namespace std; +using namespace chip::app::Clusters::AudioOutput; -CHIP_ERROR AudioOutputManager::Init() +uint8_t AudioOutputManager::HandleGetCurrentOutput() { - CHIP_ERROR err = CHIP_NO_ERROR; - - // TODO: Store feature map once it is supported - map featureMap; - featureMap["NU"] = true; - - return err; + return 0; } -CHIP_ERROR AudioOutputManager::proxyGetListOfAudioOutputInfo(chip::EndpointId mEndpointId, - chip::app::AttributeValueEncoder & aEncoder) +std::list AudioOutputManager::HandleGetOutputList() { - return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { - // TODO: Insert code here - int maximumVectorSize = 3; - char name[] = "exampleName"; - - for (int i = 0; i < maximumVectorSize; ++i) - { - chip::app::Clusters::AudioOutput::Structs::OutputInfo::Type outputInfo; - outputInfo.outputType = chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi; - outputInfo.name = chip::CharSpan(name, sizeof(name) - 1); - outputInfo.index = static_cast(1 + i); - ReturnErrorOnFailure(encoder.Encode(outputInfo)); - } - return CHIP_NO_ERROR; - }); + std::list list; + // TODO: Insert code here + int maximumVectorSize = 3; + + for (int i = 0; i < maximumVectorSize; ++i) + { + chip::app::Clusters::AudioOutput::Structs::OutputInfo::Type outputInfo; + outputInfo.outputType = chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi; + outputInfo.name = chip::CharSpan("exampleName", strlen("exampleName")); + outputInfo.index = static_cast(1 + i); + list.push_back(outputInfo); + } + return list; } -bool audioOutputClusterSelectOutput(uint8_t index) +bool AudioOutputManager::HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name) { // TODO: Insert code here return true; } -bool audioOutputClusterRenameOutput(uint8_t index, const chip::CharSpan & name) + +bool AudioOutputManager::HandleSelectOutput(const uint8_t & index) { // TODO: Insert code here return true; diff --git a/examples/tv-app/linux/include/audio-output/AudioOutputManager.h b/examples/tv-app/linux/include/audio-output/AudioOutputManager.h index 0aecc1ffe2d845..8dcd3ed344fc9a 100644 --- a/examples/tv-app/linux/include/audio-output/AudioOutputManager.h +++ b/examples/tv-app/linux/include/audio-output/AudioOutputManager.h @@ -18,13 +18,13 @@ #pragma once -#include +#include -#include -#include -class AudioOutputManager +class AudioOutputManager : public chip::app::Clusters::AudioOutput::Delegate { public: - CHIP_ERROR Init(); - CHIP_ERROR proxyGetListOfAudioOutputInfo(chip::EndpointId mEndpointId, chip::app::AttributeValueEncoder & aEncoder); + uint8_t HandleGetCurrentOutput() override; + std::list HandleGetOutputList() override; + bool HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name) override; + bool HandleSelectOutput(const uint8_t & index) override; }; diff --git a/examples/tv-app/linux/include/channel/ChannelManager.cpp b/examples/tv-app/linux/include/channel/ChannelManager.cpp index 1300281fe0aec7..066476c57c759e 100644 --- a/examples/tv-app/linux/include/channel/ChannelManager.cpp +++ b/examples/tv-app/linux/include/channel/ChannelManager.cpp @@ -16,68 +16,68 @@ */ #include "ChannelManager.h" -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include using namespace chip; +using namespace chip::app::Clusters::Channel; -CHIP_ERROR ChannelManager::Init() +std::list ChannelManager::HandleGetChannelList() { - CHIP_ERROR err = CHIP_NO_ERROR; - // TODO: Store feature map once it is supported - std::map featureMap; - featureMap["CL"] = true; - featureMap["LI"] = true; + std::list list; + // TODO: Insert code here + int maximumVectorSize = 2; - SuccessOrExit(err); -exit: - return err; + for (int i = 0; i < maximumVectorSize; ++i) + { + chip::app::Clusters::Channel::Structs::ChannelInfo::Type channelInfo; + channelInfo.affiliateCallSign = chip::CharSpan("exampleASign", strlen("exampleASign")); + channelInfo.callSign = chip::CharSpan("exampleCSign", strlen("exampleCSign")); + channelInfo.name = chip::CharSpan("exampleName", strlen("exampleName")); + channelInfo.majorNumber = static_cast(1 + i); + channelInfo.minorNumber = static_cast(2 + i); + list.push_back(channelInfo); + } + return list; } -CHIP_ERROR ChannelManager::proxyGetChannelList(chip::EndpointId mEndpointId, chip::app::AttributeValueEncoder & aEncoder) +chip::app::Clusters::Channel::Structs::LineupInfo::Type ChannelManager::HandleGetLineup() { - return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { - // TODO: Insert code here - int maximumVectorSize = 2; - char affiliateCallSign[] = "exampleASign"; - char callSign[] = "exampleCSign"; - char name[] = "exampleName"; + chip::app::Clusters::Channel::Structs::LineupInfo::Type lineup; + lineup.operatorName = chip::CharSpan("operatorName", strlen("operatorName")); + lineup.lineupName = chip::CharSpan("lineupName", strlen("lineupName")); + lineup.postalCode = chip::CharSpan("postalCode", strlen("postalCode")); + lineup.lineupInfoType = chip::app::Clusters::Channel::LineupInfoTypeEnum::kMso; + return lineup; +} - for (int i = 0; i < maximumVectorSize; ++i) - { - chip::app::Clusters::Channel::Structs::ChannelInfo::Type channelInfo; - channelInfo.affiliateCallSign = CharSpan(affiliateCallSign, sizeof(affiliateCallSign) - 1); - channelInfo.callSign = CharSpan(callSign, sizeof(callSign) - 1); - channelInfo.name = CharSpan(name, sizeof(name) - 1); - channelInfo.majorNumber = static_cast(1 + i); - channelInfo.minorNumber = static_cast(2 + i); - ReturnErrorOnFailure(encoder.Encode(channelInfo)); - } - return CHIP_NO_ERROR; - }); +chip::app::Clusters::Channel::Structs::ChannelInfo::Type ChannelManager::HandleGetCurrentChannel() +{ + chip::app::Clusters::Channel::Structs::ChannelInfo::Type currentChannel; + currentChannel.affiliateCallSign = chip::CharSpan("exampleASign", strlen("exampleASign")); + currentChannel.callSign = chip::CharSpan("exampleCSign", strlen("exampleCSign")); + currentChannel.name = chip::CharSpan("exampleName", strlen("exampleName")); + currentChannel.majorNumber = 1; + currentChannel.minorNumber = 0; + return currentChannel; } -ChannelInfo ChannelClusterChangeChannel(std::string match) +Commands::ChangeChannelResponse::Type ChannelManager::HandleChangeChannel(const chip::CharSpan & match) { - // TODO: Insert code here - ChannelInfo channel = {}; - return channel; + Commands::ChangeChannelResponse::Type response; + response.channelMatch.majorNumber = 1; + response.channelMatch.minorNumber = 0; + response.channelMatch.name = chip::CharSpan("name", strlen("name")); + response.channelMatch.callSign = chip::CharSpan("callSign", strlen("callSign")); + response.channelMatch.affiliateCallSign = chip::CharSpan("affiliateCallSign", strlen("affiliateCallSign")); + response.errorType = chip::app::Clusters::Channel::ErrorTypeEnum::kMultipleMatches; + return response; } -bool ChannelClusterChangeChannelByNumber(uint16_t majorNumber, uint16_t minorNumber) + +bool ChannelManager::HandleChangeChannelByNumber(const uint16_t & majorNumber, const uint16_t & minorNumber) { // TODO: Insert code here return true; } -bool ChannelClusterSkipChannel(uint16_t count) +bool ChannelManager::HandleSkipChannel(const uint16_t & count) { // TODO: Insert code here return true; diff --git a/examples/tv-app/linux/include/channel/ChannelManager.h b/examples/tv-app/linux/include/channel/ChannelManager.h index 9c65bcbd44e0a4..f090b18150de27 100644 --- a/examples/tv-app/linux/include/channel/ChannelManager.h +++ b/examples/tv-app/linux/include/channel/ChannelManager.h @@ -17,15 +17,16 @@ #pragma once -#include +#include -#include -#include -#include - -class ChannelManager +class ChannelManager : public chip::app::Clusters::Channel::Delegate { public: - CHIP_ERROR Init(); - CHIP_ERROR proxyGetChannelList(chip::EndpointId mEndpointId, chip::app::AttributeValueEncoder & aEncoder); + std::list HandleGetChannelList() override; + chip::app::Clusters::Channel::Structs::LineupInfo::Type HandleGetLineup() override; + chip::app::Clusters::Channel::Structs::ChannelInfo::Type HandleGetCurrentChannel() override; + + chip::app::Clusters::Channel::Commands::ChangeChannelResponse::Type HandleChangeChannel(const chip::CharSpan & match) override; + bool HandleChangeChannelByNumber(const uint16_t & majorNumber, const uint16_t & minorNumber) override; + bool HandleSkipChannel(const uint16_t & count) override; }; diff --git a/examples/tv-app/linux/include/cluster-init.cpp b/examples/tv-app/linux/include/cluster-init.cpp index ad572d5645d952..bbb889d264404d 100644 --- a/examples/tv-app/linux/include/cluster-init.cpp +++ b/examples/tv-app/linux/include/cluster-init.cpp @@ -54,188 +54,3 @@ class TvAttrAccess : public app::AttributeAccessInterface }; } // anonymous namespace - -/** @brief Application Basic Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfApplicationBasicClusterInitCallback(chip::EndpointId endpoint) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - ApplicationBasicManager & aManager = ApplicationBasicManager::GetInstance(); - err = aManager.Init(); - if (CHIP_NO_ERROR == err) - { - chip::app::Clusters::ApplicationBasic::Application application = aManager.getApplicationForEndpoint(endpoint); - aManager.store(endpoint, &application); - } - else - { - ChipLogError(Zcl, "Failed to store application for endpoint: %d. Error:%s", endpoint, chip::ErrorStr(err)); - } -} - -/** @brief Wake On LAN Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfWakeOnLanClusterInitCallback(chip::EndpointId endpoint) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - WakeOnLanManager & wolManager = WakeOnLanManager::GetInstance(); - err = wolManager.Init(); - if (CHIP_NO_ERROR == err) - { - char macAddress[32] = ""; - wolManager.setMacAddress(endpoint, macAddress); - wolManager.store(endpoint, macAddress); - } - else - { - ChipLogError(Zcl, "Failed to store mac address for endpoint: %d. Error:%s", endpoint, chip::ErrorStr(err)); - } -} - -namespace { - -TvAttrAccess - gChannelAttrAccess; - -} // anonymous namespace - -/** @brief Channel Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfChannelClusterInitCallback(EndpointId endpoint) -{ - static bool attrAccessRegistered = false; - if (!attrAccessRegistered) - { - registerAttributeAccessOverride(&gChannelAttrAccess); - attrAccessRegistered = true; - } -} - -namespace { - -TvAttrAccess - gApplicationLauncherAttrAccess; - -} // anonymous namespace - -/** @brief Application Launcher Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfApplicationLauncherClusterInitCallback(EndpointId endpoint) -{ - static bool attrAccessRegistered = false; - if (!attrAccessRegistered) - { - registerAttributeAccessOverride(&gApplicationLauncherAttrAccess); - attrAccessRegistered = true; - } -} - -namespace { - -TvAttrAccess - gAudioOutputAttrAccess; - -} // anonymous namespace - -/** @brief Audio Output Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfAudioOutputClusterInitCallback(EndpointId endpoint) -{ - static bool attrAccessRegistered = false; - if (!attrAccessRegistered) - { - registerAttributeAccessOverride(&gAudioOutputAttrAccess); - attrAccessRegistered = true; - } -} - -namespace { - -TvAttrAccess - gMediaInputAttrAccess; - -} // anonymous namespace - -/** @brief Media Input Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfMediaInputClusterInitCallback(EndpointId endpoint) -{ - static bool attrAccessRegistered = false; - if (!attrAccessRegistered) - { - registerAttributeAccessOverride(&gMediaInputAttrAccess); - attrAccessRegistered = true; - } -} - -namespace { - -TvAttrAccess - gTargetNavigatorAttrAccess; - -} // anonymous namespace - -/** @brief Target Navigator Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfTargetNavigatorClusterInitCallback(EndpointId endpoint) -{ - static bool attrAccessRegistered = false; - if (!attrAccessRegistered) - { - registerAttributeAccessOverride(&gTargetNavigatorAttrAccess); - attrAccessRegistered = true; - } -} diff --git a/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.cpp b/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.cpp index a45066f5ba5283..33891a9f9bbfa7 100644 --- a/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.cpp +++ b/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.cpp @@ -17,31 +17,17 @@ */ #include "ContentLauncherManager.h" - -#include -#include -#include -#include -#include - -#include -#include #include -#include -#include -#include -#include - -#include -#include using namespace std; +using namespace chip::app::Clusters::ContentLauncher; using namespace chip::AppPlatform; -LaunchResponse ContentLauncherManager::HandleLaunchContent(chip::EndpointId endpointId, const std::list & parameterList, - bool autoplay, const chip::CharSpan & data) +Commands::LaunchResponse::Type ContentLauncherManager::HandleLaunchContent(chip::EndpointId endpointId, + const std::list & parameterList, + bool autoplay, const chip::CharSpan & data) { - ChipLogProgress(Zcl, "ContentLauncherManager::HandleLaunchContent "); + ChipLogProgress(Zcl, "ContentLauncherManager::HandleLaunchContent"); string dataString(data.data(), data.size()); #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED @@ -53,15 +39,15 @@ LaunchResponse ContentLauncherManager::HandleLaunchContent(chip::EndpointId endp #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED // TODO: Insert code here - LaunchResponse response; - response.err = CHIP_NO_ERROR; + Commands::LaunchResponse::Type response; response.data = chip::CharSpan("exampleData", strlen("exampleData")); response.status = chip::app::Clusters::ContentLauncher::StatusEnum::kSuccess; return response; } -LaunchResponse ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString, - const std::list & brandingInformation) +Commands::LaunchResponse::Type ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & contentUrl, + const chip::CharSpan & displayString, + const std::list & brandingInformation) { ChipLogProgress(Zcl, "ContentLauncherManager::HandleLaunchUrl"); @@ -69,8 +55,7 @@ LaunchResponse ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & co string displayStringString(displayString.data(), displayString.size()); // TODO: Insert code here - LaunchResponse response; - response.err = CHIP_NO_ERROR; + Commands::LaunchResponse::Type response; response.data = chip::CharSpan("exampleData", strlen("exampleData")); response.status = chip::app::Clusters::ContentLauncher::StatusEnum::kSuccess; return response; diff --git a/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.h b/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.h index c9dbe270e5859c..132afeb37a9812 100644 --- a/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.h +++ b/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.h @@ -18,22 +18,17 @@ #pragma once -#include -#include -#include - -#include -#include -#include -#include +#include class ContentLauncherManager : public chip::app::Clusters::ContentLauncher::Delegate { public: - LaunchResponse HandleLaunchContent(chip::EndpointId endpointId, const std::list & parameterList, bool autoplay, - const chip::CharSpan & data) override; - LaunchResponse HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString, - const std::list & brandingInformation) override; + chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type + HandleLaunchContent(chip::EndpointId endpointId, const std::list & parameterList, bool autoplay, + const chip::CharSpan & data) override; + chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type + HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString, + const std::list & brandingInformation) override; std::list HandleGetAcceptHeaderList() override; uint32_t HandleGetSupportedStreamingProtocols() override; }; diff --git a/examples/tv-app/linux/include/keypad-input/KeypadInputManager.cpp b/examples/tv-app/linux/include/keypad-input/KeypadInputManager.cpp index dd586636ebb691..32bcc0342cb36d 100644 --- a/examples/tv-app/linux/include/keypad-input/KeypadInputManager.cpp +++ b/examples/tv-app/linux/include/keypad-input/KeypadInputManager.cpp @@ -18,32 +18,13 @@ #include "KeypadInputManager.h" -#include -#include -#include +using namespace chip; +using namespace chip::app::Clusters::KeypadInput; -#include -#include - -using namespace std; - -CHIP_ERROR KeypadInputManager::Init() -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - // TODO: Store feature map once it is supported - map featureMap; - featureMap["NV"] = true; - featureMap["LK"] = true; - featureMap["NK"] = true; - - SuccessOrExit(err); -exit: - return err; -} - -chip::app::Clusters::KeypadInput::StatusEnum keypadInputClusterSendKey(chip::app::Clusters::KeypadInput::CecKeyCode keyCode) +Commands::SendKeyResponse::Type KeypadInputManager::HandleSendKey(const CecKeyCode & keycCode) { // TODO: Insert code here - return chip::app::Clusters::KeypadInput::StatusEnum::kSuccess; + Commands::SendKeyResponse::Type response; + response.status = chip::app::Clusters::KeypadInput::StatusEnum::kSuccess; + return response; } diff --git a/examples/tv-app/linux/include/keypad-input/KeypadInputManager.h b/examples/tv-app/linux/include/keypad-input/KeypadInputManager.h index d55161a5e1cad4..93d3f66e8a003a 100644 --- a/examples/tv-app/linux/include/keypad-input/KeypadInputManager.h +++ b/examples/tv-app/linux/include/keypad-input/KeypadInputManager.h @@ -18,13 +18,11 @@ #pragma once -#include +#include -#include -#include - -class KeypadInputManager +class KeypadInputManager : public chip::app::Clusters::KeypadInput::Delegate { public: - CHIP_ERROR Init(); + chip::app::Clusters::KeypadInput::Commands::SendKeyResponse::Type + HandleSendKey(const chip::app::Clusters::KeypadInput::CecKeyCode & keyCode) override; }; diff --git a/examples/tv-app/linux/include/low-power/LowPowerManager.cpp b/examples/tv-app/linux/include/low-power/LowPowerManager.cpp index 97016d4b01a74f..57399c0ba1de5c 100644 --- a/examples/tv-app/linux/include/low-power/LowPowerManager.cpp +++ b/examples/tv-app/linux/include/low-power/LowPowerManager.cpp @@ -18,7 +18,7 @@ #include "LowPowerManager.h" -bool lowPowerClusterSleep() +bool LowPowerManager::HandleSleep() { // TODO: Insert code here return true; diff --git a/examples/tv-app/linux/include/low-power/LowPowerManager.h b/examples/tv-app/linux/include/low-power/LowPowerManager.h index 75d500ca12de74..92bb1417be514d 100644 --- a/examples/tv-app/linux/include/low-power/LowPowerManager.h +++ b/examples/tv-app/linux/include/low-power/LowPowerManager.h @@ -18,9 +18,10 @@ #pragma once -#include +#include -class LowPowerManager +class LowPowerManager : public chip::app::Clusters::LowPower::Delegate { public: + bool HandleSleep() override; }; diff --git a/examples/tv-app/linux/include/media-input/MediaInputManager.cpp b/examples/tv-app/linux/include/media-input/MediaInputManager.cpp index 4d72d82b993737..4b654d0b838d87 100644 --- a/examples/tv-app/linux/include/media-input/MediaInputManager.cpp +++ b/examples/tv-app/linux/include/media-input/MediaInputManager.cpp @@ -17,63 +17,51 @@ #include "MediaInputManager.h" -#include -#include -#include -#include -#include -#include +using namespace chip; +using namespace chip::app::Clusters::MediaInput; -CHIP_ERROR MediaInputManager::Init() +std::list MediaInputManager::HandleGetInputList() { - CHIP_ERROR err = CHIP_NO_ERROR; + std::list list; + // TODO: Insert code here + int maximumVectorSize = 2; - // TODO: Store feature map once it is supported - std::map featureMap; - featureMap["NU"] = true; - SuccessOrExit(err); -exit: - return err; + for (int i = 0; i < maximumVectorSize; ++i) + { + chip::app::Clusters::MediaInput::Structs::InputInfo::Type inputInfo; + inputInfo.description = chip::CharSpan("exampleDescription", strlen("exampleDescription")); + inputInfo.name = chip::CharSpan("exampleName", strlen("exampleName")); + inputInfo.inputType = chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi; + inputInfo.index = static_cast(1 + i); + list.push_back(inputInfo); + } + return list; } -CHIP_ERROR MediaInputManager::proxyGetInputList(chip::EndpointId mEndpointId, chip::app::AttributeValueEncoder & aEncoder) +uint8_t MediaInputManager::HandleGetCurrentInput() { - return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { - // TODO: Insert code here - int maximumVectorSize = 2; - char description[] = "exampleDescription"; - char name[] = "exampleName"; - - for (int i = 0; i < maximumVectorSize; ++i) - { - chip::app::Clusters::MediaInput::Structs::InputInfo::Type inputInfo; - inputInfo.description = chip::CharSpan(description, sizeof(description) - 1); - inputInfo.name = chip::CharSpan(name, sizeof(name) - 1); - inputInfo.inputType = chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi; - inputInfo.index = static_cast(1 + i); - ReturnErrorOnFailure(encoder.Encode(inputInfo)); - } - - return CHIP_NO_ERROR; - }); + return 0; } -bool mediaInputClusterSelectInput(uint8_t input) +bool MediaInputManager::HandleSelectInput(const uint8_t index) { // TODO: Insert code here return true; } -bool mediaInputClusterShowInputStatus() + +bool MediaInputManager::HandleShowInputStatus() { // TODO: Insert code here return true; } -bool mediaInputClusterHideInputStatus() + +bool MediaInputManager::HandleHideInputStatus() { // TODO: Insert code here return true; } -bool mediaInputClusterRenameInput(uint8_t input, std::string name) + +bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharSpan & name) { // TODO: Insert code here return true; diff --git a/examples/tv-app/linux/include/media-input/MediaInputManager.h b/examples/tv-app/linux/include/media-input/MediaInputManager.h index eb9fad3ead077e..84e0114f43c3f3 100644 --- a/examples/tv-app/linux/include/media-input/MediaInputManager.h +++ b/examples/tv-app/linux/include/media-input/MediaInputManager.h @@ -18,15 +18,15 @@ #pragma once -#include +#include -#include -#include -#include - -class MediaInputManager +class MediaInputManager : public chip::app::Clusters::MediaInput::Delegate { public: - CHIP_ERROR Init(); - CHIP_ERROR proxyGetInputList(chip::EndpointId mEndpointId, chip::app::AttributeValueEncoder & aEncoder); + std::list HandleGetInputList() override; + uint8_t HandleGetCurrentInput() override; + bool HandleSelectInput(const uint8_t index) override; + bool HandleShowInputStatus() override; + bool HandleHideInputStatus() override; + bool HandleRenameInput(const uint8_t index, const chip::CharSpan & name) override; }; diff --git a/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.cpp b/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.cpp index c4b285761c8b42..81e6872e14d83a 100644 --- a/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.cpp +++ b/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.cpp @@ -16,65 +16,132 @@ */ #include "MediaPlaybackManager.h" -#include -#include -#include - -#include -#include using namespace std; using namespace chip::app::Clusters::MediaPlayback; -CHIP_ERROR MediaPlaybackManager::Init() +PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState() +{ + return PlaybackStateEnum::kPlaying; +} + +uint64_t MediaPlaybackManager::HandleGetStartTime() +{ + return 0; +} + +uint64_t MediaPlaybackManager::HandleGetDuration() { - CHIP_ERROR err = CHIP_NO_ERROR; + return 0; +} - // TODO: Store feature map once it is supported - map featureMap; - featureMap["AS"] = true; +Structs::PlaybackPosition::Type MediaPlaybackManager::HandleGetSampledPosition() +{ + Structs::PlaybackPosition::Type sampledPosition; + sampledPosition.updatedAt = 0; + sampledPosition.position = 0; + return sampledPosition; +} - SuccessOrExit(err); -exit: - return err; +float MediaPlaybackManager::HandleGetPlaybackSpeed() +{ + return 0; } -StatusEnum MediaPlaybackManager::proxyMediaPlaybackRequest(MediaPlaybackRequest mediaPlaybackRequest, - uint64_t deltaPositionMilliseconds) +uint64_t MediaPlaybackManager::HandleGetSeekRangeStart() +{ + return 0; +} + +uint64_t MediaPlaybackManager::HandleGetSeekRangeEnd() +{ + return 0; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandlePlay() { - switch (mediaPlaybackRequest) - { - case MEDIA_PLAYBACK_REQUEST_PLAY: // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_PAUSE: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandlePause() +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_STOP: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleStop() +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_START_OVER: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleFastForward() +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_PREVIOUS: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandlePrevious() +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_NEXT: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleRewind() +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_REWIND: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleSkipBackward(const uint64_t & deltaPositionMilliseconds) +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_FAST_FORWARD: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleSkipForward(const uint64_t & deltaPositionMilliseconds) +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_SKIP_FORWARD: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleSeekRequest(const uint64_t & positionMilliseconds) +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_SKIP_BACKWARD: + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; +} + +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleNext() +{ // TODO: Insert code here - case MEDIA_PLAYBACK_REQUEST_SEEK: - return chip::app::Clusters::MediaPlayback::StatusEnum::kSuccess; - break; - default: { - return chip::app::Clusters::MediaPlayback::StatusEnum::kSuccess; - } - } + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; } -chip::app::Clusters::MediaPlayback::StatusEnum -mediaPlaybackClusterSendMediaPlaybackRequest(MediaPlaybackRequest mediaPlaybackRequest, uint64_t deltaPositionMilliseconds) +Commands::PlaybackResponse::Type MediaPlaybackManager::HandleStartOverRequest() { - return MediaPlaybackManager().proxyMediaPlaybackRequest(mediaPlaybackRequest, deltaPositionMilliseconds); + // TODO: Insert code here + Commands::PlaybackResponse::Type response; + response.status = StatusEnum::kSuccess; + return response; } diff --git a/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.h b/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.h index a15aa49bcbb415..9bf4c6607cf2f9 100644 --- a/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.h +++ b/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.h @@ -18,21 +18,31 @@ #pragma once -#include -#include #include -#include -#include - -class MediaPlaybackManager +class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate { public: - CHIP_ERROR Init(); - void storeNewPlaybackState(chip::EndpointId endpoint, uint8_t newPlaybackState); - chip::app::Clusters::MediaPlayback::StatusEnum proxyMediaPlaybackRequest(MediaPlaybackRequest mediaPlaybackRequest, - uint64_t deltaPositionMilliseconds); + chip::app::Clusters::MediaPlayback::PlaybackStateEnum HandleGetCurrentState() override; + uint64_t HandleGetStartTime() override; + uint64_t HandleGetDuration() override; + chip::app::Clusters::MediaPlayback::Structs::PlaybackPosition::Type HandleGetSampledPosition() override; + float HandleGetPlaybackSpeed() override; + uint64_t HandleGetSeekRangeStart() override; + uint64_t HandleGetSeekRangeEnd() override; -private: - uint8_t oldPlaybackState; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandlePlay() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandlePause() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleStop() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleFastForward() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandlePrevious() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleRewind() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type + HandleSkipBackward(const uint64_t & deltaPositionMilliseconds) override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type + HandleSkipForward(const uint64_t & deltaPositionMilliseconds) override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type + HandleSeekRequest(const uint64_t & positionMilliseconds) override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleNext() override; + chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type HandleStartOverRequest() override; }; diff --git a/examples/tv-app/linux/include/target-navigator/TargetNavigatorManager.cpp b/examples/tv-app/linux/include/target-navigator/TargetNavigatorManager.cpp index dfecfea9b6226e..ddfcb0d6fd723b 100644 --- a/examples/tv-app/linux/include/target-navigator/TargetNavigatorManager.cpp +++ b/examples/tv-app/linux/include/target-navigator/TargetNavigatorManager.cpp @@ -16,82 +16,37 @@ */ #include "TargetNavigatorManager.h" -#include -#include -#include -#include -#include -#include -#include - -#include -#include using namespace std; -using namespace chip::AppPlatform; - -// index starts at 1 for -std::list gTargets = { "exampleName", "exampleName" }; -uint8_t gCurrentTarget = 1; +using namespace chip::app::Clusters::TargetNavigator; -CHIP_ERROR TargetNavigatorManager::Init() +std::list TargetNavigatorManager::HandleGetTargetList() { - CHIP_ERROR err = CHIP_NO_ERROR; - - SuccessOrExit(err); -exit: - return err; -} + std::list list; + // TODO: Insert code here + int maximumVectorSize = 2; -CHIP_ERROR TargetNavigatorManager::proxyGetTargetInfoList(chip::EndpointId endpointId, chip::app::AttributeValueEncoder & aEncoder) -{ -#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - ContentApp * app = chip::AppPlatform::AppPlatform::GetInstance().GetContentAppByEndpointId(endpointId); - if (app != NULL) + for (int i = 0; i < maximumVectorSize; ++i) { - return app->GetTargetNavigator()->GetTargetInfoList(aEncoder); + Structs::TargetInfo::Type outputInfo; + outputInfo.identifier = static_cast(i + 1); + outputInfo.name = chip::CharSpan("exampleName", strlen("exampleName")); + list.push_back(outputInfo); } -#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - - return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { - int i = 1; // make sure TV_TargetNavigatorCluster.yaml test suite passes - assumes index starts at 1 - for (string entry : gTargets) - { - // ReturnErrorOnFailure(encoder.Encode(chip::CharSpan(entry.c_str(), entry.length()))); - - chip::app::Clusters::TargetNavigator::Structs::TargetInfo::Type targetInfo; - targetInfo.name = chip::CharSpan(entry.c_str(), entry.length()); - targetInfo.identifier = static_cast(i++); - ReturnErrorOnFailure(encoder.Encode(targetInfo)); - } - return CHIP_NO_ERROR; - }); + return list; } -TargetNavigatorResponse targetNavigatorClusterNavigateTarget(chip::EndpointId endpointId, uint8_t target, std::string data) +uint8_t TargetNavigatorManager::HandleGetCurrentTarget() { - ChipLogProgress(Zcl, "targetNavigatorClusterNavigateTarget endpoint=%d", endpointId); - -#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - ContentApp * app = chip::AppPlatform::AppPlatform::GetInstance().GetContentAppByEndpointId(endpointId); - if (app != NULL) - { - return app->GetTargetNavigator()->NavigateTarget(target, data); - } -#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED + return 0; +} - TargetNavigatorResponse response; - const char * testData = "data response"; - response.data = (uint8_t *) testData; - // make sure TV_TargetNavigatorCluster.yaml test suite passes - assumes index starts at 1 - if (target == 0 || target > gTargets.size()) - { - response.status = chip::to_underlying(chip::app::Clusters::TargetNavigator::StatusEnum::kAppNotAvailable); - } - else - { - response.status = chip::to_underlying(chip::app::Clusters::TargetNavigator::StatusEnum::kSuccess); - gCurrentTarget = target; - } +Commands::NavigateTargetResponse::Type TargetNavigatorManager::HandleNavigateTarget(const uint64_t & target, + const chip::CharSpan & data) +{ + // TODO: Insert code here + Commands::NavigateTargetResponse::Type response; + response.data = chip::CharSpan("data response", strlen("data response")); + response.status = chip::app::Clusters::TargetNavigator::StatusEnum::kSuccess; return response; } diff --git a/examples/tv-app/linux/include/target-navigator/TargetNavigatorManager.h b/examples/tv-app/linux/include/target-navigator/TargetNavigatorManager.h index 4166f977dcdaaf..7da10ea51448f5 100644 --- a/examples/tv-app/linux/include/target-navigator/TargetNavigatorManager.h +++ b/examples/tv-app/linux/include/target-navigator/TargetNavigatorManager.h @@ -17,18 +17,13 @@ #pragma once -#include +#include -#include -#include -#include -#include - -class TargetNavigatorManager +class TargetNavigatorManager : public chip::app::Clusters::TargetNavigator::Delegate { public: - CHIP_ERROR Init(); - CHIP_ERROR proxyGetTargetInfoList(chip::EndpointId endpointId, chip::app::AttributeValueEncoder & aEncoder); - -protected: + std::list HandleGetTargetList() override; + uint8_t HandleGetCurrentTarget() override; + chip::app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::Type + HandleNavigateTarget(const uint64_t & target, const chip::CharSpan & data) override; }; diff --git a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp index 3072b0e3928f30..291c2951c221f8 100644 --- a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp +++ b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.cpp @@ -18,56 +18,10 @@ #include "WakeOnLanManager.h" -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - using namespace chip; -using namespace chip::app::Clusters; - -CHIP_ERROR WakeOnLanManager::Init() -{ - CHIP_ERROR err = CHIP_NO_ERROR; - EndpointConfigurationStorage & endpointConfiguration = EndpointConfigurationStorage::GetInstance(); - err = endpointConfiguration.Init(); - SuccessOrExit(err); - es = &endpointConfiguration; -exit: - return err; -} +using namespace chip::app::Clusters::WakeOnLan; -void WakeOnLanManager::store(chip::EndpointId endpoint, char macAddress[32]) +chip::CharSpan WakeOnLanManager::HandleGetMacAddress() { - uint8_t bufferMemory[32]; - MutableByteSpan zclString(bufferMemory); - MakeZclCharString(zclString, macAddress); - EmberAfStatus macAddressStatus = emberAfWriteServerAttribute( - endpoint, WakeOnLan::Id, WakeOnLan::Attributes::WakeOnLanMacAddress::Id, zclString.data(), ZCL_CHAR_STRING_ATTRIBUTE_TYPE); - if (macAddressStatus != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store mac address attribute."); - } -} - -void WakeOnLanManager::setMacAddress(chip::EndpointId endpoint, char * macAddress) -{ - char address[18]; - uint16_t size = static_cast(sizeof(address)); - - std::string section = "endpoint" + std::to_string(endpoint); - CHIP_ERROR err = es->get(section, "macAddress", macAddress, size); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get mac address. Error:%s", chip::ErrorStr(err)); - } + return chip::CharSpan("00:00:00:00:00", strlen("00:00:00:00:00")); } diff --git a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.h b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.h index 2f0cca32df737e..ba4a6964a5bfc8 100644 --- a/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.h +++ b/examples/tv-app/linux/include/wake-on-lan/WakeOnLanManager.h @@ -18,24 +18,10 @@ #pragma once -#include -#include +#include -#include "../endpoint-configuration/EndpointConfigurationStorage.h" - -class WakeOnLanManager +class WakeOnLanManager : public chip::app::Clusters::WakeOnLan::Delegate { public: - CHIP_ERROR Init(); - void store(chip::EndpointId endpoint, char macAddress[32]); - void setMacAddress(chip::EndpointId endpoint, char * macAddress); - - static WakeOnLanManager & GetInstance() - { - static WakeOnLanManager instance; - return instance; - } - -private: - EndpointConfigurationStorage * es = nullptr; + chip::CharSpan HandleGetMacAddress() override; }; diff --git a/examples/tv-app/linux/main.cpp b/examples/tv-app/linux/main.cpp index 41e61a257a3cd3..e0549f20559cd9 100644 --- a/examples/tv-app/linux/main.cpp +++ b/examples/tv-app/linux/main.cpp @@ -28,14 +28,18 @@ #include +#include "include/account-login/AccountLoginManager.h" +#include "include/application-basic/ApplicationBasicManager.h" #include "include/application-launcher/ApplicationLauncherManager.h" #include "include/audio-output/AudioOutputManager.h" #include "include/channel/ChannelManager.h" #include "include/content-launcher/ContentLauncherManager.h" #include "include/keypad-input/KeypadInputManager.h" +#include "include/low-power/LowPowerManager.h" #include "include/media-input/MediaInputManager.h" #include "include/media-playback/MediaPlaybackManager.h" #include "include/target-navigator/TargetNavigatorManager.h" +#include "include/wake-on-lan/WakeOnLanManager.h" #if defined(ENABLE_CHIP_SHELL) #include @@ -54,47 +58,28 @@ bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::CommandHandler * comm namespace { static ContentLauncherManager contentLauncherManager; -constexpr chip::EndpointId kContentLauncherEndpoint = 1; +static AccountLoginManager accountLoginManager; +static ApplicationBasicManager applicationBasicManager; +static ApplicationLauncherManager applicationLauncherManager; +static AudioOutputManager audioOutputManager; +static ChannelManager channelManager; +static KeypadInputManager keypadInputManager; +static LowPowerManager lowPowerManager; +static MediaInputManager mediaInputManager; +static MediaPlaybackManager mediaPlaybackManager; +static TargetNavigatorManager targetNavigatorManager; +static WakeOnLanManager wakeOnLanManager; } // namespace void ApplicationInit() {} int main(int argc, char * argv[]) { - CHIP_ERROR err = CHIP_NO_ERROR; #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED chip::AppPlatform::ContentAppFactoryImpl factory; #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - // Init Keypad Input manager - err = KeypadInputManager().Init(); - SuccessOrExit(err); - - // Init Application Launcher Manager - err = ApplicationLauncherManager().Init(); - SuccessOrExit(err); - - // Init Audio Output Manager - err = AudioOutputManager().Init(); - SuccessOrExit(err); - - // Init Media Input Manager - err = MediaInputManager().Init(); - SuccessOrExit(err); - - // Init Media Playback Manager - err = MediaPlaybackManager().Init(); - SuccessOrExit(err); - - // Init Target Navigator Manager - err = TargetNavigatorManager().Init(); - SuccessOrExit(err); - - // Init Channel Manager - err = ChannelManager().Init(); - SuccessOrExit(err); - VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0); #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED @@ -109,18 +94,78 @@ int main(int argc, char * argv[]) #endif ChipLinuxAppMainLoop(); -exit: - if (err != CHIP_NO_ERROR) - { - std::cerr << "Failed to run TV App: " << ErrorStr(err) << std::endl; - // End the program with non zero error code to indicate a error. - return 1; - } + return 0; } void emberAfContentLauncherClusterInitCallback(EndpointId endpoint) { - ChipLogProgress(Zcl, "TV Linux App: ContentLauncherManager::SetDelegate"); - chip::app::Clusters::ContentLauncher::SetDelegate(kContentLauncherEndpoint, &contentLauncherManager); + ChipLogProgress(Zcl, "TV Linux App: ContentLauncher::SetDelegate"); + chip::app::Clusters::ContentLauncher::SetDelegate(endpoint, &contentLauncherManager); +} + +void emberAfAccountLoginClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: AccountLogin::SetDefaultDelegate"); + chip::app::Clusters::AccountLogin::SetDefaultDelegate(endpoint, &accountLoginManager); +} + +void emberAfApplicationBasicClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: ApplicationBasic::SetDefaultDelegate"); + chip::app::Clusters::ApplicationBasic::SetDefaultDelegate(endpoint, &applicationBasicManager); +} + +void emberAfApplicationLauncherClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: ApplicationLauncher::SetDefaultDelegate"); + chip::app::Clusters::ApplicationLauncher::SetDefaultDelegate(endpoint, &applicationLauncherManager); +} + +void emberAfAudioOutputClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: AudioOutput::SetDefaultDelegate"); + chip::app::Clusters::AudioOutput::SetDefaultDelegate(endpoint, &audioOutputManager); +} + +void emberAfChannelClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: Channel::SetDefaultDelegate"); + chip::app::Clusters::Channel::SetDefaultDelegate(endpoint, &channelManager); +} + +void emberAfKeypadInputClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: KeypadInput::SetDefaultDelegate"); + chip::app::Clusters::KeypadInput::SetDefaultDelegate(endpoint, &keypadInputManager); +} + +void emberAfLowPowerClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: LowPower::SetDefaultDelegate"); + chip::app::Clusters::LowPower::SetDefaultDelegate(endpoint, &lowPowerManager); +} + +void emberAfMediaInputClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: MediaInput::SetDefaultDelegate"); + chip::app::Clusters::MediaInput::SetDefaultDelegate(endpoint, &mediaInputManager); +} + +void emberAfMediaPlaybackClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: MediaPlayback::SetDefaultDelegate"); + chip::app::Clusters::MediaPlayback::SetDefaultDelegate(endpoint, &mediaPlaybackManager); +} + +void emberAfTargetNavigatorClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: TargetNavigator::SetDefaultDelegate"); + chip::app::Clusters::TargetNavigator::SetDefaultDelegate(endpoint, &targetNavigatorManager); +} + +void emberAfWakeOnLanClusterInitCallback(chip::EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: WakeOnLanManager::SetDefaultDelegate"); + chip::app::Clusters::WakeOnLan::SetDefaultDelegate(endpoint, &wakeOnLanManager); } diff --git a/src/app/clusters/account-login-server/account-login-delegate.h b/src/app/clusters/account-login-server/account-login-delegate.h new file mode 100644 index 00000000000000..3880b7aa7f6456 --- /dev/null +++ b/src/app/clusters/account-login-server/account-login-delegate.h @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace AccountLogin { + +/** @brief + * Defines methods for implementing application-specific logic for the Account Login Cluster. + */ +class Delegate +{ +public: + virtual bool HandleLogin(const chip::CharSpan & tempAccountIdentifierString, const chip::CharSpan & setupPinString) = 0; + virtual bool HandleLogout() = 0; + virtual Commands::GetSetupPINResponse::Type HandleGetSetupPin(const chip::CharSpan & tempAccountIdentifierString) = 0; + + virtual ~Delegate() = default; +}; + +} // namespace AccountLogin +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/account-login-server/account-login-server.cpp b/src/app/clusters/account-login-server/account-login-server.cpp index 4a892849b962fe..a095944282f97c 100644 --- a/src/app/clusters/account-login-server/account-login-server.cpp +++ b/src/app/clusters/account-login-server/account-login-server.cpp @@ -21,62 +21,117 @@ ******************************************************************************* ******************************************************************************/ +#include +#include + #include #include #include #include -#include using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::AccountLogin; -bool accountLoginClusterIsUserLoggedIn(std::string requestTempAccountIdentifier, std::string requestSetupPin); -bool accountLoginClusterLogout(); -std::string accountLoginClusterGetSetupPin(std::string requestTempAccountIdentifier, EndpointId endpoint); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::AccountLogin::Delegate; + +namespace { -void sendResponse(app::CommandHandler * command, const char * responseSetupPin) +Delegate * gDelegateTable[EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), AccountLogin::Id, Commands::GetSetupPINResponse::Id }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = command->PrepareCommand(path)); - VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = writer->PutString(TLV::ContextTag(0), responseSetupPin)); - SuccessOrExit(err = command->FinishCommand()); -exit: - if (err != CHIP_NO_ERROR) + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::AccountLogin::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) { - ChipLogError(Zcl, "Failed to encode GetSetupPIN command. Error:%s", ErrorStr(err)); + ChipLogError(Zcl, "Account Login has no delegate set for endpoint:%" PRIu16, endpoint); + return true; } + return false; } +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace AccountLogin { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::AccountLogin::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} + +} // namespace AccountLogin +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Matter Framework Callbacks Implementation bool emberAfAccountLoginClusterGetSetupPINRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::GetSetupPINRequest::DecodableType & commandData) { + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; auto & tempAccountIdentifier = commandData.tempAccountIdentifier; - std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); - std::string responseSetupPin = accountLoginClusterGetSetupPin(tempAccountIdentifierString, emberAfCurrentEndpoint()); - sendResponse(command, responseSetupPin.c_str()); + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::GetSetupPINResponse::Type response = delegate->HandleGetSetupPin(tempAccountIdentifier); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfAccountLoginClusterGetSetupPINCallback error: %s", err.AsString()); + + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } bool emberAfAccountLoginClusterLoginRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::LoginRequest::DecodableType & commandData) { + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; auto & tempAccountIdentifier = commandData.tempAccountIdentifier; - auto & tempSetupPin = commandData.setupPIN; + auto & setupPin = commandData.setupPIN; - std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); - std::string tempSetupPinString(tempSetupPin.data(), tempSetupPin.size()); - bool isLoggedIn = accountLoginClusterIsUserLoggedIn(tempAccountIdentifierString, tempSetupPinString); - EmberAfStatus status = isLoggedIn ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_NOT_AUTHORIZED; - if (!isLoggedIn) + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + +exit: + if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "User is not authorized."); + ChipLogError(Zcl, "emberAfAccountLoginClusterLoginRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); } + + bool isLoggedIn = delegate->HandleLogin(tempAccountIdentifier, setupPin); + EmberAfStatus status = isLoggedIn ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_NOT_AUTHORIZED; emberAfSendImmediateDefaultResponse(status); return true; } @@ -84,14 +139,24 @@ bool emberAfAccountLoginClusterLoginRequestCallback(app::CommandHandler * comman bool emberAfAccountLoginClusterLogoutRequestCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const Commands::LogoutRequest::DecodableType & commandData) { - bool isLoggedOut = accountLoginClusterLogout(); - EmberAfStatus status = isLoggedOut ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_NOT_AUTHORIZED; - if (!isLoggedOut) + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); +exit: + if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "User is not logged out."); + ChipLogError(Zcl, "emberAfAccountLoginClusterLogoutRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); } + + bool isLoggedOut = delegate->HandleLogout(); + EmberAfStatus status = isLoggedOut ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_NOT_AUTHORIZED; emberAfSendImmediateDefaultResponse(status); return true; } +// ----------------------------------------------------------------------------- +// Plugin initialization + void MatterAccountLoginPluginServerInitCallback() {} diff --git a/src/app/clusters/account-login-server/account-login-server.h b/src/app/clusters/account-login-server/account-login-server.h new file mode 100644 index 00000000000000..297bc3acc7e724 --- /dev/null +++ b/src/app/clusters/account-login-server/account-login-server.h @@ -0,0 +1,32 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "account-login-delegate.h" + +namespace chip { +namespace app { +namespace Clusters { +namespace AccountLogin { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace AccountLogin +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/application-basic-server/application-basic-delegate.h b/src/app/clusters/application-basic-server/application-basic-delegate.h new file mode 100644 index 00000000000000..cc53f85c999dd0 --- /dev/null +++ b/src/app/clusters/application-basic-server/application-basic-delegate.h @@ -0,0 +1,52 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace ApplicationBasic { + +/** @brief + * Defines methods for implementing application-specific logic for the Application Basic Cluster. + */ +class Delegate +{ +public: + virtual chip::CharSpan HandleGetVendorName() = 0; + virtual uint16_t HandleGetVendorId() = 0; + virtual chip::CharSpan HandleGetApplicationName() = 0; + virtual uint16_t HandleGetProductId() = 0; + virtual chip::app::Clusters::ApplicationBasic::Structs::Application::Type HandleGetApplication() = 0; + virtual ApplicationStatusEnum HandleGetStatus() = 0; + virtual chip::CharSpan HandleGetApplicationVersion() = 0; + virtual std::list HandleGetAllowedVendorList() = 0; + + virtual ~Delegate() = default; +}; + +} // namespace ApplicationBasic +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/application-basic-server/application-basic-server.cpp b/src/app/clusters/application-basic-server/application-basic-server.cpp index 32305ab27d68a4..6615c28b61d4f9 100644 --- a/src/app/clusters/application-basic-server/application-basic-server.cpp +++ b/src/app/clusters/application-basic-server/application-basic-server.cpp @@ -17,21 +17,202 @@ /**************************************************************************** * @file - * @brief Routines for the Application Launcher plugin, the - *server implementation of the Application Launcher cluster. + * @brief Routines for the Application Basic plugin, the + *server implementation of the Application Basic cluster. ******************************************************************************* ******************************************************************************/ -#include -#include -#include -#include -#include -#include +#include +#include + +#include +#include +#include +#include using namespace chip; +using namespace chip::app::Clusters; using namespace chip::app::Clusters::ApplicationBasic; -bool applicationBasicClusterChangeApplicationStatus(EndpointId endpoint, ApplicationStatusEnum status); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::ApplicationBasic::Delegate; + +namespace { + +Delegate * gDelegateTable[EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationBasic::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) + { + ChipLogError(Zcl, "Application Basic has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace ApplicationBasic { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationBasic::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} + +} // namespace ApplicationBasic +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Attribute Accessor Implementation + +namespace { + +class ApplicationBasicAttrAccess : public app::AttributeAccessInterface +{ +public: + ApplicationBasicAttrAccess() : + app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::ApplicationBasic::Id) + {} + + CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; + +private: + CHIP_ERROR ReadVendorNameAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadVendorIdAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadApplicationNameAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadProductIdAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadApplicationAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadStatusAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadApplicationVersionAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadAllowedVendorListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +ApplicationBasicAttrAccess gApplicationBasicAttrAccess; + +CHIP_ERROR ApplicationBasicAttrAccess::Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + switch (aPath.mAttributeId) + { + case app::Clusters::ApplicationBasic::Attributes::VendorName::Id: { + return ReadVendorNameAttribute(aEncoder, delegate); + } + case app::Clusters::ApplicationBasic::Attributes::VendorId::Id: { + return ReadVendorIdAttribute(aEncoder, delegate); + } + case app::Clusters::ApplicationBasic::Attributes::ApplicationName::Id: { + return ReadApplicationNameAttribute(aEncoder, delegate); + } + case app::Clusters::ApplicationBasic::Attributes::ProductId::Id: { + return ReadProductIdAttribute(aEncoder, delegate); + } + case app::Clusters::ApplicationBasic::Attributes::ApplicationApp::Id: { + return ReadApplicationAttribute(aEncoder, delegate); + } + case app::Clusters::ApplicationBasic::Attributes::ApplicationStatus::Id: { + return ReadStatusAttribute(aEncoder, delegate); + } + case app::Clusters::ApplicationBasic::Attributes::ApplicationVersion::Id: { + return ReadApplicationVersionAttribute(aEncoder, delegate); + } + case app::Clusters::ApplicationBasic::Attributes::AllowedVendorList::Id: { + return ReadAllowedVendorListAttribute(aEncoder, delegate); + } + default: { + break; + } + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR ApplicationBasicAttrAccess::ReadVendorNameAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + chip::CharSpan vendorName = delegate->HandleGetVendorName(); + return aEncoder.Encode(vendorName); +} + +CHIP_ERROR ApplicationBasicAttrAccess::ReadVendorIdAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint16_t vendorId = delegate->HandleGetVendorId(); + return aEncoder.Encode(vendorId); +} + +CHIP_ERROR ApplicationBasicAttrAccess::ReadApplicationNameAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + chip::CharSpan applicationName = delegate->HandleGetApplicationName(); + return aEncoder.Encode(applicationName); +} + +CHIP_ERROR ApplicationBasicAttrAccess::ReadProductIdAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint16_t vendorId = delegate->HandleGetProductId(); + return aEncoder.Encode(vendorId); +} + +CHIP_ERROR ApplicationBasicAttrAccess::ReadApplicationAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + Structs::Application::Type application = delegate->HandleGetApplication(); + return aEncoder.Encode(application); +} + +CHIP_ERROR ApplicationBasicAttrAccess::ReadStatusAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + ApplicationStatusEnum status = delegate->HandleGetStatus(); + return aEncoder.Encode(status); +} + +CHIP_ERROR ApplicationBasicAttrAccess::ReadApplicationVersionAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + chip::CharSpan applicationVersion = delegate->HandleGetApplicationVersion(); + return aEncoder.Encode(applicationVersion); +} + +CHIP_ERROR ApplicationBasicAttrAccess::ReadAllowedVendorListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + std::list allowedVendorList = delegate->HandleGetAllowedVendorList(); + return aEncoder.EncodeList([allowedVendorList](const auto & encoder) -> CHIP_ERROR { + for (const auto & allowedVendor : allowedVendorList) + { + ReturnErrorOnFailure(encoder.Encode(allowedVendor)); + } + return CHIP_NO_ERROR; + }); +} + +} // anonymous namespace + +// ----------------------------------------------------------------------------- +// Plugin initialization -void MatterApplicationBasicPluginServerInitCallback() {} +void MatterApplicationBasicPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gApplicationBasicAttrAccess); +} diff --git a/examples/tv-app/android/include/application-basic/Application.h b/src/app/clusters/application-basic-server/application-basic-server.h similarity index 61% rename from examples/tv-app/android/include/application-basic/Application.h rename to src/app/clusters/application-basic-server/application-basic-server.h index 428301c69833f2..05fa4b69ce106b 100644 --- a/examples/tv-app/android/include/application-basic/Application.h +++ b/src/app/clusters/application-basic-server/application-basic-server.h @@ -1,7 +1,6 @@ -/* +/** * * Copyright (c) 2021 Project CHIP Authors - * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,25 +17,16 @@ #pragma once +#include "application-basic-delegate.h" #include namespace chip { namespace app { namespace Clusters { namespace ApplicationBasic { -struct Application -{ - using ApplicationBasicStatus = chip::app::Clusters::ApplicationBasic::ApplicationStatusEnum; - char vendorName[32] = ""; - char name[32] = ""; - char id[32] = ""; - char version[32] = ""; - uint16_t vendorId = 0; - uint16_t productId = 0; - uint16_t catalogVendorId = 0; - uint16_t allowedVendorList[32] = { 123, 456 }; - ApplicationBasicStatus status = ApplicationBasicStatus::kStopped; -}; + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + } // namespace ApplicationBasic } // namespace Clusters } // namespace app diff --git a/src/app/clusters/application-launcher-server/application-launcher-delegate.h b/src/app/clusters/application-launcher-server/application-launcher-delegate.h new file mode 100644 index 00000000000000..7d6ff13c06a2f9 --- /dev/null +++ b/src/app/clusters/application-launcher-server/application-launcher-delegate.h @@ -0,0 +1,54 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace ApplicationLauncher { + +/** @brief + * Defines methods for implementing application-specific logic for the Application Launcher Cluster. + */ +class Delegate +{ +public: + virtual chip::app::Clusters::ApplicationLauncher::Structs::ApplicationEP::Type HandleGetCurrentApp() = 0; + virtual std::list HandleGetCatalogList() = 0; + + virtual Commands::LauncherResponse::Type + HandleLaunchApp(const chip::CharSpan & data, + const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) = 0; + virtual Commands::LauncherResponse::Type + HandleStopApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) = 0; + virtual Commands::LauncherResponse::Type + HandleHideApp(const chip::app::Clusters::ApplicationLauncher::Structs::Application::Type & application) = 0; + + virtual ~Delegate() = default; +}; + +} // namespace ApplicationLauncher +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/application-launcher-server/application-launcher-server.cpp b/src/app/clusters/application-launcher-server/application-launcher-server.cpp index c88daf9b6065b6..50b2b2506baf52 100644 --- a/src/app/clusters/application-launcher-server/application-launcher-server.cpp +++ b/src/app/clusters/application-launcher-server/application-launcher-server.cpp @@ -22,73 +22,162 @@ ******************************************************************************* ******************************************************************************/ -#include -#include -#include +#include +#include + +#include #include #include -#include -#include +#include +#include using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ApplicationLauncher; -ApplicationLauncherResponse applicationLauncherClusterLaunchApp(EndpointId endpoint, ::Application application, std::string data); +// ----------------------------------------------------------------------------- +// Delegate Implementation -ApplicationLauncherResponse applicationLauncherClusterStopApp(EndpointId endpoint, ::Application application, std::string data); +using chip::app::Clusters::ApplicationLauncher::Delegate; -ApplicationLauncherResponse applicationLauncherClusterHideApp(EndpointId endpoint, ::Application application, std::string data); +namespace { -bool emberAfApplicationLauncherClusterLaunchAppCallback(app::CommandHandler * commandObj, - const app::ConcreteCommandPath & commandPath, EndpointId endpoint, - uint8_t *, uint8_t *, - Commands::LaunchAppRequest::DecodableType & commandData) +Delegate * gDelegateTable[EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) { - EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - emberAfSendImmediateDefaultResponse(status); - return true; + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationLauncher::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); } -void sendResponse(app::CommandHandler * command, app::ConcreteCommandPath path, ApplicationLauncherResponse response) +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) { - CHIP_ERROR err = CHIP_NO_ERROR; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = command->PrepareCommand(path)); - VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = writer->Put(TLV::ContextTag(0), response.status)); - SuccessOrExit(err = writer->PutString(TLV::ContextTag(1), reinterpret_cast(response.data))); - SuccessOrExit(err = command->FinishCommand()); -exit: - if (err != CHIP_NO_ERROR) + if (delegate == nullptr) + { + ChipLogError(Zcl, "Application Launcher has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace ApplicationLauncher { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationLauncher::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} + +} // namespace ApplicationLauncher +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Attribute Accessor Implementation + +namespace { + +class ApplicationLauncherAttrAccess : public app::AttributeAccessInterface +{ +public: + ApplicationLauncherAttrAccess() : + app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::ApplicationLauncher::Id) + {} + + CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; + +private: + CHIP_ERROR ReadCatalogListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadCurrentAppAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +ApplicationLauncherAttrAccess gApplicationLauncherAttrAccess; + +CHIP_ERROR ApplicationLauncherAttrAccess::Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + switch (aPath.mAttributeId) { - ChipLogError(Zcl, "Failed to send LauncherResponse. Error:%s", ErrorStr(err)); + case app::Clusters::ApplicationLauncher::Attributes::ApplicationLauncherList::Id: { + return ReadCatalogListAttribute(aEncoder, delegate); + } + case app::Clusters::ApplicationLauncher::Attributes::ApplicationLauncherApp::Id: { + return ReadCurrentAppAttribute(aEncoder, delegate); + } + default: { + break; } + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR ApplicationLauncherAttrAccess::ReadCatalogListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + std::list catalogList = delegate->HandleGetCatalogList(); + return aEncoder.EncodeList([catalogList](const auto & encoder) -> CHIP_ERROR { + for (const auto & catalog : catalogList) + { + ReturnErrorOnFailure(encoder.Encode(catalog)); + } + return CHIP_NO_ERROR; + }); } -::Application getApplicationFromCommand(uint16_t catalogVendorId, CharSpan applicationId) +CHIP_ERROR ApplicationLauncherAttrAccess::ReadCurrentAppAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) { - ::Application application = {}; - application.applicationId = applicationId; - application.catalogVendorId = catalogVendorId; - return application; + Structs::ApplicationEP::Type currentApp = delegate->HandleGetCurrentApp(); + return aEncoder.Encode(currentApp); } +} // anonymous namespace + +// ----------------------------------------------------------------------------- +// Matter Framework Callbacks Implementation + bool emberAfApplicationLauncherClusterLaunchAppRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::LaunchAppRequest::DecodableType & commandData) { - auto & requestData = commandData.data; - auto & requestApplicationCatalogVendorId = commandData.application.catalogVendorId; - auto & requestApplicationId = commandData.application.applicationId; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & data = commandData.data; + auto & application = commandData.application; - app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ApplicationLauncher::Id, Commands::LauncherResponse::Id }; + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::LauncherResponse::Type response = delegate->HandleLaunchApp(data, application); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfApplicationLauncherClusterLaunchAppRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } - ::Application application = getApplicationFromCommand(requestApplicationCatalogVendorId, requestApplicationId); - std::string reqestDataString(requestData.data(), requestData.size()); - ApplicationLauncherResponse response = - applicationLauncherClusterLaunchApp(emberAfCurrentEndpoint(), application, reqestDataString); - sendResponse(command, path, response); return true; } @@ -99,16 +188,29 @@ bool emberAfApplicationLauncherClusterStopAppRequestCallback(app::CommandHandler const app::ConcreteCommandPath & commandPath, const Commands::StopAppRequest::DecodableType & commandData) { - auto & requestApplicationCatalogVendorId = commandData.application.catalogVendorId; - auto & requestApplicationId = commandData.application.applicationId; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & application = commandData.application; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::LauncherResponse::Type response = delegate->HandleStopApp(application); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } - app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ApplicationLauncher::Id, Commands::LauncherResponse::Id }; +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfApplicationLauncherClusterStopAppRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } - ::Application application = getApplicationFromCommand(requestApplicationCatalogVendorId, requestApplicationId); - ApplicationLauncherResponse response = applicationLauncherClusterStopApp(emberAfCurrentEndpoint(), application, "data"); - sendResponse(command, path, response); return true; } + /** * @brief Application Launcher Cluster HideApp Command callback (from client) */ @@ -116,16 +218,33 @@ bool emberAfApplicationLauncherClusterHideAppRequestCallback(app::CommandHandler const app::ConcreteCommandPath & commandPath, const Commands::HideAppRequest::DecodableType & commandData) { + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & application = commandData.application; - auto & requestApplicationCatalogVendorId = commandData.application.catalogVendorId; - auto & requestApplicationId = commandData.application.applicationId; + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); - app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ApplicationLauncher::Id, Commands::LauncherResponse::Id }; + { + Commands::LauncherResponse::Type response = delegate->HandleHideApp(application); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfApplicationLauncherClusterStopAppRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } - ::Application application = getApplicationFromCommand(requestApplicationCatalogVendorId, requestApplicationId); - ApplicationLauncherResponse response = applicationLauncherClusterHideApp(emberAfCurrentEndpoint(), application, "data"); - sendResponse(command, path, response); return true; } -void MatterApplicationLauncherPluginServerInitCallback() {} +// ----------------------------------------------------------------------------- +// Plugin initialization + +void MatterApplicationLauncherPluginServerInitCallback(void) +{ + registerAttributeAccessOverride(&gApplicationLauncherAttrAccess); +} diff --git a/src/app/clusters/application-launcher-server/application-launcher-server.h b/src/app/clusters/application-launcher-server/application-launcher-server.h index f7e538e9f52030..f2fdb156e2eacc 100644 --- a/src/app/clusters/application-launcher-server/application-launcher-server.h +++ b/src/app/clusters/application-launcher-server/application-launcher-server.h @@ -23,8 +23,17 @@ #pragma once -struct ApplicationLauncherResponse -{ - uint8_t status; - uint8_t * data; -}; +#include "application-launcher-delegate.h" +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace ApplicationLauncher { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace ApplicationLauncher +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/audio-output-server/audio-output-delegate.h b/src/app/clusters/audio-output-server/audio-output-delegate.h new file mode 100644 index 00000000000000..daa1f0f084a6d2 --- /dev/null +++ b/src/app/clusters/audio-output-server/audio-output-delegate.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace AudioOutput { + +/** @brief + * Defines methods for implementing application-specific logic for the Audio Output Cluster. + */ +class Delegate +{ +public: + virtual uint8_t HandleGetCurrentOutput() = 0; + virtual std::list HandleGetOutputList() = 0; + + virtual bool HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name) = 0; + virtual bool HandleSelectOutput(const uint8_t & index) = 0; + + virtual ~Delegate() = default; +}; + +} // namespace AudioOutput +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/audio-output-server/audio-output-server.cpp b/src/app/clusters/audio-output-server/audio-output-server.cpp index ac4a56e932d31a..fb8ff0b401919d 100644 --- a/src/app/clusters/audio-output-server/audio-output-server.cpp +++ b/src/app/clusters/audio-output-server/audio-output-server.cpp @@ -22,25 +22,155 @@ ******************************************************************************* ******************************************************************************/ -#include +#include +#include + +#include #include #include -#include +#include +#include using namespace chip; using namespace chip::app::Clusters::AudioOutput; -bool audioOutputClusterSelectOutput(uint8_t index); -bool audioOutputClusterRenameOutput(uint8_t index, const CharSpan & name); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::AudioOutput::Delegate; + +namespace { + +Delegate * gDelegateTable[EMBER_AF_AUDIO_OUTPUT_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::AudioOutput::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) + { + ChipLogError(Zcl, "Audio Output has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace AudioOutput { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::AudioOutput::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} + +} // namespace AudioOutput +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Attribute Accessor Implementation + +namespace { + +class AudioOutputAttrAccess : public app::AttributeAccessInterface +{ +public: + AudioOutputAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::AudioOutput::Id) + {} + + CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; + +private: + CHIP_ERROR ReadOutputListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadCurrentOutputAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +AudioOutputAttrAccess gAudioOutputAttrAccess; + +CHIP_ERROR AudioOutputAttrAccess::Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + switch (aPath.mAttributeId) + { + case app::Clusters::AudioOutput::Attributes::AudioOutputList::Id: { + return ReadOutputListAttribute(aEncoder, delegate); + } + case app::Clusters::AudioOutput::Attributes::CurrentAudioOutput::Id: { + return ReadCurrentOutputAttribute(aEncoder, delegate); + } + default: { + break; + } + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR AudioOutputAttrAccess::ReadOutputListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + std::list outputList = delegate->HandleGetOutputList(); + return aEncoder.EncodeList([outputList](const auto & encoder) -> CHIP_ERROR { + for (const auto & output : outputList) + { + ReturnErrorOnFailure(encoder.Encode(output)); + } + return CHIP_NO_ERROR; + }); +} + +CHIP_ERROR AudioOutputAttrAccess::ReadCurrentOutputAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint8_t currentOutput = delegate->HandleGetCurrentOutput(); + return aEncoder.Encode(currentOutput); +} + +} // anonymous namespace + +// ----------------------------------------------------------------------------- +// Matter Framework Callbacks Implementation bool emberAfAudioOutputClusterRenameOutputRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::RenameOutputRequest::DecodableType & commandData) { - auto & index = commandData.index; - auto & name = commandData.name; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & index = commandData.index; + auto & name = commandData.name; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); - bool success = audioOutputClusterRenameOutput(index, name); +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfAudioOutputClusterRenameOutputRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + + bool success = delegate->HandleRenameOutput(index, name); EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; @@ -50,12 +180,27 @@ bool emberAfAudioOutputClusterSelectOutputRequestCallback(app::CommandHandler * const app::ConcreteCommandPath & commandPath, const Commands::SelectOutputRequest::DecodableType & commandData) { - auto & index = commandData.index; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & index = commandData.index; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfAudioOutputClusterSelectOutputRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } - bool success = audioOutputClusterSelectOutput(index); + bool success = delegate->HandleSelectOutput(index); EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; } -void MatterAudioOutputPluginServerInitCallback() {} +void MatterAudioOutputPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gAudioOutputAttrAccess); +} diff --git a/src/app/clusters/audio-output-server/audio-output-server.h b/src/app/clusters/audio-output-server/audio-output-server.h new file mode 100644 index 00000000000000..f7fab288c8648b --- /dev/null +++ b/src/app/clusters/audio-output-server/audio-output-server.h @@ -0,0 +1,39 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**************************************************************************** + * @file + * @brief Routines for the Audio Output plugin, the + *server implementation of the Audio Output cluster. + ******************************************************************************* + ******************************************************************************/ + +#pragma once + +#include "audio-output-delegate.h" +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace AudioOutput { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace AudioOutput +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/channel-server/channel-delegate.h b/src/app/clusters/channel-server/channel-delegate.h new file mode 100644 index 00000000000000..0195c1004389b7 --- /dev/null +++ b/src/app/clusters/channel-server/channel-delegate.h @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace Channel { + +/** @brief + * Defines methods for implementing application-specific logic for the Channel Cluster. + */ +class Delegate +{ +public: + virtual std::list HandleGetChannelList() = 0; + virtual chip::app::Clusters::Channel::Structs::LineupInfo::Type HandleGetLineup() = 0; + virtual chip::app::Clusters::Channel::Structs::ChannelInfo::Type HandleGetCurrentChannel() = 0; + + virtual Commands::ChangeChannelResponse::Type HandleChangeChannel(const chip::CharSpan & match) = 0; + virtual bool HandleChangeChannelByNumber(const uint16_t & majorNumber, const uint16_t & minorNumber) = 0; + virtual bool HandleSkipChannel(const uint16_t & count) = 0; + + virtual ~Delegate() = default; +}; + +} // namespace Channel +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/channel-server/channel-server.cpp b/src/app/clusters/channel-server/channel-server.cpp index c0f06252489f87..c5f08c427a750d 100644 --- a/src/app/clusters/channel-server/channel-server.cpp +++ b/src/app/clusters/channel-server/channel-server.cpp @@ -33,39 +33,169 @@ */ /**************************************************************************** * @file - * @brief Routines for the TV Channel plugin, the - *server implementation of the TV Channel cluster. + * @brief Routines for the Channel plugin, the + *server implementation of the Channel cluster. ******************************************************************************* ******************************************************************************/ -#include -#include +#include +#include + +#include #include #include -#include +#include +#include using namespace chip; -using namespace chip::app::Clusters; using namespace chip::app::Clusters::Channel; -::ChannelInfo ChannelClusterChangeChannel(std::string match); -bool ChannelClusterChangeChannelByNumber(uint16_t majorNumer, uint16_t minorNumber); -bool ChannelClusterSkipChannel(uint16_t count); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::Channel::Delegate; + +namespace { + +Delegate * gDelegateTable[EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::Channel::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) + { + ChipLogError(Zcl, "Channel has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace Channel { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::Channel::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} + +} // namespace Channel +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Attribute Accessor Implementation + +namespace { + +class ChannelAttrAccess : public app::AttributeAccessInterface +{ +public: + ChannelAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::Channel::Id) {} + + CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; + +private: + CHIP_ERROR ReadChannelListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadLineupAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadCurrentChannelAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +ChannelAttrAccess gChannelAttrAccess; + +CHIP_ERROR ChannelAttrAccess::Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + switch (aPath.mAttributeId) + { + case app::Clusters::Channel::Attributes::ChannelList::Id: { + return ReadChannelListAttribute(aEncoder, delegate); + } + case app::Clusters::Channel::Attributes::ChannelLineup::Id: { + return ReadLineupAttribute(aEncoder, delegate); + } + case app::Clusters::Channel::Attributes::CurrentChannel::Id: { + return ReadCurrentChannelAttribute(aEncoder, delegate); + } + default: { + break; + } + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR ChannelAttrAccess::ReadChannelListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + std::list channelList = delegate->HandleGetChannelList(); + return aEncoder.EncodeList([channelList](const auto & encoder) -> CHIP_ERROR { + for (const auto & channel : channelList) + { + ReturnErrorOnFailure(encoder.Encode(channel)); + } + return CHIP_NO_ERROR; + }); +} + +CHIP_ERROR ChannelAttrAccess::ReadLineupAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + Structs::LineupInfo::Type lineup = delegate->HandleGetLineup(); + return aEncoder.Encode(lineup); +} + +CHIP_ERROR ChannelAttrAccess::ReadCurrentChannelAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + Structs::ChannelInfo::Type currentChannel = delegate->HandleGetCurrentChannel(); + return aEncoder.Encode(currentChannel); +} + +} // anonymous namespace + +// ----------------------------------------------------------------------------- +// Matter Framework Callbacks Implementation bool emberAfChannelClusterChangeChannelRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::ChangeChannelRequest::DecodableType & commandData) { - Commands::ChangeChannelResponse::Type response; - response.channelMatch.majorNumber = 1; - response.channelMatch.minorNumber = 0; - response.channelMatch.name = chip::CharSpan("name", strlen("name")); - response.channelMatch.callSign = chip::CharSpan("callSign", strlen("callSign")); - response.channelMatch.affiliateCallSign = chip::CharSpan("affiliateCallSign", strlen("affiliateCallSign")); - response.errorType = (ErrorTypeEnum) 0; - - CHIP_ERROR err = command->AddResponseData(commandPath, response); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + auto & match = commandData.match; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + { + Commands::ChangeChannelResponse::Type response = delegate->HandleChangeChannel(match); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: if (err != CHIP_NO_ERROR) { + ChipLogError(Zcl, "emberAfChannelClusterChangeChannelRequestCallback error: %s", err.AsString()); emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); } return true; @@ -75,10 +205,23 @@ bool emberAfChannelClusterChangeChannelByNumberRequestCallback( app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::ChangeChannelByNumberRequest::DecodableType & commandData) { + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & majorNumber = commandData.majorNumber; auto & minorNumber = commandData.minorNumber; - bool success = ChannelClusterChangeChannelByNumber(majorNumber, minorNumber); + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfChannelClusterChangeChannelByNumberRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + + bool success = delegate->HandleChangeChannelByNumber(majorNumber, minorNumber); EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; @@ -87,12 +230,27 @@ bool emberAfChannelClusterChangeChannelByNumberRequestCallback( bool emberAfChannelClusterSkipChannelRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::SkipChannelRequest::DecodableType & commandData) { - auto & count = commandData.count; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & count = commandData.count; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); - bool success = ChannelClusterSkipChannel(count); +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfChannelClusterSkipChannelRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + + bool success = delegate->HandleSkipChannel(count); EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; } -void MatterChannelPluginServerInitCallback() {} +void MatterChannelPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gChannelAttrAccess); +} diff --git a/src/app/clusters/channel-server/channel-server.h b/src/app/clusters/channel-server/channel-server.h new file mode 100644 index 00000000000000..4901cb94e29296 --- /dev/null +++ b/src/app/clusters/channel-server/channel-server.h @@ -0,0 +1,39 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**************************************************************************** + * @file + * @brief Routines for the Channel plugin, the + *server implementation of the Channel cluster. + ******************************************************************************* + ******************************************************************************/ + +#pragma once + +#include "channel-delegate.h" +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace Channel { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace Channel +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/content-launch-server/content-launch-delegate.h b/src/app/clusters/content-launch-server/content-launch-delegate.h index fb86310ca470d1..0ac1da2bf96a0a 100644 --- a/src/app/clusters/content-launch-server/content-launch-delegate.h +++ b/src/app/clusters/content-launch-server/content-launch-delegate.h @@ -20,19 +20,10 @@ #include #include -#include #include -#include #include -struct LaunchResponse -{ - CHIP_ERROR err; - chip::CharSpan data; - chip::app::Clusters::ContentLauncher::StatusEnum status; -}; - namespace chip { namespace app { namespace Clusters { @@ -44,11 +35,12 @@ namespace ContentLauncher { class Delegate { public: - virtual LaunchResponse HandleLaunchContent(chip::EndpointId endpointId, const std::list & parameterList, - bool autoplay, const chip::CharSpan & data) = 0; + virtual Commands::LaunchResponse::Type HandleLaunchContent(chip::EndpointId endpointId, + const std::list & parameterList, bool autoplay, + const chip::CharSpan & data) = 0; - virtual LaunchResponse HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString, - const std::list & brandingInformation) = 0; + virtual Commands::LaunchResponse::Type HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString, + const std::list & brandingInformation) = 0; virtual std::list HandleGetAcceptHeaderList() = 0; diff --git a/src/app/clusters/content-launch-server/content-launch-server.cpp b/src/app/clusters/content-launch-server/content-launch-server.cpp index 52624611c9b211..286e141bd324b1 100644 --- a/src/app/clusters/content-launch-server/content-launch-server.cpp +++ b/src/app/clusters/content-launch-server/content-launch-server.cpp @@ -38,22 +38,19 @@ ******************************************************************************* ******************************************************************************/ -#include "content-launch-server.h" - -#include -#include -#include +#include +#include #include #include #include #include -#include #include #include using namespace chip; using namespace chip::app; +using namespace chip::app::Clusters::ContentLauncher; // ----------------------------------------------------------------------------- // Delegate Implementation @@ -119,7 +116,7 @@ class ContentLauncherAttrAccess : public app::AttributeAccessInterface private: CHIP_ERROR ReadAcceptHeaderAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); - CHIP_ERROR ReadSupportedStreamingProtocols(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadSupportedStreamingProtocolsAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); }; ContentLauncherAttrAccess gContentLauncherAttrAccess; @@ -140,7 +137,7 @@ CHIP_ERROR ContentLauncherAttrAccess::Read(const app::ConcreteReadAttributePath return ReadAcceptHeaderAttribute(aEncoder, delegate); } case app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::Id: { - return ReadSupportedStreamingProtocols(aEncoder, delegate); + return ReadSupportedStreamingProtocolsAttribute(aEncoder, delegate); } default: { break; @@ -163,7 +160,8 @@ CHIP_ERROR ContentLauncherAttrAccess::ReadAcceptHeaderAttribute(app::AttributeVa }); } -CHIP_ERROR ContentLauncherAttrAccess::ReadSupportedStreamingProtocols(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +CHIP_ERROR ContentLauncherAttrAccess::ReadSupportedStreamingProtocolsAttribute(app::AttributeValueEncoder & aEncoder, + Delegate * delegate) { uint32_t streamingProtocols = delegate->HandleGetSupportedStreamingProtocols(); return aEncoder.Encode(streamingProtocols); @@ -178,8 +176,7 @@ bool emberAfContentLauncherClusterLaunchContentRequestCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::ContentLauncher::Commands::LaunchContentRequest::DecodableType & commandData) { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type response; + CHIP_ERROR err = CHIP_NO_ERROR; EndpointId endpoint = commandPath.mEndpointId; auto & autoplay = commandData.autoPlay; @@ -192,20 +189,15 @@ bool emberAfContentLauncherClusterLaunchContentRequestCallback( VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); { - LaunchResponse resp = delegate->HandleLaunchContent(emberAfCurrentEndpoint(), parameterList, autoplay, data); - VerifyOrExit(resp.err == CHIP_NO_ERROR, err = resp.err); - - response.status = resp.status; - response.data = resp.data; - - err = commandObj->AddResponseData(commandPath, response); + Commands::LaunchResponse::Type response = delegate->HandleLaunchContent(endpoint, parameterList, autoplay, data); + err = commandObj->AddResponseData(commandPath, response); SuccessOrExit(err); } exit: if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "emberAfContentLauncherClusterLaunchContentCallback error: %s", err.AsString()); + ChipLogError(Zcl, "emberAfContentLauncherClusterLaunchContentRequestCallback error: %s", err.AsString()); emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); } @@ -217,8 +209,7 @@ bool emberAfContentLauncherClusterLaunchURLRequestCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::ContentLauncher::Commands::LaunchURLRequest::DecodableType & commandData) { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::app::Clusters::ContentLauncher::Commands::LaunchResponse::Type response; + CHIP_ERROR err = CHIP_NO_ERROR; EndpointId endpoint = commandPath.mEndpointId; auto & contentUrl = commandData.contentURL; @@ -231,13 +222,8 @@ bool emberAfContentLauncherClusterLaunchURLRequestCallback( VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); { - LaunchResponse resp = delegate->HandleLaunchUrl(contentUrl, displayString, brandingInformationList); - VerifyOrExit(resp.err == CHIP_NO_ERROR, err = resp.err); - - response.status = resp.status; - response.data = resp.data; - - err = commandObj->AddResponseData(commandPath, response); + Commands::LaunchResponse::Type response = delegate->HandleLaunchUrl(contentUrl, displayString, brandingInformationList); + err = commandObj->AddResponseData(commandPath, response); SuccessOrExit(err); } diff --git a/src/app/clusters/content-launch-server/content-launch-server.h b/src/app/clusters/content-launch-server/content-launch-server.h index 7a0911078ffad5..b41472a3af1a35 100644 --- a/src/app/clusters/content-launch-server/content-launch-server.h +++ b/src/app/clusters/content-launch-server/content-launch-server.h @@ -19,7 +19,6 @@ #include "content-launch-delegate.h" #include -#include namespace chip { namespace app { diff --git a/examples/tv-app/linux/include/application-basic/Application.h b/src/app/clusters/keypad-input-server/keypad-input-delegate.h similarity index 59% rename from examples/tv-app/linux/include/application-basic/Application.h rename to src/app/clusters/keypad-input-server/keypad-input-delegate.h index 428301c69833f2..633b9a4cfa2f87 100644 --- a/examples/tv-app/linux/include/application-basic/Application.h +++ b/src/app/clusters/keypad-input-server/keypad-input-delegate.h @@ -20,24 +20,25 @@ #include +#include + namespace chip { namespace app { namespace Clusters { -namespace ApplicationBasic { -struct Application +namespace KeypadInput { + +/** @brief + * Defines methods for implementing application-specific logic for the Keypad Input Cluster. + */ +class Delegate { - using ApplicationBasicStatus = chip::app::Clusters::ApplicationBasic::ApplicationStatusEnum; - char vendorName[32] = ""; - char name[32] = ""; - char id[32] = ""; - char version[32] = ""; - uint16_t vendorId = 0; - uint16_t productId = 0; - uint16_t catalogVendorId = 0; - uint16_t allowedVendorList[32] = { 123, 456 }; - ApplicationBasicStatus status = ApplicationBasicStatus::kStopped; +public: + virtual Commands::SendKeyResponse::Type HandleSendKey(const CecKeyCode & keyCode) = 0; + + virtual ~Delegate() = default; }; -} // namespace ApplicationBasic + +} // namespace KeypadInput } // namespace Clusters } // namespace app } // namespace chip diff --git a/src/app/clusters/keypad-input-server/keypad-input-server.cpp b/src/app/clusters/keypad-input-server/keypad-input-server.cpp index b6802e9785febe..bd97df20f97fc1 100644 --- a/src/app/clusters/keypad-input-server/keypad-input-server.cpp +++ b/src/app/clusters/keypad-input-server/keypad-input-server.cpp @@ -21,47 +21,89 @@ ******************************************************************************* ******************************************************************************/ -#include -#include -#include -#include -#include +#include +#include + #include #include -#include +#include using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::KeypadInput; -StatusEnum keypadInputClusterSendKey(CecKeyCode keyCode); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::KeypadInput::Delegate; + +namespace { + +Delegate * gDelegateTable[EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::KeypadInput::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} -static void sendResponse(app::CommandHandler * command, StatusEnum keypadInputStatus) +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), KeypadInput::Id, KeypadInput::Commands::SendKeyResponse::Id }; - TLV::TLVWriter * writer = nullptr; + if (delegate == nullptr) + { + ChipLogError(Zcl, "Keypad Input has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace - VerifyOrExit(command != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = command->PrepareCommand(path)); - VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = writer->Put(TLV::ContextTag(0), keypadInputStatus)); - SuccessOrExit(err = command->FinishCommand()); +namespace chip { +namespace app { +namespace Clusters { +namespace KeypadInput { -exit: - if (err != CHIP_NO_ERROR) +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::KeypadInput::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else { - ChipLogError(Zcl, "Failed to encode KeypadInputResponse command. Error:%s", ErrorStr(err)); } } +} // namespace KeypadInput +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Matter Framework Callbacks Implementation + bool emberAfKeypadInputClusterSendKeyRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::SendKeyRequest::DecodableType & commandData) { - auto & keyCode = commandData.keyCode; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & keyCode = commandData.keyCode; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + { + Commands::SendKeyResponse::Type response = delegate->HandleSendKey(keyCode); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } - StatusEnum status = keypadInputClusterSendKey(static_cast(keyCode)); - sendResponse(command, status); +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfKeypadInputClusterSendKeyRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } return true; } diff --git a/src/app/clusters/keypad-input-server/keypad-input-server.h b/src/app/clusters/keypad-input-server/keypad-input-server.h new file mode 100644 index 00000000000000..e73552e6700ff9 --- /dev/null +++ b/src/app/clusters/keypad-input-server/keypad-input-server.h @@ -0,0 +1,39 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**************************************************************************** + * @file + * @brief Routines for the Keypad Input plugin, the + *server implementation of the Keypad Input cluster. + ******************************************************************************* + ******************************************************************************/ + +#pragma once + +#include "keypad-input-delegate.h" +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace KeypadInput { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace KeypadInput +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/low-power-server/low-power-delegate.h b/src/app/clusters/low-power-server/low-power-delegate.h new file mode 100644 index 00000000000000..75b0ba2771cb67 --- /dev/null +++ b/src/app/clusters/low-power-server/low-power-delegate.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace LowPower { + +/** @brief + * Defines methods for implementing application-specific logic for the Low Power Cluster. + */ +class Delegate +{ +public: + virtual bool HandleSleep() = 0; + + virtual ~Delegate() = default; +}; + +} // namespace LowPower +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/low-power-server/low-power-server.cpp b/src/app/clusters/low-power-server/low-power-server.cpp index 59fb42b2c42bc5..9f43fb3a3604b3 100644 --- a/src/app/clusters/low-power-server/low-power-server.cpp +++ b/src/app/clusters/low-power-server/low-power-server.cpp @@ -18,11 +18,13 @@ /**************************************************************************** * @file * @brief Routines for the Low Power plugin, the - *server implementation of the Low power cluster. + *server implementation of the Low Power cluster. ******************************************************************************* ******************************************************************************/ -#include +#include +#include + #include #include #include @@ -30,12 +32,71 @@ using namespace chip; using namespace chip::app::Clusters::LowPower; -bool lowPowerClusterSleep(); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::LowPower::Delegate; + +namespace { + +Delegate * gDelegateTable[EMBER_AF_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) + { + ChipLogError(Zcl, "LowPower has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace LowPower { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} + +} // namespace LowPower +} // namespace Clusters +} // namespace app +} // namespace chip bool emberAfLowPowerClusterSleepCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::Sleep::DecodableType & commandData) { - bool success = lowPowerClusterSleep(); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfLowPowerClusterSleepCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + + bool success = delegate->HandleSleep(); EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; diff --git a/src/app/clusters/low-power-server/low-power-server.h b/src/app/clusters/low-power-server/low-power-server.h new file mode 100644 index 00000000000000..27ca2bc8ae8ab7 --- /dev/null +++ b/src/app/clusters/low-power-server/low-power-server.h @@ -0,0 +1,38 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**************************************************************************** + * @file + * @brief Routines for the Low Power plugin, the + *server implementation of the Low Power cluster. + ******************************************************************************* + ******************************************************************************/ + +#pragma once + +#include "low-power-delegate.h" + +namespace chip { +namespace app { +namespace Clusters { +namespace LowPower { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace LowPower +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/media-input-server/media-input-delegate.h b/src/app/clusters/media-input-server/media-input-delegate.h new file mode 100644 index 00000000000000..b596a9c5e58b2f --- /dev/null +++ b/src/app/clusters/media-input-server/media-input-delegate.h @@ -0,0 +1,50 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace MediaInput { + +/** @brief + * Defines methods for implementing application-specific logic for the Media Input Cluster. + */ +class Delegate +{ +public: + virtual std::list HandleGetInputList() = 0; + virtual uint8_t HandleGetCurrentInput() = 0; + virtual bool HandleSelectInput(const uint8_t index) = 0; + virtual bool HandleShowInputStatus() = 0; + virtual bool HandleHideInputStatus() = 0; + virtual bool HandleRenameInput(const uint8_t index, const chip::CharSpan & name) = 0; + + virtual ~Delegate() = default; +}; + +} // namespace MediaInput +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/media-input-server/media-input-server.cpp b/src/app/clusters/media-input-server/media-input-server.cpp index 95eb498decbfef..896a759ba0a758 100644 --- a/src/app/clusters/media-input-server/media-input-server.cpp +++ b/src/app/clusters/media-input-server/media-input-server.cpp @@ -21,42 +21,155 @@ ******************************************************************************* ******************************************************************************/ -#include -#include +#include "media-input-server.h" +#include "media-input-delegate.h" + +#include #include #include -#include -#include +#include +#include using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::MediaInput; -bool mediaInputClusterSelectInput(uint8_t input); -bool mediaInputClusterShowInputStatus(); -bool mediaInputClusterHideInputStatus(); -bool mediaInputClusterRenameInput(uint8_t input, std::string name); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::MediaInput::Delegate; + +namespace { -static void storeCurrentInput(EndpointId endpoint, uint8_t currentInput) +Delegate * gDelegateTable[EMBER_AF_MEDIA_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) { - EmberAfStatus status = Attributes::CurrentMediaInput::Set(endpoint, currentInput); - if (status != EMBER_ZCL_STATUS_SUCCESS) + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::MediaInput::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) { - ChipLogError(Zcl, "Failed to store media playback attribute."); + ChipLogError(Zcl, "Media Input has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace MediaInput { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::MediaInput::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} + +} // namespace MediaInput +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Attribute Accessor Implementation + +namespace { + +class MediaInputAttrAccess : public app::AttributeAccessInterface +{ +public: + MediaInputAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::MediaInput::Id) {} + + CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; + +private: + CHIP_ERROR ReadInputListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadCurrentInputAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +MediaInputAttrAccess gMediaInputAttrAccess; + +CHIP_ERROR MediaInputAttrAccess::Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + switch (aPath.mAttributeId) + { + case app::Clusters::MediaInput::Attributes::MediaInputList::Id: { + return ReadInputListAttribute(aEncoder, delegate); + } + case app::Clusters::MediaInput::Attributes::CurrentMediaInput::Id: { + return ReadCurrentInputAttribute(aEncoder, delegate); } + default: { + break; + } + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR MediaInputAttrAccess::ReadInputListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + std::list inputList = delegate->HandleGetInputList(); + return aEncoder.EncodeList([inputList](const auto & encoder) -> CHIP_ERROR { + for (const auto & input : inputList) + { + ReturnErrorOnFailure(encoder.Encode(input)); + } + return CHIP_NO_ERROR; + }); +} + +CHIP_ERROR MediaInputAttrAccess::ReadCurrentInputAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint8_t currentInput = delegate->HandleGetCurrentInput(); + return aEncoder.Encode(currentInput); } +} // anonymous namespace + +// ----------------------------------------------------------------------------- +// Matter Framework Callbacks Implementation + bool emberAfMediaInputClusterSelectInputRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::SelectInputRequest::DecodableType & commandData) { + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & input = commandData.index; - bool success = mediaInputClusterSelectInput(input); - EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; - if (success) + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + +exit: + if (err != CHIP_NO_ERROR) { - storeCurrentInput(emberAfCurrentEndpoint(), input); + ChipLogError(Zcl, "emberAfMediaInputClusterSelectInputRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); } + + bool success = delegate->HandleSelectInput(input); + EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; } @@ -65,7 +178,20 @@ bool emberAfMediaInputClusterShowInputStatusRequestCallback(app::CommandHandler const app::ConcreteCommandPath & commandPath, const Commands::ShowInputStatusRequest::DecodableType & commandData) { - bool success = mediaInputClusterShowInputStatus(); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaInputClusterShowInputStatusRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + + bool success = delegate->HandleShowInputStatus(); EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; @@ -75,7 +201,20 @@ bool emberAfMediaInputClusterHideInputStatusRequestCallback(app::CommandHandler const app::ConcreteCommandPath & commandPath, const Commands::HideInputStatusRequest::DecodableType & commandData) { - bool success = mediaInputClusterHideInputStatus(); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaInputClusterHideInputStatusRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + + bool success = delegate->HandleHideInputStatus(); EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; @@ -84,15 +223,28 @@ bool emberAfMediaInputClusterHideInputStatusRequestCallback(app::CommandHandler bool emberAfMediaInputClusterRenameInputRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::RenameInputRequest::DecodableType & commandData) { - auto & input = commandData.index; - auto & name = commandData.name; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & index = commandData.index; + auto & name = commandData.name; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaInputClusterRenameInputRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } - // TODO: char is not null terminated, verify this code once #7963 gets merged. - std::string nameString(name.data(), name.size()); - bool success = mediaInputClusterRenameInput(input, nameString); + bool success = delegate->HandleRenameInput(index, name); EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; } -void MatterMediaInputPluginServerInitCallback() {} +void MatterMediaInputPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gMediaInputAttrAccess); +} diff --git a/src/app/clusters/media-input-server/media-input-server.h b/src/app/clusters/media-input-server/media-input-server.h new file mode 100644 index 00000000000000..12f45a0e8a1bbd --- /dev/null +++ b/src/app/clusters/media-input-server/media-input-server.h @@ -0,0 +1,39 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**************************************************************************** + * @file + * @brief Routines for the Media Input plugin, the + *server implementation of the Media Input cluster. + ******************************************************************************* + ******************************************************************************/ + +#pragma once + +#include "media-input-delegate.h" +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace MediaInput { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace MediaInput +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/media-playback-server/media-playback-delegate.h b/src/app/clusters/media-playback-server/media-playback-delegate.h new file mode 100644 index 00000000000000..ed7b43d1b3b98f --- /dev/null +++ b/src/app/clusters/media-playback-server/media-playback-delegate.h @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace MediaPlayback { + +/** @brief + * Defines methods for implementing application-specific logic for the Media Playback Cluster. + */ +class Delegate +{ +public: + virtual PlaybackStateEnum HandleGetCurrentState() = 0; + virtual uint64_t HandleGetStartTime() = 0; + virtual uint64_t HandleGetDuration() = 0; + virtual Structs::PlaybackPosition::Type HandleGetSampledPosition() = 0; + virtual float HandleGetPlaybackSpeed() = 0; + virtual uint64_t HandleGetSeekRangeStart() = 0; + virtual uint64_t HandleGetSeekRangeEnd() = 0; + + virtual Commands::PlaybackResponse::Type HandlePlay() = 0; + virtual Commands::PlaybackResponse::Type HandlePause() = 0; + virtual Commands::PlaybackResponse::Type HandleStop() = 0; + virtual Commands::PlaybackResponse::Type HandleFastForward() = 0; + virtual Commands::PlaybackResponse::Type HandlePrevious() = 0; + virtual Commands::PlaybackResponse::Type HandleRewind() = 0; + virtual Commands::PlaybackResponse::Type HandleSkipBackward(const uint64_t & deltaPositionMilliseconds) = 0; + virtual Commands::PlaybackResponse::Type HandleSkipForward(const uint64_t & deltaPositionMilliseconds) = 0; + virtual Commands::PlaybackResponse::Type HandleSeekRequest(const uint64_t & positionMilliseconds) = 0; + virtual Commands::PlaybackResponse::Type HandleNext() = 0; + virtual Commands::PlaybackResponse::Type HandleStartOverRequest() = 0; + + virtual ~Delegate() = default; +}; + +} // namespace MediaPlayback +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/media-playback-server/media-playback-server.cpp b/src/app/clusters/media-playback-server/media-playback-server.cpp index 03480ca6eee4f7..38746abdf612b5 100644 --- a/src/app/clusters/media-playback-server/media-playback-server.cpp +++ b/src/app/clusters/media-playback-server/media-playback-server.cpp @@ -22,99 +22,253 @@ ******************************************************************************* ******************************************************************************/ -#include -#include +#include +#include + +#include #include #include -#include -#include +#include +#include using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::MediaPlayback; -StatusEnum mediaPlaybackClusterSendMediaPlaybackRequest(MediaPlaybackRequest mediaPlaybackRequest, - uint64_t deltaPositionMilliseconds); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::MediaPlayback::Delegate; + +namespace { + +Delegate * gDelegateTable[EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; -static void writePlaybackState(EndpointId endpoint, MediaPlayback::PlaybackStateEnum playbackState) +Delegate * GetDelegate(EndpointId endpoint) { - EmberAfStatus status = Attributes::PlaybackState::Set(endpoint, playbackState); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - ChipLogError(Zcl, "Failed to store media playback attribute."); - } + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::MediaPlayback::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); } -static PlaybackStateEnum readPlaybackStatus(EndpointId endpoint) +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) { - chip::app::Clusters::MediaPlayback::PlaybackStateEnum playbackState; - EmberAfStatus status = Attributes::PlaybackState::Get(endpoint, &playbackState); - if (status != EMBER_ZCL_STATUS_SUCCESS) + if (delegate == nullptr) { - ChipLogError(Zcl, "Failed to read media playback attribute."); + ChipLogError(Zcl, "Media Playback has no delegate set for endpoint:%" PRIu16, endpoint); + return true; } - - return playbackState; + return false; } +} // namespace -void storeNewPlaybackState(EndpointId endpoint, MediaPlayback::PlaybackStateEnum newPlaybackState) -{ - MediaPlayback::PlaybackStateEnum mediaPlaybackClusterPlaybackState = readPlaybackStatus(endpoint); +namespace chip { +namespace app { +namespace Clusters { +namespace MediaPlayback { - if (mediaPlaybackClusterPlaybackState == newPlaybackState) +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::MediaPlayback::Id); + if (ep != 0xFFFF) { - return; + gDelegateTable[ep] = delegate; } else { - writePlaybackState(endpoint, newPlaybackState); } } -static void sendResponse(app::CommandHandler * command, const char * responseName, CommandId commandId, - StatusEnum mediaPlaybackStatus) +} // namespace MediaPlayback +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Attribute Accessor Implementation + +namespace { + +class MediaPlaybackAttrAccess : public app::AttributeAccessInterface { - CHIP_ERROR err = CHIP_NO_ERROR; - app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), MediaPlayback::Id, commandId }; - TLV::TLVWriter * writer = nullptr; +public: + MediaPlaybackAttrAccess() : + app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::MediaPlayback::Id) + {} - VerifyOrExit(command != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = command->PrepareCommand(path)); - VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = writer->Put(TLV::ContextTag(0), mediaPlaybackStatus)); - SuccessOrExit(err = command->FinishCommand()); + CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; -exit: - if (err != CHIP_NO_ERROR) +private: + CHIP_ERROR ReadCurrentStateAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadStartTimeAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadDurationAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadSampledPositionAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadPlaybackSpeedAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadSeekRangeStartAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadSeekRangeEndAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +MediaPlaybackAttrAccess gMediaPlaybackAttrAccess; + +CHIP_ERROR MediaPlaybackAttrAccess::Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + switch (aPath.mAttributeId) { - ChipLogError(Zcl, "Failed to send %s. Error:%s", responseName, ErrorStr(err)); + case app::Clusters::MediaPlayback::Attributes::PlaybackState::Id: { + return ReadCurrentStateAttribute(aEncoder, delegate); + } + case app::Clusters::MediaPlayback::Attributes::StartTime::Id: { + return ReadStartTimeAttribute(aEncoder, delegate); + } + case app::Clusters::MediaPlayback::Attributes::Duration::Id: { + return ReadDurationAttribute(aEncoder, delegate); + } + case app::Clusters::MediaPlayback::Attributes::Position::Id: { + return ReadSampledPositionAttribute(aEncoder, delegate); + } + case app::Clusters::MediaPlayback::Attributes::PlaybackSpeed::Id: { + return ReadPlaybackSpeedAttribute(aEncoder, delegate); } + case app::Clusters::MediaPlayback::Attributes::SeekRangeStart::Id: { + return ReadSeekRangeStartAttribute(aEncoder, delegate); + } + case app::Clusters::MediaPlayback::Attributes::SeekRangeEnd::Id: { + return ReadSeekRangeEndAttribute(aEncoder, delegate); + } + default: { + break; + } + } + + return CHIP_NO_ERROR; } +CHIP_ERROR MediaPlaybackAttrAccess::ReadCurrentStateAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + chip::app::Clusters::MediaPlayback::PlaybackStateEnum currentState = delegate->HandleGetCurrentState(); + return aEncoder.Encode(currentState); +} + +CHIP_ERROR MediaPlaybackAttrAccess::ReadStartTimeAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint64_t startTime = delegate->HandleGetStartTime(); + return aEncoder.Encode(startTime); +} + +CHIP_ERROR MediaPlaybackAttrAccess::ReadDurationAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint64_t duration = delegate->HandleGetDuration(); + return aEncoder.Encode(duration); +} + +CHIP_ERROR MediaPlaybackAttrAccess::ReadSampledPositionAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + Structs::PlaybackPosition::Type sampledPosition = delegate->HandleGetSampledPosition(); + return aEncoder.Encode(sampledPosition); +} + +CHIP_ERROR MediaPlaybackAttrAccess::ReadPlaybackSpeedAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + float playbackSpeed = delegate->HandleGetPlaybackSpeed(); + return aEncoder.Encode(playbackSpeed); +} + +CHIP_ERROR MediaPlaybackAttrAccess::ReadSeekRangeStartAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint64_t seekRangeStart = delegate->HandleGetSeekRangeStart(); + return aEncoder.Encode(seekRangeStart); +} + +CHIP_ERROR MediaPlaybackAttrAccess::ReadSeekRangeEndAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint64_t seekRangeEnd = delegate->HandleGetSeekRangeEnd(); + return aEncoder.Encode(seekRangeEnd); +} + +} // anonymous namespace + +// ----------------------------------------------------------------------------- +// Matter Framework Callbacks Implementation + bool emberAfMediaPlaybackClusterPlayRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::PlayRequest::DecodableType & commandData) { - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_PLAY, 0); - storeNewPlaybackState(emberAfCurrentEndpoint(), MediaPlayback::PlaybackStateEnum::kPlaying); - sendResponse(command, "MediaPlayResponse", Commands::PlaybackResponse::Id, status); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandlePlay(); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterPlayRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } bool emberAfMediaPlaybackClusterPauseRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::PauseRequest::DecodableType & commandData) { - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_PAUSE, 0); - storeNewPlaybackState(emberAfCurrentEndpoint(), MediaPlayback::PlaybackStateEnum::kPaused); - sendResponse(command, "MediaPauseResponse", Commands::PlaybackResponse::Id, status); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandlePause(); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterPauseRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } bool emberAfMediaPlaybackClusterStopRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::StopRequest::DecodableType & commandData) { - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_STOP, 0); - storeNewPlaybackState(emberAfCurrentEndpoint(), MediaPlayback::PlaybackStateEnum::kNotPlaying); - sendResponse(command, "MediaStopResponse", Commands::PlaybackResponse::Id, status); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandleStop(); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterStopRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } @@ -122,24 +276,75 @@ bool emberAfMediaPlaybackClusterFastForwardRequestCallback(app::CommandHandler * const app::ConcreteCommandPath & commandPath, const Commands::FastForwardRequest::DecodableType & commandData) { - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_FAST_FORWARD, 0); - sendResponse(command, "MediaFastForward", Commands::PlaybackResponse::Id, status); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandleFastForward(); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterFastForwardRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } bool emberAfMediaPlaybackClusterPreviousRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::PreviousRequest::DecodableType & commandData) { - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_PREVIOUS, 0); - sendResponse(command, "MediaPrevious", Commands::PlaybackResponse::Id, status); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandlePrevious(); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterPreviousRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } bool emberAfMediaPlaybackClusterRewindRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::RewindRequest::DecodableType & commandData) { - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_REWIND, 0); - sendResponse(command, "MediaRewind", Commands::PlaybackResponse::Id, status); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandleRewind(); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterRewindRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } @@ -147,11 +352,27 @@ bool emberAfMediaPlaybackClusterSkipBackwardRequestCallback(app::CommandHandler const app::ConcreteCommandPath & commandPath, const Commands::SkipBackwardRequest::DecodableType & commandData) { + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & deltaPositionMilliseconds = commandData.deltaPositionMilliseconds; - StatusEnum status = - mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_SKIP_BACKWARD, deltaPositionMilliseconds); - sendResponse(command, "MediaSkipBackward", Commands::PlaybackResponse::Id, status); + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandleSkipBackward(deltaPositionMilliseconds); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterSkipBackwardRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } @@ -159,38 +380,107 @@ bool emberAfMediaPlaybackClusterSkipForwardRequestCallback(app::CommandHandler * const app::ConcreteCommandPath & commandPath, const Commands::SkipForwardRequest::DecodableType & commandData) { + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; auto & deltaPositionMilliseconds = commandData.deltaPositionMilliseconds; - StatusEnum status = - mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_SKIP_FORWARD, deltaPositionMilliseconds); - sendResponse(command, "MediaSkipForward", Commands::PlaybackResponse::Id, status); + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandleSkipForward(deltaPositionMilliseconds); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterSkipForwardRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } bool emberAfMediaPlaybackClusterSeekRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::SeekRequest::DecodableType & commandData) { + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; auto & positionMilliseconds = commandData.position; - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_SEEK, positionMilliseconds); - sendResponse(command, "MediaSeek", Commands::PlaybackResponse::Id, status); + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandleSeekRequest(positionMilliseconds); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterSeekRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } bool emberAfMediaPlaybackClusterNextRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::NextRequest::DecodableType & commandData) { - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_NEXT, 0); - sendResponse(command, "MediaNext", Commands::PlaybackResponse::Id, status); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandleNext(); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterNextRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } + bool emberAfMediaPlaybackClusterStartOverRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::StartOverRequest::DecodableType & commandData) { - StatusEnum status = mediaPlaybackClusterSendMediaPlaybackRequest(MEDIA_PLAYBACK_REQUEST_START_OVER, 0); - sendResponse(command, "MediaStartOver", Commands::PlaybackResponse::Id, status); + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::PlaybackResponse::Type response = delegate->HandleStartOverRequest(); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaPlaybackClusterStartOverRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } + return true; } -void MatterMediaPlaybackPluginServerInitCallback() {} +void MatterMediaPlaybackPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gMediaPlaybackAttrAccess); +} diff --git a/src/app/clusters/media-playback-server/media-playback-server.h b/src/app/clusters/media-playback-server/media-playback-server.h index 94edf7ed6fd6cc..2befa118207396 100644 --- a/src/app/clusters/media-playback-server/media-playback-server.h +++ b/src/app/clusters/media-playback-server/media-playback-server.h @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /**************************************************************************** * @file * @brief Routines for the Media Playback plugin, the @@ -24,19 +23,17 @@ #pragma once -#include +#include "media-playback-delegate.h" +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace MediaPlayback { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); -enum MediaPlaybackRequest : uint8_t -{ - MEDIA_PLAYBACK_REQUEST_PLAY = 0, - MEDIA_PLAYBACK_REQUEST_PAUSE = 1, - MEDIA_PLAYBACK_REQUEST_STOP = 2, - MEDIA_PLAYBACK_REQUEST_START_OVER = 3, - MEDIA_PLAYBACK_REQUEST_PREVIOUS = 4, - MEDIA_PLAYBACK_REQUEST_NEXT = 5, - MEDIA_PLAYBACK_REQUEST_REWIND = 6, - MEDIA_PLAYBACK_REQUEST_FAST_FORWARD = 7, - MEDIA_PLAYBACK_REQUEST_SKIP_FORWARD = 8, - MEDIA_PLAYBACK_REQUEST_SKIP_BACKWARD = 9, - MEDIA_PLAYBACK_REQUEST_SEEK = 10, -}; +} // namespace MediaPlayback +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/target-navigator-server/target-navigator-delegate.h b/src/app/clusters/target-navigator-server/target-navigator-delegate.h new file mode 100644 index 00000000000000..5c2de2a23d7287 --- /dev/null +++ b/src/app/clusters/target-navigator-server/target-navigator-delegate.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace TargetNavigator { + +/** @brief + * Defines methods for implementing application-specific logic for the Target Navigator Cluster. + */ +class Delegate +{ +public: + virtual std::list HandleGetTargetList() = 0; + virtual uint8_t HandleGetCurrentTarget() = 0; + virtual Commands::NavigateTargetResponse::Type HandleNavigateTarget(const uint64_t & target, const chip::CharSpan & data) = 0; + + virtual ~Delegate() = default; +}; + +} // namespace TargetNavigator +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/target-navigator-server/target-navigator-server.cpp b/src/app/clusters/target-navigator-server/target-navigator-server.cpp index d88ee883edca9e..13eb7552d1721d 100644 --- a/src/app/clusters/target-navigator-server/target-navigator-server.cpp +++ b/src/app/clusters/target-navigator-server/target-navigator-server.cpp @@ -22,48 +22,166 @@ ******************************************************************************* ******************************************************************************/ -#include +#include +#include + +#include #include #include -#include -#include +#include +#include using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::TargetNavigator; -TargetNavigatorResponse targetNavigatorClusterNavigateTarget(chip::EndpointId endpointId, uint8_t target, std::string data); +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::TargetNavigator::Delegate; -void sendResponse(app::CommandHandler * command, TargetNavigatorResponse response) +namespace { + +Delegate * gDelegateTable[EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), TargetNavigator::Id, - TargetNavigator::Commands::NavigateTargetResponse::Id }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = command->PrepareCommand(path)); - VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = writer->Put(TLV::ContextTag(0), response.status)); - SuccessOrExit(err = writer->PutString(TLV::ContextTag(1), reinterpret_cast(response.data))); - SuccessOrExit(err = command->FinishCommand()); -exit: - if (err != CHIP_NO_ERROR) + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::TargetNavigator::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) + { + ChipLogError(Zcl, "Target Navigator has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace TargetNavigator { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::TargetNavigator::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else { - ChipLogError(Zcl, "Failed to send NavigateTargetResponse. Error:%s", ErrorStr(err)); } } +} // namespace TargetNavigator +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Attribute Accessor Implementation + +namespace { + +class TargetNavigatorAttrAccess : public app::AttributeAccessInterface +{ +public: + TargetNavigatorAttrAccess() : + app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::TargetNavigator::Id) + {} + + CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; + +private: + CHIP_ERROR ReadTargetListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadCurrentTargetAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +TargetNavigatorAttrAccess gTargetNavigatorAttrAccess; + +CHIP_ERROR TargetNavigatorAttrAccess::Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + switch (aPath.mAttributeId) + { + case app::Clusters::TargetNavigator::Attributes::TargetNavigatorList::Id: { + return ReadTargetListAttribute(aEncoder, delegate); + } + case app::Clusters::TargetNavigator::Attributes::CurrentNavigatorTarget::Id: { + return ReadCurrentTargetAttribute(aEncoder, delegate); + } + default: { + break; + } + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR TargetNavigatorAttrAccess::ReadTargetListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + std::list targetList = delegate->HandleGetTargetList(); + return aEncoder.EncodeList([targetList](const auto & encoder) -> CHIP_ERROR { + for (const auto & target : targetList) + { + ReturnErrorOnFailure(encoder.Encode(target)); + } + return CHIP_NO_ERROR; + }); +} + +CHIP_ERROR TargetNavigatorAttrAccess::ReadCurrentTargetAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + uint8_t currentTarget = delegate->HandleGetCurrentTarget(); + return aEncoder.Encode(currentTarget); +} + +} // anonymous namespace + +// ----------------------------------------------------------------------------- +// Matter Framework Callbacks Implementation + bool emberAfTargetNavigatorClusterNavigateTargetRequestCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::NavigateTargetRequest::DecodableType & commandData) { - auto & target = commandData.target; - auto & data = commandData.data; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + auto & target = commandData.target; + auto & data = commandData.data; + + Delegate * delegate = GetDelegate(endpoint); + VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + + { + Commands::NavigateTargetResponse::Type response = delegate->HandleNavigateTarget(target, data); + err = command->AddResponseData(commandPath, response); + SuccessOrExit(err); + } + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfTargetNavigatorClusterNavigateTargetRequestCallback error: %s", err.AsString()); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + } - // TODO: char is not null terminated, verify this code once #7963 gets merged. - std::string dataString(data.data(), data.size()); - TargetNavigatorResponse response = targetNavigatorClusterNavigateTarget(emberAfCurrentEndpoint(), target, dataString); - sendResponse(command, response); return true; } -void MatterTargetNavigatorPluginServerInitCallback() {} +void MatterTargetNavigatorPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gTargetNavigatorAttrAccess); +} diff --git a/src/app/clusters/target-navigator-server/target-navigator-server.h b/src/app/clusters/target-navigator-server/target-navigator-server.h index 17d77613e0302a..584b2152c19364 100644 --- a/src/app/clusters/target-navigator-server/target-navigator-server.h +++ b/src/app/clusters/target-navigator-server/target-navigator-server.h @@ -23,8 +23,17 @@ #pragma once -struct TargetNavigatorResponse -{ - uint8_t status; - uint8_t * data; -}; +#include "target-navigator-delegate.h" +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace TargetNavigator { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace TargetNavigator +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/wake-on-lan-server/wake-on-lan-delegate.h b/src/app/clusters/wake-on-lan-server/wake-on-lan-delegate.h new file mode 100644 index 00000000000000..400dda253a867d --- /dev/null +++ b/src/app/clusters/wake-on-lan-server/wake-on-lan-delegate.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace WakeOnLan { + +/** @brief + * Defines methods for implementing application-specific logic for the Wake on LAN Cluster. + */ +class Delegate +{ +public: + virtual chip::CharSpan HandleGetMacAddress() = 0; + + virtual ~Delegate() = default; +}; + +} // namespace WakeOnLan +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp b/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp new file mode 100644 index 00000000000000..9b6e5d20e9634a --- /dev/null +++ b/src/app/clusters/wake-on-lan-server/wake-on-lan-server.cpp @@ -0,0 +1,138 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** + * @file + * @brief Routines for the Wake on LAN plugin, the + *server implementation of the Wake on LAN cluster. + ******************************************************************************* + ******************************************************************************/ + +#include +#include + +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::WakeOnLan; + +// ----------------------------------------------------------------------------- +// Delegate Implementation + +using chip::app::Clusters::WakeOnLan::Delegate; + +namespace { + +Delegate * gDelegateTable[EMBER_AF_WAKE_ON_LAN_CLUSTER_SERVER_ENDPOINT_COUNT] = { nullptr }; + +Delegate * GetDelegate(EndpointId endpoint) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::WakeOnLan::Id); + return (ep == 0xFFFF ? NULL : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) + { + ChipLogError(Zcl, "WakeOnLan has no delegate set for endpoint:%" PRIu16, endpoint); + return true; + } + return false; +} +} // namespace + +namespace chip { +namespace app { +namespace Clusters { +namespace WakeOnLan { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::WakeOnLan::Id); + if (ep != 0xFFFF) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} + +} // namespace WakeOnLan +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Attribute Accessor Implementation + +namespace { + +class WakeOnLanAttrAccess : public app::AttributeAccessInterface +{ +public: + WakeOnLanAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::WakeOnLan::Id) {} + + CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; + +private: + CHIP_ERROR ReadMacAddressAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +WakeOnLanAttrAccess gWakeOnLanAttrAccess; + +CHIP_ERROR WakeOnLanAttrAccess::Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + switch (aPath.mAttributeId) + { + case app::Clusters::WakeOnLan::Attributes::WakeOnLanMacAddress::Id: { + return ReadMacAddressAttribute(aEncoder, delegate); + } + default: { + break; + } + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR WakeOnLanAttrAccess::ReadMacAddressAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + chip::CharSpan macAddress = delegate->HandleGetMacAddress(); + return aEncoder.Encode(macAddress); +} + +} // anonymous namespace + +void MatterWakeOnLanPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gWakeOnLanAttrAccess); +} diff --git a/src/app/clusters/wake-on-lan-server/wake-on-lan-server.h b/src/app/clusters/wake-on-lan-server/wake-on-lan-server.h new file mode 100644 index 00000000000000..abce9778d93265 --- /dev/null +++ b/src/app/clusters/wake-on-lan-server/wake-on-lan-server.h @@ -0,0 +1,38 @@ +/** + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**************************************************************************** + * @file + * @brief Routines for the Wake on LAN plugin, the + *server implementation of the Wake on LAN cluster. + ******************************************************************************* + ******************************************************************************/ + +#pragma once + +#include "wake-on-lan-delegate.h" + +namespace chip { +namespace app { +namespace Clusters { +namespace WakeOnLan { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace WakeOnLan +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/tests/suites/TV_AccountLoginCluster.yaml b/src/app/tests/suites/TV_AccountLoginCluster.yaml index 7e0f989ddb616e..3bfc2195950dc0 100644 --- a/src/app/tests/suites/TV_AccountLoginCluster.yaml +++ b/src/app/tests/suites/TV_AccountLoginCluster.yaml @@ -30,12 +30,10 @@ tests: values: - name: "tempAccountIdentifier" value: "asdf" - - # TODO: Enable these once they are able to work - # response: - # values: - # - name: "setupPIN" - # value: "tempPin123" + response: + values: + - name: "setupPIN" + value: "tempPin123" - label: "Login Command" command: "loginRequest" timedInteractionTimeoutMs: 10000 diff --git a/src/app/tests/suites/TV_MediaPlaybackCluster.yaml b/src/app/tests/suites/TV_MediaPlaybackCluster.yaml index efc7ee3323524b..edafcffe6ae856 100644 --- a/src/app/tests/suites/TV_MediaPlaybackCluster.yaml +++ b/src/app/tests/suites/TV_MediaPlaybackCluster.yaml @@ -33,7 +33,7 @@ tests: command: "readAttribute" attribute: "start time" response: - value: 255 + value: 0 - label: "Read attribute duration" command: "readAttribute" diff --git a/src/app/util/ContentApp.cpp b/src/app/util/ContentApp.cpp index 90afd8bd3d4600..ec02ed1e7d14ad 100644 --- a/src/app/util/ContentApp.cpp +++ b/src/app/util/ContentApp.cpp @@ -237,20 +237,21 @@ CHIP_ERROR TargetNavigator::GetTargetInfoList(chip::app::AttributeValueEncoder & }); } -TargetNavigatorResponse TargetNavigator::NavigateTarget(uint8_t target, std::string data) +app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::Type TargetNavigator::NavigateTarget(uint8_t target, + std::string data) { ChipLogProgress(DeviceLayer, "TargetNavigator: NavigateTarget target=%d data=\"%s\"", target, data.c_str()); - TargetNavigatorResponse response; - const char * testData = "data response"; - response.data = (uint8_t *) testData; + app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::Type response; + response.data = chip::CharSpan("data response", strlen("data response")); + if (target >= mTargets.size()) { - response.status = to_underlying(app::Clusters::TargetNavigator::StatusEnum::kAppNotAvailable); + response.status = app::Clusters::TargetNavigator::StatusEnum::kAppNotAvailable; } else { - response.status = to_underlying(app::Clusters::TargetNavigator::StatusEnum::kSuccess); + response.status = app::Clusters::TargetNavigator::StatusEnum::kSuccess; mCurrentTarget = target; } return response; diff --git a/src/app/util/ContentApp.h b/src/app/util/ContentApp.h index c7e38a33728457..1c9a9ab1a46815 100644 --- a/src/app/util/ContentApp.h +++ b/src/app/util/ContentApp.h @@ -91,7 +91,8 @@ class DLL_EXPORT ApplicationLauncher : public ContentAppCluster public: virtual ~ApplicationLauncher() = default; - virtual ApplicationLauncherResponse LaunchApp(Application application, std::string data) = 0; + virtual app::Clusters::ApplicationLauncher::Commands::LauncherResponse::Type LaunchApp(Application application, + std::string data) = 0; EmberAfStatus HandleReadAttribute(chip::AttributeId attributeId, uint8_t * buffer, uint16_t maxReadLength) override; EmberAfStatus HandleWriteAttribute(chip::AttributeId attributeId, uint8_t * buffer) override; @@ -102,7 +103,8 @@ class DLL_EXPORT ContentLauncher : public ContentAppCluster public: virtual ~ContentLauncher() = default; - virtual LaunchResponse LaunchContent(std::list parameterList, bool autoplay, std::string data) = 0; + virtual app::Clusters::ContentLauncher::Commands::LaunchResponse::Type LaunchContent(std::list parameterList, + bool autoplay, std::string data) = 0; EmberAfStatus HandleReadAttribute(chip::AttributeId attributeId, uint8_t * buffer, uint16_t maxReadLength) override; EmberAfStatus HandleWriteAttribute(chip::AttributeId attributeId, uint8_t * buffer) override; @@ -123,7 +125,7 @@ class DLL_EXPORT TargetNavigator : public ContentAppCluster TargetNavigator(std::list targets, uint8_t currentTarget); virtual ~TargetNavigator() = default; - TargetNavigatorResponse NavigateTarget(uint8_t target, std::string data); + app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::Type NavigateTarget(uint8_t target, std::string data); CHIP_ERROR GetTargetInfoList(chip::app::AttributeValueEncoder & aEncoder); EmberAfStatus HandleReadAttribute(chip::AttributeId attributeId, uint8_t * buffer, uint16_t maxReadLength) override; diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index 6efe0a6398c75d..22f6d3794d5c30 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -300,7 +300,6 @@ void MatterBinaryInputBasicPluginServerInitCallback() {} void MatterPressureMeasurementPluginServerInitCallback() {} void MatterTemperatureMeasurementPluginServerInitCallback() {} void MatterFlowMeasurementPluginServerInitCallback() {} -void MatterWakeOnLanPluginServerInitCallback() {} void MatterOnOffSwitchConfigurationPluginServerInitCallback() {} void MatterPowerSourcePluginServerInitCallback() {} void MatterThermostatUserInterfaceConfigurationPluginServerInitCallback() {} diff --git a/src/app/zap-templates/zcl/data-model/chip/application-launcher-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/application-launcher-cluster.xml index d5e0809dcd9117..0baa9f4e964998 100644 --- a/src/app/zap-templates/zcl/data-model/chip/application-launcher-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/application-launcher-cluster.xml @@ -70,4 +70,9 @@ limitations under the License. + + + + + diff --git a/src/app/zap-templates/zcl/data-model/chip/audio-output-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/audio-output-cluster.xml index ba3a44aee75594..27f92dbb34554d 100644 --- a/src/app/zap-templates/zcl/data-model/chip/audio-output-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/audio-output-cluster.xml @@ -58,4 +58,9 @@ limitations under the License. + + + + + diff --git a/src/app/zap-templates/zcl/data-model/chip/channel-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/channel-cluster.xml index b69929d53927ca..b5284916f1e0d5 100644 --- a/src/app/zap-templates/zcl/data-model/chip/channel-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/channel-cluster.xml @@ -81,4 +81,10 @@ limitations under the License. + + + + + + diff --git a/src/app/zap-templates/zcl/data-model/chip/content-launch-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/content-launch-cluster.xml index 774321b0afab05..d42d97d0622b9b 100644 --- a/src/app/zap-templates/zcl/data-model/chip/content-launch-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/content-launch-cluster.xml @@ -129,4 +129,10 @@ limitations under the License. + + + + + + diff --git a/src/app/zap-templates/zcl/data-model/chip/keypad-input-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/keypad-input-cluster.xml index 096b22e43d6522..6022d3bd9972c9 100644 --- a/src/app/zap-templates/zcl/data-model/chip/keypad-input-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/keypad-input-cluster.xml @@ -140,7 +140,12 @@ limitations under the License. - + + + + + + diff --git a/src/app/zap-templates/zcl/data-model/chip/media-input-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/media-input-cluster.xml index 03f37e0da1e39a..f4a3962e9ac8d2 100644 --- a/src/app/zap-templates/zcl/data-model/chip/media-input-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/media-input-cluster.xml @@ -73,4 +73,9 @@ limitations under the License. + + + + + diff --git a/src/app/zap-templates/zcl/data-model/chip/media-playback-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/media-playback-cluster.xml index b7819f3e1665b1..e9b4dde1249ef6 100644 --- a/src/app/zap-templates/zcl/data-model/chip/media-playback-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/media-playback-cluster.xml @@ -27,7 +27,7 @@ limitations under the License. This cluster provides an interface for controlling Media Playback (PLAY, PAUSE, etc) on a media device such as a TV or Speaker. playback state - start time + start time duration position playback speed diff --git a/src/app/zap_cluster_list.py b/src/app/zap_cluster_list.py index 0397a65369b7a9..efea6547296770 100755 --- a/src/app/zap_cluster_list.py +++ b/src/app/zap_cluster_list.py @@ -84,7 +84,7 @@ 'TIME_CLUSTER': [], 'TIME_SYNCHRONIZATION_CLUSTER': [], 'USER_LABEL_CLUSTER': ['user-label-server'], - 'WAKE_ON_LAN_CLUSTER': [], + 'WAKE_ON_LAN_CLUSTER': ['wake-on-lan-server'], 'WIFI_NETWORK_DIAGNOSTICS_CLUSTER': ['wifi-network-diagnostics-server'], 'WINDOW_COVERING_CLUSTER': ['window-covering-server'], 'ZLL_COMMISSIONING_CLUSTER': [] diff --git a/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h b/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h index bd13c3ed4a04c9..c373f6ee379d3f 100644 --- a/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h +++ b/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h @@ -2073,13 +2073,13 @@ { 0xFFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0001) }, /* ClusterRevision */ \ \ /* Endpoint: 1, Cluster: Media Playback (server) */ \ - { 0x0000, ZAP_TYPE(ENUM8), 1, 0, ZAP_SIMPLE_DEFAULT(0x00) }, /* playback state */ \ - { 0x0001, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(1486) }, /* start time */ \ - { 0x0002, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(1494) }, /* duration */ \ - { 0x0004, ZAP_TYPE(SINGLE), 4, 0, ZAP_LONG_DEFAULTS_INDEX(1502) }, /* playback speed */ \ - { 0x0005, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(1506) }, /* seek range end */ \ - { 0x0006, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(1514) }, /* seek range start */ \ - { 0xFFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0001) }, /* ClusterRevision */ \ + { 0x0000, ZAP_TYPE(ENUM8), 1, 0, ZAP_SIMPLE_DEFAULT(0x00) }, /* playback state */ \ + { 0x0001, ZAP_TYPE(EPOCH_US), 8, 0, ZAP_LONG_DEFAULTS_INDEX(1486) }, /* start time */ \ + { 0x0002, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(1494) }, /* duration */ \ + { 0x0004, ZAP_TYPE(SINGLE), 4, 0, ZAP_LONG_DEFAULTS_INDEX(1502) }, /* playback speed */ \ + { 0x0005, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(1506) }, /* seek range end */ \ + { 0x0006, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(1514) }, /* seek range start */ \ + { 0xFFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0001) }, /* ClusterRevision */ \ \ /* Endpoint: 1, Cluster: Media Input (server) */ \ { 0x0000, ZAP_TYPE(ARRAY), 254, 0, ZAP_LONG_DEFAULTS_INDEX(1522) }, /* media input list */ \ diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp index 60bca6f419a4d9..a859b22d8a7e7c 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp @@ -29831,7 +29831,7 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint64_t value) Traits::StorageType storageValue; Traits::WorkingToStorage(value, storageValue); uint8_t * writable = Traits::ToAttributeStoreRepresentation(storageValue); - return emberAfWriteServerAttribute(endpoint, Clusters::MediaPlayback::Id, Id, writable, ZCL_INT64U_ATTRIBUTE_TYPE); + return emberAfWriteServerAttribute(endpoint, Clusters::MediaPlayback::Id, Id, writable, ZCL_EPOCH_US_ATTRIBUTE_TYPE); } } // namespace StartTime diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h index cb858dc836fec7..f2f6c84aa35382 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h @@ -5246,7 +5246,7 @@ EmberAfStatus Set(chip::EndpointId endpoint, chip::app::Clusters::MediaPlayback: } // namespace PlaybackState namespace StartTime { -EmberAfStatus Get(chip::EndpointId endpoint, uint64_t * value); // int64u +EmberAfStatus Get(chip::EndpointId endpoint, uint64_t * value); // epoch_us EmberAfStatus Set(chip::EndpointId endpoint, uint64_t value); } // namespace StartTime diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index 5363d8bb17ec0c..bb4c23db05797d 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -31416,6 +31416,12 @@ enum class InputTypeEnum : uint8_t kOther = 0x0B, }; +// Bitmap for MediaInputFeature +enum class MediaInputFeature : uint32_t +{ + kNameUpdates = 0x1, +}; + namespace Structs { namespace InputInfo { enum class Fields @@ -31871,6 +31877,14 @@ enum class StatusEnum : uint8_t kInvalidKeyInCurrentState = 0x02, }; +// Bitmap for KeypadInputFeature +enum class KeypadInputFeature : uint32_t +{ + kNavigationKeyCodes = 0x1, + kLocationKeys = 0x2, + kNumberKeys = 0x4, +}; + namespace Commands { // Forward-declarations so we can reference these later. @@ -32039,6 +32053,13 @@ enum class StatusEnum : uint8_t kAuthFailed = 0x02, }; +// Bitmap for ContentLauncherFeature +enum class ContentLauncherFeature : uint32_t +{ + kContentSearch = 0x1, + kURLPlayback = 0x2, +}; + // Bitmap for SupportedStreamingProtocol enum class SupportedStreamingProtocol : uint32_t { @@ -32417,6 +32438,12 @@ enum class OutputTypeEnum : uint8_t kOther = 0x05, }; +// Bitmap for AudiouOutputFeature +enum class AudiouOutputFeature : uint32_t +{ + kNameUpdates = 0x1, +}; + namespace Structs { namespace OutputInfo { enum class Fields @@ -32617,6 +32644,19 @@ enum class StatusEnum : uint8_t kSystemBusy = 0x02, }; +// Bitmap for ApplicationLauncherFeature +enum class ApplicationLauncherFeature : uint32_t +{ + kApplicationPlatform = 0x1, +}; + +// Bitmap for ChannelFeature +enum class ChannelFeature : uint32_t +{ + kChannelList = 0x1, + kLineupInfo = 0x2, +}; + namespace Structs { namespace Application { enum class Fields diff --git a/zzz_generated/app-common/app-common/zap-generated/enums.h b/zzz_generated/app-common/app-common/zap-generated/enums.h index 16cbcd723fbf29..16a982466a2a46 100644 --- a/zzz_generated/app-common/app-common/zap-generated/enums.h +++ b/zzz_generated/app-common/app-common/zap-generated/enums.h @@ -649,6 +649,10 @@ enum EmberAfWiFiVersionType : uint8_t #define EMBER_AF_ALERT_STRUCTURE_CATEGORY_OFFSET (8) #define EMBER_AF_ALERT_STRUCTURE_PRESENCE_RECOVERY (12288) #define EMBER_AF_ALERT_STRUCTURE_PRESENCE_RECOVERY_OFFSET (12) +#define EMBER_AF_APPLICATION_LAUNCHER_FEATURE_APPLICATION_PLATFORM (1) +#define EMBER_AF_APPLICATION_LAUNCHER_FEATURE_APPLICATION_PLATFORM_OFFSET (0) +#define EMBER_AF_AUDIOU_OUTPUT_FEATURE_NAME_UPDATES (1) +#define EMBER_AF_AUDIOU_OUTPUT_FEATURE_NAME_UPDATES_OFFSET (0) #define EMBER_AF_BALLAST_STATUS_NON_OPERATIONAL (1) #define EMBER_AF_BALLAST_STATUS_NON_OPERATIONAL_OFFSET (0) #define EMBER_AF_BALLAST_STATUS_LAMP_NOT_IN_SOCKET (2) @@ -665,6 +669,10 @@ enum EmberAfWiFiVersionType : uint8_t #define EMBER_AF_BARRIER_CONTROL_SAFETY_STATUS_POSITION_FAILURE_OFFSET (3) #define EMBER_AF_BATTERY_ALARM_MASK_VOLTAGE_TOO_LOW (1) #define EMBER_AF_BATTERY_ALARM_MASK_VOLTAGE_TOO_LOW_OFFSET (0) +#define EMBER_AF_CHANNEL_FEATURE_CHANNEL_LIST (1) +#define EMBER_AF_CHANNEL_FEATURE_CHANNEL_LIST_OFFSET (0) +#define EMBER_AF_CHANNEL_FEATURE_LINEUP_INFO (2) +#define EMBER_AF_CHANNEL_FEATURE_LINEUP_INFO_OFFSET (1) #define EMBER_AF_COLOR_CAPABILITIES_HUE_SATURATION_SUPPORTED (1) #define EMBER_AF_COLOR_CAPABILITIES_HUE_SATURATION_SUPPORTED_OFFSET (0) #define EMBER_AF_COLOR_CAPABILITIES_ENHANCED_HUE_SUPPORTED (2) @@ -707,6 +715,10 @@ enum EmberAfWiFiVersionType : uint8_t #define EMBER_AF_COMMAND_BITS_DISABLE_ACTION_OFFSET (10) #define EMBER_AF_COMMAND_BITS_DISABLE_ACTION_WITH_DURATION (2048) #define EMBER_AF_COMMAND_BITS_DISABLE_ACTION_WITH_DURATION_OFFSET (11) +#define EMBER_AF_CONTENT_LAUNCHER_FEATURE_CONTENT_SEARCH (1) +#define EMBER_AF_CONTENT_LAUNCHER_FEATURE_CONTENT_SEARCH_OFFSET (0) +#define EMBER_AF_CONTENT_LAUNCHER_FEATURE_URL_PLAYBACK (2) +#define EMBER_AF_CONTENT_LAUNCHER_FEATURE_URL_PLAYBACK_OFFSET (1) #define EMBER_AF_DAY_OF_WEEK_SUNDAY (1) #define EMBER_AF_DAY_OF_WEEK_SUNDAY_OFFSET (0) #define EMBER_AF_DAY_OF_WEEK_MONDAY (2) @@ -939,6 +951,12 @@ enum EmberAfWiFiVersionType : uint8_t #define EMBER_AF_IAS_ZONE_STATUS_TEST_OFFSET (8) #define EMBER_AF_IAS_ZONE_STATUS_BATTERY_DEFECT (512) #define EMBER_AF_IAS_ZONE_STATUS_BATTERY_DEFECT_OFFSET (9) +#define EMBER_AF_KEYPAD_INPUT_FEATURE_NAVIGATION_KEY_CODES (1) +#define EMBER_AF_KEYPAD_INPUT_FEATURE_NAVIGATION_KEY_CODES_OFFSET (0) +#define EMBER_AF_KEYPAD_INPUT_FEATURE_LOCATION_KEYS (2) +#define EMBER_AF_KEYPAD_INPUT_FEATURE_LOCATION_KEYS_OFFSET (1) +#define EMBER_AF_KEYPAD_INPUT_FEATURE_NUMBER_KEYS (4) +#define EMBER_AF_KEYPAD_INPUT_FEATURE_NUMBER_KEYS_OFFSET (2) #define EMBER_AF_LAMP_ALARM_MODE_LAMP_BURN_HOURS (1) #define EMBER_AF_LAMP_ALARM_MODE_LAMP_BURN_HOURS_OFFSET (0) #define EMBER_AF_MAINS_ALARM_MASK_VOLTAGE_TOO_LOW (1) @@ -947,6 +965,8 @@ enum EmberAfWiFiVersionType : uint8_t #define EMBER_AF_MAINS_ALARM_MASK_VOLTAGE_TOO_HIGH_OFFSET (1) #define EMBER_AF_MAINS_ALARM_MASK_MAINS_POWER_SUPPLY_LOST (4) #define EMBER_AF_MAINS_ALARM_MASK_MAINS_POWER_SUPPLY_LOST_OFFSET (2) +#define EMBER_AF_MEDIA_INPUT_FEATURE_NAME_UPDATES (1) +#define EMBER_AF_MEDIA_INPUT_FEATURE_NAME_UPDATES_OFFSET (0) #define EMBER_AF_MESSAGING_CONFIRMATION_CONTROL_NO_RETURNED (1) #define EMBER_AF_MESSAGING_CONFIRMATION_CONTROL_NO_RETURNED_OFFSET (0) #define EMBER_AF_MESSAGING_CONFIRMATION_CONTROL_YES_RETURNED (2) diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index 4d1fe8f3452150..34d7ab9a0bf208 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -32825,7 +32825,12 @@ class TV_AccountLoginCluster : public TestCommand void OnFailureResponse_1(EmberAfStatus status) { ThrowFailureResponse(); } - void OnSuccessResponse_1(chip::CharSpan setupPIN) { NextTest(); } + void OnSuccessResponse_1(chip::CharSpan setupPIN) + { + VerifyOrReturn(CheckValueAsString("setupPIN", setupPIN, chip::CharSpan("tempPin123", 10))); + + NextTest(); + } CHIP_ERROR TestLoginCommand_2() { @@ -33452,7 +33457,7 @@ class TV_MediaPlaybackCluster : public TestCommand void OnSuccessResponse_2(uint64_t startTime) { - VerifyOrReturn(CheckValue("startTime", startTime, 255ULL)); + VerifyOrReturn(CheckValue("startTime", startTime, 0ULL)); NextTest(); } diff --git a/zzz_generated/tv-app/zap-generated/endpoint_config.h b/zzz_generated/tv-app/zap-generated/endpoint_config.h index 123045375135b4..5f1e6e16bbf511 100644 --- a/zzz_generated/tv-app/zap-generated/endpoint_config.h +++ b/zzz_generated/tv-app/zap-generated/endpoint_config.h @@ -1325,9 +1325,9 @@ { 0xFFFD, ZAP_TYPE(INT16U), 0, ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE), ZAP_SIMPLE_DEFAULT(1) }, /* ClusterRevision */ \ \ /* Endpoint: 3, Cluster: Media Playback (server) */ \ - { 0x0000, ZAP_TYPE(ENUM8), 1, 0, ZAP_SIMPLE_DEFAULT(0x00) }, /* playback state */ \ - { 0x0001, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(2655) }, /* start time */ \ - { 0x0002, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(2663) }, /* duration */ \ + { 0x0000, ZAP_TYPE(ENUM8), 1, 0, ZAP_SIMPLE_DEFAULT(0x00) }, /* playback state */ \ + { 0x0001, ZAP_TYPE(EPOCH_US), 8, 0, ZAP_LONG_DEFAULTS_INDEX(2655) }, /* start time */ \ + { 0x0002, ZAP_TYPE(INT64U), 8, 0, ZAP_LONG_DEFAULTS_INDEX(2663) }, /* duration */ \ { 0x0003, ZAP_TYPE(STRUCT), 0, ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ ZAP_EMPTY_DEFAULT() }, /* position */ \ { 0x0004, ZAP_TYPE(SINGLE), 4, 0, ZAP_LONG_DEFAULTS_INDEX(2671) }, /* playback speed */ \