Ejemplo 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);
        }
Ejemplo n.º 2
0
        public override void pushitgood(ISubscriptionCallbackHelper helper, IMessageDeserializer deserializer, bool nonconst_need_copy, ref bool was_full, TimeData receipt_time)
        {
            lock (queue_mutex)
            {
                if (was_full)
                {
                    was_full = false;
                }
                if (fullNoLock())
                {
                    queue.Dequeue();
                    --queue_size;

                    _full = true;
                    if (was_full)
                    {
                        was_full = true;
                    }
                }
                else
                {
                    _full = false;
                }

                Item i = new Item
                {
                    helper             = helper,
                    deserializer       = deserializer,
                    nonconst_need_copy = nonconst_need_copy,
                    receipt_time       = receipt_time
                };
                queue.Enqueue(i);

                ++queue_size;
            }
        }
Ejemplo n.º 3
0
        internal ulong handleMessage(IRosMessage msg, bool ser, bool nocopy, IDictionary connection_header,
                                     PublisherLink link)
        {
            lock (callbacks_mutex)
            {
                ulong drops = 0;
                cached_deserializers.Clear();
                TimeData receipt_time = ROS.GetTime().data;
                foreach (ICallbackInfo info in callbacks)
                {
                    MsgTypes ti = info.helper.type;
                    if (nocopy || ser)
                    {
                        IMessageDeserializer deserializer = null;
                        if (cached_deserializers.ContainsKey(ti))
                        {
                            deserializer = cached_deserializers[ti];
                        }
                        else
                        {
                            deserializer = MakeDeserializer(ti, info.helper, msg, connection_header);
                            cached_deserializers.Add(ti, deserializer);
                        }
                        bool was_full           = false;
                        bool nonconst_need_copy = callbacks.Count > 1;
                        //info.helper.callback().func(msg);
                        //info.helper.callback().pushitgood(info.helper, deserializer, nonconst_need_copy, ref was_full, receipt_time);
                        info.subscription_queue.pushitgood(info.helper, deserializer, nonconst_need_copy, ref was_full, receipt_time);
                        //push(info.helper, deserializer, nonconst_need_copy, ref was_full,receipt_time);
                        if (was_full)
                        {
                            ++drops;
                        }
                        else
                        {
                            info.callback.addCallback(info.subscription_queue, info.Get());
                        }
                    }
                }

                if (link.Latched)
                {
                    LatchInfo li = new LatchInfo
                    {
                        message           = msg,
                        link              = link,
                        connection_header = connection_header,
                        receipt_time      = receipt_time
                    };
                    if (latched_messages.ContainsKey(link))
                    {
                        latched_messages[link] = li;
                    }
                    else
                    {
                        latched_messages.Add(link, li);
                    }
                }

                cached_deserializers.Clear();
                return(drops);
            }
        }
Ejemplo n.º 4
0
 public virtual void pushitgood(ISubscriptionCallbackHelper helper, IMessageDeserializer deserializer, bool nonconst_need_copy, ref bool was_full, TimeData receipt_time)
 {
     throw new NotImplementedException();
 }