예제 #1
0
 public static void WriteMessage(Message msg, TextWriter w)
 {
     w.WriteLine("# Message");
     w.WriteLine("# Header");
     MessageDumper.WriteBlock(msg.GetHeaderData(), w);
     w.WriteLine("# Body");
     MessageDumper.WriteBlock(msg.Body, w);
     w.WriteLine();
     w.Flush();
 }
예제 #2
0
        public static Message ReadMessage(TextReader r)
        {
            byte[] header = MessageDumper.ReadBlock(r);

            if (header == null)
            {
                return(null);
            }

            byte[] body = MessageDumper.ReadBlock(r);

            Message msg = new Message();

            msg.SetHeaderData(header);
            msg.Body = body;

            return(msg);
        }
예제 #3
0
        public override uint Send(Message msg)
        {
            if (!isConnected)
            {
                return(0);
            }

            /*
             * if (msg.Header.MessageType == NDesk.DBus.MessageType.Signal) {
             *      Signal signal = new Signal (msg);
             *      if (signal.Member == "NameAcquired" || signal.Member == "NameLost") {
             *              string dest = (string)msg.Header[FieldCode.Destination];
             *              if (dest != UniqueName)
             *                      return 0;
             *      }
             * }
             */

            if (msg.Header.MessageType != NDesk.DBus.MessageType.MethodReturn)
            {
                msg.Header[FieldCode.Sender] = ServerBus.DBusBusName;
            }

            if (UniqueName != null)
            {
                msg.Header[FieldCode.Destination] = UniqueName;
            }

            if (shouldDump)
            {
                MessageDumper.WriteComment("Sending:", Console.Out);
                MessageDumper.WriteMessage(msg, Console.Out);
            }

            //return base.Send (msg);
            return(SendReal(msg));
        }
예제 #4
0
        public override void HandleMessage(Message msg)
        {
            if (!isConnected)
            {
                return;
            }

            if (msg == null)
            {
                Console.Error.WriteLine("Disconnected!");
                isConnected = false;
                //Server.Bus.RemoveConnection (this);
                //ServerBus sbus = Unregister (new ObjectPath ("/org/freedesktop/DBus")) as ServerBus;

                /*
                 * ServerBus sbus = Unregister (new ObjectPath ("/org/freedesktop/DBus")) as ServerBus;
                 * Register (new ObjectPath ("/org/freedesktop/DBus"), sbus);
                 * sbus.RemoveConnection (this);
                 */

                Server.SBus.RemoveConnection(this);

                //Server.ConnectionLost (this);
                return;
            }

            Server.CurrentMessageConnection = this;
            Server.CurrentMessage           = msg;

            try {
                if (shouldDump)
                {
                    MessageDumper.WriteComment("Handling:", Console.Out);
                    MessageDumper.WriteMessage(msg, Console.Out);
                }

                if (UniqueName != null)
                {
                    msg.Header[FieldCode.Sender] = UniqueName;
                }

                object fieldValue = msg.Header[FieldCode.Destination];
                if (fieldValue != null)
                {
                    if ((string)fieldValue == ServerBus.DBusBusName)
                    {
                        // Workaround for our daemon only listening on a single path
                        if (msg.Header.MessageType == NDesk.DBus.MessageType.MethodCall)
                        {
                            msg.Header[FieldCode.Path] = ServerBus.Path;
                        }

                        base.HandleMessage(msg);
                        //return;
                    }
                }
                //base.HandleMessage (msg);

                Server.SBus.HandleMessage(msg);
            } finally {
                Server.CurrentMessageConnection = null;
                Server.CurrentMessage           = null;
            }
        }