Skip to content

Commit 7b6cbc5

Browse files
hicklinrestyled-commitsbzbarsky-apple
authored
Replaced the use of std::set with IntrusiveList in ModeBase. (project-chip#28163)
* Replaced the use of std::set with IntrusiveList in ModeBase. * Removed the std::set exeption for ModeBase. * Restyled by clang-format * Refoctor from review. * Added a way to gracefully shutdown the ModeBase dreived clusters and used it in the linux all-clusters-app. * Restyled by whitespace * Restyled by clang-format * Implemented required ApplicationExit(). * Restyled by clang-format * Modified the ModeBase example shutdowns to be safe if Shutdown is called twice and properly free the memory. * Renamed ApplicationExit() to ApplicationShutdown() * Apply documentation suggestions from code review Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 3efdd36 commit 7b6cbc5

File tree

33 files changed

+158
-44
lines changed

33 files changed

+158
-44
lines changed

examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class DishwasherModeDelegate : public ModeBase::Delegate
6969
~DishwasherModeDelegate() override = default;
7070
};
7171

72+
void Shutdown();
73+
7274
} // namespace DishwasherMode
7375

7476
} // namespace Clusters

examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class LaundryWasherModeDelegate : public ModeBase::Delegate
7474
~LaundryWasherModeDelegate() override = default;
7575
};
7676

77+
void Shutdown();
78+
7779
} // namespace LaundryWasherMode
7880

7981
} // namespace Clusters

examples/all-clusters-app/all-clusters-common/include/rvc-modes.h

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class RvcRunModeDelegate : public ModeBase::Delegate
6666
~RvcRunModeDelegate() override = default;
6767
};
6868

69+
void Shutdown();
70+
6971
} // namespace RvcRunMode
7072

7173
namespace RvcCleanMode {
@@ -107,6 +109,8 @@ class RvcCleanModeDelegate : public ModeBase::Delegate
107109
~RvcCleanModeDelegate() override = default;
108110
};
109111

112+
void Shutdown();
113+
110114
} // namespace RvcCleanMode
111115

112116
} // namespace Clusters

examples/all-clusters-app/all-clusters-common/include/tcc-mode.h

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class TccModeDelegate : public ModeBase::Delegate
6767
~TccModeDelegate() override = default;
6868
};
6969

70+
void Shutdown();
71+
7072
} // namespace RefrigeratorAndTemperatureControlledCabinetMode
7173

7274
} // namespace Clusters

examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,24 @@ CHIP_ERROR DishwasherModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<Mo
7676
return CHIP_NO_ERROR;
7777
}
7878

79+
void DishwasherMode::Shutdown()
80+
{
81+
if (gDishwasherModeInstance != nullptr)
82+
{
83+
delete gDishwasherModeInstance;
84+
gDishwasherModeInstance = nullptr;
85+
}
86+
if (gDishwasherModeDelegate != nullptr)
87+
{
88+
gDishwasherModeDelegate->~DishwasherModeDelegate();
89+
}
90+
}
91+
7992
void emberAfDishwasherModeClusterInitCallback(chip::EndpointId endpointId)
8093
{
8194
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
8295
VerifyOrDie(gDishwasherModeDelegate == nullptr && gDishwasherModeInstance == nullptr);
8396
gDishwasherModeDelegate = new DishwasherMode::DishwasherModeDelegate;
84-
// todo use Clusters::XxxMode::Feature::kXxxx to set features.
8597
gDishwasherModeInstance =
8698
new ModeBase::Instance(gDishwasherModeDelegate, 0x1, DishwasherMode::Id, chip::to_underlying(Feature::kOnOff));
8799
gDishwasherModeInstance->Init();

examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ CHIP_ERROR LaundryWasherModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List
7575
return CHIP_NO_ERROR;
7676
}
7777

78+
void LaundryWasherMode::Shutdown()
79+
{
80+
if (gLaundryWasherModeInstance != nullptr)
81+
{
82+
delete gLaundryWasherModeInstance;
83+
gLaundryWasherModeInstance = nullptr;
84+
}
85+
if (gLaundryWasherModeDelegate != nullptr)
86+
{
87+
gLaundryWasherModeDelegate->~LaundryWasherModeDelegate();
88+
}
89+
}
90+
7891
void emberAfLaundryWasherModeClusterInitCallback(chip::EndpointId endpointId)
7992
{
8093
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.

examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ CHIP_ERROR RvcRunModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTa
8888
return CHIP_NO_ERROR;
8989
}
9090

