Skip to content

Commit

Permalink
add im revision support (#14479)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored and pull[bot] committed Oct 11, 2023
1 parent 5b5b7f3 commit 3655997
Show file tree
Hide file tree
Showing 32 changed files with 546 additions and 259 deletions.
5 changes: 5 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static_library("app") {
"EventManagement.cpp",
"EventPathParams.h",
"InteractionModelEngine.cpp",
"InteractionModelRevision.h",
"MessageDef/ArrayBuilder.cpp",
"MessageDef/ArrayParser.cpp",
"MessageDef/AttributeDataIB.cpp",
Expand Down Expand Up @@ -107,8 +108,12 @@ static_library("app") {
"MessageDef/InvokeResponseMessage.cpp",
"MessageDef/ListBuilder.cpp",
"MessageDef/ListParser.cpp",
"MessageDef/MessageBuilder.cpp",
"MessageDef/MessageBuilder.h",
"MessageDef/MessageDefHelper.cpp",
"MessageDef/MessageDefHelper.h",
"MessageDef/MessageParser.cpp",
"MessageDef/MessageParser.h",
"MessageDef/Parser.cpp",
"MessageDef/Parser.h",
"MessageDef/ReadRequestMessage.cpp",
Expand Down
29 changes: 29 additions & 0 deletions src/app/InteractionModelRevision.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
*
* Copyright (c) 2022 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.
*/

#pragma once

/**
* CHIP_DEVICE_CONFIG_INTERACTION_MODEL_REVISION
*
* A monothonic number identifying the interaction model revision.
*/
#ifndef CHIP_DEVICE_CONFIG_INTERACTION_MODEL_REVISION
#define CHIP_DEVICE_CONFIG_INTERACTION_MODEL_REVISION 1
#endif

constexpr uint8_t kInteractionModelRevisionTag = 0xFF;
28 changes: 19 additions & 9 deletions src/app/MessageDef/InvokeRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace app {
CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const
{
CHIP_ERROR err = CHIP_NO_ERROR;
int TagPresenceMask = 0;
int tagPresenceMask = 0;
TLV::TLVReader reader;

PRETTY_PRINT("InvokeRequestMessage =");
Expand All @@ -46,8 +46,8 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const
{
case to_underlying(Tag::kSuppressResponse):
// check if this tag has appeared before
VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG);
TagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse));
VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG);
tagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse));
#if CHIP_DETAIL_LOGGING
{
bool suppressResponse;
Expand All @@ -59,8 +59,8 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const

case to_underlying(Tag::kTimedRequest):
// check if this tag has appeared before
VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kTimedRequest))), CHIP_ERROR_INVALID_TLV_TAG);
TagPresenceMask |= (1 << to_underlying(Tag::kTimedRequest));
VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kTimedRequest))), CHIP_ERROR_INVALID_TLV_TAG);
tagPresenceMask |= (1 << to_underlying(Tag::kTimedRequest));
#if CHIP_DETAIL_LOGGING
{
bool timedRequest;
Expand All @@ -71,8 +71,8 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const
break;
case to_underlying(Tag::kInvokeRequests):
// check if this tag has appeared before
VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kInvokeRequests))), CHIP_ERROR_INVALID_TLV_TAG);
TagPresenceMask |= (1 << to_underlying(Tag::kInvokeRequests));
VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kInvokeRequests))), CHIP_ERROR_INVALID_TLV_TAG);
tagPresenceMask |= (1 << to_underlying(Tag::kInvokeRequests));
{
InvokeRequests::Parser invokeRequests;
ReturnErrorOnFailure(invokeRequests.Init(reader));
Expand All @@ -82,6 +82,9 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const
PRETTY_PRINT_DECDEPTH();
}
break;
case kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
break;
Expand All @@ -96,7 +99,7 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const
const int RequiredFields = (1 << to_underlying(Tag::kSuppressResponse)) | (1 << to_underlying(Tag::kTimedRequest)) |
(1 << to_underlying(Tag::kInvokeRequests));

