Esempio n. 1
0
        /// <summary>
        ///     Creates a publisher with the given advertise options
        /// </summary>
        /// <typeparam name="M">Type of topic</typeparam>
        /// <param name="ops">Advertise options</param>
        /// <returns>A publisher with the specified options</returns>
        public Publisher <M> advertise <M>(AdvertiseOptions <M> ops) where M : IRosMessage, new()
        {
            if (Process.GetCurrentProcess().ProcessName == "devenv")
            {
                return(null);
            }
            ops.topic = resolveName(ops.topic);
            if (ops.callback_queue == null)
            {
                ops.callback_queue = Callback;
            }
            SubscriberCallbacks callbacks = new SubscriberCallbacks(ops.connectCB, ops.disconnectCB, ops.callback_queue);

            if (TopicManager.Instance.advertise(ops, callbacks))
            {
                Publisher <M> pub = new Publisher <M>(ops.topic, ops.md5sum, ops.datatype, this, callbacks);
                lock (collection.mutex)
                {
                    collection.publishers.Add(pub);
                }
                return(pub);
            }
            Console.WriteLine("ADVERTISE FAILED!!!!");
            return(null);
        }
Esempio n. 2
0
        public bool unadvertise(string topic, SubscriberCallbacks callbacks)
        {
            Publication pub = null;

            lock (advertised_topics_mutex)
            {
                foreach (Publication p in advertised_topics)
                {
                    if (p.Name == topic && !p.Dropped)
                    {
                        pub = p;
                        break;
                    }
                }
            }
            if (pub == null)
            {
                return(false);
            }
            pub.removeCallbacks(callbacks);
            lock (advertised_topics_mutex)
            {
                if (pub.NumCallbacks == 0)
                {
                    unregisterPublisher(pub.Name);
                    pub.drop();
                    advertised_topics.Remove(pub);
                }
            }
            return(true);
        }
Esempio n. 3
0
 public RosOutAppender()
 {
     publish_thread = new Thread(logThread) {IsBackground = true};
     publish_thread.Start();
     AdvertiseOptions<Log> ops = new AdvertiseOptions<Log>(names.resolve("/rosout"), 0) {latch = true};
     SubscriberCallbacks cbs = new SubscriberCallbacks();
     TopicManager.Instance.advertise(ops, cbs);
 }
 /// <summary>
 ///     Creates a ros publisher
 /// </summary>
 /// <param name="topic">Topic name to publish to</param>
 /// <param name="md5sum">md5sum for topic and type</param>
 /// <param name="datatype">Datatype to publish</param>
 /// <param name="nodeHandle">nodehandle</param>
 /// <param name="callbacks">Any callbacks to attach</param>
 public Publisher(string topic, string md5sum, string datatype, NodeHandle nodeHandle,
                  SubscriberCallbacks callbacks)
 {
     // TODO: Complete member initialization
     this.topic      = topic;
     this.md5sum     = md5sum;
     this.datatype   = datatype;
     this.nodeHandle = nodeHandle;
     this.callbacks  = callbacks;
 }
Esempio n. 5
0
 public void removeCallbacks(SubscriberCallbacks callbacks)
 {
     lock (callbacks_mutex)
     {
         callbacks.Callback.removeByID(callbacks.Get());
         if (this.callbacks.Contains(callbacks))
         {
             this.callbacks.Remove(callbacks);
         }
     }
 }
Esempio n. 6
0
        public RosOutAppender()
        {
            publish_thread = new Thread(logThread)
            {
                IsBackground = true
            };
            publish_thread.Start();
            AdvertiseOptions <Log> ops = new AdvertiseOptions <Log>(names.resolve("/rosout"), 0)
            {
                latch = true
            };
            SubscriberCallbacks cbs = new SubscriberCallbacks();

            TopicManager.Instance.advertise(ops, cbs);
        }
Esempio n. 7
0
        public void addCallbacks(SubscriberCallbacks callbacks)
        {
            lock (callbacks_mutex)
            {
                this.callbacks.Add(callbacks);
                if (callbacks.connect != null && callbacks.Callback != null)
                {
                    lock (subscriber_links_mutex)
                    {
                        foreach (SubscriberLink i in subscriber_links)
                        {
                            CallbackInterface cb = new PeerConnDisconnCallback(callbacks.connect, i);

                            callbacks.Callback.addCallback(cb, callbacks.Get());
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 public void removeCallbacks(SubscriberCallbacks callbacks)
 {
     lock (callbacks_mutex)
     {
         callbacks.Callback.removeByID(callbacks.Get());
         if (this.callbacks.Contains(callbacks))
             this.callbacks.Remove(callbacks);
     }
 }
Esempio n. 9
0
        public void addCallbacks(SubscriberCallbacks callbacks)
        {
            lock (callbacks_mutex)
            {
                this.callbacks.Add(callbacks);
                if (callbacks.connect != null && callbacks.Callback != null)
                {
                    lock (subscriber_links_mutex)
                    {
                        foreach (SubscriberLink i in subscriber_links)
                        {
                            CallbackInterface cb = new PeerConnDisconnCallback(callbacks.connect, i);

                            callbacks.Callback.addCallback(cb, callbacks.Get());
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        ///     Register as a publisher on a topic.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ops"></param>
        /// <param name="callbacks"></param>
        /// <returns></returns>
        public bool advertise <T>(AdvertiseOptions <T> ops, SubscriberCallbacks callbacks) where T : IRosMessage, new()
        {
            if (!isValid(ops))
            {
                return(false);
            }
            Publication pub = null;

            lock (advertised_topics_mutex)
            {
                if (shutting_down)
                {
                    return(false);
                }
                pub = lookupPublicationWithoutLock(ops.topic);
                if (pub != null)
                {
                    if (pub.Md5sum != ops.md5sum)
                    {
                        EDB.WriteLine
                            ("Tried to advertise on topic [{0}] with md5sum [{1}] and datatype [{2}], but the topic is already advertised as md5sum [{3}] and datatype [{4}]",
                            ops.topic, ops.md5sum,
                            ops.datatype, pub.Md5sum, pub.DataType);
                        return(false);
                    }
                }
                else
                {
                    pub = new Publication(ops.topic, ops.datatype, ops.md5sum, ops.message_definition, ops.queue_size,
                                          ops.latch, ops.has_header);
                }
                pub.addCallbacks(callbacks);
                advertised_topics.Add(pub);
            }

            bool         found = false;
            Subscription sub   = null;

            lock (subs_mutex)
            {
                foreach (Subscription s in subscriptions)
                {
                    if (s.name == ops.topic && md5sumsMatch(s.md5sum, ops.md5sum) && !s.IsDropped)
                    {
                        found = true;
                        sub   = s;
                        break;
                    }
                }
            }

            if (found)
            {
                sub.addLocalConnection(pub);
            }

            XmlRpcValue args    = new XmlRpcValue(this_node.Name, ops.topic, ops.datatype, XmlRpcManager.Instance.uri),
                        result  = new XmlRpcValue(),
                        payload = new XmlRpcValue();

            master.execute("registerPublisher", args, result, payload, true);
            return(true);
        }