writeHeader() public method

public writeHeader ( IDictionary key_vals, WriteFinishedFunc finished_func ) : void
key_vals IDictionary
finished_func WriteFinishedFunc
return void
Exemplo n.º 1
0
        public bool initialize(Connection connection)
        {
#if DEBUG
            EDB.WriteLine("Init transport publisher link: " + parent.name);
#endif
            this.connection          = connection;
            connection.DroppedEvent += onConnectionDropped;
            if (connection.transport.getRequiresHeader())
            {
                connection.setHeaderReceivedCallback(onHeaderReceived);

                IDictionary header = new Hashtable();
                header["topic"]       = parent.name;
                header["md5sum"]      = parent.md5sum;
                header["callerid"]    = this_node.Name;
                header["type"]        = parent.datatype;
                header["tcp_nodelay"] = "1";
                connection.writeHeader(header, onHeaderWritten);
            }
            else
            {
                connection.read(4, onMessageLength);
            }
            return(true);
        }
Exemplo n.º 2
0
        public bool handleHeader(Header header)
        {
            if (!header.Values.Contains("md5sum") || !header.Values.Contains("service") || !header.Values.Contains("callerid"))
            {
                string bbq = "Bogus tcpros header. did not have required elements: md5sum, service, callerid";
                ROS.Error(bbq);
                connection.sendHeaderError(ref bbq);
                return(false);
            }
            string md5sum          = (string)header.Values["md5sum"];
            string service         = (string)header.Values["service"];
            string client_callerid = (string)header.Values["client_callerid"];

            if (header.Values.Contains("persistent") && ((string)header.Values["persistent"] == "1" || (string)header.Values["persistent"] == "true"))
            {
                persistent = true;
            }

            ROS.Debug("Service client [{0}] wants service [{1}] with md5sum [{2}]", client_callerid, service, md5sum);
            IServicePublication isp = ServiceManager.Instance.lookupServicePublication(service);

            if (isp == null)
            {
                string bbq = string.Format("received a tcpros connection for a nonexistent service [{0}]", service);
                ROS.Error(bbq);
                connection.sendHeaderError(ref bbq);
                return(false);
            }

            if (isp.md5sum != md5sum && md5sum != "*" && isp.md5sum != "*")
            {
                string bbq = "client wants service " + service + " to have md5sum " + md5sum + " but it has " + isp.md5sum + ". Dropping connection";
                ROS.Error(bbq);
                connection.sendHeaderError(ref bbq);
                return(false);
            }

            if (isp.isDropped)
            {
                string bbq = "received a tcpros connection for a nonexistent service [" + service + "]";
                ROS.Error(bbq);
                connection.sendHeaderError(ref bbq);
                return(false);
            }

            parent = isp;
            IDictionary m = new Hashtable();

            m["request_type"]  = isp.req_datatype;
            m["response_type"] = isp.res_datatype;
            m["type"]          = isp.datatype;
            m["md5sum"]        = isp.md5sum;
            m["callerid"]      = this_node.Name;

            connection.writeHeader(m, onHeaderWritten);

            isp.addServiceClientLink(this);
            return(true);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        internal void initialize(Connection connection)
        {
            this.connection          = connection;
            connection.DroppedEvent += onConnectionDropped;
            connection.setHeaderReceivedCallback(onHeaderReceived);

            IDictionary dict = new Hashtable();

            dict["service"]    = name;
            dict["md5sum"]     = IRosService.generate((SrvTypes)Enum.Parse(typeof(SrvTypes), RequestType.ToString().Replace("__Request", "").Replace("__Response", ""))).MD5Sum();
            dict["callerid"]   = this_node.Name;
            dict["persistent"] = persistent ? "1" : "0";
            if (header_values != null)
            {
                foreach (object o in header_values.Keys)
                {
                    dict[o] = header_values[o];
                }
            }
            connection.writeHeader(dict, onHeaderWritten);
        }