Skip to content

Commit facdb55

Browse files
iceoryx data transport
1 parent edb2448 commit facdb55

File tree

11 files changed

+160
-12
lines changed

11 files changed

+160
-12
lines changed

MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ git_override(
102102
remote = "https://github.com/eclipse-score/score-crates.git",
103103
)
104104

105+
bazel_dep(name = "iceoryx2", version = "0.7.0")
106+
local_path_override(
107+
module_name = "iceoryx2",
108+
path = "/home/piotr/score/iceoryx2",
109+
)
110+
105111
bazel_dep(name = "boost.program_options", version = "1.87.0")
106112
bazel_dep(name = "download_utils", version = "1.0.1")
107113

score/mw/com/impl/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ cc_library(
173173
":skeleton_field",
174174
"//score/mw/com/impl/methods:skeleton_method",
175175
"//score/mw/com/impl/plumbing:event",
176+
"@iceoryx2//:iceoryx2-cxx-static",
176177
],
177178
)
178179

@@ -272,6 +273,7 @@ cc_library(
272273
"//score/mw/com/impl/plumbing",
273274
"//score/mw/com/impl/tracing:skeleton_tracing",
274275
"@score_baselibs//score/language/futurecpp",
276+
"@iceoryx2//:iceoryx2-cxx-static",
275277
],
276278
)
277279

@@ -323,6 +325,7 @@ cc_library(
323325
"//score/mw/com/impl/plumbing",
324326
"@score_baselibs//score/language/futurecpp",
325327
"@score_baselibs//score/result",
328+
"@iceoryx2//:iceoryx2-cxx-static",
326329
],
327330
)
328331

@@ -348,6 +351,7 @@ cc_library(
348351
"//score/mw/com/impl/tracing:proxy_event_tracing_data",
349352
"@score_baselibs//score/language/futurecpp",
350353
"@score_baselibs//score/language/safecpp/scoped_function:scope",
354+
"@iceoryx2//:iceoryx2-cxx-static",
351355
],
352356
)
353357

score/mw/com/impl/plumbing/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,10 @@ cc_library(
523523
features = COMPILER_WARNING_FEATURES,
524524
tags = ["FFI"],
525525
visibility = ["//score/mw/com/impl:__subpackages__"],
526-
deps = ["//score/mw/com/impl/bindings/lola:event"],
526+
deps = [
527+
"//score/mw/com/impl/bindings/lola:event",
528+
"@iceoryx2//:iceoryx2-cxx-static",
529+
],
527530
)
528531

529532
cc_library(

score/mw/com/impl/plumbing/sample_allocatee_ptr.h

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <utility>
2424
#include <variant>
2525

26+
#include "iox2/iceoryx2.hpp"
27+
2628
namespace score::mw::com::impl
2729
{
2830

@@ -105,7 +107,7 @@ class SampleAllocateePtr
105107
// coverity[autosar_cpp14_a15_5_3_violation : FALSE]
106108
pointer operator->() const noexcept;
107109

108-
private:
110+
109111
template <typename T>
110112
// Suppress "AUTOSAR C++14 A0-1-3" rule finding. This rule states: "Every function defined in an anonymous
111113
// namespace, or static function with internal linkage, or private member function shall be used.".
@@ -114,7 +116,17 @@ class SampleAllocateePtr
114116
explicit SampleAllocateePtr(T ptr) : internal_{std::move(ptr)}
115117
{
116118
}
119+
template <typename T>
120+
explicit SampleAllocateePtr(T ptr, std::shared_ptr<iox2::SampleMut<iox2::ServiceType::Ipc, SampleType, void>> iox2_sample) :
121+
internal_{std::move(ptr)}, iox2_sample_{std::move(iox2_sample)}
122+
{
123+
}
117124

125+
std::shared_ptr<iox2::SampleMut<iox2::ServiceType::Ipc, SampleType, void>> GetIox2Sample() const noexcept
126+
{
127+
return iox2_sample_;
128+
}
129+
private:
118130
// Suppress "AUTOSAR C++14 A11-3-1", The rule states: "Friend declarations shall not be used".
119131
// Friend class required to access private constructor as we do not have everything we need public.
120132
// This is because we want to shield the end user from implementation details and avoid wrong usage.
@@ -133,7 +145,8 @@ class SampleAllocateePtr
133145
friend class SampleAllocateePtrMutableView;
134146

135147
// We don't use the pimpl idiom because it would require dynamic memory allocation (that we want to avoid)
136-
std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>> internal_;
148+
std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>, SampleType*> internal_;
149+
std::shared_ptr<iox2::SampleMut<iox2::ServiceType::Ipc, SampleType, void>> iox2_sample_;
137150
};
138151

139152
template <typename SampleType>
@@ -175,8 +188,13 @@ void SampleAllocateePtr<SampleType>::reset() noexcept
175188
internal_ptr.reset(nullptr);
176189
},
177190
// coverity[autosar_cpp14_a7_1_7_violation]
178-
[](const score::cpp::blank&) noexcept -> void {});
191+
[](const score::cpp::blank&) noexcept -> void {},
192+
[](SampleType* internal_ptr) noexcept -> void {
193+
internal_ptr = nullptr;
194+
}
195+
);
179196
std::visit(visitor, internal_);
197+
//iox2_sample_.reset();
180198
}
181199

