30
30
#include < app/util/attribute-storage.h>
31
31
#include < app/util/config.h>
32
32
#include < lib/support/logging/CHIPLogging.h>
33
+ #include < protocols/interaction_model/StatusCode.h>
34
+
33
35
using namespace chip ;
34
36
using namespace chip ::app;
35
37
using namespace chip ::app::Clusters;
@@ -117,7 +119,7 @@ CHIP_ERROR CheckValidBindingList(const EndpointId localEndpoint, const Decodable
117
119
return CHIP_NO_ERROR;
118
120
}
119
121
120
- void CreateBindingEntry (const TargetStructType & entry, EndpointId localEndpoint)
122
+ CHIP_ERROR CreateBindingEntry (const TargetStructType & entry, EndpointId localEndpoint)
121
123
{
122
124
EmberBindingTableEntry bindingEntry;
123
125
@@ -131,7 +133,7 @@ void CreateBindingEntry(const TargetStructType & entry, EndpointId localEndpoint
131
133
entry.cluster );
132
134
}
133
135
134
- AddBindingEntry (bindingEntry);
136
+ return AddBindingEntry (bindingEntry);
135
137
}
136
138
137
139
CHIP_ERROR BindingTableAccess::Read (const ConcreteReadAttributePath & path, AttributeValueEncoder & encoder)
@@ -225,10 +227,11 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
225
227
}
226
228
227
229
// Add new entries
228
- auto iter = newBindingList.begin ();
229
- while (iter.Next ())
230
+ auto iter = newBindingList.begin ();
231
+ CHIP_ERROR err = CHIP_NO_ERROR;
232
+ while (iter.Next () && err == CHIP_NO_ERROR)
230
233
{
231
- CreateBindingEntry (iter.GetValue (), path.mEndpointId );
234
+ err = CreateBindingEntry (iter.GetValue (), path.mEndpointId );
232
235
}
233
236
234
237
// If this was not caused by a list operation, OnListWriteEnd is not going to be triggered
@@ -238,7 +241,7 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
238
241
// Notify binding table has changed
239
242
LogErrorOnFailure (NotifyBindingsChanged ());
240
243
}
241
- return CHIP_NO_ERROR ;
244
+ return err ;
242
245
}
243
246
if (path.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)
244
247
{
@@ -248,8 +251,7 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
248
251
{
249
252
return CHIP_IM_GLOBAL_STATUS (ConstraintError);
250
253
}
251
- CreateBindingEntry (target, path.mEndpointId );
252
- return CHIP_NO_ERROR;
254
+ return CreateBindingEntry (target, path.mEndpointId );
253
255
}
254
256
return CHIP_IM_GLOBAL_STATUS (UnsupportedWrite);
255
257
}
@@ -269,11 +271,22 @@ void MatterBindingPluginServerInitCallback()
269
271
registerAttributeAccessOverride (&gAttrAccess );
270
272
}
271
273
272
- void AddBindingEntry (const EmberBindingTableEntry & entry)
274
+ CHIP_ERROR AddBindingEntry (const EmberBindingTableEntry & entry)
273
275
{
276
+ CHIP_ERROR err = BindingTable::GetInstance ().Add (entry);
277
+ if (err == CHIP_ERROR_NO_MEMORY)
278
+ {
279
+ return CHIP_IM_GLOBAL_STATUS (ResourceExhausted);
280
+ }
281
+
282
+ if (err != CHIP_NO_ERROR)
283
+ {
284
+ return err;
285
+ }
286
+
274
287
if (entry.type == EMBER_UNICAST_BINDING)
275
288
{
276
- CHIP_ERROR err = BindingManager::GetInstance ().UnicastBindingCreated (entry.fabricIndex , entry.nodeId );
289
+ err = BindingManager::GetInstance ().UnicastBindingCreated (entry.fabricIndex , entry.nodeId );
277
290
if (err != CHIP_NO_ERROR)
278
291
{
279
292
// Unicast connection failure can happen if peer is offline. We'll retry connection on-demand.
@@ -283,5 +296,5 @@ void AddBindingEntry(const EmberBindingTableEntry & entry)
283
296
}
284
297
}
285
298
286
- BindingTable::GetInstance (). Add (entry) ;
299
+ return CHIP_NO_ERROR ;
287
300
}
0 commit comments