Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This comprises the following items:
* `GenericProxy` class: We will provide a class `GenericProxy`, but opposed to the concept (linked above) **not** in
the `ara::com`, but in the `mw::com` namespace.
* This `GenericProxy` class will (in relation to the concept) **only** provide a public method `GetEvents()`, which
returns a `GenericProxy::EventMap` (which is a stripped down `std::map`)
returns a `GenericProxy::EventMapView` (which is a read-only view to a `std::map`)
* this map returned by `GetEvents()` will only contain all the events mentioned in the service deployment. Later (when
our fields get extended with get/set method functionality), this will change
(broken_link_j/Ticket-156027)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ abstract class "ProxyBinding" {

class "mw::com::impl::GenericProxy" #yellow {
using HandleType = ProxyBase::HandleType
using EventMap = ServiceElementMap<GenericProxyEvent>
using EventMapView = ServiceElementMapView<GenericProxyEvent>
..
+GenericProxy(ConstructionToken&&)
+GenericProxy(HandleType)
+events_ : EventMap
+{static} Create(HandleType instance_handle) : Result<GenericProxy>
-GenericProxy(std::unique_ptr<ProxyBinding> proxy_binding, HandleType instance_handle)
+GetEvents() : EventMapView

-events_ : std::unique_ptr<ServiceElementMapViewFactory<GenericProxyEvent>::map_type> events_
}

class "lola::Proxy" {
Expand Down Expand Up @@ -179,11 +181,19 @@ class "lola::GenericProxyEvent" #yellow {
-common_dispatch_ : lola::ProxyEventCommon
}