91+
void RvcRunMode::Shutdown()
92+
{
93+
if (gRvcRunModeInstance != nullptr)
94+
{
95+
delete gRvcRunModeInstance;
96+
gRvcRunModeInstance = nullptr;
97+
}
98+
if (gRvcRunModeDelegate != nullptr)
99+
{
100+
gRvcRunModeDelegate->~RvcRunModeDelegate();
101+
}
102+
}
103+
91104
void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId)
92105
{
93106
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
@@ -158,6 +171,19 @@ CHIP_ERROR RvcCleanModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<Mode
158171
return CHIP_NO_ERROR;
159172
}
160173

174+
void RvcCleanMode::Shutdown()
175+
{
176+
if (gRvcCleanModeInstance != nullptr)
177+
{
178+
delete gRvcCleanModeInstance;
179+
gRvcCleanModeInstance = nullptr;
180+
}
181+
if (gRvcCleanModeDelegate != nullptr)
182+
{
183+
gRvcCleanModeDelegate->~RvcCleanModeDelegate();
184+
}
185+
}
186+
161187
void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
162188
{
163189
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.

examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ CHIP_ERROR TccModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTagSt
7575
return CHIP_NO_ERROR;
7676
}
7777

78+
void RefrigeratorAndTemperatureControlledCabinetMode::Shutdown()
79+
{
80+
if (gTccModeInstance != nullptr)
81+
{
82+
delete gTccModeInstance;
83+
gTccModeInstance = nullptr;
84+
}
85+
if (gTccModeDelegate != nullptr)
86+
{
87+
gTccModeDelegate->~TccModeDelegate();
88+
}
89+
}
90+
7891
void emberAfRefrigeratorAndTemperatureControlledCabinetModeClusterInitCallback(chip::EndpointId endpointId)
7992
{
8093
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.

examples/all-clusters-app/linux/main-common.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "main-common.h"
2019
#include "AllClustersCommandDelegate.h"
2120
#include "WindowCoveringManager.h"
2221
#include "dishwasher-mode.h"
@@ -191,8 +190,15 @@ void ApplicationInit()
191190
app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
192191
}
193192

194-
void ApplicationExit()
193+
void ApplicationShutdown()
195194
{
195+
// These may have been initialised via the emberAfXxxClusterInitCallback methods. We need to destroy them before shutdown.
196+
Clusters::DishwasherMode::Shutdown();
197+
Clusters::LaundryWasherMode::Shutdown();
198+
Clusters::RvcCleanMode::Shutdown();
199+
Clusters::RvcRunMode::Shutdown();
200+
Clusters::RefrigeratorAndTemperatureControlledCabinetMode::Shutdown();
201+
196202
if (sChipNamedPipeCommands.Stop() != CHIP_NO_ERROR)
197203
{
198204
ChipLogError(NotSpecified, "Failed to stop CHIP NamedPipeCommands");

examples/all-clusters-app/linux/main-common.h

-21
This file was deleted.

examples/all-clusters-app/linux/main.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "AppMain.h"
2020
#include "AppOptions.h"
2121
#include "binding-handler.h"
22-
#include "main-common.h"
2322

2423
// Network commissioning
2524
namespace {
@@ -35,7 +34,6 @@ int main(int argc, char * argv[])
3534
LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider();
3635

3736
ChipLinuxAppMainLoop();
38-
ApplicationExit();
3937

4038
return 0;
4139
}

examples/all-clusters-app/tizen/src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ void ApplicationInit()
5151
app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate);
5252
}
5353

