/src/Fast-DDS/src/cpp/rtps/transport/ChannelResource.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2019 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 | | #ifndef _FASTDDS_CHANNEL_RESOURCE_INFO_ |
16 | | #define _FASTDDS_CHANNEL_RESOURCE_INFO_ |
17 | | |
18 | | #include <atomic> |
19 | | |
20 | | #include <fastdds/dds/log/Log.hpp> |
21 | | #include <fastdds/rtps/common/CDRMessage_t.hpp> |
22 | | |
23 | | #include <utils/thread.hpp> |
24 | | |
25 | | namespace eprosima { |
26 | | namespace fastdds { |
27 | | namespace rtps { |
28 | | |
29 | | class ChannelResource |
30 | | { |
31 | | public: |
32 | | |
33 | | ChannelResource(); |
34 | | ChannelResource( |
35 | | ChannelResource&& channelResource); |
36 | | ChannelResource( |
37 | | uint32_t rec_buffer_size); |
38 | | virtual ~ChannelResource(); |
39 | | |
40 | | virtual void clear(); |
41 | | |
42 | | inline void thread( |
43 | | eprosima::thread&& pThread) |
44 | 0 | { |
45 | 0 | if (thread_.joinable()) |
46 | 0 | { |
47 | 0 | thread_.join(); |
48 | 0 | } |
49 | |
|
50 | 0 | thread_.swap(pThread); |
51 | 0 | } |
52 | | |
53 | | inline bool alive() const |
54 | 0 | { |
55 | 0 | return alive_.load(); |
56 | 0 | } |
57 | | |
58 | | inline virtual void disable() |
59 | 0 | { |
60 | 0 | alive_.store(false); |
61 | 0 | } |
62 | | |
63 | | inline CDRMessage_t& message_buffer() |
64 | 0 | { |
65 | 0 | return message_buffer_; |
66 | 0 | } |
67 | | |
68 | | protected: |
69 | | |
70 | | //!Received message |
71 | | CDRMessage_t message_buffer_; |
72 | | |
73 | | std::atomic<bool> alive_; |
74 | | eprosima::thread thread_; |
75 | | }; |
76 | | |
77 | | } // namespace rtps |
78 | | } // namespace fastdds |
79 | | } // namespace eprosima |
80 | | |
81 | | #endif // _FASTDDS_CHANNEL_RESOURCE_INFO_ |