Skip to content

Commit a6fd6ce

Browse files
Create a separate 'constants' source set in src/app (project-chip#32228)
* Create constants file * Restyle * Place everything into a `Revision` namespace to avoid name collision with a Tags enum * Rename --------- Co-authored-by: Andrei Litvin <andreilitvin@google.com>
1 parent ef8ee32 commit a6fd6ce

24 files changed

+65
-108
lines changed

src/app/BUILD.gn

+13-10
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,6 @@ source_set("app_config") {
7676
deps = [ ":app_buildconfig" ]
7777
}
7878

79-
source_set("revision_info") {
80-
sources = [
81-
"DataModelRevision.h",
82-
"InteractionModelRevision.h",
83-
"SpecificationVersion.h",
84-
]
85-
}
86-
8779
source_set("paths") {
8880
sources = [
8981
"AttributePathParams.h",
@@ -130,6 +122,17 @@ config("config-controller-dynamic-server") {
130122
]
131123
}
132124

125+
source_set("constants") {
126+
sources = [
127+
"InteractionModelTimeout.h",
128+
"SpecificationDefinedRevisions.h",
129+
]
130+
public_deps = [
131+
"${chip_root}/src/lib/core",
132+
"${chip_root}/src/system",
133+
]
134+
}
135+
133136
# 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
134137
# which in tern depens on the interaction-model.
135138
# Using source_set prevents the unit test to build correctly.
@@ -149,7 +152,6 @@ static_library("interaction-model") {
149152
"InteractionModelEngine.cpp",
150153
"InteractionModelEngine.h",
151154
"InteractionModelHelper.h",
152-
"InteractionModelTimeout.h",
153155
"OperationalSessionSetup.cpp",
154156
"OperationalSessionSetup.h",
155157
"OperationalSessionSetupPool.h",
@@ -181,6 +183,7 @@ static_library("interaction-model") {
181183

182184
public_deps = [
183185
":app_config",
186+
":constants",
184187
":paths",
185188
":subscription-manager",
186189
"${chip_root}/src/app/MessageDef",
@@ -276,9 +279,9 @@ static_library("app") {
276279

277280
public_deps = [
278281
":app_config",
282+
":constants",
279283
":global-attributes",
280284
":interaction-model",
281-
":revision_info",
282285
"${chip_root}/src/app/data-model",
283286
"${chip_root}/src/app/icd/server:icd-server-config",
284287
"${chip_root}/src/lib/address_resolve",

src/app/DataModelRevision.h

-31
This file was deleted.

src/app/InteractionModelTimeout.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#pragma once
1919

2020
#include <system/SystemClock.h>
21-
#include <transport/Session.h>
2221

2322
namespace chip {
2423
namespace app {

src/app/MessageDef/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ source_set("MessageDef") {
113113

114114
deps = [
115115
"${chip_root}/src/app:app_config",
116+
"${chip_root}/src/app:constants",
116117
"${chip_root}/src/app:paths",
117-
"${chip_root}/src/app:revision_info",
118118
"${chip_root}/src/lib/core",
119119
"${chip_root}/src/lib/support",
120120
"${chip_root}/src/protocols/interaction_model",

src/app/MessageDef/InvokeRequestMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ CHIP_ERROR InvokeRequestMessage::Parser::PrettyPrint() const
7474
PRETTY_PRINT_DECDEPTH();
7575
}
7676
break;
77-
case kInteractionModelRevisionTag:
77+
case Revision::kInteractionModelRevisionTag:
7878
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
7979
break;
8080
default:

src/app/MessageDef/InvokeResponseMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ CHIP_ERROR InvokeResponseMessage::Parser::PrettyPrint() const
7373
}
7474
#endif // CHIP_DETAIL_LOGGING
7575
break;
76-
case kInteractionModelRevisionTag:
76+
case Revision::kInteractionModelRevisionTag:
7777
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
7878
break;
7979
default:

src/app/MessageDef/MessageBuilder.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ namespace chip {
2424
namespace app {
2525
CHIP_ERROR MessageBuilder::EncodeInteractionModelRevision()
2626
{
27-
return mpWriter->Put(TLV::ContextTag(kInteractionModelRevisionTag),
28-
static_cast<InteractionModelRevision>(CHIP_DEVICE_INTERACTION_MODEL_REVISION));
27+
return mpWriter->Put(TLV::ContextTag(Revision::kInteractionModelRevisionTag), Revision::kInteractionModelRevision);
2928
}
3029
} // namespace app
3130
} // namespace chip

src/app/MessageDef/MessageBuilder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#pragma once
1919

2020
#include "StructBuilder.h"
21-
#include <app/InteractionModelRevision.h>
21+
#include <app/SpecificationDefinedRevisions.h>
2222
#include <app/util/basic-types.h>
2323

2424
namespace chip {

src/app/MessageDef/MessageDefHelper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "MessageDefHelper.h"
2525
#include <algorithm>
2626
#include <app/AppConfig.h>
27-
#include <app/InteractionModelRevision.h>
27+
#include <app/SpecificationDefinedRevisions.h>
2828
#include <app/util/basic-types.h>
2929
#include <inttypes.h>
3030
#include <lib/support/logging/CHIPLogging.h>

src/app/MessageDef/MessageParser.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "MessageParser.h"
1818
#include "MessageDefHelper.h"
19-
#include <app/InteractionModelRevision.h>
19+
#include <app/SpecificationDefinedRevisions.h>
2020

2121
namespace chip {
2222
namespace app {
@@ -52,7 +52,7 @@ CHIP_ERROR MessageParser::CheckInteractionModelRevision(TLV::TLVReader & aReader
5252

5353
CHIP_ERROR MessageParser::GetInteractionModelRevision(InteractionModelRevision * const apInteractionModelRevision) const
5454
{
55-
return GetUnsignedInteger(kInteractionModelRevisionTag, apInteractionModelRevision);
55+
return GetUnsignedInteger(Revision::kInteractionModelRevisionTag, apInteractionModelRevision);
5656
}
5757

5858
} // namespace app

src/app/MessageDef/MessageParser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "StructParser.h"
2222
#include <app/AppConfig.h>
23-
#include <app/InteractionModelRevision.h>
23+
#include <app/SpecificationDefinedRevisions.h>
2424
#include <app/util/basic-types.h>
2525

2626
namespace chip {

src/app/MessageDef/ReadRequestMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ CHIP_ERROR ReadRequestMessage::Parser::PrettyPrint() const
9191
}
9292
#endif // CHIP_DETAIL_LOGGING
9393
break;
94-
case kInteractionModelRevisionTag:
94+
case Revision::kInteractionModelRevisionTag:
9595
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
9696
break;
9797
default:

src/app/MessageDef/ReportDataMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ CHIP_ERROR ReportDataMessage::Parser::PrettyPrint() const
112112
}
113113
#endif // CHIP_DETAIL_LOGGING
114114
break;
115-
case kInteractionModelRevisionTag:
115+
case Revision::kInteractionModelRevisionTag:
116116
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
117117
break;
118118
default:

src/app/MessageDef/StatusResponseMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CHIP_ERROR StatusResponseMessage::Parser::PrettyPrint() const
5252
}
5353
#endif // CHIP_DETAIL_LOGGING
5454
break;
55-
case kInteractionModelRevisionTag:
55+
case Revision::kInteractionModelRevisionTag:
5656
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
5757
break;
5858
default:

src/app/MessageDef/SubscribeRequestMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ CHIP_ERROR SubscribeRequestMessage::Parser::PrettyPrint() const
115115
}
116116
#endif // CHIP_DETAIL_LOGGING
117117
break;
118-
case kInteractionModelRevisionTag:
118+
case Revision::kInteractionModelRevisionTag:
119119
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
120120
break;
121121
default:

src/app/MessageDef/SubscribeResponseMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CHIP_ERROR SubscribeResponseMessage::Parser::PrettyPrint() const
5959
}
6060
#endif // CHIP_DETAIL_LOGGING
6161
break;
62-
case kInteractionModelRevisionTag:
62+
case Revision::kInteractionModelRevisionTag:
6363
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
6464
break;
6565
default:

src/app/MessageDef/TimedRequestMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ CHIP_ERROR TimedRequestMessage::Parser::PrettyPrint() const
4949
}
5050
#endif // CHIP_DETAIL_LOGGING
5151
break;
52-
case kInteractionModelRevisionTag:
52+
case Revision::kInteractionModelRevisionTag:
5353
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
5454
break;
5555
default:

src/app/MessageDef/WriteRequestMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CHIP_ERROR WriteRequestMessage::Parser::PrettyPrint() const
8888
}
8989
#endif // CHIP_DETAIL_LOGGING
9090
break;
91-
case kInteractionModelRevisionTag:
91+
case Revision::kInteractionModelRevisionTag:
9292
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
9393
break;
9494
default:

src/app/MessageDef/WriteResponseMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ CHIP_ERROR WriteResponseMessage::Parser::PrettyPrint() const
5454
ReturnErrorOnFailure(writeResponses.PrettyPrint());
5555
PRETTY_PRINT_DECDEPTH();
5656
break;
57-
case kInteractionModelRevisionTag:
57+
case Revision::kInteractionModelRevisionTag:
5858
ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
5959
break;
6060
default:

src/app/InteractionModelRevision.h src/app/SpecificationDefinedRevisions.h

+27-6
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,37 @@
2020
#include <inttypes.h>
2121
#include <stddef.h>
2222

23+
#include <lib/core/DataModelTypes.h>
24+
25+
namespace chip {
26+
namespace Revision {
27+
2328
/**
24-
* CHIP_DEVICE_INTERACTION_MODEL_REVISION
25-
*
2629
* A monothonic number identifying the interaction model revision.
2730
*
2831
* See section 8.1.1. "Revision History" in the "Interaction Model
2932
* Specification" chapter of the core Matter specification.
3033
*/
31-
#ifndef CHIP_DEVICE_INTERACTION_MODEL_REVISION
32-
#define CHIP_DEVICE_INTERACTION_MODEL_REVISION 11
33-
#endif
34+
inline constexpr InteractionModelRevision kInteractionModelRevision = 11;
35+
inline constexpr uint8_t kInteractionModelRevisionTag = 0xFF;
36+
37+
/**
38+
* A monotonic number identifying the revision number of the Data Model against
39+
* which the Node is certified.
40+
*
41+
* See section 7.1.1. "Revision History" in the "Data Model Specification"
42+
* chapter of the core Matter specification.
43+
*/
44+
inline constexpr uint16_t kDataModelRevision = 17;
45+
46+
/*
47+
* A number identifying the specification version against which the
48+
* Node is certified.
49+
*
50+
* See section 11.1.5.22. "SpecificationVersion Attribute" in "Service and
51+
* Device Management" chapter of the core Matter specification.
52+
*/
53+
inline constexpr uint32_t kSpecificationVersion = 0x01030000;
3454

35-
inline constexpr uint8_t kInteractionModelRevisionTag = 0xFF;
55+
} // namespace Revision
56+
} // namespace chip

src/app/SpecificationVersion.h

-31
This file was deleted.

src/app/clusters/basic-information/basic-information.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020

2121
#include <app-common/zap-generated/attributes/Accessors.h>
2222
#include <app-common/zap-generated/cluster-objects.h>
23-
#include <app/DataModelRevision.h>
2423
#include <app/EventLogging.h>
2524
#include <app/InteractionModelEngine.h>
26-
#include <app/SpecificationVersion.h>
25+
#include <app/SpecificationDefinedRevisions.h>
2726
#include <app/util/attribute-storage.h>
2827
#include <lib/core/CHIPConfig.h>
2928
#include <platform/CHIPDeviceLayer.h>
@@ -314,7 +313,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib
314313

315314
CHIP_ERROR BasicAttrAccess::ReadDataModelRevision(AttributeValueEncoder & aEncoder)
316315
{
317-
uint16_t revision = CHIP_DEVICE_DATA_MODEL_REVISION;
316+
uint16_t revision = Revision::kDataModelRevision;
318317
return aEncoder.Encode(revision);
319318
}
320319

@@ -399,7 +398,7 @@ CHIP_ERROR BasicAttrAccess::ReadProductAppearance(AttributeValueEncoder & aEncod
399398

400399
CHIP_ERROR BasicAttrAccess::ReadSpecificationVersion(AttributeValueEncoder & aEncoder)
401400
{
402-
uint32_t specification_version = CHIP_DEVICE_SPECIFICATION_VERSION;
401+
uint32_t specification_version = Revision::kSpecificationVersion;
403402
return aEncoder.Encode(specification_version);
404403
}
405404

src/protocols/secure_channel/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ static_library("secure_channel") {
8888
"${chip_root}/src/transport",
8989
]
9090

91-
deps = [ "${chip_root}/src/app:revision_info" ]
91+
deps = [ "${chip_root}/src/app:constants" ]
9292
}

src/protocols/secure_channel/PairingSession.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
#include <protocols/secure_channel/PairingSession.h>
2020

21-
#include <app/DataModelRevision.h>
22-
#include <app/InteractionModelRevision.h>
23-
#include <app/SpecificationVersion.h>
21+
#include <app/SpecificationDefinedRevisions.h>
2422
#include <lib/core/CHIPConfig.h>
2523
#include <lib/core/TLVTypes.h>
2624
#include <lib/support/SafeInt.h>
@@ -112,13 +110,13 @@ CHIP_ERROR PairingSession::EncodeSessionParameters(TLV::Tag tag, const Optional<
112110
ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(SessionParameters::Tag::kSessionActiveThreshold),
113111
mrpLocalConfig.mActiveThresholdTime.count()));
114112

115-
uint16_t dataModel = CHIP_DEVICE_DATA_MODEL_REVISION;
113+
uint16_t dataModel = Revision::kDataModelRevision;
116114
ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(SessionParameters::Tag::kDataModelRevision), dataModel));
117115

118-
uint16_t interactionModel = CHIP_DEVICE_INTERACTION_MODEL_REVISION;
116+
uint16_t interactionModel = Revision::kInteractionModelRevision;
119117
ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(SessionParameters::Tag::kInteractionModelRevision), interactionModel));
120118

121-
uint32_t specVersion = CHIP_DEVICE_SPECIFICATION_VERSION;
119+
uint32_t specVersion = Revision::kSpecificationVersion;
122120
ReturnErrorOnFailure(tlvWriter.Put(TLV::ContextTag(SessionParameters::Tag::kSpecificationVersion), specVersion));
123121

124122
uint16_t maxPathsPerInvoke = CHIP_CONFIG_MAX_PATHS_PER_INVOKE;

0 commit comments

Comments
 (0)