Example #1
0
        public void SendRequest <T>(T request)
            where T : MessageWrapper, new()
        {
            ValueType msg;

            request.GetData(out msg);
            int             ret    = rcl_send_request(ref native_handle, msg, ref last_sequence_number);
            RCLReturnValues retVal = (RCLReturnValues)ret;

            switch (retVal)
            {
            case RCLReturnValues.RCL_RET_OK:
                break;

            case RCLReturnValues.RCL_RET_INVALID_ARGUMENT:
                throw new RCLInvalidArgumentException();
                break;

            case RCLReturnValues.RCL_RET_CLIENT_INVALID:
                throw new RCLClientInvalidException();
                break;

            case RCLReturnValues.RCL_RET_ERROR:
                throw new RCLErrorException();
                break;

            default:
                break;
            }
        }
Example #2
0
        public override T TakeResponse <T>(ref bool success)
        {
            success = false;
            rmw_request_id_t request_header = new rmw_request_id_t();
            T         response = new T();
            ValueType msg;

            response.GetData(out msg);
            int             ret    = rcl_take_response(ref native_handle, ref request_header, msg);
            RCLReturnValues retVal = (RCLReturnValues)ret;

            switch (retVal)
            {
            case RCLReturnValues.RCL_RET_OK:
                success = true;
                response.SetData(ref msg);
                break;

            case RCLReturnValues.RCL_RET_INVALID_ARGUMENT:
                throw new RCLInvalidArgumentException();

            case RCLReturnValues.RCL_RET_CLIENT_INVALID:
                throw new RCLClientInvalidException();

            case RCLReturnValues.RCL_RET_ERROR:
                success = false;
                break;

            default:
                break;
            }
            return(response);
        }
Example #3
0
        /// <summary>
        /// This method gets called from the Publisher<T> class in order to publish a message. Have in mind this method does not perform any type checks
        /// </summary>
        /// <returns><c>true</c>, if message was published, <c>false</c> otherwise.</returns>
        /// <param name="msg">Message.</param>
        public override bool PublishMessage(ValueType msg)
        {
            int ret = rcl_publish(ref native_handle, msg);
            //Handle the return types
            RCLReturnValues ret_val = (RCLReturnValues)ret;

            bool publish_message_success = false;

            switch (ret_val)
            {
            case RCLReturnValues.RCL_RET_OK:
                publish_message_success = true;
                break;

            case RCLReturnValues.RCL_RET_INVALID_ARGUMENT:
                throw new RCLInvalidArgumentException();

            case RCLReturnValues.RCL_RET_PUBLISHER_INVALID:
                throw new RCLPublisherInvalidException();

            case RCLReturnValues.RCL_RET_ERROR:
                throw new RCLInvalidArgumentException();

            default:
                break;
            }
            return(publish_message_success);
        }
Example #4
0
        /// <summary>
        /// This method does the initilisation of the ros client lib
        /// <remarks>Call this method before you do any other calls to ros
        /// You can specify a custom memory allocator for ros but I wouldn't recommend doing this at the moment. </remarks>
        /// </summary>
        /// <param name="args">Arguments.</param>
        /// <param name="custom_allocator">Custom allocator.</param>
        public override void Init(String[] args, rcl_allocator_t custom_allocator)
        {
            if (args == null)
            {
                throw new ArgumentNullException();
            }
            RCLReturnValues retVal = (RCLReturnValues)rcl_init(args.Length, args, custom_allocator);

            switch (retVal)
            {
            case RCLReturnValues.RCL_RET_OK:

                break;

            case RCLReturnValues.RCL_RET_ALREADY_INIT:
                throw new RCLAlreadyInitExcption();

            case RCLReturnValues.RCL_RET_BAD_ALLOC:
                throw new RCLBadAllocException();

            case RCLReturnValues.RCL_RET_ERROR:
                throw new RCLErrorException(RCLErrorHandling.Instance.GetRMWErrorState());

            default:
                break;
            }
        }
