Skip to content

Commit

Permalink
Introduce a Shutdown method to DeviceControllerFactory (#14723)
Browse files Browse the repository at this point in the history
The new method would the symmetrical API for DeviceControllerFactory's
already existing `Init()` API.

What is the root of the problem?

The problem we intend to solve is that we'd like to use `Shutdown()` method
to shut down and clean up any memory/functionality enabled by `Init()` as
opposed to waiting for the DeviceControllerFactory desctructor, which only
happens once the program shuts down due to the nature of how
DeviceControllerFactory is instantiated.

DeviceControllerFactory can only be instantiated through ::GetInstance(),
this method constructs DeviceControllerFactory only once for the life of
the program (the constructor is a private method). Once the Init() is
invoked, the `mSystemState` is allocated as shown in the following:

```
    mSystemState = chip::Platform::New<DeviceControllerSystemState>(stateParams);
```

However, in DeviceControllerFactory's destructor, which currently is only
invoked once the program shuts down, the deallocation of `mSystemState`
is requested via `chip::Platform::Delete`. This can be problematic since
the application will need to ensure `chip::Platform` memory stays initailized
throughout the memory shutdown.

Adding a shutdown methods allows the applications to have a symmetry between
the initialization and shutdown sequence related to the
DeviceControllerFactory
  • Loading branch information
kianooshkarami authored and pull[bot] committed Dec 6, 2023
1 parent 9a59ded commit 2065522
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ CHIP_ERROR DeviceControllerFactory::ServiceEvents()
}

DeviceControllerFactory::~DeviceControllerFactory()
{
Shutdown();
}

void DeviceControllerFactory::Shutdown()
{
if (mSystemState != nullptr)
{
Expand Down
1 change: 1 addition & 0 deletions src/controller/CHIPDeviceControllerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class DeviceControllerFactory
}

CHIP_ERROR Init(FactoryInitParams params);
void Shutdown();
CHIP_ERROR SetupController(SetupParams params, DeviceController & controller);
CHIP_ERROR SetupCommissioner(SetupParams params, DeviceCommissioner & commissioner);

Expand Down

0 comments on commit 2065522

Please sign in to comment.