Пример #1
0
        public void addTextCommand(string command, CommandStruct.eMode mode, CommandStruct.CS_TextDelegate callback, object userData, Dispatcher dispatch)
        {
            CommandStruct cs = new CommandStruct
            {
                binary       = false,
                mode         = mode,
                textDelegate = callback,
                command      = command,
                userData     = userData,
                dispatch     = dispatch
            };

            mCommands.Add(cs);
        }
Пример #2
0
        public void addBinaryMemCommand(int start, int end, CommandStruct.CS_BinaryDelegate callback, object userData, Dispatcher dispatch)
        {
            // https://sourceforge.net/p/vice-emu/code/HEAD/tree/trunk/vice/src/monitor/monitor_network.c#l267

            byte[] sendCommand = new byte[5];

            sendCommand[0] = 0x1; // mem dump
            sendCommand[1] = (byte)(start & 255);
            sendCommand[2] = (byte)((start >> 8) & 255);
            sendCommand[3] = (byte)(end & 255);
            sendCommand[4] = (byte)((end >> 8) & 255);

            CommandStruct cs = new CommandStruct
            {
                binary         = true,
                mode           = CommandStruct.eMode.DoCommandReturnResults,
                binaryDelegate = callback,
                binaryParams   = sendCommand,
                userData       = userData,
                dispatch       = dispatch
            };

            mCommands.Add(cs);
        }
Пример #3
0
        private void BackgroundThread()
        {
            while (true)
            {
                try
                {
                    bool wasConnected = false;

                    if (mSocket == null)
                    {
                        mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                        mSocket.Blocking = false;
                    }

                    try
                    {
                        mSocket.Connect("localhost", 6510);
                    }
                    catch (System.Exception /*ex*/)
                    {
                    }

                    CommandStruct lastCommand = null;

                    while (mSocket.Connected)
                    {
                        if (mSocket.Poll(0, SelectMode.SelectError))
                        {
                            break;
                        }
                        wasConnected = true;
                        if (mCommands.Count > 0)
                        {
                            ConsumeData();
                            lastCommand = mCommands[0];
                            mCommands.RemoveAt(0);

                            if (lastCommand.binary == true)
                            {
                                // do binary here
                                byte[] response = sendBinaryCommand(lastCommand.binaryParams);
                                lastCommand.dispatch.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, lastCommand.binaryDelegate, response, lastCommand.userData);
                            }
                            else
                            { // string based
                                SendCommand(lastCommand.command);
                                switch (lastCommand.mode)
                                {
                                default:
                                case CommandStruct.eMode.DoCommandThrowAwayResults:
                                    GetReply();
                                    if (lastCommand.textDelegate != null)
                                    {
                                        lastCommand.dispatch.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, lastCommand.textDelegate, null, lastCommand.userData);
                                    }
                                    break;

                                case CommandStruct.eMode.DoCommandReturnResults:
                                    string reply = GetReply();
                                    lastCommand.dispatch.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, lastCommand.textDelegate, reply, lastCommand.userData);
                                    break;

                                case CommandStruct.eMode.DoCommandThenExit:
                                    GetReply();
                                    SendCommand("x");
                                    break;

                                case CommandStruct.eMode.DoCommandOnly:
                                    ConsumeData();
                                    break;     //don't a single thing

                                case CommandStruct.eMode.DoCommandFireCallback:
                                    if (lastCommand.textDelegate != null)
                                    {
                                        lastCommand.dispatch.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, lastCommand.textDelegate, null, lastCommand.userData);
                                    }
                                    break;
                                }
                            }

                            /*
                             *
                             * if (gotText.Length > 0)
                             * {
                             *  gotText = gotText.Replace("\n", "\r");
                             *  this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new OneArgDelegate(SetSourceView), gotText);
                             * }*/
                        }
                        else
                        {
                            Thread.Sleep(100);
                            if (mSocket.Available > 0)
                            {
                                //mNeedNewMemoryDump = true;
                                // This happens if a break/watch point is hit, then a reply is received without any command being sent
                                string theReply = GetReply();
                                //gotText += theReply;
                                //								this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new OneArgDelegate(SetSourceView), gotText);
                                mErrorDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, mVICEMsg, theReply);
                            }
                        }
                    } //< while (mSocket.Connected)

                    if (wasConnected)
                    {
                        // Only if it was connected the dispose and try again
                        if (mSocket != null)
                        {
                            mSocket.Dispose();
                            mSocket = null;
                            mErrorDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, mErrorCallback, "Not connected");
                        }
                    }

                    Thread.Sleep(250);
                }
                catch (System.Exception /*ex*/)
                {
                    mErrorDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, mErrorCallback, "Exception. Not connected");
                    if (mSocket != null)
                    {
                        mSocket.Dispose();
                        mSocket = null;
                    }
                    Thread.Sleep(250);
                }
            }
        }