blob-msg.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2023 Intel Corporation. All Rights Reserved.
3 #pragma once
4 
5 #include "blob/blob.h"
6 #include <realdds/dds-defines.h>
7 
8 #include <string>
9 #include <memory>
10 #include <vector>
11 
12 
13 namespace eprosima {
14 namespace fastdds {
15 namespace dds {
16 struct SampleInfo;
17 }
18 } // namespace fastdds
19 } // namespace eprosima
20 
21 
22 namespace udds {
23 class blobPubSubType;
24 } // namespace raw
25 
26 
27 namespace realdds {
28 
29 
30 class dds_participant;
31 class dds_topic;
32 class dds_topic_reader;
33 class dds_topic_writer;
34 
35 
36 namespace topics {
37 
38 
39 class blob_msg : public udds::blob
40 {
41 public:
43 
44  blob_msg() = default;
45  blob_msg( std::vector< uint8_t > && data_ ) { data( std::move( data_ ) ); }
46 
47  bool is_valid() const { return ! data().empty(); }
48  void invalidate() { data().clear(); }
49 
50  static std::shared_ptr< dds_topic > create_topic( std::shared_ptr< dds_participant > const & participant,
51  char const * topic_name );
52  static std::shared_ptr< dds_topic > create_topic( std::shared_ptr< dds_participant > const & participant,
53  std::string const & topic_name )
54  {
55  return create_topic( participant, topic_name.c_str() );
56  }
57 
58  // This helper method will take the next sample from a reader.
59  //
60  // Returns true if successful. Make sure you still check is_valid() in case the sample info isn't!
61  // Returns false if no more data is available.
62  // Will throw if an unexpected error occurs.
63  //
64  static bool take_next( dds_topic_reader &,
65  blob_msg * output,
66  eprosima::fastdds::dds::SampleInfo * optional_info = nullptr );
67 
68  // Returns some unique (to the writer) identifier for the sample that was sent, or 0 if unsuccessful
70 
71  // Cast the raw data to the desired type
72  template< typename T >
73  T const * custom_data() const
74  {
75  return data().size() > 0 ? reinterpret_cast< T const * >( data().data() ) : nullptr;
76  }
77  template< typename T >
79  {
80  return data().size() > 0 ? reinterpret_cast< T * >( data().data() ) : nullptr;
81  }
82 };
83 
84 
85 } // namespace topics
86 } // namespace realdds
udds::blob::data
const eProsima_user_DllExport std::vector< uint8_t > & data() const
This function returns a constant reference to member data.
Definition: blob.cpp:152
realdds::topics::blob_msg
Definition: blob-msg.h:39
realdds::dds_topic_writer
Definition: dds-topic-writer.h:36
devices.participant
participant
Definition: third-party/realdds/scripts/devices.py:40
udds::blobPubSubType
This class represents the TopicDataType of the type blob defined by the user in the IDL file.
Definition: blobPubSubTypes.h:31
realdds::topics::blob_msg::custom_data
T * custom_data()
Definition: blob-msg.h:78
realdds::topics::blob_msg::blob_msg
blob_msg(std::vector< uint8_t > &&data_)
Definition: blob-msg.h:45
string
GLsizei const GLchar *const * string
Definition: glad/glad/glad.h:2861
realdds::topics::blob_msg::is_valid
bool is_valid() const
Definition: blob-msg.h:47
realdds::topics::blob_msg::write_to
dds_sequence_number write_to(dds_topic_writer &) const
Definition: blob-msg.cpp:59
realdds::topics::blob_msg::invalidate
void invalidate()
Definition: blob-msg.h:48
blob.h
realdds::dds_sequence_number
uint64_t dds_sequence_number
Definition: dds-defines.h:32
dds
Definition: dds.py:1
realdds::dds_topic_reader
Definition: dds-topic-reader.h:34
realdds::topics::blob_msg::create_topic
static std::shared_ptr< dds_topic > create_topic(std::shared_ptr< dds_participant > const &participant, std::string const &topic_name)
Definition: blob-msg.h:52
realdds::topics::blob_msg::take_next
static bool take_next(dds_topic_reader &, blob_msg *output, eprosima::fastdds::dds::SampleInfo *optional_info=nullptr)
Definition: blob-msg.cpp:31
realdds::topics::blob_msg::custom_data
const T * custom_data() const
Definition: blob-msg.h:73
udds
Definition: blob.h:55
dds-defines.h
realdds::topics::blob_msg::create_topic
static std::shared_ptr< dds_topic > create_topic(std::shared_ptr< dds_participant > const &participant, char const *topic_name)
Definition: blob-msg.cpp:22
test-metadata.topic_name
string topic_name
Definition: dds/test-metadata.py:43
realdds
Definition: rs-dds-device-info.h:12
udds::blob
This class represents the structure blob defined by the user in the IDL file.
Definition: blob.h:60
eprosima
Definition: dds-defines.h:9
realdds::topics::blob_msg::blob_msg
blob_msg()=default


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Fri Aug 2 2024 08:30:01