11 #ifndef RTI_ROUTING_ADAPTER_STREAM_READER_HPP_
12 #define RTI_ROUTING_ADAPTER_STREAM_READER_HPP_
16 #include <dds/core/SafeEnumeration.hpp>
17 #include <dds/sub/status/DataState.hpp>
18 #include <dds/core/InstanceHandle.hpp>
19 #include <dds/core/types.hpp>
20 #include <dds/topic/Filter.hpp>
21 #include <dds/core/xtypes/DynamicData.hpp>
22 #include <dds/sub/SampleInfo.hpp>
23 #include <rti/core/NativeValueType.hpp>
24 #include <rti/routing/UpdatableEntity.hpp>
25 #include <rti/routing/detail/ForwarderUtils.hpp>
27 namespace rti {
namespace routing {
namespace adapter {
48 typedef void* SamplePtr;
49 typedef void* InfoPtr;
90 std::vector<SamplePtr>& sample_seq,
91 std::vector<InfoPtr>& info_seq) = 0;
101 std::vector<SamplePtr>& sample_seq,
102 std::vector<InfoPtr>& info_seq) = 0;
121 std::vector<SamplePtr>& sample_seq,
122 std::vector<InfoPtr>& info_seq,
142 std::vector<SamplePtr>& sample_seq,
143 std::vector<InfoPtr>& info_seq,
162 std::vector<SamplePtr>& sample_seq,
163 std::vector<InfoPtr>& info_seq) = 0;
188 void *old_query_data,
189 const dds::topic::Filter& filter) = 0;
219 template <
typename Data,
typename Info>
242 std::vector<SamplePtr>& sample_seq,
243 std::vector<InfoPtr>& info_seq) RTI_FINAL
245 take(sample_seq_, info_seq_);
246 convert_samples(sample_seq, info_seq);
254 std::vector<SamplePtr>& sample_seq,
255 std::vector<InfoPtr>& info_seq) RTI_FINAL
257 read(sample_seq_, info_seq_);
258 convert_samples(sample_seq, info_seq);
266 std::vector<SamplePtr>& sample_seq,
267 std::vector<InfoPtr>& info_seq,
270 take(sample_seq_, info_seq_, selector_state);
271 convert_samples(sample_seq, info_seq);
279 std::vector<SamplePtr>& sample_seq,
280 std::vector<InfoPtr>& info_seq,
283 read(sample_seq_, info_seq_, selector_state);
284 convert_samples(sample_seq, info_seq);
292 std::vector<SamplePtr>& sample_seq,
293 std::vector<InfoPtr>& info_seq) RTI_FINAL
295 RTI_ROUTING_SAMPLE_VECTOR_COPY_PTRS(sample_seq_, sample_seq);
296 RTI_ROUTING_SAMPLE_VECTOR_COPY_PTRS(info_seq_, info_seq);
308 std::vector<Data*>& sample_seq,
309 std::vector<Info*>& info_seq) = 0;
317 std::vector<Data*>& sample_seq,
318 std::vector<Info*>& info_seq) = 0;
326 std::vector<Data*>& sample_seq,
327 std::vector<Info*>& info_seq,
336 std::vector<Data*>& sample_seq,
337 std::vector<Info*>& info_seq,
346 std::vector<Data*>& sample_seq,
347 std::vector<Info*>& info_seq) = 0;
358 void convert_samples(
359 std::vector<SamplePtr>& sample_seq,
360 std::vector<InfoPtr>& info_seq)
362 RTI_ROUTING_SAMPLE_VECTOR_COPY_PTRS(sample_seq, sample_seq_);
363 RTI_ROUTING_SAMPLE_VECTOR_COPY_PTRS(info_seq, info_seq_);
367 std::vector<Data*> sample_seq_;
368 std::vector<Info*> info_seq_;
380 template <
typename Data,
typename Info>
386 std::vector<Info*>&) RTI_OVERRIDE
392 std::vector<Info*>&) RTI_OVERRIDE
412 std::vector<Info*>&) RTI_OVERRIDE
418 const dds::topic::Filter&) RTI_OVERRIDE
444 typedef NoOpStreamReader<dds::core::xtypes::DynamicData, dds::sub::SampleInfo>
449 class SelectorStateAdapter {
451 typedef RTI_RoutingServiceSelectorState native_type;
453 static void initialize(native_type& native_value)
455 RTI_RoutingServiceSelectorState native_state =
456 RTI_RoutingServiceSelectorState_INITIALIZER;
457 memcpy(&native_value, &native_state,
sizeof(native_state));
460 static void finalize(native_type& native_value)
462 if (native_value.content.expression != NULL) {
463 DDS_String_free(native_value.content.expression);
465 DDS_StringSeq_finalize(&native_value.content.expression_parameters);
468 static void copy(native_type& destination,
const native_type& source)
470 destination.sample_state = source.sample_state;
471 destination.view_state = source.view_state;
472 destination.instance_state = source.instance_state;
473 destination.instance_handle = source.instance_handle;
474 destination.instance_selection = source.instance_selection;
475 destination.sample_count_max = source.sample_count_max;
476 destination.query_data = source.query_data;
477 char *result = DDS_String_replace(
478 &destination.content.expression,
479 source.content.expression);
480 if (source.content.expression != NULL && result == NULL) {
481 throw std::bad_alloc();
483 if (DDS_StringSeq_copy(
484 &destination.content.expression_parameters,
485 &source.content.expression_parameters) == NULL) {
486 throw std::bad_alloc();
490 static bool equals(
const native_type& first,
const native_type& second)
492 if (first.sample_state != second.sample_state) {
495 if (first.view_state != second.view_state) {
498 if (first.instance_state != second.instance_state) {
501 if (first.instance_selection != second.instance_selection) {
504 if (first.sample_count_max != second.sample_count_max) {
507 if (first.query_data != second.query_data) {
510 if (first.content.expression != NULL
511 && second.content.expression != NULL
512 && strcmp(first.content.expression, second.content.expression) != 0) {
515 return DDS_StringSeq_equals(
516 &first.content.expression_parameters,
517 &second.content.expression_parameters);
528 struct native_type_traits<rti::routing::adapter::SelectorState> {
529 typedef rti::routing::adapter::SelectorStateAdapter adapter_type;
530 typedef RTI_RoutingServiceSelectorState native_type;
535 namespace routing {
namespace adapter {
549 RTI_NATIVE_VALUE_TYPE_DEFINE_DEFAULT_MOVE_OPERATIONS(
SelectorState)
551 typedef rti::core::NativeValueType<SelectorState> Base;
563 dds::sub::status::DataState state()
const
565 return dds::sub::status::DataState(
566 dds::sub::status::SampleState(native().sample_state),
567 dds::sub::status::ViewState(native().view_state),
568 dds::sub::status::InstanceState(native().instance_state));
571 SelectorState& state(
const dds::sub::status::DataState& state)
573 native().sample_state = state.sample_state().to_ulong();
574 native().view_state = state.view_state().to_ulong();
575 native().instance_state = state.instance_state().to_ulong();
579 int32_t max_samples()
const
581 return native().sample_count_max;
586 native().sample_count_max = count;
590 dds::core::InstanceHandle instance()
const
592 if (native().instance_selection
593 == RTI_ROUTING_SERVICE_THIS_INSTANCE_SELECTION) {
594 return rti::core::native_conversions::from_native_handle(
595 native().instance_handle);
598 return dds::core::InstanceHandle::nil();
601 SelectorState& instance(
const dds::core::InstanceHandle& handle)
603 native().instance_handle =
604 static_cast<DDS_InstanceHandle_t
>(handle->native());
605 native().instance_selection = RTI_ROUTING_SERVICE_THIS_INSTANCE_SELECTION;
609 dds::core::InstanceHandle next_instance()
const
611 if (native().instance_selection
612 == RTI_ROUTING_SERVICE_NEXT_INSTANCE_SELECTION) {
613 return rti::core::native_conversions::from_native_handle(
614 native().instance_handle);
617 return dds::core::InstanceHandle::nil();
621 const dds::core::InstanceHandle& handle)
623 native().instance_handle =
624 static_cast<DDS_InstanceHandle_t
>(handle->native());
625 native().instance_selection = RTI_ROUTING_SERVICE_NEXT_INSTANCE_SELECTION;
631 return native().query_data;
636 native().query_data = query_data;
640 dds::topic::Filter filter()
const
642 return dds::topic::Filter(
643 native().content.expression == NULL ?
"" : native().content.expression,
644 rti::core::native_conversions::from_native<std::string>(
645 native().content.expression_parameters));
651 &native().content.expression,
652 filter.expression().c_str());
653 rti::core::native_conversions::to_native(
654 native().content.expression_parameters,
655 filter->parameters());
663 #endif // RTI_ROUTING_ADAPTER_STREAM_READER_HPP_