1 // Copyright (C) 2014-2018 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_SERVICE_DISCOVERY_HOST_HPP_
7 #define VSOMEIP_V3_SERVICE_DISCOVERY_HOST_HPP_
8 
9 #include <map>
10 #include <memory>
11 #include <chrono>
12 
13 #include <boost/asio/ip/address.hpp>
14 #include <boost/asio/io_service.hpp>
15 
16 #include "../../routing/include/function_types.hpp"
17 #include "../../routing/include/types.hpp"
18 
19 #include <vsomeip/message.hpp>
20 
21 namespace vsomeip_v3 {
22 
23 class configuration;
24 class endpoint;
25 class endpoint_definition;
26 
27 namespace sd {
28 
29 class service_discovery_host {
30 public:
~service_discovery_host()31     virtual ~service_discovery_host() {
32     }
33 
34     virtual boost::asio::io_service & get_io() = 0;
35 
36     virtual std::shared_ptr<endpoint> create_service_discovery_endpoint(
37             const std::string &_address, uint16_t _port, bool _reliable) = 0;
38 
39     virtual services_t get_offered_services() const = 0;
40     virtual std::shared_ptr<eventgroupinfo> find_eventgroup(service_t _service,
41             instance_t _instance, eventgroup_t _eventgroup) const = 0;
42 
43     virtual bool send(client_t _client, std::shared_ptr<message> _message) = 0;
44 
45     virtual bool send_via_sd(const std::shared_ptr<endpoint_definition> &_target,
46             const byte_t *_data, uint32_t _size, uint16_t _sd_port) = 0;
47 
48     virtual void add_routing_info(service_t _service, instance_t _instance,
49             major_version_t _major, minor_version_t _minor, ttl_t _ttl,
50             const boost::asio::ip::address &_reliable_address,
51             uint16_t _reliable_port,
52             const boost::asio::ip::address &_unreliable_address,
53             uint16_t _unreliable_port) = 0;
54 
55     virtual void del_routing_info(service_t _service, instance_t _instance,
56             bool _has_reliable, bool _has_unreliable) = 0;
57 
58     virtual void update_routing_info(std::chrono::milliseconds _elapsed) = 0;
59 
60     virtual void on_remote_unsubscribe(
61             std::shared_ptr<remote_subscription> &_subscription) = 0;
62 
63     virtual void on_subscribe_ack(client_t _client,
64             service_t _service, instance_t _instance, eventgroup_t _eventgroup,
65             event_t _event, remote_subscription_id_t _subscription_id) = 0;
66 
67     virtual void on_subscribe_ack_with_multicast(
68             service_t _service, instance_t _instance,
69             const boost::asio::ip::address &_sender,
70             const boost::asio::ip::address &_address, uint16_t _port) = 0;
71 
72     virtual std::shared_ptr<endpoint> find_or_create_remote_client(
73             service_t _service, instance_t _instance, bool _reliable) = 0;
74 
75     virtual void expire_subscriptions(const boost::asio::ip::address &_address) = 0;
76     virtual void expire_subscriptions(const boost::asio::ip::address &_address,
77                                       std::uint16_t _port, bool _reliable) = 0;
78     virtual void expire_services(const boost::asio::ip::address &_address) = 0;
79     virtual void expire_services(const boost::asio::ip::address &_address,
80                                  std::uint16_t _port, bool _reliable) = 0;
81 
82 
83     virtual void on_remote_subscribe(
84             std::shared_ptr<remote_subscription> &_subscription,
85             const remote_subscription_callback_t& _callback) = 0;
86 
87     virtual void on_subscribe_nack(client_t _client,
88             service_t _service, instance_t _instance, eventgroup_t _eventgroup,
89             event_t _event, remote_subscription_id_t _subscription_id, bool _simulated) = 0;
90 
91     virtual std::chrono::steady_clock::time_point expire_subscriptions(bool _force) = 0;
92 
93     virtual std::shared_ptr<serviceinfo> get_offered_service(
94             service_t _service, instance_t _instance) const = 0;
95     virtual std::map<instance_t, std::shared_ptr<serviceinfo>> get_offered_service_instances(
96             service_t _service) const = 0;
97 
98     virtual std::set<eventgroup_t> get_subscribed_eventgroups(service_t _service,
99             instance_t _instance) = 0;
100 };
101 
102 }  // namespace sd
103 }  // namespace vsomeip_v3
104 
105 #endif // VSOMEIP_V3_SERVICE_DISCOVERY_HOST_HPP_
106 
107