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 #include <vsomeip/constants.hpp>
7 
8 #include "../include/endpoint_definition.hpp"
9 
10 namespace vsomeip_v3 {
11 
12 std::map<std::tuple<service_t, instance_t, boost::asio::ip::address, uint16_t, bool>,
13          std::shared_ptr<endpoint_definition> > endpoint_definition::definitions_;
14 
15 std::mutex endpoint_definition::definitions_mutex_;
16 
17 std::shared_ptr<endpoint_definition>
get(const boost::asio::ip::address & _address,uint16_t _port,bool _is_reliable,service_t _service,instance_t _instance)18 endpoint_definition::get(const boost::asio::ip::address &_address,
19                          uint16_t _port, bool _is_reliable, service_t _service, instance_t _instance) {
20     auto key = std::make_tuple(_service, _instance, _address, _port, _is_reliable);
21     std::lock_guard<std::mutex> its_lock(definitions_mutex_);
22     std::shared_ptr<endpoint_definition> its_result;
23 
24     auto found_endpoint = definitions_.find(key);
25     if (found_endpoint != definitions_.end()) {
26         its_result = found_endpoint->second;
27     }
28 
29     if (!its_result) {
30             its_result = std::make_shared<endpoint_definition>(
31                              _address, _port, _is_reliable);
32             definitions_[key] = its_result;
33     }
34 
35     return its_result;
36 }
37 
endpoint_definition(const boost::asio::ip::address & _address,uint16_t _port,bool _is_reliable)38 endpoint_definition::endpoint_definition(
39         const boost::asio::ip::address &_address, uint16_t _port,
40         bool _is_reliable)
41         : address_(_address), port_(_port), remote_port_(_port),
42           is_reliable_(_is_reliable) {
43 }
44 
get_address() const45 const boost::asio::ip::address & endpoint_definition::get_address() const {
46     return address_;
47 }
48 
get_port() const49 uint16_t endpoint_definition::get_port() const {
50     return port_;
51 }
52 
is_reliable() const53 bool endpoint_definition::is_reliable() const {
54     return is_reliable_;
55 }
56 
get_remote_port() const57 uint16_t endpoint_definition::get_remote_port() const {
58     return remote_port_;
59 }
60 
set_remote_port(uint16_t _port)61 void endpoint_definition::set_remote_port(uint16_t _port) {
62     remote_port_ = _port;
63 }
64 
65 
66 } // namespace vsomeip_v3
67