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_VIRTUAL_SERVER_ENDPOINT_IMPL_HPP_
7 #define VSOMEIP_V3_VIRTUAL_SERVER_ENDPOINT_IMPL_HPP_
8 
9 #include <boost/asio/io_service.hpp>
10 
11 #include <vsomeip/primitive_types.hpp>
12 
13 #include "../include/endpoint.hpp"
14 
15 namespace vsomeip_v3 {
16 
17 class virtual_server_endpoint_impl : public endpoint, public std::enable_shared_from_this<virtual_server_endpoint_impl> {
18 public:
19     virtual_server_endpoint_impl(
20             const std::string &_address,
21             uint16_t _port,
22             bool _reliable,
23             boost::asio::io_service& _service);
24 
25     virtual ~virtual_server_endpoint_impl();
26 
27     void start();
28     void prepare_stop(endpoint::prepare_stop_handler_t _handler,
29                       service_t _service);
30     void stop();
31 
32     bool is_established() const;
33     bool is_established_or_connected() const;
34     void set_established(bool _established);
35     void set_connected(bool _connected);
36 
37     bool send(const byte_t *_data, uint32_t _size);
38     bool send(const std::vector<byte_t>& _cmd_header, const byte_t *_data,
39               uint32_t _size);
40     bool send_to(const std::shared_ptr<endpoint_definition> _target,
41             const byte_t *_data, uint32_t _size);
42     bool send_error(const std::shared_ptr<endpoint_definition> _target,
43             const byte_t *_data, uint32_t _size);
44     void enable_magic_cookies();
45     void receive();
46 
47     void add_default_target(service_t _service,
48             const std::string &_address, uint16_t _port);
49     void remove_default_target(service_t _service);
50 
51     bool get_remote_address(boost::asio::ip::address &_address) const;
52     std::uint16_t get_local_port() const;
53     void set_local_port(uint16_t _port);
54     std::uint16_t get_remote_port() const;
55     bool is_reliable() const;
56     bool is_local() const;
57 
58     void increment_use_count();
59     void decrement_use_count();
60     uint32_t get_use_count();
61 
62     void restart(bool _force);
63 
64     void register_error_handler(error_handler_t _handler);
65     void print_status();
66 
67     size_t get_queue_size() const;
68 
69 private:
70     std::string address_;
71     uint16_t port_;
72     bool reliable_;
73 
74     uint32_t use_count_;
75     boost::asio::io_service& service_;
76 };
77 
78 } // namespace vsomeip_v3
79 
80 #endif // VSOMEIP_V3_VIRTUAL_SERVER_ENDPOINT_IMPL_HPP_
81