1 // Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 
6 #ifndef VSOMEIP_V3_TP_MESSAGE_HPP_
7 #define VSOMEIP_V3_TP_MESSAGE_HPP_
8 
9 #include <set>
10 #include <chrono>
11 
12 #include <vsomeip/primitive_types.hpp>
13 #include <vsomeip/enumeration_types.hpp>
14 
15 #include "buffer.hpp"
16 
17 namespace vsomeip_v3 {
18 namespace tp {
19 
20 class tp_message {
21 public:
22     tp_message(const byte_t* const _data, std::uint32_t _data_length,
23                std::uint32_t _max_message_size);
24 
25     bool add_segment(const byte_t* const _data, std::uint32_t _data_length);
26 
27     message_buffer_t get_message();
28 
29     std::chrono::steady_clock::time_point get_creation_time() const;
30 
31 private:
32     std::string get_message_id(const byte_t* const _data, std::uint32_t _data_length);
33     bool check_lengths(const byte_t* const _data, std::uint32_t _data_length,
34                        length_t _segment_size, bool _more_fragments);
35 private:
36     std::chrono::steady_clock::time_point timepoint_creation_;
37     std::uint32_t max_message_size_;
38     std::uint32_t current_message_size_;
39     bool last_segment_received_;
40 
41     struct segment_t {
segment_tvsomeip_v3::tp::tp_message::segment_t42         segment_t(std::uint32_t _start, std::uint32_t _end) :
43                 start_(_start),
44                 end_(_end) {
45         }
46 
operator <vsomeip_v3::tp::tp_message::segment_t47         bool operator<(const segment_t& _other) const {
48             return start_ < _other.start_
49                     || ((start_ >= _other.start_) && (end_ < _other.end_));
50         };
51 
52         std::uint32_t start_;
53         std::uint32_t end_;
54     };
55     std::set<segment_t> segments_;
56     message_buffer_t message_;
57 };
58 
59 } // namespace tp
60 } // namespace vsomeip_v3
61 
62 #endif // VSOMEIP_V3_TP_MESSAGE_HPP_
63