Main Page | Class Hierarchy | Class List | File List | Class Members

ProtocolStack/StackInterface.cs

00001 using System;
00002 using System.Threading;
00003 using System.Collections;
00004 
00005 
00006 namespace ProtocolStack
00007 {
00008         public class StackInterface {
00009 
00010                 protected IncomingMessageQueue receivedMessages;
00015                 public IncomingMessageQueue ReceivedMessages {
00016                         get { return receivedMessages; }
00017                         set {receivedMessages = value; }
00018                 }
00023                 public OutgoingMessageQueue MessagesToSend {
00024                         get { return messagesToSend; }
00025                         set { messagesToSend = value; }
00026                 }
00027                 protected OutgoingMessageQueue messagesToSend;
00028 
00032                 internal SegmentReceiver segmentReceiver;
00036                 internal StackSettings settings;
00037                 public StackSettings Settings {
00038                         get { return settings; }
00039                         set { settings = value; }
00040                 }
00044                 protected Hashtable remoteHostList;
00045 
00046                 internal IPMapper ipMappings;
00047 
00048                 internal ConnectionResetDelegate connectionReset;
00049 
00054                 public StackInterface(ConnectionResetDelegate connectionReset) {
00055                         Console.WriteLine("\nInitialising GPRSWeb Protocol Stack (Version {0}, Build {1})\n\n", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(2), System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build);
00056                         this.connectionReset = connectionReset;
00057                         settings = new StackSettings();
00058                         messagesToSend = new OutgoingMessageQueue(this);
00059                         receivedMessages = new IncomingMessageQueue(this);
00060                         remoteHostList = new Hashtable();
00061                         segmentReceiver = new SegmentReceiver(this);
00062                         ipMappings = new IPMapper(this);
00063                         AddDefaultRemoteHostTEMP();
00064 
00065                 }
00066 
00070                 public void ResetConnection() {
00071                         Console.WriteLine("Reseting Protocol Stack ...");
00072                         Stop();
00073                         receivedMessages.ResetConnection();
00074                         foreach (DictionaryEntry de in remoteHostList) {
00075                                 ((RemoteHostComms)de.Value).ResetConnection();
00076                         }
00077                         Start();
00078                         Console.WriteLine("... Protocol Stack Reset");
00079                 }
00080 
00084                 public void Start() {
00085                         Console.WriteLine("Starting Protocol Stack ...");
00086             messagesToSend.Start();
00087                         foreach (DictionaryEntry de in remoteHostList) {
00088                                 ((RemoteHostComms)de.Value).Start();
00089                         }
00090                         segmentReceiver.Start();
00091                         Console.WriteLine("... Protocol Stack Started");
00092                 }
00093 
00097                 public void Stop() {
00098                         Console.WriteLine("Stopping Protocol Stack ...");
00099                         messagesToSend.Stop();
00100                         foreach (DictionaryEntry de in remoteHostList) {
00101                                 ((RemoteHostComms)de.Value).Stop();
00102                         }
00103                         segmentReceiver.Stop();
00104                         Console.WriteLine("... Protocol Stack Stopped");
00105                 }
00106 
00107                 internal void AddRemoteHost(RemoteHostComms remoteHost) {
00108                         remoteHostList.Add(remoteHost.RemoteDeviceID, remoteHost);
00109                 }
00110 
00111                 internal RemoteHostComms GetRemoteHostByID(ushort remoteID) {
00112                         RemoteHostComms result = (RemoteHostComms)remoteHostList[remoteID];
00113                         if (result == null) {
00114                                 throw new ApplicationException("Unable to find remote host communiation object for device " + remoteID);
00115                         }
00116                         return result;
00117                 }
00118 
00119                 private void AddDefaultRemoteHostTEMP() {
00120                         Console.WriteLine("### TODO: Better way of adding clients if we're the server ###");
00121                         if (settings.MyDeviceID == 0 /* SERVER */) {
00122                                 AddRemoteHost(new RemoteHostComms(this, 1));
00123                                 //AddRemoteHost(new RemoteHostComms(this, 2)); // if we're the server, add lots of clients
00124                         } else {
00125                                 AddRemoteHost(new RemoteHostComms(this, 0)); // else we're a client, so just add the server
00126                         }
00127                 }
00128         }
00129 
00130         
00131 }

Generated on Mon May 8 22:07:27 2006 by  doxygen 1.3.9.1