From d4da2fa535eb9de15fc780ffc616f2444667e0cd Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 28 Apr 2021 11:25:25 -0400 Subject: [PATCH] Update init params for controller to include ble layer (#6315) * Update init parameters for controller and commisioner, change CPP references to use the new format. Make android pass in the BLE layer * Update iOS arguments to controller init * Revert unintentional changes in xml/settings files --- .../commands/clusters/ModelCommand.cpp | 5 +++- .../commands/discover/DiscoverCommand.cpp | 8 +++---- .../commands/pairing/PairingCommand.cpp | 11 +++++---- .../commands/reporting/ReportingCommand.cpp | 5 +++- src/controller/CHIPDeviceController.cpp | 21 ++--------------- src/controller/CHIPDeviceController.h | 23 ++++++------------- .../java/AndroidDeviceControllerWrapper.cpp | 13 ++++++++++- .../java/CHIPDeviceController-JNI.cpp | 9 ++++++++ .../ChipDeviceController-ScriptBinding.cpp | 9 +++++--- .../python/chip/internal/CommissionerImpl.cpp | 15 ++++++------ .../Framework/CHIP/CHIPDeviceController.mm | 11 +++++---- 11 files changed, 68 insertions(+), 62 deletions(-) diff --git a/examples/chip-tool/commands/clusters/ModelCommand.cpp b/examples/chip-tool/commands/clusters/ModelCommand.cpp index d71c5d2e31db0d..efe866b451800e 100644 --- a/examples/chip-tool/commands/clusters/ModelCommand.cpp +++ b/examples/chip-tool/commands/clusters/ModelCommand.cpp @@ -29,11 +29,14 @@ constexpr uint16_t kWaitDurationInSeconds = 10; CHIP_ERROR ModelCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) { CHIP_ERROR err = CHIP_NO_ERROR; + chip::Controller::CommissionerInitParams initParams; + + initParams.storageDelegate = &storage; err = mCommissioner.SetUdpListenPort(storage.GetListenPort()); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err))); - err = mCommissioner.Init(localId, &storage); + err = mCommissioner.Init(localId, initParams); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err))); err = mCommissioner.ServiceEvents(); diff --git a/examples/chip-tool/commands/discover/DiscoverCommand.cpp b/examples/chip-tool/commands/discover/DiscoverCommand.cpp index 3e75dbf07cdc46..ad8ffb1805ddb7 100644 --- a/examples/chip-tool/commands/discover/DiscoverCommand.cpp +++ b/examples/chip-tool/commands/discover/DiscoverCommand.cpp @@ -22,10 +22,10 @@ constexpr uint16_t kWaitDurationInSeconds = 30; CHIP_ERROR DiscoverCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) { - chip::Controller::ControllerInitParams params{ - .storageDelegate = &storage, - .mDeviceAddressUpdateDelegate = this, - }; + chip::Controller::CommissionerInitParams params; + + params.storageDelegate = &storage; + params.mDeviceAddressUpdateDelegate = this; ReturnErrorOnFailure(mCommissioner.SetUdpListenPort(storage.GetListenPort())); ReturnErrorOnFailure(mCommissioner.Init(localId, params)); diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 0471e3be6898f5..c22841355d3422 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -31,15 +31,16 @@ CHIP_ERROR PairingCommand::Run(PersistentStorage & storage, NodeId localId, Node { CHIP_ERROR err = CHIP_NO_ERROR; - chip::Controller::ControllerInitParams params{ - .storageDelegate = &storage, - .mDeviceAddressUpdateDelegate = this, - }; + chip::Controller::CommissionerInitParams params; + + params.storageDelegate = &storage; + params.mDeviceAddressUpdateDelegate = this; + params.pairingDelegate = this; err = mCommissioner.SetUdpListenPort(storage.GetListenPort()); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err))); - err = mCommissioner.Init(localId, params, this); + err = mCommissioner.Init(localId, params); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err))); err = mCommissioner.ServiceEvents(); diff --git a/examples/chip-tool/commands/reporting/ReportingCommand.cpp b/examples/chip-tool/commands/reporting/ReportingCommand.cpp index 48219eeb1fa5b2..6f79239c0b3354 100644 --- a/examples/chip-tool/commands/reporting/ReportingCommand.cpp +++ b/examples/chip-tool/commands/reporting/ReportingCommand.cpp @@ -32,11 +32,14 @@ CHIP_ERROR ReportingCommand::Run(PersistentStorage & storage, NodeId localId, No { CHIP_ERROR err = CHIP_NO_ERROR; chip::Controller::BasicCluster cluster; + chip::Controller::CommissionerInitParams initParams; + + initParams.storageDelegate = &storage; err = mCommissioner.SetUdpListenPort(storage.GetListenPort()); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err))); - err = mCommissioner.Init(localId, &storage); + err = mCommissioner.Init(localId, initParams); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Commissioner: %s", ErrorStr(err))); err = mCommissioner.ServiceEvents(); diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index e239a86a7edad2..617a2226ec28f5 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -106,13 +106,6 @@ DeviceController::DeviceController() mListenPort = CHIP_PORT; } -CHIP_ERROR DeviceController::Init(NodeId localDeviceId, PersistentStorageDelegate * storageDelegate, System::Layer * systemLayer, - Inet::InetLayer * inetLayer) -{ - return Init(localDeviceId, - ControllerInitParams{ .storageDelegate = storageDelegate, .systemLayer = systemLayer, .inetLayer = inetLayer }); -} - CHIP_ERROR DeviceController::Init(NodeId localDeviceId, ControllerInitParams params) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -646,7 +639,6 @@ DeviceCommissioner::DeviceCommissioner() mDeviceBeingPaired = kNumMaxActiveDevices; mPairedDevicesUpdated = false; } - CHIP_ERROR DeviceCommissioner::LoadKeyId(PersistentStorageDelegate * delegate, uint16_t & out) { VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -661,16 +653,7 @@ CHIP_ERROR DeviceCommissioner::LoadKeyId(PersistentStorageDelegate * delegate, u return CHIP_NO_ERROR; } -CHIP_ERROR DeviceCommissioner::Init(NodeId localDeviceId, PersistentStorageDelegate * storageDelegate, - DevicePairingDelegate * pairingDelegate, System::Layer * systemLayer, - Inet::InetLayer * inetLayer) -{ - return Init(localDeviceId, - ControllerInitParams{ .storageDelegate = storageDelegate, .systemLayer = systemLayer, .inetLayer = inetLayer }, - pairingDelegate); -} - -CHIP_ERROR DeviceCommissioner::Init(NodeId localDeviceId, ControllerInitParams params, DevicePairingDelegate * pairingDelegate) +CHIP_ERROR DeviceCommissioner::Init(NodeId localDeviceId, CommissionerInitParams params) { ReturnErrorOnFailure(DeviceController::Init(localDeviceId, params)); @@ -679,7 +662,7 @@ CHIP_ERROR DeviceCommissioner::Init(NodeId localDeviceId, ControllerInitParams p mNextKeyId = 0; } - mPairingDelegate = pairingDelegate; + mPairingDelegate = params.pairingDelegate; return CHIP_NO_ERROR; } diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index 3c62ac05531df8..791a6c083a79d8 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -125,6 +125,11 @@ class DLL_EXPORT DevicePairingDelegate virtual void OnPairingDeleted(CHIP_ERROR error) {} }; +struct CommissionerInitParams : public ControllerInitParams +{ + DevicePairingDelegate * pairingDelegate = nullptr; +}; + /** * @brief * Controller applications can use this class to communicate with already paired CHIP devices. The @@ -145,16 +150,8 @@ class DLL_EXPORT DeviceController : public Messaging::ExchangeDelegate, DeviceController(); virtual ~DeviceController() {} - /** - * Init function to be used when there exists a device layer that takes care of initializing - * System::Layer and InetLayer. - */ CHIP_ERROR Init(NodeId localDeviceId, ControllerInitParams params); - // Note: Future modifications should be made to ControllerInitParams - CHIP_ERROR Init(NodeId localDeviceId, PersistentStorageDelegate * storageDelegate = nullptr, - System::Layer * systemLayer = nullptr, Inet::InetLayer * inetLayer = nullptr); - virtual CHIP_ERROR Shutdown(); /** @@ -319,15 +316,9 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, public Rendezvous ~DeviceCommissioner() {} /** - * Init function to be used when there exists a device layer that takes care of initializing - * System::Layer and InetLayer. + * Commisioner-specific initialization, includes parameters such as the pairing delegate. */ - CHIP_ERROR Init(NodeId localDeviceId, ControllerInitParams params, DevicePairingDelegate * pairingDelegate = nullptr); - - // Note: Future modifications should be made to ControllerInitParams - CHIP_ERROR Init(NodeId localDeviceId, PersistentStorageDelegate * storageDelegate = nullptr, - DevicePairingDelegate * pairingDelegate = nullptr, System::Layer * systemLayer = nullptr, - Inet::InetLayer * inetLayer = nullptr); + CHIP_ERROR Init(NodeId localDeviceId, CommissionerInitParams params); void SetDevicePairingDelegate(DevicePairingDelegate * pairingDelegate) { mPairingDelegate = pairingDelegate; } diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 08904a90ed555d..0917afb769d9df 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -25,6 +25,8 @@ using chip::PersistentStorageResultDelegate; using chip::Controller::DeviceCommissioner; +extern chip::Ble::BleLayer * GetJNIBleLayer(); + namespace { bool FindMethod(JNIEnv * env, jobject object, const char * methodName, const char * methodSignature, jmethodID * methodId) @@ -187,7 +189,16 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(Jav wrapper->SetJavaObjectRef(vm, deviceControllerObj); wrapper->Controller()->SetUdpListenPort(CHIP_PORT + 1); - *errInfoOnFailure = wrapper->Controller()->Init(nodeId, wrapper.get(), wrapper.get(), systemLayer, inetLayer); + + chip::Controller::CommissionerInitParams initParams; + + initParams.storageDelegate = wrapper.get(); + initParams.pairingDelegate = wrapper.get(); + initParams.systemLayer = systemLayer; + initParams.inetLayer = inetLayer; + initParams.bleLayer = GetJNIBleLayer(); + + *errInfoOnFailure = wrapper->Controller()->Init(nodeId, initParams); if (*errInfoOnFailure != CHIP_NO_ERROR) { diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index df4e946a069828..6c7ef31cc04662 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -124,6 +124,15 @@ struct StackUnlockGuard chip::NodeId kLocalDeviceId = chip::kTestControllerNodeId; chip::NodeId kRemoteDeviceId = chip::kTestDeviceNodeId; +#if CONFIG_NETWORK_LAYER_BLE + +chip::Ble::BleLayer * GetJNIBleLayer() +{ + return &sBleLayer; +} + +#endif + jint JNI_OnLoad(JavaVM * jvm, void * reserved) { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index 2e0f97b7ac909a..ba1d14009c031d 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -128,8 +128,7 @@ CHIP_ERROR pychip_DeviceController_NewDeviceController(chip::Controller::DeviceC chip::NodeId localDeviceId) { CHIP_ERROR err = CHIP_NO_ERROR; - ControllerInitParams initParams{ .storageDelegate = &sStorageDelegate, - .mDeviceAddressUpdateDelegate = &sDeviceAddressUpdateDelegate }; + CommissionerInitParams initParams; *outDevCtrl = new chip::Controller::DeviceCommissioner(); VerifyOrExit(*outDevCtrl != NULL, err = CHIP_ERROR_NO_MEMORY); @@ -139,11 +138,15 @@ CHIP_ERROR pychip_DeviceController_NewDeviceController(chip::Controller::DeviceC localDeviceId = kDefaultLocalDeviceId; } + initParams.storageDelegate = &sStorageDelegate; + initParams.mDeviceAddressUpdateDelegate = &sDeviceAddressUpdateDelegate; + initParams.pairingDelegate = &sPairingDelegate; + #if CHIP_ENABLE_INTERACTION_MODEL initParams.imDelegate = &PythonInteractionModelDelegate::Instance(); #endif - SuccessOrExit(err = (*outDevCtrl)->Init(localDeviceId, initParams, &sPairingDelegate)); + SuccessOrExit(err = (*outDevCtrl)->Init(localDeviceId, initParams)); SuccessOrExit(err = (*outDevCtrl)->ServiceEvents()); exit: diff --git a/src/controller/python/chip/internal/CommissionerImpl.cpp b/src/controller/python/chip/internal/CommissionerImpl.cpp index 6fa3e739fddf37..af207f78abcec7 100644 --- a/src/controller/python/chip/internal/CommissionerImpl.cpp +++ b/src/controller/python/chip/internal/CommissionerImpl.cpp @@ -231,13 +231,14 @@ extern "C" chip::Controller::DeviceCommissioner * pychip_internal_Commissioner_N // System and Inet layers explicitly passed to indicate that the CHIP stack is // already assumed initialized - err = result->Init(localDeviceId, - chip::Controller::ControllerInitParams{ - .storageDelegate = &gServerStorage, - .systemLayer = &chip::DeviceLayer::SystemLayer, - .inetLayer = &chip::DeviceLayer::InetLayer, - }, - &gPairingDelegate); + chip::Controller::CommissionerInitParams params; + + params.storageDelegate = &gServerStorage; + params.systemLayer = &chip::DeviceLayer::SystemLayer; + params.inetLayer = &chip::DeviceLayer::InetLayer; + params.pairingDelegate = &gPairingDelegate; + + err = result->Init(localDeviceId, params); }); if (err != CHIP_NO_ERROR) diff --git a/src/darwin/Framework/CHIP/CHIPDeviceController.mm b/src/darwin/Framework/CHIP/CHIPDeviceController.mm index 4b5b1ba7bd9c3f..c97f338737b1dc 100644 --- a/src/darwin/Framework/CHIP/CHIPDeviceController.mm +++ b/src/darwin/Framework/CHIP/CHIPDeviceController.mm @@ -152,12 +152,13 @@ - (BOOL)startup:(_Nullable id)storageDelegate que } } - chip::Controller::ControllerInitParams params { - .storageDelegate = _persistentStorageDelegateBridge, - .mDeviceAddressUpdateDelegate = _pairingDelegateBridge, - }; + chip::Controller::CommissionerInitParams params; - errorCode = _cppCommissioner->Init(_localDeviceId, params, _pairingDelegateBridge); + params.storageDelegate = _persistentStorageDelegateBridge; + params.mDeviceAddressUpdateDelegate = _pairingDelegateBridge; + params.pairingDelegate = _pairingDelegateBridge; + + errorCode = _cppCommissioner->Init(_localDeviceId, params); if ([self checkForStartError:(CHIP_NO_ERROR == errorCode) logMsg:kErrorCommissionerInit]) { return; }