Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
3f68319
rcl_node_namespace() implemented
sloretz Feb 2, 2018
d77489f
Committing whatever is there, todo rewrite history
sloretz Feb 27, 2018
d160ca6
INIT_GLOBAL_ARGS test macro
sloretz Feb 28, 2018
949feee
rcl_remap_namespace -> rcl_remap_node_namespace
sloretz Feb 28, 2018
cbea457
Test local arguments used for namespace replacement
sloretz Feb 28, 2018
6f22ea3
Split topic and service remapping functions
sloretz Feb 28, 2018
896af8b
Test topic remap using local arugments
sloretz Feb 28, 2018
f50dde1
Terminate copied string with \0. Add service remap tests
sloretz Feb 28, 2018
55b17e6
Refactored remap rule parsing and application
sloretz Mar 1, 2018
5bd5106
Nodename replacement tests with validation fix
sloretz Mar 1, 2018
4a0ed73
Tests for rules with node-name prefixes
sloretz Mar 1, 2018
f4a23d0
Support remap rules with relative names
sloretz Mar 2, 2018
bbf2b15
Remove comment
sloretz Mar 2, 2018
b811a4f
Check allocator before using it
sloretz Mar 2, 2018
f12280d
uncrustify
sloretz Mar 2, 2018
4db3285
Remove out of date TODO
sloretz Mar 2, 2018
e21795a
rcl_node_init remaps node name
sloretz Mar 2, 2018
9c03f7a
Namespace remapping works. Fix logger name not being remapped
sloretz Mar 2, 2018
ad7790a
Node name and namespace obeys use_global_arguments
sloretz Mar 2, 2018
342c36a
rcl_node_init remaps using arguments supplied to options
sloretz Mar 2, 2018
0f2e2f2
Added failing tests for publisher topic remapping
sloretz Mar 3, 2018
f324e45
Publisher topic name can be remapped
sloretz Mar 5, 2018
f8bfd8e
Add tests for subscriber
sloretz Mar 5, 2018
1fa0f74
Subscription obeys remap rules
sloretz Mar 5, 2018
6e445fd
Client service name can be remapped
sloretz Mar 5, 2018
aecfb79
Service service can now be remapped
sloretz Mar 5, 2018
7b95137
Fix crash on invalid namespace
sloretz Mar 5, 2018
0484332
Fix leaks reported by ASAN
sloretz Mar 5, 2018
8023a33
Shorten sentence
sloretz Mar 7, 2018
21d0311
Shorten sentence
sloretz Mar 7, 2018
f04ed71
wrong param documentation
sloretz Mar 7, 2018
39214bd
Expand field documentation in node_options
sloretz Mar 7, 2018
d661f36
Fix parameter documentation
sloretz Mar 7, 2018
bd0b481
null local arguments and use_global_options false is invalid
sloretz Mar 7, 2018
f146ae9
Function documentation
sloretz Mar 7, 2018
ea03e51
RCL_LOCAL
sloretz Mar 7, 2018
0355ff5
RCL_LOCAL + documentation
sloretz Mar 7, 2018
de189e1
Doc + exit early if colon in replacement
sloretz Mar 7, 2018
3852c82
Comment
sloretz Mar 7, 2018
f86af0e
Swap lhs and rhs in comparison
sloretz Mar 7, 2018
25d5340
Add functions to get unparsed arguments
sloretz Mar 7, 2018
62c8154
Fix validation of match and replacement, test unparsed args functions
sloretz Mar 7, 2018
d74e537
Check that colon is not NULL
sloretz Mar 7, 2018
1b6cb90
consolidate tests for arguments
sloretz Mar 7, 2018
d971b01
Fix '/' not seen as a valid namespace
sloretz Mar 7, 2018
582ff8d
Change comparision
sloretz Mar 7, 2018
d2c2d68
Better cleanup in failure cases
sloretz Mar 7, 2018
a8528f2
Fix comment
sloretz Mar 8, 2018
6a59c19
fix leak in fini
sloretz Mar 8, 2018
97f68b4
Smarter arg macros
sloretz Mar 8, 2018
c7c52e7
Split remapping tests
sloretz Mar 8, 2018
65273b1
Fix windows error array of len 0
sloretz Mar 8, 2018
f5618ca
style
sloretz Mar 8, 2018
09dd51f
fix windows warning about strncpy
sloretz Mar 8, 2018
49fcf13
Fix windows warnings about data loss
sloretz Mar 8, 2018
b9c64fb
Remove memory_tools
sloretz Mar 8, 2018
2083bf3
Shorten test code
sloretz Mar 8, 2018
0f7c344
Rename fixture
sloretz Mar 8, 2018
b76273c
blank lines
sloretz Mar 8, 2018
b9f0108
Document arguments_impl
sloretz Mar 8, 2018
b6c056e
Remove memorytools
sloretz Mar 8, 2018
60d7747
style
sloretz Mar 8, 2018
51df697
Style
sloretz Mar 8, 2018
7963397
Consistent punctuation in comments
sloretz Mar 14, 2018
a98baf2
indentation and vertical whitespace
sloretz Mar 14, 2018
a78266c
Make name argument more specific
sloretz Mar 14, 2018
6ac891f
remap rules and arguments store allocator, and fini fixes
sloretz Mar 14, 2018
6dbab0f
Declaritive \brief
sloretz Mar 14, 2018
015bff1
Add method to get global CLI args
sloretz Mar 14, 2018
0ad0f63
Rename two functions to start with rcl_arguments_
sloretz Mar 14, 2018
129aeb7
-1 if args is NULL or zero initialized
sloretz Mar 14, 2018
d08034b
Sorted includes
sloretz Mar 14, 2018
b52bb8b
are -> as
sloretz Mar 14, 2018
0b465df
remap functions accept global args instead of bool
sloretz Mar 14, 2018
21b9806
use rcutils_reallocf
sloretz Mar 15, 2018
42ea8df
Print error message if fini fails in error handling
sloretz Mar 15, 2018
12e5f59
Improved error messages in _rcl_parse_remap_rule
sloretz Mar 15, 2018
21227ca
Remove out of date comment
sloretz Mar 15, 2018
a58b71f
const argv
sloretz Mar 15, 2018
c04c2eb
expand docs on remapping and argument parsing
sloretz Mar 15, 2018
1925221
Use rmw_validate_node_name_with_size
sloretz Mar 15, 2018
4f5180f
Better error messages for arg parsing
sloretz Mar 15, 2018
8cbe7f8
Flatten logic and better error handling while remapping
sloretz Mar 15, 2018
3aa044a
Merge branch 'master' into impl_static_remapping
sloretz Mar 15, 2018
6f39edf
use rcl_validate_topic_name_with_size
sloretz Mar 15, 2018
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
2 changes: 2 additions & 0 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

