|
37 | 37 | #include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilder.hpp> |
38 | 38 | #include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp> |
39 | 39 | #include <fastdds/dds/xtypes/type_representation/TypeObject.hpp> |
| 40 | +#include <fastdds/dds/xtypes/utils.hpp> |
40 | 41 | #include <fastdds/rtps/attributes/ThreadSettings.hpp> |
41 | 42 | #include <fastdds/rtps/common/WriteParams.hpp> |
42 | 43 | #include <fastdds/rtps/history/IPayloadPool.hpp> |
@@ -1156,6 +1157,36 @@ class RemoteDiscoveryDomainParticipantListener : public DomainParticipantListene |
1156 | 1157 | }; |
1157 | 1158 | //!-- |
1158 | 1159 |
|
| 1160 | +//!--REMOTE_TYPE_INTROSPECTION |
| 1161 | +class TypeIntrospectionSubscriber : public DomainParticipantListener |
| 1162 | +{ |
| 1163 | + //!--DYNDATA_JSON_SERIALIZATION |
| 1164 | + void on_data_available( |
| 1165 | + DataReader* reader) |
| 1166 | + { |
| 1167 | + // Dynamic DataType |
| 1168 | + DynamicData::_ref_type new_data = |
| 1169 | + DynamicDataFactory::get_instance()->create_data(dyn_type_); |
| 1170 | + |
| 1171 | + SampleInfo info; |
| 1172 | + |
| 1173 | + while ((RETCODE_OK == reader->take_next_sample(&new_data, &info))) |
| 1174 | + { |
| 1175 | + std::stringstream output; |
| 1176 | + output << std::setw(4); |
| 1177 | + |
| 1178 | + // Serialize DynamicData into JSON string format |
| 1179 | + json_serialize(new_data, DynamicDataJsonFormat::EPROSIMA, output); |
| 1180 | + std::cout << "Message received:\n" << output.str() << std::endl; |
| 1181 | + } |
| 1182 | + } |
| 1183 | + |
| 1184 | + // DynamicType created in discovery callback |
| 1185 | + DynamicType::_ref_type dyn_type_; |
| 1186 | + //!-- |
| 1187 | +}; |
| 1188 | +//!-- |
| 1189 | + |
1159 | 1190 | void dds_discovery_examples() |
1160 | 1191 | { |
1161 | 1192 | using Locator_t = eprosima::fastdds::rtps::Locator_t; |
|
0 commit comments