コード例 #1
0
        public AdvertiseOptions(
            string topic,
            int queueSize,
            string md5Sum,
            string dataType,
            string messageDefinition,
            SubscriberStatusCallback connectcallback    = null,
            SubscriberStatusCallback disconnectcallback = null,
            ICallbackQueue callbackQueue = null
            )
        {
            this.topic         = topic;
            this.md5Sum        = md5Sum;
            this.queueSize     = queueSize;
            this.callbackQueue = callbackQueue;

            T tt = new T();

            this.dataType          = dataType.Length > 0 ? dataType : tt.MessageType;
            this.messageDefinition = string.IsNullOrEmpty(messageDefinition) ? tt.MessageDefinition() : messageDefinition;
            this.hasHeader         = tt.HasHeader();

            this.connectCB    = connectcallback;
            this.disconnectCB = disconnectcallback;
        }
コード例 #2
0
ファイル: ChatRoom.cs プロジェクト: half-ogre/MvcAsyncChat
 public ChatRoom(
     ICallbackQueue callbackQueue,
     IDateTimeSvc dateTimeSvc,
     IMessageRepo messageRepo)
 {
     this.callbackQueue = callbackQueue;
     this.dateTimeSvc = dateTimeSvc;
     this.messageRepo = messageRepo;
 }
コード例 #3
0
        internal bool AddCallback(
            ISubscriptionCallbackHelper helper,
            string md5sum,
            ICallbackQueue queue,
            int queueSize,
            bool allowConcurrentCallbacks,
            string topic
            )
        {
            lock (gate)
            {
                if (this.Md5Sum == "*" && md5sum != "*")
                {
                    this.Md5Sum = md5sum;
                }

                if (md5sum != "*" && md5sum != this.Md5Sum)
                {
                    return(false);
                }

                var info = new CallbackInfo
                {
                    Helper            = helper,
                    CallbackQueue     = queue,
                    SubscriptionQueue = new Callback(helper.Callback.SendEvent, topic, queueSize, allowConcurrentCallbacks)
                };

                callbacks.Add(info);

                if (latchedMessages.Count > 0)
                {
                    string ti          = info.Helper.type;
                    var    receiptTime = ROS.GetTime().data;
                    foreach (PublisherLink link in publisherLinks)
                    {
                        if (link.Latched)
                        {
                            if (latchedMessages.ContainsKey(link))
                            {
                                LatchInfo latch_info         = latchedMessages[link];
                                bool      wasFull            = false;
                                bool      nonconst_need_copy = callbacks.Count > 1;
                                info.SubscriptionQueue.AddToCallbackQueue(info.Helper, latchedMessages[link].Message, nonconst_need_copy, ref wasFull, receiptTime);
                                if (!wasFull)
                                {
                                    info.CallbackQueue.AddCallback(info.SubscriptionQueue, helper);
                                }
                            }
                        }
                    }
                }

                return(true);
            }
        }
コード例 #4
0
ファイル: _Init.cs プロジェクト: YaseenAlk/ROS.NET
 private static void ResetStaticMembers()
 {
     globalCallbackQueue = null;
     initialized         = false;
     _ok          = false;
     timerManager = new TimerManager();
     started      = false;
     _ok          = false;
     shuttingDown = false;
 }
コード例 #5
0
 public SubscriberCallbacks(
     SubscriberStatusCallback connectCB,
     SubscriberStatusCallback disconnectCB,
     ICallbackQueue callbackQueue
     )
 {
     this.connect       = connectCB;
     this.disconnect    = disconnectCB;
     this.CallbackQueue = callbackQueue;
 }
コード例 #6
0
 public SubscriberCallbacks(
     SubscriberStatusCallback onConnect,
     SubscriberStatusCallback onDisconnect,
     ICallbackQueue callbackQueue
     )
 {
     this.OnConnect     = onConnect;
     this.OnDisconnect  = onDisconnect;
     this.CallbackQueue = callbackQueue;
 }
コード例 #7
0
 public static AdvertiseOptions <M> Create <M>(
     string topic,
     int queueSize,
     SubscriberStatusCallback connectcallback,
     SubscriberStatusCallback disconnectcallback,
     ICallbackQueue callbackQueue
     )
     where M : RosMessage, new()
 {
     return(new AdvertiseOptions <M>(topic, queueSize, connectcallback, disconnectcallback, callbackQueue));
 }
コード例 #8
0
 private void Destruct()
 {
     lock (gate)
     {
         --referenceCount;
     }
     callbackQueue = null;
     if (referenceCount == 0 && initializedRos)
     {
         ROS.Shutdown();
     }
 }
コード例 #9
0
ファイル: Global.asax.cs プロジェクト: half-ogre/MvcAsyncChat
        public static void StartTimers(ICallbackQueue callbackQueue, ITimerSvc timerSvc, IDateTimeSvc dateTimeSvc)
        {
            var period = Math.Floor(Const.IdleCallbackLimit / 2) * 1000;

            timerSvc.AddPeriodicTimer(Const.CallIdleCallbacksTimerId, period, () =>
            {
                var expiry = dateTimeSvc.GetCurrentDateTimeAsUtc().AddSeconds(Const.IdleCallbackLimit * -1);
                var newSince = dateTimeSvc.GetCurrentDateTimeAsUtc().AddSeconds(-1);

                foreach (var callback in callbackQueue.DequeueExpired(expiry))
                    callback(new string[] { }, newSince);
            });
        }