if ((TagPresenceMask & RequiredFields) == RequiredFields)
if ((tagPresenceMask & RequiredFields) == RequiredFields)
{
err = CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -159,7 +162,14 @@ InvokeRequests::Builder & InvokeRequestMessage::Builder::CreateInvokeRequests()

InvokeRequestMessage::Builder & InvokeRequestMessage::Builder::EndOfInvokeRequestMessage()
{
EndOfContainer();
if (mError == CHIP_NO_ERROR)
{
mError = MessageBuilder::EncodeInteractionModelRevision();
}
if (mError == CHIP_NO_ERROR)
{
EndOfContainer();
}
return *this;
}
}; // namespace app
Expand Down
14 changes: 7 additions & 7 deletions src/app/MessageDef/InvokeRequestMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <lib/support/logging/CHIPLogging.h>

#include "InvokeRequests.h"
#include "StructBuilder.h"
#include "StructParser.h"
#include "MessageBuilder.h"
#include "MessageParser.h"

namespace chip {
namespace app {
Expand All @@ -38,7 +38,7 @@ enum class Tag : uint8_t
kInvokeRequests = 2,
};

class Parser : public StructParser
class Parser : public MessageParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
Expand Down Expand Up @@ -85,7 +85,7 @@ class Parser : public StructParser
CHIP_ERROR GetInvokeRequests(InvokeRequests::Parser * const apInvokeRequests) const;
};

