[style] clean up of recent changes to time.h/c

This commit is contained in:
William Woodall 2016-02-12 00:42:20 -08:00
parent 135836e1de
commit b2acdd126d
2 changed files with 298 additions and 255 deletions

View file

@ -24,15 +24,14 @@ extern "C"
#include "rcl/types.h" #include "rcl/types.h"
#include "rcl/visibility_control.h" #include "rcl/visibility_control.h"
#define RCL_S_TO_NS(seconds) (seconds * 1000 * 1000 * 1000) #define RCL_S_TO_NS(seconds) (seconds * (1000 * 1000 * 1000))
#define RCL_MS_TO_NS(milliseconds) (milliseconds * 1000 * 1000) #define RCL_MS_TO_NS(milliseconds) (milliseconds * (1000 * 1000))
#define RCL_US_TO_NS(microseconds) (microseconds * 1000) #define RCL_US_TO_NS(microseconds) (microseconds * 1000)
#define RCL_NS_TO_S(nanoseconds) (nanoseconds / (1000 * 1000 * 1000)) #define RCL_NS_TO_S(nanoseconds) (nanoseconds / (1000 * 1000 * 1000))
#define RCL_NS_TO_MS(nanoseconds) (nanoseconds / (1000 * 1000)) #define RCL_NS_TO_MS(nanoseconds) (nanoseconds / (1000 * 1000))
#define RCL_NS_TO_US(nanoseconds) (nanoseconds / 1000) #define RCL_NS_TO_US(nanoseconds) (nanoseconds / 1000)
enum rcl_time_source_type_t enum rcl_time_source_type_t
{ {
RCL_TIME_SOURCE_UNINITIALIZED = 0, RCL_TIME_SOURCE_UNINITIALIZED = 0,
@ -78,15 +77,16 @@ typedef struct rcl_duration_t
/// Check if the time_source has valid values. /// Check if the time_source has valid values.
/* This function returns true if the time source appears to be valid. /* This function returns true if the time source appears to be valid.
* It will check that the type is not uninitialized, and that pointers * It will check that the type is not uninitialized, and that pointers
* are not invalid. Note that if data is uninitialized it may give a * are not invalid.
* false positive. * Note that if data is uninitialized it may give a false positive.
* *
* \param[in] time_source the handle to the time_source which is being queried * \param[in] time_source the handle to the time_source which is being queried
* \return true if the source is believed to be valid, otherwise return false. * \return true if the source is believed to be valid, otherwise return false.
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
bool rcl_time_source_valid(rcl_time_source_t * time_source); bool
rcl_time_source_valid(rcl_time_source_t * time_source);
/// Initialize a timesource as a RCL_ROS_TIME time source. /// Initialize a timesource as a RCL_ROS_TIME time source.
/* This will allocate all necessary internal structures, and initialize variables. /* This will allocate all necessary internal structures, and initialize variables.
@ -99,7 +99,8 @@ bool rcl_time_source_valid(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_init_ros_time_source(rcl_time_source_t * time_source); rcl_ret_t
rcl_init_ros_time_source(rcl_time_source_t * time_source);
/// Finalize a timesource as a RCL_ROS_TIME time source. /// Finalize a timesource as a RCL_ROS_TIME time source.
/* This will deallocate all necessary internal structures, and clean up any variables. /* This will deallocate all necessary internal structures, and clean up any variables.
@ -113,7 +114,8 @@ rcl_ret_t rcl_init_ros_time_source(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_fini_ros_time_source(rcl_time_source_t * time_source); rcl_ret_t
rcl_fini_ros_time_source(rcl_time_source_t * time_source);
/// Initialize a timesource as a RCL_STEADY_TIME time source. /// Initialize a timesource as a RCL_STEADY_TIME time source.
/* This will allocate all necessary internal structures, and initialize variables. /* This will allocate all necessary internal structures, and initialize variables.
@ -126,7 +128,8 @@ rcl_ret_t rcl_fini_ros_time_source(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_init_steady_time_source(rcl_time_source_t * time_source); rcl_ret_t
rcl_init_steady_time_source(rcl_time_source_t * time_source);
/// Finalize a timesource as a RCL_STEADY_TIME time source. /// Finalize a timesource as a RCL_STEADY_TIME time source.
/* Finalize the timesource as a RCL_STEADY_TIME time source. /* Finalize the timesource as a RCL_STEADY_TIME time source.
@ -142,7 +145,8 @@ rcl_ret_t rcl_init_steady_time_source(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_fini_steady_time_source(rcl_time_source_t * time_source); rcl_ret_t
rcl_fini_steady_time_source(rcl_time_source_t * time_source);
/// Initialize a timesource as a RCL_SYSTEM_TIME time source. /// Initialize a timesource as a RCL_SYSTEM_TIME time source.
/* Initialize the timesource as a RCL_SYSTEM_TIME time source. /* Initialize the timesource as a RCL_SYSTEM_TIME time source.
@ -157,7 +161,8 @@ rcl_ret_t rcl_fini_steady_time_source(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_init_system_time_source(rcl_time_source_t * time_source); rcl_ret_t
rcl_init_system_time_source(rcl_time_source_t * time_source);
/// Finalize a timesource as a RCL_SYSTEM_TIME time source. /// Finalize a timesource as a RCL_SYSTEM_TIME time source.
/* Finalize the timesource as a RCL_SYSTEM_TIME time source. /* Finalize the timesource as a RCL_SYSTEM_TIME time source.
@ -173,7 +178,8 @@ rcl_ret_t rcl_init_system_time_source(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_fini_system_time_source(rcl_time_source_t * time_source); rcl_ret_t
rcl_fini_system_time_source(rcl_time_source_t * time_source);
/// Initialize a time point using the time_source. /// Initialize a time point using the time_source.
/* This function will initialize the time_point using the time_source /* This function will initialize the time_point using the time_source
@ -191,13 +197,14 @@ rcl_ret_t rcl_fini_system_time_source(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_init_time_point(rcl_time_point_t * time_point, rcl_time_source_t * time_source); rcl_ret_t
rcl_init_time_point(rcl_time_point_t * time_point, rcl_time_source_t * time_source);
/// Finalize a time_point /// Finalize a time_point
/* Finalize the time_point such that it is ready for deallocation. /* Finalize the time_point such that it is ready for deallocation.
* *
* This will deallocate all necessary internal structures, and clean up any variables. * This will deallocate all necessary internal structures, and clean up any variables.
* * *
* \param[in] time_point the handle to the time_source which is being finalized. * \param[in] time_point the handle to the time_source which is being finalized.
* \return RCL_RET_OK if the last call time was retrieved successfully, or * \return RCL_RET_OK if the last call time was retrieved successfully, or
* RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or * RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
@ -205,11 +212,11 @@ rcl_ret_t rcl_init_time_point(rcl_time_point_t * time_point, rcl_time_source_t *
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_fini_time_point(rcl_time_point_t * time_point); rcl_ret_t
rcl_fini_time_point(rcl_time_point_t * time_point);
/// Initialize a duration using the time_source. /// Initialize a duration using the time_source.
/* This function will initialize the duration using the time_source /* This function will initialize the duration using the time_source as a reference.
* as a reference.
* If the time_source is null it will use the system default time_source. * If the time_source is null it will use the system default time_source.
* *
* This will allocate all necessary internal structures, and initialize variables. * This will allocate all necessary internal structures, and initialize variables.
@ -223,13 +230,14 @@ rcl_ret_t rcl_fini_time_point(rcl_time_point_t * time_point);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_init_duration(rcl_duration_t * duration, rcl_time_source_t * time_source); rcl_ret_t
rcl_init_duration(rcl_duration_t * duration, rcl_time_source_t * time_source);
/// Finalize a duration /// Finalize a duration
/* Finalize the duration such that it is ready for deallocation. /* Finalize the duration such that it is ready for deallocation.
* *
* This will deallocate all necessary internal structures, and clean up any variables. * This will deallocate all necessary internal structures, and clean up any variables.
* * *
* \param[in] duration the handle to the duration which is being finalized. * \param[in] duration the handle to the duration which is being finalized.
* \return RCL_RET_OK if the last call time was retrieved successfully, or * \return RCL_RET_OK if the last call time was retrieved successfully, or
* RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or * RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
@ -237,7 +245,8 @@ rcl_ret_t rcl_init_duration(rcl_duration_t * duration, rcl_time_source_t * time_
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_fini_duration(rcl_duration_t * duration); rcl_ret_t
rcl_fini_duration(rcl_duration_t * duration);
/// Get the default RCL_ROS_TIME time source /// Get the default RCL_ROS_TIME time source
/* This function will get the process default time source. /* This function will get the process default time source.
@ -248,11 +257,12 @@ rcl_ret_t rcl_fini_duration(rcl_duration_t * duration);
* and initialize the time source. * and initialize the time source.
* *
* \return rcl_time_source_t if it successfully found or allocated a * \return rcl_time_source_t if it successfully found or allocated a
time source. If an error occurred it will return NULL. * time source. If an error occurred it will return NULL.
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_time_source_t * rcl_get_default_ros_time_source(void); rcl_time_source_t *
rcl_get_default_ros_time_source(void);
/// Get the default RCL_STEADY_TIME time source /// Get the default RCL_STEADY_TIME time source
/* This function will get the process default time source. /* This function will get the process default time source.
@ -263,11 +273,12 @@ rcl_time_source_t * rcl_get_default_ros_time_source(void);
* and initialize the time source. * and initialize the time source.
* *
* \return rcl_time_source_t if it successfully found or allocated a * \return rcl_time_source_t if it successfully found or allocated a
time source. If an error occurred it will return NULL. * time source. If an error occurred it will return NULL.
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_time_source_t * rcl_get_default_steady_time_source(void); rcl_time_source_t *
rcl_get_default_steady_time_source(void);
/// Get the default RCL_SYSTEM_TIME time source /// Get the default RCL_SYSTEM_TIME time source
/* This function will get the process default time source. /* This function will get the process default time source.
@ -278,11 +289,12 @@ rcl_time_source_t * rcl_get_default_steady_time_source(void);
* and initialize the time source. * and initialize the time source.
* *
* \return rcl_time_source_t if it successfully found or allocated a * \return rcl_time_source_t if it successfully found or allocated a
time source. If an error occurred it will return NULL. * time source. If an error occurred it will return NULL.
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_time_source_t * rcl_get_default_system_time_source(void); rcl_time_source_t *
rcl_get_default_system_time_source(void);
/// Set the current time on the RCL_ROS_TIME time source /// Set the current time on the RCL_ROS_TIME time source
/* This function is used to set the time on a ros time source. /* This function is used to set the time on a ros time source.
@ -300,12 +312,13 @@ rcl_time_source_t * rcl_get_default_system_time_source(void);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_set_default_ros_time_source(rcl_time_source_t * process_time_source); rcl_ret_t
rcl_set_default_ros_time_source(rcl_time_source_t * process_time_source);
/// Compute the difference between two time points /// Compute the difference between two time points
/* This function takes two time points and computes the duration between them. /* This function takes two time points and computes the duration between them.
* The two time points must be using the same time abstraction.. * The two time points must be using the same time abstraction, and the
* And the resultant duration will also be of the same abstraction. * resultant duration will also be of the same abstraction.
* *
* The value will be computed as duration = finish - start. If start is after * The value will be computed as duration = finish - start. If start is after
* finish the duration will be negative. * finish the duration will be negative.
@ -319,7 +332,8 @@ rcl_ret_t rcl_set_default_ros_time_source(rcl_time_source_t * process_time_sourc
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_difference_times(rcl_time_point_t * start, rcl_time_point_t * finish, rcl_ret_t
rcl_difference_times(rcl_time_point_t * start, rcl_time_point_t * finish,
rcl_duration_t * delta); rcl_duration_t * delta);
/// Fill the time point with the current value of the associated clock. /// Fill the time point with the current value of the associated clock.
@ -333,7 +347,8 @@ rcl_ret_t rcl_difference_times(rcl_time_point_t * start, rcl_time_point_t * fini
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_get_time_point_now(rcl_time_point_t * time_point); rcl_ret_t
rcl_get_time_point_now(rcl_time_point_t * time_point);
/// Enable the ros time abstraction override. /// Enable the ros time abstraction override.
@ -348,7 +363,8 @@ rcl_ret_t rcl_get_time_point_now(rcl_time_point_t * time_point);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_enable_ros_time_override(rcl_time_source_t * time_source); rcl_ret_t
rcl_enable_ros_time_override(rcl_time_source_t * time_source);
/// Disable the ros time abstraction override. /// Disable the ros time abstraction override.
/* This method will disable the RCL_ROS_TIME time abstraction override values, /* This method will disable the RCL_ROS_TIME time abstraction override values,
@ -362,7 +378,8 @@ rcl_ret_t rcl_enable_ros_time_override(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_disable_ros_time_override(rcl_time_source_t * time_source); rcl_ret_t
rcl_disable_ros_time_override(rcl_time_source_t * time_source);
/// Check if the RCL_ROS_TIME time source has the override enabled. /// Check if the RCL_ROS_TIME time source has the override enabled.
@ -378,7 +395,8 @@ rcl_ret_t rcl_disable_ros_time_override(rcl_time_source_t * time_source);
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_is_enabled_ros_time_override(rcl_time_source_t * time_source, rcl_ret_t
rcl_is_enabled_ros_time_override(rcl_time_source_t * time_source,
bool * is_enabled); bool * is_enabled);
/// Set the current time for this RCL_ROS_TIME time source. /// Set the current time for this RCL_ROS_TIME time source.
@ -394,7 +412,8 @@ rcl_ret_t rcl_is_enabled_ros_time_override(rcl_time_source_t * time_source,
*/ */
RCL_PUBLIC RCL_PUBLIC
RCL_WARN_UNUSED RCL_WARN_UNUSED
rcl_ret_t rcl_set_ros_time_override(rcl_time_source_t * time_source, rcl_ret_t
rcl_set_ros_time_override(rcl_time_source_t * time_source,
rcl_time_point_value_t time_value); rcl_time_point_value_t time_value);
/// Retrieve the current time as a rcl_time_point_value_t (an alias for unint64_t). /// Retrieve the current time as a rcl_time_point_value_t (an alias for unint64_t).
@ -412,7 +431,7 @@ rcl_ret_t rcl_set_ros_time_override(rcl_time_source_t * time_source,
* On Windows this is lock-free if the C11's stdatomic.h function * On Windows this is lock-free if the C11's stdatomic.h function
* atomic_is_lock_free() returns true for atomic_int_least64_t. * atomic_is_lock_free() returns true for atomic_int_least64_t.
* *
* TODO(tfoote) I talked with @wjwwood about possibly promoting this * TODO(tfoote): I talked with @wjwwood about possibly promoting this
* method into rmw for more reuse. * method into rmw for more reuse.
* *
* \param[out] now a datafield in which the current time is stored * \param[out] now a datafield in which the current time is stored

View file

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#if defined(WIN32) #if defined(WIN32)
@ -27,9 +28,8 @@ static rcl_time_source_t * rcl_default_ros_time_source;
static rcl_time_source_t * rcl_default_steady_time_source; static rcl_time_source_t * rcl_default_steady_time_source;
static rcl_time_source_t * rcl_default_system_time_source; static rcl_time_source_t * rcl_default_system_time_source;
// Internal storage for RCL_ROS_TIME implementation // Internal storage for RCL_ROS_TIME implementation
typedef struct typedef struct rcl_ros_time_source_storage_t
{ {
atomic_uint_least64_t current_time; atomic_uint_least64_t current_time;
bool active; bool active;
@ -37,21 +37,24 @@ typedef struct
} rcl_ros_time_source_storage_t; } rcl_ros_time_source_storage_t;
// Implementation only // Implementation only
rcl_ret_t rcl_get_steady_time(void * data, rcl_time_point_value_t * current_time) rcl_ret_t
rcl_get_steady_time(void * data, rcl_time_point_value_t * current_time)
{ {
(void)data; // unused (void)data; // unused
return rcl_steady_time_now(current_time); return rcl_steady_time_now(current_time);
} }
// Implementation only // Implementation only
rcl_ret_t rcl_get_system_time(void * data, rcl_time_point_value_t * current_time) rcl_ret_t
rcl_get_system_time(void * data, rcl_time_point_value_t * current_time)
{ {
(void)data; // unused (void)data; // unused
return rcl_system_time_now(current_time); return rcl_system_time_now(current_time);
} }
// Internal method for zeroing values on init, assumes time_source is valid // Internal method for zeroing values on init, assumes time_source is valid
void rcl_init_generic_time_source(rcl_time_source_t * time_source) void
rcl_init_generic_time_source(rcl_time_source_t * time_source)
{ {
time_source->type = RCL_TIME_SOURCE_UNINITIALIZED; time_source->type = RCL_TIME_SOURCE_UNINITIALIZED;
time_source->pre_update = NULL; time_source->pre_update = NULL;
@ -62,7 +65,8 @@ void rcl_init_generic_time_source(rcl_time_source_t * time_source)
// The function used to get the current ros time. // The function used to get the current ros time.
// This is in the implementation only // This is in the implementation only
rcl_ret_t rcl_get_ros_time(void * data, rcl_time_point_value_t * current_time) rcl_ret_t
rcl_get_ros_time(void * data, rcl_time_point_value_t * current_time)
{ {
rcl_ros_time_source_storage_t * t = (rcl_ros_time_source_storage_t *)data; rcl_ros_time_source_storage_t * t = (rcl_ros_time_source_storage_t *)data;
if (!t->active) { if (!t->active) {
@ -72,7 +76,8 @@ rcl_ret_t rcl_get_ros_time(void * data, rcl_time_point_value_t * current_time)
return RCL_RET_OK; return RCL_RET_OK;
} }
bool rcl_time_source_valid(rcl_time_source_t * time_source) bool
rcl_time_source_valid(rcl_time_source_t * time_source)
{ {
if (time_source == NULL || if (time_source == NULL ||
time_source->type == RCL_TIME_SOURCE_UNINITIALIZED || time_source->type == RCL_TIME_SOURCE_UNINITIALIZED ||
@ -83,7 +88,8 @@ bool rcl_time_source_valid(rcl_time_source_t * time_source)
return true; return true;
} }
rcl_ret_t rcl_init_ros_time_source(rcl_time_source_t * time_source) rcl_ret_t
rcl_init_ros_time_source(rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
rcl_init_generic_time_source(time_source); rcl_init_generic_time_source(time_source);
@ -93,7 +99,8 @@ rcl_ret_t rcl_init_ros_time_source(rcl_time_source_t * time_source)
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_fini_ros_time_source(rcl_time_source_t * time_source) rcl_ret_t
rcl_fini_ros_time_source(rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
if (time_source->type != RCL_ROS_TIME) { if (time_source->type != RCL_ROS_TIME) {
@ -104,7 +111,8 @@ rcl_ret_t rcl_fini_ros_time_source(rcl_time_source_t * time_source)
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_init_steady_time_source(rcl_time_source_t * time_source) rcl_ret_t
rcl_init_steady_time_source(rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
rcl_init_generic_time_source(time_source); rcl_init_generic_time_source(time_source);
@ -113,7 +121,8 @@ rcl_ret_t rcl_init_steady_time_source(rcl_time_source_t * time_source)
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_fini_steady_time_source(rcl_time_source_t * time_source) rcl_ret_t
rcl_fini_steady_time_source(rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
if (time_source->type != RCL_STEADY_TIME) { if (time_source->type != RCL_STEADY_TIME) {
@ -123,19 +132,18 @@ rcl_ret_t rcl_fini_steady_time_source(rcl_time_source_t * time_source)
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_init_system_time_source(rcl_time_source_t * time_source) rcl_ret_t
rcl_init_system_time_source(rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
rcl_init_generic_time_source(time_source); rcl_init_generic_time_source(time_source);
time_source->get_now = rcl_get_system_time; time_source->get_now = rcl_get_system_time;
time_source->type = RCL_SYSTEM_TIME; time_source->type = RCL_SYSTEM_TIME;
if (!time_source) {
return RCL_RET_ERROR;
}
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_fini_system_time_source(rcl_time_source_t * time_source) rcl_ret_t
rcl_fini_system_time_source(rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
if (time_source->type != RCL_SYSTEM_TIME) { if (time_source->type != RCL_SYSTEM_TIME) {
@ -145,7 +153,8 @@ rcl_ret_t rcl_fini_system_time_source(rcl_time_source_t * time_source)
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_init_time_point(rcl_time_point_t * time_point, rcl_time_source_t * time_source) rcl_ret_t
rcl_init_time_point(rcl_time_point_t * time_point, rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_point, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_point, RCL_RET_INVALID_ARGUMENT);
if (!time_source) { if (!time_source) {
@ -157,14 +166,16 @@ rcl_ret_t rcl_init_time_point(rcl_time_point_t * time_point, rcl_time_source_t *
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_fini_time_point(rcl_time_point_t * time_point) rcl_ret_t
rcl_fini_time_point(rcl_time_point_t * time_point)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_point, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_point, RCL_RET_INVALID_ARGUMENT);
(void)time_point; (void)time_point;
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_init_duration(rcl_duration_t * duration, rcl_time_source_t * time_source) rcl_ret_t
rcl_init_duration(rcl_duration_t * duration, rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(duration, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(duration, RCL_RET_INVALID_ARGUMENT);
if (!time_source) { if (!time_source) {
@ -176,17 +187,19 @@ rcl_ret_t rcl_init_duration(rcl_duration_t * duration, rcl_time_source_t * time_
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_fini_duration(rcl_duration_t * duration) rcl_ret_t
rcl_fini_duration(rcl_duration_t * duration)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(duration, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(duration, RCL_RET_INVALID_ARGUMENT);
(void)duration; (void)duration;
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_time_source_t * rcl_get_default_ros_time_source(void) rcl_time_source_t *
rcl_get_default_ros_time_source(void)
{ {
if (!rcl_default_ros_time_source) { if (!rcl_default_ros_time_source) {
rcl_default_ros_time_source = calloc(1, sizeof(rcl_time_source_t)); rcl_default_ros_time_source = (rcl_time_source_t *)calloc(1, sizeof(rcl_time_source_t));
rcl_ret_t retval = rcl_init_ros_time_source(rcl_default_ros_time_source); rcl_ret_t retval = rcl_init_ros_time_source(rcl_default_ros_time_source);
if (retval != RCL_RET_OK) { if (retval != RCL_RET_OK) {
return NULL; return NULL;
@ -195,10 +208,11 @@ rcl_time_source_t * rcl_get_default_ros_time_source(void)
return rcl_default_ros_time_source; return rcl_default_ros_time_source;
} }
rcl_time_source_t * rcl_get_default_steady_time_source(void) rcl_time_source_t *
rcl_get_default_steady_time_source(void)
{ {
if (!rcl_default_steady_time_source) { if (!rcl_default_steady_time_source) {
rcl_default_steady_time_source = calloc(1, sizeof(rcl_time_source_t)); rcl_default_steady_time_source = (rcl_time_source_t *)calloc(1, sizeof(rcl_time_source_t));
rcl_ret_t retval = rcl_init_steady_time_source(rcl_default_steady_time_source); rcl_ret_t retval = rcl_init_steady_time_source(rcl_default_steady_time_source);
if (retval != RCL_RET_OK) { if (retval != RCL_RET_OK) {
return NULL; return NULL;
@ -207,10 +221,11 @@ rcl_time_source_t * rcl_get_default_steady_time_source(void)
return rcl_default_steady_time_source; return rcl_default_steady_time_source;
} }
rcl_time_source_t * rcl_get_default_system_time_source(void) rcl_time_source_t *
rcl_get_default_system_time_source(void)
{ {
if (!rcl_default_system_time_source) { if (!rcl_default_system_time_source) {
rcl_default_system_time_source = calloc(1, sizeof(rcl_time_source_t)); rcl_default_system_time_source = (rcl_time_source_t *)calloc(1, sizeof(rcl_time_source_t));
rcl_ret_t retval = rcl_init_system_time_source(rcl_default_system_time_source); rcl_ret_t retval = rcl_init_system_time_source(rcl_default_system_time_source);
if (retval != RCL_RET_OK) { if (retval != RCL_RET_OK) {
return NULL; return NULL;
@ -219,7 +234,8 @@ rcl_time_source_t * rcl_get_default_system_time_source(void)
return rcl_default_system_time_source; return rcl_default_system_time_source;
} }
rcl_ret_t rcl_set_default_ros_time_source(rcl_time_source_t * process_time_source) rcl_ret_t
rcl_set_default_ros_time_source(rcl_time_source_t * process_time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(process_time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(process_time_source, RCL_RET_INVALID_ARGUMENT);
if (rcl_default_ros_time_source) { if (rcl_default_ros_time_source) {
@ -229,7 +245,8 @@ rcl_ret_t rcl_set_default_ros_time_source(rcl_time_source_t * process_time_sourc
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_difference_times(rcl_time_point_t * start, rcl_time_point_t * finish, rcl_ret_t
rcl_difference_times(rcl_time_point_t * start, rcl_time_point_t * finish,
rcl_duration_t * delta) rcl_duration_t * delta)
{ {
if (start->time_source->type != finish->time_source->type) { if (start->time_source->type != finish->time_source->type) {
@ -244,7 +261,8 @@ rcl_ret_t rcl_difference_times(rcl_time_point_t * start, rcl_time_point_t * fini
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_get_time_point_now(rcl_time_point_t * time_point) rcl_ret_t
rcl_get_time_point_now(rcl_time_point_t * time_point)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_point, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_point, RCL_RET_INVALID_ARGUMENT);
if (time_point->time_source && time_point->time_source->get_now) { if (time_point->time_source && time_point->time_source->get_now) {
@ -255,7 +273,8 @@ rcl_ret_t rcl_get_time_point_now(rcl_time_point_t * time_point)
return RCL_RET_ERROR; return RCL_RET_ERROR;
} }
rcl_ret_t rcl_enable_ros_time_override(rcl_time_source_t * time_source) rcl_ret_t
rcl_enable_ros_time_override(rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
if (time_source->type != RCL_ROS_TIME) { if (time_source->type != RCL_ROS_TIME) {
@ -272,7 +291,8 @@ rcl_ret_t rcl_enable_ros_time_override(rcl_time_source_t * time_source)
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_disable_ros_time_override(rcl_time_source_t * time_source) rcl_ret_t
rcl_disable_ros_time_override(rcl_time_source_t * time_source)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
if (time_source->type != RCL_ROS_TIME) { if (time_source->type != RCL_ROS_TIME) {
@ -288,7 +308,9 @@ rcl_ret_t rcl_disable_ros_time_override(rcl_time_source_t * time_source)
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_is_enabled_ros_time_override(rcl_time_source_t * time_source, rcl_ret_t
rcl_is_enabled_ros_time_override(
rcl_time_source_t * time_source,
bool * is_enabled) bool * is_enabled)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);
@ -306,7 +328,9 @@ rcl_ret_t rcl_is_enabled_ros_time_override(rcl_time_source_t * time_source,
return RCL_RET_OK; return RCL_RET_OK;
} }
rcl_ret_t rcl_set_ros_time_override(rcl_time_source_t * time_source, rcl_ret_t
rcl_set_ros_time_override(
rcl_time_source_t * time_source,
rcl_time_point_value_t time_value) rcl_time_point_value_t time_value)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(time_source, RCL_RET_INVALID_ARGUMENT);