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

Release all active device handles on controller shutdown #3959

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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