Skip to content

Commit

Permalink
ModeSelect: Add setter API for SupportedModesManager. (project-chip#3…
Browse files Browse the repository at this point in the history
…4809)

* Add setter API for SupportedModesManager

* Example changes

* Restyled by clang-format

* Fix namespace usage

* Address review comments

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
jadhavrohit924 and restyled-commits authored Aug 18, 2024
1 parent 2787db2 commit 1d4f684
Show file tree
Hide file tree
Showing 30 changed files with 105 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ModeSelect {
* This implementation statically defines the options.
*/

class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::SupportedModesManager
class StaticSupportedModesManager : public SupportedModesManager
{
using ModeOptionStructType = Structs::ModeOptionStruct::Type;
using storage_value_type = const ModeOptionStructType;
Expand All @@ -52,8 +52,6 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp
static const EndpointSpanPair supportedOptionsByEndpoints[MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT];

public:
static const StaticSupportedModesManager instance;

SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override;

Protocols::InteractionModel::Status getModeOptionByMode(EndpointId endpointId, uint8_t mode,
Expand All @@ -62,12 +60,8 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp
~StaticSupportedModesManager(){};

StaticSupportedModesManager() {}

static inline const StaticSupportedModesManager & getStaticSupportedModesManagerInstance() { return instance; }
};

const SupportedModesManager * getSupportedModesManager();

} // namespace ModeSelect
} // namespace Clusters
} // namespace app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const StaticSupportedModesManager::EndpointSpanPair
EndpointSpanPair(1, Span<storage_value_type>(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1
};

const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager();

SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const
{
for (auto & endpointSpanPair : supportedOptionsByEndpoints)
Expand Down Expand Up @@ -76,8 +74,3 @@ Status StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointI
ChipLogProgress(Zcl, "Cannot find the mode %u", mode);
return Status::InvalidCommand;
}

const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager()
{
return &StaticSupportedModesManager::instance;
}
3 changes: 3 additions & 0 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>
#include <support/CHIPMem.h>
#if CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER
Expand Down Expand Up @@ -77,6 +78,7 @@ app::Clusters::NetworkCommissioning::Instance
&(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));

app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;
} // namespace

void NetWorkCommissioningInstInit()
Expand Down Expand Up @@ -181,6 +183,7 @@ static void InitServer(intptr_t context)
InitManualOperation();
#endif
app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
MatterMicrowaveOvenServerInit();
#if CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER
static SmokeCOTestEventTriggerHandler sSmokeCOTestEventTriggerHandler;
Expand Down
3 changes: 3 additions & 0 deletions examples/all-clusters-app/asr/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <protocols/interaction_model/StatusCode.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>

using chip::Protocols::InteractionModel::Status;
Expand All @@ -66,6 +67,7 @@ app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */,
&(NetworkCommissioning::ASRWiFiDriver::GetInstance()));
app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;
} // namespace

AppTask AppTask::sAppTask;
Expand Down Expand Up @@ -131,6 +133,7 @@ CHIP_ERROR AppTask::Init()
#endif /* CONFIG_NETWORK_LAYER_BLE */

app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);

return CHIP_NO_ERROR;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <app/clusters/general-diagnostics-server/GenericFaultTestEventTriggerHandler.h>
#include <src/platform/cc13xx_26xx/DefaultTestEventTriggerDelegate.h>

#include <static-supported-modes-manager.h>
#include <ti/drivers/apps/Button.h>
#include <ti/drivers/apps/LED.h>

Expand All @@ -73,6 +74,7 @@ static Button_Handle sAppRightHandle;
static DeviceInfoProviderImpl sExampleDeviceInfoProvider;

AppTask AppTask::sAppTask;
app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;

constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

Expand Down Expand Up @@ -334,6 +336,7 @@ int AppTask::Init()
// QR code will be used with CHIP Tool
PrintOnboardingCodes(RendezvousInformationFlags(RendezvousInformationFlag::kBLE));

app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
return 0;
}