Example #5
0
        /// <summary>
        /// Implementation of IDisposable
        /// </summary>
        /// <param name="disposing">If set to <c>true</c> disposing.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }
            if (disposing)
            {
                // Free any other managed objects here.
            }
            // Free any unmanaged objects here.
            RCLReturnValues retVal = (RCLReturnValues)rcl_shutdown();

            switch (retVal)
            {
            case RCLReturnValues.RCL_RET_OK:
                break;

            case RCLReturnValues.RCL_RET_NOT_INIT:
                //throw new RCLNotInitException ();
                break;

            case RCLReturnValues.RCL_RET_ERROR:
                //throw new RCLErrorException (RCLErrorHandling.GetRMWErrorState());
                break;

            default:
                break;
            }
            disposed = true;
        }
Example #6
0
        public void SendResponse <T>(T response)
            where T : MessageWrapper, new()
        {
            ValueType msg;

            response.GetData(out msg);
            int             ret    = rcl_send_response(ref native_handle, ref last_request_header, msg);
            RCLReturnValues retVal = (RCLReturnValues)ret;

            switch (retVal)
            {
            case RCLReturnValues.RCL_RET_OK:
                return;

                break;

            case RCLReturnValues.RCL_RET_INVALID_ARGUMENT:
                throw new RCLInvalidArgumentException();
                break;

            case RCLReturnValues.RCL_RET_SERVICE_INVALID:
                throw new RCLServiceInvalidException();
                break;

            case RCLReturnValues.RCL_RET_ERROR:
                throw new RCLErrorException();
                break;

            default:
                break;
            }
        }
Example #7
0
        public rcl_service_linux(rcl_node_t _node, rosidl_service_type_support_t typesupport, string service_name, rcl_service_options_t options) : base(_node, typesupport, service_name, options)
        {
            native_handle = rcl_get_zero_initialized_service();
            int             ret    = rcl_service_init(ref native_handle, ref native_node, ref typesupport, service_name, ref options);
            RCLReturnValues retVal = (RCLReturnValues)ret;

            switch (retVal)
            {
            case RCLReturnValues.RCL_RET_OK:

                break;

            case RCLReturnValues.RCL_RET_NODE_INVALID:
                throw new RCLNodeInvalidException();

            case RCLReturnValues.RCL_RET_INVALID_ARGUMENT:
                throw new RCLInvalidArgumentException();

            case RCLReturnValues.RCL_RET_SERVICE_INVALID:
                throw new RCLServiceInvalidException();

            case RCLReturnValues.RCL_RET_BAD_ALLOC:
                throw new RCLBadAllocException();

            case RCLReturnValues.RCL_RET_ERROR:

                break;

            default:
                break;
            }
        }
Example #8
0
        public T TakeRequest <T> (ref bool success)
            where T : MessageWrapper, new()
        {
            success             = false;
            last_request_header = new rmw_request_id_t();
            T         request = new T();
            ValueType msg;

            request.GetData(out msg);
            int             ret    = rcl_take_request(ref native_handle, ref last_request_header, msg);
            RCLReturnValues retVal = (RCLReturnValues)ret;

            switch (retVal)
            {
            case RCLReturnValues.RCL_RET_OK:
                success = true;
                request.SetData(ref msg);
                break;

            case RCLReturnValues.RCL_RET_INVALID_ARGUMENT:
                //throw new RCLInvalidArgumentException();
                break;

            case RCLReturnValues.RCL_RET_SERVICE_INVALID:
                throw new RCLServiceInvalidException();
                break;

            case RCLReturnValues.RCL_RET_BAD_ALLOC:
                throw new RCLBadAllocException();
                break;

            case RCLReturnValues.RCL_RET_ERROR:
                success = false;
                break;

            default:
                break;
            }
            return(request);
        }
Example #9
0
 public RCLSubscriptonTakeFailedException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_SUBSCRIPTION_TAKE_FAILED;
 }
Example #10
0
 public RCLInvalidArgumentException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_INVALID_ARGUMENT;
 }
