@@ -35,13 +35,15 @@ using chip::Protocols::InteractionModel::Status;
35
35
36
36
namespace JointFabricDatastoreCluster = chip::app::Clusters::JointFabricDatastore;
37
37
38
- class JointFabricDatastoreAttrAccess : public AttributeAccessInterface
38
+ class JointFabricDatastoreAttrAccess : public AttributeAccessInterface , public app ::JointFabricDatastore::Listener
39
39
{
40
40
public:
41
41
JointFabricDatastoreAttrAccess () : AttributeAccessInterface(Optional<EndpointId>::Missing(), JointFabricDatastoreCluster::Id) {}
42
42
43
43
CHIP_ERROR Read (const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override ;
44
44
45
+ void MarkNodeListChanged () override ;
46
+
45
47
private:
46
48
CHIP_ERROR ReadAnchorNodeId (AttributeValueEncoder & aEncoder);
47
49
CHIP_ERROR ReadAnchorVendorId (AttributeValueEncoder & aEncoder);
@@ -81,41 +83,94 @@ CHIP_ERROR JointFabricDatastoreAttrAccess::Read(const ConcreteReadAttributePath
81
83
return CHIP_NO_ERROR;
82
84
}
83
85
84
- // TODO
85
86
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadAnchorNodeId (AttributeValueEncoder & aEncoder)
86
87
{
87
- return CHIP_ERROR_NOT_IMPLEMENTED;
88
+ NodeId anchorNodeId = Server::GetInstance ().GetJointFabricDatastore ().GetAnchorNodeId ();
89
+ ReturnErrorOnFailure (aEncoder.Encode (anchorNodeId));
90
+ return CHIP_NO_ERROR;
88
91
}
89
92
90
- // TODO
91
93
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadAnchorVendorId (AttributeValueEncoder & aEncoder)
92
94
{
93
- return CHIP_ERROR_NOT_IMPLEMENTED;
95
+ VendorId anchorVendorId = Server::GetInstance ().GetJointFabricDatastore ().GetAnchorVendorId ();
96
+ ReturnErrorOnFailure (aEncoder.Encode (anchorVendorId));
97
+ return CHIP_NO_ERROR;
94
98
}
95
99
96
- // TODO
97
100
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadGroupKeySetList (AttributeValueEncoder & aEncoder)
98
101
{
99
- return CHIP_ERROR_NOT_IMPLEMENTED;
102
+ return aEncoder.EncodeList ([&](const auto & encoder) -> CHIP_ERROR {
103
+ auto entries = Server::GetInstance ().GetJointFabricDatastore ().GetGroupKeySetList ();
104
+
105
+ for (auto & entry : entries)
106
+ {
107
+ ReturnErrorOnFailure (encoder.Encode (entry));
108
+ }
109
+ return CHIP_NO_ERROR;
110
+ });
100
111
}
101
112
102
- // TODO
103
113
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadAdminList (AttributeValueEncoder & aEncoder)
104
114
{
105
- return CHIP_ERROR_NOT_IMPLEMENTED;
115
+ return aEncoder.EncodeList ([&](const auto & encoder) -> CHIP_ERROR {
116
+ auto entries = Server::GetInstance ().GetJointFabricDatastore ().GetAdminEntries ();
117
+
118
+ for (auto & entry : entries)
119
+ {
120
+ ReturnErrorOnFailure (encoder.Encode (entry));
121
+ }
122
+ return CHIP_NO_ERROR;
123
+ });
106
124
}
107
125
108
- // TODO
109
126
CHIP_ERROR JointFabricDatastoreAttrAccess::ReadNodeList (AttributeValueEncoder & aEncoder)
110
127
{
111
- return CHIP_ERROR_NOT_IMPLEMENTED;
128
+ return aEncoder.EncodeList ([&](const auto & encoder) -> CHIP_ERROR {
129
+ auto entries = Server::GetInstance ().GetJointFabricDatastore ().GetNodeInformationEntries ();
130
+
131
+ for (auto & entry : entries)
132
+ {
133
+ ReturnErrorOnFailure (encoder.Encode (entry));
134
+ }
135
+ return CHIP_NO_ERROR;
136
+ });
137
+ }
138
+
139
+ void JointFabricDatastoreAttrAccess::MarkNodeListChanged ()
140
+ {
141
+ MatterReportingAttributeChangeCallback (kRootEndpointId , JointFabricDatastoreCluster::Id,
142
+ JointFabricDatastoreCluster::Attributes::NodeList::Id);
112
143
}
113
144
114
- // TODO
115
145
bool emberAfJointFabricDatastoreClusterAddAdminCallback (
116
146
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
117
147
const JointFabricDatastoreCluster::Commands::AddAdmin::DecodableType & commandData)
118
148
{
149
+ CHIP_ERROR err = CHIP_NO_ERROR;
150
+ app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance ().GetJointFabricDatastore ();
151
+
152
+ auto nodeID = commandData.nodeID ;
153
+ auto friendlyName = commandData.friendlyName ;
154
+ auto vendorID = commandData.vendorID ;
155
+ auto icac = commandData.icac ;
156
+
157
+ JointFabricDatastoreCluster::Structs::DatastoreAdministratorInformationEntryStruct::DecodableType adminInformationEntry = {
158
+ .nodeID = nodeID, .friendlyName = friendlyName, .vendorID = vendorID, .icac = icac
159
+ };
160
+
161
+ SuccessOrExit (err = jointFabricDatastore.AddAdmin (adminInformationEntry));
162
+
163
+ exit :
164
+ if (err == CHIP_NO_ERROR)
165
+ {
166
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
167
+ }
168
+ else
169
+ {
170
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
171
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
172
+ }
173
+
119
174
return true ;
120
175
}
121
176
@@ -127,43 +182,121 @@ bool emberAfJointFabricDatastoreClusterAddGroupCallback(
127
182
return true ;
128
183
}
129
184
130
- // TODO
131
185
bool emberAfJointFabricDatastoreClusterAddKeySetCallback (
132
186
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
133
187
const JointFabricDatastoreCluster::Commands::AddKeySet::DecodableType & commandData)
134
188
{
189
+ CHIP_ERROR err = CHIP_NO_ERROR;
190
+ JointFabricDatastoreCluster::Structs::DatastoreGroupKeySetStruct::DecodableType groupKeySet = commandData.groupKeySet ;
191
+ app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance ().GetJointFabricDatastore ();
192
+
193
+ VerifyOrExit (jointFabricDatastore.IsGroupKeySetEntryPresent (groupKeySet.groupKeySetID ) == false ,
194
+ err = CHIP_ERROR_INVALID_ARGUMENT);
195
+ SuccessOrExit (err = jointFabricDatastore.AddGroupKeySetEntry (groupKeySet));
196
+
197
+ exit :
198
+ if (err == CHIP_NO_ERROR)
199
+ {
200
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
201
+ }
202
+ else
203
+ {
204
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
205
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
206
+ }
207
+
135
208
return true ;
136
209
}
137
210
138
- // TODO
139
211
bool emberAfJointFabricDatastoreClusterRemoveNodeCallback (
140
212
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
141
213
const JointFabricDatastoreCluster::Commands::RemoveNode::DecodableType & commandData)
142
214
{
215
+ NodeId nodeId = commandData.nodeID ;
216
+
217
+ CHIP_ERROR err = Server::GetInstance ().GetJointFabricDatastore ().RemoveNode (nodeId);
218
+
219
+ if (err == CHIP_NO_ERROR)
220
+ {
221
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
222
+ }
223
+ else
224
+ {
225
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
226
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
227
+ }
228
+
143
229
return true ;
144
230
}
145
231
146
- // TODO
147
232
bool emberAfJointFabricDatastoreClusterUpdateNodeCallback (
148
233
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
149
234
const JointFabricDatastoreCluster::Commands::UpdateNode::DecodableType & commandData)
150
235
{
236
+ NodeId nodeId = commandData.nodeID ;
237
+ const CharSpan & friendlyName = commandData.friendlyName ;
238
+
239
+ CHIP_ERROR err = Server::GetInstance ().GetJointFabricDatastore ().UpdateNode (nodeId, friendlyName);
240
+
241
+ if (err == CHIP_NO_ERROR)
242
+ {
243
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
244
+ }
245
+ else
246
+ {
247
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
248
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
249
+ }
250
+
151
251
return true ;
152
252
}
153
253
154
- // TODO
155
254
bool emberAfJointFabricDatastoreClusterRefreshNodeCallback (
156
255
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
157
256
const JointFabricDatastoreCluster::Commands::RefreshNode::DecodableType & commandData)
158
257
{
258
+ CHIP_ERROR err = CHIP_NO_ERROR;
259
+ NodeId nodeId = commandData.nodeID ;
260
+
261
+ app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance ().GetJointFabricDatastore ();
262
+
263
+ SuccessOrExit (err = jointFabricDatastore.RefreshNode (nodeId));
264
+
265
+ exit :
266
+ if (err == CHIP_NO_ERROR)
267
+ {
268
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
269
+ }
270
+ else
271
+ {
272
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
273
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
274
+ }
275
+
159
276
return true ;
160
277
}
161
278
162
- // TODO
163
279
bool emberAfJointFabricDatastoreClusterRemoveAdminCallback (
164
280
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
165
281
const JointFabricDatastoreCluster::Commands::RemoveAdmin::DecodableType & commandData)
166
282
{
283
+ CHIP_ERROR err = CHIP_NO_ERROR;
284
+ auto nodeId = commandData.nodeID ;
285
+ app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance ().GetJointFabricDatastore ();
286
+
287
+ SuccessOrExit (err = jointFabricDatastore.RemoveAdmin (nodeId));
288
+
289
+ exit :
290
+ if (err == CHIP_NO_ERROR)
291
+ {
292
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
293
+ }
294
+ else
295
+ {
296
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
297
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
298
+ }
299
+
167
300
return true ;
168
301
}
169
302
@@ -175,11 +308,29 @@ bool emberAfJointFabricDatastoreClusterRemoveGroupCallback(
175
308
return true ;
176
309
}
177
310
178
- // TODO
179
311
bool emberAfJointFabricDatastoreClusterUpdateAdminCallback (
180
312
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
181
313
const JointFabricDatastoreCluster::Commands::UpdateAdmin::DecodableType & commandData)
182
314
{
315
+ CHIP_ERROR err = CHIP_NO_ERROR;
316
+ auto nodeId = commandData.nodeID .Value ();
317
+ auto friendlyName = commandData.friendlyName .Value ();
318
+ auto icac = commandData.icac .Value ();
319
+ app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance ().GetJointFabricDatastore ();
320
+
321
+ SuccessOrExit (err = jointFabricDatastore.UpdateAdmin (nodeId, friendlyName, icac));
322
+
323
+ exit :
324
+ if (err == CHIP_NO_ERROR)
325
+ {
326
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
327
+ }
328
+ else
329
+ {
330
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
331
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
332
+ }
333
+
183
334
return true ;
184
335
}
185
336
@@ -199,11 +350,27 @@ bool emberAfJointFabricDatastoreClusterAddACLToNodeCallback(
199
350
return true ;
200
351
}
201
352
202
- // TODO
203
353
bool emberAfJointFabricDatastoreClusterRemoveKeySetCallback (
204
354
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
205
355
const JointFabricDatastoreCluster::Commands::RemoveKeySet::DecodableType & commandData)
206
356
{
357
+ CHIP_ERROR err = CHIP_NO_ERROR;
358
+ uint16_t groupKeySetId = commandData.groupKeySetID ;
359
+ app::JointFabricDatastore & jointFabricDatastore = Server::GetInstance ().GetJointFabricDatastore ();
360
+
361
+ SuccessOrExit (err = jointFabricDatastore.RemoveGroupKeySetEntry (groupKeySetId));
362
+
363
+ exit :
364
+ if (err == CHIP_NO_ERROR)
365
+ {
366
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
367
+ }
368
+ else
369
+ {
370
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
371
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
372
+ }
373
+
207
374
return true ;
208
375
}
209
376
@@ -215,11 +382,25 @@ bool emberAfJointFabricDatastoreClusterUpdateKeySetCallback(
215
382
return true ;
216
383
}
217
384
218
- // TODO
219
385
bool emberAfJointFabricDatastoreClusterAddPendingNodeCallback (
220
386
CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
221
387
const JointFabricDatastoreCluster::Commands::AddPendingNode::DecodableType & commandData)
222
388
{
389
+ NodeId nodeId = commandData.nodeID ;
390
+ const CharSpan & friendlyName = commandData.friendlyName ;
391
+
392
+ CHIP_ERROR err = Server::GetInstance ().GetJointFabricDatastore ().AddPendingNode (nodeId, friendlyName);
393
+
394
+ if (err == CHIP_NO_ERROR)
395
+ {
396
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::Status::Success);
397
+ }
398
+ else
399
+ {
400
+ ChipLogError (DataManagement, " JointFabricDatastoreCluster: failed with error: %" CHIP_ERROR_FORMAT, err.Format ());
401
+ commandObj->AddStatus (commandPath, Protocols::InteractionModel::ClusterStatusCode (err));
402
+ }
403
+
223
404
return true ;
224
405
}
225
406
@@ -275,4 +456,6 @@ void MatterJointFabricDatastorePluginServerInitCallback()
275
456
{
276
457
ChipLogProgress (Zcl, " Initiating Joint Fabric Datastore cluster." );
277
458
AttributeAccessInterfaceRegistry::Instance ().Register (&gJointFabricDatastoreAttrAccess );
459
+
460
+ Server::GetInstance ().GetJointFabricDatastore ().AddListener (gJointFabricDatastoreAttrAccess );
278
461
}
0 commit comments