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
|
// Copyright (C) 2016-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/.
#include <cstring>
#include "../include/header.hpp"
#include "../../endpoints/include/endpoint.hpp"
#include "../../endpoints/include/client_endpoint.hpp"
#include "../../utility/include/byteorder.hpp"
namespace vsomeip {
namespace trace {
bool header::prepare(const std::shared_ptr<endpoint> &_endpoint,
bool _is_sending, instance_t _instance) {
return prepare(_endpoint.get(), _is_sending, _instance);
}
bool header::prepare(const endpoint *_endpoint, bool _is_sending,
instance_t _instance) {
boost::asio::ip::address its_address;
unsigned short its_port(0);
protocol_e its_protocol(protocol_e::unknown);
if (_endpoint) {
const client_endpoint* its_client_endpoint =
dynamic_cast<const client_endpoint*>(_endpoint);
if (its_client_endpoint) {
its_client_endpoint->get_remote_address(its_address);
if (its_address.is_v6()) {
return false;
}
its_port = its_client_endpoint->get_remote_port();
if (_endpoint->is_local()) {
its_protocol = protocol_e::local;
} else {
if (_endpoint->is_reliable()) {
its_protocol = protocol_e::tcp;
} else {
its_protocol = protocol_e::udp;
}
}
}
}
prepare(its_address.to_v4(), its_port, its_protocol, _is_sending, _instance);
return true;
}
void header::prepare(const boost::asio::ip::address_v4 &_address,
std::uint16_t _port, protocol_e _protocol,
bool _is_sending, instance_t _instance) {
unsigned long its_address_as_long = _address.to_ulong();
data_[0] = VSOMEIP_LONG_BYTE3(its_address_as_long);
data_[1] = VSOMEIP_LONG_BYTE2(its_address_as_long);
data_[2] = VSOMEIP_LONG_BYTE1(its_address_as_long);
data_[3] = VSOMEIP_LONG_BYTE0(its_address_as_long);
data_[4] = VSOMEIP_WORD_BYTE1(_port);
data_[5] = VSOMEIP_WORD_BYTE0(_port);
data_[6] = static_cast<byte_t>(_protocol);
data_[7] = static_cast<byte_t>(_is_sending);
data_[8] = VSOMEIP_WORD_BYTE1(_instance);
data_[9] = VSOMEIP_WORD_BYTE0(_instance);
}
} // namespace trace
} // namespace vsomeip
|