Example #11
0
 public RCLSubscriptonTakeFailedException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_SUBSCRIPTION_TAKE_FAILED;
 }
Example #12
0
 public RCLBadAllocException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_BAD_ALLOC;
 }
Example #13
0
 public RCLBadAllocException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_BAD_ALLOC;
 }
Example #14
0
 public RCLPublisherInvalidException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_PUBLISHER_INVALID;
 }
Example #15
0
 public RCLClientInvalidException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_CLIENT_INVALID;
 }
Example #16
0
 public RCLPublisherInvalidException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_PUBLISHER_INVALID;
 }
Example #17
0
 public RCLTimeoutException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_TIMEOUT;
 }
Example #18
0
 public RCLAlreadyInitExcption()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_ALREADY_INIT;
 }
Example #19
0
 public RCLServiceInvalidException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_SERVICE_INVALID;
 }
Example #20
0
 public RCLNodeInvalidException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_NODE_INVALID;
 }
Example #21
0
 public RCLNodeInvalidException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_NODE_INVALID;
 }
Example #22
0
 public RCLClientInvalidException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_CLIENT_INVALID;
 }
Example #23
0
 public RCLSubscriptionInvalidException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_SUBSCRIPTION_INVALID;
 }
Example #24
0
 public RCLNotInitException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_NOT_INIT;
 }
Example #25
0
 public RCLSubscriptionInvalidException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_SUBSCRIPTION_INVALID;
 }
Example #26
0
 public RCLNotInitException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_NOT_INIT;
 }
Example #27
0
 public RCLAlreadyInitExcption(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_ALREADY_INIT;
 }
Example #28
0
 public RCLServiceInvalidException(string message, Exception inner) : base(message, inner)
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_SERVICE_INVALID;
 }
Example #29
0
        public override T TakeMessage <T>(ref bool success, ref rmw_message_info_t _message_info)

        {
            MessageWrapper ret_msg = new T();
            ValueType      msg;

            ret_msg.GetData(out msg);
            rmw_message_info_t message_info = _message_info;

            int ret = rcl_take(ref subscription, msg, message_info);

            RCLReturnValues ret_val = (RCLReturnValues)ret;
            //Console.WriteLine (ret_val);

            /*return RCL_RET_OK if the message was published, or
             *         RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
             *         RCL_RET_SUBSCRIPTION_INVALID if the subscription is invalid, or
             *         RCL_RET_BAD_ALLOC if allocating memory failed, or
             *         RCL_RET_SUBSCRIPTION_TAKE_FAILED if take failed but no error
             *         occurred in the middleware, or
             *         RCL_RET_ERROR if an unspecified error occurs.*/
            bool take_message_success = false;

            switch (ret_val)
            {
            case RCLReturnValues.RCL_RET_INVALID_ARGUMENT:
                throw new RCLInvalidArgumentException();

            case RCLReturnValues.RCL_RET_SUBSCRIPTION_INVALID:
                throw new RCLSubscriptionInvalidException();

            case RCLReturnValues.RCL_RET_BAD_ALLOC:
                throw new RCLBadAllocException();

            case RCLReturnValues.RCL_RET_SUBSCRIPTION_TAKE_FAILED:
                //throw new RCLSubscriptonTakeFailedException ();
                take_message_success = false;
                //Marshal.FreeHGlobal (msg_ptr);
                break;

            case RCLReturnValues.RCL_RET_ERROR:
                throw new RCLErrorException();

            case RCLReturnValues.RCL_RET_OK:
            {
                take_message_success = true;
                //Bring the data back into the message wrapper
                ret_msg.SetData(ref msg);
                //And do a sync for nested types. This is in my opinion a hack because I can't store references on value types in C#
                ret_msg.SyncDataIn();
            }
            break;

            default:
                break;
            }
            success = take_message_success;
            //Marshal.FreeHGlobal (message_info_ptr);

            return((T)ret_msg);
        }
Example #30
0
 public RCLTimeoutException()
 {
     RCLReturnValue = RCLReturnValues.RCL_RET_TIMEOUT;
 }