Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ddsenabler/examples/action/CLIParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CLIParser
struct example_config
{
std::string config_file_path = "";
std::string action_name = "fibonacci/_action/";
std::string action_name = "fibonacci";
Comment thread
juanlofer-eprosima marked this conversation as resolved.
bool announce_server = true;
uint32_t timeout = 30;
std::string persistence_path = "";
Expand Down Expand Up @@ -60,7 +60,7 @@ class CLIParser
std::endl;
std::cout << "--action-name <str> Name of the action to be registered" <<
std::endl;
std::cout << " (Default: 'Fibonacci/_action/')" <<
std::cout << " (Default: 'fibonacci')" <<
std::endl;
std::cout << "--timeout <num> Time (seconds) to wait before stopping the" <<
std::endl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"action_name": "fibonacci/_action/",
"action_name": "fibonacci",
"cancel_reply_action_serialized_qos": "reliability: true\ndurability: false\nownership: false\nkeyed: false",
"cancel_reply_action_type": "action_msgs::srv::dds_::CancelGoal_Response_",
"cancel_request_action_serialized_qos": "reliability: true\ndurability: false\nownership: false\nkeyed: false",
Expand Down
4 changes: 2 additions & 2 deletions ddsenabler/test/ddsEnablerTests/DdsEnablerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ TEST_F(DDSEnablerTest, action_client)
std::this_thread::sleep_for(std::chrono::seconds(2));

std::string json = "{\"order\": 20}";
std::string action_name = "fibonacci/_action/";
std::string action_name = "fibonacci";
UUID action_id;

ASSERT_FALSE(enabler->send_action_goal(action_name, json, action_id));
Expand All @@ -439,7 +439,7 @@ TEST_F(DDSEnablerTest, action_server)
auto enabler = create_ddsenabler();
ASSERT_TRUE(enabler != nullptr);

std::string action_name = "fibonacci/_action/";
std::string action_name = "fibonacci";

ASSERT_FALSE(enabler->revoke_action(action_name));
ASSERT_TRUE(enabler->announce_action(action_name));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"action_name": "fibonacci/_action/",
"action_name": "fibonacci",
"cancel_reply_action_serialized_qos": "reliability: true\ndurability: false\nownership: false\nkeyed: false",
"cancel_reply_action_type": "action_msgs::srv::dds_::CancelGoal_Response_",
"cancel_request_action_serialized_qos": "reliability: true\ndurability: false\nownership: false\nkeyed: false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ constexpr const char* DDS_REPLY_PREFIX("");
constexpr const char* DDS_REPLY_SUFFIX("_Reply");

// Action mangling
constexpr const char* ACTION_INFIX("/_action/");
constexpr const char* ACTION_GOAL_SUFFIX("send_goal");
constexpr const char* ACTION_RESULT_SUFFIX("get_result");
constexpr const char* ACTION_CANCEL_SUFFIX("cancel_goal");
Expand Down
26 changes: 13 additions & 13 deletions ddsenabler_participants/src/cpp/EnablerParticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ bool EnablerParticipant::send_action_goal(
Protocol Protocol)
{
std::string goal_json = RpcUtils::create_goal_request_msg(json, action_id);
std::string goal_request_topic = action_name + ACTION_GOAL_SUFFIX;
std::string goal_request_topic = action_name + ACTION_INFIX + ACTION_GOAL_SUFFIX;
uint64_t goal_request_id = 0;

if (!send_service_request(
Expand Down Expand Up @@ -561,7 +561,7 @@ bool EnablerParticipant::cancel_action_goal(
Protocol protocol = handler_->get_action_protocol(action_name, goal_id);

uint64_t cancel_request_id = 0;
std::string cancel_request_topic = action_name + ACTION_CANCEL_SUFFIX;
std::string cancel_request_topic = action_name + ACTION_INFIX + ACTION_CANCEL_SUFFIX;

if (send_service_request(
cancel_request_topic,
Expand All @@ -583,7 +583,7 @@ bool EnablerParticipant::send_action_get_result_request(
{
std::string json = RpcUtils::create_result_request_msg(action_id);

std::string get_result_request_topic = action_name + ACTION_RESULT_SUFFIX;
std::string get_result_request_topic = action_name + ACTION_INFIX + ACTION_RESULT_SUFFIX;
uint64_t get_result_request_id = 0;

Protocol protocol = handler_->get_action_protocol(action_name, action_id);
Expand Down Expand Up @@ -623,7 +623,7 @@ void EnablerParticipant::send_action_send_goal_reply(
std::string reply_json = RpcUtils::create_goal_reply_msg(accepted);

if (!send_service_reply(
action_name + ACTION_GOAL_SUFFIX,
action_name + ACTION_INFIX + ACTION_GOAL_SUFFIX,
reply_json,
goal_id))
{
Expand Down Expand Up @@ -654,7 +654,7 @@ bool EnablerParticipant::send_action_cancel_goal_reply(
std::string reply_json = RpcUtils::create_cancel_reply_msg(cancelling_goals, cancel_code);

if (!send_service_reply(
std::string(action_name) + ACTION_CANCEL_SUFFIX,
std::string(action_name) + ACTION_INFIX + ACTION_CANCEL_SUFFIX,
reply_json,
request_id))
{
Expand Down Expand Up @@ -691,7 +691,7 @@ bool EnablerParticipant::send_action_get_result_reply(
const std::string& reply_json,
const uint64_t request_id)
{
std::string result_topic = action_name + ACTION_RESULT_SUFFIX;
std::string result_topic = action_name + ACTION_INFIX + ACTION_RESULT_SUFFIX;

if (send_service_reply(
result_topic,
Expand Down Expand Up @@ -740,7 +740,7 @@ bool EnablerParticipant::send_action_feedback(
}

std::string feedback_json = RpcUtils::create_feedback_msg(json, goal_id);
std::string feedback_topic = prefix + std::string(action_name) + ACTION_FEEDBACK_SUFFIX;
std::string feedback_topic = prefix + std::string(action_name) + ACTION_INFIX + ACTION_FEEDBACK_SUFFIX;

return publish(feedback_topic, feedback_json);
}
Expand Down Expand Up @@ -778,7 +778,7 @@ bool EnablerParticipant::update_action_status(
}

std::string status_json = RpcUtils::create_status_msg(goal_id, status_code, goal_accepted_stamp);
std::string status_topic = prefix + action_name + ACTION_STATUS_SUFFIX;
std::string status_topic = prefix + action_name + ACTION_INFIX + ACTION_STATUS_SUFFIX;
return publish(status_topic, status_json);
}

Expand Down Expand Up @@ -856,9 +856,9 @@ bool EnablerParticipant::query_action_nts_(
return false;
}

std::string goal_service_name = action.action_name + ACTION_GOAL_SUFFIX;
std::string cancel_service_name = action.action_name + ACTION_CANCEL_SUFFIX;
std::string result_service_name = action.action_name + ACTION_RESULT_SUFFIX;
std::string goal_service_name = action.action_name + ACTION_INFIX + ACTION_GOAL_SUFFIX;
std::string cancel_service_name = action.action_name + ACTION_INFIX + ACTION_CANCEL_SUFFIX;
std::string result_service_name = action.action_name + ACTION_INFIX + ACTION_RESULT_SUFFIX;
std::vector<std::string> topics_names =
{
goal_service_name,
Expand Down Expand Up @@ -950,7 +950,7 @@ bool EnablerParticipant::query_action_nts_(
return false;
}

std::string feedback_topic_name = prefix + action.action_name + ACTION_FEEDBACK_SUFFIX;
std::string feedback_topic_name = prefix + action.action_name + ACTION_INFIX + ACTION_FEEDBACK_SUFFIX;
DdsTopic feedback_topic;
if (!fill_topic_struct_nts_(
feedback_topic_name,
Expand Down Expand Up @@ -980,7 +980,7 @@ bool EnablerParticipant::query_action_nts_(
action.feedback = feedback_topic;
action.feedback_discovered = true;

std::string status_topic_name = prefix + action.action_name + ACTION_STATUS_SUFFIX;
std::string status_topic_name = prefix + action.action_name + ACTION_INFIX + ACTION_STATUS_SUFFIX;
DdsTopic status_topic;
if (!fill_topic_struct_nts_(
status_topic_name,
Expand Down
101 changes: 73 additions & 28 deletions ddsenabler_participants/src/cpp/rpc/RpcStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ namespace eprosima {
namespace ddsenabler {
namespace participants {

/**
* Remove the ACTION_INFIX ("/_action/") substring from @p name wherever it occurs.
*
* @param [in, out] name The name to be stripped.
* @return true and updates @p name if the infix was found; false otherwise.
*/
static bool strip_action_infix(
std::string& name)
{
const std::size_t pos = name.find(ACTION_INFIX);
if (pos == std::string::npos)
{
return false;
}
name.erase(pos, std::strlen(ACTION_INFIX));
return true;
}

RpcAction::RpcAction(
const std::string& action_name,
const ddspipe::core::types::RpcTopic& goal,
Expand Down Expand Up @@ -115,32 +133,43 @@ void RpcInfo::extract_rpc_info()
service_type = ServiceType::REQUEST;
service_name = base;

if (strip_action_infix(base))
{
rpc_type = RpcType::ACTION;
}

if (rpc_type != RpcType::ACTION)
{
rpc_type = RpcType::SERVICE;
return;
}

// Check the action type suffix, and extract the action name
if (base.size() >= (std::strlen(ACTION_GOAL_SUFFIX)) &&
base.substr(base.size() - (std::strlen(ACTION_GOAL_SUFFIX))) == ACTION_GOAL_SUFFIX)
{
action_name = base.substr(0, base.size() - (std::strlen(ACTION_GOAL_SUFFIX)));
rpc_type = RpcType::ACTION;
action_type = ActionType::GOAL;
return;
}
else if (base.size() >= (std::strlen(ACTION_RESULT_SUFFIX)) &&
base.substr(base.size() - (std::strlen(ACTION_RESULT_SUFFIX))) == ACTION_RESULT_SUFFIX)
{
action_name = base.substr(0, base.size() - (std::strlen(ACTION_RESULT_SUFFIX)));
rpc_type = RpcType::ACTION;
action_type = ActionType::RESULT;
return;
}
else if (base.size() >= (std::strlen(ACTION_CANCEL_SUFFIX)) &&
base.substr(base.size() - (std::strlen(ACTION_CANCEL_SUFFIX))) == ACTION_CANCEL_SUFFIX)
{
action_name = base.substr(0, base.size() - (std::strlen(ACTION_CANCEL_SUFFIX)));
rpc_type = RpcType::ACTION;
action_type = ActionType::CANCEL;
return;
}

rpc_type = RpcType::SERVICE;
else
{
EPROSIMA_LOG_ERROR(DDSENABLER_RPC_UTILS,
"Failed to extract RPC info from topic name " << topic_name <<
": unknown action request type suffix");
throw std::runtime_error("Unknown action request type suffix");
}
return;
}

Expand All @@ -154,58 +183,74 @@ void RpcInfo::extract_rpc_info()
service_type = ServiceType::REPLY;
service_name = base;

if (strip_action_infix(base))
{
rpc_type = RpcType::ACTION;
}

if (rpc_type != RpcType::ACTION)
{
rpc_type = RpcType::SERVICE;
return;
}

if (base.size() >= (std::strlen(ACTION_GOAL_SUFFIX)) &&
base.substr(base.size() - (std::strlen(ACTION_GOAL_SUFFIX))) == ACTION_GOAL_SUFFIX)
{
action_name = base.substr(0, base.size() - (std::strlen(ACTION_GOAL_SUFFIX)));
rpc_type = RpcType::ACTION;
action_type = ActionType::GOAL;
return;
}
else if (base.size() >= (std::strlen(ACTION_RESULT_SUFFIX)) &&
base.substr(base.size() - (std::strlen(ACTION_RESULT_SUFFIX))) == ACTION_RESULT_SUFFIX)
{
action_name = base.substr(0, base.size() - (std::strlen(ACTION_RESULT_SUFFIX)));
rpc_type = RpcType::ACTION;
action_type = ActionType::RESULT;
return;
}
else if (base.size() >= (std::strlen(ACTION_CANCEL_SUFFIX)) &&
base.substr(base.size() - (std::strlen(ACTION_CANCEL_SUFFIX))) == ACTION_CANCEL_SUFFIX)
{
action_name = base.substr(0, base.size() - (std::strlen(ACTION_CANCEL_SUFFIX)));
rpc_type = RpcType::ACTION;
action_type = ActionType::CANCEL;
return;
}

rpc_type = RpcType::SERVICE;
else
{
EPROSIMA_LOG_ERROR(DDSENABLER_RPC_UTILS,
"Failed to extract RPC info from topic name " << topic_name <<
": unknown action reply type suffix");
throw std::runtime_error("Unknown action reply type suffix");
}
return;
}

// Check for action feedback/status topics
if (Protocol::ROS2 != protocol) // Feedback and Status topics only exist for ROS2 actions
if (strip_action_infix(base))
{
rpc_type = RpcType::ACTION;
}
if (Protocol::ROS2 != protocol || rpc_type != RpcType::ACTION) // Feedback and Status topics only exist for ROS2 actions
{
return;
}
base = base.substr(topic_prefix.length());
if (base.size() >= (std::strlen(ACTION_FEEDBACK_SUFFIX) + 1) &&
base.substr(base.size() - (std::strlen(ACTION_FEEDBACK_SUFFIX) + 1)) ==
(std::string("/") + ACTION_FEEDBACK_SUFFIX))
if (base.size() >= (std::strlen(ACTION_FEEDBACK_SUFFIX)) &&
base.substr(base.size() - (std::strlen(ACTION_FEEDBACK_SUFFIX))) ==
(ACTION_FEEDBACK_SUFFIX))
{
action_name = base.substr(0, base.size() - std::strlen(ACTION_FEEDBACK_SUFFIX));
rpc_type = RpcType::ACTION;
action_name = base.substr(0, base.size() - (std::strlen(ACTION_FEEDBACK_SUFFIX)));
action_type = ActionType::FEEDBACK;
return;
}
if (base.size() >= (std::strlen(ACTION_STATUS_SUFFIX) + 1) &&
base.substr(base.size() - (std::strlen(ACTION_STATUS_SUFFIX) + 1)) ==
(std::string("/") + ACTION_STATUS_SUFFIX))
else if (base.size() >= (std::strlen(ACTION_STATUS_SUFFIX)) &&
base.substr(base.size() - (std::strlen(ACTION_STATUS_SUFFIX))) ==
(ACTION_STATUS_SUFFIX))
{
action_name = base.substr(0, base.size() - (std::strlen(ACTION_STATUS_SUFFIX)));
rpc_type = RpcType::ACTION;
action_type = ActionType::STATUS;
return;
}
else
{
EPROSIMA_LOG_ERROR(DDSENABLER_RPC_UTILS,
"Failed to extract RPC info from topic name " << topic_name << ": unknown topic type suffix");
throw std::runtime_error("Unknown topic type suffix");
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- std_net
volumes:
- ./config.yml:/config/config.yml
- ../persistence:/persistence
- ../persistence:/persistence:ro
command: ./install/ddsenabler/examples/action/ddsenabler_example_action client --persistence-path /persistence --goals-path /persistence/goals --config /config/config.yml --request-initial-wait 2

fibonacci_server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- std_net
volumes:
- ./config.yml:/config/config.yml
- ../persistence:/persistence
- ../persistence:/persistence:ro
command: ./install/ddsenabler/examples/action/ddsenabler_example_action client --persistence-path /persistence --goals-path /persistence/goals --config /config/config.yml --request-initial-wait 2 --cancel-requests true

fibonacci_server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- std_net
volumes:
- ./config.yml:/config/config.yml
- ../persistence:/persistence
- ../persistence:/persistence:ro
command: ./install/ddsenabler/examples/action/ddsenabler_example_action server --persistence-path /persistence --goals-path /persistence/goals --config /config/config.yml --expected-requests 3

fibonacci_client:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- std_net
volumes:
- ./config.yml:/config/config.yml
- ../persistence:/persistence
- ../persistence:/persistence:ro
command: ./install/ddsenabler/examples/action/ddsenabler_example_action server --persistence-path /persistence --goals-path /persistence/goals --config /config/config.yml --expected-requests 9

fibonacci_client_1:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"action_name": "fibonacci/_action/",
"action_name": "fibonacci",
"cancel_reply_action_serialized_qos": "reliability: true\ndurability: false\nownership: false\nkeyed: false",
"cancel_reply_action_type": "action_msgs::srv::dds_::CancelGoal_Response_",
"cancel_request_action_serialized_qos": "reliability: true\ndurability: false\nownership: false\nkeyed: false",
Expand All @@ -16,4 +16,4 @@
"result_request_action_type": "action_tutorials_interfaces::action::dds_::Fibonacci_GetResult_Request_",
"status_action_serialized_qos": "reliability: true\ndurability: true\nownership: false\nkeyed: false",
"status_action_type": "action_msgs::msg::dds_::GoalStatusArray_"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- std_net
volumes:
- ./config.yml:/config/config.yml
- ../persistence:/persistence
- ../persistence:/persistence:ro
command: ./install/ddsenabler/examples/service/ddsenabler_example_service client --persistence-path /persistence --requests-path /persistence/requests --config /config/config.yml --request-initial-wait 2
add_two_ints_server:
image: ${DDSENABLER_COMPOSE_TEST_ROS2_DOCKER_IMAGE}
Expand Down
Loading
Loading