@@ -28,8 +28,8 @@ using namespace chip::app::Clusters::OperationalState;
28
28
using namespace chip ::app::Clusters::RvcOperationalState;
29
29
using chip::Protocols::InteractionModel::Status;
30
30
31
- static RvcOperationalState::Instance * gRvcOperationalStateInstance = nullptr ;
32
- static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr ;
31
+ static std::unique_ptr<RvcOperationalStateDelegate> gRvcOperationalStateDelegate ;
32
+ static std::unique_ptr<RvcOperationalState::Instance > gRvcOperationalStateInstance ;
33
33
34
34
static void onOperationalStateTimerTick (System::Layer * systemLayer, void * data);
35
35
@@ -141,7 +141,7 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
141
141
{
142
142
RvcOperationalStateDelegate * delegate = reinterpret_cast <RvcOperationalStateDelegate *>(data);
143
143
144
- OperationalState::Instance * instance = gRvcOperationalStateInstance ;
144
+ OperationalState::Instance * instance = gRvcOperationalStateInstance . get () ;
145
145
OperationalState::OperationalStateEnum state =
146
146
static_cast <OperationalState::OperationalStateEnum>(instance->GetCurrentOperationalState ());
147
147
@@ -171,16 +171,8 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
171
171
172
172
void RvcOperationalState::Shutdown ()
173
173
{
174
- if (gRvcOperationalStateInstance != nullptr )
175
- {
176
- delete gRvcOperationalStateInstance ;
177
- gRvcOperationalStateInstance = nullptr ;
178
- }
179
- if (gRvcOperationalStateDelegate != nullptr )
180
- {
181
- delete gRvcOperationalStateDelegate ;
182
- gRvcOperationalStateDelegate = nullptr ;
183
- }
174
+ gRvcOperationalStateInstance .reset ();
175
+ gRvcOperationalStateDelegate .reset ();
184
176
}
185
177
186
178
chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback (chip::EndpointId endpointId,
@@ -261,13 +253,10 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch
261
253
void emberAfRvcOperationalStateClusterInitCallback (chip::EndpointId endpointId)
262
254
{
263
255
VerifyOrDie (endpointId == 1 ); // this cluster is only enabled for endpoint 1.
264
- VerifyOrDie (gRvcOperationalStateInstance == nullptr && gRvcOperationalStateDelegate == nullptr );
265
-
266
- gRvcOperationalStateDelegate = new chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate ();
267
- EndpointId operationalStateEndpoint = 0x01 ;
268
- gRvcOperationalStateInstance = new RvcOperationalState::Instance (gRvcOperationalStateDelegate , operationalStateEndpoint);
256
+ VerifyOrDie (!gRvcOperationalStateDelegate && !gRvcOperationalStateInstance );
269
257
270
- gRvcOperationalStateInstance ->SetOperationalState (to_underlying (OperationalState::OperationalStateEnum::kStopped ));
258
+ gRvcOperationalStateDelegate = std::make_unique<RvcOperationalStateDelegate>();
259
+ gRvcOperationalStateInstance = std::make_unique<RvcOperationalState::Instance>(gRvcOperationalStateDelegate .get (), endpointId);
271
260
gRvcOperationalStateInstance ->Init ();
272
261
}
273
262
#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
0 commit comments