182200
template <typename SampleType>
@@ -185,6 +203,7 @@ void SampleAllocateePtr<SampleType>::Swap(SampleAllocateePtr<SampleType>& other)
185203
// Search for custom swap functions via ADL, and use std::swap if none are found.
186204
using std::swap;
187205
swap(internal_, other.internal_);
206+
swap(iox2_sample_, other.iox2_sample_);
188207
}
189208

190209
template <typename SampleType>
@@ -213,7 +232,12 @@ auto SampleAllocateePtr<SampleType>::Get() const noexcept -> pointer
213232
// coverity[autosar_cpp14_a7_1_7_violation]
214233
[](const score::cpp::blank&) noexcept -> ReturnType {
215234
return nullptr;
216-
});
235+
},
236+
[](SampleType* internal_ptr) noexcept -> ReturnType {
237+
return internal_ptr;
238+
}
239+
240+
);
217241

218242
return std::visit(visitor, internal_);
219243
}
@@ -241,7 +265,11 @@ SampleAllocateePtr<SampleType>::operator bool() const noexcept
241265
// coverity[autosar_cpp14_a7_1_7_violation]
242266
[](const score::cpp::blank&) noexcept -> bool {
243267
return false;
244-
});
268+
},
269+
[](SampleType* internal_ptr) noexcept -> bool {
270+
return internal_ptr != nullptr;
271+
}
272+
);
245273

246274
return std::visit(visitor, internal_);
247275
}
@@ -273,7 +301,11 @@ typename std::add_lvalue_reference<SampleType>::type SampleAllocateePtr<SampleTy
273301
// coverity[autosar_cpp14_a7_1_7_violation]
274302
[](const score::cpp::blank&) noexcept -> ReturnType {
275303
std::terminate();
276-
});
304+
},
305+
[](SampleType* internal_ptr) noexcept -> ReturnType {
306+
return *internal_ptr;
307+
}
308+
);
277309

278310
return std::visit(visitor, internal_);
279311
}
@@ -304,7 +336,11 @@ auto SampleAllocateePtr<SampleType>::operator->() const noexcept -> pointer
304336
// coverity[autosar_cpp14_a7_1_7_violation]
305337
[](const score::cpp::blank&) noexcept -> ReturnType {
306338
std::terminate();
307-
});
339+
},
340+
[](SampleType* internal_ptr) noexcept -> ReturnType {
341+
return internal_ptr;
342+
}
343+
);
308344

309345
return std::visit(visitor, internal_);
310346
}
@@ -353,7 +389,7 @@ class SampleAllocateePtrView
353389
return std::get_if<T>(&ptr_.internal_);
354390
}
355391

