Skip to content

Commit 9f6f8fb

Browse files
committed
Several updates: comments and remove inline
1 parent fc3591d commit 9f6f8fb

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/app/CommandHandler.h

+16-13
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,19 @@ class EncoderToTLV
6666
virtual CHIP_ERROR Encode(TLV::TLVWriter &, TLV::Tag tag) = 0;
6767
};
6868

69-
/// An `EncoderToTLV` the uses `DataModel::Encode` to encode things.
69+
/// An `EncoderToTLV` that uses `DataModel::Encode` to encode things.
7070
///
7171
/// Generally useful to encode things like <ClusterName>::Commands::<CommandName>::Type
7272
/// structures.
7373
template <typename T>
7474
class DataModelEncoderToTLV : public EncoderToTLV
7575
{
7676
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.
7782
DataModelEncoderToTLV(const T & value) : mValue(value) {}
7883

7984
virtual CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) { return DataModel::Encode(writer, tag, mValue); }
@@ -350,18 +355,16 @@ class CommandHandler
350355
* @param [in] aRequestCommandPath the concrete path of the command we are
351356
* responding to.
352357
* @param [in] aData the data for the response.
353-
*
354-
* NOTE: this is a convenience function for `AddResponseDataViaEncoder`
355358
*/
356359
template <typename CommandData>
357-
inline CHIP_ERROR AddResponseData(const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
360+
CHIP_ERROR AddResponseData(const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
358361
{
359362
DataModelEncoderToTLV<CommandData> encoder(aData);
360-
return AddResponseDataViaEncoder(aRequestCommandPath, CommandData::GetCommandId(), encoder);
363+
return AddResponseData(aRequestCommandPath, CommandData::GetCommandId(), encoder);
361364
}
362365

363366
/**
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
365368
* a ClusterName::Commands::CommandName::Type struct, but any
366369
* object should work.
367370
*
@@ -374,13 +377,13 @@ class CommandHandler
374377
* Most applications are likely to use `AddResponseData` as a more convenient
375378
* one-call that auto-sets command ID and creates the underlying encoders.
376379
*/
377-
CHIP_ERROR AddResponseDataViaEncoder(const ConcreteCommandPath & aRequestCommandPath, CommandId commandId,
380+
CHIP_ERROR AddResponseData(const ConcreteCommandPath & aRequestCommandPath, CommandId commandId,
378381
EncoderToTLV & encoder)
379382
{
380383
// Return early when response should not be sent out.
381384
VerifyOrReturnValue(ResponsesAccepted(), CHIP_NO_ERROR);
382385
return TryAddingResponse(
383-
[&]() -> CHIP_ERROR { return TryAddResponseDataViaEncoder(aRequestCommandPath, commandId, encoder); });
386+
[&]() -> CHIP_ERROR { return TryAddResponseData(aRequestCommandPath, commandId, encoder); });
384387
}
385388

386389
/**
@@ -398,10 +401,10 @@ class CommandHandler
398401
* @param [in] aData the data for the response.
399402
*/
400403
template <typename CommandData>
401-
inline void AddResponse(const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
404+
void AddResponse(const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
402405
{
403406
DataModelEncoderToTLV<CommandData> encoder(aData);
404-
return AddResponseViaEncoder(aRequestCommandPath, CommandData::GetCommandId(), encoder);
407+
return AddResponse(aRequestCommandPath, CommandData::GetCommandId(), encoder);
405408
}
406409

407410
/**
@@ -410,9 +413,9 @@ class CommandHandler
410413
* The encoder would generally encode a ClusterName::Commands::CommandName::Type with
411414
* the corresponding `GetCommandId` call.
412415
*/
413-
void AddResponseViaEncoder(const ConcreteCommandPath & aRequestCommandPath, CommandId commandId, EncoderToTLV & encoder)
416+
void AddResponse(const ConcreteCommandPath & aRequestCommandPath, CommandId commandId, EncoderToTLV & encoder)
414417
{
415-
if (AddResponseDataViaEncoder(aRequestCommandPath, commandId, encoder) != CHIP_NO_ERROR)
418+
if (AddResponseData(aRequestCommandPath, commandId, encoder) != CHIP_NO_ERROR)
416419
{
417420
AddStatus(aRequestCommandPath, Protocols::InteractionModel::Status::Failure);
418421
}
@@ -699,7 +702,7 @@ class CommandHandler
699702
* responding to.
700703
* @param [in] aData the data for the response.
701704
*/
702-
CHIP_ERROR TryAddResponseDataViaEncoder(const ConcreteCommandPath & aRequestCommandPath, CommandId commandId,
705+
CHIP_ERROR TryAddResponseData(const ConcreteCommandPath & aRequestCommandPath, CommandId commandId,
703706
EncoderToTLV & encoder)
704707
{
705708
ConcreteCommandPath responseCommandPath = { aRequestCommandPath.mEndpointId, aRequestCommandPath.mClusterId, commandId };

0 commit comments

Comments
 (0)