@@ -70,6 +70,11 @@ void JointFabricDatastore::RemoveListener(Listener & listener)
7070CHIP_ERROR JointFabricDatastore::AddPendingNode (NodeId nodeId, const CharSpan & friendlyName)
7171{
7272 VerifyOrReturnError (mNodeInformationEntries .size () < kMaxNodes , CHIP_ERROR_NO_MEMORY);
73+ // check that nodeId does not already exist
74+ VerifyOrReturnError (
75+ std::none_of (mNodeInformationEntries .begin (), mNodeInformationEntries .end (),
76+ [nodeId](const GenericDatastoreNodeInformationEntry & entry) { return entry.nodeID == nodeId; }),
77+ CHIP_IM_GLOBAL_STATUS (ConstraintError));
7378
7479 mNodeInformationEntries .push_back (GenericDatastoreNodeInformationEntry (
7580 nodeId, Clusters::JointFabricDatastore::DatastoreStateEnum::kPending , MakeOptional (friendlyName)));
@@ -659,6 +664,8 @@ CHIP_ERROR JointFabricDatastore::IsNodeIdAndEndpointInEndpointInformationEntries
659664
660665CHIP_ERROR JointFabricDatastore::AddGroupIDToEndpointForNode (NodeId nodeId, chip::EndpointId endpointId, chip::GroupId groupId)
661666{
667+ VerifyOrReturnError (mDelegate != nullptr , CHIP_ERROR_INCORRECT_STATE);
668+
662669 size_t index = 0 ;
663670 ReturnErrorOnFailure (IsNodeIdAndEndpointInEndpointInformationEntries (nodeId, endpointId, index));
664671
@@ -687,11 +694,11 @@ CHIP_ERROR JointFabricDatastore::AddGroupIDToEndpointForNode(NodeId nodeId, chip
687694 newNodeKeySet.groupKeySetID = groupKeySetID;
688695 newNodeKeySet.statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kPending ;
689696
690- // TODO: Update device
691-
692697 mNodeKeySetEntries .push_back (newNodeKeySet);
693698
694- mNodeKeySetEntries .back ().statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kCommitted ;
699+ ReturnErrorOnFailure (mDelegate ->SyncNode (nodeId, newNodeKeySet, [this ]() {
700+ mNodeKeySetEntries .back ().statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kCommitted ;
701+ }));
695702 }
696703 }
697704
@@ -713,18 +720,18 @@ CHIP_ERROR JointFabricDatastore::AddGroupIDToEndpointForNode(NodeId nodeId, chip
713720 newGroupEntry.groupID = groupId;
714721 newGroupEntry.statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kPending ;
715722
716- // TODO: Update device
717-
718723 // Add the new ACL entry to the datastore
719724 mEndpointGroupIDEntries .push_back (newGroupEntry);
720725
721- mEndpointGroupIDEntries . back (). statusEntry . state = Clusters::JointFabricDatastore::DatastoreStateEnum:: kCommitted ;
722-
723- return CHIP_NO_ERROR ;
726+ return mDelegate -> SyncNode (nodeId, newGroupEntry, [ this ]() {
727+ mEndpointGroupIDEntries . back (). statusEntry . state = Clusters::JointFabricDatastore::DatastoreStateEnum:: kCommitted ;
728+ }) ;
724729}
725730
726731CHIP_ERROR JointFabricDatastore::RemoveGroupIDFromEndpointForNode (NodeId nodeId, chip::EndpointId endpointId, chip::GroupId groupId)
727732{
733+ VerifyOrReturnError (mDelegate != nullptr , CHIP_ERROR_INCORRECT_STATE);
734+
728735 size_t index = 0 ;
729736 ReturnErrorOnFailure (IsNodeIdAndEndpointInEndpointInformationEntries (nodeId, endpointId, index));
730737
@@ -734,9 +741,11 @@ CHIP_ERROR JointFabricDatastore::RemoveGroupIDFromEndpointForNode(NodeId nodeId,
734741 {
735742 it->statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kDeletePending ;
736743
737- // TODO: Update device
744+ // zero-initialized struct to indicate deletion for the SyncNode call
745+ Clusters::JointFabricDatastore::Structs::DatastoreEndpointGroupIDEntryStruct::Type endpointGroupIdNullEntry{ 0 };
738746
739- mEndpointGroupIDEntries .erase (it);
747+ ReturnErrorOnFailure (
748+ mDelegate ->SyncNode (nodeId, endpointGroupIdNullEntry, [this , it]() { mEndpointGroupIDEntries .erase (it); }));
740749
741750 if (IsGroupIDInDatastore (groupId, index) == CHIP_NO_ERROR)
742751 {
@@ -748,8 +757,11 @@ CHIP_ERROR JointFabricDatastore::RemoveGroupIDFromEndpointForNode(NodeId nodeId,
748757 it2->groupKeySetID == mGroupInformationEntries [index].groupKeySetID .Value ())
749758 {
750759 it2->statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kDeletePending ;
751- // TODO: Update device
752- it2 = mNodeKeySetEntries .erase (it2);
760+
761+ // zero-initialized struct to indicate deletion for the SyncNode call
762+ Clusters::JointFabricDatastore::Structs::DatastoreNodeKeySetEntryStruct::Type nodeKeySetNullEntry{ 0 };
763+ ReturnErrorOnFailure (
764+ mDelegate ->SyncNode (nodeId, nodeKeySetNullEntry, [this , it2]() { mNodeKeySetEntries .erase (it2); }));
753765
754766 incrementIndex = false ;
755767 }
@@ -856,6 +868,8 @@ JointFabricDatastore::AddBindingToEndpointForNode(
856868 NodeId nodeId, chip::EndpointId endpointId,
857869 const Clusters::JointFabricDatastore::Structs::DatastoreBindingTargetStruct::Type & binding)
858870{
871+ VerifyOrReturnError (mDelegate != nullptr , CHIP_ERROR_INCORRECT_STATE);
872+
859873 size_t index = 0 ;
860874 ReturnErrorOnFailure (IsNodeIdAndEndpointInEndpointInformationEntries (nodeId, endpointId, index));
861875
@@ -884,16 +898,16 @@ JointFabricDatastore::AddBindingToEndpointForNode(
884898 // Add the new binding entry to the datastore
885899 mEndpointBindingEntries .push_back (newBindingEntry);
886900
887- // TODO: Update device
888-
889- mEndpointBindingEntries .back ().statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kCommitted ;
890-
891- return CHIP_NO_ERROR;
901+ return mDelegate ->SyncNode (nodeId, newBindingEntry, [this ]() {
902+ mEndpointBindingEntries .back ().statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kCommitted ;
903+ });
892904}
893905
894906CHIP_ERROR
895907JointFabricDatastore::RemoveBindingFromEndpointForNode (uint16_t listId, NodeId nodeId, chip::EndpointId endpointId)
896908{
909+ VerifyOrReturnError (mDelegate != nullptr , CHIP_ERROR_INCORRECT_STATE);
910+
897911 size_t index = 0 ;
898912 ReturnErrorOnFailure (IsNodeIdAndEndpointInEndpointInformationEntries (nodeId, endpointId, index));
899913
@@ -903,11 +917,9 @@ JointFabricDatastore::RemoveBindingFromEndpointForNode(uint16_t listId, NodeId n
903917 {
904918 it->statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kDeletePending ;
905919
906- // TODO: Update device
907-
908- mEndpointBindingEntries .erase (it);
909-
910- return CHIP_NO_ERROR;
920+ // zero-initialized struct to indicate deletion for the SyncNode call
921+ Clusters::JointFabricDatastore::Structs::DatastoreEndpointBindingEntryStruct::Type nullEntry{ 0 };
922+ return mDelegate ->SyncNode (nodeId, nullEntry, [this , it]() { mEndpointBindingEntries .erase (it); });
911923 }
912924 }
913925
@@ -1016,6 +1028,8 @@ CHIP_ERROR
10161028JointFabricDatastore::AddACLToNode (
10171029 NodeId nodeId, const Clusters::JointFabricDatastore::Structs::DatastoreAccessControlEntryStruct::DecodableType & aclEntry)
10181030{
1031+ VerifyOrReturnError (mDelegate != nullptr , CHIP_ERROR_INCORRECT_STATE);
1032+
10191033 size_t index = 0 ;
10201034 ReturnErrorOnFailure (IsNodeIdInNodeInformationEntries (nodeId, index));
10211035
@@ -1062,15 +1076,27 @@ JointFabricDatastore::AddACLToNode(
10621076 // Add the new ACL entry to the datastore
10631077 mACLEntries .push_back (newACLEntry);
10641078
1065- // TODO: Update device
1066-
1067- mACLEntries .back ().statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kCommitted ;
1068-
1069- return CHIP_NO_ERROR;
1079+ Clusters::JointFabricDatastore::Structs::DatastoreACLEntryStruct::Type entryToEncode;
1080+ entryToEncode.nodeID = newACLEntry.nodeID ;
1081+ entryToEncode.listID = newACLEntry.listID ;
1082+ entryToEncode.ACLEntry .authMode = newACLEntry.ACLEntry .authMode ;
1083+ entryToEncode.ACLEntry .privilege = newACLEntry.ACLEntry .privilege ;
1084+ entryToEncode.ACLEntry .subjects =
1085+ DataModel::List<const uint64_t >(newACLEntry.ACLEntry .subjects .data (), newACLEntry.ACLEntry .subjects .size ());
1086+ entryToEncode.ACLEntry .targets =
1087+ DataModel::List<const Clusters::JointFabricDatastore::Structs::DatastoreAccessControlTargetStruct::Type>(
1088+ newACLEntry.ACLEntry .targets .data (), newACLEntry.ACLEntry .targets .size ());
1089+ entryToEncode.statusEntry = newACLEntry.statusEntry ;
1090+
1091+ return mDelegate ->SyncNode (nodeId, entryToEncode, [this ]() {
1092+ mACLEntries .back ().statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kCommitted ;
1093+ });
10701094}
10711095
10721096CHIP_ERROR JointFabricDatastore::RemoveACLFromNode (uint16_t listId, NodeId nodeId)
10731097{
1098+ VerifyOrReturnError (mDelegate != nullptr , CHIP_ERROR_INCORRECT_STATE);
1099+
10741100 size_t index = 0 ;
10751101 ReturnErrorOnFailure (IsNodeIdInNodeInformationEntries (nodeId, index));
10761102
@@ -1079,9 +1105,10 @@ CHIP_ERROR JointFabricDatastore::RemoveACLFromNode(uint16_t listId, NodeId nodeI
10791105 if (it->nodeID == nodeId && it->listID == listId)
10801106 {
10811107 it->statusEntry .state = Clusters::JointFabricDatastore::DatastoreStateEnum::kDeletePending ;
1082- // TODO: Update device
1083- mACLEntries .erase (it);
1084- return CHIP_NO_ERROR;
1108+
1109+ // zero-initialized struct to indicate deletion for the SyncNode call
1110+ Clusters::JointFabricDatastore::Structs::DatastoreACLEntryStruct::Type nullEntry{ 0 };
1111+ return mDelegate ->SyncNode (nodeId, nullEntry, [this , it]() { mACLEntries .erase (it); });
10851112 }
10861113 }
10871114
0 commit comments