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_UDP_CLIENT_ENDPOINT_IMPL_HPP_
7  #define VSOMEIP_V3_UDP_CLIENT_ENDPOINT_IMPL_HPP_
8  
9  #include <memory>
10  
11  #include <boost/asio/io_service.hpp>
12  #include <boost/asio/strand.hpp>
13  #include <boost/asio/ip/udp.hpp>
14  
15  #include <vsomeip/defines.hpp>
16  
17  #include "client_endpoint_impl.hpp"
18  #include "tp_reassembler.hpp"
19  
20  namespace vsomeip_v3 {
21  
22  class endpoint_adapter;
23  
24  typedef client_endpoint_impl<
25              boost::asio::ip::udp
26          > udp_client_endpoint_base_impl;
27  
28  class udp_client_endpoint_impl: virtual public udp_client_endpoint_base_impl {
29  
30  public:
31      udp_client_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                               const endpoint_type& _remote,
35                               boost::asio::io_service &_io,
36                               const std::shared_ptr<configuration>& _configuration);
37      virtual ~udp_client_endpoint_impl();
38  
39      void start();
40      void restart(bool _force);
41  
42      void receive_cbk(boost::system::error_code const &_error,
43                       std::size_t _bytes, const message_buffer_ptr_t& _recv_buffer);
44  
45      bool get_remote_address(boost::asio::ip::address &_address) const;
46      std::uint16_t get_remote_port() const;
47      bool is_local() const;
48      void print_status();
49      bool is_reliable() const;
50  
51      void send_cbk(boost::system::error_code const &_error, std::size_t _bytes,
52                    const message_buffer_ptr_t &_sent_msg);
53  private:
54      void send_queued(message_buffer_ptr_t _buffer);
55      void get_configured_times_from_endpoint(
56              service_t _service, method_t _method,
57              std::chrono::nanoseconds *_debouncing,
58              std::chrono::nanoseconds *_maximum_retention) const;
59      void connect();
60      void receive();
61      void set_local_port();
62      const std::string get_address_port_remote() const;
63      const std::string get_address_port_local() const;
64      std::string get_remote_information() const;
65      bool tp_segmentation_enabled(service_t _service, method_t _method) const;
66      std::uint32_t get_max_allowed_reconnects() const;
67      void max_allowed_reconnects_reached();
68  
69  private:
70      const boost::asio::ip::address remote_address_;
71      const std::uint16_t remote_port_;
72      int udp_receive_buffer_size_;
73      std::shared_ptr<tp::tp_reassembler> tp_reassembler_;
74  };
75  
76  } // namespace vsomeip_v3
77  
78  #endif // VSOMEIP_V3_UDP_CLIENT_ENDPOINT_IMPL_HPP_
79