33
33
#include < app/MessageDef/InvokeResponseMessage.h>
34
34
#include < app/MessageDef/StatusIB.h>
35
35
#include < app/PendingResponseTrackerImpl.h>
36
+ #include < app/data-model/EncodableToTLV.h>
36
37
#include < app/data-model/Encode.h>
37
38
#include < lib/core/CHIPCore.h>
38
39
#include < lib/core/Optional.h>
@@ -375,6 +376,26 @@ class CommandSender final : public Messaging::ExchangeDelegate
375
376
376
377
TLV::TLVWriter * GetCommandDataIBTLVWriter ();
377
378
379
+ /* *
380
+ * API for adding a request data. The `aEncodable` is generally expected to encode
381
+ * a ClusterName::Commands::CommandName::Type struct, however any object should work.
382
+ *
383
+ * @param [in] aCommandPath The path of the command being requested.
384
+ * @param [in] aEncodable - an encodable that places the command data structure
385
+ * for `aResponseCommandId` into a TLV Writer.
386
+ * @param [in] aAddRequestDataParams parameters associated with building the
387
+ * InvokeRequestMessage that are associated with this request.
388
+ *
389
+ * This API does not validate if command provided requires timed invoke. If caller
390
+ * wants that certainty they should call templated version of AddRequestData.
391
+ */
392
+ CHIP_ERROR AddRequestData (const CommandPathParams & aCommandPath,
393
+ DataModel::EncodableToTLV & aEncodable,
394
+ AddRequestDataParameters & aAddRequestDataParams)
395
+ {
396
+ return AddRequestDataInternal (aCommandPath, aEncodable, aAddRequestDataParams);
397
+ }
398
+
378
399
/* *
379
400
* API for adding a data request. The template parameter T is generally
380
401
* expected to be a ClusterName::Commands::CommandName::Type struct, but any
@@ -388,24 +409,19 @@ class CommandSender final : public Messaging::ExchangeDelegate
388
409
CHIP_ERROR AddRequestData (const CommandPathParams & aCommandPath, const CommandDataT & aData)
389
410
{
390
411
AddRequestDataParameters addRequestDataParams;
391
- return AddRequestData (aCommandPath, aData, addRequestDataParams);
412
+ DataModel::EncodableType<CommandDataT> encoder (aData);
413
+ return AddRequestData (aCommandPath, encoder, addRequestDataParams);
392
414
}
393
415
394
- template <typename CommandDataT>
395
- CHIP_ERROR AddRequestData (const CommandPathParams & aCommandPath, const CommandDataT & aData,
396
- AddRequestDataParameters & aAddRequestDataParams)
397
- {
398
- VerifyOrReturnError (!CommandDataT::MustUseTimedInvoke () || aAddRequestDataParams.timedInvokeTimeoutMs .HasValue (),
399
- CHIP_ERROR_INVALID_ARGUMENT);
400
-
401
- return AddRequestDataInternal (aCommandPath, aData, aAddRequestDataParams);
402
- }
403
416
template <typename CommandDataT>
404
417
CHIP_ERROR AddRequestData (const CommandPathParams & aCommandPath, const CommandDataT & aData,
405
418
const Optional<uint16_t > & aTimedInvokeTimeoutMs)
406
419
{
420
+ VerifyOrReturnError (!CommandDataT::MustUseTimedInvoke () || aTimedInvokeTimeoutMs.HasValue (),
421
+ CHIP_ERROR_INVALID_ARGUMENT);
407
422
AddRequestDataParameters addRequestDataParams (aTimedInvokeTimeoutMs);
408
- return AddRequestData (aCommandPath, aData, addRequestDataParams);
423
+ DataModel::EncodableType<CommandDataT> encoder (aData);
424
+ return AddRequestData (aCommandPath, encoder, addRequestDataParams);
409
425
}
410
426
411
427
/* *
@@ -426,7 +442,8 @@ class CommandSender final : public Messaging::ExchangeDelegate
426
442
CHIP_ERROR TestOnlyAddRequestDataNoTimedCheck (const CommandPathParams & aCommandPath, const CommandDataT & aData,
427
443
AddRequestDataParameters & aAddRequestDataParams)
428
444
{
429
- return AddRequestDataInternal (aCommandPath, aData, aAddRequestDataParams);
445
+ DataModel::EncodableType<CommandDataT> encoder (aData);
446
+ return AddRequestDataInternal (aCommandPath, encoder, aAddRequestDataParams);
430
447
}
431
448
432
449
CHIP_ERROR TestOnlyFinishCommand (FinishCommandParameters & aFinishCommandParams)
@@ -448,18 +465,9 @@ class CommandSender final : public Messaging::ExchangeDelegate
448
465
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
449
466
450
467
private:
451
- template <typename CommandDataT>
452
- CHIP_ERROR AddRequestDataInternal (const CommandPathParams & aCommandPath, const CommandDataT & aData,
453
- AddRequestDataParameters & aAddRequestDataParams)
454
- {
455
- PrepareCommandParameters prepareCommandParams (aAddRequestDataParams);
456
- ReturnErrorOnFailure (PrepareCommand (aCommandPath, prepareCommandParams));
457
- TLV::TLVWriter * writer = GetCommandDataIBTLVWriter ();
458
- VerifyOrReturnError (writer != nullptr , CHIP_ERROR_INCORRECT_STATE);
459
- ReturnErrorOnFailure (DataModel::Encode (*writer, TLV::ContextTag (CommandDataIB::Tag::kFields ), aData));
460
- FinishCommandParameters finishCommandParams (aAddRequestDataParams);
461
- return FinishCommand (finishCommandParams);
462
- }
468
+ CHIP_ERROR AddRequestDataInternal (const CommandPathParams & aCommandPath,
469
+ DataModel::EncodableToTLV & aEncodable,
470
+ AddRequestDataParameters & aAddRequestDataParams);
463
471
464
472
CHIP_ERROR FinishCommandInternal (FinishCommandParameters & aFinishCommandParams);
465
473
0 commit comments