00001 using System;
00002 using System.Collections;
00003
00004
00005 namespace ProtocolStack
00006 {
00011 public class RemoteHostComms {
00012 private ReceiveQueue incomingSegementQueue;
00013 private TransmissionQueue transmissionQueue;
00014 private SegmentTransmitter segmentTransmitter;
00015 private NACKManager nackManager;
00016 private ACKManager ackManager;
00017 private SequenceManager sequenceManager;
00018 private RateManager rateManager;
00019 private MessageAssembly messageAssembly;
00020 private RetransmissionBuffer retransmissionBuffer;
00021 internal StackInterface thisStack;
00022
00023 internal bool readyToSendUserData;
00024
00025 public RemoteHostComms(StackInterface thisStack, ushort remoteDeviceID) {
00026 this.thisStack = thisStack;
00027 RemoteDeviceID = remoteDeviceID;
00028 incomingSegementQueue = new ReceiveQueue(this);
00029 transmissionQueue = new TransmissionQueue();
00030 segmentTransmitter = new SegmentTransmitter(this);
00031 nackManager = new NACKManager(this);
00032 ackManager = new ACKManager(this);
00033 sequenceManager = new SequenceManager(nackManager);
00034 rateManager = new RateManager(this);
00035 retransmissionBuffer = new RetransmissionBuffer(sequenceManager);
00036 messageAssembly = new MessageAssembly(this);
00037 }
00038
00039 private int remoteDeviceID = -1;
00040
00044 public void Start() {
00045 Console.WriteLine("Starting Remote Host Comms with remote host {0} ...", remoteDeviceID);
00046 readyToSendUserData = false;
00047 messageAssembly.Start();
00048 incomingSegementQueue.Start();
00049 segmentTransmitter.Start();
00050 ackManager.StartAckableGenerator();
00051 Console.WriteLine("... Remote Host Comms with remote host {0} Started", remoteDeviceID);
00052 }
00053
00054 public void Stop() {
00055 Console.WriteLine("Stopping Remote Host Comms with remote host {0} ...", remoteDeviceID);
00056 ackManager.StopAckableGenerator();
00057 segmentTransmitter.Stop();
00058 incomingSegementQueue.Stop();
00059 messageAssembly.Stop();
00060 Console.WriteLine("... Remote Host Comms with remote host {0} Stopped", remoteDeviceID);
00061 }
00062
00063 public void ResetConnection() {
00064 Console.WriteLine("Reseting Remote Host Comms with remote host {0} ...", remoteDeviceID);
00065 readyToSendUserData = false;
00066 transmissionQueue.ResetConnection();
00067 nackManager.ResetConnections();
00068 ackManager.ResetConnection();
00069 sequenceManager.ResetConnection();
00070 rateManager.ResetConnection();
00071 retransmissionBuffer.ResetConnection();
00072 Console.WriteLine("... Remote Host Comms with remote host {0} Reset", remoteDeviceID);
00073 }
00074
00075 public ushort RemoteDeviceID {
00076 get { if (remoteDeviceID != -1) {
00077 return (ushort)remoteDeviceID;
00078 } else {
00079 throw new ApplicationException("Unable to return remote device ID - no remote device ID set");
00080 }
00081 }
00082 set { remoteDeviceID = value; }
00083 }
00084
00085 public void AcceptIncomingSegment(Segment incomingSegment) {
00086 incomingSegementQueue.EnqueueBlocking(incomingSegment);
00087 }
00088
00089
00091 public NACKManager NackManager {
00092 get { return nackManager; }
00093 set { nackManager = value; }
00094 }
00095
00096 public ACKManager AckManager {
00097 get { return ackManager; }
00098 set { ackManager = value; }
00099 }
00100
00101 public SequenceManager SeqManager {
00102 get { return sequenceManager; }
00103 set { sequenceManager = value; }
00104 }
00105
00106 public RateManager RateManager {
00107 get { return rateManager; }
00108 set { rateManager = value; }
00109 }
00110
00111
00112 public RetransmissionBuffer RetransmissionBuffer {
00113 get {return retransmissionBuffer; }
00114 set {retransmissionBuffer = value; }
00115 }
00116
00120 public TransmissionQueue TxQueue {
00121 get { return transmissionQueue; }
00122 set { transmissionQueue = value; }
00123 }
00124
00125 public MessageAssembly MessageAssembler {
00126 get { return messageAssembly; }
00127 set { messageAssembly = value; }
00128 }
00129
00130
00131
00132
00133 }
00134 }