forked from ros2/ros1_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor command parser to use vector of char* Signed-off-by: LucasHaug <[email protected]> * Add argc argv splitter to dynamic bridge Signed-off-by: LucasHaug <[email protected]> * Add argc argv splitter to paramter bridge Signed-off-by: LucasHaug <[email protected]> * Update github action Signed-off-by: LucasHaug <[email protected]> * Fix parameter bridge argv split Signed-off-by: LucasHaug <[email protected]> * Remove static argv reading Signed-off-by: LucasHaug <[email protected]> * Add command parser to parameter bridge Signed-off-by: LucasHaug <[email protected]> * Fix compilation errors Signed-off-by: LucasHaug <[email protected]> * Fix compilation errors Signed-off-by: LucasHaug <[email protected]> * Fix parameter bidge command parser Signed-off-by: LucasHaug <[email protected]> * Refactor to add command parser utils file Signed-off-by: LucasHaug <[email protected]> * Add github action issue workaround Signed-off-by: LucasHaug <[email protected]> * Ty to run github action inside container Signed-off-by: LucasHaug <[email protected]> * Fix ROS2 args when no ROS1 args Signed-off-by: LucasHaug <[email protected]> * ⏪ Revert changes on GitHub Action config Signed-off-by: LucasHaug <[email protected]> * Change parameter bridge ROS init order Signed-off-by: LucasHaug <[email protected]> * Rename parser functions Signed-off-by: LucasHaug <[email protected]> * Add get_option_values function Signed-off-by: LucasHaug <[email protected]> * Fix wrong help for the parameter bridge Signed-off-by: LucasHaug <[email protected]> * Fix get_option_values parser function Signed-off-by: LucasHaug <[email protected]> * Refactor bridges to use the get_option_values Signed-off-by: LucasHaug <[email protected]> * Add running scetion to README Signed-off-by: LucasHaug <[email protected]> * Add print pairs to parameter bridge --------- Signed-off-by: LucasHaug <[email protected]> Co-authored-by: LucasHaug <[email protected]>
- Loading branch information
1 parent
3d5328d
commit b868d16
Showing
7 changed files
with
421 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,3 @@ jobs: | |
package-name: ros1_bridge | ||
target-ros1-distro: noetic | ||
target-ros2-distro: rolling | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2015 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. | ||
|
||
#ifndef ROS1_BRIDGE__COMMAND_PARSER_UTILS_HPP_ | ||
#define ROS1_BRIDGE__COMMAND_PARSER_UTILS_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace ros1_bridge | ||
{ | ||
|
||
bool find_command_option( | ||
const std::vector<const char *> & args, | ||
const std::string & option); | ||
|
||
bool get_option_value( | ||
std::vector<const char *> & args, | ||
const std::string & option, | ||
const char * & value, | ||
bool remove = false); | ||
|
||
bool get_option_values( | ||
std::vector<const char *> & args, const std::string & option, | ||
std::vector<const char *> & available_options, | ||
std::vector<const char *> & values, bool remove = false); | ||
|
||
bool get_option_flag( | ||
std::vector<const char *> & args, | ||
const std::string & option, | ||
bool remove = false); | ||
|
||
void split_ros1_ros2_args( | ||
const std::vector<const char *> & args, | ||
std::vector<const char *> & ros1_args, | ||
std::vector<const char *> & ros2_args); | ||
|
||
} // namespace ros1_bridge | ||
|
||
#endif // ROS1_BRIDGE__COMMAND_PARSER_UTILS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright 2015 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 "ros1_bridge/command_parser_utils.hpp" | ||
|
||
#include <algorithm> | ||
#include <cstring> | ||
|
||
namespace ros1_bridge | ||
{ | ||
|
||
bool find_command_option(const std::vector<const char *> & args, const std::string & option) | ||
{ | ||
auto it = std::find_if(args.begin(), args.end(), [&option] (const char * const & element) { | ||
return strcmp(element, option.c_str()) == 0; | ||
}); | ||
|
||
return it != args.end(); | ||
} | ||
|
||
bool get_option_value(std::vector<const char *> & args, const std::string & option, const char * & value, bool remove) | ||
{ | ||
auto it = std::find_if(args.begin(), args.end(), [&option] (const char * const & element) { | ||
return strcmp(element, option.c_str()) == 0; | ||
}); | ||
|
||
if (it != args.end()) { | ||
auto value_it = std::next(it); | ||
|
||
if (value_it != args.end()) { | ||
value = *value_it; | ||
|
||
if (remove) { | ||
args.erase(it); // Remove option | ||
args.erase(it); // Remove value | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool get_option_values( | ||
std::vector<const char *> & args, const std::string & option, | ||
std::vector<const char *> & available_options, | ||
std::vector<const char *> & values, bool remove) | ||
{ | ||
auto it = std::find_if(args.begin(), args.end(), [&option] (const char * const & element) { | ||
return strcmp(element, option.c_str()) == 0; | ||
}); | ||
|
||
if (it != args.end()) { | ||
auto value_it = std::next(it); | ||
|
||
while (value_it != args.end() and | ||
std::none_of(available_options.begin(), available_options.end(), | ||
[value_it](const char * available_option) { | ||
return strcmp(*value_it, available_option) == 0; | ||
})) { | ||
values.push_back(*value_it); | ||
|
||
if (remove) { | ||
args.erase(value_it); | ||
} else { | ||
++value_it; | ||
} | ||
} | ||
|
||
if (remove) { | ||
args.erase(it); // Remove option | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool get_option_flag(std::vector<const char *> & args, const std::string & option, bool remove) | ||
{ | ||
auto it = std::find_if(args.begin(), args.end(), [&option] (const char * const & element) { | ||
return strcmp(element, option.c_str()) == 0; | ||
}); | ||
|
||
if (it != args.end()) { | ||
if (remove) { | ||
args.erase(it); | ||
} | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void split_ros1_ros2_args( | ||
const std::vector<const char *> & args, std::vector<const char *> & ros1_args, | ||
std::vector<const char *> & ros2_args) | ||
{ | ||
// Start iterating from the second argument, since the first argument is the executable name | ||
auto it = std::find_if(args.begin() + 1, args.end(), [] (const char * const & element) { | ||
return strcmp(element, "--ros-args") == 0; | ||
}); | ||
|
||
if (it != args.end()) { | ||
ros1_args = std::vector<const char *>(args.begin(), it); | ||
ros2_args = std::vector<const char *>(it, args.end()); | ||
} else { | ||
ros1_args = args; | ||
ros2_args = {}; | ||
} | ||
|
||
ros2_args.insert(ros2_args.begin(), args.at(0)); | ||
} | ||
|
||
} // namespace ros1_bridge |
Oops, something went wrong.