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_HANDLER_HPP_
7 #define VSOMEIP_V3_HANDLER_HPP_
8 
9 #include <functional>
10 #include <memory>
11 #include <tuple>
12 
13 #include <vsomeip/primitive_types.hpp>
14 
15 namespace vsomeip_v3 {
16 
17 class message;
18 
19 typedef std::function< void (state_type_e) > state_handler_t;
20 typedef std::function< void (const std::shared_ptr< message > &) > message_handler_t;
21 typedef std::function< void (service_t, instance_t, bool) > availability_handler_t;
22 typedef std::function< bool (client_t, uid_t, gid_t, bool) > subscription_handler_t;
23 typedef std::function< void (const uint16_t) > error_handler_t;
24 typedef std::function< void (const service_t, const instance_t, const eventgroup_t,
25                              const event_t, const uint16_t) > subscription_status_handler_t;
26 typedef std::function< void (client_t, uid_t, gid_t, bool, std::function< void (const bool) > )> async_subscription_handler_t;
27 
28 typedef std::function< void (const std::vector<std::pair<service_t, instance_t>> &_services) > offered_services_handler_t;
29 typedef std::function< void () > watchdog_handler_t;
30 
31 struct ip_address_t {
32     union {
33         ipv4_address_t v4_;
34         ipv6_address_t v6_;
35     } address_;
36     bool is_v4_;
37 
operator <vsomeip_v3::ip_address_t38     bool operator<(const ip_address_t& _other) const {
39         if (is_v4_ && _other.is_v4_) {
40             return address_.v4_ < _other.address_.v4_;
41         } else if (!is_v4_ && !_other.is_v4_) {
42             return address_.v6_ < _other.address_.v6_;
43         } else if (is_v4_ && !_other.is_v4_) {
44             return true;
45         } else {
46             return false;
47         }
48     }
49 
operator ==vsomeip_v3::ip_address_t50     bool operator==(const ip_address_t& _other) const {
51         if (is_v4_ && _other.is_v4_) {
52             return address_.v4_ == _other.address_.v4_;
53         } else if (!is_v4_ && !_other.is_v4_) {
54             return address_.v6_ == _other.address_.v6_;
55         } else {
56             return false;
57         }
58     }
59 
operator !=vsomeip_v3::ip_address_t60     bool operator!=(const ip_address_t& _other) const {
61         return !(*this == _other);
62     }
63 
64 };
65 
66 struct remote_info_t {
67     ip_address_t ip_;
68     std::uint16_t first_;
69     std::uint16_t last_;
70     bool is_range_;
71     bool is_reliable_;
72 
operator <vsomeip_v3::remote_info_t73     bool operator<(const remote_info_t& _other) const {
74         return std::tie(ip_, first_, last_, is_range_, is_reliable_) <
75                 std::tie(_other.ip_, _other.first_, _other.last_,
76                          _other.is_range_, _other.is_reliable_);
77     }
78 };
79 
80 typedef std::function<bool(const remote_info_t&)> sd_acceptance_handler_t;
81 typedef std::function<void(const ip_address_t&)> reboot_notification_handler_t;
82 typedef std::function<void()> routing_ready_handler_t;
83 typedef std::function<void(routing_state_e)> routing_state_handler_t;
84 typedef std::function<void(security_update_state_e)> security_update_handler_t;
85 
86 } // namespace vsomeip_v3
87 
88 #endif // VSOMEIP_V3_HANDLER_HPP_
89