Exemplo n.º 1
0
        internal bool addCallback <M>(SubscriptionCallbackHelper <M> helper, string md5sum, CallbackQueueInterface queue,
                                      uint queue_size, bool allow_concurrent_callbacks, string topiclol) where M : IRosMessage, new()
        {
            lock (md5sum_mutex)
            {
                if (this.md5sum == "*" && md5sum != "*")
                {
                    this.md5sum = md5sum;
                }
            }

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

            lock (callbacks_mutex)
            {
                CallbackInfo <M> info = new CallbackInfo <M> {
                    helper = helper, callback = queue, subscription_queue = new Callback <M>(helper.callback().func, topiclol, queue_size, allow_concurrent_callbacks)
                };
                //if (!helper.isConst())
                //{
                ++nonconst_callbacks;
                //}

                callbacks.Add(info);

                if (latched_messages.Count > 0)
                {
                    lock (publisher_links_mutex)
                    {
                        foreach (PublisherLink link in publisher_links)
                        {
                            if (link.Latched)
                            {
                                if (latched_messages.ContainsKey(link))
                                {
                                    LatchInfo            latch_info = latched_messages[link];
                                    IMessageDeserializer des        = new IMessageDeserializer(helper, latch_info.message,
                                                                                               latch_info.connection_header);
                                    bool was_full = false;
                                    ((Callback <M>)info.subscription_queue).push((SubscriptionCallbackHelper <M>)info.helper, (MessageDeserializer <M>)des, true,
                                                                                 ref was_full,
                                                                                 latch_info.receipt_time);
                                    ((Callback <M>)info.subscription_queue).topic = topiclol;
                                    if (!was_full)
                                    {
                                        info.callback.addCallback(info.subscription_queue, info.Get());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        internal bool addCallback <M>(SubscriptionCallbackHelper <M> helper, string md5sum, CallbackQueueInterface queue,
                                      uint queue_size, bool allow_concurrent_callbacks, string topiclol) where M : IRosMessage, new()
        {
            lock (md5sum_mutex)
            {
                if (this.md5sum == "*" && md5sum != "*")
                {
                    this.md5sum = md5sum;
                }
            }

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

            lock (callbacks_mutex)
            {
                CallbackInfo <M> info = new CallbackInfo <M> {
                    helper = helper, callback = queue, subscription_queue = new Callback <M>(helper.callback().func, topiclol, queue_size, allow_concurrent_callbacks)
                };
                //if (!helper.isConst())
                //{
                ++nonconst_callbacks;
                //}

                callbacks.Add(info);

                if (latched_messages.Count > 0)
                {
                    MsgTypes 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 = false; //callbacks.Count > 1;
                                    info.subscription_queue.pushitgood(info.helper, latched_messages[link].message, nonconst_need_copy, ref was_full, ROS.GetTime().data);
                                    if (!was_full)
                                    {
                                        info.callback.addCallback(info.subscription_queue, info.Get());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }