Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
added NOLINT whenever both cpplint and uncrustify cannot be satisfied
ament/ament_lint#158

Signed-off-by: Harsh Deshpande <harshavardhan.deshpande@ipa.fraunhofer.de>
  • Loading branch information
hsd-dev committed Jan 13, 2022
1 parent 1c64f10 commit 305bffd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 41 deletions.
9 changes: 6 additions & 3 deletions include/ros1_bridge/action_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class ActionFactory_1_2 : public ActionFactoryInterface
client_ = rclcpp_action::create_client<ROS2_T>(ros2_node, action_name);
}

virtual void shutdown() {
virtual void shutdown()
{
std::lock_guard<std::mutex> lock(mutex_);
for (auto goal : goals_) {
std::thread([handler = goal.second]() mutable {handler->cancel();}).detach();
Expand Down Expand Up @@ -147,7 +148,8 @@ class ActionFactory_1_2 : public ActionFactoryInterface
std::shared_future<ROS2ClientGoalHandle> gh2_future;
// Changes as per Dashing
auto send_goal_ops = ROS2SendGoalOptions();
send_goal_ops.goal_response_callback = [this, &gh2_future](std::shared_future<ROS2GoalHandle> gh2) mutable {
send_goal_ops.goal_response_callback =
[this, &gh2_future](std::shared_future<ROS2GoalHandle> gh2) mutable {
auto goal_handle = gh2_future.get();
if (!goal_handle) {
gh1_.setRejected(); // goal was not accepted by remote server
Expand Down Expand Up @@ -253,7 +255,8 @@ class ActionFactory_2_1 : public ActionFactoryInterface
std::bind(&ActionFactory_2_1::handle_accepted, this, std::placeholders::_1));
}

virtual void shutdown() {
virtual void shutdown()
{
std::lock_guard<std::mutex> lock(mutex_);
for (auto goal : goals_) {
std::thread([handler = goal.second]() mutable {handler->cancel();}).detach();
Expand Down
28 changes: 16 additions & 12 deletions ros1_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from io import StringIO # Python 3.x

import genmsg
import genmsg.msg_loader
from genmsg.base import COMMENTCHAR, IODELIM
import genmsg.msg_loader

import rosidl_adapter.parser
from rosidl_cmake import expand_template
Expand Down Expand Up @@ -408,7 +408,7 @@ def get_ros1_actions(rospack=None):
# actual function: rosmsg.iterate_packages(rospack, rosmsg.MODE_MSG))
pkgs = sorted(x for x in iterate_action_packages(rospack))
for package_name, path in pkgs:
for action_name in rosmsg._list_types(path, 'msg', ".action"):
for action_name in rosmsg._list_types(path, 'msg', '.action'):
actions.append(Message(package_name, action_name, path))
return actions

Expand Down Expand Up @@ -447,7 +447,8 @@ def get_ros2_actions():
file=sys.stderr)
continue
for data in content:
if all(n not in data for n in ('ros1_message_name', 'ros2_message_name', 'ros1_service_name', 'ros2_service_name')):
if (all(n not in data for n in ('ros1_message_name', 'ros2_message_name',
'ros1_service_name', 'ros2_service_name'))):
try:
rules.append(ActionMappingRule(data, package_name))
except Exception as e:
Expand Down Expand Up @@ -869,7 +870,9 @@ def determine_common_actions(
# the check for 'builtin_interfaces' should be removed
# once merged with __init__.py
# It seems to handle it already
if (ros1_type, ros2_type) not in message_string_pairs and not ros2_type.startswith("builtin_interfaces") and "GripperCommand" not in ros2_type:
if ((ros1_type, ros2_type) not in message_string_pairs and
not ros2_type.startswith('builtin_interfaces') and
'GripperCommand' not in ros2_type):
match = False
break
output[direction].append({
Expand Down Expand Up @@ -1074,6 +1077,7 @@ def load_ros1_service(ros1_srv):


# genmsg/actions.py

class ActionSpec(object):

def __init__(self, goal, result, feedback, text, full_name='', short_name='', package=''):
Expand Down Expand Up @@ -1109,12 +1113,11 @@ def __ne__(self, other):
return not self.__eq__(other)

def __repr__(self):
return "ActionSpec[%s, %s, %s]" % (repr(self.goal), repr(self.result), repr(self.feedback))
return 'ActionSpec[%s, %s, %s]' % (repr(self.goal), repr(self.result), repr(self.feedback))


# genmsg.msg_loader


def load_action_from_string(msg_context, text, full_name):
"""
Load :class:`ActionSpec` from the .action file.
Expand All @@ -1132,15 +1135,15 @@ def load_action_from_string(msg_context, text, full_name):
count = 0
accum = text_goal
for l in text.split('\n'):
l = l.split(COMMENTCHAR)[0].strip() # strip comments
if l.startswith(IODELIM): # lenient, by request
s = l.split(COMMENTCHAR)[0].strip() # strip comments
if s.startswith(IODELIM): # lenient, by request
if count == 0:
accum = text_result
count = 1
else:
accum = text_feedback
else:
accum.write(l+'\n')
accum.write(s+'\n')

# create separate MsgSpec objects for each half of file
msg_goal = genmsg.msg_loader.load_msg_from_string(
Expand All @@ -1156,8 +1159,8 @@ def load_action_from_string(msg_context, text, full_name):
def load_action_from_file(msg_context, file_path, full_name):
"""
Convert the .action representation in the file to a :class:`MsgSpec` instance.
NOTE: this will register the message in the *msg_context*.
NOTE: this will register the message in the *msg_context*.
:param file_path: path of file to load from, ``str``
:returns: :class:`MsgSpec` instance
:raises: :exc:`InvalidMsgSpec`: if syntax errors or other problems are detected in file
Expand All @@ -1177,7 +1180,8 @@ def load_ros1_action(ros1_action):
ros1_action.prefix_path, ros1_action.message_name + '.action')
try:
spec = load_action_from_file(
msg_context, message_path, '%s/%s' % (ros1_action.package_name, ros1_action.message_name))
msg_context, message_path, '%s/%s' %
(ros1_action.package_name, ros1_action.message_name))
except genmsg.InvalidMsgSpec:
return None
return spec
Expand Down Expand Up @@ -1245,7 +1249,7 @@ def load_ros2_action(ros2_action):
spec = rosidl_adapter.parser.parse_action_file(
ros2_action.package_name, actiom_path)
except rosidl_adapter.parser.InvalidSpecification:
print("Invalid spec")
print('Invalid spec')
return None
return spec

Expand Down
68 changes: 42 additions & 26 deletions src/dynamic_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <string>
#include <utility>
#include <vector>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/predicate.hpp> // NOLINT

// include ROS 1
#ifdef __clang__
Expand Down Expand Up @@ -151,8 +151,10 @@ void update_bridge(
std::map<std::string, Bridge2to1HandlesAndMessageTypes> & bridges_2to1,
std::map<std::string, ros1_bridge::ServiceBridge1to2> & service_bridges_1_to_2,
std::map<std::string, ros1_bridge::ServiceBridge2to1> & service_bridges_2_to_1,
std::map<std::string, std::unique_ptr<ros1_bridge::ActionFactoryInterface>> & action_bridges_1_to_2,
std::map<std::string, std::unique_ptr<ros1_bridge::ActionFactoryInterface>> & action_bridges_2_to_1,
std::map<std::string,
std::unique_ptr<ros1_bridge::ActionFactoryInterface>> & action_bridges_1_to_2,
std::map<std::string,
std::unique_ptr<ros1_bridge::ActionFactoryInterface>> & action_bridges_2_to_1,
bool bridge_all_1to2_topics, bool bridge_all_2to1_topics)
{
std::lock_guard<std::mutex> lock(g_bridge_mutex);
Expand Down Expand Up @@ -569,9 +571,12 @@ inline bool is_action_topic(
// action type is 'Fibonacci'
if (!type.empty() && is_action_type) {
std::string pkg_name = type.substr(0, type.find("/"));
std::string action_type = type.substr(type.find_last_of("/") + 1, type.length() - (type.find_last_of("/") + type_ends_with.length() + 1));
std::string action_type =
type.substr(
type.find_last_of("/") + 1,
type.length() - (type.find_last_of("/") + type_ends_with.length() + 1));
actions[name]["package"] = pkg_name;
if(is_ros2) {
if (is_ros2) {
actions[name]["type"] = "action/" + action_type;
} else {
actions[name]["type"] = action_type;
Expand Down Expand Up @@ -605,31 +610,34 @@ void get_active_ros1_actions(

for (it = publishers.begin(); it != publishers.end(); it++) {
// check for action client
if (is_action_topic(
if (
is_action_topic(
active_ros1_action_clients, action_client_nums, false,
it->first.c_str(), "/cancel", it->second.c_str(), "/GoalID"))
{
continue;
} else if (is_action_topic(
} else if ( // NOLINT
is_action_topic(
active_ros1_action_clients, action_client_nums, true,
it->first.c_str(), "/goal", it->second.c_str(), "ActionGoal"))
{
continue;
}
// check for action server
else if (is_action_topic(
} else if ( // NOLINT // check for action server
is_action_topic(
active_ros1_action_servers, action_server_nums, true,
it->first.c_str(), "/feedback", it->second.c_str(),
"ActionFeedback"))
{
continue;
}
if (is_action_topic(
if (
is_action_topic(
active_ros1_action_servers, action_server_nums, false,
it->first.c_str(), "/result", it->second.c_str(), "ActionResult"))
{
continue;
} else if (is_action_topic(
} else if ( // NOLINT
is_action_topic(
active_ros1_action_servers, action_server_nums, false,
it->first.c_str(), "/status", it->second.c_str(),
"GoalStatusArray"))
Expand All @@ -641,29 +649,32 @@ void get_active_ros1_actions(
// subscribers do not report their types, but use it to confirm action
for (it = subscribers.begin(); it != subscribers.end(); it++) {
// check for action server
if (is_action_topic(
if (
is_action_topic(
active_ros1_action_servers, action_server_nums, false,
it->first.c_str(), "/cancel", it->second.c_str(), ""))
{
continue;
} else if (is_action_topic(
} else if ( // NOLINT
is_action_topic(
active_ros1_action_servers, action_server_nums, false,
it->first.c_str(), "/goal", it->second.c_str(), ""))
{
continue;
}
// check for action client
else if (is_action_topic(
} else if ( // NOLINT // check for action client
is_action_topic(
active_ros1_action_clients, action_client_nums, false,
it->first.c_str(), "/feedback", it->second.c_str(), ""))
{
continue;
} else if (is_action_topic(
} else if ( // NOLINT
is_action_topic(
active_ros1_action_clients, action_client_nums, false,
it->first.c_str(), "/result", it->second.c_str(), ""))
{
continue;
} else if (is_action_topic(
} else if ( // NOLINT
is_action_topic(
active_ros1_action_clients, action_client_nums, false,
it->first.c_str(), "/status", it->second.c_str(), ""))
{
Expand Down Expand Up @@ -696,12 +707,14 @@ void get_active_ros2_actions(
std::map<std::string, uint8_t>::iterator it_num;
std::map<std::string, uint8_t> action_server_nums, action_client_nums;
for (it = active_ros2_publishers.begin(); it != active_ros2_publishers.end(); it++) {
if (is_action_topic(
if (
is_action_topic(
active_ros2_action_servers, action_server_nums, true, it->first.c_str(),
"/_action/feedback", it->second.c_str(), "_FeedbackMessage", true))
{
continue;
} else if (is_action_topic(
} else if ( // NOLINT
is_action_topic(
active_ros2_action_servers, action_server_nums, false,
it->first.c_str(), "/_action/status", it->second.c_str(),
"GoalStatusArray"), true)
Expand All @@ -710,13 +723,15 @@ void get_active_ros2_actions(
}
}
for (it = active_ros2_subscribers.begin(); it != active_ros2_subscribers.end(); it++) {
if (is_action_topic(
if (
is_action_topic(
active_ros2_action_clients, action_client_nums, true,
it->first.c_str(), "/_action/feedback", it->second.c_str(),
"_FeedbackMessage", true))
{
continue;
} else if (is_action_topic(
} else if ( // NOLINT
is_action_topic(
active_ros2_action_clients, action_client_nums, false,
it->first.c_str(), "/_action/status", it->second.c_str(),
"GoalStatusArray", true))
Expand All @@ -734,7 +749,6 @@ void get_active_ros2_actions(
active_ros2_action_servers.erase(it_num->first);
}
}

}

int main(int argc, char * argv[])
Expand Down Expand Up @@ -889,7 +903,8 @@ int main(int argc, char * argv[])
}

// check actions
std::map<std::string, std::map<std::string, std::string>> active_ros1_action_servers, active_ros1_action_clients;
std::map<std::string, std::map<std::string, std::string>> active_ros1_action_servers,
active_ros1_action_clients;
get_active_ros1_actions(
current_ros1_publishers, current_ros1_subscribers,
active_ros1_action_servers, active_ros1_action_clients);
Expand Down Expand Up @@ -1066,7 +1081,8 @@ int main(int argc, char * argv[])
}
}

std::map<std::string, std::map<std::string, std::string>> active_ros2_action_servers, active_ros2_action_clients;
std::map<std::string, std::map<std::string, std::string>> active_ros2_action_servers,
active_ros2_action_clients;
get_active_ros2_actions(
current_ros2_publishers, current_ros2_subscribers,
active_ros2_action_servers, active_ros2_action_clients);
Expand Down

0 comments on commit 305bffd

Please sign in to comment.