Skip to content

Commit

Permalink
Release all active device handles on controller shutdown (#3959)
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-apple authored and pull[bot] committed Nov 24, 2020
1 parent 01982ed commit a3905a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/controller/CHIPDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
14 changes: 13 additions & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ CHIP_ERROR DeviceController::Init(NodeId localDeviceId, PersistentStorageDelegat
mState = State::Initialized;
mLocalDeviceId = localDeviceId;

ReleaseAllDevices();

exit:
return err;
}
Expand Down Expand Up @@ -174,6 +176,8 @@ CHIP_ERROR DeviceController::Shutdown()
mSessionManager = nullptr;
}

ReleaseAllDevices();

exit:
return err;
}
Expand Down Expand Up @@ -351,7 +355,7 @@ uint16_t DeviceController::GetInactiveDeviceIndex()

void DeviceController::ReleaseDevice(Device * device)
{
device->SetActive(false);
device->Reset();
}

void DeviceController::ReleaseDevice(uint16_t index)
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit a3905a6

Please sign in to comment.