Skip to content

Commit

Permalink
Rename CommandDataElement to CommandDataIB (#10695)
Browse files Browse the repository at this point in the history
* Rename CommandDataElement to CommandDataIB

* run codegen
  • Loading branch information
yunhanw-google authored and pull[bot] committed Jan 11, 2022
1 parent c5ee6c0 commit 0f0072d
Show file tree
Hide file tree
Showing 36 changed files with 319 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
TLVWriter * writer = nullptr;
uint8_t tagNum = 0;
VerifyOrReturnError((commandObj->PrepareCommand(cmdParams) == CHIP_NO_ERROR), EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError((writer = commandObj->GetCommandDataElementTLVWriter()) != nullptr, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->Put(ContextTag(tagNum++), queryStatus) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->Put(ContextTag(tagNum++), mDelayedActionTimeSec) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->PutString(ContextTag(tagNum++), uriBuf) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
Expand Down Expand Up @@ -190,7 +190,7 @@ EmberAfStatus OTAProviderExample::HandleApplyUpdateRequest(chip::app::CommandHan
TLVWriter * writer = nullptr;

VerifyOrReturnError((commandObj->PrepareCommand(cmdParams) == CHIP_NO_ERROR), EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError((writer = commandObj->GetCommandDataElementTLVWriter()) != nullptr, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->Put(ContextTag(0), updateAction) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->Put(ContextTag(1), mDelayedActionTimeSec) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError((commandObj->FinishCommand() == CHIP_NO_ERROR), EMBER_ZCL_STATUS_FAILURE);
Expand Down
4 changes: 2 additions & 2 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static_library("app") {
"MessageDef/AttributeStatusList.h",
"MessageDef/Builder.cpp",
"MessageDef/Builder.h",
"MessageDef/CommandDataElement.cpp",
"MessageDef/CommandDataElement.h",
"MessageDef/CommandDataIB.cpp",
"MessageDef/CommandDataIB.h",
"MessageDef/CommandList.cpp",
"MessageDef/CommandList.h",
"MessageDef/CommandPathIB.cpp",
Expand Down
31 changes: 15 additions & 16 deletions src/app/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ CHIP_ERROR Command::ProcessCommandMessage(System::PacketBufferHandle && payload,
VerifyOrExit(chip::TLV::AnonymousTag == commandListReader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG);
VerifyOrExit(chip::TLV::kTLVType_Structure == commandListReader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);

CommandDataElement::Parser commandElement;
CommandDataIB::Parser commandElement;

err = commandElement.Init(commandListReader);
SuccessOrExit(err);

err = ProcessCommandDataElement(commandElement);
err = ProcessCommandDataIB(commandElement);
SuccessOrExit(err);
}

Expand All @@ -115,7 +115,7 @@ CHIP_ERROR Command::ProcessCommandMessage(System::PacketBufferHandle && payload,
CHIP_ERROR Command::PrepareCommand(const CommandPathParams & aCommandPathParams, bool aStartDataStruct)
{
CHIP_ERROR err = CHIP_NO_ERROR;
CommandDataElement::Builder commandDataElement;
CommandDataIB::Builder commandDataIB;

err = AllocateBuffer();
SuccessOrExit(err);
Expand All @@ -125,17 +125,17 @@ CHIP_ERROR Command::PrepareCommand(const CommandPathParams & aCommandPathParams,
//
VerifyOrExit(mState == CommandState::Idle, err = CHIP_ERROR_INCORRECT_STATE);

commandDataElement = mInvokeCommandBuilder.GetCommandListBuilder().CreateCommandDataElementBuilder();
err = commandDataElement.GetError();
commandDataIB = mInvokeCommandBuilder.GetCommandListBuilder().CreateCommandDataIBBuilder();
err = commandDataIB.GetError();
SuccessOrExit(err);

err = ConstructCommandPath(aCommandPathParams, commandDataElement);
err = ConstructCommandPath(aCommandPathParams, commandDataIB);
SuccessOrExit(err);

if (aStartDataStruct)
{
err = commandDataElement.GetWriter()->StartContainer(TLV::ContextTag(CommandDataElement::kCsTag_Data),
TLV::kTLVType_Structure, mDataElementContainerType);
err = commandDataIB.GetWriter()->StartContainer(TLV::ContextTag(CommandDataIB::kCsTag_Data), TLV::kTLVType_Structure,
mDataElementContainerType);
}

MoveToState(CommandState::AddingCommand);
Expand All @@ -144,15 +144,15 @@ CHIP_ERROR Command::PrepareCommand(const CommandPathParams & aCommandPathParams,
return err;
}

TLV::TLVWriter * Command::GetCommandDataElementTLVWriter()
TLV::TLVWriter * Command::GetCommandDataIBTLVWriter()
{
if (mState != CommandState::AddingCommand)
{
return nullptr;
}
else
{
return mInvokeCommandBuilder.GetCommandListBuilder().GetCommandDataElementBuilder().GetWriter();
return mInvokeCommandBuilder.GetCommandListBuilder().GetCommandDataIBBuilder().GetWriter();
}
}

Expand All @@ -168,13 +168,13 @@ CHIP_ERROR Command::FinishCommand(bool aEndDataStruct)

VerifyOrReturnError(mState == CommandState::AddingCommand, err = CHIP_ERROR_INCORRECT_STATE);

CommandDataElement::Builder commandDataElement = mInvokeCommandBuilder.GetCommandListBuilder().GetCommandDataElementBuilder();
CommandDataIB::Builder commandDataIB = mInvokeCommandBuilder.GetCommandListBuilder().GetCommandDataIBBuilder();
if (aEndDataStruct)
{
ReturnErrorOnFailure(commandDataElement.GetWriter()->EndContainer(mDataElementContainerType));
ReturnErrorOnFailure(commandDataIB.GetWriter()->EndContainer(mDataElementContainerType));
}

ReturnErrorOnFailure(commandDataElement.EndOfCommandDataElement().GetError());
ReturnErrorOnFailure(commandDataIB.EndOfCommandDataIB().GetError());
ReturnErrorOnFailure(mInvokeCommandBuilder.GetCommandListBuilder().EndOfCommandList().GetError());
ReturnErrorOnFailure(mInvokeCommandBuilder.EndOfInvokeCommand().GetError());

Expand All @@ -183,10 +183,9 @@ CHIP_ERROR Command::FinishCommand(bool aEndDataStruct)
return CHIP_NO_ERROR;
}

CHIP_ERROR Command::ConstructCommandPath(const CommandPathParams & aCommandPathParams,
CommandDataElement::Builder aCommandDataElement)
CHIP_ERROR Command::ConstructCommandPath(const CommandPathParams & aCommandPathParams, CommandDataIB::Builder aCommandDataIB)
{
CommandPathIB::Builder commandPath = aCommandDataElement.CreateCommandPathBuilder();
CommandPathIB::Builder commandPath = aCommandDataIB.CreateCommandPathBuilder();
if (aCommandPathParams.mFlags.Has(CommandPathFlags::kEndpointIdValid))
{
commandPath.EndpointId(aCommandPathParams.mEndpointId);
Expand Down
8 changes: 4 additions & 4 deletions src/app/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <app/CommandPathParams.h>
#include <app/ConcreteCommandPath.h>
#include <app/InteractionModelDelegate.h>
#include <app/MessageDef/CommandDataElement.h>
#include <app/MessageDef/CommandDataIB.h>
#include <app/MessageDef/CommandList.h>
#include <app/MessageDef/InvokeCommand.h>
#include <lib/core/CHIPCore.h>
Expand Down Expand Up @@ -74,7 +74,7 @@ class Command
* A set of methods to construct command request or response payloads
*/
CHIP_ERROR PrepareCommand(const CommandPathParams & aCommandPathParams, bool aStartDataStruct = true);
TLV::TLVWriter * GetCommandDataElementTLVWriter();
TLV::TLVWriter * GetCommandDataIBTLVWriter();
CHIP_ERROR FinishCommand(bool aEndDataStruct = true);
CHIP_ERROR Finalize(System::PacketBufferHandle & commandPacket);

Expand Down Expand Up @@ -102,7 +102,7 @@ class Command
*/
Messaging::ExchangeContext * GetExchangeContext() const { return mpExchangeCtx; }

virtual CHIP_ERROR ProcessCommandDataElement(CommandDataElement::Parser & aCommandElement) = 0;
virtual CHIP_ERROR ProcessCommandDataIB(CommandDataIB::Parser & aCommandElement) = 0;

protected:
Command();
Expand All @@ -124,7 +124,7 @@ class Command

void MoveToState(const CommandState aTargetState);
CHIP_ERROR ProcessCommandMessage(System::PacketBufferHandle && payload, CommandRoleId aCommandRoleId);
CHIP_ERROR ConstructCommandPath(const CommandPathParams & aCommandPathParams, CommandDataElement::Builder aCommandDataElement);
CHIP_ERROR ConstructCommandPath(const CommandPathParams & aCommandPathParams, CommandDataIB::Builder aCommandDataIB);
const char * GetStateStr() const;

InvokeCommand::Builder mInvokeCommandBuilder;
Expand Down
4 changes: 2 additions & 2 deletions src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ CHIP_ERROR CommandHandler::SendCommandResponse()
return CHIP_NO_ERROR;
}

CHIP_ERROR CommandHandler::ProcessCommandDataElement(CommandDataElement::Parser & aCommandElement)
CHIP_ERROR CommandHandler::ProcessCommandDataIB(CommandDataIB::Parser & aCommandElement)
{
CHIP_ERROR err = CHIP_NO_ERROR;
CommandPathIB::Parser commandPath;
Expand Down Expand Up @@ -167,7 +167,7 @@ CHIP_ERROR CommandHandler::AddStatus(const ConcreteCommandPath & aCommandPath, c
err = PrepareCommand(commandPathParams, false /* aStartDataStruct */);
SuccessOrExit(err);

statusIBBuilder = mInvokeCommandBuilder.GetCommandListBuilder().GetCommandDataElementBuilder().CreateStatusIBBuilder();
statusIBBuilder = mInvokeCommandBuilder.GetCommandListBuilder().GetCommandDataIBBuilder().CreateStatusIBBuilder();

//
// TODO: Most of the callers are incorrectly passing SecureChannel as the protocol ID, when in fact, the status code provided
Expand Down
8 changes: 4 additions & 4 deletions src/app/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <app/Command.h>
#include <app/ConcreteCommandPath.h>
#include <app/MessageDef/CommandDataElement.h>
#include <app/MessageDef/CommandDataIB.h>
#include <app/data-model/Encode.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPTLV.h>
Expand Down Expand Up @@ -88,9 +88,9 @@ class CommandHandler : public Command
CHIP_ERROR AddResponseData(const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData)
{
ReturnErrorOnFailure(PrepareResponse(aRequestCommandPath, CommandData::GetCommandId()));
TLV::TLVWriter * writer = GetCommandDataElementTLVWriter();
TLV::TLVWriter * writer = GetCommandDataIBTLVWriter();
VerifyOrReturnError(writer != nullptr, CHIP_ERROR_INCORRECT_STATE);
ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(CommandDataElement::kCsTag_Data), aData));
ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(CommandDataIB::kCsTag_Data), aData));

return FinishCommand(/* aEndDataStruct = */ false);
}
Expand All @@ -105,7 +105,7 @@ class CommandHandler : public Command

friend class TestCommandInteraction;
CHIP_ERROR SendCommandResponse();
CHIP_ERROR ProcessCommandDataElement(CommandDataElement::Parser & aCommandElement) override;
CHIP_ERROR ProcessCommandDataIB(CommandDataIB::Parser & aCommandElement) override;
CHIP_ERROR PrepareResponse(const ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommand);
Callback * mpCallback = nullptr;
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/CommandSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void CommandSender::Close()
}
}

CHIP_ERROR CommandSender::ProcessCommandDataElement(CommandDataElement::Parser & aCommandElement)
CHIP_ERROR CommandSender::ProcessCommandDataIB(CommandDataIB::Parser & aCommandElement)
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::ClusterId clusterId;
Expand Down
6 changes: 3 additions & 3 deletions src/app/CommandSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ class CommandSender final : public Command, public Messaging::ExchangeDelegate
CHIP_ERROR AddRequestData(const CommandPathParams & aCommandPath, const CommandDataT & aData)
{
ReturnErrorOnFailure(PrepareCommand(aCommandPath, /* aStartDataStruct = */ false));
TLV::TLVWriter * writer = GetCommandDataElementTLVWriter();
TLV::TLVWriter * writer = GetCommandDataIBTLVWriter();
VerifyOrReturnError(writer != nullptr, CHIP_ERROR_INCORRECT_STATE);
ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(CommandDataElement::kCsTag_Data), aData));
ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(CommandDataIB::kCsTag_Data), aData));
return FinishCommand(/* aEndDataStruct = */ false);
}

Expand Down Expand Up @@ -171,7 +171,7 @@ class CommandSender final : public Command, public Messaging::ExchangeDelegate
//
void Close();

CHIP_ERROR ProcessCommandDataElement(CommandDataElement::Parser & aCommandElement) override;
CHIP_ERROR ProcessCommandDataIB(CommandDataIB::Parser & aCommandElement) override;

Callback * mpCallback = nullptr;
Messaging::ExchangeManager * mpExchangeMgr = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
/**
* @file
* This file defines CommandDataElement parser and builder in CHIP interaction model
* This file defines CommandDataIB parser and builder in CHIP interaction model
*
*/

#include "CommandDataElement.h"
#include "CommandDataIB.h"

#include "MessageDefHelper.h"

Expand All @@ -36,7 +36,7 @@ using namespace chip::TLV;

namespace chip {
namespace app {
CHIP_ERROR CommandDataElement::Parser::Init(const chip::TLV::TLVReader & aReader)
CHIP_ERROR CommandDataIB::Parser::Init(const chip::TLV::TLVReader & aReader)
{
CHIP_ERROR err = CHIP_NO_ERROR;

Expand All @@ -52,7 +52,7 @@ CHIP_ERROR CommandDataElement::Parser::Init(const chip::TLV::TLVReader & aReader
}

CHIP_ERROR
CommandDataElement::Parser::ParseData(chip::TLV::TLVReader & aReader, int aDepth) const
CommandDataIB::Parser::ParseData(chip::TLV::TLVReader & aReader, int aDepth) const
{
CHIP_ERROR err = CHIP_NO_ERROR;

Expand Down Expand Up @@ -223,14 +223,14 @@ CommandDataElement::Parser::ParseData(chip::TLV::TLVReader & aReader, int aDepth
}

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
CHIP_ERROR CommandDataElement::Parser::CheckSchemaValidity() const
CHIP_ERROR CommandDataIB::Parser::CheckSchemaValidity() const
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint16_t TagPresenceMask = 0;
chip::TLV::TLVReader reader;
uint32_t tagNum = 0;

PRETTY_PRINT("CommandDataElement =");
PRETTY_PRINT("CommandDataIB =");
PRETTY_PRINT("{");

// make a copy of the reader
Expand Down Expand Up @@ -321,7 +321,7 @@ CHIP_ERROR CommandDataElement::Parser::CheckSchemaValidity() const
}
#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK

CHIP_ERROR CommandDataElement::Parser::GetCommandPath(CommandPathIB::Parser * const apCommandPath) const
CHIP_ERROR CommandDataIB::Parser::GetCommandPath(CommandPathIB::Parser * const apCommandPath) const
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::TLV::TLVReader reader;
Expand All @@ -340,7 +340,7 @@ CHIP_ERROR CommandDataElement::Parser::GetCommandPath(CommandPathIB::Parser * co
return err;
}

CHIP_ERROR CommandDataElement::Parser::GetData(chip::TLV::TLVReader * const apReader) const
CHIP_ERROR CommandDataIB::Parser::GetData(chip::TLV::TLVReader * const apReader) const
{
CHIP_ERROR err = CHIP_NO_ERROR;

Expand All @@ -353,7 +353,7 @@ CHIP_ERROR CommandDataElement::Parser::GetData(chip::TLV::TLVReader * const apRe
return err;
}

CHIP_ERROR CommandDataElement::Parser::GetStatusIB(StatusIB::Parser * const apStatusIB) const
CHIP_ERROR CommandDataIB::Parser::GetStatusIB(StatusIB::Parser * const apStatusIB) const
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::TLV::TLVReader reader;
Expand All @@ -370,12 +370,12 @@ CHIP_ERROR CommandDataElement::Parser::GetStatusIB(StatusIB::Parser * const apSt
return err;
}

CHIP_ERROR CommandDataElement::Builder::Init(chip::TLV::TLVWriter * const apWriter)
CHIP_ERROR CommandDataIB::Builder::Init(chip::TLV::TLVWriter * const apWriter)
{
return InitAnonymousStructure(apWriter);
}

CommandPathIB::Builder & CommandDataElement::Builder::CreateCommandPathBuilder()
CommandPathIB::Builder & CommandDataIB::Builder::CreateCommandPathBuilder()
{
// skip if error has already been set
VerifyOrExit(CHIP_NO_ERROR == mError, mCommandPathBuilder.ResetError(mError));
Expand All @@ -387,7 +387,7 @@ CommandPathIB::Builder & CommandDataElement::Builder::CreateCommandPathBuilder()
return mCommandPathBuilder;
}

StatusIB::Builder & CommandDataElement::Builder::CreateStatusIBBuilder()
StatusIB::Builder & CommandDataIB::Builder::CreateStatusIBBuilder()
{
// skip if error has already been set
VerifyOrExit(CHIP_NO_ERROR == mError, mStatusIBBuilder.ResetError(mError));
Expand All @@ -399,7 +399,7 @@ StatusIB::Builder & CommandDataElement::Builder::CreateStatusIBBuilder()
return mStatusIBBuilder;
}

CommandDataElement::Builder & CommandDataElement::Builder::EndOfCommandDataElement()
CommandDataIB::Builder & CommandDataIB::Builder::EndOfCommandDataIB()
{
EndOfContainer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
/**
* @file
* This file defines CommandDataElement parser and builder in CHIP interaction model
* This file defines CommandDataIB parser and builder in CHIP interaction model
*
*/

Expand All @@ -38,7 +38,7 @@

namespace chip {
namespace app {
namespace CommandDataElement {
namespace CommandDataIB {
enum
{
kCsTag_CommandPath = 0,
Expand All @@ -52,7 +52,7 @@ class Parser : public chip::app::Parser
/**
* @brief Initialize the parser object with TLVReader
*
* @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this CommandDataElement
* @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this CommandDataIB
*
* @return #CHIP_NO_ERROR on success
*/
Expand Down Expand Up @@ -139,16 +139,16 @@ class Builder : public chip::app::Builder
StatusIB::Builder & CreateStatusIBBuilder();

/**
* @brief Mark the end of this CommandDataElement
* @brief Mark the end of this CommandDataIB
*
* @return A reference to *this
*/
CommandDataElement::Builder & EndOfCommandDataElement();
CommandDataIB::Builder & EndOfCommandDataIB();

private:
CommandPathIB::Builder mCommandPathBuilder;
StatusIB::Builder mStatusIBBuilder;
};
}; // namespace CommandDataElement
}; // namespace CommandDataIB
}; // namespace app
}; // namespace chip
Loading

0 comments on commit 0f0072d

Please sign in to comment.