Skip to content

Commit

Permalink
Create a separate 'constants' source set in src/app (#32228)
Browse files Browse the repository at this point in the history
* Create constants file

* Restyle

* Place everything into a `Revision` namespace to avoid name collision with a Tags enum

* Rename

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
andy31415 and andreilitvin authored Feb 23, 2024
1 parent ef8ee32 commit a6fd6ce
Show file tree
Hide file tree
Showing 24 changed files with 65 additions and 108 deletions.
23 changes: 13 additions & 10 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ source_set("app_config") {
deps = [ ":app_buildconfig" ]
}

source_set("revision_info") {
sources = [
"DataModelRevision.h",
"InteractionModelRevision.h",
"SpecificationVersion.h",
]
}

source_set("paths") {
sources = [
"AttributePathParams.h",
Expand Down Expand Up @@ -130,6 +122,17 @@ config("config-controller-dynamic-server") {
]
}

source_set("constants") {
sources = [
"InteractionModelTimeout.h",
"SpecificationDefinedRevisions.h",
]
public_deps = [
"${chip_root}/src/lib/core",
"${chip_root}/src/system",
]
}

# interaction-model is a static-library because it currently requires global functions (app/util/...) that are stubbed in different test files that depend on the app static_library
# which in tern depens on the interaction-model.
# Using source_set prevents the unit test to build correctly.
Expand All @@ -149,7 +152,6 @@ static_library("interaction-model") {
"InteractionModelEngine.cpp",
"InteractionModelEngine.h",
"InteractionModelHelper.h",
"InteractionModelTimeout.h",
"OperationalSessionSetup.cpp",
"OperationalSessionSetup.h",
"OperationalSessionSetupPool.h",
Expand Down Expand Up @@ -181,6 +183,7 @@ static_library("interaction-model") {

public_deps = [
":app_config",
":constants",
":paths",
":subscription-manager",
"${chip_root}/src/app/MessageDef",
Expand Down Expand Up @@ -276,9 +279,9 @@ static_library("app") {

public_deps = [
":app_config",
":constants",
":global-attributes",
":interaction-model",
":revision_info",
"${chip_root}/src/app/data-model",
"${chip_root}/src/app/icd/server:icd-server-config",
"${chip_root}/src/lib/address_resolve",
Expand Down
31 changes: 0 additions & 31 deletions src/app/DataModelRevision.h

This file was deleted.

1 change: 0 additions & 1 deletion src/app/InteractionModelTimeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#pragma once

#include <system/SystemClock.h>
#include <transport/Session.h>

namespace chip {
namespace app {
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ source_set("MessageDef") {

deps = [
"${chip_root}/src/app:app_config",
"${chip_root}/src/app:constants",
"${chip_root}/src/app:paths",
"${chip_root}/src/app:revision_info",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
"${chip_root}/src/protocols/interaction_model",
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/InvokeRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ CHIP_ERROR InvokeRequestMessage::Parser::PrettyPrint() const
PRETTY_PRINT_DECDEPTH();
}
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/InvokeResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CHIP_ERROR InvokeResponseMessage::Parser::PrettyPrint() const
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
3 changes: 1 addition & 2 deletions src/app/MessageDef/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ namespace chip {
namespace app {
CHIP_ERROR MessageBuilder::EncodeInteractionModelRevision()
{
return mpWriter->Put(TLV::ContextTag(kInteractionModelRevisionTag),
static_cast<InteractionModelRevision>(CHIP_DEVICE_INTERACTION_MODEL_REVISION));
return mpWriter->Put(TLV::ContextTag(Revision::kInteractionModelRevisionTag), Revision::kInteractionModelRevision);
}
} // namespace app
} // namespace chip
2 changes: 1 addition & 1 deletion src/app/MessageDef/MessageBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#pragma once

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

namespace chip {
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/MessageDefHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "MessageDefHelper.h"
#include <algorithm>
#include <app/AppConfig.h>
#include <app/InteractionModelRevision.h>
#include <app/SpecificationDefinedRevisions.h>
#include <app/util/basic-types.h>
#include <inttypes.h>
#include <lib/support/logging/CHIPLogging.h>
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/MessageParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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

namespace chip {
namespace app {
Expand Down Expand Up @@ -52,7 +52,7 @@ CHIP_ERROR MessageParser::CheckInteractionModelRevision(TLV::TLVReader & aReader

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

} // namespace app
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/MessageParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "StructParser.h"
#include <app/AppConfig.h>
#include <app/InteractionModelRevision.h>
#include <app/SpecificationDefinedRevisions.h>
#include <app/util/basic-types.h>

namespace chip {
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/ReadRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ CHIP_ERROR ReadRequestMessage::Parser::PrettyPrint() const
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/ReportDataMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ CHIP_ERROR ReportDataMessage::Parser::PrettyPrint() const
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/StatusResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CHIP_ERROR StatusResponseMessage::Parser::PrettyPrint() const
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/SubscribeRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ CHIP_ERROR SubscribeRequestMessage::Parser::PrettyPrint() const
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/SubscribeResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CHIP_ERROR SubscribeResponseMessage::Parser::PrettyPrint() const
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/TimedRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CHIP_ERROR TimedRequestMessage::Parser::PrettyPrint() const
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/WriteRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ CHIP_ERROR WriteRequestMessage::Parser::PrettyPrint() const
}
#endif // CHIP_DETAIL_LOGGING
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/WriteResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ CHIP_ERROR WriteResponseMessage::Parser::PrettyPrint() const
ReturnErrorOnFailure(writeResponses.PrettyPrint());
PRETTY_PRINT_DECDEPTH();
break;
case kInteractionModelRevisionTag:
case Revision::kInteractionModelRevisionTag:
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,37 @@
#include <inttypes.h>
#include <stddef.h>

#include <lib/core/DataModelTypes.h>

namespace chip {
namespace Revision {

/**
* CHIP_DEVICE_INTERACTION_MODEL_REVISION
*
* A monothonic number identifying the interaction model revision.
*
* See section 8.1.1. "Revision History" in the "Interaction Model
* Specification" chapter of the core Matter specification.
*/
#ifndef CHIP_DEVICE_INTERACTION_MODEL_REVISION
#define CHIP_DEVICE_INTERACTION_MODEL_REVISION 11
#endif
inline constexpr InteractionModelRevision kInteractionModelRevision = 11;
inline constexpr uint8_t kInteractionModelRevisionTag = 0xFF;

/**
* A monotonic number identifying the revision number of the Data Model against
* which the Node is certified.
*
* See section 7.1.1. "Revision History" in the "Data Model Specification"
* chapter of the core Matter specification.
*/
inline constexpr uint16_t kDataModelRevision = 17;

/*
* A number identifying the specification version against which the
* Node is certified.
*
* See section 11.1.5.22. "SpecificationVersion Attribute" in "Service and
* Device Management" chapter of the core Matter specification.
*/
inline constexpr uint32_t kSpecificationVersion = 0x01030000;

inline constexpr uint8_t kInteractionModelRevisionTag = 0xFF;
} // namespace Revision
} // namespace chip
31 changes: 0 additions & 31 deletions src/app/SpecificationVersion.h

This file was deleted.

7 changes: 3 additions & 4 deletions src/app/clusters/basic-information/basic-information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app/DataModelRevision.h>
#include <app/EventLogging.h>
#include <app/InteractionModelEngine.h>
#include <app/SpecificationVersion.h>
#include <app/SpecificationDefinedRevisions.h>
#include <app/util/attribute-storage.h>
#include <lib/core/CHIPConfig.h>
#include <platform/CHIPDeviceLayer.h>
Expand Down Expand Up @@ -314,7 +313,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib

CHIP_ERROR BasicAttrAccess::ReadDataModelRevision(AttributeValueEncoder & aEncoder)
{
uint16_t revision = CHIP_DEVICE_DATA_MODEL_REVISION;
uint16_t revision = Revision::kDataModelRevision;
return aEncoder.Encode(revision);
}

Expand Down Expand Up @@ -399,7 +398,7 @@ CHIP_ERROR BasicAttrAccess::ReadProductAppearance(AttributeValueEncoder & aEncod

CHIP_ERROR BasicAttrAccess::ReadSpecificationVersion(AttributeValueEncoder & aEncoder)
{
uint32_t specification_version = CHIP_DEVICE_SPECIFICATION_VERSION;
uint32_t specification_version = Revision::kSpecificationVersion;
return aEncoder.Encode(specification_version);
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocols/secure_channel/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ static_library("secure_channel") {
"${chip_root}/src/transport",
]

deps = [ "${chip_root}/src/app:revision_info" ]
deps = [ "${chip_root}/src/app:constants" ]
}
10 changes: 4 additions & 6 deletions src/protocols/secure_channel/PairingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

#include <protocols/secure_channel/PairingSession.h>

#include <app/DataModelRevision.h>
#include <app/InteractionModelRevision.h>
#include <app/SpecificationVersion.h>
#include <app/SpecificationDefinedRevisions.h>
#include <lib/core/CHIPConfig.h>
#include <lib/core/TLVTypes.h>
#include <lib/support/SafeInt.h>
Expand Down Expand Up @@ -112,13 +110,13 @@ CHIP_ERROR PairingSession::EncodeSessionParameters(TLV::Tag tag, const Optional<
ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(SessionParameters::Tag::kSessionActiveThreshold),
mrpLocalConfig.mActiveThresholdTime.count()));

uint16_t dataModel = CHIP_DEVICE_DATA_MODEL_REVISION;
uint16_t dataModel = Revision::kDataModelRevision;
ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(SessionParameters::Tag::kDataModelRevision), dataModel));

uint16_t interactionModel = CHIP_DEVICE_INTERACTION_MODEL_REVISION;
uint16_t interactionModel = Revision::kInteractionModelRevision;
ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(SessionParameters::Tag::kInteractionModelRevision), interactionModel));

uint32_t specVersion = CHIP_DEVICE_SPECIFICATION_VERSION;
uint32_t specVersion = Revision::kSpecificationVersion;
ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(SessionParameters::Tag::kSpecificationVersion), specVersion));

uint16_t maxPathsPerInvoke = CHIP_CONFIG_MAX_PATHS_PER_INVOKE;
Expand Down

0 comments on commit a6fd6ce

Please sign in to comment.