summaryrefslogtreecommitdiff
path: root/implementation/endpoints/src/endpoint_impl.cpp
blob: 5b0e088faeb3ebfde6a6b6555676a385bbb9e24c (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
142
143
144
145
146
147
148
149
// Copyright (C) 2014-2015 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/.

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

#include "../include/endpoint_host.hpp"
#include "../include/endpoint_impl.hpp"
#include "../../logging/include/logger.hpp"

namespace vsomeip {

template<int MaxBufferSize>
endpoint_impl<MaxBufferSize>::endpoint_impl(
        std::shared_ptr<endpoint_host> _host, boost::asio::io_service &_io,
        std::uint32_t _max_message_size)
    : service_(_io),
      host_(_host),
      is_supporting_magic_cookies_(false),
      has_enabled_magic_cookies_(false),
      max_message_size_(_max_message_size) {
}

template<int MaxBufferSize>
endpoint_impl<MaxBufferSize>::~endpoint_impl() {
}

template<int MaxBufferSize>
void endpoint_impl<MaxBufferSize>::enable_magic_cookies() {
    has_enabled_magic_cookies_ = is_supporting_magic_cookies_;
}

template<int MaxBufferSize>
bool endpoint_impl<MaxBufferSize>::is_magic_cookie() const {
    return false;
}

template<int MaxBufferSize>
uint32_t endpoint_impl<MaxBufferSize>::find_magic_cookie(
        byte_t *_buffer, size_t _size) {
    bool is_found(false);
    uint32_t its_offset = 0xFFFFFFFF;
    if (has_enabled_magic_cookies_) {
        uint8_t its_cookie_identifier, its_cookie_type;

        if (is_client()) {
            its_cookie_identifier =
                    static_cast<uint8_t>(MAGIC_COOKIE_SERVICE_MESSAGE);
            its_cookie_type =
                    static_cast<uint8_t>(MAGIC_COOKIE_SERVICE_MESSAGE_TYPE);
        } else {
            its_cookie_identifier =
                    static_cast<uint8_t>(MAGIC_COOKIE_CLIENT_MESSAGE);
            its_cookie_type =
                    static_cast<uint8_t>(MAGIC_COOKIE_CLIENT_MESSAGE_TYPE);
        }

        do {
            its_offset++; // --> first loop has "its_offset = 0"
            if (_size > its_offset + 16) {
                is_found = (_buffer[its_offset] == 0xFF
                         && _buffer[its_offset + 1] == 0xFF
                         && _buffer[its_offset + 2] == its_cookie_identifier
                         && _buffer[its_offset + 3] == 0x00
                         && _buffer[its_offset + 4] == 0x00
                         && _buffer[its_offset + 5] == 0x00
                         && _buffer[its_offset + 6] == 0x00
                         && _buffer[its_offset + 7] == 0x08
                         && _buffer[its_offset + 8] == 0xDE
                         && _buffer[its_offset + 9] == 0xAD
                         && _buffer[its_offset + 10] == 0xBE
                         && _buffer[its_offset + 11] == 0xEF
                         && _buffer[its_offset + 12] == 0x01
                         && _buffer[its_offset + 13] == 0x01
                         && _buffer[its_offset + 14] == its_cookie_type
                         && _buffer[its_offset + 15] == 0x00);
            } else {
                break;
            }

        } while (!is_found);
    }

    return (is_found ? its_offset : 0xFFFFFFFF);
}

template<int MaxBufferSize>
void endpoint_impl<MaxBufferSize>::join(const std::string &) {
}

template<int MaxBufferSize>
void endpoint_impl<MaxBufferSize>::leave(const std::string &) {
}

template<int MaxBufferSize>
void endpoint_impl<MaxBufferSize>::add_multicast(
        service_t, event_t, const std::string &, uint16_t) {
}

template<int MaxBufferSize>
void endpoint_impl<MaxBufferSize>::remove_multicast(service_t, event_t) {
}

template<int MaxBufferSize>
bool endpoint_impl<MaxBufferSize>::get_remote_address(
        boost::asio::ip::address &_address) const {
    (void)_address;
    return false;
}

template<int MaxBufferSize>
unsigned short endpoint_impl<MaxBufferSize>::get_local_port() const {
    return 0;
}

template<int MaxBufferSize>
unsigned short endpoint_impl<MaxBufferSize>::get_remote_port() const {
    return 0;
}

template<int MaxBufferSize>
bool endpoint_impl<MaxBufferSize>::is_reliable() const {
    return false;
}

template<int MaxBufferSize>
void endpoint_impl<MaxBufferSize>::increment_use_count() {
    use_count_++;
}

template<int MaxBufferSize>
void endpoint_impl<MaxBufferSize>::decrement_use_count() {
    if (use_count_ > 0)
        use_count_--;
}

template<int MaxBufferSize>
uint32_t endpoint_impl<MaxBufferSize>::get_use_count() {
    return use_count_;
}

// Instantiate template
template class endpoint_impl< VSOMEIP_MAX_LOCAL_MESSAGE_SIZE> ;
template class endpoint_impl< VSOMEIP_MAX_TCP_MESSAGE_SIZE> ;
template class endpoint_impl< VSOMEIP_MAX_UDP_MESSAGE_SIZE> ;

} // namespace vsomeip