Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ git_override(
remote = "https://github.com/eclipse-score/score-crates.git",
)

bazel_dep(name = "iceoryx2", version = "0.7.0")
local_path_override(
module_name = "iceoryx2",
path = "/home/piotr/score/iceoryx2",
)

bazel_dep(name = "boost.program_options", version = "1.87.0")
bazel_dep(name = "download_utils", version = "1.0.1")

Expand Down
4 changes: 4 additions & 0 deletions score/mw/com/impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ cc_library(
":skeleton_field",
"//score/mw/com/impl/methods:skeleton_method",
"//score/mw/com/impl/plumbing:event",
"@iceoryx2//:iceoryx2-cxx-static",
],
)

Expand Down Expand Up @@ -272,6 +273,7 @@ cc_library(
"//score/mw/com/impl/plumbing",
"//score/mw/com/impl/tracing:skeleton_tracing",
"@score_baselibs//score/language/futurecpp",
"@iceoryx2//:iceoryx2-cxx-static",
],
)

Expand Down Expand Up @@ -323,6 +325,7 @@ cc_library(
"//score/mw/com/impl/plumbing",
"@score_baselibs//score/language/futurecpp",
"@score_baselibs//score/result",
"@iceoryx2//:iceoryx2-cxx-static",
],
)

Expand All @@ -348,6 +351,7 @@ cc_library(
"//score/mw/com/impl/tracing:proxy_event_tracing_data",
"@score_baselibs//score/language/futurecpp",
"@score_baselibs//score/language/safecpp/scoped_function:scope",
"@iceoryx2//:iceoryx2-cxx-static",
],
)

Expand Down
5 changes: 4 additions & 1 deletion score/mw/com/impl/plumbing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ cc_library(
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
visibility = ["//score/mw/com/impl:__subpackages__"],
deps = ["//score/mw/com/impl/bindings/lola:event"],
deps = [
"//score/mw/com/impl/bindings/lola:event",
"@iceoryx2//:iceoryx2-cxx-static",
],
)

cc_library(
Expand Down
54 changes: 45 additions & 9 deletions score/mw/com/impl/plumbing/sample_allocatee_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <utility>
#include <variant>

#include "iox2/iceoryx2.hpp"

namespace score::mw::com::impl
{

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

private:

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

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

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

template <typename SampleType>
Expand Down Expand Up @@ -175,8 +188,13 @@ void SampleAllocateePtr<SampleType>::reset() noexcept
internal_ptr.reset(nullptr);
},
// coverity[autosar_cpp14_a7_1_7_violation]
[](const score::cpp::blank&) noexcept -> void {});
[](const score::cpp::blank&) noexcept -> void {},
[](SampleType* internal_ptr) noexcept -> void {
internal_ptr = nullptr;
}
);
std::visit(visitor, internal_);
//iox2_sample_.reset();
}

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

template <typename SampleType>
Expand Down Expand Up @@ -213,7 +232,12 @@ auto SampleAllocateePtr<SampleType>::Get() const noexcept -> pointer
// coverity[autosar_cpp14_a7_1_7_violation]
[](const score::cpp::blank&) noexcept -> ReturnType {
return nullptr;
});
},
[](SampleType* internal_ptr) noexcept -> ReturnType {
return internal_ptr;
}

);

return std::visit(visitor, internal_);
}
Expand Down Expand Up @@ -241,7 +265,11 @@ SampleAllocateePtr<SampleType>::operator bool() const noexcept
// coverity[autosar_cpp14_a7_1_7_violation]
[](const score::cpp::blank&) noexcept -> bool {
return false;
});
},
[](SampleType* internal_ptr) noexcept -> bool {
return internal_ptr != nullptr;
}
);

return std::visit(visitor, internal_);
}
Expand Down Expand Up @@ -273,7 +301,11 @@ typename std::add_lvalue_reference<SampleType>::type SampleAllocateePtr<SampleTy
// coverity[autosar_cpp14_a7_1_7_violation]
[](const score::cpp::blank&) noexcept -> ReturnType {
std::terminate();
});
},
[](SampleType* internal_ptr) noexcept -> ReturnType {
return *internal_ptr;
}
);

