Skip to content

Commit

Permalink
Merge pull request #49 from ros2/waitset_handle
Browse files Browse the repository at this point in the history
Add rmw_waitset_t and create/destroy functions
  • Loading branch information
jacquelinekay committed Jan 13, 2016
2 parents 97008fd + 9afe2a5 commit c0b1048
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rmw/include/rmw/allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ RMW_PUBLIC
void
rmw_service_free(rmw_service_t * service);

RMW_PUBLIC
rmw_waitset_t *
rmw_waitset_allocate();

RMW_PUBLIC
void
rmw_waitset_free(rmw_waitset_t * waitset);

#if __cplusplus
}
#endif
Expand Down
24 changes: 24 additions & 0 deletions rmw/include/rmw/rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ RMW_WARN_UNUSED
rmw_ret_t
rmw_trigger_guard_condition(const rmw_guard_condition_t * guard_condition);

/// Create a waitset to store conditions that the middleware will block on.
/**
* If max_conditions is 0, the waitset can store an unbounded number of conditions to wait on.
* If max_conditions is greater than 0, the number of conditions that can be attached to the
* waitset is bounded at max_conditions.
* \param[in] fixed_guard_conditions Guard conditions that are attached to the waitset immediately
* after initialization and are not removed from the waitset until rmw_destroy_waitset is called.
* For example, the guard condition for the CTRL-C signal handler is a "fixed condition".
* Must stay valid until rmw_destroy_waitset is called. The caller must keep ownership of the
* allocated guard conditions and deallocate them after rmw_destroy_waitset is called.
* \param[in] max_conditions The maximum number of conditions that can be attached to the waitset.
* \return A pointer to the created waitset, nullptr if an error occurred.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_waitset_t *
rmw_create_waitset(rmw_guard_conditions_t * fixed_guard_conditions, size_t max_conditions);

RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_destroy_waitset(rmw_waitset_t * waitset);

RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
Expand All @@ -190,6 +213,7 @@ rmw_wait(
rmw_guard_conditions_t * guard_conditions,
rmw_services_t * services,
rmw_clients_t * clients,
rmw_waitset_t * waitset,
const rmw_time_t * wait_timeout);

RMW_PUBLIC
Expand Down
7 changes: 7 additions & 0 deletions rmw/include/rmw/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ typedef struct RMW_PUBLIC_TYPE rmw_guard_conditions_t
void ** guard_conditions;
} rmw_guard_conditions_t;

typedef struct RMW_PUBLIC_TYPE rmw_waitset_t
{
const char * implementation_identifier;
rmw_guard_conditions_t * fixed_guard_conditions;
void * data;
} rmw_waitset_t;

typedef struct RMW_PUBLIC_TYPE rmw_request_id_t
{
int8_t writer_guid[16];
Expand Down
14 changes: 14 additions & 0 deletions rmw/src/allocators.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,17 @@ rmw_service_free(rmw_service_t * service)
// Should have matching overide with rmw_service_allocate
rmw_free(service);
}

rmw_waitset_t *
rmw_waitset_allocate()
{
// Could be overridden with custom (maybe static) client struct allocator
return (rmw_waitset_t *)rmw_allocate(sizeof(rmw_waitset_t));
}

void
rmw_waitset_free(rmw_waitset_t * waitset)
{
// Should have matching overide with rmw_waitset_allocate
rmw_free(waitset);
}

0 comments on commit c0b1048

Please sign in to comment.