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

SmartDeviceGUIClient/Message.cs

00001 using System;
00002 using System.IO;
00003 
00004 namespace SmartDeviceGUIClient
00005 {
00009         public abstract class Message
00010         {
00015                 public Message(MessageType type, ushort destination, MessagePriority priority) {
00016                         this.Type = type;
00017                         this.Destination = destination;
00018                         this.Priority = priority;
00019                 }
00020 
00026                 public Message(MessageType type, ushort destination) : this(type, destination, MessagePriority.Normal) {}
00027 
00031                 public MessageType Type {
00032                         get { return type; }
00033                         set { type = value; }
00034                 }
00035                 protected MessageType type;
00036                 
00040                 public ushort Destination {
00041                         get { return destination; }
00042                         set { destination = value; }
00043                 }
00044                 private ushort destination;
00045 
00049                 public ushort Source {
00050                         get { return source; }
00051                         set { source = value; } 
00052                 }
00053                 private ushort source;
00054 
00058                 public MessagePriority Priority {
00059                         get { return priority; }
00060                         set { priority = value; }
00061                 }
00062                 private MessagePriority priority;
00063 
00068                 public abstract MemoryStream SerialiseData(); 
00069 
00074                 public abstract void DeserialiseData(Stream serialisedDataStream); 
00075 
00076                 public static MemoryStream SerialiseMessage(Message msg) {
00077                         MemoryStream result = new MemoryStream();
00078                         result.Write(new byte[] {(byte)msg.Type}, 0, 1);
00079                         msg.SerialiseData().WriteTo(result);
00080                         return result;
00081                 }
00082 
00083                 public static Message DeserialiseMessage(Stream serialisedMessageStream /*, 'Mapping Table (from messageType to classname) */) {
00084                         int bBuffer = serialisedMessageStream.ReadByte();
00085                         if (bBuffer == -1) {
00086                                 // end of stream
00087                                 // TODO: Code for end of stream on deserialise message
00088                         } else {
00089                                 MessageType msgType= (MessageType)bBuffer;
00090                                 // TODO: Code for creating new message classes from the 'message type', possibly calling Reflection type things
00091                                 // May need a mapping table from type to classname
00092                         }
00093                         return null;
00094                 }
00095         }
00096 
00100         public enum MessageType : byte { 
00104                 Noop,
00108                 Retransmission,
00112                 String,
00116                 HTTPRequest,
00120                 HTTPResponse,
00124                 NoChange,
00128                 CacheIndex,
00132                 CacheUpdateNoChange,
00136                 CacheUpdateHTTPResponse,
00140                 Chunk,
00144                 CacheIndexRequest,
00145         }
00146 
00150         public enum MessagePriority {
00151                 Low,
00152                 Normal,
00153                 High // unused
00154         }
00155 }

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