Ejemplo n.º 1
0
 private void OnDeviceCommand(_WP.IncomingMessage msg, bool fReply)
 {
     if (!fReply)
     {
         switch (msg.Header.m_cmd)
         {
         case _WP.Commands.c_Profiling_Stream:
             _WP.Commands.Profiling_Stream pay = (_WP.Commands.Profiling_Stream)msg.Payload;
             //Some sort of packet ordering with 'pay.seqId' to gurantee packets are need to arrived in the correct order and aren't lost.
             if (m_firstPacket)
             {
                 m_firstPacket            = false;
                 m_lastSeenStreamPacketID = pay.seqId;
             }
             else
             {
                 if (pay.seqId == 0)
                 {
                     //Sometimes the device manages to send out a packet before the device restarts and manages to throw off sequence id checking.
                     m_lastSeenStreamPacketID = 0;
                 }
                 else
                 {
                     System.Diagnostics.Debug.Assert(pay.seqId == m_lastSeenStreamPacketID + 1);
                     m_lastSeenStreamPacketID = pay.seqId;
                 }
             }
             m_bitsReceived += pay.bitLen;
             m_incomingStream.AppendChunk(pay.payload, 0, pay.bitLen);
             break;
         }
     }
 }
Ejemplo n.º 2
0
 private void OnMessage(_DBG.WireProtocol.IncomingMessage msg, string text)
 {
     if (OnDebugText != null)
     {
         OnDebugText(this, new DebugOutputEventArgs(text));
     }
 }
Ejemplo n.º 3
0
 public void OnWPCommand(_WP.IncomingMessage msg, bool fReply)
 {
     switch (msg.Header.m_cmd)
     {
     case _WP.Commands.c_Monitor_ProgramExit:
         this.Invoke((MethodInvoker)SoftDisconnect);
         break;
     }
 }
Ejemplo n.º 4
0
        bool _WP.IControllerHostRemote.ProcessMessage(byte[] header, byte[] payload, bool fReply)
        {
            _WP.MessageRaw      raw = new _WP.MessageRaw(); raw.m_header = header; raw.m_payload = payload;
            _WP.MessageBase     bs  = new _WP.MessageBase();
            _WP.IncomingMessage msg = new _WP.IncomingMessage(this, raw, bs);

            bs.m_header = new _WP.Packet();

            new _WP.Converter(this.ParentIControllerRemote.Capabilities).Deserialize(bs.m_header, raw.m_header);

            return(m_owner.ProcessMessage(msg, fReply));
        }
Ejemplo n.º 5
0
 public void OnWPMessage(_WP.IncomingMessage msg, string text)
 {
     char[] NEWLINE_CHARS = { '\r', '\n' };
     text = text.TrimEnd(NEWLINE_CHARS);
     if (String.IsNullOrEmpty(text))
     {
         LogText("");
     }
     else
     {
         LogText(String.Concat("Received message from device: ", text));
     }
 }