54+
void ApplicationShutdown() {}
55+
5456
int main(int argc, char * argv[])
5557
{
5658
TizenServiceAppMain app;

examples/all-clusters-minimal-app/linux/main-common.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ static Identify gIdentify1 = {
8484

8585
void ApplicationInit() {}
8686

87+
void ApplicationShutdown() {}
88+
8789
void emberAfLowPowerClusterInitCallback(EndpointId endpoint)
8890
{
8991
ChipLogProgress(Zcl, "TV Linux App: LowPower::SetDefaultDelegate");

examples/all-clusters-minimal-app/tizen/src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void ApplicationInit()
4747
sEthernetNetworkCommissioningInstance.Init();
4848
}
4949

50+
void ApplicationShutdown(){};
51+
5052
int main(int argc, char * argv[])
5153
{
5254
TizenServiceAppMain app;

examples/bridge-app/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ bool emberAfActionsClusterInstantActionCallback(app::CommandHandler * commandObj
741741

742742
void ApplicationInit() {}
743743

744+
void ApplicationShutdown() {}
745+
744746
const EmberAfDeviceType gBridgedOnOffDeviceTypes[] = { { DEVICE_TYPE_LO_ON_OFF_LIGHT, DEVICE_VERSION_DEFAULT },
745747
{ DEVICE_TYPE_BRIDGED_NODE, DEVICE_VERSION_DEFAULT } };
746748

examples/chef/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ using namespace chip::app;
3232

3333
void ApplicationInit() {}
3434

35+
void ApplicationShutdown() {}
36+
3537
int main(int argc, char * argv[])
3638
{
3739
if (ChipLinuxAppInit(argc, argv) != 0)

examples/contact-sensor-app/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ using namespace chip::app::Clusters;
3333

3434
void ApplicationInit() {}
3535

36+
void ApplicationShutdown() {}
37+
3638
int main(int argc, char * argv[])
3739
{
3840
VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0);

examples/dishwasher-app/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ void ApplicationInit()
3232
MatterOperationalStateServerInit();
3333
}
3434

35+
void ApplicationShutdown() {}
36+
3537
int main(int argc, char * argv[])
3638
{
3739
if (ChipLinuxAppInit(argc, argv) != 0)

examples/lighting-app/linux/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void ApplicationInit()
8585
}
8686
}
8787

88-
void ApplicationExit()
88+
void ApplicationShutdown()
8989
{
9090
if (sChipNamedPipeCommands.Stop() != CHIP_NO_ERROR)
9191
{

examples/lighting-app/tizen/src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ void ApplicationInit()
5252
#endif
5353
}
5454

55+
void ApplicationShutdown() {}
56+
5557
int main(int argc, char * argv[])
5658
{
5759
TizenServiceAppMain app;

examples/lock-app/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void ApplicationInit()
4343
}
4444
}
4545

46+
void ApplicationShutdown() {}
47+
4648
int main(int argc, char * argv[])
4749
{
4850
VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0);

examples/ota-provider-app/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ void ApplicationInit()
380380
chip::app::Clusters::OTAProvider::SetDelegate(kOtaProviderEndpoint, &gOtaProvider);
381381
}
382382

383+
void ApplicationShutdown() {}
384+
383385
int main(int argc, char * argv[])
384386
{
385387
VerifyOrDie(ChipLinuxAppInit(argc, argv, &cmdLineOptions) == 0);

examples/ota-requestor-app/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ void ApplicationInit()
255255
InitOTARequestor();
256256
}
257257

258+
void ApplicationShutdown() {}
259+
258260
int main(int argc, char * argv[])
259261
{
260262
VerifyOrDie(ChipLinuxAppInit(argc, argv, &cmdLineOptions, MakeOptional(kNetworkCommissioningEndpointSecondary)) == 0);

examples/placeholder/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
void ApplicationInit() {}
2424

25+
void ApplicationShutdown() {}
26+
2527
int main(int argc, char * argv[])
2628
{
2729
VerifyOrDie(ChipLinuxAppInit(argc, argv, AppOptions::GetOptions()) == 0);

examples/platform/linux/AppMain.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
578578
}
579579
gMainLoopImplementation = nullptr;
580580

581+
ApplicationShutdown();
582+
581583
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
582584
ShutdownCommissioner();
583585
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

examples/platform/linux/AppMain.h

+3
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ CommissionerDiscoveryController * GetCommissionerDiscoveryController();
103103

104104
// For extra init calls, the function will be called right before running Matter main loop.
105105
void ApplicationInit();
106+
107+
// For extra shutdown calls, the function will be called before any of the core Matter objects are shut down.
108+
void ApplicationShutdown();

examples/resource-monitoring-app/linux/src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ void ApplicationInit()
4848
gActivatedCarbonFilterInstance.Init();
4949
}
5050

51+
void ApplicationShutdown() {}
52+
5153
int main(int argc, char * argv[])
5254
{
5355
if (ChipLinuxAppInit(argc, argv) != 0)

examples/thermostat/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ static Identify gIdentify1 = {
7171

7272
void ApplicationInit() {}
7373

74+
void ApplicationShutdown() {}
75+
7476
int main(int argc, char * argv[])
7577
{
7678
VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0);

examples/tv-app/linux/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void ApplicationInit()
4747
// emberAfEndpointEnableDisable(3, false);
4848
}
4949

50+
void ApplicationShutdown() {}
51+
5052
int main(int argc, char * argv[])
5153
{
5254

scripts/tools/check_includes_config.py

-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,4 @@
158158
# Library meant for non-embedded
159159
'src/tracing/json/json_tracing.cpp': {'string', 'sstream'},
160160
'src/tracing/json/json_tracing.h': {'fstream'},
161-
162-
# Temporary solution util the OnOff server can provide a callback API for state change.
163-
'src/app/clusters/mode-base-server/mode-base-server.h': {'set'}
164161
}

0 commit comments

Comments
 (0)