summaryrefslogtreecommitdiff
path: root/implementation/endpoints/include/endpoint_definition.hpp
blob: 2dca226eae0ca8f442c031911c143f8dddb8bb28 (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
// Copyright (C) 2014-2021 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_ENDPOINT_DEFINITION_HPP_
#define VSOMEIP_V3_ENDPOINT_DEFINITION_HPP_

#include <map>
#include <memory>
#include <atomic>
#include <mutex>

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

#include <vsomeip/export.hpp>

namespace vsomeip_v3 {

class endpoint_definition {
public:
    VSOMEIP_EXPORT static std::shared_ptr<endpoint_definition> get(
            const boost::asio::ip::address &_address,
            uint16_t _port, bool _is_reliable, service_t _service, instance_t _instance);

    VSOMEIP_EXPORT const boost::asio::ip::address &get_address() const;

    VSOMEIP_EXPORT uint16_t get_port() const;

    VSOMEIP_EXPORT uint16_t get_remote_port() const;
    VSOMEIP_EXPORT void set_remote_port(uint16_t _port);

    VSOMEIP_EXPORT bool is_reliable() const;

    VSOMEIP_EXPORT endpoint_definition(
            const boost::asio::ip::address &_address,
            uint16_t _port, bool _is_reliable);
private:
    boost::asio::ip::address address_;
    uint16_t port_;
    std::atomic<uint16_t> remote_port_;
    bool is_reliable_;

    static std::mutex definitions_mutex_;
    static std::map<
        std::tuple<service_t, instance_t, boost::asio::ip::address, uint16_t, bool>,
        std::shared_ptr<endpoint_definition> > definitions_;
};

} // namespace vsomeip_v3

#endif // VSOMEIP_V3_ENDPOINT_DEFINITION_HPP_