summaryrefslogtreecommitdiff
path: root/implementation/routing/include/types.hpp
blob: 59acfa36c5c3b95346a3f0e9052a7a6d45af6b6c (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
// 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_ROUTING_TYPES_HPP
#define VSOMEIP_ROUTING_TYPES_HPP

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

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

#include "../../service_discovery/include/message_impl.hpp"
#include "../../configuration/include/internal.hpp"

namespace vsomeip {

class serviceinfo;
class endpoint_definition;


typedef std::map<service_t,
                 std::map<instance_t,
                          std::shared_ptr<serviceinfo> > > services_t;

class eventgroupinfo;

typedef std::map<service_t,
                 std::map<instance_t,
                          std::map<eventgroup_t,
                                   std::shared_ptr<
                                       eventgroupinfo> > > > eventgroups_t;

enum class registration_type_e : std::uint8_t {
    REGISTER = 0x1,
    DEREGISTER = 0x2,
    DEREGISTER_ON_ERROR = 0x3
};

struct sd_message_identifier_t {
    sd_message_identifier_t(session_t _session,
                            boost::asio::ip::address _sender,
                            boost::asio::ip::address _destination,
                            const std::shared_ptr<sd::message_impl> &_response) :
            session_(_session),
            sender_(_sender),
            destination_(_destination),
            response_(_response) {
    }

    sd_message_identifier_t() :
        session_(0),
        sender_(boost::asio::ip::address()),
        destination_(boost::asio::ip::address()),
        response_(std::shared_ptr<sd::message_impl>()) {
    }

    bool operator==(const sd_message_identifier_t &_other) const {
        return !(session_ != _other.session_ ||
                sender_ != _other.sender_ ||
                destination_ != _other.destination_ ||
                response_ != _other.response_);
    }

    bool operator<(const sd_message_identifier_t &_other) const {
        return (session_ < _other.session_
                || (session_ == _other.session_ && sender_ < _other.sender_)
                || (session_ == _other.session_ && sender_ == _other.sender_
                        && destination_ < _other.destination_)
                || (session_ == _other.session_ && sender_ == _other.sender_
                        && destination_ == _other.destination_
                        && response_ < _other.response_));
    }

    session_t session_;
    boost::asio::ip::address sender_;
    boost::asio::ip::address destination_;
    std::shared_ptr<sd::message_impl> response_;
};

struct pending_subscription_t {
    pending_subscription_t(
            std::shared_ptr<sd_message_identifier_t> _sd_message_identifier,
            std::shared_ptr<endpoint_definition> _subscriber,
            std::shared_ptr<endpoint_definition> _target,
            ttl_t _ttl,
            client_t _subscribing_client) :
            sd_message_identifier_(_sd_message_identifier),
            subscriber_(_subscriber),
            target_(_target),
            ttl_(_ttl),
            subscribing_client_(_subscribing_client),
            pending_subscription_id_(DEFAULT_SUBSCRIPTION) {
    }
    pending_subscription_t () :
        sd_message_identifier_(std::shared_ptr<sd_message_identifier_t>()),
        subscriber_(std::shared_ptr<endpoint_definition>()),
        target_(std::shared_ptr<endpoint_definition>()),
        ttl_(0),
        subscribing_client_(VSOMEIP_ROUTING_CLIENT),
        pending_subscription_id_(DEFAULT_SUBSCRIPTION) {
    }
    std::shared_ptr<sd_message_identifier_t> sd_message_identifier_;
    std::shared_ptr<endpoint_definition> subscriber_;
    std::shared_ptr<endpoint_definition> target_;
    ttl_t ttl_;
    client_t subscribing_client_;
    pending_subscription_id_t pending_subscription_id_;
};

enum remote_subscription_state_e : std::uint8_t {
    SUBSCRIPTION_ACKED,
    SUBSCRIPTION_NACKED,
    SUBSCRIPTION_PENDING,
    SUBSCRIPTION_ERROR
};

typedef std::uint32_t pending_remote_offer_id_t;

}
// namespace vsomeip

#endif // VSOMEIP_ROUTING_TYPES_HPP