Skip to content

Commit eeb716e

Browse files
Adjust current state response according to concept
1 parent 68e9490 commit eeb716e

File tree

5 files changed

+95
-27
lines changed

5 files changed

+95
-27
lines changed

src/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if(SUA_BUILD_TESTS)
1818
)
1919
endif()
2020

21-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/version.h @ONLY)
21+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/version.cpp @ONLY)
2222

2323
include_directories(
2424
${CMAKE_SOURCE_DIR}/src
@@ -35,11 +35,11 @@ include_directories(
3535
${CMAKE_BINARY_DIR}/3rdparty/curl/lib
3636
${CMAKE_BINARY_DIR}/glib
3737
${CMAKE_BINARY_DIR}/glib/glib
38-
${CMAKE_BINARY_DIR}/src/include
3938
)
4039

4140
file(GLOB_RECURSE SRCS *.cpp *.h)
4241
list(FILTER SRCS EXCLUDE REGEX "main.cpp" )
42+
list(APPEND SRCS ${CMAKE_CURRENT_BINARY_DIR}/version.cpp)
4343

4444
add_library(sua SHARED ${SRCS})
4545
add_executable(${PROJECT_NAME} ${SRCS} main.cpp)

src/Mqtt/MqttMessagingProtocolJSON.cpp

+33-12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "spdlog/fmt/fmt.h"
2121
#include "nlohmann/json.hpp"
22+
#include "version.h"
2223

2324
#include <regex>
2425
#include <iostream>
@@ -224,21 +225,31 @@ namespace sua {
224225
"payload": {
225226
"softwareNodes": [
226227
{
227-
"id": "os-image",
228+
"id": "self-update-agent",
229+
"version": "build-{},
230+
"name": "OTA NG Self Update Agent",
231+
"type": "APPLICATION"
232+
},
233+
{
234+
"id": "self-update:leda-deviceimage",
228235
"version": "{}",
229-
"name": "System Image",
230-
"type": "IMAGE",
231-
"parameters": []
236+
"name": "Official Leda device image",
237+
"type": "IMAGE"
232238
}
233239
],
234240
"hardwareNodes": [],
235-
"associations": []
241+
"associations": [
242+
{
243+
"sourceId": "self-update-agent",
244+
"targetId": "self-update:leda-deviceimage"
245+
}
246+
]
236247
}
237248
}
238249
)");
239250
// clang-format on
240251

241-
return fmt::format(tpl, epochTime(), version);
252+
return fmt::format(tpl, epochTime(), SUA_BUILD_NUMBER, version);
242253
}
243254

244255
std::string MqttMessagingProtocolJSON::writeSystemVersionWithActivityId(const std::string & version, const std::string & activityId)
@@ -251,21 +262,31 @@ namespace sua {
251262
"payload": {
252263
"softwareNodes": [
253264
{
254-
"id": "os-image",
265+
"id": "self-update-agent",
266+
"version": "build-{},
267+
"name": "OTA NG Self Update Agent",
268+
"type": "APPLICATION"
269+
},
270+
{
271+
"id": "self-update:leda-deviceimage",
255272
"version": "{}",
256-
"name": "System Image",
257-
"type": "IMAGE",
258-
"parameters": []
273+
"name": "Official Leda device image",
274+
"type": "IMAGE"
259275
}
260276
],
261277
"hardwareNodes": [],
262-
"associations": []
278+
"associations": [
279+
{
280+
"sourceId": "self-update-agent",
281+
"targetId": "self-update:leda-deviceimage"
282+
}
283+
]
263284
}
264285
}
265286
)");
266287
// clang-format on
267288

268-
return fmt::format(tpl, activityId, epochTime(), version);
289+
return fmt::format(tpl, activityId, epochTime(), SUA_BUILD_NUMBER, version);
269290
}
270291

271292
} // namespace sua

src/version.h.in renamed to src/version.cpp.in

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
1616

17-
#ifndef SDV_SUA_VERSION_H
18-
#define SDV_SUA_VERSION_H
17+
#include "version.h"
1918

2019
const char * SUA_COMMIT_HASH = "@SUA_COMMIT_HASH@";
2120
const char * SUA_BUILD_NUMBER = "@SUA_BUILD_NUMBER@";
2221

23-
#endif

src/version.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2022 Contributors to the Eclipse Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
17+
#ifndef SDV_SUA_VERSION_H
18+
#define SDV_SUA_VERSION_H
19+
20+
extern const char * SUA_COMMIT_HASH;
21+
extern const char * SUA_BUILD_NUMBER;
22+
23+
#endif

utest/TestMqttMessagingProtocolJSON.cpp

+36-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "Context.h"
55
#include "Utils.h"
66

7+
#include "version.h"
8+
79
namespace {
810

911
class ProtocolJSON : public sua::MqttMessagingProtocolJSON {
@@ -84,6 +86,8 @@ namespace {
8486

8587
TEST_F(TestMessagingProtocolJSON, createMessage_systemVersionWithoutActivityId)
8688
{
89+
SUA_BUILD_NUMBER = "42";
90+
8791
ctx.desiredState.activityId = "";
8892
const std::string result = ProtocolJSON().createMessage(ctx, "systemVersion");
8993

@@ -94,15 +98,25 @@ namespace {
9498
"payload": {
9599
"softwareNodes": [
96100
{
97-
"id": "os-image",
101+
"id": "self-update-agent",
102+
"version": "build-42,
103+
"name": "OTA NG Self Update Agent",
104+
"type": "APPLICATION"
105+
},
106+
{
107+
"id": "self-update:leda-deviceimage",
98108
"version": "1.0",
99-
"name": "System Image",
100-
"type": "IMAGE",
101-
"parameters": []
109+
"name": "Official Leda device image",
110+
"type": "IMAGE"
102111
}
103112
],
104113
"hardwareNodes": [],
105-
"associations": []
114+
"associations": [
115+
{
116+
"sourceId": "self-update-agent",
117+
"targetId": "self-update:leda-deviceimage"
118+
}
119+
]
106120
}
107121
}
108122
)";
@@ -113,6 +127,8 @@ namespace {
113127

114128
TEST_F(TestMessagingProtocolJSON, createMessage_systemVersionWithActivityId)
115129
{
130+
SUA_BUILD_NUMBER = "42";
131+
116132
const std::string result = ProtocolJSON().createMessage(ctx, "systemVersion");
117133

118134
// clang-format off
@@ -123,15 +139,25 @@ namespace {
123139
"payload": {
124140
"softwareNodes": [
125141
{
126-
"id": "os-image",
142+
"id": "self-update-agent",
143+
"version": "build-42,
144+
"name": "OTA NG Self Update Agent",
145+
"type": "APPLICATION"
146+
},
147+
{
148+
"id": "self-update:leda-deviceimage",
127149
"version": "1.0",
128-
"name": "System Image",
129-
"type": "IMAGE",
130-
"parameters": []
150+
"name": "Official Leda device image",
151+
"type": "IMAGE"
131152
}
132153
],
133154
"hardwareNodes": [],
134-
"associations": []
155+
"associations": [
156+
{
157+
"sourceId": "self-update-agent",
158+
"targetId": "self-update:leda-deviceimage"
159+
}
160+
]
135161
}
136162
}
137163
)";

0 commit comments

Comments
 (0)