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

SmartDeviceClient/SmartProtocolStack/IPMapper.cs

00001 using System;
00002 using System.Net;
00003 using System.Collections;
00004 
00005 namespace GPRSWeb.SmartDeviceClient.SmartProtocolStack
00006 {
00007         public class IPMapper : System.Collections.Specialized.ListDictionary {
00008                 StackInterface thisStack;
00009 
00010                 public IPMapper(StackInterface thisStack) : base() {
00011                         this.thisStack = thisStack;
00012                         // add server IP address
00013                         AddDefaultServerIP();
00014                         // add client IP address
00015                         AddDefaultClientIP();
00016                 } 
00017 
00021                 protected void AddDefaultServerIP() {
00022                         IPAddress serverIP = thisStack.settings.ServerIP;
00023                         thisStack.msgLog.Log("Server IP Address is {0}", serverIP.ToString());
00024                         this.AddMapping(0, serverIP);
00025                 }
00026 
00030                 protected void AddDefaultClientIP() {
00031                         IPAddress defaultAddress = thisStack.settings.ClientIP;
00032                         Console.Write("GPRS Phone (Client) Address is {0}", defaultAddress.ToString());
00033                         this.AddMapping(1, defaultAddress); 
00034                 }
00035                         
00041                 public IPAddress Lookup(ushort deviceID) {
00042                         if (Contains(deviceID)) {
00043                                 return (IPAddress)this[deviceID];
00044                         } else {
00045                                 throw new ApplicationException(String.Format("IP Mapping for Device {0} not found", deviceID));
00046                         }
00047                 }
00048 
00049                 public void AddMapping(ushort deviceID, IPAddress ipAddress) {
00050                         try {
00051                                 this[deviceID] = ipAddress; // this way we update any old mappings
00052                         } catch (Exception ex) {
00053                                 throw new ApplicationException("Unable to Add mapping to IP Mapper\n\r" + ex.ToString());
00054                         }
00055                 }
00056         }
00057 }

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