33
33
#include < app/CommandHandlerExchangeInterface.h>
34
34
#include < app/CommandPathRegistry.h>
35
35
#include < app/ConcreteCommandPath.h>
36
+ #include < app/data-model/EncodableToTLV.h>
36
37
#include < app/data-model/Encode.h>
37
- #include < app/data-model/EncoderToTLV.h>
38
38
#include < lib/core/CHIPCore.h>
39
39
#include < lib/core/TLV.h>
40
40
#include < lib/core/TLVDebug.h>
@@ -329,7 +329,7 @@ class CommandHandler
329
329
template <typename CommandData>
330
330
CHIP_ERROR AddResponseData (const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
331
331
{
332
- DataModel::ObjectEncoderToTLV <CommandData> encoder (aData);
332
+ DataModel::ObjectEncodableToTLV <CommandData> encoder (aData);
333
333
return AddResponseData (aRequestCommandPath, CommandData::GetCommandId (), encoder);
334
334
}
335
335
@@ -340,19 +340,20 @@ class CommandHandler
340
340
*
341
341
* @param [in] aRequestCommandPath the concrete path of the command we are
342
342
* responding to.
343
- * @param [in] commandId the command whose content is being encoded.
344
- * @param [in] encoder - an encoder that places the command data structure for `commandId `
343
+ * @param [in] aResponseCommandId the command whose content is being encoded.
344
+ * @param [in] encoder - an encoder that places the command data structure for `aResponseCommandId `
345
345
* into a TLV Writer.
346
346
*
347
347
* Most applications are likely to use `AddResponseData` as a more convenient
348
348
* one-call that auto-sets command ID and creates the underlying encoders.
349
349
*/
350
- CHIP_ERROR AddResponseData (const ConcreteCommandPath & aRequestCommandPath, CommandId commandId ,
351
- DataModel::EncoderToTLV & encoder )
350
+ CHIP_ERROR AddResponseData (const ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommandId ,
351
+ DataModel::EncodableToTLV & aEncodable )
352
352
{
353
353
// Return early when response should not be sent out.
354
354
VerifyOrReturnValue (ResponsesAccepted (), CHIP_NO_ERROR);
355
- return TryAddingResponse ([&]() -> CHIP_ERROR { return TryAddResponseData (aRequestCommandPath, commandId, encoder); });
355
+ return TryAddingResponse (
356
+ [&]() -> CHIP_ERROR { return TryAddResponseData (aRequestCommandPath, aResponseCommandId, aEncodable); });
356
357
}
357
358
358
359
/* *
@@ -372,19 +373,20 @@ class CommandHandler
372
373
template <typename CommandData>
373
374
void AddResponse (const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
374
375
{
375
- DataModel::ObjectEncoderToTLV <CommandData> encoder (aData);
376
- return AddResponse (aRequestCommandPath, CommandData::GetCommandId (), encoder );
376
+ DataModel::ObjectEncodableToTLV <CommandData> encodable (aData);
377
+ return AddResponse (aRequestCommandPath, CommandData::GetCommandId (), encodable );
377
378
}
378
379
379
380
/* *
380
- * API for adding a response with a given encoder of TLV data.
381
+ * API for adding a response with a given encodable of TLV data.
381
382
*
382
- * The encoder would generally encode a ClusterName::Commands::CommandName::Type with
383
+ * The encodable would generally encode a ClusterName::Commands::CommandName::Type with
383
384
* the corresponding `GetCommandId` call.
384
385
*/
385
- void AddResponse (const ConcreteCommandPath & aRequestCommandPath, CommandId commandId, DataModel::EncoderToTLV & encoder)
386
+ void AddResponse (const ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommandId,
387
+ DataModel::EncodableToTLV & encodable)
386
388
{
387
- if (AddResponseData (aRequestCommandPath, commandId, encoder ) != CHIP_NO_ERROR)
389
+ if (AddResponseData (aRequestCommandPath, aResponseCommandId, encodable ) != CHIP_NO_ERROR)
388
390
{
389
391
AddStatus (aRequestCommandPath, Protocols::InteractionModel::Status::Failure);
390
392
}
@@ -638,40 +640,17 @@ class CommandHandler
638
640
639
641
CHIP_ERROR AddStatusInternal (const ConcreteCommandPath & aCommandPath, const StatusIB & aStatus);
640
642
641
- /* *
642
- * Non-templated function called before DataModel::Encode when attempting to add a response,
643
- * which does all the work needed before encoding the actual type-dependent data into the buffer.
644
- *
645
- * **Important:** If this function fails, the TLV buffer may be left in an inconsistent state.
646
- * Callers should create snapshots as necessary before invoking this function and implement
647
- * rollback mechanisms if needed.
648
- *
649
- * **Usage:** This function is intended to be called exclusively by TryAddResponseData. It was
650
- * factored out to optimize code size.
651
- *
652
- * @param aRequestCommandPath The concrete path of the command being responded to.
653
- * @param aResponseCommandPath The concrete path of the command response.
654
- */
655
- CHIP_ERROR TryAddResponseDataPreEncode (const ConcreteCommandPath & aRequestCommandPath,
656
- const ConcreteCommandPath & aResponseCommandPath)
657
- {
658
- InvokeResponseParameters prepareParams (aRequestCommandPath);
659
- prepareParams.SetStartOrEndDataStruct (false );
660
-
661
- ScopedChange<bool > internalCallToAddResponse (mInternalCallToAddResponseData , true );
662
- return PrepareInvokeResponseCommand (aResponseCommandPath, prepareParams);
663
- }
664
-
665
643
/* *
666
644
* If this function fails, it may leave our TLV buffer in an inconsistent state.
667
645
* Callers should snapshot as needed before calling this function, and roll back
668
646
* as needed afterward.
669
647
*
670
- * @param [in] path the concrete path of the command we are responding to
671
- * @param [in] commandId the id of the command to encode
672
- * @param [in] encoder the data to encode for the given commandId
648
+ * @param [in] aCommandPath the concrete path of the command we are responding to
649
+ * @param [in] aResponseCommandId the id of the command to encode
650
+ * @param [in] aEncodable the data to encode for the given aResponseCommandId
673
651
*/
674
- CHIP_ERROR TryAddResponseData (const ConcreteCommandPath & path, CommandId commandId, DataModel::EncoderToTLV & encoder);
652
+ CHIP_ERROR TryAddResponseData (const ConcreteCommandPath & aCommandPath, CommandId aResponseCommandId,
653
+ DataModel::EncodableToTLV & aEncodable);
675
654
676
655
void SetExchangeInterface (CommandHandlerExchangeInterface * commandResponder);
677
656
0 commit comments