diff options
Diffstat (limited to 'implementation/utility/include/utility.hpp')
-rw-r--r-- | implementation/utility/include/utility.hpp | 83 |
1 files changed, 55 insertions, 28 deletions
diff --git a/implementation/utility/include/utility.hpp b/implementation/utility/include/utility.hpp index 359bc7c..970fb0f 100644 --- a/implementation/utility/include/utility.hpp +++ b/implementation/utility/include/utility.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. @@ -6,11 +6,12 @@ #ifndef VSOMEIP_V3_UTILITY_HPP #define VSOMEIP_V3_UTILITY_HPP +#include <atomic> +#include <chrono> #include <map> -#include <set> #include <memory> +#include <set> #include <vector> -#include <atomic> #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -19,6 +20,8 @@ #include <vsomeip/enumeration_types.hpp> #include <vsomeip/message.hpp> +#include <vsomeip/vsomeip_sec.h> + #include "criticalsection.hpp" namespace vsomeip_v3 { @@ -36,7 +39,9 @@ public: } static inline bool is_request(message_type_e _type) { - return (_type < message_type_e::MT_NOTIFICATION); + return ((_type < message_type_e::MT_NOTIFICATION) + || (_type >= message_type_e::MT_REQUEST_ACK + && _type <= message_type_e::MT_REQUEST_NO_RETURN_ACK)); } static inline bool is_request_no_return(std::shared_ptr<message> _message) { @@ -68,10 +73,6 @@ public: return _type == message_type_e::MT_ERROR; } - static inline bool is_event(byte_t _data) { - return (0x80 & _data) > 0; - } - static inline bool is_notification(byte_t _type) { return (is_notification(static_cast<message_type_e>(_type))); } @@ -90,19 +91,20 @@ public: static uint32_t get_payload_size(const byte_t *_data, uint32_t _size); - static bool is_routing_manager(const std::shared_ptr<configuration> &_config); - static void remove_lockfile(const std::shared_ptr<configuration> &_config); + static bool is_routing_manager(const std::string &_network); + static void remove_lockfile(const std::string &_network); static bool exists(const std::string &_path); static bool VSOMEIP_IMPORT_EXPORT is_file(const std::string &_path); static bool VSOMEIP_IMPORT_EXPORT is_folder(const std::string &_path); - static const std::string get_base_path(const std::shared_ptr<configuration> &_config); + static std::string get_base_path(const std::string &_network); static client_t request_client_id(const std::shared_ptr<configuration> &_config, const std::string &_name, client_t _client); - static void release_client_id(client_t _client); - static std::set<client_t> get_used_client_ids(); - static void reset_client_ids(); + static void release_client_id(const std::string &_network, + client_t _client); + static std::set<client_t> get_used_client_ids(const std::string &_network); + static void reset_client_ids(const std::string &_network); static inline bool is_valid_message_type(message_type_e _type) { return (_type == message_type_e::MT_REQUEST @@ -129,27 +131,52 @@ public: || _code == return_code_e::E_WRONG_PROTOCOL_VERSION || _code == return_code_e::E_WRONG_INTERFACE_VERSION || _code == return_code_e::E_MALFORMED_MESSAGE - || _code == return_code_e::E_WRONG_MESSAGE_TYPE - || (static_cast<std::uint8_t>(_code) >= 0x20 - && static_cast<std::uint8_t>(_code) <= 0x5E)); + || _code == return_code_e::E_WRONG_MESSAGE_TYPE); + } + + static inline bool compare(const vsomeip_sec_client_t &_lhs, + const vsomeip_sec_client_t &_rhs) { + + bool is_equal(false); + if (_lhs.client_type == _rhs.client_type) { + switch (_lhs.client_type) { + case VSOMEIP_CLIENT_INVALID: + is_equal = true; + break; + case VSOMEIP_CLIENT_UDS: + is_equal = (_lhs.client.uds_client.user == _rhs.client.uds_client.user + && _lhs.client.uds_client.group == _rhs.client.uds_client.group); + break; + case VSOMEIP_CLIENT_TCP: + is_equal = (_lhs.client.ip_client.ip == _rhs.client.ip_client.ip + && _lhs.client.ip_client.port == _rhs.client.ip_client.port); + break; + default: + break; + } + } + return (is_equal); } private: - static std::uint16_t get_max_client_number(const std::shared_ptr<configuration> &_config); + struct data_t { + data_t(); - static std::mutex mutex__; - static client_t next_client__; - static std::map<client_t, std::string> used_clients__; + client_t next_client_; + std::map<client_t, std::string> used_clients_; #ifdef _WIN32 - static HANDLE lock_handle__; -#else - static int lock_fd__; -#endif -#ifndef VSOMEIP_ENABLE_CONFIGURATION_OVERLAYS - static bool is_checked__; + HANDLE lock_handle_; #else - static std::set<std::string> is_checked__; + int lock_fd_; #endif + }; + +private: + static std::uint16_t get_max_client_number( + const std::shared_ptr<configuration> &_config); + + static std::mutex mutex__; + static std::map<std::string, data_t> data__; // network --> data }; } // namespace vsomeip_v3 |