diff --git a/examples/lighting-app/linux/main.cpp b/examples/lighting-app/linux/main.cpp index 77fdc5911c90e6..f83509cd71ae1c 100644 --- a/examples/lighting-app/linux/main.cpp +++ b/examples/lighting-app/linux/main.cpp @@ -25,7 +25,17 @@ #include #include #include + +#if CHIP_DEVICE_LAYER_TARGET_DARWIN +#include +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI +#endif // CHIP_DEVICE_LAYER_TARGET_DARWIN + +#if CHIP_DEVICE_LAYER_TARGET_LINUX #include +#endif // CHIP_DEVICE_LAYER_TARGET_LINUX #if defined(CHIP_IMGUI_ENABLED) && CHIP_IMGUI_ENABLED #include @@ -39,12 +49,39 @@ using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; -#if CHIP_DEVICE_CONFIG_ENABLE_WPA namespace { -DeviceLayer::NetworkCommissioning::LinuxWiFiDriver sLinuxWiFiDriver; -Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0, &sLinuxWiFiDriver); + +#if CHIP_DEVICE_LAYER_TARGET_LINUX +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +DeviceLayer::NetworkCommissioning::LinuxThreadDriver sThreadDriver; +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +DeviceLayer::NetworkCommissioning::LinuxWiFiDriver sWiFiDriver; +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI + +DeviceLayer::NetworkCommissioning::LinuxEthernetDriver sEthernetDriver; +#endif // CHIP_DEVICE_LAYER_TARGET_LINUX + +#if CHIP_DEVICE_LAYER_TARGET_DARWIN +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +DeviceLayer::NetworkCommissioning::DarwinWiFiDriver sWiFiDriver; +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI + +DeviceLayer::NetworkCommissioning::DarwinEthernetDriver sEthernetDriver; +#endif // CHIP_DEVICE_LAYER_TARGET_DARWIN + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0, &sWiFiDriver); +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +Clusters::NetworkCommissioning::Instance sThreadNetworkCommissioningInstance(0, &sThreadDriver); +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD + +Clusters::NetworkCommissioning::Instance sEthernetNetworkCommissioningInstance(0, &sEthernetDriver); + } // namespace -#endif void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) @@ -77,9 +114,45 @@ void emberAfOnOffClusterInitCallback(EndpointId endpoint) void ApplicationInit() { -#if CHIP_DEVICE_CONFIG_ENABLE_WPA - sWiFiNetworkCommissioningInstance.Init(); + const bool kThreadEnabled = { +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + LinuxDeviceOptions::GetInstance().mThread +#else + false +#endif + }; + + const bool kWiFiEnabled = { +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + LinuxDeviceOptions::GetInstance().mWiFi +#else + false +#endif + }; + + if (kThreadEnabled && kWiFiEnabled) + { + // Just use the Thread one. +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + sThreadNetworkCommissioningInstance.Init(); +#endif + } + else if (kThreadEnabled) + { +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + sThreadNetworkCommissioningInstance.Init(); +#endif + } + else if (kWiFiEnabled) + { +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + sWiFiNetworkCommissioningInstance.Init(); #endif + } + else + { + sEthernetNetworkCommissioningInstance.Init(); + } } int main(int argc, char * argv[])