00001 using System;
00002 using System.Threading;
00003 using System.Collections;
00004 using GPRSWeb.SmartDeviceClient.Common;
00005
00006 namespace GPRSWeb.SmartDeviceClient.SmartProtocolStack.RemoteHost
00007 {
00013 public class ReceiveQueue : Queue
00014 {
00016 RemoteHostComms thisRemoteHost;
00017 Segment workingSegment;
00018 Thread processingThread;
00019
00023 public ReceiveQueue(RemoteHostComms thisRemoteHost) : base() {
00024 this.thisRemoteHost = thisRemoteHost;
00025 }
00026
00027 public void EnqueueBlocking(Segment seg) {
00028 lock(SyncRoot) {
00029 base.Enqueue(seg);
00030 Monitor.PulseAll(SyncRoot);
00031 }
00032 }
00033
00034 public Segment DequeueBlocking() {
00035 Segment result;
00036 lock(SyncRoot) {
00037 while (Count == 0) {
00038 Monitor.Wait(SyncRoot);
00039 }
00040 result = (Segment)base.Dequeue();
00041 Monitor.PulseAll(SyncRoot);
00042 }
00043 return result;
00044 }
00045
00046 public void Start() {
00047 if (processingThread == null || !processingThread.IsAlive) {
00048 processingThread = new Thread(new ThreadStart(ProcessQueue));
00049 processingThread.Start();
00050 }
00051 }
00052
00053 public void Stop() {
00054 if (processingThread.IsAlive) {
00055 processingThread.Abort();
00056 processingThread.Join();
00057 }
00058 }
00059
00060
00064 void ProcessQueue() {
00065 while(true) {
00066 workingSegment = this.DequeueBlocking();
00067
00068 if (thisRemoteHost.SeqManager.IsProcessable(workingSegment.Headers)) {
00069 ProcessSegmentHeaders(workingSegment.Headers, workingSegment.Data.DataLength);
00070
00071 thisRemoteHost.MessageAssembler.Process(workingSegment);
00072 }
00073 }
00074 }
00075
00081 private void ProcessSegmentHeaders(SegmentHeaders myHeaders, uint dataLength) {
00082
00083 thisRemoteHost.SeqManager.ProcessReceivedSegmentHeaders(ref myHeaders);
00084
00085 thisRemoteHost.AckManager.ProcessReceivedSegmentHeaders(ref myHeaders);
00086
00087 thisRemoteHost.NackManager.ProcessReceivedSegmentHeaders(ref myHeaders);
00088
00089 thisRemoteHost.RateManager.ProcessReceivedSegmentHeaders(ref myHeaders, dataLength);
00090 }
00091 }
00092
00093
00094
00095 }