Converting XML to Code

4 posts / 0 new
Last post
Offline
Last seen: 5 years 3 weeks ago
Joined: 08/13/2014
Posts: 55
Converting XML to Code

 

Hi everybody,

I want to know the equivalent code of below xml in Modern C++ RTI V 5.2.0. 

<participant_qos>
 
 <discovery_config>
  <ignore_default_domain_announcements>false</ignore_default_domain_announcements>
 
  <participant_liveliness_assert_period>
   <sec>1</sec>
   <nanosec>0</nanosec>
  </participant_liveliness_assert_period>
  <participant_liveliness_lease_duration>
   <sec>10</sec>
   <nanosec>0</nanosec>
  </participant_liveliness_lease_duration>
 
  <!-- quickly detect the loss of liveness of remote participants -->
  <max_liveliness_loss_detection_period>
   <sec>5</sec>
   <nanosec>0</nanosec>
  </max_liveliness_loss_detection_period>
 
  <asynchronous_publisher>
   <disable_asynchronous_write>false</disable_asynchronous_write>
  </asynchronous_publisher>
 
  <publication_writer_publish_mode>
   <kind>ASYNCHRONOUS_PUBLISH_MODE_QOS</kind>
  </publication_writer_publish_mode>
 
  <subscription_writer_publish_mode>
   <kind>ASYNCHRONOUS_PUBLISH_MODE_QOS</kind>
  </subscription_writer_publish_mode>
 
 </discovery_config>
 
 <resource_limits>
  <type_code_max_serialized_length>65535</type_code_max_serialized_length>
  <deserialized_type_object_dynamic_allocation_threshold>1024</deserialized_type_object_dynamic_allocation_threshold>
  <type_object_max_deserialized_length>LENGTH_UNLIMITED</type_object_max_deserialized_length>
  <type_object_max_serialized_length>12288</type_object_max_serialized_length>
  <participant_property_list_max_length>1024</participant_property_list_max_length>
  <participant_property_string_max_length>32768</participant_property_string_max_length>
 </resource_limits>
 
 <property>
 <value>
  <!-- Don't ignore the local loopback. -->
  <element>
   <name>dds.transport.UDPv4.builtin.ignore_loopback_interface</name>
   <value>0</value>
  </element>
  <element>
   <name>dds.transport.UDPv4.builtin.recv_socket_buffer_size</name>
   <value>1048576</value>
  </element>
 </value>
 </property>
</participant_qos>

I wrote the following code in my app:

 dds::domain::qos::DomainParticipantFactoryQos factoryQos =
 dds::domain::DomainParticipant::participant_factory_qos();
 factoryQos << dds::core::policy::EntityFactory::ManuallyEnable();
 dds::domain::DomainParticipant::participant_factory_qos(factoryQos);
 dds::domain::qos::DomainParticipantQos dp_qos = dds::core::QosProvider::Default()
 .participant_qos(rti::core::builtin_profiles::qos_lib::baseline());
 dp_qos->discovery_config.ignore_default_domain_announcements(false);
 dp_qos->discovery_config.participant_liveliness_assert_period(dds::core::Duration(10,0));
 dp_qos->discovery_config.participant_liveliness_lease_duration(dds::core::Duration(10,0));
 // quickly detect the loss of liveness of remote participants
 dp_qos->discovery_config.max_liveliness_loss_detection_period(dds::core::Duration(5,0));
 dp_qos->discovery_config.asynchronous_publisher().disable_asynchronous_write(false);
 dp_qos->discovery_config.publication_writer_publish_mode().Asynchronous();
 dp_qos->discovery_config.subscription_writer_publish_mode().Asynchronous();
dp_qos->resource_limits.type_code_max_serialized_length(65535);
 dp_qos->resource_limits.type_object_max_deserialized_length(dds::core::LENGTH_UNLIMITED);
 dp_qos->resource_limits.type_object_max_serialized_length(12228);
 dp_qos->resource_limits.participant_property_list_max_length(1024);
 dp_qos->resource_limits.participant_property_string_max_length(32768);

But I don't know how to write relevant code for setting property part. Thanks in advance for your help.

Bonjefir

Keywords:
Offline
Last seen: 1 month 3 weeks ago
Joined: 04/02/2013
Posts: 196

Hi,

Here's a small tutorial on how to set and get QoS policies in code. And here's the documentation of the Property Qos policy.

You have two ways to set a Qos policy P: 

1) using the policy<P>() getter to retrieve it by reference and modify it.

2) creating and configuring an object P and then using the << or policy<P> setters.

For example, instead of 

dp_qos->resource_limits.type_code_max_serialized_length(65535);

Try this:

dp_qos.policy<DomainParticipantResourceLimits>().type_code_max_serialized_length(65535);

There are several ways to set the Property qos. One example:

Property property {{"dds.transport.UDPv4.builtin.ignore_loopback_interface", "0},{"dds.transport.UDPv4.builtin.recv_socket_buffer_size", "0}};

dp_qos << property;

Another option is passing a std::map containing the properties.

std::map prop_map = ...;
dp_qos << Property(prop_map.begin(), prop_map.end());

Or setting them one by one with Property::set().

 

I hope this helps.

Offline
Last seen: 5 years 3 weeks ago
Joined: 08/13/2014
Posts: 55

Dear Alex,

Thanks for your prompt and comprehensive reply. As far as I know, the mentioned link in the first line of your answer is not available in the documentation of version 5.2.0 and that's not good at all. Actually, I think there are still lots of work to do in documentation sections and it needs more examples (especially in Modern C++ language) to bo clear and easy to understand. Please pass my feedback to your colleages. You and your colleages in RTI company have done a great job for developing your software. Thanks again for your work.

Sincerely,

Bonjefir

Offline
Last seen: 1 month 3 weeks ago
Joined: 04/02/2013
Posts: 196

Thanks for your feedback. I have entered your suggestions into our issue database and will try to work on it for our next release. I totally agree that the documentation and examples are hard to find and not as expansive as we'd like.

I was wondering if you have seen this set of examples from the RTI Community portal, it can probably help you figure out how to solve some common problems in the new C++ API: