/src/Fast-DDS/src/cpp/statistics/rtps/messages/OutputTrafficManager.hpp
Line | Count | Source |
1 | | // Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | /** |
16 | | * @file OutputTrafficManager.hpp |
17 | | */ |
18 | | |
19 | | #ifndef _STATISTICS_RTPS_MESSAGES_OUTPUTTRAFFICMANAGER_HPP_ |
20 | | #define _STATISTICS_RTPS_MESSAGES_OUTPUTTRAFFICMANAGER_HPP_ |
21 | | |
22 | | #include <algorithm> |
23 | | #include <cstdint> |
24 | | #include <list> |
25 | | #include <utility> |
26 | | |
27 | | #include <fastdds/config.hpp> |
28 | | #include <fastdds/dds/log/Log.hpp> |
29 | | #include <fastdds/rtps/common/Locator.hpp> |
30 | | |
31 | | #include <statistics/rtps/messages/RTPSStatisticsMessages.hpp> |
32 | | |
33 | | namespace eprosima { |
34 | | namespace fastdds { |
35 | | namespace statistics { |
36 | | namespace rtps { |
37 | | |
38 | | /** |
39 | | * A container for output locators sequencing information. |
40 | | * @note This is non-thread-safe class. |
41 | | */ |
42 | | class OutputTrafficManager |
43 | | { |
44 | | public: |
45 | | |
46 | | /** |
47 | | * Adds an output locator to the collection. |
48 | | * If the locator is already present in the collection, this method is a no-op. |
49 | | * @param locator The locator for which sequencing information should be kept. |
50 | | */ |
51 | | inline void add_entry( |
52 | | const eprosima::fastdds::rtps::Locator_t& locator) |
53 | 0 | { |
54 | 0 | static_cast<void>(locator); |
55 | |
|
56 | 0 | #ifdef FASTDDS_STATISTICS |
57 | 0 | auto search = [locator](const entry_type& entry) -> bool |
58 | 0 | { |
59 | 0 | return locator == entry.first; |
60 | 0 | }; |
61 | 0 | auto it = std::find_if(collection_.cbegin(), collection_.cend(), search); |
62 | 0 | if (it == collection_.cend()) |
63 | 0 | { |
64 | 0 | collection_.emplace_back(locator, value_type{}); |
65 | 0 | } |
66 | 0 | #endif // FASTDDS_STATISTICS |
67 | 0 | } |
68 | | |
69 | | /** |
70 | | * |
71 | | */ |
72 | | inline void set_statistics_message_data( |
73 | | const eprosima::fastdds::rtps::Locator_t& locator, |
74 | | const eprosima::fastdds::rtps::NetworkBuffer& send_buffer, |
75 | | const uint32_t& total_bytes) |
76 | 0 | { |
77 | 0 | static_cast<void>(locator); |
78 | 0 | static_cast<void>(send_buffer); |
79 | 0 | static_cast<void>(total_bytes); |
80 | |
|
81 | 0 | #ifdef FASTDDS_STATISTICS |
82 | 0 | auto search = [locator](const entry_type& entry) -> bool |
83 | 0 | { |
84 | 0 | return locator == entry.first; |
85 | 0 | }; |
86 | 0 | auto it = std::find_if(collection_.begin(), collection_.end(), search); |
87 | 0 | if (it == collection_.end()) |
88 | 0 | { |
89 | 0 | EPROSIMA_LOG_ERROR(RTPS_OUT, |
90 | 0 | "Locator '" << locator << "' not found in collection. Adding entry."); |
91 | 0 | it = collection_.insert(it, entry_type(locator, value_type{})); |
92 | 0 | } |
93 | 0 | set_statistics_submessage_from_transport(locator, send_buffer, total_bytes, it->second); |
94 | 0 | #endif // FASTDDS_STATISTICS |
95 | 0 | } |
96 | | |
97 | | #ifdef FASTDDS_STATISTICS |
98 | | |
99 | | private: |
100 | | |
101 | | using key_type = eprosima::fastdds::rtps::Locator_t; |
102 | | using value_type = StatisticsSubmessageData::Sequence; |
103 | | using entry_type = std::pair<key_type, value_type>; |
104 | | |
105 | | std::list<entry_type> collection_; |
106 | | #endif // FASTDDS_STATISTICS |
107 | | |
108 | | }; |
109 | | |
110 | | } // namespace rtps |
111 | | } // namespace statistics |
112 | | } // namespace fastdds |
113 | | } // namespace eprosima |
114 | | |
115 | | #endif // _STATISTICS_RTPS_MESSAGES_OUTPUTTRAFFICMANAGER_HPP_ |