Example #1
0
        private void ProcessPacket()
        {
            //int pointer=0;
            switch (packet[0])
            {
            case (byte)RemoteProtocolMsgs.GETMATRIX:
                int loc  = BitConverter.ToInt32(packet, 1);
                int blen = Buffer.ByteLength(localprocessor.currentcode.matrixmemory[loc].m_MatArr);
                packet = new byte[17 + blen];

                packet[4] = (byte)RemoteProtocolMsgs.RECIEVEMATRIX;
                Buffer.BlockCopy(BitConverter.GetBytes(packet.Length - 4), 0, packet, 0, 4);
                Buffer.BlockCopy(BitConverter.GetBytes(loc), 0, packet, 5, 4);
                Buffer.BlockCopy(BitConverter.GetBytes(localprocessor.currentcode.matrixmemory[loc].Rows), 0, packet, 9, 4);
                Buffer.BlockCopy(BitConverter.GetBytes(localprocessor.currentcode.matrixmemory[loc].Columns), 0, packet, 13, 4);
                Buffer.BlockCopy(localprocessor.currentcode.matrixmemory[loc].m_MatArr, 0, packet, 17, blen);
                mystream.Write(packet, 0, packet.Length);
                break;

            case (byte)RemoteProtocolMsgs.END:
                ProcessResponse();
                state = RemoteProcessorStates.BLOCKED;
                break;

            case (byte)RemoteProtocolMsgs.ERROR:
                ProcessError();
                state = RemoteProcessorStates.BLOCKED;
                break;
            }
        }
Example #2
0
        public void ThreadProc()
        {
            while (state != RemoteProcessorStates.STOP)
            {
                try
                {
                    switch (state)
                    {
                    case RemoteProcessorStates.WAITING:
                        try
                        {
                            RecievePacket();
                        }
                        catch (Exception exc)
                        {
                            //System.Windows.Forms.MessageBox.Show(exc.Message);
                            localprocessor.raiseerror("One or more remote processors are failed.Error Detail - " + exc.Message);
                            state = RemoteProcessorStates.STOP;
                        }
                        break;

                    case RemoteProcessorStates.BLOCKED:
                        //Console.WriteLine("Blocking - {0}",joinflag);
                        if (joinflag)
                        {
                            joinflag = false;
                            joinedthread.Resume();
                            joinedthread = null;
                        }
                        //Console.WriteLine("Blocking - Endd {0}",joinflag);
                        if (state == RemoteProcessorStates.BLOCKED)
                        {
                            Thread.Sleep(Timeout.Infinite);
                        }
                        break;

                    case RemoteProcessorStates.RUNNING:
                        try
                        {
                            ProcessRequest();
                        }
                        catch (Exception exc)
                        {
                            //System.Windows.Forms.MessageBox.Show(exc.Message);
                            localprocessor.raiseerror(exc.Message);
                            state = RemoteProcessorStates.STOP;
                        }
                        break;
                    }
                }
                catch (ThreadInterruptedException e) {
                }
            }
            if (joinflag)
            {
                joinflag = false;
                joinedthread.Resume();
                joinedthread = null;
            }
        }
Example #3
0
 public void Proccess()
 {
     //this.localprocessor.currentcode = localprocessor.currentcode;
     //RemoteProcessorStates tmp = state;
     state = RemoteProcessorStates.RUNNING;
     //while(thread.ThreadState == ThreadState.Suspended)
     //{
     //try
     //{
     //Console.WriteLine(thread.ThreadState.ToString());
     thread.Interrupt();
     //}
     //catch(ThreadStateException e)
     //{
     //Console.WriteLine("Not User Suspended -- " + thread.ThreadState.ToString());
     //}
     //}
 }
Example #4
0
        private void ProcessRequest()
        {
            int tmp = ((mthread.endthread - mthread.inspointer) + 1);

            packet = new byte[100 + tmp * 2];

            packet[4] = (byte)RemoteProtocolMsgs.START;

            Buffer.BlockCopy(BitConverter.GetBytes(tmp), 0, packet, 5, 4);
            Buffer.BlockCopy(localprocessor.currentcode.instructions, mthread.inspointer * 2, packet, 9, tmp * 2);
            int offset = 9 + tmp * 2;

            FillMemoryData(ref offset);
            Buffer.BlockCopy(BitConverter.GetBytes(offset - 4), 0, packet, 0, 4);
            mystream.Write(packet, 0, offset);

            state = RemoteProcessorStates.WAITING;
            //		RecievePacket();
        }
 public void Proccess()
 {
     //this.localprocessor.currentcode = localprocessor.currentcode;
     //RemoteProcessorStates tmp = state;
     state=RemoteProcessorStates.RUNNING;
     //while(thread.ThreadState == ThreadState.Suspended)
     //{
         //try
         //{
             //Console.WriteLine(thread.ThreadState.ToString());
             thread.Interrupt();
         //}
         //catch(ThreadStateException e)
         //{
             //Console.WriteLine("Not User Suspended -- " + thread.ThreadState.ToString());
         //}
     //}
 }
 public RemoteProcessor()
 {
     mthread = new ProgramThread();
     state = RemoteProcessorStates.STOP;
 }
        private void ProcessRequest()
        {
            int tmp =((mthread.endthread-mthread.inspointer)+1);
            packet = new byte[100+tmp*2];

            packet[4] = (byte)RemoteProtocolMsgs.START;

            Buffer.BlockCopy(BitConverter.GetBytes(tmp),0,packet,5,4);
            Buffer.BlockCopy(localprocessor.currentcode.instructions,mthread.inspointer*2,packet,9,tmp*2);
            int offset = 9+tmp*2;
            FillMemoryData(ref offset);
            Buffer.BlockCopy(BitConverter.GetBytes(offset-4),0,packet,0,4);
            mystream.Write(packet,0,offset);

            state = RemoteProcessorStates.WAITING;
            //		RecievePacket();
        }
        private void ProcessPacket()
        {
            //int pointer=0;
            switch(packet[0])
            {
                case (byte)RemoteProtocolMsgs.GETMATRIX:
                    int loc = BitConverter.ToInt32(packet,1);
                    int blen = Buffer.ByteLength(localprocessor.currentcode.matrixmemory[loc].m_MatArr);
                    packet = new byte[17+blen];

                    packet[4] = (byte)RemoteProtocolMsgs.RECIEVEMATRIX;
                    Buffer.BlockCopy(BitConverter.GetBytes(packet.Length-4),0,packet,0,4);
                    Buffer.BlockCopy(BitConverter.GetBytes(loc),0,packet,5,4);
                    Buffer.BlockCopy(BitConverter.GetBytes(localprocessor.currentcode.matrixmemory[loc].Rows),0,packet,9,4);
                    Buffer.BlockCopy(BitConverter.GetBytes(localprocessor.currentcode.matrixmemory[loc].Columns),0,packet,13,4);
                    Buffer.BlockCopy(localprocessor.currentcode.matrixmemory[loc].m_MatArr,0,packet,17,blen);
                    mystream.Write(packet,0,packet.Length);
                    break;
                case (byte)RemoteProtocolMsgs.END:
                    ProcessResponse();
                    state = RemoteProcessorStates.BLOCKED;
                    break;
                case (byte)RemoteProtocolMsgs.ERROR:
                    ProcessError();
                    state = RemoteProcessorStates.BLOCKED;
                    break;

            }
        }
        public void ThreadProc()
        {
            while(state != RemoteProcessorStates.STOP)
            {
                try
                {
                    switch(state)
                    {

                        case RemoteProcessorStates.WAITING:
                            try
                            {
                                RecievePacket();
                            }
                            catch(Exception exc)
                            {
                                //System.Windows.Forms.MessageBox.Show(exc.Message);
                                localprocessor.raiseerror("One or more remote processors are failed.Error Detail - " + exc.Message );
                                state=RemoteProcessorStates.STOP;
                            }
                            break;

                        case RemoteProcessorStates.BLOCKED:
                            //Console.WriteLine("Blocking - {0}",joinflag);
                            if(joinflag)
                            {
                                joinflag = false;
                                joinedthread.Resume();
                                joinedthread = null;
                            }
                            //Console.WriteLine("Blocking - Endd {0}",joinflag);
                            if(state==RemoteProcessorStates.BLOCKED)Thread.Sleep(Timeout.Infinite);
                            break;

                        case RemoteProcessorStates.RUNNING:
                            try
                            {
                                ProcessRequest();
                            }
                            catch(Exception exc)
                            {
                                //System.Windows.Forms.MessageBox.Show(exc.Message);
                                localprocessor.raiseerror(exc.Message);
                                state=RemoteProcessorStates.STOP;
                            }
                            break;

                    }
                }
                catch(ThreadInterruptedException e){

                }
            }
            if(joinflag)
            {
                joinflag = false;
                joinedthread.Resume();
                joinedthread = null;
            }
        }
 public void StopProcessor()
 {
     state=RemoteProcessorStates.STOP;
     thread.Interrupt();
 }
 public void StartProcessor()
 {
     thread = new Thread(new ThreadStart(this.ThreadProc));
     state= RemoteProcessorStates.BLOCKED;
     thread.Start();
 }
Example #12
0
 public void StopProcessor()
 {
     state = RemoteProcessorStates.STOP;
     thread.Interrupt();
 }
Example #13
0
 public void StartProcessor()
 {
     thread = new Thread(new ThreadStart(this.ThreadProc));
     state  = RemoteProcessorStates.BLOCKED;
     thread.Start();
 }
Example #14
0
 public RemoteProcessor()
 {
     mthread = new ProgramThread();
     state   = RemoteProcessorStates.STOP;
 }