Пример #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);
        }
Пример #2
0
 /// <summary>
 ///     Checks if the given topic is valid.
 /// </summary>
 /// <typeparam name="T">Advertise Options </typeparam>
 /// <param name="ops"></param>
 /// <returns></returns>
 private bool isValid <T>(AdvertiseOptions <T> ops) where T : IRosMessage, new()
 {
     if (ops.datatype == "*")
     {
         throw new Exception("Advertising with * as the datatype is not allowed.  Topic [" + ops.topic + "]");
     }
     if (ops.md5sum == "*")
     {
         throw new Exception("Advertising with * as the md5sum is not allowed.  Topic [" + ops.topic + "]");
     }
     if (ops.md5sum == "")
     {
         throw new Exception("Advertising on topic [" + ops.topic + "] with an empty md5sum");
     }
     if (ops.datatype == "")
     {
         throw new Exception("Advertising on topic [" + ops.topic + "] with an empty datatype");
     }
     if (ops.message_definition == "")
     {
         EDB.WriteLine
             ("Danger, Will Robinson... Advertising on topic [" + ops.topic +
             "] with an empty message definition. Some tools (that don't exist in this implementation) may not work correctly");
     }
     return(true);
 }
Пример #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);
        }
Пример #4
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);
        }