コード例 #10
0
        /// <summary>
        ///     Creates a subscriber
        /// </summary>
        /// <typeparam name="M">Topic type</typeparam>
        /// <param name="topic">Topic name</param>
        /// <param name="queueSize">How many messages to qeueue</param>
        /// <param name="cb">Function to fire when a message is recieved</param>
        /// <param name="allowConcurrentCallbacks">Probably breaks things when true</param>
        /// <returns>A subscriber</returns>
        public async Task <Subscriber> SubscribeAsync <M>(string topic, int queueSize, CallbackInterface cb, bool allowConcurrentCallbacks)
            where M : RosMessage, new()
        {
            if (callbackQueue == null)
            {
                callbackQueue = ROS.GlobalCallbackQueue;
            }

            var ops = new SubscribeOptions <M>(topic, queueSize, cb.SendEvent)
            {
                callback_queue             = callbackQueue,
                allow_concurrent_callbacks = allowConcurrentCallbacks
            };

            ops.callback_queue.AddCallback(cb);
            return(await SubscribeAsync(ops));
        }
コード例 #11
0
        public async Task <Subscriber> SubscribeAsync(string topic, string messageType, int queueSize, CallbackInterface cb, bool allowConcurrentCallbacks = false)
        {
            if (callbackQueue == null)
            {
                callbackQueue = ROS.GlobalCallbackQueue;
            }

            var message = RosMessage.Generate(messageType);
            var ops     = new SubscribeOptions(topic, message.MessageType, message.MD5Sum(), queueSize, new SubscriptionCallbackHelper <RosMessage>(message.MessageType, cb.SendEvent))
            {
                callback_queue             = callbackQueue,
                allow_concurrent_callbacks = allowConcurrentCallbacks
            };

            ops.callback_queue.AddCallback(cb);
            return(await SubscribeAsync(ops));
        }
コード例 #12
0
 public AdvertiseOptions(
     string topic,
     int queueSize,
     SubscriberStatusCallback connectCallback,
     SubscriberStatusCallback disconnectCallback,
     ICallbackQueue callbackQueue = null
     )
     : this(
         topic,
         queueSize,
         new T().MD5Sum(),
         new T().MessageType,
         new T().MessageDefinition(),
         connectCallback,
         disconnectCallback
         )
 {
 }
コード例 #13
0
ファイル: Spinner.cs プロジェクト: wiwing/ROS.NET
 /// <summary>
 /// Create a spinner for the given callback queue
 /// </summary>
 /// <param name="callbackQueue"></param>
 public AsyncSpinner(ICallbackQueue callbackQueue)
 {
     this.callbackQueue = callbackQueue;
 }
コード例 #14
0
ファイル: Spinner.cs プロジェクト: wiwing/ROS.NET
 /// <summary>
 /// Creates a spinner for the global ROS callback queue
 /// </summary>
 public AsyncSpinner()
 {
     this.callbackQueue = ROS.GlobalCallbackQueue;
 }
コード例 #15
0
ファイル: Spinner.cs プロジェクト: wiwing/ROS.NET
 /// <summary>
 /// Creates a spinner for the given callback queue
 /// </summary>
 /// <param name="callbackQueue"></param>
 public SingleThreadSpinner(ICallbackQueue callbackQueue)
 {
     this.callbackQueue = callbackQueue;
 }
コード例 #16
0
ファイル: Spinner.cs プロジェクト: wiwing/ROS.NET
 /// <summary>
 /// Creats a spinner for the global ROS callback queue
 /// </summary>
 public SingleThreadSpinner()
 {
     this.callbackQueue = ROS.GlobalCallbackQueue;
 }
コード例 #17
0
        public ServicePublication(string name, string md5Sum, string datatype, string reqDatatype, string resDatatype, ServiceCallbackHelper <MReq, MRes> helper, ICallbackQueue callback)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            this.name         = name;
            this.md5sum       = md5Sum;
            this.dataType     = datatype;
            this.req_datatype = reqDatatype;
            this.res_datatype = resDatatype;
            this.helper       = helper;
            this.callback     = callback;
        }
