Module: Rclrb::CApi

Extended by:
FFI::Library
Defined in:
lib/rclrb/capi.rb

Overview

This module contains the function and data structures used to interface with the RCL C library The content of CApi is internal API to rclrb and should not be directly called and is subject to change.

Defined Under Namespace

Classes: BoolPtr, Int64Ptr, RclAllocatorT, RclArgumentsT, RclClientOptionsT, RclClientT, RclClockT, RclContextT, RclGuardConditionOptionsT, RclGuardConditionT, RclInitOptionsT, RclNodeOptionsT, RclNodeT, RclPublisherOptionsT, RclPublisherT, RclServiceOptionsT, RclServiceT, RclSubscriptionOptionsT, RclSubscriptionT, RclTimerT, RclWaitSetT, RcutilsErrorStringT, RmwGidT, RmwMessageInfoT, RmwPublisherAllocationT, RmwPublisherOptionsT, RmwQoSProfileT, RmwRequestIdT, RmwServiceInfoT, RmwSubscriptionAllocationT, RmwSubscriptionOptionsT, RmwTimeS, RosidlMessageTypeSupportT, RosidlServiceTypeSupportT, SizeTPtr

Constant Summary collapse

RCL_RET_OK =
0
RCL_RET_TIMEOUT =
2
RCL_RET_SUBSCRIPTION_TAKE_FAILED =
401
RCL_RET_CLIENT_TAKE_FAILED =
501
RCL_RET_SERVICE_TAKE_FAILED =
601
RCUTILS_ERROR_MESSAGE_MAX_LENGTH =
1024
RMW_GID_STORAGE_SIZE =
24
POINTER_SIZE =
FFI::Pointer::SIZE
SIZE_T_SIZE =
FFI::type_size(:size_t)
INT32_SIZE =
FFI::type_size(:int32)
UINT32_SIZE =
FFI::type_size(:uint32)
RmwTimePointValueT =
:int64
RclRetT =

Misc

:int

Class Method Summary collapse

Class Method Details

.create_nodeObject



354
355
356
# File 'lib/rclrb/capi.rb', line 354

def CApi.create_node()
  return CApi::RclNodeT.new()
end

.create_type_support_library(module_name, package_name, longtype, shorttype, idltype, messages) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/rclrb/capi.rb', line 338

def CApi.create_type_support_library(module_name, package_name, longtype, shorttype, idltype, messages)
  template = ERB.new <<-EOF
module <%= module_name %>
  module TypeSupportCApi
extend FFI::Library
ffi_lib '<%= package_name %>__rosidl_typesupport_c'
<% messages.each() do | m | %>
attach_function :rosidl_typesupport_c__get_#{longtype}_type_support_handle__<%= package_name %>__#{shorttype}__<%= m %>, [], CApi::#{idltype}.by_ref
TypeSupport_#{shorttype}_<%= m %> = rosidl_typesupport_c__get_#{longtype}_type_support_handle__<%= package_name %>__#{shorttype}__<%= m %>
<% end %>
  end
end
EOF
  Object.class_eval template.result(binding)
end

.get_error_stringObject



357
358
359
360
361
# File 'lib/rclrb/capi.rb', line 357

def CApi.get_error_string()
  msg = CApi.rcutils_get_error_string()[:str]
  CApi.rcutils_reset_error();
  return msg
end

.handle_result(ret, always_call = nil) ⇒ Object



362
363
364
365
366
367
# File 'lib/rclrb/capi.rb', line 362

def CApi.handle_result(ret, always_call = nil)
  always_call.call if always_call
  if ret != RCL_RET_OK
    raise RclError.new "Error #{ret.to_i}: #{CApi.get_error_string()}"
  end
end