Skip to content

Commit

Permalink
refactors and renames
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodall <william@osrfoundation.org>
  • Loading branch information
wjwwood committed Nov 8, 2018
1 parent e8c9d01 commit 6c02319
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 42 deletions.
26 changes: 14 additions & 12 deletions rmw/include/rmw/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RMW__RMW_H_
#define RMW__RMW_H_
#ifndef RMW__INIT_H_
#define RMW__INIT_H_

#ifdef __cplusplus
extern "C"
Expand All @@ -23,7 +23,7 @@ extern "C"
#include <stdint.h>

#include "rmw/macros.h"
#include "rmw/types.h"
#include "rmw/ret_types.h"
#include "rmw/visibility_control.h"

/// Implementation defined options structure used during rmw_init().
Expand All @@ -44,6 +44,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_init_options_t {
/// Implementation identifier, used to ensure two different implementations are not being mixed.
const char * implementation_identifier;
/// Implementation defined init options.
/** May be NULL if there are no implementation defined options. */
rmw_init_options_impl_t * impl;
} rmw_init_options_t;

Expand All @@ -60,23 +61,24 @@ rmw_get_default_init_options(void);
/**
* This should be defined by the rmw implementation.
*/
typedef struct rmw_init_context_impl_t rmw_init_context_impl_t;
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_init_context_t {
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 init context information.
rmw_init_context_impl_t * impl;
} rmw_init_context_t;
/** May be NULL if there is no implementation defined context information. */
rmw_context_impl_t * impl;
} rmw_context_t;

/// Return a zero initialized init context structure.
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_init_context_t
rmw_get_zero_initialized_init_context(void);
rmw_context_t
rmw_get_zero_initialized_context(void);

/// Initialize the middleware with the given options, and yielding an init context.
/**
Expand Down Expand Up @@ -106,7 +108,7 @@ rmw_get_zero_initialized_init_context(void);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_init(const rmw_init_options_t * options, rmw_init_context_t * context);
rmw_init(const rmw_init_options_t * options, rmw_context_t * context);

/// Shutdown the middleware for a given init context.
/**
Expand All @@ -133,10 +135,10 @@ rmw_init(const rmw_init_options_t * options, rmw_init_context_t * context);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_shutdown(rmw_init_context_t * context);
rmw_shutdown(rmw_context_t * context);

#ifdef __cplusplus
}
#endif

#endif // RMW__RMW_H_
#endif // RMW__INIT_H_
41 changes: 41 additions & 0 deletions rmw/include/rmw/ret_types.h
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_
20 changes: 10 additions & 10 deletions rmw/include/rmw/rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ rmw_get_serialization_format(void);
/// Create a node and return a handle to that node.
/**
* This function can fail, and therefore return `NULL`, if:
* - init_context, name, namespace_, or security_options is `NULL`
* - init_context, security_options is invalid
* - context, name, namespace_, or security_options is `NULL`
* - context, security_options is invalid
* - memory allocation fails during node creation
* - an unspecified error occurs
*
* The init_context must be non-null and valid, i.e. it has been initialized
* The context must be non-null and valid, i.e. it has been initialized
* by `rmw_init()` and has not been finalized by `rmw_shutdown()`.
*
* The name and namespace_ should be valid node name and namespace,
Expand All @@ -153,7 +153,7 @@ rmw_get_serialization_format(void);
*
* This should be defined by the rmw implementation.
*
* \param[in] init_context init context that this node should be associated with
* \param[in] context init context that this node should be associated with
* \param[in] name the node name
* \param[in] namespace_ the node namespace
* \param[in] domain_id the id of the domain that the node should join
Expand All @@ -164,7 +164,7 @@ RMW_PUBLIC
RMW_WARN_UNUSED
rmw_node_t *
rmw_create_node(
rmw_init_context_t * init_context,
rmw_context_t * context,
const char * name,
const char * namespace_,
size_t domain_id,
Expand Down Expand Up @@ -438,12 +438,12 @@ rmw_send_response(
/// Create a guard condition and return a handle to that guard condition.
/**
* This function can fail, and therefore return `NULL`, if:
* - init_context is `NULL`
* - init_context is invalid
* - context is `NULL`
* - context is invalid
* - memory allocation fails during guard condition creation
* - an unspecified error occurs
*
* The init_context must be non-null and valid, i.e. it has been initialized
* The context must be non-null and valid, i.e. it has been initialized
* by `rmw_init()` and has not been finalized by `rmw_shutdown()`.
*
* <hr>
Expand All @@ -457,13 +457,13 @@ rmw_send_response(
*
* This should be defined by the rmw implementation.
*
* \param[in] init_context init context that this node should be associated with
* \param[in] context init context that this node should be associated with
* \return rmw guard condition handle or `NULL` if there was an error
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_guard_condition_t *
rmw_create_guard_condition(rmw_init_context_t * init_context);
rmw_create_guard_condition(rmw_context_t * context);


/// Finalize a given guard condition handle, reclaim the resources, and deallocate the handle.
Expand Down
21 changes: 4 additions & 17 deletions rmw/include/rmw/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,22 @@ extern "C"
// map rcutils specific log levels to rmw speicfic type
#include <rcutils/logging.h>

#include "rmw/init.h"
#include "rmw/ret_types.h"
#include "rmw/serialized_message.h"
#include "rmw/visibility_control.h"

typedef int 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

// 24 bytes is the most memory needed to represent the GID by any current
// implementation. It may need to be increased in the future.
#define RMW_GID_STORAGE_SIZE 24

// forward declaration to avoid circular dependency
typedef struct rmw_init_context_t rmw_init_context_t;

typedef struct RMW_PUBLIC_TYPE rmw_node_t
{
const char * implementation_identifier;
void * data;
const char * name;
const char * namespace_;
rmw_init_context_t * init_context;
rmw_context_t * context;
} rmw_node_t;

typedef struct RMW_PUBLIC_TYPE rmw_publisher_t
Expand Down Expand Up @@ -90,7 +77,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_guard_condition_t
{
const char * implementation_identifier;
void * data;
rmw_init_context_t * init_context;
rmw_context_t * context;
} rmw_guard_condition_t;

/// Array of subscriber handles.
Expand Down
8 changes: 5 additions & 3 deletions rmw/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <stddef.h>

#include "rmw/init.h"

#ifdef __cplusplus
extern "C"
{
#endif

rmw_init_context_t
rmw_get_zero_initialized_init_context(void)
rmw_context_t
rmw_get_zero_initialized_context(void)
{
return (const rmw_init_context_t) {
return (const rmw_context_t) {
.instance_id = 0,
.impl = NULL
};
Expand Down

0 comments on commit 6c02319

Please sign in to comment.