Skip to content

Commit

Permalink
Cleanup IM message def
Browse files Browse the repository at this point in the history
Summary of Changes:
--Remove extra header check in all im message def headers.
--Run im schema check only under CheckSchemaValidity in debug linux/mac build
--Remove redundant schema check
  • Loading branch information
yunhanw-google authored and erjiaqing committed Apr 13, 2021
1 parent c69dbdc commit 35620cc
Show file tree
Hide file tree
Showing 30 changed files with 103 additions and 172 deletions.
11 changes: 11 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ import("//build_overrides/chip.gni")
import("//build_overrides/nlio.gni")
import("common_flags.gni")

declare_args() {
# Enable strict schema checks.
chip_enable_schema_check =
is_debug && (current_os == "linux" || current_os == "mac")
}

config("app_config") {
include_dirs = [
"util",
".",
"${target_gen_dir}/include",
]
if (chip_enable_schema_check) {
defines = [ "CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK=1" ]
} else {
defines = [ "CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK=0" ]
}
}

static_library("app") {
Expand Down
6 changes: 2 additions & 4 deletions src/app/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ CHIP_ERROR Command::ProcessCommandMessage(System::PacketBufferHandle && payload,
err = invokeCommandParser.Init(reader);
SuccessOrExit(err);

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
err = invokeCommandParser.CheckSchemaValidity();
SuccessOrExit(err);

#endif
err = invokeCommandParser.GetCommandList(&commandListParser);
SuccessOrExit(err);

Expand All @@ -111,9 +112,6 @@ CHIP_ERROR Command::ProcessCommandMessage(System::PacketBufferHandle && payload,
err = commandElement.Init(commandListReader);
SuccessOrExit(err);

err = commandElement.CheckSchemaValidity();
SuccessOrExit(err);

err = ProcessCommandDataElement(commandElement);
SuccessOrExit(err);
}
Expand Down
3 changes: 0 additions & 3 deletions src/app/CommandSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ CHIP_ERROR CommandSender::ProcessCommandDataElement(CommandDataElement::Parser &
err = aCommandElement.GetStatusElement(&statusElementParser);
if (CHIP_NO_ERROR == err)
{
// Response has status element since either there is error in command response or it is empty response
err = statusElementParser.CheckSchemaValidity();
SuccessOrExit(err);
err = statusElementParser.DecodeStatusElement(&generalCode, &protocolId, &protocolCode);
SuccessOrExit(err);
if (mpDelegate != nullptr)
Expand Down
7 changes: 2 additions & 5 deletions src/app/MessageDef/AttributeDataElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_ELEMENT_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_ELEMENT_H

#include "AttributePath.h"
#include "Builder.h"
#include "Parser.h"
Expand Down Expand Up @@ -58,6 +55,7 @@ class Parser : public chip::app::Parser
*/
CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -72,6 +70,7 @@ class Parser : public chip::app::Parser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;
#endif

/**
* @brief Get a TLVReader for the AttributePath. Next() must be called before accessing them.
Expand Down Expand Up @@ -174,5 +173,3 @@ class Builder : public chip::app::Builder

}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_ELEMENT_H
7 changes: 2 additions & 5 deletions src/app/MessageDef/AttributeDataList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_LIST_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_LIST_H

#include "AttributeDataElement.h"
#include "ListBuilder.h"
#include "ListParser.h"
Expand All @@ -41,6 +38,7 @@ namespace AttributeDataList {
class Parser : public ListParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -55,6 +53,7 @@ class Parser : public ListParser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;
#endif
};

class Builder : public ListBuilder
Expand All @@ -81,5 +80,3 @@ class Builder : public ListBuilder

}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_LIST_H
7 changes: 2 additions & 5 deletions src/app/MessageDef/AttributeDataVersionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_VERSION_LIST_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_VERSION_LIST_H

#include "AttributeDataElement.h"
#include "ListBuilder.h"
#include "ListParser.h"
Expand All @@ -42,6 +39,7 @@ namespace AttributeDataVersionList {
class Parser : public ListParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -56,6 +54,7 @@ class Parser : public ListParser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;
#endif

/**
* @brief Check if this element is valid
Expand Down Expand Up @@ -112,5 +111,3 @@ class Builder : public ListBuilder
}; // namespace AttributeDataVersionList
}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_DATA_VERSION_LIST_H
8 changes: 2 additions & 6 deletions src/app/MessageDef/AttributePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_H

#include "Builder.h"
#include "Parser.h"
#include <core/CHIPCore.h>
Expand Down Expand Up @@ -58,6 +55,7 @@ class Parser : public chip::app::Parser
*/
CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -72,7 +70,7 @@ class Parser : public chip::app::Parser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;

#endif
/**
* @brief Get a TLVReader for the NodeId. Next() must be called before accessing them.
*
Expand Down Expand Up @@ -212,5 +210,3 @@ class Builder : public chip::app::Builder

}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_H
7 changes: 2 additions & 5 deletions src/app/MessageDef/AttributePathList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_LIST_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_LIST_H

#include "AttributePath.h"
#include "ListBuilder.h"
#include "ListParser.h"
Expand All @@ -42,6 +39,7 @@ namespace AttributePathList {
class Parser : public ListParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -56,6 +54,7 @@ class Parser : public ListParser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;
#endif
};

class Builder : public ListBuilder
Expand All @@ -81,5 +80,3 @@ class Builder : public ListBuilder
}; // namespace AttributePathList
}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_LIST_H
8 changes: 2 additions & 6 deletions src/app/MessageDef/AttributeStatusElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_ELEMENT_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_ELEMENT_H

#include "AttributePath.h"
#include "Builder.h"
#include "Parser.h"
Expand Down Expand Up @@ -94,7 +91,7 @@ class Parser : public chip::app::Parser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -109,6 +106,7 @@ class Parser : public chip::app::Parser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;
#endif

/**
* @brief Get a TLVReader for the AttributePath. Next() must be called before accessing them.
Expand Down Expand Up @@ -136,5 +134,3 @@ class Parser : public chip::app::Parser

}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_ELEMENT_H
3 changes: 2 additions & 1 deletion src/app/MessageDef/AttributeStatusList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ AttributeStatusList::Builder & AttributeStatusList::Builder::EndOfAttributeStatu
EndOfContainer();
return *this;
}

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
CHIP_ERROR AttributeStatusList::Parser::CheckSchemaValidity() const
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -108,5 +108,6 @@ CHIP_ERROR AttributeStatusList::Parser::CheckSchemaValidity() const

return err;
}
#endif
}; // namespace app
}; // namespace chip
7 changes: 2 additions & 5 deletions src/app/MessageDef/AttributeStatusList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_LIST_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_LIST_H

#include "AttributeStatusElement.h"
#include "ListBuilder.h"
#include "ListParser.h"
Expand Down Expand Up @@ -63,6 +60,7 @@ class Builder : public ListBuilder
class Parser : public ListParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -77,10 +75,9 @@ class Parser : public ListParser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;
#endif
};
}; // namespace AttributeStatusList

}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_LIST_H
5 changes: 0 additions & 5 deletions src/app/MessageDef/Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H

#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
#include <support/CodeUtils.h>
Expand Down Expand Up @@ -100,5 +97,3 @@ class Builder
};
}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H
7 changes: 2 additions & 5 deletions src/app/MessageDef/CommandDataElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_COMMAND_DATA_ELEMENT_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_COMMAND_DATA_ELEMENT_H

#include "Builder.h"
#include "CommandPath.h"

Expand Down Expand Up @@ -59,6 +56,7 @@ class Parser : public chip::app::Parser
*/
CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -73,6 +71,7 @@ class Parser : public chip::app::Parser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;
#endif

/**
* @brief Get a TLVReader for the CommandPath. Next() must be called before accessing them.
Expand Down Expand Up @@ -151,5 +150,3 @@ class Builder : public chip::app::Builder
}; // namespace CommandDataElement
}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_COMMAND_DATA_ELEMENT_H
7 changes: 2 additions & 5 deletions src/app/MessageDef/CommandList.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

#pragma once

#ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_COMMAND_LIST_H
#define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_COMMAND_LIST_H

#include "CommandDataElement.h"
#include "ListBuilder.h"
#include "ListParser.h"
Expand All @@ -42,6 +39,7 @@ namespace CommandList {
class Parser : public ListParser
{
public:
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
/**
* @brief Roughly verify the message is correctly formed
* 1) all mandatory tags are present
Expand All @@ -56,6 +54,7 @@ class Parser : public ListParser
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR CheckSchemaValidity() const;
#endif
};

class Builder : public ListBuilder
Expand All @@ -81,5 +80,3 @@ class Builder : public ListBuilder
}; // namespace CommandList
}; // namespace app
}; // namespace chip

#endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_COMMAND_LIST_H
Loading

0 comments on commit 35620cc

Please sign in to comment.