diff --git a/src/controller/CHIPDevice.h b/src/controller/CHIPDevice.h index 380685aa3ba6d2..be8b5a83753d1a 100644 --- a/src/controller/CHIPDevice.h +++ b/src/controller/CHIPDevice.h @@ -167,6 +167,15 @@ class DLL_EXPORT Device void SetActive(bool active) { mActive = active; } + void Reset() + { + SetActive(false); + mState = ConnectionState::NotConnected; + mSessionManager = nullptr; + mStatusDelegate = nullptr; + mInetLayer = nullptr; + } + NodeId GetDeviceId() const { return mDeviceId; } void SetAddress(const Inet::IPAddress & deviceAddr) { mDeviceAddr = deviceAddr; } diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 54bbc86fb0dfdd..dc7a02acd79328 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -134,6 +134,8 @@ CHIP_ERROR DeviceController::Init(NodeId localDeviceId, PersistentStorageDelegat mState = State::Initialized; mLocalDeviceId = localDeviceId; + ReleaseAllDevices(); + exit: return err; } @@ -174,6 +176,8 @@ CHIP_ERROR DeviceController::Shutdown() mSessionManager = nullptr; } + ReleaseAllDevices(); + exit: return err; } @@ -351,7 +355,7 @@ uint16_t DeviceController::GetInactiveDeviceIndex() void DeviceController::ReleaseDevice(Device * device) { - device->SetActive(false); + device->Reset(); } void DeviceController::ReleaseDevice(uint16_t index) @@ -362,6 +366,14 @@ void DeviceController::ReleaseDevice(uint16_t index) } } +void DeviceController::ReleaseAllDevices() +{ + for (uint16_t i = 0; i < kNumMaxActiveDevices; i++) + { + ReleaseDevice(&mActiveDevices[i]); + } +} + uint16_t DeviceController::FindDeviceIndex(NodeId id) { uint16_t i = 0; diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index e7ec8593b8354b..64a884a3c59dba 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -203,6 +203,8 @@ class DLL_EXPORT DeviceController : public SecureSessionMgrDelegate, public Pers void OnValue(const char * key, const char * value) override; void OnStatus(const char * key, Operation op, CHIP_ERROR err) override; + void ReleaseAllDevices(); + System::Layer * mSystemLayer; };