blob-msg.cpp
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 
6 
7 #include <realdds/dds-topic.h>
10 #include <realdds/dds-utilities.h>
11 
12 #include <fastdds/dds/subscriber/DataReader.hpp>
13 #include <fastdds/dds/publisher/DataWriter.hpp>
14 #include <fastdds/dds/topic/Topic.hpp>
15 
16 
17 namespace realdds {
18 namespace topics {
19 
20 
21 /*static*/ std::shared_ptr< dds_topic >
22 blob_msg::create_topic( std::shared_ptr< dds_participant > const & participant, char const * topic_name )
23 {
24  return std::make_shared< dds_topic >( participant,
25  eprosima::fastdds::dds::TypeSupport( new blob_msg::type ),
26  topic_name );
27 }
28 
29 
30 /*static*/ bool
31 blob_msg::take_next( dds_topic_reader & reader, blob_msg * output, eprosima::fastdds::dds::SampleInfo * info )
32 {
33  eprosima::fastdds::dds::SampleInfo info_;
34  if( ! info )
35  info = &info_; // use the local copy if the user hasn't provided their own
36  auto status = reader->take_next_sample( static_cast< udds::blob * >( output ), info );
37  if( status == ReturnCode_t::RETCODE_OK )
38  {
39  // We have data
40  if( output )
41  {
42  // Only samples for which valid_data is true should be accessed
43  // valid_data indicates that the instance is still ALIVE and the `take` return an
44  // updated sample
45  if( ! info->valid_data )
46  output->invalidate();
47  }
48  return true;
49  }
50  if( status == ReturnCode_t::RETCODE_NO_DATA )
51  {
52  // This is an expected return code and is not an error
53  return false;
54  }
55  DDS_API_CALL_THROW( "blob_msg::take_next", status );
56 }
57 
58 
60 {
61  eprosima::fastrtps::rtps::WriteParams params;
62  bool success = DDS_API_CALL(
63  writer.get()->write( const_cast< udds::blob * >( static_cast< udds::blob const * >( this ) ), params ) );
64  if( ! success )
65  {
66  LOG_ERROR( "Error writing message" );
67  return 0;
68  }
69  // The params will contain, after the write, the sequence number (incremented automatically) for the sample that was
70  // sent. The source_timestamp is always INVALID for some reason.
71  return params.sample_identity().sequence_number().to64long();
72 }
73 
74 
75 } // namespace topics
76 } // namespace realdds
librealsense::device_serializer::status
status
Defines return codes that SDK interfaces use. Negative values indicate errors, a zero value indicates...
Definition: src/core/serialization.h:311
realdds::topics::blob_msg
Definition: blob-msg.h:39
realdds::dds_topic_writer
Definition: dds-topic-writer.h:36
params
GLenum const GLfloat * params
Definition: glad/glad/glad.h:1403
librealsense::ds::success
@ success
Definition: d400-private.h:266
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::write_to
dds_sequence_number write_to(dds_topic_writer &) const
Definition: blob-msg.cpp:59
DDS_API_CALL_THROW
#define DDS_API_CALL_THROW(desc, r)
Definition: dds-utilities.h:35
realdds::topics::blob_msg::invalidate
void invalidate()
Definition: blob-msg.h:48
realdds::dds_sequence_number
uint64_t dds_sequence_number
Definition: dds-defines.h:32
dds-utilities.h
dds-topic.h
realdds::dds_topic_reader
Definition: dds-topic-reader.h:34
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
DDS_API_CALL
#define DDS_API_CALL(func)
Definition: dds-utilities.h:38
fps.info
info
Definition: fps.py:50
dds-topic-reader.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
dds-topic-writer.h
blob-msg.h
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
blobPubSubTypes.h
topic-send.writer
writer
Definition: topic-send.py:60
LOG_ERROR
#define LOG_ERROR(...)
Definition: easyloggingpp.h:73


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Mon Apr 22 2024 02:12:55