return std::visit(visitor, internal_);
}
Expand Down Expand Up @@ -304,7 +336,11 @@ auto SampleAllocateePtr<SampleType>::operator->() const noexcept -> pointer
// coverity[autosar_cpp14_a7_1_7_violation]
[](const score::cpp::blank&) noexcept -> ReturnType {
std::terminate();
});
},
[](SampleType* internal_ptr) noexcept -> ReturnType {
return internal_ptr;
}
);

return std::visit(visitor, internal_);
}
Expand Down Expand Up @@ -353,7 +389,7 @@ class SampleAllocateePtrView
return std::get_if<T>(&ptr_.internal_);
}

const std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>>&
const std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>, SampleType*>&
GetUnderlyingVariant() const noexcept
{
return ptr_.internal_;
Expand All @@ -370,7 +406,7 @@ class SampleAllocateePtrMutableView
public:
explicit SampleAllocateePtrMutableView(SampleAllocateePtr<SampleType>& ptr) : ptr_{ptr} {}

std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>>&
std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>, SampleType*>&
GetUnderlyingVariant() noexcept
{
// Suppress "AUTOSAR C++14 A9-3-1", The rule states: "Member functions shall not return non-const “raw” pointers
Expand Down
3 changes: 3 additions & 0 deletions score/mw/com/impl/proxy_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ ProxyBase::ProxyBase(std::unique_ptr<ProxyBinding> proxy_binding, HandleType han
fields_{},
methods_{}
{
iox2_node_ = std::make_unique<iox2::Node<iox2::ServiceType::Ipc>>(
iox2::NodeBuilder().create<iox2::ServiceType::Ipc>().expect("successful node creation")
);
}

ProxyBase::ProxyBase(ProxyBase&& other) noexcept
Expand Down
4 changes: 4 additions & 0 deletions score/mw/com/impl/proxy_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <memory>

#include "iox2/iceoryx2.hpp"

namespace score::mw::com::impl
{

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

std::unique_ptr<iox2::Node<iox2::ServiceType::Ipc>> iox2_node_;

protected:
using ProxyEvents = std::map<std::string_view, std::reference_wrapper<ProxyEventBase>>;
using ProxyFields = std::map<std::string_view, std::reference_wrapper<ProxyFieldBase>>;
Expand Down
48 changes: 47 additions & 1 deletion score/mw/com/impl/proxy_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <string_view>
#include <utility>

#include "iox2/iceoryx2.hpp"

namespace score::mw::com::impl
{

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

Result<std::size_t> GetNumNewSamplesAvailable() const noexcept;

void InjectMock(IProxyEvent<SampleType>& proxy_event_mock)
{
proxy_event_mock_ = &proxy_event_mock;
Expand All @@ -130,7 +134,8 @@ class ProxyEvent final : public ProxyEventBase

private:
ProxyEventBinding<SampleType>* GetTypedEventBinding() const noexcept;

std::unique_ptr<iox2::PortFactoryPublishSubscribe<iox2::ServiceType::Ipc, SampleDataType, void>> iox2_service_;
std::unique_ptr<iox2::Subscriber<iox2::ServiceType::Ipc, SampleDataType, void>> iox2_subscriber_;
IProxyEvent<SampleType>* proxy_event_mock_;

/// \brief Indicates whether this event is a field event (i.e. owned by a ProxyField, which is a composite of
Expand All @@ -154,6 +159,28 @@ ProxyEvent<SampleType>::ProxyEvent(ProxyBase& base,
proxy_base_view.MarkServiceElementBindingInvalid();
return;
}

const auto& instance_identifier = proxy_base_view.GetAssociatedHandleType().GetInstanceIdentifier();
const auto& service_instance_deployment = InstanceIdentifierView{instance_identifier}.GetServiceInstanceDeployment();
auto instance_specifier = service_instance_deployment.instance_specifier_.ToString();
std::cout << "Creating ProxyEvent for instance specifier: " << instance_specifier << std::endl;
std::string service_name = (std::string(instance_specifier) + "/" + std::string(event_name));
std::cout << "Creating iox2 service with name: " << service_name << std::endl;
iox2_service_ = std::make_unique<iox2::PortFactoryPublishSubscribe<iox2::ServiceType::Ipc, SampleType, void>>(
base.iox2_node_->service_builder(
iox2::ServiceName::create(service_name.c_str()).expect("valid service name")
)
.publish_subscribe<SampleType>()
.open_or_create()
.expect("successful service creation/opening")
);
iox2_subscriber_ = std::make_unique<iox2::Subscriber<iox2::ServiceType::Ipc, SampleType, void>>(
iox2_service_->subscriber_builder().create().expect("successful subscriber creation")
);
if(iox2_subscriber_ != nullptr)
{
std::cout << "iox2 subscriber created successfully for event: " << event_name << std::endl;
}
}

template <typename SampleType>
Expand Down Expand Up @@ -193,6 +220,8 @@ ProxyEvent<SampleType>::ProxyEvent(ProxyEvent&& other) noexcept
proxy_event_mock_{std::move(other.proxy_event_mock_)},
is_field_event_{std::move(other.is_field_event_)}
{
iox2_service_ = std::move(other.iox2_service_);
iox2_subscriber_ = std::move(other.iox2_subscriber_);
if (!is_field_event_)
{
// Since the address of this event has changed, we need update the address stored in the parent proxy.
Expand Down Expand Up @@ -225,10 +254,27 @@ auto ProxyEvent<SampleType>::operator=(ProxyEvent&& other) & noexcept -> ProxyEv
return *this;
}

template <typename SampleType>
Result<std::size_t> ProxyEvent<SampleType>::GetNumNewSamplesAvailable() const noexcept
{
bool has_samples = iox2_subscriber_->has_samples().expect("has_samples succeeds");
return has_samples ? 1 : 0;
}

template <typename SampleType>
template <typename F>
Result<std::size_t> ProxyEvent<SampleType>::GetNewSamples(F&& receiver, std::size_t max_num_samples) noexcept
{
size_t samples_num = 0;
auto sample = iox2_subscriber_->receive().expect("receive succeeds");
while (sample.has_value()) {
samples_num++;
SampleReferenceGuard reference_guard{};
receiver(SamplePtr<SampleType>(std::make_unique<SampleType>(sample->payload()), std::move(reference_guard)));
sample = iox2_subscriber_->receive().expect("receive succeeds");
}
return samples_num;

if (proxy_event_mock_ != nullptr)
{
typename IProxyEvent<SampleType>::Callback mock_callback =
Expand Down
3 changes: 3 additions & 0 deletions score/mw/com/impl/skeleton_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ SkeletonBase::SkeletonBase(std::unique_ptr<SkeletonBinding> skeleton_binding,
skeleton_mock_{nullptr},
service_offered_flag_{}
{
iox2_node_ = std::make_unique<iox2::Node<iox2::ServiceType::Ipc>>(
iox2::NodeBuilder().create<iox2::ServiceType::Ipc>().expect("successful node creation")
);
}

SkeletonBase::~SkeletonBase()
Expand Down
4 changes: 4 additions & 0 deletions score/mw/com/impl/skeleton_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <memory>
#include <string_view>

#include "iox2/iceoryx2.hpp"

namespace score::mw::com::impl
{

Expand Down Expand Up @@ -99,6 +101,8 @@ class SkeletonBase
skeleton_mock_ = &skeleton_mock;
}

std::unique_ptr<iox2::Node<iox2::ServiceType::Ipc>> iox2_node_;

protected:
bool AreBindingsValid() const noexcept;

Expand Down
Loading
Loading