diff --git a/examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h b/examples/all-clusters-app/all-clusters-common/include/static-supported-modes-manager.h similarity index 100% rename from examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h rename to examples/all-clusters-app/all-clusters-common/include/static-supported-modes-manager.h diff --git a/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp b/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp similarity index 99% rename from examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp rename to examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp index edb62ae4031c72..62a864be8adc68 100644 --- a/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp @@ -32,6 +32,7 @@ const StaticSupportedModesManager StaticSupportedModesManager::instance = Static const SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const { for (auto & endpointSpanPair : supportedOptionsByEndpoints) + { if (endpointSpanPair.mEndpointId == endpointId) { return ModeOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end()); diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake index ca6eeb5d0668d2..6b0541edb6b76b 100755 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -36,13 +36,13 @@ list( ${chip_dir}/zzz_generated/all-clusters-app/zap-generated/CHIPClusters.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp + ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp ${chip_dir}/examples/all-clusters-app/ameba/main/chipinterface.cpp ${chip_dir}/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp ${chip_dir}/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp ${chip_dir}/examples/all-clusters-app/ameba/main/Globals.cpp ${chip_dir}/examples/all-clusters-app/ameba/main/LEDWidget.cpp - ${chip_dir}/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp ) add_library( @@ -64,6 +64,7 @@ target_include_directories( ${chip_dir}/zzz_generated/all-clusters-app/zap-generated ${chip_dir}/zzz_generated/app-common ${chip_dir}/examples/all-clusters-app/all-clusters-common + ${chip_dir}/examples/all-clusters-app/all-clusters-common/include ${chip_dir}/examples/all-clusters-app/ameba/main/include ${chip_dir_output}/gen/include ${chip_dir}/src/include/ diff --git a/examples/all-clusters-app/esp32/main/CMakeLists.txt b/examples/all-clusters-app/esp32/main/CMakeLists.txt index d342e16e5beff0..e2697abb1afc8b 100644 --- a/examples/all-clusters-app/esp32/main/CMakeLists.txt +++ b/examples/all-clusters-app/esp32/main/CMakeLists.txt @@ -19,6 +19,7 @@ # The list of src and include dirs must be in sync with that in all-clusters-app/esp32/main/component.mk set(PRIV_INCLUDE_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/all-clusters-app" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/include" "${CMAKE_CURRENT_LIST_DIR}/include" ) set(SRC_DIRS_LIST diff --git a/examples/all-clusters-app/esp32/main/include/static-supported-modes-manager.h b/examples/all-clusters-app/esp32/main/include/static-supported-modes-manager.h deleted file mode 100644 index 2d4f674a65920d..00000000000000 --- a/examples/all-clusters-app/esp32/main/include/static-supported-modes-manager.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * 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 ModeSelect { - -/** - * This implementation statically defines the options. - */ - -class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::SupportedModesManager -{ - using ModeOptionStructType = Structs::ModeOptionStruct::Type; - using storage_value_type = const ModeOptionStructType; - - struct EndpointSpanPair - { - const EndpointId mEndpointId; - const Span mSpan; - - EndpointSpanPair(const EndpointId aEndpointId, const Span && aSpan) : - mEndpointId(aEndpointId), mSpan(aSpan) - {} - - EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} - }; - - static storage_value_type coffeeOptions[]; - static const EndpointSpanPair supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT]; - -public: - static const StaticSupportedModesManager instance; - - const SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override; - - EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override; - - ~StaticSupportedModesManager(){}; - - StaticSupportedModesManager() {} - - static inline const StaticSupportedModesManager & getStaticSupportedModesManagerInstance() { return instance; } -}; - -const SupportedModesManager * getSupportedModesManager(); - -} // namespace ModeSelect -} // namespace Clusters -} // namespace app -} // namespace chip diff --git a/examples/all-clusters-app/esp32/main/static-supported-modes-manager.cpp b/examples/all-clusters-app/esp32/main/static-supported-modes-manager.cpp deleted file mode 100644 index 3f25d4db41dd4b..00000000000000 --- a/examples/all-clusters-app/esp32/main/static-supported-modes-manager.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include - -using namespace std; -using namespace chip; -using namespace chip::app::Clusters; -using namespace chip::app::Clusters::ModeSelect; - -using ModeOptionStructType = Structs::ModeOptionStruct::Type; -using storage_value_type = const ModeOptionStructType; -namespace { -Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode, uint32_t semanticTag) -{ - Structs::ModeOptionStruct::Type option; - option.label = CharSpan(label, strlen(label)); - option.mode = mode; - option.semanticTag = semanticTag; - return option; -} -} // namespace - -// TODO: Configure your options for each endpoint -storage_value_type StaticSupportedModesManager::coffeeOptions[] = { buildModeOptionStruct("Black", 0, 0), - buildModeOptionStruct("Cappuccino", 4, 0), - buildModeOptionStruct("Espresso", 7, 0) }; -const StaticSupportedModesManager::EndpointSpanPair - StaticSupportedModesManager::supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = { - EndpointSpanPair(1, Span(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1 - }; - -const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager(); - -const SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const -{ - for (size_t i = 0; i < EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT; ++i) - { - const EndpointSpanPair & endpointSpanPair = supportedOptionsByEndpoints[i]; - if (endpointSpanPair.mEndpointId == endpointId) - { - return ModeOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end()); - } - } - return ModeOptionsProvider(nullptr, nullptr); -} - -EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode, - const ModeOptionStructType ** dataPtr) const -{ - auto modeOptionsProvider = this->getModeOptionsProvider(endpointId); - if (modeOptionsProvider.begin() == nullptr) - { - return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER; - } - auto * begin = this->getModeOptionsProvider(endpointId).begin(); - auto * end = this->getModeOptionsProvider(endpointId).end(); - - for (auto * it = begin; it != end; ++it) - { - auto & modeOption = *it; - if (modeOption.mode == mode) - { - *dataPtr = &modeOption; - return EMBER_ZCL_STATUS_SUCCESS; - } - } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %" PRIu8, mode); - return EMBER_ZCL_STATUS_INVALID_ARGUMENT; -} - -const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager() -{ - return &StaticSupportedModesManager::instance; -} diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 4df4191cc4507c..b7b6f896e1a987 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -16,7 +16,9 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") static_library("static-supported-modes-manager") { - sources = [ "include/static-supported-modes-manager.cpp" ] + sources = [ + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", + ] #zap_pregenerated_dir = "${chip_root}/zzz_generated" @@ -29,13 +31,13 @@ static_library("static-supported-modes-manager") { ] include_dirs = [ "include", + "${chip_root}/examples/all-clusters-app/all-clusters-common/include", "${chip_root}/src", "${chip_root}/zzz_generated/all-clusters-app", ] cflags = [ "-Wconversion" ] - print("include_dirs = ") } executable("chip-all-clusters-app") { diff --git a/examples/all-clusters-app/linux/include/static-supported-modes-manager.cpp b/examples/all-clusters-app/linux/include/static-supported-modes-manager.cpp deleted file mode 100644 index 3f25d4db41dd4b..00000000000000 --- a/examples/all-clusters-app/linux/include/static-supported-modes-manager.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include - -using namespace std; -using namespace chip; -using namespace chip::app::Clusters; -using namespace chip::app::Clusters::ModeSelect; - -using ModeOptionStructType = Structs::ModeOptionStruct::Type; -using storage_value_type = const ModeOptionStructType; -namespace { -Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode, uint32_t semanticTag) -{ - Structs::ModeOptionStruct::Type option; - option.label = CharSpan(label, strlen(label)); - option.mode = mode; - option.semanticTag = semanticTag; - return option; -} -} // namespace - -// TODO: Configure your options for each endpoint -storage_value_type StaticSupportedModesManager::coffeeOptions[] = { buildModeOptionStruct("Black", 0, 0), - buildModeOptionStruct("Cappuccino", 4, 0), - buildModeOptionStruct("Espresso", 7, 0) }; -const StaticSupportedModesManager::EndpointSpanPair - StaticSupportedModesManager::supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = { - EndpointSpanPair(1, Span(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1 - }; - -const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager(); - -const SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const -{ - for (size_t i = 0; i < EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT; ++i) - { - const EndpointSpanPair & endpointSpanPair = supportedOptionsByEndpoints[i]; - if (endpointSpanPair.mEndpointId == endpointId) - { - return ModeOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end()); - } - } - return ModeOptionsProvider(nullptr, nullptr); -} - -EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode, - const ModeOptionStructType ** dataPtr) const -{ - auto modeOptionsProvider = this->getModeOptionsProvider(endpointId); - if (modeOptionsProvider.begin() == nullptr) - { - return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER; - } - auto * begin = this->getModeOptionsProvider(endpointId).begin(); - auto * end = this->getModeOptionsProvider(endpointId).end(); - - for (auto * it = begin; it != end; ++it) - { - auto & modeOption = *it; - if (modeOption.mode == mode) - { - *dataPtr = &modeOption; - return EMBER_ZCL_STATUS_SUCCESS; - } - } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %" PRIu8, mode); - return EMBER_ZCL_STATUS_INVALID_ARGUMENT; -} - -const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager() -{ - return &StaticSupportedModesManager::instance; -} diff --git a/examples/all-clusters-app/linux/include/static-supported-modes-manager.h b/examples/all-clusters-app/linux/include/static-supported-modes-manager.h deleted file mode 100644 index 2d4f674a65920d..00000000000000 --- a/examples/all-clusters-app/linux/include/static-supported-modes-manager.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * 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 ModeSelect { - -/** - * This implementation statically defines the options. - */ - -class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::SupportedModesManager -{ - using ModeOptionStructType = Structs::ModeOptionStruct::Type; - using storage_value_type = const ModeOptionStructType; - - struct EndpointSpanPair - { - const EndpointId mEndpointId; - const Span mSpan; - - EndpointSpanPair(const EndpointId aEndpointId, const Span && aSpan) : - mEndpointId(aEndpointId), mSpan(aSpan) - {} - - EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} - }; - - static storage_value_type coffeeOptions[]; - static const EndpointSpanPair supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT]; - -public: - static const StaticSupportedModesManager instance; - - const SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override; - - EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override; - - ~StaticSupportedModesManager(){}; - - StaticSupportedModesManager() {} - - static inline const StaticSupportedModesManager & getStaticSupportedModesManagerInstance() { return instance; } -}; - -const SupportedModesManager * getSupportedModesManager(); - -} // namespace ModeSelect -} // namespace Clusters -} // namespace app -} // namespace chip diff --git a/examples/all-clusters-app/mbed/CMakeLists.txt b/examples/all-clusters-app/mbed/CMakeLists.txt index 80aa415ca638f6..d6a7f3d290e6f5 100644 --- a/examples/all-clusters-app/mbed/CMakeLists.txt +++ b/examples/all-clusters-app/mbed/CMakeLists.txt @@ -37,6 +37,7 @@ target_include_directories(${APP_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/main/include/ ${APP_ROOT}/all-clusters-common + ${APP_ROOT}/all-clusters-common/include ${APP_CLUSTERS} ${MBED_COMMON}/util/include ${CHIP_ROOT}/src/app @@ -50,7 +51,6 @@ target_sources(${APP_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/main/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/main/AppTask.cpp ${CMAKE_CURRENT_SOURCE_DIR}/main/LowPowerManager.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/main/static-supported-modes-manager.cpp ${MBED_COMMON}/util/LEDWidget.cpp @@ -69,6 +69,7 @@ target_sources(${APP_TARGET} PRIVATE ${CHIP_ROOT}/src/app/server/CommissioningWindowManager.cpp ${CHIP_ROOT}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp + ${CHIP_ROOT}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp ${APP_UTIL}/DataModelHandler.cpp ${APP_UTIL}/af-event.cpp diff --git a/examples/all-clusters-app/mbed/main/include/static-supported-modes-manager.h b/examples/all-clusters-app/mbed/main/include/static-supported-modes-manager.h deleted file mode 100644 index fda7ac72ae2d51..00000000000000 --- a/examples/all-clusters-app/mbed/main/include/static-supported-modes-manager.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * 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 ModeSelect { - -/** - * This implementation statically defines the options. - */ - -class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::SupportedModesManager -{ - using ModeOptionStructType = Structs::ModeOptionStruct::Type; - using storage_value_type = const ModeOptionStructType; - - struct EndpointSpanPair - { - const EndpointId mEndpointId; - const Span mSpan; - - EndpointSpanPair(const EndpointId aEndpointId, const Span && aSpan) : - mEndpointId(aEndpointId), mSpan(aSpan) - {} - - EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} - }; - - static storage_value_type coffeeOptions[]; - static const EndpointSpanPair supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT]; - -public: - static const StaticSupportedModesManager instance; - - const SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override; - - EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override; - - ~StaticSupportedModesManager(){}; - - StaticSupportedModesManager() {} - - static inline const StaticSupportedModesManager & getStaticSupportedModesManagerInstance() { return instance; } -}; - -const SupportedModesManager * getSupportedModesManager(); - -} // namespace ModeSelect -} // namespace Clusters -} // namespace app -} // namespace chip diff --git a/examples/all-clusters-app/mbed/main/static-supported-modes-manager.cpp b/examples/all-clusters-app/mbed/main/static-supported-modes-manager.cpp deleted file mode 100644 index 3f25d4db41dd4b..00000000000000 --- a/examples/all-clusters-app/mbed/main/static-supported-modes-manager.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include - -using namespace std; -using namespace chip; -using namespace chip::app::Clusters; -using namespace chip::app::Clusters::ModeSelect; - -using ModeOptionStructType = Structs::ModeOptionStruct::Type; -using storage_value_type = const ModeOptionStructType; -namespace { -Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode, uint32_t semanticTag) -{ - Structs::ModeOptionStruct::Type option; - option.label = CharSpan(label, strlen(label)); - option.mode = mode; - option.semanticTag = semanticTag; - return option; -} -} // namespace - -// TODO: Configure your options for each endpoint -storage_value_type StaticSupportedModesManager::coffeeOptions[] = { buildModeOptionStruct("Black", 0, 0), - buildModeOptionStruct("Cappuccino", 4, 0), - buildModeOptionStruct("Espresso", 7, 0) }; -const StaticSupportedModesManager::EndpointSpanPair - StaticSupportedModesManager::supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = { - EndpointSpanPair(1, Span(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1 - }; - -const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager(); - -const SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const -{ - for (size_t i = 0; i < EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT; ++i) - { - const EndpointSpanPair & endpointSpanPair = supportedOptionsByEndpoints[i]; - if (endpointSpanPair.mEndpointId == endpointId) - { - return ModeOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end()); - } - } - return ModeOptionsProvider(nullptr, nullptr); -} - -EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode, - const ModeOptionStructType ** dataPtr) const -{ - auto modeOptionsProvider = this->getModeOptionsProvider(endpointId); - if (modeOptionsProvider.begin() == nullptr) - { - return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER; - } - auto * begin = this->getModeOptionsProvider(endpointId).begin(); - auto * end = this->getModeOptionsProvider(endpointId).end(); - - for (auto * it = begin; it != end; ++it) - { - auto & modeOption = *it; - if (modeOption.mode == mode) - { - *dataPtr = &modeOption; - return EMBER_ZCL_STATUS_SUCCESS; - } - } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %" PRIu8, mode); - return EMBER_ZCL_STATUS_INVALID_ARGUMENT; -} - -const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager() -{ - return &StaticSupportedModesManager::instance; -} diff --git a/examples/all-clusters-app/p6/BUILD.gn b/examples/all-clusters-app/p6/BUILD.gn index b396bc12512a4e..b5842c4137cc2b 100644 --- a/examples/all-clusters-app/p6/BUILD.gn +++ b/examples/all-clusters-app/p6/BUILD.gn @@ -55,7 +55,7 @@ p6_sdk_sources("all_clusters_app_sdk_sources") { } static_library("static-supported-modes-manager") { - sources = [ "src/static-supported-modes-manager.cpp" ] + sources = [ "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp" ] #zap_pregenerated_dir = "${chip_root}/zzz_generated" @@ -70,6 +70,7 @@ static_library("static-supported-modes-manager") { "${chip_root}", "${chip_root}/src", "${chip_root}/zzz_generated/all-clusters-app", + "${chip_root}/examples/all-clusters-app/all-clusters-common/include", ] cflags = [ "-Wconversion" ] @@ -91,7 +92,6 @@ p6_executable("clusters_app") { "src/ClusterManager.cpp", "src/ZclCallbacks.cpp", "src/main.cpp", - "src/static-supported-modes-manager.cpp", ] deps = [ diff --git a/examples/all-clusters-app/p6/include/static-supported-modes-manager.h b/examples/all-clusters-app/p6/include/static-supported-modes-manager.h deleted file mode 100644 index 2d4f674a65920d..00000000000000 --- a/examples/all-clusters-app/p6/include/static-supported-modes-manager.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * 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 ModeSelect { - -/** - * This implementation statically defines the options. - */ - -class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::SupportedModesManager -{ - using ModeOptionStructType = Structs::ModeOptionStruct::Type; - using storage_value_type = const ModeOptionStructType; - - struct EndpointSpanPair - { - const EndpointId mEndpointId; - const Span mSpan; - - EndpointSpanPair(const EndpointId aEndpointId, const Span && aSpan) : - mEndpointId(aEndpointId), mSpan(aSpan) - {} - - EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} - }; - - static storage_value_type coffeeOptions[]; - static const EndpointSpanPair supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT]; - -public: - static const StaticSupportedModesManager instance; - - const SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override; - - EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override; - - ~StaticSupportedModesManager(){}; - - StaticSupportedModesManager() {} - - static inline const StaticSupportedModesManager & getStaticSupportedModesManagerInstance() { return instance; } -}; - -const SupportedModesManager * getSupportedModesManager(); - -} // namespace ModeSelect -} // namespace Clusters -} // namespace app -} // namespace chip diff --git a/examples/all-clusters-app/p6/src/static-supported-modes-manager.cpp b/examples/all-clusters-app/p6/src/static-supported-modes-manager.cpp deleted file mode 100644 index 3f25d4db41dd4b..00000000000000 --- a/examples/all-clusters-app/p6/src/static-supported-modes-manager.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include - -using namespace std; -using namespace chip; -using namespace chip::app::Clusters; -using namespace chip::app::Clusters::ModeSelect; - -using ModeOptionStructType = Structs::ModeOptionStruct::Type; -using storage_value_type = const ModeOptionStructType; -namespace { -Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode, uint32_t semanticTag) -{ - Structs::ModeOptionStruct::Type option; - option.label = CharSpan(label, strlen(label)); - option.mode = mode; - option.semanticTag = semanticTag; - return option; -} -} // namespace - -// TODO: Configure your options for each endpoint -storage_value_type StaticSupportedModesManager::coffeeOptions[] = { buildModeOptionStruct("Black", 0, 0), - buildModeOptionStruct("Cappuccino", 4, 0), - buildModeOptionStruct("Espresso", 7, 0) }; -const StaticSupportedModesManager::EndpointSpanPair - StaticSupportedModesManager::supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = { - EndpointSpanPair(1, Span(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1 - }; - -const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager(); - -const SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const -{ - for (size_t i = 0; i < EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT; ++i) - { - const EndpointSpanPair & endpointSpanPair = supportedOptionsByEndpoints[i]; - if (endpointSpanPair.mEndpointId == endpointId) - { - return ModeOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end()); - } - } - return ModeOptionsProvider(nullptr, nullptr); -} - -EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode, - const ModeOptionStructType ** dataPtr) const -{ - auto modeOptionsProvider = this->getModeOptionsProvider(endpointId); - if (modeOptionsProvider.begin() == nullptr) - { - return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER; - } - auto * begin = this->getModeOptionsProvider(endpointId).begin(); - auto * end = this->getModeOptionsProvider(endpointId).end(); - - for (auto * it = begin; it != end; ++it) - { - auto & modeOption = *it; - if (modeOption.mode == mode) - { - *dataPtr = &modeOption; - return EMBER_ZCL_STATUS_SUCCESS; - } - } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %" PRIu8, mode); - return EMBER_ZCL_STATUS_INVALID_ARGUMENT; -} - -const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager() -{ - return &StaticSupportedModesManager::instance; -} diff --git a/third_party/cirque/repo b/third_party/cirque/repo index 262ea772466722..144767dd06f1f8 160000 --- a/third_party/cirque/repo +++ b/third_party/cirque/repo @@ -1 +1 @@ -Subproject commit 262ea7724667229f0d21d6a1c1e96d90415f0906 +Subproject commit 144767dd06f1f8549ffaa4beb06dadf71621c28d diff --git a/third_party/zap/repo b/third_party/zap/repo index 98b43b32758cbf..0376d5eb812d0f 160000 --- a/third_party/zap/repo +++ b/third_party/zap/repo @@ -1 +1 @@ -Subproject commit 98b43b32758cbfd8f643ef0a365cab9e0d9dcfde +Subproject commit 0376d5eb812d0f3d5585861b0b88b2480799e92e