00001 using System;
00002 using System.Threading;
00003 using System.Collections;
00004 using Common;
00005
00006 namespace ProtocolStack
00007 {
00008
00012 public class OutgoingMessageQueue : MessageQueue {
00013 private DateTime lastTimestampUsed;
00014 private int lastOffsetUsed;
00015 private StackInterface thisStack;
00016 private Thread processingThread;
00017
00018 public OutgoingMessageQueue(StackInterface thisStack) : base() {
00019 this.thisStack = thisStack;
00020 }
00021
00022 public void Start() {
00023 if (processingThread == null || !processingThread.IsAlive) {
00024 lastTimestampUsed = DateTime.MinValue;
00025 lastOffsetUsed = 0;
00026 processingThread = new Thread(new ThreadStart(DemuxToTransmissionQueues));
00027 processingThread.Start();
00028 } else {
00029 Console.Error.WriteLine("*** \"Messages To Send\" Queue Processing thread already started ***");
00030 }
00031 }
00032
00033 public void Stop() {
00034 if (processingThread != null && processingThread.IsAlive) {
00035 processingThread.Abort();
00036 processingThread.Join();
00037 }
00038 }
00043 public void DemuxToTransmissionQueues() {
00044
00045 while (true) {
00046 Message workingMessage;
00047 workingMessage = DequeueBlocking();
00048
00049 try {
00050 if (workingMessage.isLowPriority) {
00051 Console.WriteLine("ProtocolStack: Sending Low Priority");
00052 MessageChunk[] chunks = MessageChunk.GetChunksFromMessage(workingMessage, ref lastTimestampUsed, ref lastOffsetUsed);
00053 foreach (MessageChunk chunk in chunks) {
00054 chunk.Destination = workingMessage.Destination;
00055 chunk.source = 0;
00056 thisStack.GetRemoteHostByID(chunk.Destination).TxQueue.Enqueue(TransmissionQueueEntry.FromMessage(chunk, true), true);
00057 }
00058 } else {
00059 thisStack.GetRemoteHostByID(workingMessage.Destination).TxQueue.Enqueue(TransmissionQueueEntry.FromMessage(workingMessage), false);
00060 }
00061 } catch (ApplicationException appEx) {
00062 Console.Error.WriteLine("*** Unable to send transmission queue object ***\n\n{0}\nSkipping and continuing...", appEx);
00063 }
00064 }
00065 }
00066 }
00067
00068 public class IncomingMessageQueue : Common.MessageQueue {
00069 private StackInterface thisStack;
00070
00071 public void ResetConnection() {
00072
00073 }
00074
00075 public IncomingMessageQueue(StackInterface thisStack) {
00076 this.thisStack = thisStack;
00077 }
00078
00079 }
00080
00081
00082
00083 }