From adb67d93d62f86dac92f1c47f6b70db3a2802088 Mon Sep 17 00:00:00 2001 From: Youngho Yoon <34558998+yhoyoon@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:20:55 +0900 Subject: [PATCH 1/2] Update bridge app to init network commissioning This change modifies the linux bridge app to initialize the Network Commissioning cluster, so that the FeatureMap of the cluster is set to ethernet. In other Linux example apps, the FeatureMap of the Network Commissioning cluster is set to ethernet, but in the bridge app, the cluster is not initialized, so the FeatureMap is set to thread. The default value of the FeatureMap is thread in zap file of example apps. Signed-off-by: Youngho Yoon <34558998+yhoyoon@users.noreply.github.com> --- examples/bridge-app/linux/main.cpp | 1 + examples/platform/linux/AppMain.cpp | 6 +++--- examples/platform/linux/AppMain.h | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/bridge-app/linux/main.cpp b/examples/bridge-app/linux/main.cpp index 3d73688594c5a9..2cfe37a12d4125 100644 --- a/examples/bridge-app/linux/main.cpp +++ b/examples/bridge-app/linux/main.cpp @@ -1024,6 +1024,7 @@ int main(int argc, char * argv[]) // Run CHIP + ChipLinuxAppInitNetworkCommissioning(); ApplicationInit(); registerAttributeAccessOverride(&gPowerAttrAccess); chip::DeviceLayer::PlatformMgr().RunEventLoop(); diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 56e6edd44687f2..2056734dfa7696 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -177,8 +177,9 @@ void EnableWiFiNetworkCommissioning(EndpointId endpoint) sWiFiNetworkCommissioningInstance.Value().Init(); #endif // CHIP_APP_MAIN_HAS_WIFI_DRIVER } +} // anonymous namespace -void InitNetworkCommissioning() +void ChipLinuxAppInitNetworkCommissioning() { if (sSecondaryNetworkCommissioningEndpoint.HasValue()) { @@ -232,7 +233,6 @@ void InitNetworkCommissioning() #endif // CHIP_APP_MAIN_HAS_ETHERNET_DRIVER } } -} // anonymous namespace #if defined(ENABLE_CHIP_SHELL) using chip::Shell::Engine; @@ -582,7 +582,7 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl) #endif // defined(ENABLE_CHIP_SHELL) #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE - InitNetworkCommissioning(); + ChipLinuxAppInitNetworkCommissioning(); ApplicationInit(); diff --git a/examples/platform/linux/AppMain.h b/examples/platform/linux/AppMain.h index 94bf4d3e609da1..d8af2775bd2346 100644 --- a/examples/platform/linux/AppMain.h +++ b/examples/platform/linux/AppMain.h @@ -88,6 +88,11 @@ class DefaultAppMainLoopImplementation : public AppMainLoopImplementation */ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl = nullptr); +// This function supports initializing the Network Commissioning cluster for the +// Linux app that does not call ChipLinuxAppMainLoop. This function should be +// called before calling the ApplicationInit function. +void ChipLinuxAppInitNetworkCommissioning(); + #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE using chip::Controller::DeviceCommissioner; From d1b39c81198567813b558df6968d58c9245ddea2 Mon Sep 17 00:00:00 2001 From: Youngho Yoon <34558998+yhoyoon@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:01:49 +0900 Subject: [PATCH 2/2] Move the setup code into ApplicationInit Signed-off-by: Youngho Yoon <34558998+yhoyoon@users.noreply.github.com> --- examples/bridge-app/linux/main.cpp | 41 ++++++++--------------------- examples/platform/linux/AppMain.cpp | 6 ++--- examples/platform/linux/AppMain.h | 5 ---- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/examples/bridge-app/linux/main.cpp b/examples/bridge-app/linux/main.cpp index 2cfe37a12d4125..f9edf960ded512 100644 --- a/examples/bridge-app/linux/main.cpp +++ b/examples/bridge-app/linux/main.cpp @@ -739,10 +739,6 @@ bool emberAfActionsClusterInstantActionCallback(app::CommandHandler * commandObj return true; } -void ApplicationInit() {} - -void ApplicationShutdown() {} - const EmberAfDeviceType gBridgedOnOffDeviceTypes[] = { { DEVICE_TYPE_LO_ON_OFF_LIGHT, DEVICE_VERSION_DEFAULT }, { DEVICE_TYPE_BRIDGED_NODE, DEVICE_VERSION_DEFAULT } }; @@ -891,7 +887,7 @@ void * bridge_polling_thread(void * context) return nullptr; } -int main(int argc, char * argv[]) +void ApplicationInit() { // Clear out the device database memset(gDevices, 0, sizeof(gDevices)); @@ -934,26 +930,6 @@ int main(int argc, char * argv[]) ComposedTempSensor2.SetChangeCallback(&HandleDeviceTempSensorStatusChanged); ComposedPowerSource.SetChangeCallback(&HandleDevicePowerSourceStatusChanged); - if (ChipLinuxAppInit(argc, argv) != 0) - { - return -1; - } - - // Init Data Model and CHIP App Server - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - -#if CHIP_DEVICE_ENABLE_PORT_PARAMS - // use a different service port to make testing possible with other sample devices running on same host - initParams.operationalServicePort = LinuxDeviceOptions::GetInstance().securedDevicePort; -#endif - - initParams.interfaceId = LinuxDeviceOptions::GetInstance().interfaceId; - chip::Server::GetInstance().Init(initParams); - - // Initialize device attestation config - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - // Set starting endpoint id where dynamic endpoints will be assigned, which // will be the next consecutive endpoint id after the last fixed endpoint. gFirstDynamicEndpointId = static_cast( @@ -1022,12 +998,17 @@ int main(int argc, char * argv[]) } } - // Run CHIP - - ChipLinuxAppInitNetworkCommissioning(); - ApplicationInit(); registerAttributeAccessOverride(&gPowerAttrAccess); - chip::DeviceLayer::PlatformMgr().RunEventLoop(); +} +void ApplicationShutdown() {} + +int main(int argc, char * argv[]) +{ + if (ChipLinuxAppInit(argc, argv) != 0) + { + return -1; + } + ChipLinuxAppMainLoop(); return 0; } diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 2056734dfa7696..56e6edd44687f2 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -177,9 +177,8 @@ void EnableWiFiNetworkCommissioning(EndpointId endpoint) sWiFiNetworkCommissioningInstance.Value().Init(); #endif // CHIP_APP_MAIN_HAS_WIFI_DRIVER } -} // anonymous namespace -void ChipLinuxAppInitNetworkCommissioning() +void InitNetworkCommissioning() { if (sSecondaryNetworkCommissioningEndpoint.HasValue()) { @@ -233,6 +232,7 @@ void ChipLinuxAppInitNetworkCommissioning() #endif // CHIP_APP_MAIN_HAS_ETHERNET_DRIVER } } +} // anonymous namespace #if defined(ENABLE_CHIP_SHELL) using chip::Shell::Engine; @@ -582,7 +582,7 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl) #endif // defined(ENABLE_CHIP_SHELL) #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE - ChipLinuxAppInitNetworkCommissioning(); + InitNetworkCommissioning(); ApplicationInit(); diff --git a/examples/platform/linux/AppMain.h b/examples/platform/linux/AppMain.h index d8af2775bd2346..94bf4d3e609da1 100644 --- a/examples/platform/linux/AppMain.h +++ b/examples/platform/linux/AppMain.h @@ -88,11 +88,6 @@ class DefaultAppMainLoopImplementation : public AppMainLoopImplementation */ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl = nullptr); -// This function supports initializing the Network Commissioning cluster for the -// Linux app that does not call ChipLinuxAppMainLoop. This function should be -// called before calling the ApplicationInit function. -void ChipLinuxAppInitNetworkCommissioning(); - #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE using chip::Controller::DeviceCommissioner;