Ejemplo n.º 6
0
        //--//

        private GatewayStub FindGatewayStubForReply(_WP.IncomingMessage msg)
        {
            ArrayList stubs = CreateCopyOfStubs();

            for (int iStub = stubs.Count - 1; iStub >= 0; iStub--)
            {
                GatewayStub stub = (GatewayStub)stubs[iStub];

                if (stub.CanProcessMessageReply(msg))
                {
                    return(stub);
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
        private GatewayStub FindGatewayStubForRpc(_WP.IncomingMessage msg)
        {
            object payload = msg.Payload;
            uint   epType  = 0;
            uint   epId    = 0;

            _WP.Commands.Debugging_Messaging_Address addr = null;

            switch (msg.Header.m_cmd)
            {
            case _WP.Commands.c_Debugging_Messaging_Query:
                addr = ((_WP.Commands.Debugging_Messaging_Query)payload).m_addr;

                epType = addr.m_to_Type;
                epId   = addr.m_to_Id;
                break;

            case _WP.Commands.c_Debugging_Messaging_Reply:
                addr = ((_WP.Commands.Debugging_Messaging_Reply)payload).m_addr;

                epType = addr.m_from_Type;
                epId   = addr.m_from_Id;
                break;

            case _WP.Commands.c_Debugging_Messaging_Send:
                addr = ((_WP.Commands.Debugging_Messaging_Send)payload).m_addr;

                epType = addr.m_to_Type;
                epId   = addr.m_to_Id;
                break;

            default:
                return(null);
            }

            ulong epKey = EndpointKeyFromTypeId(epType, epId);

            GatewayStub stub = (GatewayStub)m_endpoints[epKey];

            return(stub);
        }
Ejemplo n.º 8
0
        bool _WP.IControllerHostLocal.ProcessMessage(_WP.IncomingMessage msg, bool fReply)
        {
            bool fRes = true;

            ArrayList stubs = FindGatewayStubsForMessage(msg, fReply);

            foreach (GatewayStub stub in stubs)
            {
                try
                {
                    if (!stub.ProcessMessage(msg, fReply))
                    {
                        fRes = false;
                    }
                }
                catch
                {
                }
            }

            return(fRes);
        }
Ejemplo n.º 9
0
 private static void DebugDump(WireProtocol.IncomingMessage m, string text)
 {
 }
Ejemplo n.º 10
0
        public bool ProcessMessage( IncomingMessage msg, bool fReply )
        {
            msg.Payload = Commands.ResolveCommandToPayload( msg.Header.m_cmd, fReply, m_capabilities );

            if( fReply == true )
            {
                Request reply = null;

                lock( m_requests.SyncRoot )
                {
                    foreach( Request req in m_requests )
                    {
                        if( req.MatchesReply( msg ) )
                        {
                            m_requests.Remove( req );

                            reply = req;
                            break;
                        }
                    }
                }

                if( reply != null )
                {
                    reply.Signal( msg );
                    return true;
                }
            }
            else
            {
                Packet bp = msg.Header;

                switch( bp.m_cmd )
                {
                case Commands.c_Monitor_Ping:
                    {
                        Commands.Monitor_Ping.Reply cmdReply = new Commands.Monitor_Ping.Reply( );

                        cmdReply.m_source = Commands.Monitor_Ping.c_Ping_Source_Host;
                        cmdReply.m_dbg_flags = ( m_stopDebuggerOnConnect ? Commands.Monitor_Ping.c_Ping_DbgFlag_Stop : 0 );

                        msg.Reply( CreateConverter( ), Flags.c_NonCritical, cmdReply );

                        m_evtPing.Set( );

                        return true;
                    }

                case Commands.c_Monitor_Message:
                    {
                        Commands.Monitor_Message payload = msg.Payload as Commands.Monitor_Message;

                        Debug.Assert( payload != null );

                        if( payload != null )
                        {
                            QueueNotify( m_eventMessage, msg, payload.ToString( ) );
                        }

                        return true;
                    }

                case Commands.c_Debugging_Messaging_Query:
                case Commands.c_Debugging_Messaging_Reply:
                case Commands.c_Debugging_Messaging_Send:
                    {
                        Debug.Assert( msg.Payload != null );

                        if( msg.Payload != null )
                        {
                            QueueRpc( msg );
                        }

                        return true;
                    }
                }
            }

            if( m_eventCommand != null )
            {
                QueueNotify( m_eventCommand, msg, fReply );
                return true;
            }

            return false;
        }
Ejemplo n.º 11
0
        internal bool MatchesReply( IncomingMessage res )
        {
            Packet headerReq = m_outMsg.Header;
            Packet headerRes = res.Header;

            if( headerReq.m_cmd == headerRes.m_cmd &&
               headerReq.m_seq == headerRes.m_seqReply )
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Essential Rx method. Drives state machine by reading data and processing it. This works in
        /// conjunction with NotificationThreadWorker [Tx].
        /// </summary>
        internal async Task <IncomingMessage> ProcessAsync(CancellationToken cancellationToken)
        {
            int count;
            int bytesRead;

            try
            {
                switch (m_state)
                {
                case ReceiveState.Initialize:

                    if (cancellationToken.IsCancellationRequested)
                    {
                        // cancellation requested
                        return(null);
                    }

                    m_rawPos = 0;

                    m_base          = new MessageBase();
                    m_base.m_header = new Packet();

                    m_raw          = new MessageRaw();
                    m_raw.m_header = m_parent.CreateConverter().Serialize(m_base.m_header);

                    m_state = ReceiveState.WaitingForHeader;
                    DebuggerEventSource.Log.WireProtocolReceiveState(m_state);
                    goto case ReceiveState.WaitingForHeader;

                case ReceiveState.WaitingForHeader:
                    count = m_raw.m_header.Length - m_rawPos;

                    //Debug.WriteLine("WaitingForHeader");

                    // need to have a timeout to cancel the read task otherwise it may end up waiting forever for this to return
                    // because we have an external cancellation token and the above timeout cancellation token, need to combine both

                    bytesRead = await m_parent.ReadBufferAsync(m_raw.m_header, m_rawPos, count, request.waitRetryTimeout, cancellationToken.AddTimeout(request.waitRetryTimeout)).ConfigureAwait(false);

                    m_rawPos += bytesRead;

                    // sanity check
                    if (bytesRead != 32)
                    {
                        // doesn't look like a header, better restart
                        m_state = ReceiveState.Initialize;
                        goto case ReceiveState.Initialize;
                    }

                    while (m_rawPos > 0)
                    {
                        int flag_Debugger = ValidSignature(marker_Debugger);
                        int flag_Packet   = ValidSignature(marker_Packet);

                        if (flag_Debugger == 1 || flag_Packet == 1)
                        {
                            m_state = ReceiveState.ReadingHeader;
                            DebuggerEventSource.Log.WireProtocolReceiveState(m_state);
                            goto case ReceiveState.ReadingHeader;
                        }

                        if (flag_Debugger == 0 || flag_Packet == 0)
                        {
                            break;     // Partial match.
                        }

                        m_parent.App.SpuriousCharacters(m_raw.m_header, 0, 1);

                        Array.Copy(m_raw.m_header, 1, m_raw.m_header, 0, --m_rawPos);
                    }
                    break;

                case ReceiveState.ReadingHeader:
                    count = m_raw.m_header.Length - m_rawPos;

                    //Debug.WriteLine("ReadingHeader");

                    // need to have a timeout to cancel the read task otherwise it may end up waiting forever for this to return
                    // because we have an external cancellation token and the above timeout cancellation token, need to combine both

                    bytesRead = await m_parent.ReadBufferAsync(m_raw.m_header, m_rawPos, count, request.waitRetryTimeout, cancellationToken.AddTimeout(request.waitRetryTimeout)).ConfigureAwait(false);

                    m_rawPos += bytesRead;

                    if (bytesRead != count)
                    {
                        break;
                    }

                    m_state = ReceiveState.CompleteHeader;
                    DebuggerEventSource.Log.WireProtocolReceiveState(m_state);
                    goto case ReceiveState.CompleteHeader;
                //break;

                case ReceiveState.CompleteHeader:
                    try
                    {
                        //Debug.WriteLine("CompleteHeader");

                        m_parent.CreateConverter().Deserialize(m_base.m_header, m_raw.m_header);

                        if (VerifyHeader() == true)
                        {
                            //Debug.WriteLine("CompleteHeader, header OK");

                            bool fReply = (m_base.m_header.m_flags & Flags.c_Reply) != 0;

                            DebuggerEventSource.Log.WireProtocolRxHeader(m_base.m_header.m_crcHeader, m_base.m_header.m_crcData, m_base.m_header.m_cmd, m_base.m_header.m_flags, m_base.m_header.m_seq, m_base.m_header.m_seqReply, m_base.m_header.m_size);

                            if (m_base.m_header.m_size != 0)
                            {
                                m_raw.m_payload = new byte[m_base.m_header.m_size];
                                //reuse m_rawPos for position in header to read.
                                m_rawPos = 0;

                                m_state = ReceiveState.ReadingPayload;
                                DebuggerEventSource.Log.WireProtocolReceiveState(m_state);
                                goto case ReceiveState.ReadingPayload;
                            }
                            else
                            {
                                m_state = ReceiveState.CompletePayload;
                                DebuggerEventSource.Log.WireProtocolReceiveState(m_state);
                                goto case ReceiveState.CompletePayload;
                            }
                        }

                        //Debug.WriteLine("CompleteHeader, header not valid");
                    }
                    //catch (ThreadAbortException)
                    //{
                    //    throw;
                    //}
                    catch (Exception e)
                    {
                        Debug.WriteLine("Fault at payload deserialization:\n\n{0}", e.ToString());
                    }

                    m_state = ReceiveState.Initialize;
                    DebuggerEventSource.Log.WireProtocolReceiveState(m_state);

                    if ((m_base.m_header.m_flags & Flags.c_NonCritical) == 0)
                    {
                        // FIXME
                        // evaluate the purpose of this reply back to the NETMF device, the TinyCRL doesn't seem to have to handle this. In the end it looks like this does have any real purpose and will only be wasting CPU.
                        //await IncomingMessage.ReplyBadPacketAsync(m_parent, Flags.c_BadHeader).ConfigureAwait(false);
                        return(null);
                    }

                    break;

                case ReceiveState.ReadingPayload:
                    count = m_raw.m_payload.Length - m_rawPos;

                    //Debug.WriteLine("ReadingPayload");

                    // need to have a timeout to cancel the read task otherwise it may end up waiting forever for this to return
                    // because we have an external cancellation token and the above timeout cancellation token, need to combine both

                    bytesRead = await m_parent.ReadBufferAsync(m_raw.m_payload, m_rawPos, count, request.waitRetryTimeout, cancellationToken.AddTimeout(request.waitRetryTimeout)).ConfigureAwait(false);

                    m_rawPos += bytesRead;

                    if (bytesRead != count)
                    {
                        break;
                    }

                    m_state = ReceiveState.CompletePayload;
                    DebuggerEventSource.Log.WireProtocolReceiveState(m_state);
                    goto case ReceiveState.CompletePayload;

                case ReceiveState.CompletePayload:
                    //Debug.WriteLine("CompletePayload");

                    if (VerifyPayload() == true)
                    {
                        //Debug.WriteLine("CompletePayload payload OK");

                        try
                        {
                            bool fReply = (m_base.m_header.m_flags & Flags.c_Reply) != 0;

                            if ((m_base.m_header.m_flags & Flags.c_NACK) != 0)
                            {
                                m_raw.m_payload = null;
                            }

                            if (await ProcessMessage(this.GetCompleteMessage(), fReply).ConfigureAwait(false))
                            {
                                DebuggerEventSource.Log.WireProtocolReceiveState(m_state);

                                //Debug.WriteLine("*** leaving reassembler");

                                return(this.GetCompleteMessage());
                            }
                            else
                            {
                                // this is not the message we were waiting
                                // FIXME
                            }
                            //m_parent.App.ProcessMessage(this.GetCompleteMessage(), fReply);

                            //m_state = ReceiveState.Initialize;
                            //return;
                        }
                        //catch (ThreadAbortException)
                        //{
                        //    throw;
                        //}
                        catch (Exception e)
                        {
                            Debug.WriteLine("Fault at payload deserialization:\n\n{0}", e.ToString());
                        }
                    }
                    else
                    {
                        Debug.WriteLine("CompletePayload payload not valid");
                    }

                    m_state = ReceiveState.Initialize;
                    DebuggerEventSource.Log.WireProtocolReceiveState(m_state);

                    if ((m_base.m_header.m_flags & Flags.c_NonCritical) == 0)
                    {
                        // FIXME
                        // evaluate the purpose of this reply back to the NETMF device, the TinyCRL doesn't seem to have to handle this. In the end it looks like this does have any real purpose and will only be wasting CPU.
                        await IncomingMessage.ReplyBadPacketAsync(m_parent, Flags.c_BadPayload).ConfigureAwait(false);

                        return(null);
                    }

                    break;
                }
            }
            catch
            {
                m_state = ReceiveState.Initialize;
                DebuggerEventSource.Log.WireProtocolReceiveState(m_state);
                //Debug.WriteLine("*** leaving reassembler");
                throw;
            }

            //Debug.WriteLine("*** leaving reassembler");
            return(null);
        }
        private WireProtocol.IncomingMessage[] SyncMessages(WireProtocol.OutgoingMessage[] messages, int retries, int timeout)
        {
            int cMessage = messages.Length;
            WireProtocol.IncomingMessage[] replies = new WireProtocol.IncomingMessage[cMessage];
            Request[] requests = new Request[cMessage];

            for (int iMessage = 0; iMessage < cMessage; iMessage++)
            {
                replies[iMessage] = SyncRequest(messages[iMessage], retries, timeout);
            }

            return replies;
        }
Ejemplo n.º 14
0
        bool _WP.IControllerHostRemote.ProcessMessage( byte[] header, byte[] payload, bool fReply )
        {
            _WP.MessageRaw      raw = new _WP.MessageRaw (); raw.m_header = header; raw.m_payload = payload;
            _WP.MessageBase     bs  = new _WP.MessageBase();
            _WP.IncomingMessage msg = new _WP.IncomingMessage( this, raw, bs );

            bs.m_header = new _WP.Packet();

            new _WP.Converter( this.ParentIControllerRemote.Capabilities ).Deserialize( bs.m_header, raw.m_header );

            return m_owner.ProcessMessage( msg, fReply );
        }
Ejemplo n.º 15
0
 static public bool IsPositiveAcknowledge(IncomingMessage reply)
 {
     return(reply != null && ((reply.Header.m_flags & WireProtocol.Flags.c_ACK) != 0));
 }
Ejemplo n.º 16
0
 private void OnCommand(IncomingMessage msg, bool reply)
 {
     // The event will signal the program exit. Set the manual reset event once the program exits
     // and dispose the engine. 
     if (msg.Header.m_cmd == Microsoft.SPOT.Debugger.WireProtocol.Commands.c_Monitor_ProgramExit)
     {
         m_deviceDone.Set();
     }
 }
Ejemplo n.º 17
0
        internal bool ProcessMessage(_WP.IncomingMessage msg, bool fReply)
        {
            m_requests.Remove(msg.Header.m_seqReply);

            return(m_owner.ProcessMessage(msg.Raw.m_header, msg.Raw.m_payload, fReply));
        }
Ejemplo n.º 18
0
 internal bool CanProcessMessageReply(_WP.IncomingMessage msg)
 {
     return(m_requests.Contains(msg.Header.m_seqReply));
 }
Ejemplo n.º 19
0
        private ArrayList FindGatewayStubsForMessage(_WP.IncomingMessage msg, bool fReply)
        {
            ArrayList   stubs      = null;
            GatewayStub stub       = null;
            bool        fMulticast = false;

            msg.Payload = _WP.Commands.ResolveCommandToPayload(msg.Header.m_cmd, fReply, ((_WP.IController) this).Capabilities);

            _WP.Packet bp = msg.Header;

            if (fReply)
            {
                stub = FindGatewayStubForReply(msg);
            }
            else
            {
                switch (bp.m_cmd)
                {
                case _WP.Commands.c_Monitor_Ping:
                    if ((msg.Header.m_flags & _WP.Flags.c_NonCritical) == 0)
                    {
                        _WP.Commands.Monitor_Ping.Reply cmdReply = new _WP.Commands.Monitor_Ping.Reply();
                        cmdReply.m_source    = _WP.Commands.Monitor_Ping.c_Ping_Source_Host;
                        cmdReply.m_dbg_flags = (m_stopDebuggerOnBoot? _WP.Commands.Monitor_Ping.c_Ping_DbgFlag_Stop: 0);

                        msg.Reply(null, _WP.Flags.c_NonCritical, cmdReply);
                    }
                    break;

                case _WP.Commands.c_Monitor_Message:
                case _WP.Commands.c_Monitor_ProgramExit:
                case _WP.Commands.c_Debugging_Button_Report:
                case _WP.Commands.c_Debugging_Execution_BreakpointHit:
                case _WP.Commands.c_Debugging_Lcd_NewFrame:
                case _WP.Commands.c_Debugging_Lcd_NewFrameData:
                    fMulticast = true;
                    break;

                case _WP.Commands.c_Debugging_Messaging_Query:
                case _WP.Commands.c_Debugging_Messaging_Reply:
                case _WP.Commands.c_Debugging_Messaging_Send:
                    stub = FindGatewayStubForRpc(msg);
                    break;
                }
            }

            if (fMulticast)
            {
                stubs = CreateCopyOfStubs();
            }
            else
            {
                stubs = new ArrayList();

                if (stub != null)
                {
                    stubs.Add(stub);
                }
            }

            return(stubs);
        }
Ejemplo n.º 20
0
 private void OnMessage(IncomingMessage msg, string mesg)
 {
     // Append the debug message to the output string object.
     m_debugText.Append(mesg);
 }
Ejemplo n.º 21
0
 static public bool IsPositiveAcknowledge( IncomingMessage reply )
 {
     return reply != null && ((reply.Header.m_flags & WireProtocol.Flags.c_ACK) != 0);
 }
Ejemplo n.º 22
0
        void OnMessage(_WP.IncomingMessage msg, string text)
        {
            byte[] buf = Encoding.ASCII.GetBytes(text);

            HandleOutput(buf, 0, buf.Length);
        }
Ejemplo n.º 23
0
            /// <summary>
            /// Essential Rx method. Drives state machine by reading data and processing it. This works in
            /// conjunction with NotificationThreadWorker [Tx].
            /// </summary>
            internal void Process()
            {
                int count;
                int bytesRead;

                try
                {
                    switch (m_state)
                    {
                    case ReceiveState.Initialize:
                        m_rawPos = 0;

                        m_base          = new MessageBase();
                        m_base.m_header = new Packet();

                        m_raw          = new MessageRaw();
                        m_raw.m_header = m_parent.CreateConverter().Serialize(m_base.m_header);

                        m_state = ReceiveState.WaitingForHeader;
                        goto case ReceiveState.WaitingForHeader;

                    case ReceiveState.WaitingForHeader:
                        count = m_raw.m_header.Length - m_rawPos;

                        bytesRead = m_parent.Read(m_raw.m_header, m_rawPos, count);
                        m_rawPos += bytesRead;

                        while (m_rawPos > 0)
                        {
                            int flag_Debugger = ValidSignature(m_parent.marker_Debugger);
                            int flag_Packet   = ValidSignature(m_parent.marker_Packet);

                            if (flag_Debugger == 1 || flag_Packet == 1)
                            {
                                m_state = ReceiveState.ReadingHeader;
                                goto case ReceiveState.ReadingHeader;
                            }

                            if (flag_Debugger == 0 || flag_Packet == 0)
                            {
                                break;     // Partial match.
                            }

                            m_parent.App.SpuriousCharacters(m_raw.m_header, 0, 1);

                            Array.Copy(m_raw.m_header, 1, m_raw.m_header, 0, --m_rawPos);
                        }
                        break;

                    case ReceiveState.ReadingHeader:
                        count = m_raw.m_header.Length - m_rawPos;

                        bytesRead = m_parent.Read(m_raw.m_header, m_rawPos, count);

                        m_rawPos += bytesRead;

                        if (bytesRead != count)
                        {
                            break;
                        }

                        m_state = ReceiveState.CompleteHeader;
                        goto case ReceiveState.CompleteHeader;

                    case ReceiveState.CompleteHeader:
                        try
                        {
                            m_parent.CreateConverter().Deserialize(m_base.m_header, m_raw.m_header);

                            if (VerifyHeader() == true)
                            {
                                bool fReply = (m_base.m_header.m_flags & Flags.c_Reply) != 0;

                                m_base.DumpHeader("Receiving");

                                if (m_base.m_header.m_size != 0)
                                {
                                    m_raw.m_payload = new byte[m_base.m_header.m_size];
                                    //reuse m_rawPos for position in header to read.
                                    m_rawPos = 0;

                                    m_state = ReceiveState.ReadingPayload;
                                    goto case ReceiveState.ReadingPayload;
                                }
                                else
                                {
                                    m_state = ReceiveState.CompletePayload;
                                    goto case ReceiveState.CompletePayload;
                                }
                            }
                        }
                        catch (ThreadAbortException)
                        {
                            throw;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Fault at payload deserialization:\n\n{0}", e.ToString());
                        }

                        m_state = ReceiveState.Initialize;

                        if ((m_base.m_header.m_flags & Flags.c_NonCritical) == 0)
                        {
                            IncomingMessage.ReplyBadPacket(m_parent, Flags.c_BadHeader);
                        }

                        break;

                    case ReceiveState.ReadingPayload:
                        count = m_raw.m_payload.Length - m_rawPos;

                        bytesRead = m_parent.Read(m_raw.m_payload, m_rawPos, count);

                        m_rawPos += bytesRead;

                        if (bytesRead != count)
                        {
                            break;
                        }

                        m_state = ReceiveState.CompletePayload;
                        goto case ReceiveState.CompletePayload;

                    case ReceiveState.CompletePayload:
                        if (VerifyPayload() == true)
                        {
                            try
                            {
                                bool fReply = (m_base.m_header.m_flags & Flags.c_Reply) != 0;

                                if ((m_base.m_header.m_flags & Flags.c_NACK) != 0)
                                {
                                    m_raw.m_payload = null;
                                }

                                m_parent.App.ProcessMessage(this.GetCompleteMessage(), fReply);

                                m_state = ReceiveState.Initialize;
                                return;
                            }
                            catch (ThreadAbortException)
                            {
                                throw;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Fault at payload deserialization:\n\n{0}", e.ToString());
                            }
                        }

                        m_state = ReceiveState.Initialize;

                        if ((m_base.m_header.m_flags & Flags.c_NonCritical) == 0)
                        {
                            IncomingMessage.ReplyBadPacket(m_parent, Flags.c_BadPayload);
                        }

                        break;
                    }
                }
                catch
                {
                    m_state = ReceiveState.Initialize;
                    throw;
                }
            }
Ejemplo n.º 24
0
        internal OutgoingMessage( IncomingMessage req, Converter converter, uint flags, object payload )
        {
            InitializeForSend( req.Parent, converter, req.Header.m_cmd, flags, payload );

            m_base.m_header.m_seqReply  = req.Header.m_seq;
            m_base.m_header.m_flags    |= Flags.c_Reply;

            UpdateCRC( converter );
        }
Ejemplo n.º 25
0
 internal void QueueRpc( IncomingMessage msg )
 {
     m_rpcQueue.Add( msg );
     m_rpcEvent.Set( );
 }
Ejemplo n.º 26
0
 private void OnWPCommand(IncomingMessage msg, bool fReply)
 {
     switch (msg.Header.m_cmd)
     {
         case Commands.c_Monitor_ProgramExit:
             if (m_session != null)
             {
                 m_session.OnDisconnect += SoftDisconnectDone;
                 m_session.Disconnect();
             }
             break;
     }
 }
Ejemplo n.º 27
0
        private void RpcReceiveQuery( IncomingMessage msg, Commands.Debugging_Messaging_Query query )
        {
            Commands.Debugging_Messaging_Address addr = query.m_addr;
            EndPointRegistration eep = RpcFind( addr.m_to_Type, addr.m_to_Id, true );

            Commands.Debugging_Messaging_Query.Reply res = new Commands.Debugging_Messaging_Query.Reply( );

            res.m_found = ( eep != null ) ? 1u : 0u;
            res.m_addr = addr;

            msg.Reply( CreateConverter( ), Flags.c_NonCritical, res );
        }
Ejemplo n.º 28
0
        private void RpcReceiveSend( IncomingMessage msg, Commands.Debugging_Messaging_Send send )
        {
            Commands.Debugging_Messaging_Address addr = send.m_addr;
            EndPointRegistration eep;

            eep = RpcFind( addr.m_to_Type, addr.m_to_Id, true );

            Commands.Debugging_Messaging_Send.Reply res = new Commands.Debugging_Messaging_Send.Reply( );

            res.m_found = ( eep != null ) ? 1u : 0u;
            res.m_addr = addr;

            msg.Reply( CreateConverter( ), Flags.c_NonCritical, res );

            if( eep != null )
            {
                Message msgNew = new Message( eep.m_ep, addr, send.m_data );

                EndPointRegistration.InboundRequest ir = new EndPointRegistration.InboundRequest( eep, msgNew );

                ThreadPool.QueueUserWorkItem( new WaitCallback( RpcReceiveSendDispatch ), ir );
            }
        }
Ejemplo n.º 29
0
        private void RpcReceiveReply( IncomingMessage msg, Commands.Debugging_Messaging_Reply reply )
        {
            Commands.Debugging_Messaging_Address addr = reply.m_addr;
            EndPointRegistration eep;

            eep = RpcFind( addr.m_from_Type, addr.m_from_Id, false );

            Commands.Debugging_Messaging_Reply.Reply res = new Commands.Debugging_Messaging_Reply.Reply( );

            res.m_found = ( eep != null ) ? 1u : 0u;
            res.m_addr = addr;

            msg.Reply( CreateConverter( ), Flags.c_NonCritical, res );

            if( eep != null )
            {
                lock( eep.m_req_Outbound.SyncRoot )
                {
                    foreach( EndPointRegistration.OutboundRequest or in eep.m_req_Outbound )
                    {
                        if( or.Seq == addr.m_seq && or.Type == addr.m_to_Type && or.Id == addr.m_to_Id )
                        {
                            or.Reply = reply.m_data;

                            break;
                        }
                    }
                }
            }
        }
            internal void Signal(WireProtocol.IncomingMessage res)
            {
                lock (this)
                {
                    if (m_timer != null)
                    {
                        m_timer.Dispose();

                        m_timer = null;
                    }

                    m_res = res;
                }

                Signal();
            }
Ejemplo n.º 31
0
        public async Task <bool> ProcessMessage(IncomingMessage msg, bool fReply)
        {
            msg.Payload = Commands.ResolveCommandToPayload(msg.Header.m_cmd, fReply, m_parent.Capabilities);

            if (fReply == true)
            {
                Request reply = null;

                if (request.MatchesReply(msg))
                {
                    reply = request;

                    // FIXME: check if this return can happen here without the QueueNotify call bellow
                    return(true);
                }
                else
                if (reply != null)
                {
                    // FIXME
                    reply.Signal(msg);
                    return(true);
                }
            }
            else
            {
                Packet bp = msg.Header;

                switch (bp.m_cmd)
                {
                case Commands.c_Monitor_Ping:
                {
                    Commands.Monitor_Ping.Reply cmdReply = new Commands.Monitor_Ping.Reply();

                    cmdReply.m_source = Commands.Monitor_Ping.c_Ping_Source_Host;

                    // FIXME
                    //cmdReply.m_dbg_flags = (m_stopDebuggerOnConnect ? Commands.Monitor_Ping.c_Ping_DbgFlag_Stop : 0);

                    await msg.ReplyAsync(m_parent.CreateConverter(), Flags.c_NonCritical, cmdReply).ConfigureAwait(false);

                    //m_evtPing.Set();

                    return(true);
                }

                case Commands.c_Monitor_Message:
                {
                    Commands.Monitor_Message payload = msg.Payload as Commands.Monitor_Message;

                    Debug.Assert(payload != null);

                    if (payload != null)
                    {
                        // FIXME
                        //QueueNotify(m_eventMessage, msg, payload.ToString());
                    }

                    return(true);
                }

                case Commands.c_Debugging_Messaging_Query:
                case Commands.c_Debugging_Messaging_Reply:
                case Commands.c_Debugging_Messaging_Send:
                {
                    Debug.Assert(msg.Payload != null);

                    if (msg.Payload != null)
                    {
                        // FIXME
                        //QueueRpc(msg);
                    }

                    return(true);
                }
                }
            }

            // FIXME
            //if (m_eventCommand != null)
            //{
            //    QueueNotify(m_eventCommand, msg, fReply);
            //    return true;
            //}

            return(false);
        }