Inheritance: IDisposable
コード例 #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);
            }

            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);
        }
コード例 #2
0
 public LocalSubscriberLink(Publication pub)
 {
     parent = pub;
     topic = parent.Name;
 }
コード例 #3
0
 public LocalSubscriberLink(Publication pub)
 {
     parent = pub;
     topic  = parent.Name;
 }
コード例 #4
0
        public bool handleHeader(Header header)
        {
            if (!header.Values.Contains("topic"))
            {
                string msg = "Header from subscriber did not have the required element: topic";
                EDB.WriteLine(msg);
                connection.sendHeaderError(ref msg);
                return false;
            }
            string name = (string) header.Values["topic"];
            string client_callerid = (string) header.Values["callerid"];
            Publication pt = TopicManager.Instance.lookupPublication(name);
            if (pt == null)
            {
                string msg = "received a connection for a nonexistent topic [" + name + "] from [" +
                             connection.transport + "] [" + client_callerid + "]";
                EDB.WriteLine(msg);
                connection.sendHeaderError(ref msg);
                return false;
            }
            string error_message = "";
            if (!pt.validateHeader(header, ref error_message))
            {
                connection.sendHeaderError(ref error_message);
                EDB.WriteLine(error_message);
                return false;
            }
            destination_caller_id = client_callerid;
            connection_id = ConnectionManager.Instance.GetNewConnectionID();
            name = pt.Name;
            parent = pt;
            lock (parent)
            {
                max_queue = parent.MaxQueue;
            }
            IDictionary m = new Hashtable();
            m["type"] = pt.DataType;
            m["md5sum"] = pt.Md5sum;
            m["message_definition"] = pt.MessageDefinition;
            m["callerid"] = this_node.Name;
            m["latching"] = pt.Latch;
            connection.writeHeader(m, onHeaderWritten);
            pt.addSubscriberLink(this);
#if DEBUG
            EDB.WriteLine("Finalize transport subscriber link for " + name);
#endif
            return true;
        }
コード例 #5
0
ファイル: TopicManager.cs プロジェクト: cephdon/ROS.NET
 public void publish(string topic, IRosMessage message, ref Publication p)
 {
     publish(topic, message.Serialize, message, ref p);
 }
コード例 #6
0
ファイル: TopicManager.cs プロジェクト: cephdon/ROS.NET
        public void publish(string topic, IRosMessage message)
        {
            Publication p = null;

            publish(topic, message.Serialize, message, ref p);
        }
コード例 #7
0
ファイル: TopicManager.cs プロジェクト: cephdon/ROS.NET
        public void publish <M>(string topic, M message) where M : IRosMessage, new()
        {
            Publication p = null;

            publish(topic, message.Serialize, message, ref p);
        }