Expand Down
6 changes: 1 addition & 5 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/mode-support"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/icd/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util"
Expand Down Expand Up @@ -112,8 +111,6 @@ set(SRC_DIRS_LIST
)


set(EXCLUDE_SRCS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp")

if (CONFIG_ENABLE_PW_RPC)
# Append additional directories for RPC build
set(PRIV_INCLUDE_DIRS_LIST "${PRIV_INCLUDE_DIRS_LIST}"
Expand Down Expand Up @@ -143,8 +140,7 @@ if (CONFIG_ENABLE_ICD_SERVER)
endif()

idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST}
SRC_DIRS ${SRC_DIRS_LIST}
EXCLUDE_SRCS ${EXCLUDE_SRCS})
SRC_DIRS ${SRC_DIRS_LIST})

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)

Expand Down
11 changes: 3 additions & 8 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
#include <common/Esp32ThreadInit.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <examples/platform/esp32/mode-support/static-supported-modes-manager.h>
#include <platform/ESP32/ESP32Utils.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>

#if CONFIG_HAVE_DISPLAY
Expand Down Expand Up @@ -95,6 +95,7 @@ class AppCallbacks : public AppDelegate
AppCallbacks sCallbacks;

app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;

constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

Expand Down Expand Up @@ -122,15 +123,9 @@ static void InitServer(intptr_t context)
#if CONFIG_DEVICE_TYPE_M5STACK
SetupPretendDevices();
#endif
CHIP_ERROR err =
app::Clusters::ModeSelect::StaticSupportedModesManager::getStaticSupportedModesManagerInstance().InitEndpointArray(
FIXED_ENDPOINT_COUNT);
if (err != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "Failed to initialize endpoint array for supported-modes, err:%" CHIP_ERROR_FORMAT, err.Format());
}

app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
}

// #include <laundry-washer-controls-server/laundry-washer-controls-server.h>
Expand Down
3 changes: 3 additions & 0 deletions examples/all-clusters-app/infineon/psoc6/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <DeviceInfoProviderImpl.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <platform/Infineon/PSOC6/NetworkCommissioningDriver.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>

/* OTA related includes */
Expand Down Expand Up @@ -98,6 +99,7 @@ OTAImageProcessorImpl gImageProcessor;
#endif

chip::app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
chip::app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;
} // namespace

using namespace ::chip;
Expand Down Expand Up @@ -141,6 +143,7 @@ static void InitServer(intptr_t context)
GetAppTask().InitOTARequestor();
#endif
chip::app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
chip::app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
}

CHIP_ERROR AppTask::StartAppTask()
Expand Down
3 changes: 3 additions & 0 deletions examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include <platform/DeviceInstanceInfoProvider.h>
#include <platform/DiagnosticDataProvider.h>
#include <platform/PlatformManager.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SessionManager.h>
Expand All @@ -80,6 +81,7 @@ AllClustersCommandDelegate sAllClustersCommandDelegate;
Clusters::WindowCovering::WindowCoveringManager sWindowCoveringManager;

Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;
Clusters::ValveConfigurationAndControl::ValveControlDelegate sValveDelegate;
Clusters::TimeSynchronization::ExtendedTimeSyncDelegate sTimeSyncDelegate;

Expand Down Expand Up @@ -246,6 +248,7 @@ void ApplicationInit()
MatterDishwasherAlarmServerInit();
#endif
Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);

Clusters::ValveConfigurationAndControl::SetDefaultDelegate(chip::EndpointId(1), &sValveDelegate);
Clusters::TimeSynchronization::SetDefaultDelegate(&sTimeSyncDelegate);
Expand Down
5 changes: 4 additions & 1 deletion examples/all-clusters-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>

#include <lib/support/logging/CHIPLogging.h>
Expand All @@ -45,7 +46,8 @@ using namespace ::chip::Credentials;

namespace {
app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
}
app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;
} // namespace

AppTask AppTask::sAppTask;

Expand Down Expand Up @@ -90,6 +92,7 @@ int AppTask::Init()
return EXIT_FAILURE;
}
app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions examples/all-clusters-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>