コード例 #18
0
        internal bool addCallback(
            ISubscriptionCallbackHelper helper,
            string md5sum,
            ICallbackQueue queue,
            int queue_size,
            bool allow_concurrent_callbacks,
            string topiclol
            )
        {
            lock ( md5sum_mutex )
            {
                if (this.md5sum == "*" && md5sum != "*")
                {
                    this.md5sum = md5sum;
                }
            }

            if (md5sum != "*" && md5sum != this.md5sum)
            {
                return(false);
            }

            lock ( callbacks_mutex )
            {
                ICallbackInfo info = new ICallbackInfo
                {
                    helper             = helper,
                    callback           = queue,
                    subscription_queue = new Callback(helper.Callback.SendEvent, topiclol, queue_size, allow_concurrent_callbacks)
                };

                //if (!helper.isConst())
                //{
                ++nonconst_callbacks;
                //}

                callbacks.Add(info);

                if (latched_messages.Count > 0)
                {
                    string ti = info.helper.type;
                    lock ( publisher_links_mutex )
                    {
                        foreach (PublisherLink link in publisher_links)
                        {
                            if (link.Latched)
                            {
                                if (latched_messages.ContainsKey(link))
                                {
                                    LatchInfo latch_info         = latched_messages[link];
                                    bool      was_full           = false;
                                    bool      nonconst_need_copy = callbacks.Count > 1;
                                    info.subscription_queue.AddToCallbackQueue(info.helper, latched_messages[link].message, nonconst_need_copy, ref was_full, ROS.GetTime().data);
                                    if (!was_full)
                                    {
                                        info.callback.AddCallback(info.subscription_queue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
コード例 #19
0
        public ServicePublication(string name, string md5Sum, string datatype, string reqDatatype, string resDatatype, ServiceCallbackHelper <MReq, MRes> helper, ICallbackQueue callback, object trackedObject)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            this.name           = name;
            this.md5sum         = md5Sum;
            this.datatype       = datatype;
            this.req_datatype   = reqDatatype;
            this.res_datatype   = resDatatype;
            this.helper         = helper;
            this.callback       = callback;
            this.tracked_object = trackedObject;

            if (trackedObject != null)
            {
                has_tracked_object = true;
            }
        }
コード例 #20
0
ファイル: _Init.cs プロジェクト: YaseenAlk/ROS.NET
        /// <summary>
        /// Initializes ROS
        /// </summary>
        /// <param name="remappingArgs"> dictionary of remapping args </param>
        /// <param name="name"> node name </param>
        /// <param name="options"> options </param>
        public static void Init(IDictionary <string, string> remappingArgs, string name, InitOptions options = 0)
        {
            lock (typeof(ROS))
            {
                // register process unload and cancel (CTRL+C) event handlers
                if (!atExitRegistered)
                {
                    atExitRegistered = true;
#if NETCORE
                    AssemblyLoadContext.Default.Unloading += (AssemblyLoadContext obj) =>
                    {
                        Shutdown();
                        WaitForShutdown();
                    };
#else
                    Process.GetCurrentProcess().EnableRaisingEvents = true;
                    Process.GetCurrentProcess().Exited += (o, args) =>
                    {
                        Shutdown();
                        WaitForShutdown();
                    };
#endif

                    Console.CancelKeyPress += (o, args) =>
                    {
                        Shutdown();
                        WaitForShutdown();
                        args.Cancel = true;
                    };
                }

                // crate global callback queue
                if (globalCallbackQueue == null)
                {
                    globalCallbackQueue = new CallbackQueue();
                }

                // run the actual ROS initialization
                if (!initialized)
                {
                    MessageTypeRegistry.Default.Reset();
                    ServiceTypeRegistry.Default.Reset();
                    var msgRegistry = MessageTypeRegistry.Default;
                    var srvRegistry = ServiceTypeRegistry.Default;

                    // Load RosMessages from MessageBase assembly
                    msgRegistry.ParseAssemblyAndRegisterRosMessages(typeof(RosMessage).GetTypeInfo().Assembly);

                    // Load RosMessages from all assemblies that reference Uml.Robotics.Ros.MessageBas
                    var candidates = MessageTypeRegistry.GetCandidateAssemblies("Uml.Robotics.Ros.MessageBase");
                    foreach (var assembly in candidates)
                    {
                        logger.LogDebug($"Parse assembly: {assembly.Location}");
                        msgRegistry.ParseAssemblyAndRegisterRosMessages(assembly);
                        srvRegistry.ParseAssemblyAndRegisterRosServices(assembly);
                    }

                    initOptions = options;
                    _ok         = true;

                    Param.Reset();
                    SimTime.Reset();
                    RosOutAppender.Reset();

                    Network.Init(remappingArgs);
                    Master.Init(remappingArgs);
                    ThisNode.Init(name, remappingArgs, options);
                    Param.Init(remappingArgs);
                    SimTime.Instance.SimTimeEvent += SimTimeCallback;

                    lock (shuttingDownMutex)
                    {
                        switch (shutdownTask?.Status)
                        {
                        case null:
                        case TaskStatus.RanToCompletion:
                            break;

                        default:
                            throw new InvalidOperationException("ROS was not shut down correctly");
                        }
                        shutdownTask = new Task(_shutdown);
                    }
                    initialized = true;

                    GlobalNodeHandle = new NodeHandle(ThisNode.Namespace, remappingArgs);
                    RosOutAppender.Instance.Start();
                }
            }
        }
コード例 #21
0
 /// <summary>
 ///     Creates a new nodehandle using the given callback queue
 /// </summary>
 public NodeHandle(ICallbackQueue callbackQueue)
     : this(ThisNode.Namespace, null)
 {
     Callback = callbackQueue;
 }