diff options
Diffstat (limited to 'implementation/compat')
-rw-r--r-- | implementation/compat/logging/include/logger.hpp | 28 | ||||
-rw-r--r-- | implementation/compat/logging/include/logger_impl.hpp | 33 | ||||
-rw-r--r-- | implementation/compat/logging/src/logger.cpp | 16 | ||||
-rw-r--r-- | implementation/compat/logging/src/logger_impl.cpp | 30 | ||||
-rw-r--r-- | implementation/compat/message/include/message_base_impl.hpp | 82 | ||||
-rw-r--r-- | implementation/compat/message/include/message_impl.hpp | 37 | ||||
-rw-r--r-- | implementation/compat/message/include/payload_impl.hpp | 45 | ||||
-rw-r--r-- | implementation/compat/message/src/message_base_impl.cpp | 166 | ||||
-rw-r--r-- | implementation/compat/message/src/message_impl.cpp | 56 | ||||
-rw-r--r-- | implementation/compat/message/src/payload_impl.cpp | 95 | ||||
-rw-r--r-- | implementation/compat/runtime/include/application_impl.hpp | 202 | ||||
-rw-r--r-- | implementation/compat/runtime/include/runtime_impl.hpp | 58 | ||||
-rw-r--r-- | implementation/compat/runtime/src/application_impl.cpp | 649 | ||||
-rw-r--r-- | implementation/compat/runtime/src/runtime.cpp | 29 | ||||
-rw-r--r-- | implementation/compat/runtime/src/runtime_impl.cpp | 125 |
15 files changed, 1651 insertions, 0 deletions
diff --git a/implementation/compat/logging/include/logger.hpp b/implementation/compat/logging/include/logger.hpp new file mode 100644 index 0000000..0f59502 --- /dev/null +++ b/implementation/compat/logging/include/logger.hpp @@ -0,0 +1,28 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef VSOMEIP_COMPAT_LOGGER_HPP_ +#define VSOMEIP_COMPAT_LOGGER_HPP_ + +#include <memory> + +#include <boost/log/sources/severity_logger.hpp> +#include <boost/log/trivial.hpp> + +namespace vsomeip { + +class logger { +public: + static std::shared_ptr<logger> get(); + + virtual ~logger() {} + + virtual boost::log::sources::severity_logger_mt< + boost::log::trivial::severity_level> & get_internal() = 0; +}; + +} // namespace vsomeip + +#endif // VSOMEIP_COMPAT_LOGGER_HPP_ diff --git a/implementation/compat/logging/include/logger_impl.hpp b/implementation/compat/logging/include/logger_impl.hpp new file mode 100644 index 0000000..8aed18e --- /dev/null +++ b/implementation/compat/logging/include/logger_impl.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef VSOMEIP_COMPAT_LOGGER_IMPL_HPP_ +#define VSOMEIP_COMPAT_LOGGER_IMPL_HPP_ + +#include "logger.hpp" + +namespace vsomeip_v3 { +class logger; +} // namespace vsomeip_v3 + +namespace vsomeip { + +class logger_impl + : public logger { +public: + static std::shared_ptr<logger> get(); + + logger_impl(); + + boost::log::sources::severity_logger_mt< + boost::log::trivial::severity_level> & get_internal(); + +private: + std::shared_ptr<vsomeip_v3::logger> impl_; +}; + +} // namespace vsomeip + +#endif // VSOMEIP_COMPAT_LOGGER_IMPL_HPP_ diff --git a/implementation/compat/logging/src/logger.cpp b/implementation/compat/logging/src/logger.cpp new file mode 100644 index 0000000..eb11707 --- /dev/null +++ b/implementation/compat/logging/src/logger.cpp @@ -0,0 +1,16 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "../include/logger_impl.hpp" + +namespace vsomeip { + +std::shared_ptr<logger> +logger::get() { + + return (logger_impl::get()); +} + +} // namespace vsomeip diff --git a/implementation/compat/logging/src/logger_impl.cpp b/implementation/compat/logging/src/logger_impl.cpp new file mode 100644 index 0000000..4ceaaa7 --- /dev/null +++ b/implementation/compat/logging/src/logger_impl.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "../include/logger_impl.hpp" +#include <vsomeip/internal/logger.hpp> + +namespace vsomeip { + +std::shared_ptr<logger> +logger_impl::get() { + + static std::shared_ptr<logger_impl> the_logger( + std::make_shared<logger_impl>() + ); + return the_logger; +} + +logger_impl::logger_impl() + : impl_(vsomeip_v3::logger::get()) { +} + +boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> & +logger_impl::get_internal() { + + return impl_->get_internal(); +} + +} // namespace vsomeip diff --git a/implementation/compat/message/include/message_base_impl.hpp b/implementation/compat/message/include/message_base_impl.hpp new file mode 100644 index 0000000..6333965 --- /dev/null +++ b/implementation/compat/message/include/message_base_impl.hpp @@ -0,0 +1,82 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef VSOMEIP_COMPAT_MESSAGE_BASE_IMPL_HPP_ +#define VSOMEIP_COMPAT_MESSAGE_BASE_IMPL_HPP_ + +#include <compat/vsomeip/export.hpp> +#include <compat/vsomeip/message.hpp> +#include <vsomeip/message.hpp> + +namespace vsomeip_v3 { +class message_impl; +} // namespace vsomeip_v3 + +namespace vsomeip { + +class message; + +class message_base_impl + : virtual public message_base { + +public: + VSOMEIP_EXPORT message_base_impl(const std::shared_ptr<vsomeip_v3::message> &_impl); + VSOMEIP_EXPORT virtual ~message_base_impl(); + + VSOMEIP_EXPORT message_t get_message() const; + VSOMEIP_EXPORT void set_message(message_t _message); + + VSOMEIP_EXPORT service_t get_service() const; + VSOMEIP_EXPORT void set_service(service_t _service); + + VSOMEIP_EXPORT instance_t get_instance() const; + VSOMEIP_EXPORT void set_instance(instance_t _instance); + + VSOMEIP_EXPORT method_t get_method() const; + VSOMEIP_EXPORT void set_method(method_t _method); + + VSOMEIP_EXPORT length_t get_length() const; + + VSOMEIP_EXPORT request_t get_request() const; + + VSOMEIP_EXPORT client_t get_client() const; + VSOMEIP_EXPORT void set_client(client_t _client); + + VSOMEIP_EXPORT session_t get_session() const; + VSOMEIP_EXPORT void set_session(session_t _session); + + VSOMEIP_EXPORT protocol_version_t get_protocol_version() const; + + VSOMEIP_EXPORT interface_version_t get_interface_version() const; + VSOMEIP_EXPORT void set_interface_version(interface_version_t _interface_version); + + VSOMEIP_EXPORT message_type_e get_message_type() const; + VSOMEIP_EXPORT void set_message_type(message_type_e _type); + + VSOMEIP_EXPORT return_code_e get_return_code() const; + VSOMEIP_EXPORT void set_return_code(return_code_e _code); + + VSOMEIP_EXPORT bool is_reliable() const; + VSOMEIP_EXPORT void set_reliable(bool _is_reliable); + + VSOMEIP_EXPORT virtual bool is_initial() const; + VSOMEIP_EXPORT virtual void set_initial(bool _is_initial); + + //VSOMEIP_EXPORT message * get_owner() const; + //VSOMEIP_EXPORT void set_owner(message *_owner); + + VSOMEIP_EXPORT bool is_valid_crc() const; + VSOMEIP_EXPORT void set_is_valid_crc(bool _is_valid_crc); + + inline std::shared_ptr<vsomeip_v3::message> get_impl() const { return impl_; } + +protected: + //message *owner_; + std::shared_ptr<vsomeip_v3::message> impl_; +}; + +} // namespace vsomeip + +#endif // VSOMEIP_COMPAT_MESSAGE_BASE_IMPL_HPP_ diff --git a/implementation/compat/message/include/message_impl.hpp b/implementation/compat/message/include/message_impl.hpp new file mode 100644 index 0000000..d773b97 --- /dev/null +++ b/implementation/compat/message/include/message_impl.hpp @@ -0,0 +1,37 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef VSOMEIP_COMPAT_MESSAGE_IMPL_HPP_ +#define VSOMEIP_COMPAT_MESSAGE_IMPL_HPP_ + +#if _MSC_VER >= 1300 +# pragma warning( disable : 4250 ) +#endif + +#include <compat/vsomeip/message.hpp> +#include "message_base_impl.hpp" + +namespace vsomeip { + +class payload; + +class message_impl + : virtual public message_base_impl, + virtual public message { + +public: + VSOMEIP_EXPORT message_impl(const std::shared_ptr<vsomeip_v3::message> &_impl); + VSOMEIP_EXPORT virtual ~message_impl(); + + VSOMEIP_EXPORT std::shared_ptr< payload > get_payload() const; + VSOMEIP_EXPORT void set_payload(std::shared_ptr< payload > _payload); + + VSOMEIP_EXPORT bool serialize(serializer *_to) const; + VSOMEIP_EXPORT bool deserialize(deserializer *_from); +}; + +} // namespace vsomeip + +#endif // VSOMEIP_COMPAT_MESSAGE_IMPL_HPP_ diff --git a/implementation/compat/message/include/payload_impl.hpp b/implementation/compat/message/include/payload_impl.hpp new file mode 100644 index 0000000..1e8b493 --- /dev/null +++ b/implementation/compat/message/include/payload_impl.hpp @@ -0,0 +1,45 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef VSOMEIP_COMPAT_PAYLOAD_IMPL_HPP_ +#define VSOMEIP_COMPAT_PAYLOAD_IMPL_HPP_ + +#include <compat/vsomeip/payload.hpp> +#include <vsomeip/payload.hpp> + +namespace vsomeip { + +class payload_impl + : public payload { + +public: + payload_impl(const std::shared_ptr<vsomeip_v3::payload> &_impl); + ~payload_impl(); + + bool operator ==(const payload &_other); + + byte_t * get_data(); + const byte_t * get_data() const; + + void set_data(const byte_t *_data, length_t _length); + void set_data(const std::vector<byte_t> &_data); + void set_data(std::vector<byte_t> &&_data); + + length_t get_length() const; + void set_capacity(length_t _length); + + bool deserialize(deserializer *_from); + bool serialize(serializer *_to) const; + + // Wraps + inline std::shared_ptr<vsomeip_v3::payload> get_impl() const { return impl_; } + +private: + std::shared_ptr<vsomeip_v3::payload> impl_; +}; + +} // namespace vsomeip + +#endif // VSOMEIP_COMPAT_PAYLOAD_IMPL_HPP_ diff --git a/implementation/compat/message/src/message_base_impl.cpp b/implementation/compat/message/src/message_base_impl.cpp new file mode 100644 index 0000000..3d646ce --- /dev/null +++ b/implementation/compat/message/src/message_base_impl.cpp @@ -0,0 +1,166 @@ +// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <vsomeip/runtime.hpp> + +#include "../include/message_base_impl.hpp" +#include "../../../message/include/message_impl.hpp" + +namespace vsomeip { + +message_base_impl::message_base_impl( + const std::shared_ptr<vsomeip_v3::message> &_impl) + : impl_(_impl) { +} + +message_base_impl::~message_base_impl() { +} + +message_t +message_base_impl::get_message() const { + return impl_->get_message(); +} + +void +message_base_impl::set_message(message_t _message) { + impl_->set_message(_message); +} + +service_t +message_base_impl::get_service() const { + return impl_->get_service(); +} + +void +message_base_impl::set_service(service_t _service) { + impl_->set_service(_service); +} + +instance_t +message_base_impl::get_instance() const { + return impl_->get_instance(); +} + +void +message_base_impl::set_instance(instance_t _instance) { + impl_->set_instance(_instance); +} + +method_t +message_base_impl::get_method() const { + return impl_->get_method(); +} + +void +message_base_impl::set_method(method_t _method) { + impl_->set_method(_method); +} + +length_t +message_base_impl::get_length() const { + return impl_->get_length(); +} + +request_t +message_base_impl::get_request() const { + return impl_->get_request(); +} + +client_t +message_base_impl::get_client() const { + return impl_->get_client(); +} + +void +message_base_impl::set_client(client_t _client) { + impl_->set_client(_client); +} + +session_t +message_base_impl::get_session() const { + return impl_->get_session(); +} + +void +message_base_impl::set_session(session_t _session) { + impl_->set_session(_session); +} + +protocol_version_t +message_base_impl::get_protocol_version() const { + return impl_->get_protocol_version(); +} + +interface_version_t +message_base_impl::get_interface_version() const { + return impl_->get_interface_version(); +} + +void +message_base_impl::set_interface_version(interface_version_t _interface_version) { + impl_->set_interface_version(_interface_version); +} + +message_type_e +message_base_impl::get_message_type() const { + return static_cast<message_type_e>(impl_->get_message_type()); +} + +void +message_base_impl::set_message_type(message_type_e _type) { + impl_->set_message_type(static_cast<vsomeip_v3::message_type_e>(_type)); +} + +return_code_e +message_base_impl::get_return_code() const { + return static_cast<return_code_e>(impl_->get_return_code()); +} + +void +message_base_impl::set_return_code(return_code_e _code) { + impl_->set_return_code(static_cast<vsomeip_v3::return_code_e>(_code)); +} + +bool +message_base_impl::is_reliable() const { + return impl_->is_reliable(); +} + +void +message_base_impl::set_reliable(bool _is_reliable) { + impl_->set_reliable(_is_reliable); +} + +bool +message_base_impl::is_initial() const { + return impl_->is_initial(); +} + +void +message_base_impl::set_initial(bool _is_initial) { + impl_->set_initial(_is_initial); +} +/* +message * +message_base_impl::get_owner() const { + return owner_; +} + +void +message_base_impl::set_owner(message *_owner) { + owner_ = _owner; +} +*/ +bool +message_base_impl::is_valid_crc() const { + return impl_->is_valid_crc(); +} + +void +message_base_impl::set_is_valid_crc(bool _is_valid_crc) { + impl_->set_check_result(_is_valid_crc == true ? 1 : 0); +} + +} // namespace vsomeip diff --git a/implementation/compat/message/src/message_impl.cpp b/implementation/compat/message/src/message_impl.cpp new file mode 100644 index 0000000..e7e7af1 --- /dev/null +++ b/implementation/compat/message/src/message_impl.cpp @@ -0,0 +1,56 @@ +// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <vsomeip/internal/logger.hpp> + +#include "../include/message_impl.hpp" +#include "../include/payload_impl.hpp" +#include "../../../message/include/message_impl.hpp" + +namespace vsomeip { + +message_impl::message_impl(const std::shared_ptr<vsomeip_v3::message> &_impl) + : message_base_impl(_impl) { +} + +message_impl::~message_impl() { +} + +std::shared_ptr< payload > +message_impl::get_payload() const { + + return std::make_shared<payload_impl>(impl_->get_payload()); +} + +void +message_impl::set_payload(std::shared_ptr< payload > _payload) { + + if (_payload) { + auto its_payload = std::dynamic_pointer_cast<payload_impl>(_payload); + impl_->set_payload(its_payload->get_impl()); + } else { + impl_->set_payload(nullptr); + } +} + +bool +message_impl::serialize(serializer *_to) const { + + (void)_to; + VSOMEIP_ERROR << "message_impl::" << __func__ + << ": Must not be called from compatibility layer."; + return false; +} + +bool +message_impl::deserialize(deserializer *_from) { + + (void)_from; + VSOMEIP_ERROR << "message_impl::" << __func__ + << ": Must not be called from compatibility layer."; + return false; +} + +} // namespace vsomeip diff --git a/implementation/compat/message/src/payload_impl.cpp b/implementation/compat/message/src/payload_impl.cpp new file mode 100644 index 0000000..5d78304 --- /dev/null +++ b/implementation/compat/message/src/payload_impl.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <vsomeip/payload.hpp> +#include <vsomeip/runtime.hpp> +#include <vsomeip/internal/logger.hpp> + +#include "../include/payload_impl.hpp" + +namespace vsomeip { + +payload_impl::payload_impl(const std::shared_ptr<vsomeip_v3::payload> &_impl) + : impl_(_impl) { +} + +payload_impl::~payload_impl() { +} + +bool +payload_impl::operator==(const payload &_other) { + + bool is_equal(true); + try { + const payload_impl &other = dynamic_cast< const payload_impl & >(_other); + is_equal = (*(impl_.get()) == *(other.impl_.get())); + } + catch (...) { + is_equal = false; + } + return is_equal; +} + +byte_t * +payload_impl::get_data() { + + return impl_->get_data(); +} + +const byte_t * +payload_impl::get_data() const { + + return impl_->get_data(); +} + +length_t +payload_impl::get_length() const { + + return impl_->get_length(); +} + +void +payload_impl::set_capacity(length_t _capacity) { + + impl_->set_capacity(_capacity); +} + +void +payload_impl::set_data(const byte_t *_data, const length_t _length) { + + impl_->set_data(_data, _length); +} + +void +payload_impl::set_data(const std::vector< byte_t > &_data) { + + impl_->set_data(_data); +} + +void +payload_impl::set_data(std::vector< byte_t > &&_data) { + + impl_->set_data(_data); +} + +bool +payload_impl::serialize(serializer *_to) const { + + (void)_to; + VSOMEIP_ERROR << "payload_impl::" << __func__ + << ": Must not be called from compatibility layer."; + return false; +} + +bool +payload_impl::deserialize(deserializer *_from) { + + (void)_from; + VSOMEIP_ERROR << "payload_impl::" << __func__ + << ": Must not be called from compatibility layer."; + return false; +} + +} // namespace vsomeip diff --git a/implementation/compat/runtime/include/application_impl.hpp b/implementation/compat/runtime/include/application_impl.hpp new file mode 100644 index 0000000..8c3b4e0 --- /dev/null +++ b/implementation/compat/runtime/include/application_impl.hpp @@ -0,0 +1,202 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef VSOMEIP_COMPAT_APPLICATION_IMPL_HPP_ +#define VSOMEIP_COMPAT_APPLICATION_IMPL_HPP_ + +#include <map> +#include <mutex> + +#include <compat/vsomeip/application.hpp> + +namespace vsomeip_v3 { +class application; +} // namespace vsomeip_v3 + +namespace vsomeip { + +class application_impl + : public application { +public: + application_impl(const std::string &_name); + ~application_impl(); + + const std::string & get_name() const; + client_t get_client() const; + + void set_configuration( + const std::shared_ptr<configuration> _configuration); + + bool init(); + void start(); + void stop(); + + void offer_service(service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor); + void stop_offer_service(service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor); + + void offer_event(service_t _service, instance_t _instance, event_t _event, + const std::set<eventgroup_t> &_eventgroups, bool _is_field); + void stop_offer_event(service_t _service, instance_t _instance, + event_t _event); + + void request_service(service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor, + bool _use_exclusive_proxy); + void release_service(service_t _service, instance_t _instance); + + void request_event(service_t _service, instance_t _instance, + event_t _event, const std::set<eventgroup_t> &_eventgroups, + bool _is_field); + void release_event(service_t _service, instance_t _instance, + event_t _event); + + void subscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup, major_version_t _major, + subscription_type_e _subscription_type, + event_t _event); + void unsubscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup); + + bool is_available(service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor) const; + + void send(std::shared_ptr<message> _message, bool _flush); + void notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload) const; + void notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + client_t _client) const; + + void register_state_handler(state_handler_t _handler); + void unregister_state_handler(); + + void register_message_handler(service_t _service, + instance_t _instance, method_t _method, + message_handler_t _handler); + void unregister_message_handler(service_t _service, + instance_t _instance, method_t _method); + + void register_availability_handler(service_t _service, + instance_t _instance, availability_handler_t _handler, + major_version_t _major, minor_version_t _minor); + void unregister_availability_handler(service_t _service, + instance_t _instance, + major_version_t _major, minor_version_t _minor); + + void register_subscription_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, + subscription_handler_t _handler); + void unregister_subscription_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup); + + void register_subscription_error_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, + error_handler_t _handler); + void unregister_subscription_error_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup); + + void clear_all_handler(); + + bool is_routing() const; + + void offer_event(service_t _service, + instance_t _instance, event_t _event, + const std::set<eventgroup_t> &_eventgroups, + bool _is_field, + std::chrono::milliseconds _cycle, + bool _change_resets_cycle, + const epsilon_change_func_t &_epsilon_change_func); + + void notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + bool _force) const; + + void notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + client_t _client, bool _force) const; + + bool are_available(available_t &_available, + service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor) const; + + void notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + bool _force, bool _flush) const; + + void notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + client_t _client, bool _force, bool _flush) const; + + void set_routing_state(routing_state_e _routing_state); + + void unsubscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup, event_t _event); + + void register_subscription_status_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, event_t _event, + subscription_status_handler_t _handler); + + void register_subscription_status_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, event_t _event, + subscription_status_handler_t _handler, bool _is_selective); + + void get_offered_services_async( + offer_type_e _offer_type, offered_services_handler_t _handler); + + void set_watchdog_handler( + watchdog_handler_t _handler, std::chrono::seconds _interval); + + virtual void register_async_subscription_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup, + async_subscription_handler_t _handler); + + virtual void set_offer_acceptance_required( + ip_address_t _address, const std::string _path, bool _enable); + + virtual offer_acceptance_map_type_t get_offer_acceptance_required(); + + virtual void register_offer_acceptance_handler( + offer_acceptance_handler_t _handler); + + virtual void register_reboot_notification_handler( + reboot_notification_handler_t _handler); + + virtual void register_routing_ready_handler( + routing_ready_handler_t _handler); + + virtual void register_routing_state_handler( + routing_state_handler_t _handler); + + virtual bool update_service_configuration( + service_t _service, instance_t _instance, + std::uint16_t _port, bool _reliable, + bool _magic_cookies_enabled, bool _offer); + + virtual void update_security_policy_configuration( + uint32_t _uid, uint32_t _gid, + std::shared_ptr<policy> _policy, std::shared_ptr<payload> _payload, + security_update_handler_t _handler); + + virtual void remove_security_policy_configuration( + uint32_t _uid, uint32_t _gid, security_update_handler_t _handler); + +private: + bool is_selective_event( + vsomeip::service_t _service, vsomeip::instance_t _instance, + const std::set<vsomeip::eventgroup_t> &_eventgroups); + +private: + std::shared_ptr<vsomeip_v3::application> impl_; + + std::map<service_t, + std::map<instance_t, std::set<eventgroup_t> > > eventgroups_; + std::mutex eventgroups_mutex_; +}; + +} // namespace vsomeip + +#endif // VSOMEIP_COMPAT_APPLICATION_IMPL_HPP_ diff --git a/implementation/compat/runtime/include/runtime_impl.hpp b/implementation/compat/runtime/include/runtime_impl.hpp new file mode 100644 index 0000000..caadbfa --- /dev/null +++ b/implementation/compat/runtime/include/runtime_impl.hpp @@ -0,0 +1,58 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef VSOMEIP_COMPAT_RUNTIME_IMPL_HPP_ +#define VSOMEIP_COMPAT_RUNTIME_IMPL_HPP_ + +#include <map> +#include <mutex> + +#include <compat/vsomeip/runtime.hpp> + +namespace vsomeip { + +class runtime_impl + : public runtime { +public: + static std::string get_property(const std::string &_name); + static void set_property(const std::string &_name, const std::string &_value); + + static std::shared_ptr<runtime> get(); + + ~runtime_impl(); + + std::shared_ptr<application> create_application( + const std::string &_name = ""); + + std::shared_ptr<message> create_message(bool _reliable = false) const; + + std::shared_ptr<message> create_request(bool _reliable = false) const; + + std::shared_ptr<message> create_response( + const std::shared_ptr<message> &_request) const; + + std::shared_ptr<message> create_notification( + bool _reliable = false) const; + + std::shared_ptr<payload> create_payload() const; + std::shared_ptr<payload> create_payload( + const byte_t *_data, uint32_t _size) const; + virtual std::shared_ptr<payload> create_payload( + const std::vector<byte_t> &_data) const; + + std::shared_ptr<application> get_application( + const std::string &_name) const; + void remove_application( const std::string &_name); + +private: + static std::shared_ptr<runtime> the_runtime_; + + std::map<std::string, std::weak_ptr<application> > applications_; + mutable std::mutex applications_mutex_; +}; + +} // namespace vsomeip + +#endif // VSOMEIP_COMPAT_RUNTIME_IMPL_HPP_ diff --git a/implementation/compat/runtime/src/application_impl.cpp b/implementation/compat/runtime/src/application_impl.cpp new file mode 100644 index 0000000..559eae3 --- /dev/null +++ b/implementation/compat/runtime/src/application_impl.cpp @@ -0,0 +1,649 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <vsomeip/application.hpp> +#include <vsomeip/runtime.hpp> +#include <compat/vsomeip/runtime.hpp> + +#include <vsomeip/internal/logger.hpp> + +#include "../include/application_impl.hpp" +#include "../../message/include/message_impl.hpp" +#include "../../message/include/payload_impl.hpp" + +namespace vsomeip { + +application_impl::application_impl(const std::string &_name) { + + impl_ = vsomeip_v3::runtime::get()->create_application(_name); +} + +application_impl::~application_impl() { + + vsomeip::runtime::get()->remove_application(impl_->get_name()); +} + +const std::string & +application_impl::get_name() const { + + return impl_->get_name(); +} + +client_t +application_impl::get_client() const { + + return impl_->get_client(); +} + +void +application_impl::set_configuration(const std::shared_ptr<configuration> _configuration) { + + (void)_configuration; + // Not implemented +} + +bool +application_impl::init() { + + return impl_->init(); +} + +void +application_impl::start() { + + impl_->start(); +} + +void +application_impl::stop() { + + impl_->stop(); +} + +void +application_impl::offer_service(service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor) { + + impl_->offer_service(_service, _instance, _major, _minor); +} + +void +application_impl::stop_offer_service(service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor) { + + impl_->stop_offer_service(_service, _instance, _major, _minor); +} + +void +application_impl::offer_event(service_t _service, instance_t _instance, + event_t _event, const std::set<eventgroup_t> &_eventgroups, + bool _is_field) { + + // Set event type + vsomeip_v3::event_type_e its_type(vsomeip_v3::event_type_e::ET_EVENT); + if (_is_field) + its_type = vsomeip_v3::event_type_e::ET_FIELD; + else { + // Find out whether the event is selective. Requires a preceding + // call to "register_subscription_handler". + // Note: The check can be done on the eventgroup(s) as selective + // events own an exclusive eventgroup. + const bool is_selective + = is_selective_event(_service, _instance, _eventgroups); + + if (is_selective) + its_type = vsomeip_v3::event_type_e::ET_SELECTIVE_EVENT; + } + + impl_->offer_event(_service, _instance, _event, _eventgroups, its_type); +} + +void +application_impl::stop_offer_event(service_t _service, instance_t _instance, + event_t _event) { + + impl_->stop_offer_event(_service, _instance, _event); +} + +void +application_impl::request_service(service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor, + bool _use_exclusive_proxy) { + + (void)_use_exclusive_proxy; + impl_->request_service(_service, _instance, _major, _minor); +} + +void +application_impl::release_service(service_t _service, instance_t _instance) { + + impl_->release_service(_service, _instance); +} + +void +application_impl::request_event(service_t _service, instance_t _instance, + event_t _event, const std::set<eventgroup_t> &_eventgroups, + bool _is_field) { + + const vsomeip_v3::event_type_e its_type = (_is_field) ? + vsomeip_v3::event_type_e::ET_FIELD : + vsomeip_v3::event_type_e::ET_EVENT; + impl_->request_event(_service, _instance, _event, _eventgroups, its_type); +} + +void +application_impl::release_event(service_t _service, instance_t _instance, + event_t _event) { + + impl_->release_event(_service, _instance, _event); +} + +void +application_impl::subscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup, major_version_t _major, + subscription_type_e _subscription_type, event_t _event) { + + (void)_subscription_type; // unused in v3 + impl_->subscribe(_service, _instance, _eventgroup, _major, _event); +} + +void +application_impl::unsubscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup) { + + impl_->unsubscribe(_service, _instance, _eventgroup); +} + +bool +application_impl::is_available(service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor) const { + + return impl_->is_available(_service, _instance, _major, _minor); +} + +void +application_impl::send(std::shared_ptr<message> _message, bool _flush = true) { + + (void)_flush; // unused in v3 + if (_message) { + auto its_message = std::dynamic_pointer_cast<message_impl>(_message); + impl_->send(its_message->get_impl()); + } +} + +void +application_impl::notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload) const { + + if (_payload) { + auto its_payload = std::dynamic_pointer_cast<payload_impl>(_payload); + impl_->notify(_service, _instance, _event, its_payload->get_impl()); + } else { + impl_->notify(_service, _instance, _event, nullptr); + } +} + +void +application_impl::notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + client_t _client) const { + + if (_payload) { + auto its_payload = std::dynamic_pointer_cast<payload_impl>(_payload); + impl_->notify_one(_service, _instance, _event, its_payload->get_impl(), _client); + } else { + impl_->notify_one(_service, _instance, _event, nullptr, _client); + } +} + +void +application_impl::register_state_handler(state_handler_t _handler) { + + impl_->register_state_handler( + [_handler](vsomeip_v3::state_type_e _state) { + _handler(static_cast<vsomeip::state_type_e>(_state)); + } + ); +} + +void +application_impl::unregister_state_handler() { + + impl_->unregister_state_handler(); +} + +void +application_impl::register_message_handler( + service_t _service, instance_t _instance, method_t _method, + message_handler_t _handler) { + + impl_->register_message_handler(_service, _instance, _method, + [_handler](const std::shared_ptr<vsomeip_v3::message> &_message) { + auto its_message = std::make_shared<message_impl>(_message); + _handler(its_message); + } + ); +} + +void +application_impl::unregister_message_handler( + service_t _service, instance_t _instance, method_t _method) { + + impl_->unregister_message_handler(_service, _instance, _method); +} + +void +application_impl::register_availability_handler( + service_t _service, instance_t _instance, + availability_handler_t _handler, + major_version_t _major, minor_version_t _minor) { + + impl_->register_availability_handler(_service, _instance, _handler, + _major, _minor); +} + +void +application_impl::unregister_availability_handler( + service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor) { + + impl_->unregister_availability_handler(_service, _instance, _major, _minor); +} + +void +application_impl::register_subscription_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup, + subscription_handler_t _handler) { + { + std::lock_guard<std::mutex> its_lock(eventgroups_mutex_); + eventgroups_[_service][_instance].insert(_eventgroup); + } + + impl_->register_subscription_handler(_service, _instance, _eventgroup, + [_handler](client_t _client, vsomeip::uid_t _uid, + vsomeip::gid_t _gid, bool _accepted){ + (void)_uid; + (void)_gid; + return _handler(_client, _accepted); + } + ); +} + +void +application_impl::unregister_subscription_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup) { + + impl_->unregister_subscription_handler(_service, _instance, _eventgroup); +} + + +// subscription_error_handlers were exclusively used for selective events. +// As selective events use an exclusive eventgroup, the event identifier +// itself is not needed and we can use a dummy. +#define ERROR_HANDLER_DUMMY_EVENT 0xFFFE + +void +application_impl::register_subscription_error_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup, + error_handler_t _handler) { + + impl_->register_subscription_status_handler( + _service, _instance, _eventgroup, ERROR_HANDLER_DUMMY_EVENT, + [_handler](service_t _service, instance_t _instance, + eventgroup_t _eventgroup, event_t _event, + uint16_t _error) { + (void)_service; + (void)_instance; + (void)_eventgroup; + (void)_event; + + _handler(_error); + }, + true + ); +} + +void +application_impl::unregister_subscription_error_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup) { + + impl_->unregister_subscription_status_handler(_service, _instance, + _eventgroup, ERROR_HANDLER_DUMMY_EVENT); +} + +void +application_impl::clear_all_handler() { + + impl_->clear_all_handler(); +} + +bool +application_impl::is_routing() const { + + return impl_->is_routing(); +} + +void +application_impl::offer_event( + service_t _service, instance_t _instance, event_t _event, + const std::set<eventgroup_t> &_eventgroups, + bool _is_field, + std::chrono::milliseconds _cycle, + bool _change_resets_cycle, + const epsilon_change_func_t &_epsilon_change_func) { + + // Set event type + vsomeip_v3::event_type_e its_type(vsomeip_v3::event_type_e::ET_EVENT); + if (_is_field) + its_type = vsomeip_v3::event_type_e::ET_FIELD; + else { + // Find out whether the event is selective. Requires a preceding + // call to "register_subscription_handler". + // Note: The check can be done on the eventgroup(s) as selective + // events own an exclusive eventgroup. + const bool is_selective + = is_selective_event(_service, _instance, _eventgroups); + + if (is_selective) + its_type = vsomeip_v3::event_type_e::ET_SELECTIVE_EVENT; + } + + impl_->offer_event(_service, _instance, _event, _eventgroups, + its_type, _cycle, _change_resets_cycle, true, + [_epsilon_change_func]( + const std::shared_ptr<vsomeip_v3::payload> &_lhs, + const std::shared_ptr<vsomeip_v3::payload> &_rhs) { + auto its_lhs = std::make_shared<payload_impl>(_lhs); + auto its_rhs = std::make_shared<payload_impl>(_rhs); + return _epsilon_change_func(its_lhs, its_rhs); + } + ); +} + +void +application_impl::notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, bool _force) const { + + if (_payload) { + auto its_payload = std::dynamic_pointer_cast<payload_impl>(_payload); + impl_->notify(_service, _instance, _event, its_payload->get_impl(), + _force); + } else { + impl_->notify(_service, _instance, _event, nullptr, _force); + } +} + +void +application_impl::notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + client_t _client, bool _force) const { + + if (_payload) { + auto its_payload = std::dynamic_pointer_cast<payload_impl>(_payload); + impl_->notify_one(_service, _instance, _event, its_payload->get_impl(), + _client, _force); + } else { + impl_->notify_one(_service, _instance, _event, nullptr, _client, + _force); + } +} + +bool +application_impl::are_available(available_t &_available, + service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor) const { + + return impl_->are_available(_available, _service, _instance, _major, + _minor); +} + +void +application_impl::notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + bool _force, bool _flush) const { + + (void)_flush; // unused in v3 + + if (_payload) { + auto its_payload = std::dynamic_pointer_cast<payload_impl>(_payload); + impl_->notify(_service, _instance, _event, its_payload->get_impl(), + _force); + } else { + impl_->notify(_service, _instance, _event, nullptr, _force); + } +} + +void +application_impl::notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr<payload> _payload, + client_t _client, bool _force, bool _flush) const { + + (void)_flush; // unused in v3 + + if (_payload) { + auto its_payload = std::dynamic_pointer_cast<payload_impl>(_payload); + impl_->notify_one(_service, _instance, _event, its_payload->get_impl(), + _client, _force); + } else { + impl_->notify_one(_service, _instance, _event, nullptr, _client, + _force); + } +} + +void +application_impl::set_routing_state(routing_state_e _routing_state) { + + impl_->set_routing_state( + static_cast<vsomeip_v3::routing_state_e>(_routing_state)); +} + +void +application_impl::unsubscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup, event_t _event) { + + impl_->unsubscribe(_service, _instance, _eventgroup, _event); +} + +void +application_impl::register_subscription_status_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, event_t _event, + subscription_status_handler_t _handler) { + + register_subscription_status_handler(_service, _instance, + _eventgroup, _event, _handler, false); +} + +void +application_impl::register_subscription_status_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, event_t _event, + subscription_status_handler_t _handler, bool _is_selective) { + if (_is_selective) { + std::set<vsomeip::eventgroup_t> its_eventgroups; + its_eventgroups.insert(_eventgroup); + // An application may call "register_event" before + // "register_subscription_status_handler". While the call to + // "register_subscription_status_handler" contains the information + // whether an event is selective, the call to "register_event" does + // not. Therefore, we re-register the event with correct event type + // here. + impl_->request_event(_service, _instance, _event, its_eventgroups, + vsomeip_v3::event_type_e::ET_SELECTIVE_EVENT); + } + + impl_->register_subscription_status_handler(_service, _instance, + _eventgroup, _event, + [_handler](const vsomeip_v3::service_t _service, + const vsomeip_v3::instance_t _instance, + const vsomeip_v3::eventgroup_t _eventgroup, + const vsomeip_v3::event_t _event, + const uint16_t _error) { + + if (_handler) + _handler(_service, _instance, _eventgroup, _event, _error); + }, + _is_selective); +} + +void +application_impl::get_offered_services_async( + offer_type_e _offer_type, offered_services_handler_t _handler) { + + impl_->get_offered_services_async( + static_cast<vsomeip_v3::offer_type_e>(_offer_type), _handler); +} + +void +application_impl::set_watchdog_handler( + watchdog_handler_t _handler, std::chrono::seconds _interval) { + + impl_->set_watchdog_handler(_handler, _interval); +} + +void +application_impl::register_async_subscription_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup, + async_subscription_handler_t _handler) { + + { + std::lock_guard<std::mutex> its_lock(eventgroups_mutex_); + eventgroups_[_service][_instance].insert(_eventgroup); + } + impl_->register_async_subscription_handler(_service, _instance, + _eventgroup, [_handler](client_t _client, + vsomeip::uid_t _uid, vsomeip::gid_t _gid, bool _accepted, + std::function<void(const bool)> _handler2) { + (void)_uid; + (void)_gid; + _handler(_client, _accepted, _handler2); + }); +} + +//////////////////////////////////////////////////////////////////////////////// +// The following methods are not implemented as they should only be used by +// plugin implementations that are not intended to run in compatibility mode +//////////////////////////////////////////////////////////////////////////////// +void +application_impl::set_offer_acceptance_required( + ip_address_t _address, const std::string _path, bool _enable) { + + (void)_address; + (void)_path; + (void)_enable; + + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; +} + +vsomeip::application::offer_acceptance_map_type_t +application_impl::get_offer_acceptance_required() { + + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; + return vsomeip::application::offer_acceptance_map_type_t(); +} + +void +application_impl::register_offer_acceptance_handler( + offer_acceptance_handler_t _handler) { + + (void)_handler; + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; +} + +void +application_impl::register_reboot_notification_handler( + reboot_notification_handler_t _handler) { + + (void)_handler; + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; +} + +void +application_impl::register_routing_ready_handler( + routing_ready_handler_t _handler) { + + (void)_handler; + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; +} + +void +application_impl::register_routing_state_handler( + routing_state_handler_t _handler) { + + (void)_handler; + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; +} + +bool +application_impl::update_service_configuration( + service_t _service, instance_t _instance, + std::uint16_t _port, bool _reliable, + bool _magic_cookies_enabled, bool _offer) { + + (void)_service; + (void)_instance; + (void)_port; + (void)_reliable; + (void)_magic_cookies_enabled; + (void)_offer; + + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; + return false; +} + +void +application_impl::update_security_policy_configuration( + uint32_t _uid, uint32_t _gid, + std::shared_ptr<policy> _policy, std::shared_ptr<payload> _payload, + security_update_handler_t _handler) { + + (void)_uid; + (void)_gid; + (void)_policy; + (void)_payload; + (void)_handler; + + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; +} + +void +application_impl::remove_security_policy_configuration( + uint32_t _uid, uint32_t _gid, security_update_handler_t _handler) { + + (void)_uid; + (void)_gid; + (void)_handler; + + VSOMEIP_ERROR << __func__ << ": Must not be called from compatibility layer."; +} + +//////////////////////////////////////////////////////////////////////////////// +// Private helper +//////////////////////////////////////////////////////////////////////////////// + +bool +application_impl::is_selective_event( + vsomeip::service_t _service, vsomeip::instance_t _instance, + const std::set<vsomeip::eventgroup_t> &_eventgroups) { + + bool is_selective(false); + + std::lock_guard<std::mutex> its_events_lock(eventgroups_mutex_); + const auto its_service = eventgroups_.find(_service); + if (its_service != eventgroups_.end()) { + const auto its_instance = its_service->second.find(_instance); + if (its_instance != its_service->second.end()) { + for (const auto eg : _eventgroups) { + const auto its_egrp = its_instance->second.find(eg); + if (its_egrp != its_instance->second.end()) { + is_selective = true; + break; + } + } + } + } + + return is_selective; +} + +} // namespace vsomeip diff --git a/implementation/compat/runtime/src/runtime.cpp b/implementation/compat/runtime/src/runtime.cpp new file mode 100644 index 0000000..40075a8 --- /dev/null +++ b/implementation/compat/runtime/src/runtime.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <compat/vsomeip/runtime.hpp> +#include "../include/runtime_impl.hpp" + +namespace vsomeip { + +std::string +runtime::get_property(const std::string &_name) { + + return runtime_impl::get_property(_name); +} + +void +runtime::set_property(const std::string &_name, const std::string &_value) { + + runtime_impl::set_property(_name, _value); +} + +std::shared_ptr<runtime> +runtime::get() { + + return runtime_impl::get(); +} + +} // namespace vsomeip diff --git a/implementation/compat/runtime/src/runtime_impl.cpp b/implementation/compat/runtime/src/runtime_impl.cpp new file mode 100644 index 0000000..b434e5a --- /dev/null +++ b/implementation/compat/runtime/src/runtime_impl.cpp @@ -0,0 +1,125 @@ +// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <compat/vsomeip/defines.hpp> +#include <vsomeip/runtime.hpp> + +#include "../include/application_impl.hpp" +#include "../include/runtime_impl.hpp" +#include "../../message/include/message_impl.hpp" +#include "../../message/include/payload_impl.hpp" + +namespace vsomeip { + +std::shared_ptr<runtime> runtime_impl::the_runtime_ + = std::make_shared<runtime_impl>(); + +std::string +runtime_impl::get_property(const std::string &_name) { + + return vsomeip_v3::runtime::get_property(_name); +} + +void +runtime_impl::set_property(const std::string &_name, const std::string &_value) { + + vsomeip_v3::runtime::set_property(_name, _value); +} + +std::shared_ptr<runtime> +runtime_impl::get() { + + return the_runtime_; +} + +runtime_impl::~runtime_impl() { +} + +std::shared_ptr<application> +runtime_impl::create_application(const std::string &_name) { + + auto its_application = std::make_shared<application_impl>(_name); + + { + std::lock_guard<std::mutex> its_lock(applications_mutex_); + applications_[its_application->get_name()] = its_application; + } + + return (its_application); +} + +std::shared_ptr<message> +runtime_impl::create_message(bool _reliable) const { + + auto its_impl = vsomeip_v3::runtime::get()->create_message(_reliable); + return (std::make_shared<message_impl>(its_impl)); +} + +std::shared_ptr<message> +runtime_impl::create_request(bool _reliable) const { + + auto its_impl = vsomeip_v3::runtime::get()->create_request(_reliable); + return (std::make_shared<message_impl>(its_impl)); +} + +std::shared_ptr<message> +runtime_impl::create_response(const std::shared_ptr<message> &_request) const { + + auto its_request = std::dynamic_pointer_cast<message_impl>(_request); + auto its_impl = vsomeip_v3::runtime::get()->create_response( + its_request->get_impl()); + return (std::make_shared<message_impl>(its_impl)); +} + +std::shared_ptr<message> +runtime_impl::create_notification(bool _reliable) const { + + auto its_impl = vsomeip_v3::runtime::get()->create_notification(_reliable); + return (std::make_shared<message_impl>(its_impl)); +} + +std::shared_ptr<payload> +runtime_impl::create_payload() const { + + auto its_impl = vsomeip_v3::runtime::get()->create_payload(); + return (std::make_shared<payload_impl>(its_impl)); +} + +std::shared_ptr<payload> +runtime_impl::create_payload(const byte_t *_data, uint32_t _size) const { + + auto its_impl = vsomeip_v3::runtime::get()->create_payload(_data, _size); + return (std::make_shared<payload_impl>(its_impl)); +} + +std::shared_ptr<payload> +runtime_impl::create_payload(const std::vector<byte_t> &_data) const { + + auto its_impl = vsomeip_v3::runtime::get()->create_payload(_data); + return (std::make_shared<payload_impl>(its_impl)); +} + +std::shared_ptr<application> +runtime_impl::get_application(const std::string &_name) const { + + std::lock_guard<std::mutex> its_lock(applications_mutex_); + auto found_application = applications_.find(_name); + if (found_application != applications_.end()) + return found_application->second.lock(); + + return (nullptr); +} + +void +runtime_impl::remove_application(const std::string &_name) { + + std::lock_guard<std::mutex> its_lock(applications_mutex_); + auto found_application = applications_.find(_name); + if(found_application != applications_.end()) { + applications_.erase(_name); + } +} + +} // namespace vsomeip |