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_SD_SUBSCRIPTION_HPP_
7 #define VSOMEIP_V3_SD_SUBSCRIPTION_HPP_
8 
9 #include <map>
10 #include <memory>
11 #include <mutex>
12 #include <set>
13 
14 #include <vsomeip/primitive_types.hpp>
15 #include <vsomeip/enumeration_types.hpp>
16 
17 namespace vsomeip_v3 {
18 
19 class endpoint;
20 class eventgroupinfo;
21 
22 namespace sd {
23 
24 enum class subscription_state_e : uint8_t {
25     ST_ACKNOWLEDGED = 0x00,
26     ST_NOT_ACKNOWLEDGED = 0x01,
27     ST_RESUBSCRIBING = 0x2,
28     ST_RESUBSCRIBING_NOT_ACKNOWLEDGED = 0x3,
29     ST_UNKNOWN = 0xFF
30 };
31 
32 class subscription {
33 public:
34     subscription() = default;
35     ~subscription() = default;
36 
37     major_version_t get_major() const;
38     void set_major(major_version_t _major);
39 
40     ttl_t get_ttl() const;
41     void set_ttl(ttl_t _ttl);
42 
43     std::shared_ptr<endpoint> get_endpoint(bool _reliable) const;
44     void set_endpoint(const std::shared_ptr<endpoint>& _endpoint, bool _reliable);
45 
46     bool is_selective() const;
47     void set_selective(const bool _is_selective);
48 
49     subscription_state_e get_state(const client_t _client) const;
50     void set_state(const client_t _client, subscription_state_e _state);
51 
52     bool is_tcp_connection_established() const;
53     void set_tcp_connection_established(bool _is_established);
54 
55     bool is_udp_connection_established() const;
56     void set_udp_connection_established(bool _is_established);
57 
58     bool add_client(const client_t _client);
59     bool remove_client(const client_t _client);
60     std::set<client_t> get_clients() const;
61     bool has_client() const;
62     bool has_client(const client_t _client) const;
63 
64     void set_eventgroupinfo(const std::shared_ptr<eventgroupinfo> _info);
65     std::weak_ptr<eventgroupinfo> get_eventgroupinfo() const;
66 
67 private:
68     major_version_t major_;
69     ttl_t ttl_;
70 
71     std::shared_ptr<endpoint> reliable_;
72     std::shared_ptr<endpoint> unreliable_;
73 
74     bool is_selective_;
75 
76     bool tcp_connection_established_;
77     bool udp_connection_established_;
78 
79     mutable std::mutex clients_mutex_;
80     std::map<client_t, subscription_state_e> clients_; // client-> is acknowledged?
81 
82     std::weak_ptr<eventgroupinfo> eg_info_;
83 };
84 
85 } // namespace sd
86 } // namespace vsomeip_v3
87 
88 #endif // VSOMEIP_V3_SD_SUBSCRIPTION_HPP_
89 
90