1 // Copyright (C) 2014-2017 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_BUFFER_HPP_
7 #define VSOMEIP_V3_BUFFER_HPP_
8 
9 #include <array>
10 #include <chrono>
11 #include <memory>
12 #include <set>
13 
14 #include <boost/asio/io_service.hpp>
15 #include <boost/asio/steady_timer.hpp>
16 
17 #include <vsomeip/defines.hpp>
18 #include <vsomeip/primitive_types.hpp>
19 
20 #ifdef _WIN32
21     #define DEFAULT_NANOSECONDS_MAX 1000000000
22 #else
23     #define DEFAULT_NANOSECONDS_MAX std::chrono::nanoseconds::max()
24 #endif
25 
26 namespace vsomeip_v3 {
27 
28 typedef std::vector<byte_t> message_buffer_t;
29 typedef std::shared_ptr<message_buffer_t> message_buffer_ptr_t;
30 
31 struct timing {
timingvsomeip_v3::timing32     timing() : debouncing_(0), maximum_retention_(DEFAULT_NANOSECONDS_MAX) {};
33 
34     std::chrono::nanoseconds debouncing_;
35     std::chrono::nanoseconds maximum_retention_;
36 };
37 
38 struct train {
trainvsomeip_v3::train39     train(boost::asio::io_service& _io) : buffer_(std::make_shared<message_buffer_t>()),
40               departure_(DEFAULT_NANOSECONDS_MAX),
41               minimal_debounce_time_(DEFAULT_NANOSECONDS_MAX),
42               minimal_max_retention_time_(DEFAULT_NANOSECONDS_MAX),
43               last_departure_(std::chrono::steady_clock::now() - std::chrono::hours(1)),
44               departure_timer_(std::make_shared<boost::asio::steady_timer>(_io)) {};
45 
46     message_buffer_ptr_t buffer_;
47     std::chrono::nanoseconds departure_;
48     std::chrono::nanoseconds minimal_debounce_time_;
49     std::chrono::nanoseconds minimal_max_retention_time_;
50     std::chrono::steady_clock::time_point last_departure_;
51     std::shared_ptr<boost::asio::steady_timer> departure_timer_;
52     std::set<std::pair<service_t, method_t> > passengers_;
53 
update_departure_time_and_stop_departurevsomeip_v3::train54     void update_departure_time_and_stop_departure() {
55         departure_ = departure_timer_->expires_from_now();
56         boost::system::error_code ec;
57         departure_timer_->cancel(ec);
58     }
59 };
60 
61 
62 } // namespace vsomeip_v3
63 
64 #endif // VSOMEIP_V3_BUFFER_HPP_
65