Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #100 from ros2/fix_service_qos
Browse files Browse the repository at this point in the history
Fix default QoS settings for services
  • Loading branch information
jacquelinekay committed Sep 20, 2015
2 parents 38e71f9 + 287e7ee commit 030772b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 205 deletions.
116 changes: 14 additions & 102 deletions rmw_connext_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,58 +229,11 @@ rmw_create_publisher(
}
}

if (!get_datawriter_qos(participant, datawriter_qos)) {
if (!get_datawriter_qos(participant, qos_profile, datawriter_qos)) {
// error string was set within the function
goto fail;
}

switch (qos_profile.history) {
case RMW_QOS_POLICY_KEEP_LAST_HISTORY:
datawriter_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
break;
case RMW_QOS_POLICY_KEEP_ALL_HISTORY:
datawriter_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS;
break;
case RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT:
break;
default:
RMW_SET_ERROR_MSG("Unknown QoS history policy");
goto fail;
}

switch (qos_profile.reliability) {
case RMW_QOS_POLICY_BEST_EFFORT:
datawriter_qos.reliability.kind = DDS_BEST_EFFORT_RELIABILITY_QOS;
break;
case RMW_QOS_POLICY_RELIABLE:
datawriter_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
break;
case RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT:
break;
default:
RMW_SET_ERROR_MSG("Unknown QoS reliability policy");
goto fail;
}

if (qos_profile.depth != RMW_QOS_POLICY_DEPTH_SYSTEM_DEFAULT) {
datawriter_qos.history.depth = static_cast<DDS_Long>(qos_profile.depth);
}

// ensure the history depth is at least the requested queue size
assert(datawriter_qos.history.depth >= 0);
if (
datawriter_qos.history.kind == DDS::KEEP_LAST_HISTORY_QOS &&
static_cast<size_t>(datawriter_qos.history.depth) < qos_profile.depth
)
{
if (qos_profile.depth > (std::numeric_limits<DDS_Long>::max)()) {
RMW_SET_ERROR_MSG(
"failed to set history depth since the requested queue size exceeds the DDS type");
goto fail;
}
datawriter_qos.history.depth = static_cast<DDS_Long>(qos_profile.depth);
}

topic_writer = dds_publisher->create_datawriter(
topic, datawriter_qos, NULL, DDS_STATUS_MASK_NONE);
if (!topic_writer) {
Expand Down Expand Up @@ -559,58 +512,11 @@ rmw_create_subscription(const rmw_node_t * node,
}
}

if (!get_datareader_qos(participant, datareader_qos)) {
if (!get_datareader_qos(participant, qos_profile, datareader_qos)) {
// error string was set within the function
goto fail;
}

switch (qos_profile.history) {
case RMW_QOS_POLICY_KEEP_LAST_HISTORY:
datareader_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
break;
case RMW_QOS_POLICY_KEEP_ALL_HISTORY:
datareader_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS;
break;
case RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT:
break;
default:
RMW_SET_ERROR_MSG("Unknown QoS history policy");
goto fail;
}

switch (qos_profile.reliability) {
case RMW_QOS_POLICY_BEST_EFFORT:
datareader_qos.reliability.kind = DDS_BEST_EFFORT_RELIABILITY_QOS;
break;
case RMW_QOS_POLICY_RELIABLE:
datareader_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
break;
case RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT:
break;
default:
RMW_SET_ERROR_MSG("Unknown QoS reliability policy");
goto fail;
}

if (qos_profile.depth != RMW_QOS_POLICY_DEPTH_SYSTEM_DEFAULT) {
datareader_qos.history.depth = static_cast<DDS_Long>(qos_profile.depth);
}

// ensure the history depth is at least the requested queue size
assert(datareader_qos.history.depth >= 0);
if (
datareader_qos.history.kind == DDS::KEEP_LAST_HISTORY_QOS &&
static_cast<size_t>(datareader_qos.history.depth) < qos_profile.depth
)
{
if (qos_profile.depth > (std::numeric_limits<DDS_Long>::max)()) {
RMW_SET_ERROR_MSG(
"failed to set history depth since the requested queue size exceeds the DDS type");
goto fail;
}
datareader_qos.history.depth = static_cast<DDS_Long>(qos_profile.depth);
}

topic_reader = dds_subscriber->create_datareader(
topic, datareader_qos,
NULL, DDS_STATUS_MASK_NONE);
Expand Down Expand Up @@ -872,7 +778,8 @@ rmw_client_t *
rmw_create_client(
const rmw_node_t * node,
const rosidl_service_type_support_t * type_support,
const char * service_name)
const char * service_name,
const rmw_qos_profile_t & qos_profile)
{
if (!node) {
RMW_SET_ERROR_MSG("node handle is null");
Expand Down Expand Up @@ -918,18 +825,20 @@ rmw_create_client(
void * requester = nullptr;
void * buf = nullptr;
ConnextStaticClientInfo * client_info = nullptr;

// Begin inializing elements.
client = rmw_client_allocate();
if (!client) {
RMW_SET_ERROR_MSG("failed to allocate client");
goto fail;
}

if (!get_datareader_qos(participant, datareader_qos)) {
if (!get_datareader_qos(participant, qos_profile, datareader_qos)) {
// error string was set within the function
goto fail;
}
if (!get_datawriter_qos(participant, datawriter_qos)) {

if (!get_datawriter_qos(participant, qos_profile, datawriter_qos)) {
// error string was set within the function
goto fail;
}
Expand Down Expand Up @@ -1051,7 +960,8 @@ rmw_service_t *
rmw_create_service(
const rmw_node_t * node,
const rosidl_service_type_support_t * type_support,
const char * service_name)
const char * service_name,
const rmw_qos_profile_t & qos_profile)
{
if (!node) {
RMW_SET_ERROR_MSG("node handle is null");
Expand Down Expand Up @@ -1089,6 +999,7 @@ rmw_create_service(
RMW_SET_ERROR_MSG("callbacks handle is null");
return NULL;
}

// Past this point, a failure results in unrolling code in the goto fail block.
DDSDataReader * request_datareader = nullptr;
DDS_DataReaderQos datareader_qos;
Expand All @@ -1104,11 +1015,12 @@ rmw_create_service(
goto fail;
}

if (!get_datareader_qos(participant, datareader_qos)) {
if (!get_datareader_qos(participant, qos_profile, datareader_qos)) {
// error string was set within the function
goto fail;
}
if (!get_datawriter_qos(participant, datawriter_qos)) {

if (!get_datawriter_qos(participant, qos_profile, datawriter_qos)) {
// error string was set within the function
goto fail;
}
Expand Down
109 changes: 10 additions & 99 deletions rmw_connext_dynamic_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,57 +507,11 @@ rmw_create_publisher(
}
}

if (!get_datawriter_qos(participant, datawriter_qos)) {
if (!get_datawriter_qos(participant, qos_profile, datawriter_qos)) {
// error string was set within the function
goto fail;
}

switch (qos_profile.history) {
case RMW_QOS_POLICY_KEEP_LAST_HISTORY:
datawriter_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
break;
case RMW_QOS_POLICY_KEEP_ALL_HISTORY:
datawriter_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS;
break;
case RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT:
break;
default:
RMW_SET_ERROR_MSG("Unknown QoS history policy");
goto fail;
}

switch (qos_profile.reliability) {
case RMW_QOS_POLICY_BEST_EFFORT:
datawriter_qos.reliability.kind = DDS_BEST_EFFORT_RELIABILITY_QOS;
break;
case RMW_QOS_POLICY_RELIABLE:
datawriter_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
break;
case RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT:
break;
default:
RMW_SET_ERROR_MSG("Unknown QoS reliability policy");
goto fail;
}

if (qos_profile.depth != RMW_QOS_POLICY_DEPTH_SYSTEM_DEFAULT) {
datawriter_qos.history.depth = static_cast<DDS_Long>(qos_profile.depth);
}

// ensure the history depth is at least the requested queue size
assert(datawriter_qos.history.depth >= 0);
if (
datawriter_qos.history.kind == DDS::KEEP_LAST_HISTORY_QOS &&
static_cast<size_t>(datawriter_qos.history.depth) < qos_profile.depth
)
{
if (qos_profile.depth > (std::numeric_limits<DDS_Long>::max)()) {
RMW_SET_ERROR_MSG("requested queue size exceeds maximum DDS history depth");
goto fail;
}
datawriter_qos.history.depth = static_cast<DDS_Long>(qos_profile.depth);
}

topic_writer = dds_publisher->create_datawriter(
topic, datawriter_qos, NULL, DDS_STATUS_MASK_NONE);
if (!topic_writer) {
Expand Down Expand Up @@ -1316,56 +1270,11 @@ rmw_create_subscription(
}
}

if (!get_datareader_qos(participant, datareader_qos)) {
if (!get_datareader_qos(participant, qos_profile, datareader_qos)) {
// error string was set within the function
goto fail;
}

switch (qos_profile.history) {
case RMW_QOS_POLICY_KEEP_LAST_HISTORY:
datareader_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
break;
case RMW_QOS_POLICY_KEEP_ALL_HISTORY:
datareader_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS;
break;
case RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT:
break;
default:
RMW_SET_ERROR_MSG("Unknown QoS history policy");
goto fail;
}

switch (qos_profile.reliability) {
case RMW_QOS_POLICY_BEST_EFFORT:
datareader_qos.reliability.kind = DDS_BEST_EFFORT_RELIABILITY_QOS;
break;
case RMW_QOS_POLICY_RELIABLE:
datareader_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
break;
case RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT:
break;
default:
RMW_SET_ERROR_MSG("Unknown QoS reliability policy");
goto fail;
}

if (qos_profile.depth != RMW_QOS_POLICY_DEPTH_SYSTEM_DEFAULT) {
datareader_qos.history.depth = static_cast<DDS_Long>(qos_profile.depth);
}

// ensure the history depth is at least the requested queue size
assert(datareader_qos.history.depth >= 0);
if (
datareader_qos.history.kind == DDS::KEEP_LAST_HISTORY_QOS &&
static_cast<size_t>(datareader_qos.history.depth) < qos_profile.depth)
{
if (qos_profile.depth > (std::numeric_limits<DDS_Long>::max)()) {
RMW_SET_ERROR_MSG("requested queue size exceeds maximum DDS history depth");
goto fail;
}
datareader_qos.history.depth = static_cast<DDS_Long>(qos_profile.depth);
}

topic_reader = dds_subscriber->create_datareader(
topic, datareader_qos, NULL, DDS_STATUS_MASK_NONE);
if (!topic_reader) {
Expand Down Expand Up @@ -2145,7 +2054,8 @@ rmw_client_t *
rmw_create_client(
const rmw_node_t * node,
const rosidl_service_type_support_t * type_support,
const char * service_name)
const char * service_name,
const rmw_qos_profile_t & qos_profile)
{
if (!node) {
RMW_SET_ERROR_MSG("node handle is null");
Expand Down Expand Up @@ -2261,11 +2171,11 @@ rmw_create_client(

// create requester
{
if (!get_datareader_qos(participant, datareader_qos)) {
if (!get_datareader_qos(participant, qos_profile, datareader_qos)) {
// error string was set within the function
goto fail;
}
if (!get_datawriter_qos(participant, datawriter_qos)) {
if (!get_datawriter_qos(participant, qos_profile, datawriter_qos)) {
// error string was set within the function
goto fail;
}
Expand Down Expand Up @@ -2498,7 +2408,8 @@ rmw_service_t *
rmw_create_service(
const rmw_node_t * node,
const rosidl_service_type_support_t * type_support,
const char * service_name)
const char * service_name,
const rmw_qos_profile_t & qos_profile)
{
if (!node) {
RMW_SET_ERROR_MSG("node handle is null");
Expand Down Expand Up @@ -2617,11 +2528,11 @@ rmw_create_service(
buf = nullptr; // Only free the casted pointer; don't need the buf anymore.

{
if (!get_datareader_qos(participant, datareader_qos)) {
if (!get_datareader_qos(participant, qos_profile, datareader_qos)) {
// error string was set within the function
goto fail;
}
if (!get_datawriter_qos(participant, datawriter_qos)) {
if (!get_datawriter_qos(participant, qos_profile, datawriter_qos)) {
// error string was set within the function
goto fail;
}
Expand Down
Loading

0 comments on commit 030772b

Please sign in to comment.