From 4b99964ab662c1eaf47c73699c801000cade7d87 Mon Sep 17 00:00:00 2001 From: Li-An Ding Date: Tue, 2 Nov 2021 22:47:59 -0700 Subject: [PATCH 01/10] Simplfy the implementation of Mode Select Cluster Restyled by whitespace Restyled by clang-format --- .../all-clusters-app/ameba/chip_main.cmake | 1 + .../include/static-supported-modes-manager.h | 73 ++++++++++ .../main/static-supported-modes-manager.cpp | 75 ++++++++++ .../include/static-supported-modes-manager.h | 73 ++++++++++ .../main/static-supported-modes-manager.cpp | 75 ++++++++++ examples/all-clusters-app/linux/BUILD.gn | 26 ++++ .../static-supported-modes-manager.cpp | 75 ++++++++++ .../include/static-supported-modes-manager.h | 73 ++++++++++ examples/all-clusters-app/mbed/CMakeLists.txt | 3 +- .../include/static-supported-modes-manager.h | 73 ++++++++++ .../main/static-supported-modes-manager.cpp | 75 ++++++++++ examples/all-clusters-app/p6/BUILD.gn | 27 ++++ .../include/static-supported-modes-manager.h | 73 ++++++++++ .../p6/src/static-supported-modes-manager.cpp | 75 ++++++++++ src/app/chip_data_model.gni | 2 +- .../mode-select-server/mode-select-server.cpp | 24 ++-- .../static-supported-modes-manager.cpp | 65 --------- .../static-supported-modes-manager.h | 135 ------------------ .../supported-modes-manager.h | 45 ++---- 19 files changed, 820 insertions(+), 248 deletions(-) create mode 100644 examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h create mode 100644 examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp create mode 100644 examples/all-clusters-app/esp32/main/include/static-supported-modes-manager.h create mode 100644 examples/all-clusters-app/esp32/main/static-supported-modes-manager.cpp create mode 100644 examples/all-clusters-app/linux/include/static-supported-modes-manager.cpp create mode 100644 examples/all-clusters-app/linux/include/static-supported-modes-manager.h create mode 100644 examples/all-clusters-app/mbed/main/include/static-supported-modes-manager.h create mode 100644 examples/all-clusters-app/mbed/main/static-supported-modes-manager.cpp create mode 100644 examples/all-clusters-app/p6/include/static-supported-modes-manager.h create mode 100644 examples/all-clusters-app/p6/src/static-supported-modes-manager.cpp delete mode 100644 src/app/clusters/mode-select-server/static-supported-modes-manager.cpp delete mode 100644 src/app/clusters/mode-select-server/static-supported-modes-manager.h diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake index 7104367e829820..ca6eeb5d0668d2 100755 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -42,6 +42,7 @@ list( ${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( diff --git a/examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h b/examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h new file mode 100644 index 00000000000000..eede1c31d5ae49 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h @@ -0,0 +1,73 @@ +/* + * + * 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/ameba/main/static-supported-modes-manager.cpp b/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp new file mode 100644 index 00000000000000..5210cb2814fadf --- /dev/null +++ b/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp @@ -0,0 +1,75 @@ +// +// Created by Ding, Li-an on 10/21/21. +// +#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/esp32/main/include/static-supported-modes-manager.h b/examples/all-clusters-app/esp32/main/include/static-supported-modes-manager.h new file mode 100644 index 00000000000000..eede1c31d5ae49 --- /dev/null +++ b/examples/all-clusters-app/esp32/main/include/static-supported-modes-manager.h @@ -0,0 +1,73 @@ +/* + * + * 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 new file mode 100644 index 00000000000000..5210cb2814fadf --- /dev/null +++ b/examples/all-clusters-app/esp32/main/static-supported-modes-manager.cpp @@ -0,0 +1,75 @@ +// +// Created by Ding, Li-an on 10/21/21. +// +#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 f7b180f4461187..ded60aacecffb7 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -15,6 +15,31 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") +static_library("static-supported-modes-manager") { + + sources = [ "include/static-supported-modes-manager.cpp" ] + + #zap_pregenerated_dir = "${chip_root}/zzz_generated" + + deps = [] + deps += [ + "${chip_root}/src/app", + "${chip_root}/src/app/common:cluster-objects", + "${chip_root}/src/controller", + "${chip_root}/src/lib/core", + ] + include_dirs = [ + "include", + "${chip_root}/src", + "${chip_root}/zzz_generated/all-clusters-app", + ] + + cflags = [ "-Wconversion" ] + + print("include_dirs = ") + +} + executable("chip-all-clusters-app") { sources = [ "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", @@ -26,6 +51,7 @@ executable("chip-all-clusters-app") { "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/src/lib", + ":static-supported-modes-manager", ] cflags = [ "-Wconversion" ] 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 new file mode 100644 index 00000000000000..5210cb2814fadf --- /dev/null +++ b/examples/all-clusters-app/linux/include/static-supported-modes-manager.cpp @@ -0,0 +1,75 @@ +// +// Created by Ding, Li-an on 10/21/21. +// +#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 new file mode 100644 index 00000000000000..eede1c31d5ae49 --- /dev/null +++ b/examples/all-clusters-app/linux/include/static-supported-modes-manager.h @@ -0,0 +1,73 @@ +/* + * + * 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 aac0a8268e44e5..8bd0c8c674abaa 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_CLUSTERS} ${MBED_COMMON}/util/include ${CHIP_ROOT}/src/app ${CHIP_ROOT}/third_party/nlio/repo/include @@ -49,6 +50,7 @@ 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 @@ -112,7 +114,6 @@ target_sources(${APP_TARGET} PRIVATE ${APP_CLUSTERS}/media-input-server/media-input-server.cpp ${APP_CLUSTERS}/media-playback-server/media-playback-server.cpp ${APP_CLUSTERS}/mode-select-server/mode-select-server.cpp - ${APP_CLUSTERS}/mode-select-server/static-supported-modes-manager.cpp ${APP_CLUSTERS}/network-commissioning/network-commissioning-ember.cpp ${APP_CLUSTERS}/network-commissioning/network-commissioning.cpp ${APP_CLUSTERS}/on-off-server/on-off-server.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 new file mode 100644 index 00000000000000..7979ef297f1942 --- /dev/null +++ b/examples/all-clusters-app/mbed/main/include/static-supported-modes-manager.h @@ -0,0 +1,73 @@ +/* + * + * 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 new file mode 100644 index 00000000000000..5210cb2814fadf --- /dev/null +++ b/examples/all-clusters-app/mbed/main/static-supported-modes-manager.cpp @@ -0,0 +1,75 @@ +// +// Created by Ding, Li-an on 10/21/21. +// +#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 d34ad7bf427d55..ac966f0f471501 100644 --- a/examples/all-clusters-app/p6/BUILD.gn +++ b/examples/all-clusters-app/p6/BUILD.gn @@ -54,6 +54,31 @@ p6_sdk_sources("all_clusters_app_sdk_sources") { public_configs = [ "${chip_root}/third_party/p6:p6_sdk_config" ] } +static_library("static-supported-modes-manager") { + + sources = [ "src/static-supported-modes-manager.cpp" ] + + #zap_pregenerated_dir = "${chip_root}/zzz_generated" + + public_deps = [] + public_deps += [ + "${chip_root}/src/app", + "${chip_root}/src/app/common:cluster-objects", + "${chip_root}/src/controller", + "${chip_root}/src/lib/core", + ] + include_dirs = [ + "${chip_root}", + "${chip_root}/src", + "${chip_root}/zzz_generated/all-clusters-app", + ] + + cflags = [ "-Wconversion" ] + + print("include_dirs = ") + +} + p6_executable("clusters_app") { include_dirs = [] defines = [] @@ -67,10 +92,12 @@ p6_executable("clusters_app") { "src/ButtonHandler.cpp", "src/ClusterManager.cpp", "src/ZclCallbacks.cpp", + "src/static-supported-modes-manager.cpp", "src/main.cpp", ] deps = [ + ":static-supported-modes-manager", ":all_clusters_app_sdk_sources", "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/common/QRCode", 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 new file mode 100644 index 00000000000000..eede1c31d5ae49 --- /dev/null +++ b/examples/all-clusters-app/p6/include/static-supported-modes-manager.h @@ -0,0 +1,73 @@ +/* + * + * 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 new file mode 100644 index 00000000000000..5210cb2814fadf --- /dev/null +++ b/examples/all-clusters-app/p6/src/static-supported-modes-manager.cpp @@ -0,0 +1,75 @@ +// +// Created by Ding, Li-an on 10/21/21. +// +#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/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index f676f582969223..6e4766cf69da30 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -145,7 +145,7 @@ template("chip_data_model") { } else if (cluster == "mode-select-server") { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp", - "${_app_root}/clusters/${cluster}/static-supported-modes-manager.cpp", + "${_app_root}/clusters/${cluster}/supported-modes-manager.h" ] } else { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ] diff --git a/src/app/clusters/mode-select-server/mode-select-server.cpp b/src/app/clusters/mode-select-server/mode-select-server.cpp index 8662d94f7ace7b..7d90cf1c030a09 100644 --- a/src/app/clusters/mode-select-server/mode-select-server.cpp +++ b/src/app/clusters/mode-select-server/mode-select-server.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -51,25 +51,22 @@ CHIP_ERROR ModeSelectAttrAccess::Read(const ConcreteAttributePath & aPath, Attri { VerifyOrDie(aPath.mClusterId == ModeSelect::Id); - const ModeSelect::StaticSupportedModesManager & gSupportedModeManager = - ModeSelect::StaticSupportedModesManager::getStaticSupportedModesManagerInstance(); + const ModeSelect::SupportedModesManager * gSupportedModeManager = ModeSelect::getSupportedModesManager(); if (ModeSelect::Attributes::SupportedModes::Id == aPath.mAttributeId) { - const ModeSelect::StaticSupportedModesManager::IteratorFactory * iteratorFactory = - gSupportedModeManager.getIteratorFactory(aPath.mEndpointId); - if (iteratorFactory == nullptr) + const ModeSelect::SupportedModesManager::ModeOptionsProvider modeOptionsProvider = + gSupportedModeManager->getModeOptionsProvider(aPath.mEndpointId); + if (modeOptionsProvider.begin() == nullptr) { aEncoder.Encode(DataModel::List()); return CHIP_NO_ERROR; } CHIP_ERROR err; - err = aEncoder.EncodeList([iteratorFactory](const TagBoundEncoder & encoder) -> CHIP_ERROR { - const auto & end = *(iteratorFactory->end()); - for (auto it = *(iteratorFactory->begin()); it != end; ++it) + err = aEncoder.EncodeList([modeOptionsProvider](const TagBoundEncoder & encoder) -> CHIP_ERROR { + const auto * end = modeOptionsProvider.end(); + for (auto * it = modeOptionsProvider.begin(); it != end; ++it) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "ModeSelect: dereferencing it"); - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "ModeSelect: it= %p", (void *) it.operator->()); auto & modeOption = *it; ReturnErrorOnFailure(encoder.Encode(modeOption)); } @@ -90,9 +87,8 @@ bool emberAfModeSelectClusterChangeToModeCallback(CommandHandler * commandHandle uint8_t newMode = commandData.newMode; // Check that the newMode matches one of the supported options const ModeSelect::Structs::ModeOptionStruct::Type * modeOptionPtr; - const ModeSelect::StaticSupportedModesManager & gSupportedModeManager = - ModeSelect::StaticSupportedModesManager::getStaticSupportedModesManagerInstance(); - EmberAfStatus checkSupportedModeStatus = gSupportedModeManager.getModeOptionByMode(endpointId, newMode, &modeOptionPtr); + EmberAfStatus checkSupportedModeStatus = + ModeSelect::getSupportedModesManager()->getModeOptionByMode(endpointId, newMode, &modeOptionPtr); if (EMBER_ZCL_STATUS_SUCCESS != checkSupportedModeStatus) { emberAfPrintln(EMBER_AF_PRINT_DEBUG, "ModeSelect: Failed to find the option with mode %" PRIu8, newMode); diff --git a/src/app/clusters/mode-select-server/static-supported-modes-manager.cpp b/src/app/clusters/mode-select-server/static-supported-modes-manager.cpp deleted file mode 100644 index d65d0bda793437..00000000000000 --- a/src/app/clusters/mode-select-server/static-supported-modes-manager.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// -// Created by Ding, Li-an on 10/21/21. -// -#include -#include -#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 - -const Structs::ModeOptionStruct::Type StaticSupportedModesManager::blackOption = buildModeOptionStruct("Black", 0, 0); -const Structs::ModeOptionStruct::Type StaticSupportedModesManager::cappuccinoOption = buildModeOptionStruct("Cappuccino", 4, 0); -const Structs::ModeOptionStruct::Type StaticSupportedModesManager::espressoOption = buildModeOptionStruct("Espresso", 7, 0); -storage_value_type StaticSupportedModesManager::coffeeOptions[] = { &blackOption, &cappuccinoOption, &espressoOption }; -const Span StaticSupportedModesManager::coffeeOptionsSpan = - Span(StaticSupportedModesManager::coffeeOptions); -const map> StaticSupportedModesManager::optionsByEndpoints = { - { 1, StaticSupportedModesManager::coffeeOptionsSpan } -}; - -const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager(); - -const StaticSupportedModesManager::IteratorFactory * StaticSupportedModesManager::getIteratorFactory(EndpointId endpointId) const -{ - const auto & it = _iteratorFactoriesByEndpoints.find(endpointId); - return (it == _iteratorFactoriesByEndpoints.end()) ? nullptr : &(it->second); -} - -EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode, - const ModeOptionStructType ** dataPtr) const -{ - auto * iteratorFactory = this->getIteratorFactory(endpointId); - if (iteratorFactory == nullptr) - { - return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER; - } - const StaticSupportedModesManager::Iterator & begin = *(this->getIteratorFactory(endpointId)->begin()); - const StaticSupportedModesManager::Iterator & end = *(this->getIteratorFactory(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 %c", mode); - return EMBER_ZCL_STATUS_INVALID_ARGUMENT; -} diff --git a/src/app/clusters/mode-select-server/static-supported-modes-manager.h b/src/app/clusters/mode-select-server/static-supported-modes-manager.h deleted file mode 100644 index b48b96e7a8e60c..00000000000000 --- a/src/app/clusters/mode-select-server/static-supported-modes-manager.h +++ /dev/null @@ -1,135 +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 -#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 *; - - static const ModeOptionStructType blackOption; - static const ModeOptionStructType cappuccinoOption; - static const ModeOptionStructType espressoOption; - - static const ModeOptionStructType * coffeeOptions[]; - static const Span coffeeOptionsSpan; - static const std::map> optionsByEndpoints; - -public: - static const StaticSupportedModesManager instance; - - struct Iterator : public chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIterator - { - using iterator_category = std::forward_iterator_tag; - using difference_type = std::ptrdiff_t; - using pointer = storage_value_type *; - using base_iterator_type = chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIterator; - - Iterator(const pointer aPtr) : mPtr(aPtr) {} - ~Iterator() = default; - - const ModeOptionStructType & operator*() const override { return **mPtr; } - const ModeOptionStructType * operator->() override { return *mPtr; } - const ModeOptionStructType * operator->() const override { return *mPtr; } - - // Prefix increment - base_iterator_type & operator++() override - { - ++mPtr; - return *this; - } - - bool operator==(const base_iterator_type & other) const override - { - // Warning: we are not doing type check - // TODO: use of typeid requires -frtti - // if (typeid(other) != typeid(*this)) - // { - // return false; - // } - return this->operator->() == other.operator->(); - } - bool operator!=(const base_iterator_type & other) const override { return !((*this) == other); } - - private: - pointer mPtr; - }; - - struct IteratorFactory : public chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIteratorFactory - { - using pointer = Iterator *; - using const_pointer = const pointer; - - IteratorFactory(const Span & aSupportedOptions) : - _begin(Iterator(aSupportedOptions.data())), _end(Iterator(aSupportedOptions.data() + aSupportedOptions.size())) - {} - ~IteratorFactory() = default; - - const Iterator * begin() const override { return &_begin; } - const Iterator * end() const override { return &_end; } - - private: - const Iterator _begin; - const Iterator _end; - }; - - const IteratorFactory * getIteratorFactory(EndpointId endpointId) const override; - - EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override; - - ~StaticSupportedModesManager(){}; - - StaticSupportedModesManager() : StaticSupportedModesManager(&optionsByEndpoints) {} - - static inline const StaticSupportedModesManager & getStaticSupportedModesManagerInstance() { return instance; } - -private: - StaticSupportedModesManager(const std::map> * const supportedModes) : - _iteratorFactoriesByEndpoints(std::map()) - { - for (auto & entry : *supportedModes) - { - _iteratorFactoriesByEndpoints.insert( - std::pair(entry.first, IteratorFactory(entry.second))); - } - } - // TODO: Implement move constructor? - - std::map _iteratorFactoriesByEndpoints; -}; - -} // namespace ModeSelect -} // namespace Clusters -} // namespace app -} // namespace chip diff --git a/src/app/clusters/mode-select-server/supported-modes-manager.h b/src/app/clusters/mode-select-server/supported-modes-manager.h index f4d6d50216c61e..4fb5bfb0c350c3 100644 --- a/src/app/clusters/mode-select-server/supported-modes-manager.h +++ b/src/app/clusters/mode-select-server/supported-modes-manager.h @@ -18,9 +18,6 @@ #pragma once -#include -#include - #include #include #include @@ -41,53 +38,35 @@ class SupportedModesManager using ModeOptionStructType = Structs::ModeOptionStruct::Type; public: - struct ModeOptionStructIterator - { - using iterator_category = std::forward_iterator_tag; - using difference_type = std::ptrdiff_t; - using value_type = const ModeOptionStructType; - using pointer = value_type *; - using reference = value_type &; - - virtual reference operator*() const = 0; - virtual pointer operator->() = 0; - virtual pointer operator->() const = 0; - - // Prefix increment - virtual ModeOptionStructIterator & operator++() = 0; - - virtual bool operator==(const ModeOptionStructIterator & other) const = 0; - virtual bool operator!=(const ModeOptionStructIterator & other) const = 0; - - virtual ~ModeOptionStructIterator() {} - }; - /** - * A factory that can return the ModeOptionStructIterators for a specific endpoint. + * A class that can return the supported ModeOptions for a specific endpoint. */ - struct ModeOptionStructIteratorFactory + struct ModeOptionsProvider { - using const_pointer = const ModeOptionStructIterator *; + using pointer = const ModeOptionStructType *; /** * Returns the ModeOptionStructIterator to the first option. */ - virtual const_pointer begin() const = 0; + inline pointer begin() const { return mBegin; } /** * Returns the ModeOptionStructIterator to an element after the last option. */ - virtual const_pointer end() const = 0; + inline pointer end() const { return mEnd; } - virtual ~ModeOptionStructIteratorFactory() {} + ModeOptionsProvider(const pointer aBegin, const pointer aEnd) : mBegin(aBegin), mEnd(aEnd) {} + + pointer mBegin; + pointer mEnd; }; /** * Given the endpointId, returns all its supported modes options. * @param endpointId - * @return The iterator factory for the endpoint, or nullptr if the endpoint doesn't support ModeSelectCluster. + * @return The mode options provider for the endpoint. */ - virtual const ModeOptionStructIteratorFactory * getIteratorFactory(EndpointId endpointId) const = 0; + virtual const ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const = 0; /** * Given the endpointId and a mode value, find the ModeOptionStruct that matches the mode. @@ -102,6 +81,8 @@ class SupportedModesManager virtual ~SupportedModesManager() {} }; +const SupportedModesManager * getSupportedModesManager(); + } // namespace ModeSelect } // namespace Clusters } // namespace app From ed0a54a65d011cbade5f34d1f24b8a8dc81a8381 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 5 Nov 2021 10:50:38 +0000 Subject: [PATCH 02/10] Restyled by clang-format --- .../ameba/main/include/static-supported-modes-manager.h | 2 +- .../esp32/main/include/static-supported-modes-manager.h | 2 +- .../linux/include/static-supported-modes-manager.h | 2 +- .../mbed/main/include/static-supported-modes-manager.h | 4 ++-- .../p6/include/static-supported-modes-manager.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h b/examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h index eede1c31d5ae49..2d4f674a65920d 100644 --- a/examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h +++ b/examples/all-clusters-app/ameba/main/include/static-supported-modes-manager.h @@ -45,7 +45,7 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp mEndpointId(aEndpointId), mSpan(aSpan) {} - EndpointSpanPair(): mEndpointId(0), mSpan(Span()) {} + EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} }; static storage_value_type coffeeOptions[]; 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 index eede1c31d5ae49..2d4f674a65920d 100644 --- 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 @@ -45,7 +45,7 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp mEndpointId(aEndpointId), mSpan(aSpan) {} - EndpointSpanPair(): mEndpointId(0), mSpan(Span()) {} + EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} }; static storage_value_type coffeeOptions[]; 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 index eede1c31d5ae49..2d4f674a65920d 100644 --- a/examples/all-clusters-app/linux/include/static-supported-modes-manager.h +++ b/examples/all-clusters-app/linux/include/static-supported-modes-manager.h @@ -45,7 +45,7 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp mEndpointId(aEndpointId), mSpan(aSpan) {} - EndpointSpanPair(): mEndpointId(0), mSpan(Span()) {} + EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} }; static storage_value_type coffeeOptions[]; 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 index 7979ef297f1942..fda7ac72ae2d51 100644 --- 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 @@ -18,9 +18,9 @@ #pragma once -#include #include #include +#include namespace chip { namespace app { @@ -45,7 +45,7 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp mEndpointId(aEndpointId), mSpan(aSpan) {} - EndpointSpanPair(): mEndpointId(0), mSpan(Span()) {} + EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} }; static storage_value_type coffeeOptions[]; 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 index eede1c31d5ae49..2d4f674a65920d 100644 --- a/examples/all-clusters-app/p6/include/static-supported-modes-manager.h +++ b/examples/all-clusters-app/p6/include/static-supported-modes-manager.h @@ -45,7 +45,7 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp mEndpointId(aEndpointId), mSpan(aSpan) {} - EndpointSpanPair(): mEndpointId(0), mSpan(Span()) {} + EndpointSpanPair() : mEndpointId(0), mSpan(Span()) {} }; static storage_value_type coffeeOptions[]; From 44076a65f8c074fab23f54d3e66dcfcf5c256759 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 5 Nov 2021 10:50:38 +0000 Subject: [PATCH 03/10] Restyled by gn --- examples/all-clusters-app/linux/BUILD.gn | 6 ++---- examples/all-clusters-app/p6/BUILD.gn | 8 +++----- src/app/chip_data_model.gni | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index ded60aacecffb7..4df4191cc4507c 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -16,7 +16,6 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") static_library("static-supported-modes-manager") { - sources = [ "include/static-supported-modes-manager.cpp" ] #zap_pregenerated_dir = "${chip_root}/zzz_generated" @@ -28,7 +27,7 @@ static_library("static-supported-modes-manager") { "${chip_root}/src/controller", "${chip_root}/src/lib/core", ] - include_dirs = [ + include_dirs = [ "include", "${chip_root}/src", "${chip_root}/zzz_generated/all-clusters-app", @@ -37,7 +36,6 @@ static_library("static-supported-modes-manager") { cflags = [ "-Wconversion" ] print("include_dirs = ") - } executable("chip-all-clusters-app") { @@ -48,10 +46,10 @@ executable("chip-all-clusters-app") { ] deps = [ + ":static-supported-modes-manager", "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/src/lib", - ":static-supported-modes-manager", ] cflags = [ "-Wconversion" ] diff --git a/examples/all-clusters-app/p6/BUILD.gn b/examples/all-clusters-app/p6/BUILD.gn index ac966f0f471501..b396bc12512a4e 100644 --- a/examples/all-clusters-app/p6/BUILD.gn +++ b/examples/all-clusters-app/p6/BUILD.gn @@ -55,7 +55,6 @@ p6_sdk_sources("all_clusters_app_sdk_sources") { } static_library("static-supported-modes-manager") { - sources = [ "src/static-supported-modes-manager.cpp" ] #zap_pregenerated_dir = "${chip_root}/zzz_generated" @@ -67,7 +66,7 @@ static_library("static-supported-modes-manager") { "${chip_root}/src/controller", "${chip_root}/src/lib/core", ] - include_dirs = [ + include_dirs = [ "${chip_root}", "${chip_root}/src", "${chip_root}/zzz_generated/all-clusters-app", @@ -76,7 +75,6 @@ static_library("static-supported-modes-manager") { cflags = [ "-Wconversion" ] print("include_dirs = ") - } p6_executable("clusters_app") { @@ -92,13 +90,13 @@ p6_executable("clusters_app") { "src/ButtonHandler.cpp", "src/ClusterManager.cpp", "src/ZclCallbacks.cpp", - "src/static-supported-modes-manager.cpp", "src/main.cpp", + "src/static-supported-modes-manager.cpp", ] deps = [ - ":static-supported-modes-manager", ":all_clusters_app_sdk_sources", + ":static-supported-modes-manager", "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/common/QRCode", "${chip_root}/src/lib", diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index 6e4766cf69da30..217a1222572046 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -145,7 +145,7 @@ template("chip_data_model") { } else if (cluster == "mode-select-server") { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp", - "${_app_root}/clusters/${cluster}/supported-modes-manager.h" + "${_app_root}/clusters/${cluster}/supported-modes-manager.h", ] } else { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ] From c5b0253009698438868de02b68f75eac85bda455 Mon Sep 17 00:00:00 2001 From: du48s03 Date: Fri, 5 Nov 2021 06:51:34 -0700 Subject: [PATCH 04/10] Apply suggestions from code review --- .../ameba/main/static-supported-modes-manager.cpp | 3 --- .../esp32/main/static-supported-modes-manager.cpp | 3 --- .../linux/include/static-supported-modes-manager.cpp | 3 --- .../mbed/main/static-supported-modes-manager.cpp | 3 --- .../all-clusters-app/p6/src/static-supported-modes-manager.cpp | 3 --- 5 files changed, 15 deletions(-) diff --git a/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp b/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp index 5210cb2814fadf..3f25d4db41dd4b 100644 --- a/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp @@ -1,6 +1,3 @@ -// -// Created by Ding, Li-an on 10/21/21. -// #include using namespace std; 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 index 5210cb2814fadf..3f25d4db41dd4b 100644 --- a/examples/all-clusters-app/esp32/main/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/esp32/main/static-supported-modes-manager.cpp @@ -1,6 +1,3 @@ -// -// Created by Ding, Li-an on 10/21/21. -// #include using namespace std; 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 index 5210cb2814fadf..3f25d4db41dd4b 100644 --- a/examples/all-clusters-app/linux/include/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/linux/include/static-supported-modes-manager.cpp @@ -1,6 +1,3 @@ -// -// Created by Ding, Li-an on 10/21/21. -// #include using namespace std; 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 index 5210cb2814fadf..3f25d4db41dd4b 100644 --- a/examples/all-clusters-app/mbed/main/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/mbed/main/static-supported-modes-manager.cpp @@ -1,6 +1,3 @@ -// -// Created by Ding, Li-an on 10/21/21. -// #include using namespace std; 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 index 5210cb2814fadf..3f25d4db41dd4b 100644 --- a/examples/all-clusters-app/p6/src/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/p6/src/static-supported-modes-manager.cpp @@ -1,6 +1,3 @@ -// -// Created by Ding, Li-an on 10/21/21. -// #include using namespace std; From 9bd9c669af420efd9c1579a1a415dc788c6931c8 Mon Sep 17 00:00:00 2001 From: du48s03 Date: Mon, 8 Nov 2021 09:55:27 -0800 Subject: [PATCH 05/10] Update examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp Co-authored-by: Boris Zbarsky --- .../ameba/main/static-supported-modes-manager.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp b/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp index 3f25d4db41dd4b..edb62ae4031c72 100644 --- a/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/ameba/main/static-supported-modes-manager.cpp @@ -31,9 +31,7 @@ const StaticSupportedModesManager StaticSupportedModesManager::instance = Static 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]; + for (auto & endpointSpanPair : supportedOptionsByEndpoints) if (endpointSpanPair.mEndpointId == endpointId) { return ModeOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end()); From c4ca8308ca73f40d69353cc1924022e65ee21440 Mon Sep 17 00:00:00 2001 From: Li-An Ding Date: Mon, 8 Nov 2021 09:56:55 -0800 Subject: [PATCH 06/10] Put the static-supported-modes-manager to common paths. --- .../include/static-supported-modes-manager.h | 0 .../src}/static-supported-modes-manager.cpp | 1 + .../all-clusters-app/ameba/chip_main.cmake | 3 +- .../esp32/main/CMakeLists.txt | 1 + .../include/static-supported-modes-manager.h | 73 ------------------- .../main/static-supported-modes-manager.cpp | 72 ------------------ examples/all-clusters-app/linux/BUILD.gn | 6 +- .../static-supported-modes-manager.cpp | 72 ------------------ .../include/static-supported-modes-manager.h | 73 ------------------- examples/all-clusters-app/mbed/CMakeLists.txt | 3 +- .../include/static-supported-modes-manager.h | 73 ------------------- .../main/static-supported-modes-manager.cpp | 72 ------------------ examples/all-clusters-app/p6/BUILD.gn | 4 +- .../include/static-supported-modes-manager.h | 73 ------------------- .../p6/src/static-supported-modes-manager.cpp | 72 ------------------ third_party/cirque/repo | 2 +- third_party/zap/repo | 2 +- 17 files changed, 14 insertions(+), 588 deletions(-) rename examples/all-clusters-app/{ameba/main => all-clusters-common}/include/static-supported-modes-manager.h (100%) rename examples/all-clusters-app/{ameba/main => all-clusters-common/src}/static-supported-modes-manager.cpp (99%) delete mode 100644 examples/all-clusters-app/esp32/main/include/static-supported-modes-manager.h delete mode 100644 examples/all-clusters-app/esp32/main/static-supported-modes-manager.cpp delete mode 100644 examples/all-clusters-app/linux/include/static-supported-modes-manager.cpp delete mode 100644 examples/all-clusters-app/linux/include/static-supported-modes-manager.h delete mode 100644 examples/all-clusters-app/mbed/main/include/static-supported-modes-manager.h delete mode 100644 examples/all-clusters-app/mbed/main/static-supported-modes-manager.cpp delete mode 100644 examples/all-clusters-app/p6/include/static-supported-modes-manager.h delete mode 100644 examples/all-clusters-app/p6/src/static-supported-modes-manager.cpp 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 0ac61d7f8bb0da..a29e7a7ee086f3 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 8bd0c8c674abaa..2357c24ea3017f 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 From 1d419c7fc9f04fa10556e84958193616d96554ab Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 8 Nov 2021 20:34:51 +0000 Subject: [PATCH 07/10] Restyled by gn --- examples/all-clusters-app/linux/BUILD.gn | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index b7b6f896e1a987..c90f9eebc033eb 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -16,9 +16,7 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") static_library("static-supported-modes-manager") { - sources = [ - "${chip_root}/examples/all-clusters-app/all-clusters-common/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" @@ -37,7 +35,6 @@ static_library("static-supported-modes-manager") { ] cflags = [ "-Wconversion" ] - } executable("chip-all-clusters-app") { From dc21b2e4ad8a75567550625166fc43aaa393c8c0 Mon Sep 17 00:00:00 2001 From: Li-An Ding Date: Mon, 8 Nov 2021 19:44:39 -0800 Subject: [PATCH 08/10] Update submodules --- third_party/cirque/repo | 2 +- third_party/zap/repo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/cirque/repo b/third_party/cirque/repo index 144767dd06f1f8..262ea772466722 160000 --- a/third_party/cirque/repo +++ b/third_party/cirque/repo @@ -1 +1 @@ -Subproject commit 144767dd06f1f8549ffaa4beb06dadf71621c28d +Subproject commit 262ea7724667229f0d21d6a1c1e96d90415f0906 diff --git a/third_party/zap/repo b/third_party/zap/repo index 0376d5eb812d0f..98b43b32758cbf 160000 --- a/third_party/zap/repo +++ b/third_party/zap/repo @@ -1 +1 @@ -Subproject commit 0376d5eb812d0f3d5585861b0b88b2480799e92e +Subproject commit 98b43b32758cbfd8f643ef0a365cab9e0d9dcfde From ce3b8f20771cfc1a69fe6afbaf27fff83ac3c742 Mon Sep 17 00:00:00 2001 From: Li-An Ding Date: Mon, 8 Nov 2021 23:33:56 -0800 Subject: [PATCH 09/10] Remove static-supported-modes-option-manager as target from BUILD.gn --- examples/all-clusters-app/linux/BUILD.gn | 28 +++++------------------- examples/all-clusters-app/p6/BUILD.gn | 27 ++--------------------- 2 files changed, 7 insertions(+), 48 deletions(-) diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index c90f9eebc033eb..ce4bab1db2631a 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -15,42 +15,24 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -static_library("static-supported-modes-manager") { - sources = [ "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp" ] - - #zap_pregenerated_dir = "${chip_root}/zzz_generated" - - deps = [] - deps += [ - "${chip_root}/src/app", - "${chip_root}/src/app/common:cluster-objects", - "${chip_root}/src/controller", - "${chip_root}/src/lib/core", - ] - 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" ] -} - executable("chip-all-clusters-app") { sources = [ "${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", "include/tv-callbacks.cpp", "main.cpp", ] deps = [ - ":static-supported-modes-manager", "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/src/lib", ] + include_dirs = [ + "${chip_root}/examples/all-clusters-app/all-clusters-common/include" + ] + cflags = [ "-Wconversion" ] output_dir = root_out_dir diff --git a/examples/all-clusters-app/p6/BUILD.gn b/examples/all-clusters-app/p6/BUILD.gn index b5842c4137cc2b..5b99c3f3b3b6f6 100644 --- a/examples/all-clusters-app/p6/BUILD.gn +++ b/examples/all-clusters-app/p6/BUILD.gn @@ -54,30 +54,6 @@ p6_sdk_sources("all_clusters_app_sdk_sources") { public_configs = [ "${chip_root}/third_party/p6:p6_sdk_config" ] } -static_library("static-supported-modes-manager") { - sources = [ "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp" ] - - #zap_pregenerated_dir = "${chip_root}/zzz_generated" - - public_deps = [] - public_deps += [ - "${chip_root}/src/app", - "${chip_root}/src/app/common:cluster-objects", - "${chip_root}/src/controller", - "${chip_root}/src/lib/core", - ] - include_dirs = [ - "${chip_root}", - "${chip_root}/src", - "${chip_root}/zzz_generated/all-clusters-app", - "${chip_root}/examples/all-clusters-app/all-clusters-common/include", - ] - - cflags = [ "-Wconversion" ] - - print("include_dirs = ") -} - p6_executable("clusters_app") { include_dirs = [] defines = [] @@ -85,6 +61,7 @@ p6_executable("clusters_app") { sources = [ "${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", "${examples_plat_dir}/LEDWidget.cpp", "${examples_plat_dir}/init_p6Platform.cpp", "src/AppTask.cpp", @@ -96,7 +73,6 @@ p6_executable("clusters_app") { deps = [ ":all_clusters_app_sdk_sources", - ":static-supported-modes-manager", "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/common/QRCode", "${chip_root}/src/lib", @@ -107,6 +83,7 @@ p6_executable("clusters_app") { "include", "${examples_plat_dir}", "${p6_project_dir}/include", + "${chip_root}/examples/all-clusters-app/all-clusters-common/include", ] defines = [] From abe437912943ec75478ac68b00adba5a706ee6e4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 9 Nov 2021 07:34:34 +0000 Subject: [PATCH 10/10] Restyled by gn --- examples/all-clusters-app/linux/BUILD.gn | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index ce4bab1db2631a..351b79e8f5f316 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -29,9 +29,8 @@ executable("chip-all-clusters-app") { "${chip_root}/src/lib", ] - include_dirs = [ - "${chip_root}/examples/all-clusters-app/all-clusters-common/include" - ] + include_dirs = + [ "${chip_root}/examples/all-clusters-app/all-clusters-common/include" ] cflags = [ "-Wconversion" ]