@@ -66,14 +66,19 @@ class EncoderToTLV
66
66
virtual CHIP_ERROR Encode (TLV::TLVWriter &, TLV::Tag tag) = 0;
67
67
};
68
68
69
- // / An `EncoderToTLV` the uses `DataModel::Encode` to encode things.
69
+ // / An `EncoderToTLV` that uses `DataModel::Encode` to encode things.
70
70
// /
71
71
// / Generally useful to encode things like <ClusterName>::Commands::<CommandName>::Type
72
72
// / structures.
73
73
template <typename T>
74
74
class DataModelEncoderToTLV : public EncoderToTLV
75
75
{
76
76
public:
77
+ // / Encodes the given value via `DataModel::Encode` when the underlying
78
+ // / encode is called.
79
+ // /
80
+ // / LIFETIME NOTE: uses a reference to value, so value must live longer than
81
+ // / this object.
77
82
DataModelEncoderToTLV (const T & value) : mValue (value) {}
78
83
79
84
virtual CHIP_ERROR Encode (TLV::TLVWriter & writer, TLV::Tag tag) { return DataModel::Encode (writer, tag, mValue ); }
@@ -350,18 +355,16 @@ class CommandHandler
350
355
* @param [in] aRequestCommandPath the concrete path of the command we are
351
356
* responding to.
352
357
* @param [in] aData the data for the response.
353
- *
354
- * NOTE: this is a convenience function for `AddResponseDataViaEncoder`
355
358
*/
356
359
template <typename CommandData>
357
- inline CHIP_ERROR AddResponseData (const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
360
+ CHIP_ERROR AddResponseData (const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
358
361
{
359
362
DataModelEncoderToTLV<CommandData> encoder (aData);
360
- return AddResponseDataViaEncoder (aRequestCommandPath, CommandData::GetCommandId (), encoder);
363
+ return AddResponseData (aRequestCommandPath, CommandData::GetCommandId (), encoder);
361
364
}
362
365
363
366
/* *
364
- * API for adding a data response. The encoded is generally expected to encode
367
+ * API for adding a data response. The `encoder` is generally expected to encode
365
368
* a ClusterName::Commands::CommandName::Type struct, but any
366
369
* object should work.
367
370
*
@@ -374,13 +377,13 @@ class CommandHandler
374
377
* Most applications are likely to use `AddResponseData` as a more convenient
375
378
* one-call that auto-sets command ID and creates the underlying encoders.
376
379
*/
377
- CHIP_ERROR AddResponseDataViaEncoder (const ConcreteCommandPath & aRequestCommandPath, CommandId commandId,
380
+ CHIP_ERROR AddResponseData (const ConcreteCommandPath & aRequestCommandPath, CommandId commandId,
378
381
EncoderToTLV & encoder)
379
382
{
380
383
// Return early when response should not be sent out.
381
384
VerifyOrReturnValue (ResponsesAccepted (), CHIP_NO_ERROR);
382
385
return TryAddingResponse (
383
- [&]() -> CHIP_ERROR { return TryAddResponseDataViaEncoder (aRequestCommandPath, commandId, encoder); });
386
+ [&]() -> CHIP_ERROR { return TryAddResponseData (aRequestCommandPath, commandId, encoder); });
384
387
}
385
388
386
389
/* *
@@ -398,10 +401,10 @@ class CommandHandler
398
401
* @param [in] aData the data for the response.
399
402
*/
400
403
template <typename CommandData>
401
- inline void AddResponse (const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
404
+ void AddResponse (const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
402
405
{
403
406
DataModelEncoderToTLV<CommandData> encoder (aData);
404
- return AddResponseViaEncoder (aRequestCommandPath, CommandData::GetCommandId (), encoder);
407
+ return AddResponse (aRequestCommandPath, CommandData::GetCommandId (), encoder);
405
408
}
406
409
407
410
/* *
@@ -410,9 +413,9 @@ class CommandHandler
410
413
* The encoder would generally encode a ClusterName::Commands::CommandName::Type with
411
414
* the corresponding `GetCommandId` call.
412
415
*/
413
- void AddResponseViaEncoder (const ConcreteCommandPath & aRequestCommandPath, CommandId commandId, EncoderToTLV & encoder)
416
+ void AddResponse (const ConcreteCommandPath & aRequestCommandPath, CommandId commandId, EncoderToTLV & encoder)
414
417
{
415
- if (AddResponseDataViaEncoder (aRequestCommandPath, commandId, encoder) != CHIP_NO_ERROR)
418
+ if (AddResponseData (aRequestCommandPath, commandId, encoder) != CHIP_NO_ERROR)
416
419
{
417
420
AddStatus (aRequestCommandPath, Protocols::InteractionModel::Status::Failure);
418
421
}
@@ -699,7 +702,7 @@ class CommandHandler
699
702
* responding to.
700
703
* @param [in] aData the data for the response.
701
704
*/
702
- CHIP_ERROR TryAddResponseDataViaEncoder (const ConcreteCommandPath & aRequestCommandPath, CommandId commandId,
705
+ CHIP_ERROR TryAddResponseData (const ConcreteCommandPath & aRequestCommandPath, CommandId commandId,
703
706
EncoderToTLV & encoder)
704
707
{
705
708
ConcreteCommandPath responseCommandPath = { aRequestCommandPath.mEndpointId , aRequestCommandPath.mClusterId , commandId };
0 commit comments