Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update init params for controller to include ble layer #6315

Merged
merged 6 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/chip-tool/commands/clusters/ModelCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions examples/chip-tool/commands/discover/DiscoverCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
11 changes: 6 additions & 5 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the UDP listen port should instead be part of the 'Init'.

Do we expect the UDP port to be changed/set up at a different point than init?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vivien-apple - should we create some PR later that puts this in the initializing parameters?

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();
Expand Down
5 changes: 4 additions & 1 deletion examples/chip-tool/commands/reporting/ReportingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 2 additions & 19 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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));

Expand All @@ -679,7 +662,7 @@ CHIP_ERROR DeviceCommissioner::Init(NodeId localDeviceId, ControllerInitParams p
mNextKeyId = 0;
}

mPairingDelegate = pairingDelegate;
mPairingDelegate = params.pairingDelegate;
return CHIP_NO_ERROR;
}

Expand Down
23 changes: 7 additions & 16 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

/**
Expand Down Expand Up @@ -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; }

Expand Down
13 changes: 12 additions & 1 deletion src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
9 changes: 9 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/controller/python/ChipDeviceController-ScriptBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down
15 changes: 8 additions & 7 deletions src/controller/python/chip/internal/CommissionerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions src/darwin/Framework/CHIP/CHIPDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ - (BOOL)startup:(_Nullable id<CHIPPersistentStorageDelegate>)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;
}
Expand Down