summaryrefslogtreecommitdiff
path: root/implementation/routing/include/eventgroupinfo.hpp
blob: 32ce5f280b078fe0ff74e5aa229173f9cc7341da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef VSOMEIP_V3_EVENTGROUPINFO_HPP_
#define VSOMEIP_V3_EVENTGROUPINFO_HPP_

#include <atomic>
#include <chrono>
#include <list>
#include <memory>
#include <mutex>
#include <set>
#include <vector>

#include <boost/asio/ip/address.hpp>

#include <vsomeip/export.hpp>
#include <vsomeip/primitive_types.hpp>

#include "remote_subscription.hpp"
#include "types.hpp"

namespace vsomeip_v3 {

class endpoint_definition;
class event;

class eventgroupinfo {
public:
    struct subscription_t {
        std::shared_ptr<remote_subscription> subscription_;
        std::chrono::steady_clock::time_point expiration_;

        bool operator==(const subscription_t &_other) const {
            return (subscription_ == _other.subscription_);
        }
    };

    VSOMEIP_EXPORT eventgroupinfo();
    VSOMEIP_EXPORT eventgroupinfo(
            const service_t _service, const service_t _instance,
            const eventgroup_t _eventgroup, const major_version_t _major,
            const ttl_t _ttl);
    VSOMEIP_EXPORT ~eventgroupinfo();

    VSOMEIP_EXPORT service_t get_service() const;
    VSOMEIP_EXPORT void set_service(const service_t _service);

    VSOMEIP_EXPORT instance_t get_instance() const;
    VSOMEIP_EXPORT void set_instance(const instance_t _instance);

    VSOMEIP_EXPORT eventgroup_t get_eventgroup() const;
    VSOMEIP_EXPORT void set_eventgroup(const eventgroup_t _eventgroup);

    VSOMEIP_EXPORT major_version_t get_major() const;
    VSOMEIP_EXPORT void set_major(const major_version_t _major);

    VSOMEIP_EXPORT ttl_t get_ttl() const;
    VSOMEIP_EXPORT void set_ttl(const ttl_t _ttl);

    VSOMEIP_EXPORT bool is_multicast() const;
    VSOMEIP_EXPORT bool get_multicast(boost::asio::ip::address &_address,
            uint16_t &_port) const;
    VSOMEIP_EXPORT void set_multicast(const boost::asio::ip::address &_address,
            uint16_t _port);
    VSOMEIP_EXPORT bool is_sending_multicast() const;

    VSOMEIP_EXPORT const std::set<std::shared_ptr<event> > get_events() const;
    VSOMEIP_EXPORT void add_event(const std::shared_ptr<event>& _event);
    VSOMEIP_EXPORT void remove_event(const std::shared_ptr<event>& _event);
    VSOMEIP_EXPORT reliability_type_e get_reliability() const;
    VSOMEIP_EXPORT void set_reliability(reliability_type_e _reliability);
    VSOMEIP_EXPORT bool is_reliability_auto_mode() const;

    VSOMEIP_EXPORT std::set<std::shared_ptr<remote_subscription>>
            get_remote_subscriptions() const;

    std::shared_ptr<remote_subscription> get_remote_subscription(
            const remote_subscription_id_t _id);

    bool update_remote_subscription(
            const std::shared_ptr<remote_subscription> &_subscription,
            const std::chrono::steady_clock::time_point &_expiration,
            std::set<client_t> &_changed, remote_subscription_id_t &_id,
            const bool _is_subscribe);

    remote_subscription_id_t add_remote_subscription(
            const std::shared_ptr<remote_subscription> &_subscription);

    VSOMEIP_EXPORT void remove_remote_subscription(
            const remote_subscription_id_t _id);

    void clear_remote_subscriptions();

    VSOMEIP_EXPORT std::set<std::shared_ptr<endpoint_definition> >
    get_unicast_targets() const;
    VSOMEIP_EXPORT std::set<std::shared_ptr<endpoint_definition> >
    get_multicast_targets() const;

    VSOMEIP_EXPORT uint8_t get_threshold() const;
    VSOMEIP_EXPORT void set_threshold(uint8_t _threshold);

    VSOMEIP_EXPORT bool is_selective() const;

    VSOMEIP_EXPORT void send_initial_events(
            const std::shared_ptr<endpoint_definition> &_reliable,
            const std::shared_ptr<endpoint_definition> &_unreliable) const;
private:
    void update_id();
    uint32_t get_unreliable_target_count() const;

    std::atomic<service_t> service_;
    std::atomic<instance_t> instance_;
    std::atomic<eventgroup_t> eventgroup_;
    std::atomic<major_version_t> major_;
    std::atomic<ttl_t> ttl_;

    mutable std::mutex address_mutex_;
    boost::asio::ip::address address_;
    uint16_t port_;

    mutable std::mutex events_mutex_;
    std::set<std::shared_ptr<event> > events_;

    std::atomic<uint8_t> threshold_;

    mutable std::mutex subscriptions_mutex_;
    std::map<remote_subscription_id_t,
        std::shared_ptr<remote_subscription>
    > subscriptions_;
    remote_subscription_id_t id_;

    std::atomic<reliability_type_e> reliability_;
    std::atomic<bool> reliability_auto_mode_;
};

} // namespace vsomeip_v3

#endif // VSOMEIP_V3_EVENTGROUPINFO_HPP_