class Builder : public StructBuilder
class Builder : public MessageBuilder
{
public:
/**
Expand Down Expand Up @@ -122,6 +122,6 @@ class Builder : public StructBuilder
private:
InvokeRequests::Builder mInvokeRequests;
};
}; // namespace InvokeRequestMessage
}; // namespace app
}; // namespace chip
} // namespace InvokeRequestMessage
} // namespace app
} // namespace chip
24 changes: 17 additions & 7 deletions src/app/MessageDef/InvokeResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace app {
CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const
{
CHIP_ERROR err = CHIP_NO_ERROR;
int TagPresenceMask = 0;
int tagPresenceMask = 0;
TLV::TLVReader reader;

PRETTY_PRINT("InvokeResponseMessage =");
Expand All @@ -46,8 +46,8 @@ CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const
{
case to_underlying(Tag::kSuppressResponse):
// check if this tag has appeared before
VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG);
TagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse));
VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG);
tagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse));
#if CHIP_DETAIL_LOGGING
{
bool suppressResponse;
Expand All @@ -58,8 +58,8 @@ CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const
break;
case to_underlying(Tag::kInvokeResponses):
// check if this tag has appeared before
VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kInvokeResponses))), CHIP_ERROR_INVALID_TLV_TAG);
TagPresenceMask |= (1 << to_underlying(Tag::kInvokeResponses));
VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kInvokeResponses))), CHIP_ERROR_INVALID_TLV_TAG);
tagPresenceMask |= (1 << to_underlying(Tag::kInvokeResponses));
{
InvokeResponseIBs::Parser invokeResponses;
ReturnErrorOnFailure(invokeResponses.Init(reader));
Expand All @@ -69,6 +69,9 @@ CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const
PRETTY_PRINT_DECDEPTH();
}
break;
case kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
break;
Expand All @@ -82,7 +85,7 @@ CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const
{
const int RequiredFields = (1 << to_underlying(Tag::kSuppressResponse)) | (1 << to_underlying(Tag::kInvokeResponses));

if ((TagPresenceMask & RequiredFields) == RequiredFields)
if ((tagPresenceMask & RequiredFields) == RequiredFields)
{
err = CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -131,7 +134,14 @@ InvokeResponseIBs::Builder & InvokeResponseMessage::Builder::CreateInvokeRespons

InvokeResponseMessage::Builder & InvokeResponseMessage::Builder::EndOfInvokeResponseMessage()
{
EndOfContainer();
if (mError == CHIP_NO_ERROR)
{
mError = MessageBuilder::EncodeInteractionModelRevision();
}
if (mError == CHIP_NO_ERROR)
{
EndOfContainer();
}
return *this;
}
} // namespace app
Expand Down
8 changes: 4 additions & 4 deletions src/app/MessageDef/InvokeResponseMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <lib/support/logging/CHIPLogging.h>

#include "InvokeResponseIBs.h"
#include "StructBuilder.h"
#include "StructParser.h"
#include "MessageBuilder.h"
#include "MessageParser.h"

namespace chip {
namespace app {
Expand All @@ -37,7 +37,7 @@ enum class Tag : uint8_t
kInvokeResponses = 1,
};

class Parser : public StructParser
class Parser : public MessageParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
Expand Down Expand Up @@ -76,7 +76,7 @@ class Parser : public StructParser
CHIP_ERROR GetInvokeResponses(InvokeResponseIBs::Parser * const apInvokeResponses) const;
};

class Builder : public StructBuilder
class Builder : public MessageBuilder
{
public:
/**
Expand Down
32 changes: 32 additions & 0 deletions src/app/MessageDef/MessageBuilder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
*
* 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.
*/

#include "MessageBuilder.h"

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

namespace chip {
namespace app {
CHIP_ERROR MessageBuilder::EncodeInteractionModelRevision()
{
ReturnErrorOnFailure(mpWriter->Put(TLV::ContextTag(kInteractionModelRevisionTag),
static_cast<InteractionModelRevision>(CHIP_DEVICE_CONFIG_INTERACTION_MODEL_REVISION)));
return CHIP_NO_ERROR;
}
} // namespace app
} // namespace chip
32 changes: 32 additions & 0 deletions src/app/MessageDef/MessageBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
*
* 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.
*/

#pragma once

#include "StructBuilder.h"
#include <app/InteractionModelRevision.h>
#include <app/util/basic-types.h>

namespace chip {
namespace app {
class MessageBuilder : public StructBuilder
{
public:
CHIP_ERROR EncodeInteractionModelRevision();
};
} // namespace app
} // namespace chip
9 changes: 5 additions & 4 deletions src/app/MessageDef/MessageDefHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@

#include "MessageDefHelper.h"
#include <algorithm>
#include <app/AppBuildConfig.h>
#include <app/InteractionModelRevision.h>
#include <app/util/basic-types.h>
#include <inttypes.h>
#include <lib/support/logging/CHIPLogging.h>
#include <stdarg.h>
#include <stdio.h>

#include <app/AppBuildConfig.h>
#include <lib/support/logging/CHIPLogging.h>

namespace chip {
namespace app {

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK && CHIP_DETAIL_LOGGING
// this is used to run in signle thread for IM message debug purpose
namespace {
Expand Down Expand Up @@ -94,5 +94,6 @@ void DecreaseDepth()
gPrettyPrintingDepthLevel--;
}
#endif

}; // namespace app
}; // namespace chip
43 changes: 43 additions & 0 deletions src/app/MessageDef/MessageParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
*
* 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.
*/

#include "MessageParser.h"
#include "MessageDefHelper.h"
#include <app/InteractionModelRevision.h>

namespace chip {
namespace app {
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
CHIP_ERROR MessageParser::CheckInteractionModelRevision(TLV::TLVReader & aReader) const
{
#if CHIP_DETAIL_LOGGING
{
uint8_t interactionModelRevision = 0;
ReturnErrorOnFailure(aReader.Get(interactionModelRevision));
PRETTY_PRINT("\tInteractionModelRevision = %u", interactionModelRevision);
}
#endif // CHIP_DETAIL_LOGGING
return CHIP_NO_ERROR;
}
#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK

CHIP_ERROR MessageParser::GetInteractionModelRevision(InteractionModelRevision * const apInteractionModelRevision) const
{
return GetUnsignedInteger(kInteractionModelRevisionTag, apInteractionModelRevision);
}

} // namespace app
} // namespace chip
Loading

0 comments on commit 3655997

Please sign in to comment.