#ifdef CONFIG_CHIP_WIFI
Expand Down Expand Up @@ -95,6 +96,7 @@ bool sIsNetworkEnabled = false;
bool sHaveBLEConnections = false;

app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;

#ifdef CONFIG_CHIP_CRYPTO_PSA
chip::Crypto::PSAOperationalKeystore sPSAOperationalKeystore{};
Expand Down Expand Up @@ -257,6 +259,7 @@ CHIP_ERROR AppTask::Init()
}

app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
return err;
}

Expand Down
3 changes: 3 additions & 0 deletions examples/all-clusters-app/nxp/mw320/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>

#include <app/InteractionModelEngine.h>
Expand Down Expand Up @@ -121,6 +122,7 @@ static struct wlan_network sta_network;
static struct wlan_network uap_network;

chip::app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
chip::app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;

const int TASK_MAIN_PRIO = OS_PRIO_3;
const int TASK_MAIN_STACK_SIZE = 800;
Expand Down Expand Up @@ -1083,6 +1085,7 @@ static void run_chip_srv(System::Layer * aSystemLayer, void * aAppState)
// binding --

chip::app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
chip::app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);

return;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/all-clusters-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

#include "AppTask.h"
#include "binding-handler.h"
#include <static-supported-modes-manager.h>

LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);

AppTask AppTask::sAppTask;
chip::app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;

CHIP_ERROR AppTask::Init(void)
{
Expand All @@ -35,5 +37,6 @@ CHIP_ERROR AppTask::Init(void)
return err;
}

chip::app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
return CHIP_NO_ERROR;
}
3 changes: 3 additions & 0 deletions examples/all-clusters-app/tizen/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/util/endpoint-config-api.h>
#include <platform/Tizen/NetworkCommissioningDriver.h>
#include <static-supported-modes-manager.h>
#include <static-supported-temperature-levels.h>

#include <TizenServiceAppMain.h>
Expand All @@ -40,6 +41,7 @@ NetworkCommissioning::TizenEthernetDriver sEthernetDriver;
Clusters::NetworkCommissioning::Instance sEthernetNetworkCommissioningInstance(kNetworkCommissioningEndpointMain, &sEthernetDriver);

app::Clusters::TemperatureControl::AppSupportedTemperatureLevelsDelegate sAppSupportedTemperatureLevelsDelegate;
Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;
} // namespace

void ApplicationInit()
Expand All @@ -49,6 +51,7 @@ void ApplicationInit()

sEthernetNetworkCommissioningInstance.Init();
app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
}

void ApplicationShutdown() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <static-supported-modes-manager.h>
#include <support/CHIPMem.h>

#if CONFIG_ENABLE_OTA_REQUESTOR
Expand Down Expand Up @@ -64,6 +65,7 @@ namespace { // Network Commissioning
constexpr EndpointId kNetworkCommissioningEndpointMain = 0;
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;
app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */,
&(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));
Expand Down Expand Up @@ -170,6 +172,7 @@ static void InitServer(intptr_t context)
// QR code will be used with CHIP Tool
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}
Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
}

extern "C" void ChipTest(void)
Expand Down
3 changes: 3 additions & 0 deletions examples/all-clusters-minimal-app/asr/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <queue.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <static-supported-modes-manager.h>

#include "init_Matter.h"
#include "lega_rtos_api.h"
Expand All @@ -60,6 +61,7 @@ QueueHandle_t sAppEventQueue;
constexpr EndpointId kNetworkCommissioningEndpointMain = 0;
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

app::Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager;
app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */,
&(NetworkCommissioning::ASRWiFiDriver::GetInstance()));
Expand Down Expand Up @@ -120,6 +122,7 @@ CHIP_ERROR AppTask::Init()

sLightLED.Init(LIGHT_LED);

app::Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager);
return CHIP_NO_ERROR;
}

Expand Down
Loading

0 comments on commit 1d4f684

Please sign in to comment.