1 // Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) 2 // This Source Code Form is subject to the terms of the Mozilla Public 3 // License, v. 2.0. If a copy of the MPL was not distributed with this 4 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 #ifndef VSOMEIP_V3_ENDPOINT_IMPL_HPP_ 7 #define VSOMEIP_V3_ENDPOINT_IMPL_HPP_ 8 9 #include <map> 10 #include <memory> 11 #include <mutex> 12 #include <atomic> 13 14 #include <boost/asio/io_service.hpp> 15 #include <boost/asio/steady_timer.hpp> 16 17 #include "buffer.hpp" 18 #include "endpoint.hpp" 19 #include "../../configuration/include/configuration.hpp" 20 21 namespace vsomeip_v3 { 22 23 class endpoint_host; 24 class routing_host; 25 26 template<typename Protocol> 27 class endpoint_impl: public virtual endpoint { 28 public: 29 typedef typename Protocol::endpoint endpoint_type; 30 31 endpoint_impl(const std::shared_ptr<endpoint_host>& _endpoint_host, 32 const std::shared_ptr<routing_host>& _routing_host, 33 const endpoint_type& _local, 34 boost::asio::io_service &_io, 35 std::uint32_t _max_message_size, 36 configuration::endpoint_queue_limit_t _queue_limit, 37 const std::shared_ptr<configuration>& _configuration); 38 virtual ~endpoint_impl(); 39 40 void enable_magic_cookies(); 41 42 void add_default_target(service_t, const std::string &, uint16_t); 43 void remove_default_target(service_t); 44 45 virtual std::uint16_t get_local_port() const = 0; 46 virtual void set_local_port(uint16_t _port) = 0; 47 virtual bool is_reliable() const = 0; 48 49 void increment_use_count(); 50 void decrement_use_count(); 51 uint32_t get_use_count(); 52 53 void register_error_handler(error_handler_t _error_handler); 54 virtual void print_status() = 0; 55 56 virtual size_t get_queue_size() const = 0; 57 58 public: 59 // required 60 virtual bool is_client() const = 0; 61 virtual void receive() = 0; 62 virtual void restart(bool _force) = 0; 63 64 protected: 65 uint32_t find_magic_cookie(byte_t *_buffer, size_t _size); 66 67 protected: 68 enum class cms_ret_e : uint8_t { 69 MSG_TOO_BIG, 70 MSG_OK, 71 MSG_WAS_SPLIT 72 }; 73 74 // Reference to service context 75 boost::asio::io_service &service_; 76 77 // References to hosts 78 std::weak_ptr<endpoint_host> endpoint_host_; 79 std::weak_ptr<routing_host> routing_host_; 80 81 bool is_supporting_magic_cookies_; 82 std::atomic<bool> has_enabled_magic_cookies_; 83 84 // Filter configuration 85 std::map<service_t, uint8_t> opened_; 86 87 std::uint32_t max_message_size_; 88 89 std::atomic<uint32_t> use_count_; 90 91 std::atomic<bool> sending_blocked_; 92 93 std::mutex local_mutex_; 94 endpoint_type local_; 95 96 error_handler_t error_handler_; 97 std::mutex error_handler_mutex_; 98 99 const configuration::endpoint_queue_limit_t queue_limit_; 100 101 std::shared_ptr<configuration> configuration_; 102 103 bool is_supporting_someip_tp_; 104 }; 105 106 } // namespace vsomeip_v3 107 108 #endif // VSOMEIP_V3_ENDPOINT_IMPL_HPP_ 109