Program Listing for File types.h

Return to documentation for file (include/rcl_action/types.h)

// 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_ACTION__TYPES_H_
#define RCL_ACTION__TYPES_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "rcl_action/visibility_control.h"

#include "action_msgs/msg/goal_info.h"
#include "action_msgs/msg/goal_status.h"
#include "action_msgs/msg/goal_status_array.h"
#include "action_msgs/srv/cancel_goal.h"

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

#include "rosidl_runtime_c/action_type_support_struct.h"

// rcl action specific ret codes in 2XXX
#define RCL_RET_ACTION_NAME_INVALID 2000
#define RCL_RET_ACTION_GOAL_ACCEPTED 2100
#define RCL_RET_ACTION_GOAL_REJECTED 2101
#define RCL_RET_ACTION_CLIENT_INVALID 2102
#define RCL_RET_ACTION_CLIENT_TAKE_FAILED 2103
#define RCL_RET_ACTION_SERVER_INVALID 2200
#define RCL_RET_ACTION_SERVER_TAKE_FAILED 2201
#define RCL_RET_ACTION_GOAL_HANDLE_INVALID 2300
#define RCL_RET_ACTION_GOAL_EVENT_INVALID 2301

// TODO(jacobperron): Move these to a common place for UUIDs
#define UUID_SIZE 16
#define uuidcmp(uuid0, uuid1) (0 == memcmp(uuid0, uuid1, UUID_SIZE))
#define zerouuid (uint8_t[UUID_SIZE]) {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define uuidcmpzero(uuid) uuidcmp(uuid, (zerouuid))

// Typedef generated messages for convenience
typedef action_msgs__msg__GoalInfo rcl_action_goal_info_t;
typedef action_msgs__msg__GoalStatus rcl_action_goal_status_t;
typedef struct rcl_action_goal_status_array_s
{
  action_msgs__msg__GoalStatusArray msg;
  rcl_allocator_t allocator;
} rcl_action_goal_status_array_t;
typedef action_msgs__srv__CancelGoal_Request rcl_action_cancel_request_t;
typedef struct rcl_action_cancel_response_s
{
  action_msgs__srv__CancelGoal_Response msg;
  rcl_allocator_t allocator;
} rcl_action_cancel_response_t;

// TODO(jacobperron): Let states be defined by action_msgs/msg/goal_status.h
// Ideally, we could use an enum type directly from the message when the feature
// is available. Issue: https://github.com/ros2/rosidl/issues/260
typedef int8_t rcl_action_goal_state_t;
#define GOAL_STATE_UNKNOWN action_msgs__msg__GoalStatus__STATUS_UNKNOWN
#define GOAL_STATE_ACCEPTED action_msgs__msg__GoalStatus__STATUS_ACCEPTED
#define GOAL_STATE_EXECUTING action_msgs__msg__GoalStatus__STATUS_EXECUTING
#define GOAL_STATE_CANCELING action_msgs__msg__GoalStatus__STATUS_CANCELING
#define GOAL_STATE_SUCCEEDED action_msgs__msg__GoalStatus__STATUS_SUCCEEDED
#define GOAL_STATE_CANCELED action_msgs__msg__GoalStatus__STATUS_CANCELED
#define GOAL_STATE_ABORTED action_msgs__msg__GoalStatus__STATUS_ABORTED
#define GOAL_STATE_NUM_STATES 7

// Description variables in types.c should be changed if enum values change
extern const char * goal_state_descriptions[];
extern const char * goal_event_descriptions[];

typedef enum rcl_action_goal_event_e
{
  GOAL_EVENT_EXECUTE = 0,
  GOAL_EVENT_CANCEL_GOAL,
  GOAL_EVENT_SUCCEED,
  GOAL_EVENT_ABORT,
  GOAL_EVENT_CANCELED,
  GOAL_EVENT_NUM_EVENTS
} rcl_action_goal_event_t;

RCL_ACTION_PUBLIC
RCL_WARN_UNUSED
rcl_action_goal_info_t
rcl_action_get_zero_initialized_goal_info(void);


RCL_ACTION_PUBLIC
RCL_WARN_UNUSED
rcl_action_goal_status_array_t
rcl_action_get_zero_initialized_goal_status_array(void);


RCL_ACTION_PUBLIC
RCL_WARN_UNUSED
rcl_action_cancel_request_t
rcl_action_get_zero_initialized_cancel_request(void);


RCL_ACTION_PUBLIC
RCL_WARN_UNUSED
rcl_action_cancel_response_t
rcl_action_get_zero_initialized_cancel_response(void);


RCL_ACTION_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_action_goal_status_array_init(
  rcl_action_goal_status_array_t * status_array,
  const size_t num_status,
  const rcl_allocator_t allocator);


RCL_ACTION_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_action_goal_status_array_fini(rcl_action_goal_status_array_t * status_array);


RCL_ACTION_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_action_cancel_response_init(
  rcl_action_cancel_response_t * cancel_response,
  const size_t num_goals_canceling,
  const rcl_allocator_t allocator);


RCL_ACTION_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_action_cancel_response_fini(rcl_action_cancel_response_t * cancel_response);

#ifdef __cplusplus
}
#endif

#endif  // RCL_ACTION__TYPES_H_