Skip to content

Commit

Permalink
Add ListBuilder/Parser and StructBuilder/Parser
Browse files Browse the repository at this point in the history
--Fix ListBuilder naming, which should be ArrayBuilder
--Add ListBuilder/Parser and StructBuilder/Praser, the enablement for them would be
follow-up PR
  • Loading branch information
yunhanw-google committed Oct 29, 2021
1 parent e4407c4 commit bb87c8e
Show file tree
Hide file tree
Showing 23 changed files with 450 additions and 116 deletions.
6 changes: 4 additions & 2 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static_library("app") {
"CommandSender.cpp",
"EventManagement.cpp",
"InteractionModelEngine.cpp",
"MessageDef/ArrayBuilder.cpp",
"MessageDef/ArrayParser.cpp",
"MessageDef/AttributeDataElement.cpp",
"MessageDef/AttributeDataElement.h",
"MessageDef/AttributeDataList.cpp",
Expand Down Expand Up @@ -74,9 +76,7 @@ static_library("app") {
"MessageDef/InvokeCommand.cpp",
"MessageDef/InvokeCommand.h",
"MessageDef/ListBuilder.cpp",
"MessageDef/ListBuilder.h",
"MessageDef/ListParser.cpp",
"MessageDef/ListParser.h",
"MessageDef/MessageDefHelper.cpp",
"MessageDef/MessageDefHelper.h",
"MessageDef/Parser.cpp",
Expand All @@ -88,6 +88,8 @@ static_library("app") {
"MessageDef/StatusIB.cpp",
"MessageDef/StatusIB.h",
"MessageDef/StatusResponse.cpp",
"MessageDef/StructBuilder.cpp",
"MessageDef/StructParser.cpp",
"MessageDef/SubscribeRequest.cpp",
"MessageDef/SubscribeResponse.cpp",
"MessageDef/TimedRequestMessage.cpp",
Expand Down
48 changes: 48 additions & 0 deletions src/app/MessageDef/ArrayBuilder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
*
* Copyright (c) 2021 Project CHIP Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines Array builder in CHIP interaction model
*
*/

#include "ArrayBuilder.h"

#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>

namespace chip {
namespace app {
ArrayBuilder::ArrayBuilder() {}

CHIP_ERROR ArrayBuilder::Init(TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse)
{
mpWriter = apWriter;
mError = mpWriter->StartContainer(TLV::ContextTag(aContextTagToUse), chip::TLV::kTLVType_Array, mOuterContainerType);

return mError;
}

CHIP_ERROR ArrayBuilder::Init(TLV::TLVWriter * const apWriter)
{
mpWriter = apWriter;
mError = mpWriter->StartContainer(TLV::AnonymousTag, chip::TLV::kTLVType_Array, mOuterContainerType);

return mError;
}
}; // namespace app
}; // namespace chip
64 changes: 64 additions & 0 deletions src/app/MessageDef/ArrayBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines Array builder in CHIP interaction model
*
*/

#pragma once

#include "Builder.h"
#include "Parser.h"
#include <app/util/basic-types.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPTLV.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

namespace chip {
namespace app {
class ArrayBuilder : public Builder
{
protected:
ArrayBuilder();

public:
/**
* Init the TLV array container with an particular context tag.
* Required to implement arrays of arrays, and to test ArrayBuilder.
*
* @param[in] apWriter Pointer to the TLVWriter that is encoding the message.
* @param[in] aContextTagToUse A contextTag to use.
*
* @return CHIP_ERROR codes returned by chip::TLV objects.
*/

CHIP_ERROR Init(TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse);
/**
* Init the TLV array container with an anonymous tag.
* Required to implement arrays of arrays, and to test ArrayBuilder.
*
* @param[in] apWriter Pointer to the TLVWriter that is encoding the message.
*
* @return CHIP_ERROR codes returned by chip::TLV objects.
*/
CHIP_ERROR Init(TLV::TLVWriter * const apWriter);
};

}; // namespace app
}; // namespace chip
38 changes: 38 additions & 0 deletions src/app/MessageDef/ArrayParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2018 Google LLC.
* Copyright (c) 2016-2017 Nest Labs, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines Array parser in CHIP interaction model
*
*/

#include "ArrayParser.h"

namespace chip {
namespace app {
ArrayParser::ArrayParser() {}

CHIP_ERROR ArrayParser::Init(const TLV::TLVReader & aReader)
{
mReader.Init(aReader);
VerifyOrReturnError(TLV::kTLVType_Array == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
ReturnLogErrorOnFailure(mReader.EnterContainer(mOuterContainerType));
return CHIP_NO_ERROR;
}
}; // namespace app
}; // namespace chip
46 changes: 46 additions & 0 deletions src/app/MessageDef/ArrayParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2016-2017 Nest Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines Array parser in CHIP interaction model
*
*/

#pragma once

#include "Parser.h"

namespace chip {
namespace app {
class ArrayParser : public Parser
{
protected:
ArrayParser();

public:
/**
* @brief Initialize the parser object with TLVReader
*
* @param [in] aReader A pointer to a TLVReader, which should be on the element of the array element
*
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR Init(const TLV::TLVReader & aReader);
};
}; // namespace app
}; // namespace chip
8 changes: 4 additions & 4 deletions src/app/MessageDef/AttributeDataList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

#pragma once

#include "ArrayBuilder.h"
#include "ArrayParser.h"
#include "AttributeDataElement.h"
#include "ListBuilder.h"
#include "ListParser.h"

#include <app/AppBuildConfig.h>
#include <app/util/basic-types.h>
Expand All @@ -37,7 +37,7 @@
namespace chip {
namespace app {
namespace AttributeDataList {
class Parser : public ListParser
class Parser : public ArrayParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
Expand All @@ -58,7 +58,7 @@ class Parser : public ListParser
#endif
};

class Builder : public ListBuilder
class Builder : public ArrayBuilder
{
public:
/**
Expand Down
8 changes: 4 additions & 4 deletions src/app/MessageDef/AttributeDataVersionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

#pragma once

#include "ArrayBuilder.h"
#include "ArrayParser.h"
#include "AttributeDataElement.h"
#include "ListBuilder.h"
#include "ListParser.h"

#include <app/AppBuildConfig.h>
#include <app/util/basic-types.h>
Expand All @@ -37,7 +37,7 @@
namespace chip {
namespace app {
namespace AttributeDataVersionList {
class Parser : public ListParser
class Parser : public ArrayParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
Expand Down Expand Up @@ -83,7 +83,7 @@ class Parser : public ListParser
CHIP_ERROR GetVersion(chip::DataVersion * const apVersion);
};

class Builder : public ListBuilder
class Builder : public ArrayBuilder
{
public:
/**
Expand Down
8 changes: 4 additions & 4 deletions src/app/MessageDef/AttributePathList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

#pragma once

#include "ArrayBuilder.h"
#include "ArrayParser.h"
#include "AttributePath.h"
#include "ListBuilder.h"
#include "ListParser.h"

#include <app/AppBuildConfig.h>
#include <app/util/basic-types.h>
Expand All @@ -37,7 +37,7 @@
namespace chip {
namespace app {
namespace AttributePathList {
class Parser : public ListParser
class Parser : public ArrayParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
Expand All @@ -58,7 +58,7 @@ class Parser : public ListParser
#endif
};

class Builder : public ListBuilder
class Builder : public ArrayBuilder
{
public:
/**
Expand Down
8 changes: 4 additions & 4 deletions src/app/MessageDef/AttributeStatusList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

#pragma once

#include "ArrayBuilder.h"
#include "ArrayParser.h"
#include "AttributeStatusIB.h"
#include "ListBuilder.h"
#include "ListParser.h"

#include <app/AppBuildConfig.h>
#include <app/util/basic-types.h>
Expand All @@ -37,7 +37,7 @@
namespace chip {
namespace app {
namespace AttributeStatusList {
class Builder : public ListBuilder
class Builder : public ArrayBuilder
{
public:
/**
Expand All @@ -58,7 +58,7 @@ class Builder : public ListBuilder
AttributeStatusIB::Builder mAttributeStatusBuilder;
};

class Parser : public ListParser
class Parser : public ArrayParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
Expand Down
8 changes: 4 additions & 4 deletions src/app/MessageDef/CommandList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

#pragma once

#include "ArrayBuilder.h"
#include "ArrayParser.h"
#include "CommandDataIB.h"
#include "ListBuilder.h"
#include "ListParser.h"

#include <app/AppBuildConfig.h>
#include <app/util/basic-types.h>
Expand All @@ -37,7 +37,7 @@
namespace chip {
namespace app {
namespace CommandList {
class Parser : public ListParser
class Parser : public ArrayParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
Expand All @@ -58,7 +58,7 @@ class Parser : public ListParser
#endif
};

class Builder : public ListBuilder
class Builder : public ArrayBuilder
{
public:
/**
Expand Down
Loading

0 comments on commit bb87c8e

Please sign in to comment.