Esempio n. 1
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);
            }

            lock (advertised_topics_names_mutex)
            {
                advertised_topics_names.Add(ops.topic);
            }

            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, ref result, ref payload, true);
            return(true);
        }