class "ServiceElementMap" {
using key_type = score::cpp::stringview
using mapped_type = GenericProxyEvent
using value_type = std::pair<const key_type, mapped_type>
using const_iterator = LegacyBidirectionalIterator to const value_type
class "ServiceElementMapViewFactory<ElementType>" {
using map_type = typename ServiceElementMapView<ElementType>::map_type
..
+Create(map_type&) : ServiceElementMapView<ElementType>
}

class "ServiceElementMapView<ElementType>" {
using key = std::string_view;
using value_type = std::pair<const key, Value>
using iterator = typename std::map<key, Value>::iterator
using const_iterator = typename std::map<key, Value>::const_iterator
using size_type = typename std::map<key, Value>::size_type
using map_type = std::map<key, Value>
..
+cbegin() : const_iterator
+cend() : const_iterator
Expand All @@ -198,14 +208,16 @@ class "ServiceElementMap" {
"score::mw::com::impl::ProxyBase" *--> "ProxyBinding"
"score::mw::com::impl::ProxyBase" <|-- "DummyProxy"
"score::mw::com::impl::ProxyBase" <|-- "mw::com::impl::GenericProxy"
"mw::com::impl::GenericProxy" *-- "ServiceElementMap"
"ProxyBindingFactory" ..> "ProxyBinding" : creates
"ProxyBinding" <|-- "lola::Proxy"
"lola::ProxyEventCommon" o-- "1" "lola::Proxy"
"ProxyBindingFactory" <.. "mw::com::impl::GenericProxy" : uses
"ProxyBindingFactory" <.. "DummyProxy" : uses
"DummyProxy" *--> "mw::com::impl::ProxyEvent<SampleType>" : "0..n"
"mw::com::impl::GenericProxy" *--> "mw::com::impl::GenericProxyEvent" : "0..n"
"mw::com::impl::GenericProxy" ..> "ServiceElementMapViewFactory<ElementType>" : uses
"ServiceElementMapViewFactory<ElementType>" ..> "ServiceElementMapView<ElementType>" : creates
"ServiceElementMapView<ElementType>" o-- "mw::com::impl::GenericProxyEvent" : "0..n"
"mw::com::impl::ProxyEventBase" *-- "SampleReferenceTracker"
"mw::com::impl::ProxyEventBase" <|-- "mw::com::impl::ProxyEvent<SampleType>"
"mw::com::impl::ProxyEventBase" <|-- "mw::com::impl::GenericProxyEvent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ abstract class "SkeletonBinding" {
}

class "mw::com::impl::GenericSkeleton" #yellow {
using EventMap = ServiceElementMap<GenericSkeletonEvent>
using EventMapView = ServiceElementMapView<GenericSkeletonEvent>
..
+GenericSkeleton(const InstanceIdentifier&, std::unique_ptr<SkeletonBinding>, MethodCallProcessingMode)
+Create(const InstanceIdentifier&, const GenericSkeletonServiceElementInfo&, MethodCallProcessingMode): Result<GenericSkeleton>
+Create(const InstanceSpecifier&, const GenericSkeletonServiceElementInfo&, MethodCallProcessingMode): Result<GenericSkeleton>
+events_ : EventMap
+Create(const InstanceIdentifier&, const GenericSkeletonServiceElementInfo&): Result<GenericSkeleton>
+Create(const InstanceSpecifier&, const GenericSkeletonServiceElementInfo&): Result<GenericSkeleton>
+GetEvents() : EventMapView
+OfferService(): Result<void>
+StopOfferService(): void
..
-GenericSkeleton(const InstanceIdentifier&, std::unique_ptr<SkeletonBinding>)
-events_ : std::unique_ptr<ServiceElementMapViewFactory<GenericSkeletonEvent>::map_type> events_
}

class "lola::Skeleton" {
Expand Down Expand Up @@ -87,11 +89,19 @@ class "GenericSkeletonEventBindingFactory" {
+{static} Create(SkeletonBase& parent, std::string_view event_name, const DataTypeMetaInfo& size_info): Result<std::unique_ptr<GenericSkeletonEventBinding>>
}

class "ServiceElementMap" {
using key_type = score::cpp::stringview
using mapped_type = GenericSkeletonEvent
using value_type = std::pair<const key_type, mapped_type>
using const_iterator = LegacyBidirectionalIterator to const value_type
class "ServiceElementMapViewFactory<ElementType>" {
using map_type = typename ServiceElementMapView<ElementType>::map_type
..
+Create(map_type&) : ServiceElementMapView<ElementType>
}

class "ServiceElementMapView<ElementType>" {
using key = std::string_view;
using value_type = std::pair<const key, Value>
using iterator = typename std::map<key, Value>::iterator
using const_iterator = typename std::map<key, Value>::const_iterator
using size_type = typename std::map<key, Value>::size_type
using map_type = std::map<key, Value>
..
+cbegin() : const_iterator
+cend() : const_iterator
Expand Down Expand Up @@ -156,7 +166,6 @@ class "DummySkeleton" <<generated>> {
"score::mw::com::impl::SkeletonBase" *--> "SkeletonBinding"
"score::mw::com::impl::SkeletonBase" <|-- "DummySkeleton"
"score::mw::com::impl::SkeletonBase" <|-- "mw::com::impl::GenericSkeleton"
"mw::com::impl::GenericSkeleton" *-- "ServiceElementMap"
"SkeletonBindingFactory" ..> "SkeletonBinding" : creates
"SkeletonBinding" <|-- "lola::Skeleton"

Expand All @@ -179,5 +188,8 @@ class "DummySkeleton" <<generated>> {

"DummySkeleton" *--> "mw::com::impl::SkeletonEvent<SampleType>" : "0..n"
"mw::com::impl::GenericSkeleton" *--> "mw::com::impl::GenericSkeletonEvent" : "0..n"
"mw::com::impl::GenericSkeleton" ..> "ServiceElementMapViewFactory<ElementType>" : uses
"ServiceElementMapViewFactory<ElementType>" ..> "ServiceElementMapView<ElementType>" : creates
"ServiceElementMapView<ElementType>" o-- "mw::com::impl::GenericSkeletonEvent" : "0..n"

@enduml
31 changes: 24 additions & 7 deletions score/mw/com/impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ cc_library(
":handle_type",
":proxy_base",
":proxy_binding",
":service_element_map",
":service_element_map_view",
":service_element_map_view_factory",
"@score_baselibs//score/result",
],
)
Expand Down Expand Up @@ -170,7 +171,8 @@ cc_library(
":instance_identifier",
":instance_specifier",
":runtime",
":service_element_map",
":service_element_map_view",
":service_element_map_view_factory",
":skeleton_base",
":skeleton_binding",
"@score_baselibs//score/result",
Expand Down Expand Up @@ -218,6 +220,7 @@ cc_library(

cc_library(
name = "data_type_meta_info",
srcs = ["data_type_meta_info.cpp"],
hdrs = ["data_type_meta_info.h"],
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
Expand Down Expand Up @@ -970,9 +973,23 @@ cc_library(
)

cc_library(
name = "service_element_map",
srcs = ["service_element_map.cpp"],
hdrs = ["service_element_map.h"],
name = "service_element_map_view_factory",
srcs = ["service_element_map_view_factory.cpp"],
hdrs = ["service_element_map_view_factory.h"],
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
visibility = [
"//score/mw/com/impl:__subpackages__",
],
deps = [
":service_element_map_view",
],
)

cc_library(
name = "service_element_map_view",
srcs = ["service_element_map_view.cpp"],
hdrs = ["service_element_map_view.h"],
features = COMPILER_WARNING_FEATURES,
tags = ["FFI"],
visibility = [
Expand Down Expand Up @@ -1287,7 +1304,7 @@ cc_unit_test(
"proxy_event_base_test.cpp",
"proxy_event_binding_base_test.cpp",
"proxy_event_test.cpp",
"service_element_map_test.cpp",
"service_element_map_view_test.cpp",
"skeleton_binding_test.cpp",
"skeleton_event_base_test.cpp",
"skeleton_event_binding_test.cpp",
Expand All @@ -1303,7 +1320,7 @@ cc_unit_test(
":impl",
":runtime_mock",
":service_discovery_mock",
":service_element_map",
":service_element_map_view",
"//score/mw/com:types",
"//score/mw/com/impl/bindings/lola:runtime_mock",
"//score/mw/com/impl/bindings/lola/test_doubles",
Expand Down
18 changes: 7 additions & 11 deletions score/mw/com/impl/generic_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
///
/// @file
/// @copyright Copyright (C) 2023, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
///

#include "score/mw/com/impl/generic_proxy.h"

#include "score/mw/com/impl/com_error.h"
#include "score/mw/com/impl/plumbing/proxy_binding_factory.h"
#include "score/mw/com/impl/service_element_map_view_factory.h"

#include "score/mw/log/logging.h"

Expand Down Expand Up @@ -86,7 +84,8 @@ Result<GenericProxy> GenericProxy::Create(HandleType instance_handle) noexcept
}

GenericProxy::GenericProxy(std::unique_ptr<ProxyBinding> proxy_binding, HandleType instance_handle)
: ProxyBase{std::move(proxy_binding), std::move(instance_handle)}
: ProxyBase{std::move(proxy_binding), std::move(instance_handle)},
events_(std::make_unique<std::map<std::string_view, GenericProxyEvent>>())
{
Comment thread
bemerybmw marked this conversation as resolved.
}

Expand All @@ -96,7 +95,7 @@ void GenericProxy::FillEventMap(const std::vector<std::string_view>& event_names
{
if (proxy_binding_->IsEventProvided(event_name))
{
const auto emplace_result = events_.emplace(
const auto emplace_result = events_->emplace(
std::piecewise_construct, std::forward_as_tuple(event_name), std::forward_as_tuple(*this, event_name));
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(emplace_result.second,
"Could not emplace GenericProxyEvent in map.");
Expand All @@ -110,12 +109,9 @@ void GenericProxy::FillEventMap(const std::vector<std::string_view>& event_names
}
}

GenericProxy::EventMap& GenericProxy::GetEvents() noexcept
GenericProxy::EventMapView GenericProxy::GetEvents() const noexcept
{
// The signature of this function is part of the public API of the GenericProxy, specified in this requirement:
// broken_link_c/issue/14006006
// coverity[autosar_cpp14_a9_3_1_violation]
return events_;
return ServiceElementMapViewFactory<GenericProxyEvent>::Create(*events_);
}

} // namespace score::mw::com::impl
24 changes: 13 additions & 11 deletions score/mw/com/impl/generic_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
///
/// @file
/// @copyright Copyright (C) 2023, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
///

#ifndef SCORE_MW_COM_IMPL_GENERIC_PROXY_H
#define SCORE_MW_COM_IMPL_GENERIC_PROXY_H
Expand All @@ -22,7 +18,8 @@
#include "score/mw/com/impl/handle_type.h"
#include "score/mw/com/impl/proxy_base.h"
#include "score/mw/com/impl/proxy_binding.h"
#include "score/mw/com/impl/service_element_map.h"
#include "score/mw/com/impl/service_element_map_view.h"
#include "score/mw/com/impl/service_element_map_view_factory.h"

#include "score/result/result.h"

Expand Down Expand Up @@ -53,13 +50,13 @@ class GenericProxyAttorney;
class GenericProxy : public ProxyBase
{
// Suppress "AUTOSAR C++14 A11-3-1", The rule declares: "Friend declarations shall not be used".
// Design dessision: The "*Attorney" class is a helper, which sets the internal state of this class accessing
// Design decision: The "*Attorney" class is a helper, which sets the internal state of this class accessing
// private members and used for testing purposes only.
// coverity[autosar_cpp14_a11_3_1_violation]
friend class test::GenericProxyAttorney;

public:
using EventMap = ServiceElementMap<GenericProxyEvent>;
using EventMapView = ServiceElementMapView<GenericProxyEvent>;

/**
* \api
Expand All @@ -71,17 +68,22 @@ class GenericProxy : public ProxyBase

/**
* \api
* \brief Returns a reference to the event map.
* \return Reference to the event map.
* \brief Returns a read-only view to the name-keyed map of events.
* \note The returned view is valid as long as the GenericProxy lives.
* \return View to the event map.
*/
EventMap& GetEvents() noexcept;
EventMapView GetEvents() const noexcept;

private:
GenericProxy(std::unique_ptr<ProxyBinding> proxy_binding, HandleType instance_handle);

void FillEventMap(const std::vector<std::string_view>& event_names) noexcept;

EventMap events_;
/// \brief This map owns all GenericProxyEvent instances.
/// \details This map needs to be covered in a unique_ptr as it shall not be relocated by a move of the
/// GenericProxy. This is required as we hand out views to this map (see GetEvents()), which need to be valid
/// even after the GenericProxy instance has been moved.
std::unique_ptr<ServiceElementMapViewFactory<GenericProxyEvent>::map_type> events_;
};

} // namespace score::mw::com::impl
Expand Down
Loading
Loading