public static bool Take(ISubscriptionBase subscription, Message message) { rcl_subscription_t subscription_handle = subscription.Handle; IntPtr message_handle = message.Handle; RCLReturnEnum ret = (RCLReturnEnum)NativeMethods.rcl_take(ref subscription_handle, message_handle, IntPtr.Zero); return(ret == RCLReturnEnum.RCL_RET_OK); }
public WaitSet(Context ctx, IList <ISubscriptionBase> subscriptions = null) { ulong numberOfSubscriptions; if (subscriptions == null) { numberOfSubscriptions = 0; subscriptions = new List <ISubscriptionBase>(); } else { numberOfSubscriptions = (ulong)subscriptions.Count; } ulong numberOfGuardConditions = 0; ulong numberOfTimers = 0; ulong numberOfClients = 0; ulong numberOfServices = 0; ulong numberOfEvents = 0; allocator = NativeMethods.rcutils_get_default_allocator(); handle = NativeMethods.rcl_get_zero_initialized_wait_set(); Utils.CheckReturnEnum(NativeMethods.rcl_wait_set_init( ref handle, numberOfSubscriptions, numberOfGuardConditions, numberOfTimers, numberOfClients, numberOfServices, numberOfEvents, ref ctx.handle, allocator)); Clear(); foreach (ISubscriptionBase subscription in subscriptions) { rcl_subscription_t subscription_handle = subscription.Handle; Utils.CheckReturnEnum(NativeMethods.rcl_wait_set_add_subscription(ref handle, ref subscription_handle, UIntPtr.Zero)); } }
public Subscription(string topic, Node node, Action <T> callback, QualityOfServiceProfile qualityOfServiceProfile = null) { this.callback = callback; nodeHandle = node.handle; handle = NativeMethods.rcl_get_zero_initialized_subscription(); subscriptionOptions = NativeMethods.rclcs_subscription_create_default_options(); if (qualityOfServiceProfile == null) { this.qualityOfServiceProfile = new QualityOfServiceProfile(QosProfiles.DEFAULT); } else { this.qualityOfServiceProfile = qualityOfServiceProfile; } //FIXME(sam): was not able to use a c# struct as qos profile, figure out why and replace the following hack... NativeMethods.rclcs_subscription_set_qos_profile(subscriptionOptions, (int)qualityOfServiceProfile.Profile); //TODO(sam): Figure out why System.Reflection is not available //when building with colcon/xtool on ubuntu 18.04 and mono 4.5 //MethodInfo m = typeof(T).GetTypeInfo().GetDeclaredMethod("_GET_TYPE_SUPPORT"); //IntPtr typeSupportHandle = (IntPtr)m.Invoke(null, new object[] { }); IMessageInternals msg = new T(); IntPtr typeSupportHandle = msg.TypeSupportHandle; msg.Dispose(); Utils.CheckReturnEnum(NativeMethods.rcl_subscription_init( ref handle, ref nodeHandle, typeSupportHandle, topic, subscriptionOptions)); }
extern static IntPtr rcl_subscription_get_options(ref rcl_subscription_t subscription);
extern static string rcl_subscription_get_topic_name(ref rcl_subscription_t subscription);
extern static int rcl_take(ref rcl_subscription_t subscription, [Out] ValueType ros_message, [In, Out] rmw_message_info_t message_info);
extern static int rcl_subscription_fini(ref rcl_subscription_t subscription, ref rcl_node_t node);
extern static int rcl_subscription_init(ref rcl_subscription_t subscription, ref rcl_node_t node, ref rosidl_message_type_support_t typesupport, string topic_name, ref rcl_subscription_options_t options);
public rcl_subscription(Node _node, rosidl_message_type_support_t _type_support, string _topic_name, rcl_subscription_options_t _options) { subscription = rcl_get_zero_initialized_subscription(); native_node = _node.NativeNode; rcl_subscription_init(ref subscription, ref native_node, ref _type_support, _topic_name, ref _options); }