-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor init to allow options to be passed and to not be global #154
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d66880d
refactor init to allow options to be passed and to not be global
wjwwood 098a6d1
use implementation identifier in init and shutdown functions
wjwwood 3159283
refactors and renames
wjwwood ff6c946
refactor init_options into its own files
wjwwood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,115 @@ | ||
// Copyright 2014-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 RMW__INIT_H_ | ||
#define RMW__INIT_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
#include "rmw/init_options.h" | ||
#include "rmw/macros.h" | ||
#include "rmw/ret_types.h" | ||
#include "rmw/visibility_control.h" | ||
|
||
/// Implementation defined context structure returned by rmw_init(). | ||
/** | ||
* This should be defined by the rmw implementation. | ||
*/ | ||
typedef struct rmw_context_impl_t rmw_context_impl_t; | ||
|
||
/// Initialization context structure which is used to store init specific information. | ||
typedef struct RMW_PUBLIC_TYPE rmw_context_t | ||
{ | ||
/// Locally (process local) unique ID that represents this init/shutdown cycle. | ||
uint64_t instance_id; | ||
/// Implementation identifier, used to ensure two different implementations are not being mixed. | ||
const char * implementation_identifier; | ||
/// Implementation defined context information. | ||
/** May be NULL if there is no implementation defined context information. */ | ||
rmw_context_impl_t * impl; | ||
} rmw_context_t; | ||
|
||
/// Return a zero initialized context structure. | ||
RMW_PUBLIC | ||
RMW_WARN_UNUSED | ||
rmw_context_t | ||
rmw_get_zero_initialized_context(void); | ||
|
||
/// Initialize the middleware with the given options, and yielding an context. | ||
/** | ||
* The given context must be zero initialized, and is filled with | ||
* middleware specific data upon success of this function. | ||
* The context is used when initializing some entities like nodes and | ||
* guard conditions, and is also required to properly call rmw_shutdown(). | ||
* | ||
* <hr> | ||
* Attribute | Adherence | ||
* ------------------ | ------------- | ||
* Allocates Memory | Yes | ||
* Thread-Safe | No | ||
* Uses Atomics | No | ||
* Lock-Free | Yes | ||
* | ||
* This should be defined by the rmw implementation. | ||
* | ||
* \param[in] options initialization options to be used during initialization | ||
* \param[out] context resulting context struct | ||
* \return `RMW_RET_OK` if successful, or | ||
* \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the implementation | ||
* identifier does not match, or | ||
* \return `RMW_RET_INVALID_ARGUMENT` if any arguments are null or invalid, or | ||
* \return `RMW_RET_ERROR` if an unexpected error occurs. | ||
*/ | ||
RMW_PUBLIC | ||
RMW_WARN_UNUSED | ||
rmw_ret_t | ||
rmw_init(const rmw_init_options_t * options, rmw_context_t * context); | ||
|
||
/// Shutdown the middleware for a given context. | ||
/** | ||
* The given context must be a valid context which has been initialized | ||
* with rmw_init(). | ||
* | ||
* <hr> | ||
* Attribute | Adherence | ||
* ------------------ | ------------- | ||
* Allocates Memory | Yes | ||
* Thread-Safe | No | ||
* Uses Atomics | No | ||
* Lock-Free | Yes | ||
* | ||
* This should be defined by the rmw implementation. | ||
* | ||
* \param[in] context resulting context struct | ||
* \return `RMW_RET_OK` if successful, or | ||
* \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the implementation | ||
* identifier does not match, or | ||
* \return `RMW_RET_INVALID_ARGUMENT` if the argument is null or invalid, or | ||
* \return `RMW_RET_ERROR` if an unexpected error occurs. | ||
*/ | ||
RMW_PUBLIC | ||
RMW_WARN_UNUSED | ||
rmw_ret_t | ||
rmw_shutdown(rmw_context_t * context); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RMW__INIT_H_ |
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,159 @@ | ||
// Copyright 2014-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 RMW__INIT_OPTIONS_H_ | ||
#define RMW__INIT_OPTIONS_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
#include "rcutils/allocator.h" | ||
#include "rmw/macros.h" | ||
#include "rmw/ret_types.h" | ||
#include "rmw/visibility_control.h" | ||
|
||
/// Implementation defined options structure used during rmw_init(). | ||
/** | ||
* This should be defined by the rmw implementation. | ||
*/ | ||
typedef struct rmw_init_options_impl_t rmw_init_options_impl_t; | ||
|
||
/// Options structure used during rmw_init(). | ||
typedef struct RMW_PUBLIC_TYPE rmw_init_options_t | ||
{ | ||
/// Locally (process local) unique ID that represents this init/shutdown cycle. | ||
/** | ||
* This should be set by the caller of `rmw_init()` to a number that is | ||
* unique within this process. | ||
* It is designed to be used with `rcl_init()` and `rcl_get_instance_id()`. | ||
*/ | ||
uint64_t instance_id; | ||
/// Implementation identifier, used to ensure two different implementations are not being mixed. | ||
const char * implementation_identifier; | ||
// TODO(wjwwood): replace with rmw_allocator_t when that refactor happens | ||
/// Allocator used during internal allocation of init options, if needed. | ||
rcutils_allocator_t allocator; | ||
/// Implementation defined init options. | ||
/** May be NULL if there are no implementation defined options. */ | ||
rmw_init_options_impl_t * impl; | ||
} rmw_init_options_t; | ||
|
||
/// Return a zero initialized init options structure. | ||
RMW_PUBLIC | ||
RMW_WARN_UNUSED | ||
rmw_init_options_t | ||
rmw_get_zero_initialized_init_options(void); | ||
|
||
/// Initialize given init_options with the default values and implementation specific values. | ||
/** | ||
* The given allocator is used, if required, during setup of the init options, | ||
* but is also used during initialization. | ||
* | ||
* In either case the given allocator is stored in the returned init options. | ||
* | ||
* The `impl` pointer should not be changed manually. | ||
* | ||
* <hr> | ||
* Attribute | Adherence | ||
* ------------------ | ------------- | ||
* Allocates Memory | Yes | ||
* Thread-Safe | No | ||
* Uses Atomics | Yes | ||
* Lock-Free | Yes | ||
* | ||
* This should be defined by the rmw implementation. | ||
* | ||
* \param[inout] init_options object to be setup | ||
* \param[in] allocator to be used during setup and during initialization | ||
* \return `RMW_RET_OK` if setup is successful, or | ||
* \return `RMW_RET_INVALID_ARGUMENT` if init_options has already be initialized, or | ||
* \return `RMW_RET_INVALID_ARGUMENT` if any arguments are invalid, or | ||
* \return `RMW_RET_BAD_ALLOC` if allocating memory failed, or | ||
* \return `RMW_RET_ERROR` if an unspecified error occurs. | ||
*/ | ||
RMW_PUBLIC | ||
RMW_WARN_UNUSED | ||
rmw_ret_t | ||
rmw_init_options_init(rmw_init_options_t * init_options, rcutils_allocator_t allocator); | ||
|
||
/// Copy the given source init options to the destination init options. | ||
/** | ||
* The allocator from the source is used for any allocations and stored in the | ||
* destination. | ||
* | ||
* The destination should either be zero initialized with | ||
* `rmw_get_zero_initialized_init_options()` or should have had | ||
* `rmw_init_options_fini()` called on it. | ||
* Giving an already initialized init options for the destination will result | ||
* in a failure with return code `RMW_RET_INVALID_ARGUMENT`. | ||
* | ||
* <hr> | ||
* Attribute | Adherence | ||
* ------------------ | ------------- | ||
* Allocates Memory | Yes | ||
* Thread-Safe | No | ||
* Uses Atomics | Yes | ||
* Lock-Free | Yes | ||
* | ||
* This should be defined by the rmw implementation. | ||
* | ||
* \param[in] src rcl_init_options_t object to be copied from | ||
* \param[out] dst rcl_init_options_t object to be copied into | ||
* \return `RMW_RET_OK` if the copy is successful, or | ||
* \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the implementation | ||
* identifier for src does not match the implementation of this function, or | ||
* \return `RMW_RET_INVALID_ARGUMENT` if the dst has already be initialized, or | ||
* \return `RMW_RET_INVALID_ARGUMENT` if any arguments are invalid, or | ||
* \return `RMW_RET_BAD_ALLOC` if allocating memory failed, or | ||
* \return `RMW_RET_ERROR` if an unspecified error occurs. | ||
*/ | ||
RMW_PUBLIC | ||
RMW_WARN_UNUSED | ||
rmw_ret_t | ||
rmw_init_options_copy(const rmw_init_options_t * src, rmw_init_options_t * dst); | ||
|
||
/// Finalize the given init_options. | ||
/** | ||
* The given init_options must be non-`NULL` and valid, i.e. had | ||
* `rmw_init_options_init()` called on it but not this function yet. | ||
* | ||
* <hr> | ||
* Attribute | Adherence | ||
* ------------------ | ------------- | ||
* Allocates Memory | Yes | ||
* Thread-Safe | No | ||
* Uses Atomics | Yes | ||
* Lock-Free | Yes | ||
* | ||
* This should be defined by the rmw implementation. | ||
* | ||
* \param[inout] init_options object to be setup | ||
* \return `RMW_RET_OK` if setup is successful, or | ||
* \return `RMW_RET_INVALID_ARGUMENT` if any arguments are invalid, or | ||
* \return `RMW_RET_ERROR` if an unspecified error occurs. | ||
*/ | ||
RMW_PUBLIC | ||
RMW_WARN_UNUSED | ||
rmw_ret_t | ||
rmw_init_options_fini(rmw_init_options_t * init_options); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RMW__INIT_OPTIONS_H_ |
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,41 @@ | ||
// Copyright 2014-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 RMW__RET_TYPES_H_ | ||
#define RMW__RET_TYPES_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
typedef int32_t rmw_ret_t; | ||
#define RMW_RET_OK 0 | ||
#define RMW_RET_ERROR 1 | ||
#define RMW_RET_TIMEOUT 2 | ||
|
||
/// Failed to allocate memory return code. | ||
#define RMW_RET_BAD_ALLOC 10 | ||
/// Invalid argument return code. | ||
#define RMW_RET_INVALID_ARGUMENT 11 | ||
/// Incorrect rmw implementation. | ||
#define RMW_RET_INCORRECT_RMW_IMPLEMENTATION 12 | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RMW__RET_TYPES_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding another type:
RMW_RET_OPTIONS_ALREADY_INIT