/// <summary> /// Initializes a new instance of the <see cref="rclcs.Publisher`1"/> class. /// with a custom qos profile. <see cref="rclcs.rmw_qos_profile_t"/> for possible preconfigured profiles. /// </summary> /// <param name="_Node">Node.</param> /// <param name="_TopicName">Topic name.</param> /// <param name="_QOS">Custom qos profile.</param> /// public Publisher(Node _Node, string _TopicName, rmw_qos_profile_t _QOS) { QOSProfile = _QOS; RosNode = _Node; TopicName = _TopicName; //This is some reflection magic that is used in order to obtain the correct C typesupport. //Every generated message contains a method with a name similiar to rosidl_typesupport_introspection_c_get_message. //This is a interop method declaration that does a call in the corresponding C library and that returns a pointer to a rosidl_message_type_support_t struct. //This pointer is marshalled to a managed struct of the type rosidl_message_type_support_t. //This is the type of the wrapper class around the message struct Type wrapperType = typeof(T); //This variable will store the type of the message struct Type messageType = typeof(T); //Go through all methods of the wrapper class foreach (var item in wrapperType.GetMethods()) { if (item.IsStatic) { //If its a method called GetMessageType if (item.Name.Contains("GetMessageType")) { //We call it and cast the returned object to a Type. messageType = (Type)item.Invoke(null, null); } } } //Now we do the same for the message struct foreach (var item in messageType.GetMethods()) { if (item.IsStatic) { //We search for the method that does the native call if (item.Name.Contains("rosidl_typesupport_introspection_c_get_message")) { //We call it and marshal the returned IntPtr (a managed wrapper around a pointer) to the managed typesupport struct TypeSupport = (rosidl_message_type_support_t)Marshal.PtrToStructure((IntPtr)item.Invoke(null, null), typeof(rosidl_message_type_support_t)); } } } //The case that the data pointer inside the type support struct is 0 is a strong indicator that the call failed somewhere //Or that we got a wrong typesupport object at least if (TypeSupport.data == IntPtr.Zero) { throw new Exception("Couldn't get typesupport"); } //Get the default options for the rcl publisher PublisherOptions = rcl_publisher.get_default_options(); //Set the custom qos profile PublisherOptions.qos = QOSProfile; //And create an new publisher InternalPublisher = new rcl_publisher(RosNode, TypeSupport, TopicName, PublisherOptions); }
/// <summary> /// Creates a publisher. /// With specific QOS Options /// </summary> /// <returns>The publisher.</returns> /// <param name="TopicName">Topic name.</param> /// <param name="QOSProfile">QOS profile.</param> /// <param name="AddToExecutables">If set to <c>true</c> add to executables.</param> /// <typeparam name="T">Message type</typeparam> public Publisher <T> CreatePublisher <T> (string TopicName, rmw_qos_profile_t QOSProfile, bool AddToExecutables = true) where T : MessageWrapper, new() { Publisher <T> NewPublisher = new Publisher <T> (this, TopicName, QOSProfile); if (AddToExecutables) { ManagedExecutables.Add(NewPublisher); } return(NewPublisher); }
/// <summary> /// Creates a subscription. /// with a specific QOSProfile /// </summary> /// <returns>The subscription.</returns> /// <param name="TopicName">Topic name.</param> /// <param name="QOSProfile">QOS profile.</param> /// <param name="AddToExecutables">If set to <c>true</c> add to executables.</param> /// <typeparam name="T">Message type</typeparam> public Subscription <T> CreateSubscription <T> (string TopicName, rmw_qos_profile_t QOSProfile, bool AddToExecutables = true) where T : MessageWrapper, new() { Subscription <T> NewSubscription = new Subscription <T> (this, TopicName, QOSProfile); if (AddToExecutables) { ManagedExecutables.Add(NewSubscription); } return(NewSubscription); }
/// <summary> /// Creates a client /// with a specific QOS Profile /// </summary> /// <returns>The client.</returns> /// <param name="ServiceName">Service name.</param> /// <param name="QOSProfile">QOS profile.</param> /// <param name="AddToExecutables">If set to <c>true</c> add to executables.</param> /// <typeparam name="T">Request message type</typeparam> /// <typeparam name="U">Response message type</typeparam> public Client <T, U> CreateClient <T, U> (string ServiceName, rmw_qos_profile_t QOSProfile, bool AddToExecutables = true) where T : MessageWrapper, new() where U : MessageWrapper, new() { Client <T, U> NewClient = new Client <T, U> (this, ServiceName, QOSProfile); if (AddToExecutables) { ManagedExecutables.Add(NewClient); } return(NewClient); }
/// <summary> /// Initializes a new instance of the <see cref="rclcs.Subscription`1"/> class. With a custom qos profile /// </summary> /// <param name="_node">Node.</param> /// <param name="_topicName">Topic name.</param> /// <param name="_QOS">QO.</param> public Subscription(Node _node, string _topicName, rmw_qos_profile_t _QOS) { QOSProfile = _QOS; RosNode = _node; TopicName = _topicName; Type wrapperType = typeof(T); Type messageType = typeof(T); foreach (var item in wrapperType.GetMethods()) { if (item.IsStatic) { if (item.Name.Contains("GetMessageType")) { messageType = (Type)item.Invoke(null, null); } } } bool foundMethod = false; foreach (var item in messageType.GetMethods()) { if (item.IsStatic) { if (item.Name.Contains("rosidl_typesupport_introspection_c__get_message_type_support_handle")) { foundMethod = true; TypeSupport = (rosidl_message_type_support_t)Marshal.PtrToStructure((IntPtr)item.Invoke(null, null), typeof(rosidl_message_type_support_t)); } } } if (!foundMethod) { throw new MissingMethodException("Could not find typesupport method"); } if (TypeSupport.data == IntPtr.Zero) { throw new Exception("Couldn't get typesupport"); } SubscriptionOptions = rcl_subscription.get_default_options(); SubscriptionOptions.qos = QOSProfile; InternalSubscription = new rcl_subscription(RosNode, TypeSupport, TopicName, SubscriptionOptions); }
public Client(Node _Node, string _ServiceName, rmw_qos_profile_t _QOS) { QOSProfile = _QOS; RosNode = _Node; ServiceName = _ServiceName; Type ServiceType = typeof(T); Type wrapperType = typeof(T); foreach (var item in wrapperType.GetMethods()) { if (item.IsStatic) { if (item.Name.Contains("GetMessageType")) { ServiceType = (Type)item.Invoke(null, null); } } } bool foundMethod = false; foreach (var item in ServiceType.GetMethods()) { if (item.IsStatic) { if (item.Name.Contains("rosidl_typesupport_introspection_c__get_service_type_support_handle__")) { foundMethod = true; TypeSupport = (rosidl_service_type_support_t)Marshal.PtrToStructure((IntPtr)item.Invoke(null, null), typeof(rosidl_service_type_support_t)); } } } if (!foundMethod) { throw new MissingMethodException("Could not find typesupprt method"); } if (TypeSupport.data == IntPtr.Zero) { throw new Exception("Couldn't get typesupport"); } ClientOptions = rcl_client.get_default_options(); ClientOptions.qos = QOSProfile; InternalClient = new rcl_client(RosNode.NativeNode, TypeSupport, ServiceName, ClientOptions); }
public Service(Node _Node, string _ServiceName, rmw_qos_profile_t _QOS) { QOSProfile = _QOS; RosNode = _Node; ServiceName = _ServiceName; Type ServiceType = typeof(T); Type wrapperType = typeof(T); foreach (var item in wrapperType.GetMethods()) { if (item.IsStatic) { if (item.Name.Contains("GetMessageType")) { ServiceType = (Type)item.Invoke(null, null); } } } foreach (var item in ServiceType.GetMethods()) { if (item.IsStatic) { if (item.Name.Contains("rosidl_typesupport_introspection_c_get_message")) { TypeSupport = (rosidl_service_type_support_t)Marshal.PtrToStructure((IntPtr)item.Invoke(null, null), typeof(rosidl_service_type_support_t)); } } } if (TypeSupport.data == IntPtr.Zero) { throw new Exception("Couldn't get typesupport"); } ServiceOptions = rcl_service.get_default_options(); ServiceOptions.qos = QOSProfile; InternalService = new rcl_service(RosNode.NativeNode, TypeSupport, ServiceName, ServiceOptions); }
public QualityOfServiceProfile(QosProfiles profile) { handle = new rmw_qos_profile_t(); SetProfile(profile); }