356-
const std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>>&
392+
const std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>, SampleType*>&
357393
GetUnderlyingVariant() const noexcept
358394
{
359395
return ptr_.internal_;
@@ -370,7 +406,7 @@ class SampleAllocateePtrMutableView
370406
public:
371407
explicit SampleAllocateePtrMutableView(SampleAllocateePtr<SampleType>& ptr) : ptr_{ptr} {}
372408

373-
std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>>&
409+
std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>, SampleType*>&
374410
GetUnderlyingVariant() noexcept
375411
{
376412
// Suppress "AUTOSAR C++14 A9-3-1", The rule states: "Member functions shall not return non-const “raw” pointers

score/mw/com/impl/proxy_base.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ ProxyBase::ProxyBase(std::unique_ptr<ProxyBinding> proxy_binding, HandleType han
3535
fields_{},
3636
methods_{}
3737
{
38+
iox2_node_ = std::make_unique<iox2::Node<iox2::ServiceType::Ipc>>(
39+
iox2::NodeBuilder().create<iox2::ServiceType::Ipc>().expect("successful node creation")
40+
);
3841
}
3942

4043
ProxyBase::ProxyBase(ProxyBase&& other) noexcept

score/mw/com/impl/proxy_base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include <memory>
2828

29+
#include "iox2/iceoryx2.hpp"
30+
2931
namespace score::mw::com::impl
3032
{
3133

@@ -82,6 +84,8 @@ class ProxyBase
8284
/// \return Handle identifying the service that this proxy is connected to.
8385
const HandleType& GetHandle() const noexcept;
8486

87+
std::unique_ptr<iox2::Node<iox2::ServiceType::Ipc>> iox2_node_;
88+
8589
protected:
8690
using ProxyEvents = std::map<std::string_view, std::reference_wrapper<ProxyEventBase>>;
8791
using ProxyFields = std::map<std::string_view, std::reference_wrapper<ProxyFieldBase>>;

score/mw/com/impl/proxy_event.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <string_view>
3535
#include <utility>
3636

37+
#include "iox2/iceoryx2.hpp"
38+
3739
namespace score::mw::com::impl
3840
{
3941

@@ -122,6 +124,8 @@ class ProxyEvent final : public ProxyEventBase
122124
template <typename F>
123125
Result<std::size_t> GetNewSamples(F&& receiver, std::size_t max_num_samples) noexcept;
124126

127+
Result<std::size_t> GetNumNewSamplesAvailable() const noexcept;
128+
125129
void InjectMock(IProxyEvent<SampleType>& proxy_event_mock)
126130
{
127131
proxy_event_mock_ = &proxy_event_mock;
@@ -130,7 +134,8 @@ class ProxyEvent final : public ProxyEventBase
130134

131135
private:
132136
ProxyEventBinding<SampleType>* GetTypedEventBinding() const noexcept;
133-
137+
std::unique_ptr<iox2::PortFactoryPublishSubscribe<iox2::ServiceType::Ipc, SampleDataType, void>> iox2_service_;
138+
std::unique_ptr<iox2::Subscriber<iox2::ServiceType::Ipc, SampleDataType, void>> iox2_subscriber_;
134139
IProxyEvent<SampleType>* proxy_event_mock_;
135140

136141
/// \brief Indicates whether this event is a field event (i.e. owned by a ProxyField, which is a composite of
@@ -154,6 +159,28 @@ ProxyEvent<SampleType>::ProxyEvent(ProxyBase& base,
154159
proxy_base_view.MarkServiceElementBindingInvalid();
155160
return;
156161
}
162+
163+
const auto& instance_identifier = proxy_base_view.GetAssociatedHandleType().GetInstanceIdentifier();
164+
const auto& service_instance_deployment = InstanceIdentifierView{instance_identifier}.GetServiceInstanceDeployment();
165+
auto instance_specifier = service_instance_deployment.instance_specifier_.ToString();
166+
std::cout << "Creating ProxyEvent for instance specifier: " << instance_specifier << std::endl;
167+
std::string service_name = (std::string(instance_specifier) + "/" + std::string(event_name));
168+
std::cout << "Creating iox2 service with name: " << service_name << std::endl;
169+
iox2_service_ = std::make_unique<iox2::PortFactoryPublishSubscribe<iox2::ServiceType::Ipc, SampleType, void>>(
170+
base.iox2_node_->service_builder(
171+
iox2::ServiceName::create(service_name.c_str()).expect("valid service name")
172+
)
173+
.publish_subscribe<SampleType>()
174+
.open_or_create()
175+
.expect("successful service creation/opening")
176+
);
177+
iox2_subscriber_ = std::make_unique<iox2::Subscriber<iox2::ServiceType::Ipc, SampleType, void>>(
178+
iox2_service_->subscriber_builder().create().expect("successful subscriber creation")
179+
);
180+
if(iox2_subscriber_ != nullptr)
181+
{
182+
std::cout << "iox2 subscriber created successfully for event: " << event_name << std::endl;
183+
}
157184
}
158185

159186
template <typename SampleType>
@@ -193,6 +220,8 @@ ProxyEvent<SampleType>::ProxyEvent(ProxyEvent&& other) noexcept
193220
proxy_event_mock_{std::move(other.proxy_event_mock_)},
194221
is_field_event_{std::move(other.is_field_event_)}
195222
{
223+
iox2_service_ = std::move(other.iox2_service_);
224+
iox2_subscriber_ = std::move(other.iox2_subscriber_);
196225
if (!is_field_event_)
197226
{
198227
// Since the address of this event has changed, we need update the address stored in the parent proxy.
@@ -225,10 +254,27 @@ auto ProxyEvent<SampleType>::operator=(ProxyEvent&& other) & noexcept -> ProxyEv
225254
return *this;
226255
}
227256

257+
template <typename SampleType>
258+
Result<std::size_t> ProxyEvent<SampleType>::GetNumNewSamplesAvailable() const noexcept
259+
{
260+
bool has_samples = iox2_subscriber_->has_samples().expect("has_samples succeeds");
261+
return has_samples ? 1 : 0;
262+
}
263+
228264
template <typename SampleType>
229265
template <typename F>
230266
Result<std::size_t> ProxyEvent<SampleType>::GetNewSamples(F&& receiver, std::size_t max_num_samples) noexcept
231267
{
268+
size_t samples_num = 0;
269+
auto sample = iox2_subscriber_->receive().expect("receive succeeds");
270+
while (sample.has_value()) {
271+
samples_num++;
272+
SampleReferenceGuard reference_guard{};
273+
receiver(SamplePtr<SampleType>(std::make_unique<SampleType>(sample->payload()), std::move(reference_guard)));
274+
sample = iox2_subscriber_->receive().expect("receive succeeds");
275+
}
276+
return samples_num;
277+
232278
if (proxy_event_mock_ != nullptr)
233279
{
234280
typename IProxyEvent<SampleType>::Callback mock_callback =

score/mw/com/impl/skeleton_base.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ SkeletonBase::SkeletonBase(std::unique_ptr<SkeletonBinding> skeleton_binding,
9393
skeleton_mock_{nullptr},
9494
service_offered_flag_{}
9595
{
96+
iox2_node_ = std::make_unique<iox2::Node<iox2::ServiceType::Ipc>>(
97+
iox2::NodeBuilder().create<iox2::ServiceType::Ipc>().expect("successful node creation")
98+
);
9699
}
97100

98101
SkeletonBase::~SkeletonBase()

score/mw/com/impl/skeleton_base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include <memory>
3636
#include <string_view>
3737

38+
#include "iox2/iceoryx2.hpp"
39+
3840
namespace score::mw::com::impl
3941
{
4042

@@ -99,6 +101,8 @@ class SkeletonBase
99101
skeleton_mock_ = &skeleton_mock;
100102
}
101103

104+
std::unique_ptr<iox2::Node<iox2::ServiceType::Ipc>> iox2_node_;
105+
102106
protected:
103107
bool AreBindingsValid() const noexcept;
104108

0 commit comments

Comments
 (0)