text: // Copyright 2015-2017 Open Source Robotics Foundation, Inc.
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  #include "rmw_connext_shared_cpp/qos.hpp"
  
  bool
  get_datareader_qos(
    DDS::DomainParticipant * participant,
    const rmw_qos_profile_t & qos_profile,
    DDS::DataReaderQos & datareader_qos)
  {
    DDS::ReturnCode_t status = participant->get_default_datareader_qos(datareader_qos);
    if (status != DDS::RETCODE_OK) {
      RMW_SET_ERROR_MSG("failed to get default datareader qos");
      return false;
    }
  
    status = DDS::PropertyQosPolicyHelper::add_property(
      datareader_qos.property,
      "dds.data_reader.history.memory_manager.fast_pool.pool_buffer_max_size",
      "4096",
      DDS::BOOLEAN_FALSE);
    if (status != DDS::RETCODE_OK) {
      RMW_SET_ERROR_MSG("failed to add qos property");
      return false;
    }
  
    status = DDS::PropertyQosPolicyHelper::add_property(
      datareader_qos.property,
      "reader_resource_limits.dynamically_allocate_fragmented_samples",
      "1",
      DDS::BOOLEAN_FALSE);
    if (status != DDS::RETCODE_OK) {
      RMW_SET_ERROR_MSG("failed to add qos property");
      return false;
    }
  
    if (!set_entity_qos_from_profile(qos_profile, datareader_qos)) {
      return false;
    }
  
    return true;
  }
  
  bool
  get_datawriter_qos(
    DDS::DomainParticipant * participant,
    const rmw_qos_profile_t & qos_profile,
    DDS::DataWriterQos & datawriter_qos)
  {
    DDS::ReturnCode_t status = participant->get_default_datawriter_qos(datawriter_qos);
    if (status != DDS::RETCODE_OK) {
      RMW_SET_ERROR_MSG("failed to get default datawriter qos");
      return false;
    }
  
    status = DDS::PropertyQosPolicyHelper::add_property(
      datawriter_qos.property,
      "dds.data_writer.history.memory_manager.fast_pool.pool_buffer_max_size",
      "4096",
      DDS::BOOLEAN_FALSE);
    if (status != DDS::RETCODE_OK) {
      RMW_SET_ERROR_MSG("failed to add qos property");
      return false;
    }
  
    if (!set_entity_qos_from_profile(qos_profile, datawriter_qos)) {
      return false;
    }
  
    // TODO(wjwwood): conditionally use the async publish mode using a heuristic:
    //  https://github.com/ros2/rmw_connext/issues/190
    datawriter_qos.publish_mode.kind = DDS::ASYNCHRONOUS_PUBLISH_MODE_QOS;
  
    return true;
  }
  