ChannelResource.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef _FASTDDS_CHANNEL_RESOURCE_INFO_
  15. #define _FASTDDS_CHANNEL_RESOURCE_INFO_
  16. #include <memory>
  17. #include <map>
  18. #include <fastrtps/utils/Semaphore.h>
  19. #include <fastdds/dds/log/Log.hpp>
  20. #include <fastdds/rtps/common/CDRMessage_t.h>
  21. namespace eprosima{
  22. namespace fastdds{
  23. namespace rtps{
  24. class ChannelResource
  25. {
  26. public:
  27. ChannelResource();
  28. ChannelResource(ChannelResource&& channelResource);
  29. ChannelResource(uint32_t rec_buffer_size);
  30. virtual ~ChannelResource();
  31. virtual void clear();
  32. inline void thread(std::thread&& pThread)
  33. {
  34. if(thread_.joinable())
  35. {
  36. thread_.join();
  37. }
  38. thread_.swap(pThread);
  39. }
  40. inline bool alive() const
  41. {
  42. return alive_.load();
  43. }
  44. inline virtual void disable()
  45. {
  46. alive_.store(false);
  47. }
  48. inline fastrtps::rtps::CDRMessage_t& message_buffer()
  49. {
  50. return message_buffer_;
  51. }
  52. protected:
  53. //!Received message
  54. fastrtps::rtps::CDRMessage_t message_buffer_;
  55. std::atomic<bool> alive_;
  56. std::thread thread_;
  57. };
  58. } // namespace rtps
  59. } // namespace fastdds
  60. } // namespace eprosima
  61. #endif // _FASTDDS_CHANNEL_RESOURCE_INFO_