set(${PROJECT_NAME}_sources
src/rcl/arguments.c
src/rcl/client.c
src/rcl/common.c
src/rcl/expand_topic_name.c
Expand All @@ -35,6 +36,7 @@ set(${PROJECT_NAME}_sources
src/rcl/node.c
src/rcl/publisher.c
src/rcl/rcl.c
src/rcl/remap.c
src/rcl/rmw_implementation_identifier_check.c
src/rcl/service.c
src/rcl/subscription.c
Expand Down
187 changes: 187 additions & 0 deletions rcl/include/rcl/arguments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Copyright 2018 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 RCL__ARGUMENTS_H_
#define RCL__ARGUMENTS_H_

#include "rcl/allocator.h"
#include "rcl/macros.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"

#if __cplusplus
extern "C"
{
#endif

struct rcl_arguments_impl_t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general comment here, is that arguments might be a bit ambiguous, but the only alternative I can think of is pretty verbose in command line arguments, which is the terminology the spec uses (e.g. http://en.cppreference.com/w/cpp/language/main_function).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rcl_command_line_arguments_t is a pretty long name. How about rcl_cli_arguments_t?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rcl_cli_arguments_t sounds great to me, but after thinking about it, I'm not really concerned about the name. I think in context it will be relatively clear. So I'll leave it up to you to decide what to do about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this as is because I think the name is clear enough, but I'm open to changing it in another PR.


/// Hold output of parsing command line arguments.
typedef struct rcl_arguments_t
{
/// Private implementation pointer.
struct rcl_arguments_impl_t * impl;
} rcl_arguments_t;

/// Return a rcl_node_t struct with members initialized to `NULL`.
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_arguments_t
rcl_get_zero_initialized_arguments(void);

/// Parse command line arguments into a structure usable by code.
/**
* If an argument does not appear to be a valid ROS argument then it is skipped and parsing
* continues with the next argument in `argv`.
* \sa rcl_arguments_get_count_unparsed()
* \sa rcl_arguments_get_unparsed()
*
* Successfully parsed remap rules are stored in the order they were given in `argv`.
* If given arguments `{"__ns:=/foo", "__ns:=/bar"}` then the namespace used by nodes in this
* process will be `/foo` and not `/bar`.
* \sa rcl_remap_topic_name()
* \sa rcl_remap_service_name()
* \sa rcl_remap_node_name()
* \sa rcl_remap_node_namespace()
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] argc The number of arguments in argv.
* \param[in] argv Whe values of the arguments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling: Whe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 74b042b

* \param[in] allocator A valid allocator.
* \param[out] args_output A structure that will contain the result of parsing.
* \return `RCL_RET_OK` if the arguments were parsed successfully, or
* \return `RCL_RET_INVALID_ARGUMENT` if any function arguments are invalid, or
* \return `RCL_RET_BAD_ALLOC` if allocating memory failed, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_parse_arguments(
int argc,
const char * const argv[],
rcl_allocator_t allocator,
rcl_arguments_t * args_output);

/// Return the number of arguments that were not successfully parsed.
/**
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] args An arguments structure that has been parsed.
* \return number of unparsed arguments, or
* \return -1 if args is `NULL` or zero initialized.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
int
rcl_arguments_get_count_unparsed(
rcl_arguments_t * args);

/// Return a list of indexes that weren't successfully parsed.
/**
* Some arguments may not have been successfully parsed, or were not intended as ROS arguments.
* This function populates an array of indexes to these arguments in the original argv array.
* Since the first argument is always assumed to be a process name, the list will always contain
* the index 0.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] args An arguments structure that has been parsed.
* \param[in] allocator A valid allocator.
* \param[out] output_unparsed_indices An allocated array of indices into the original argv array.
* This array must be deallocated by the caller using the given allocator.
* If there are no unparsed args then the output will be set to NULL.
* \return `RCL_RET_OK` if everything goes correctly, or
* \return `RCL_RET_INVALID_ARGUMENT` if any function arguments are invalid, or
* \return `RCL_RET_BAD_ALLOC` if allocating memory failed, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_arguments_get_unparsed(
rcl_arguments_t * args,
rcl_allocator_t allocator,
int ** output_unparsed_indices);

/// Reclaim resources held inside rcl_arguments_t structure.
/**
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] args The structure to be deallocated.
* \param[in] allocator A valid allocator.
* \return `RCL_RET_OK` if the memory was successfully freed, or
* \return `RCL_RET_INVALID_ARGUMENT` if any function arguments are invalid, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_arguments_fini(
rcl_arguments_t * args);

/// Get a global instance of command line arguments.
/**
* \sa rcl_init(int, char **, rcl_allocator_t)
* \sa rcl_shutdown()
* This returns parsed command line arguments that were passed to `rcl_init()`.
* The value returned by this function is undefined before `rcl_init()` is called and after
* `rcl_shutdown()` is called.
* The return value must not be finalized.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \return a global instance of parsed command line arguments.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_arguments_t *
rcl_get_global_arguments();

#if __cplusplus
}
#endif

#endif // RCL__ARGUMENTS_H_
7 changes: 7 additions & 0 deletions rcl/include/rcl/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern "C"
#include <stdint.h>

#include "rcl/allocator.h"
#include "rcl/arguments.h"
#include "rcl/macros.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"
Expand Down Expand Up @@ -65,6 +66,12 @@ typedef struct rcl_node_options_t

/// Custom allocator used for internal allocations.
rcl_allocator_t allocator;

/// If false then only use arguments in this struct, otherwise use global arguments also.
bool use_global_arguments;

/// Command line arguments that apply only to this node.
rcl_arguments_t arguments;
} rcl_node_options_t;

/// Return a rcl_node_t struct with members initialized to `NULL`.
Expand Down
Loading