Skip to content

Commit 2ce3e04

Browse files
BjoernAtBoschDominic Sudy
andauthored
Improvements from wiper hackathon (eclipse-velocitas#4)
* Improvements from wiper hackathon * Update NOTICE-3RD-PARTY-CONTENT.md Co-authored-by: Dominic Sudy <[email protected]>
1 parent d7bb04a commit 2ce3e04

File tree

7 files changed

+105
-16
lines changed

7 files changed

+105
-16
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ jobs:
7373
indicators: true
7474
output: both
7575

76-
- name: Add Coverage PR Comment
77-
uses: marocchino/sticky-pull-request-comment@v2
78-
if: github.event_name == 'pull_request'
79-
with:
80-
recreate: true
81-
path: code-coverage-results.md
76+
#########################################################
77+
# This step was disabled temporarily due to the required
78+
# write access rights of the PRs for external contributors.
79+
#########################################################
80+
#- name: Add Coverage PR Comment
81+
# uses: marocchino/sticky-pull-request-comment@v2
82+
# if: github.event_name == 'pull_request'
83+
# with:
84+
# recreate: true
85+
# path: code-coverage-results.md
8286

8387
- name: Run Linters
8488
uses: pre-commit/[email protected]

NOTICE-3RD-PARTY-CONTENT.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,5 @@
5555
|EnricoMi/publish-unit-test-result-action|v1|Apache License 2.0|
5656
|fusion-engineering/setup-git-credentials|v2|BSD 2-Clause "Simplified" License|
5757
|irongut/CodeCoverageSummary|v1.2.0|MIT License|
58-
|marocchino/sticky-pull-request-comment|v2|MIT License|
5958
|pre-commit/action|v3.0.0|MIT License|
6059
|softprops/action-gh-release|v1|MIT License|

sdk/include/sdk/AsyncResult.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ template <typename TResultType> class AsyncResult {
163163
*/
164164
[[nodiscard]] bool isInAwaitingState() const { return m_awaiting; }
165165

166+
/**
167+
* @brief Map the result to a different type using the provided mapper function.
168+
*
169+
* @tparam TNewType The new type created by the mapper function.
170+
* @param mapper The mapper function to convert TResultType to TNewType.
171+
* @return std::shared_ptr<AsyncResult<TNewType>>
172+
* A new AsyncResult object which emits results of TNewType.
173+
*/
174+
template <typename TNewType>
175+
std::shared_ptr<AsyncResult<TNewType>> map(std::function<TNewType(const TResultType&)> mapper) {
176+
auto mappedResult = std::make_shared<AsyncResult<TNewType>>();
177+
178+
onResult([mappedResult, mapper](auto item) { mappedResult->insertResult(mapper(item)); });
179+
180+
onError([mappedResult](auto status) { mappedResult->insertError(std::move(status)); });
181+
182+
return mappedResult;
183+
}
184+
166185
private:
167186
TResultType m_result;
168187
ResultCallback_t m_callback;

sdk/include/sdk/DataPoint.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class DataPointBoolean : public DataPoint {
134134
public:
135135
using DataPoint::DataPoint;
136136

137+
using value_type = bool;
138+
137139
~DataPointBoolean() override = default;
138140

139141
DataPointBoolean(const DataPointBoolean&) = delete;
@@ -154,6 +156,8 @@ class DataPointBooleanArray : public DataPoint {
154156
public:
155157
using DataPoint::DataPoint;
156158

159+
using value_type = std::vector<bool>;
160+
157161
~DataPointBooleanArray() override = default;
158162

159163
DataPointBooleanArray(const DataPointBooleanArray&) = delete;
@@ -174,6 +178,8 @@ class DataPointInt32 : public DataPoint {
174178
public:
175179
using DataPoint::DataPoint;
176180

181+
using value_type = int32_t;
182+
177183
~DataPointInt32() override = default;
178184

179185
DataPointInt32(const DataPointInt32&) = delete;
@@ -194,6 +200,8 @@ class DataPointInt32Array : public DataPoint {
194200
public:
195201
using DataPoint::DataPoint;
196202

203+
using value_type = std::vector<int32_t>;
204+
197205
~DataPointInt32Array() override = default;
198206

199207
DataPointInt32Array(const DataPointInt32Array&) = delete;
@@ -216,6 +224,8 @@ class DataPointInt64 : public DataPoint {
216224
public:
217225
using DataPoint::DataPoint;
218226

227+
using value_type = int64_t;
228+
219229
~DataPointInt64() override = default;
220230

221231
DataPointInt64(const DataPointInt64&) = delete;
@@ -236,6 +246,8 @@ class DataPointInt64Array : public DataPoint {
236246
public:
237247
using DataPoint::DataPoint;
238248

249+
using value_type = std::vector<int64_t>;
250+
239251
~DataPointInt64Array() override = default;
240252

241253
DataPointInt64Array(const DataPointInt64Array&) = delete;
@@ -258,6 +270,8 @@ class DataPointUint32 : public DataPoint {
258270
public:
259271
using DataPoint::DataPoint;
260272

273+
using value_type = uint32_t;
274+
261275
~DataPointUint32() override = default;
262276

263277
DataPointUint32(const DataPointUint32&) = delete;
@@ -278,6 +292,8 @@ class DataPointUint32Array : public DataPoint {
278292
public:
279293
using DataPoint::DataPoint;
280294

295+
using value_type = std::vector<uint32_t>;
296+
281297
~DataPointUint32Array() override = default;
282298

283299
DataPointUint32Array(const DataPointUint32Array&) = delete;
@@ -300,6 +316,8 @@ class DataPointUint64 : public DataPoint {
300316
public:
301317
using DataPoint::DataPoint;
302318

319+
using value_type = uint64_t;
320+
303321
~DataPointUint64() override = default;
304322

305323
DataPointUint64(const DataPointUint64&) = delete;
@@ -320,6 +338,8 @@ class DataPointUint64Array : public DataPoint {
320338
public:
321339
using DataPoint::DataPoint;
322340

341+
using value_type = std::vector<uint64_t>;
342+
323343
~DataPointUint64Array() override = default;
324344

325345
DataPointUint64Array(const DataPointUint64Array&) = delete;
@@ -342,6 +362,8 @@ class DataPointFloat : public DataPoint {
342362
public:
343363
using DataPoint::DataPoint;
344364

365+
using value_type = float;
366+
345367
~DataPointFloat() override = default;
346368

347369
DataPointFloat(const DataPointFloat&) = delete;
@@ -362,6 +384,8 @@ class DataPointFloatArray : public DataPoint {
362384
public:
363385
using DataPoint::DataPoint;
364386

387+
using value_type = std::vector<float>;
388+
365389
~DataPointFloatArray() override = default;
366390

367391
DataPointFloatArray(const DataPointFloatArray&) = delete;
@@ -384,6 +408,8 @@ class DataPointDouble : public DataPoint {
384408
public:
385409
using DataPoint::DataPoint;
386410

411+
using value_type = double;
412+
387413
~DataPointDouble() override = default;
388414

389415
DataPointDouble(const DataPointDouble&) = delete;
@@ -404,6 +430,8 @@ class DataPointDoubleArray : public DataPoint {
404430
public:
405431
using DataPoint::DataPoint;
406432

433+
using value_type = std::vector<double>;
434+
407435
~DataPointDoubleArray() override = default;
408436

409437
DataPointDoubleArray(const DataPointDoubleArray&) = delete;
@@ -426,6 +454,8 @@ class DataPointString : public DataPoint {
426454
public:
427455
using DataPoint::DataPoint;
428456

457+
using value_type = std::string;
458+
429459
~DataPointString() override = default;
430460

431461
DataPointString(const DataPointString&) = delete;
@@ -446,6 +476,8 @@ class DataPointStringArray : public DataPoint {
446476
public:
447477
using DataPoint::DataPoint;
448478

479+
using value_type = std::vector<std::string>;
480+
449481
~DataPointStringArray() override = default;
450482

451483
DataPointStringArray(const DataPointStringArray&) = delete;

sdk/include/sdk/DataPointsResult.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#ifndef VEHICLE_APP_SDK_DATAPOINTSRESULT_H
1818
#define VEHICLE_APP_SDK_DATAPOINTSRESULT_H
1919

20+
#include "sdk/Exceptions.h"
21+
22+
#include <fmt/core.h>
23+
2024
#include <map>
2125
#include <string>
2226

@@ -49,17 +53,22 @@ class DataPointsResult final {
4953
[[nodiscard]] std::shared_ptr<TDataPointType> get(const TDataPointType& dataPoint) const {
5054
static_assert(std::is_base_of_v<DataPoint, TDataPointType>);
5155

56+
if (m_dataPointsMap.find(dataPoint.getPath()) == m_dataPointsMap.end()) {
57+
throw InvalidValueException(
58+
fmt::format("{} is not contained in result!", dataPoint.getPath()));
59+
}
60+
5261
auto result = m_dataPointsMap.at(dataPoint.getPath());
5362
return std::dynamic_pointer_cast<TDataPointType>(result);
5463
}
5564

56-
/**
57-
* @brief Check if the result is empty.
58-
*
59-
* @return true Result is empty.
60-
* @return false Result is not empty.
61-
*/
62-
bool empty() { return m_dataPointsMap.empty(); }
65+
/**
66+
* @brief Check if the result is empty.
67+
*
68+
* @return true Result is empty.
69+
* @return false Result is not empty.
70+
*/
71+
bool empty() { return m_dataPointsMap.empty(); }
6372

6473
private:
6574
DataPointMap_t m_dataPointsMap;

sdk/include/sdk/VehicleApp.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,27 @@ class VehicleApp {
9797
* @brief Get values for all provided data points from the data broker.
9898
*
9999
* @param dataPoints Vector of data points to obtain values for.
100-
* @return AsyncResultPtr_t<DataPointsResult> The result that contains data point results for
101-
* all requested data points.
100+
* @return AsyncResultPtr_t<DataPointsResult> The result containing the data point
101+
* results for all requested data points.
102102
*/
103103
AsyncResultPtr_t<DataPointsResult>
104104
getDataPoints(const std::vector<std::reference_wrapper<DataPoint>>& dataPoints);
105105

106+
/**
107+
* @brief Get the value a certain data point from the data broker.
108+
*
109+
* @param dataPoint The data point to obtain values for.
110+
* @return AsyncResultPtr_t<typename TDataPoint::value_type> The result containing
111+
* the data point result of the requested data point.
112+
*/
113+
template <typename TDataPoint>
114+
AsyncResultPtr_t<typename TDataPoint::value_type> getDataPoint(const TDataPoint& dataPoint) const {
115+
return getDataPoint_internal(dataPoint)->template map<typename TDataPoint::value_type>(
116+
[&dataPoint](const DataPointsResult& dataPointsResult) {
117+
return dataPointsResult.get<TDataPoint>(dataPoint)->value();
118+
});
119+
}
120+
106121
/**
107122
* @brief Subscribes to the query string for data points.
108123
*
@@ -126,6 +141,9 @@ class VehicleApp {
126141
std::shared_ptr<IPubSubClient> getPubSubClient();
127142

128143
private:
144+
[[nodiscard]] AsyncResultPtr_t<DataPointsResult>
145+
getDataPoint_internal(const DataPoint& dataPoint) const;
146+
129147
std::shared_ptr<IVehicleDataBrokerClient> m_vdbClient;
130148
std::shared_ptr<IPubSubClient> m_pubSubClient;
131149
};

sdk/src/sdk/VehicleApp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ VehicleApp::getDataPoints(const std::vector<std::reference_wrapper<DataPoint>>&
7070
return m_vdbClient->getDatapoints(dataPointPaths);
7171
}
7272

73+
AsyncResultPtr_t<DataPointsResult>
74+
VehicleApp::getDataPoint_internal(const DataPoint& dataPoint) const {
75+
std::vector<std::string> dataPointPaths;
76+
dataPointPaths.reserve(1);
77+
dataPointPaths.emplace_back(dataPoint.getPath());
78+
return m_vdbClient->getDatapoints(dataPointPaths);
79+
}
80+
7381
AsyncSubscriptionPtr_t<DataPointsResult> VehicleApp::subscribeDataPoints(const std::string& query) {
7482
return m_vdbClient->subscribe(query);
7583
}

0 commit comments

Comments
 (0)