]> git.mxchange.org Git - flightgear.git/blob - src/Server/message.hxx
Tune up the starter torque to match the recent changes to engine
[flightgear.git] / src / Server / message.hxx
1 // message.hxx -- Multiplayer Client/Server message base class\r
2 //\r
3 // Written by John Barrett, started November 2003.\r
4 //\r
5 // Copyright (C) 2003  John R. Barrett - jbarrett@accesshosting.com\r
6 //\r
7 // This program is free software; you can redistribute it and/or\r
8 // modify it under the terms of the GNU General Public License as\r
9 // published by the Free Software Foundation; either version 2 of the\r
10 // License, or (at your option) any later version.\r
11 //\r
12 // This program is distributed in the hope that it will be useful, but\r
13 // WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
15 // General Public License for more details.\r
16 //\r
17 // You should have received a copy of the GNU General Public License\r
18 // along with this program; if not, write to the Free Software\r
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
20 //\r
21 \r
22 \r
23 #ifndef _FG_MPS_MESSAGE_HXX\r
24 #define _FG_MPS_MESSAGE_HXX\r
25 \r
26 #include <simgear/compiler.h>\r
27 \r
28 #include STL_STRING\r
29 #include <stdexcept>\r
30 #include <map>\r
31 \r
32 SG_USING_STD(string);\r
33 SG_USING_STD(invalid_argument);\r
34 SG_USING_STD(map);\r
35 \r
36 #include "messagebuf.hxx"\r
37 \r
38 typedef enum \r
39 {\r
40         fgmps_null      = 0x00,\r
41         fgmps_uchar     = 0xf0,\r
42         fgmps_uint      = 0xf1,\r
43         fgmps_ulong     = 0xf2,\r
44         fgmps_ulonglong = 0xf3,\r
45         fgmps_char      = 0xf4,\r
46         fgmps_int       = 0xf5,\r
47         fgmps_long      = 0xf6,\r
48         fgmps_longlong  = 0xf7,\r
49         fgmps_float     = 0xf8,\r
50         fgmps_double    = 0xf9,\r
51         fgmps_string    = 0xfa,\r
52         fgmps_reserved  = 0xfb,\r
53         fgmps_eom       = 0xfc,\r
54         fgmps_som8      = 0xfd,\r
55         fgmps_som16     = 0xfe,\r
56         fgmps_esc       = 0xfe\r
57 } FGMPSMsgElementType;\r
58 \r
59 typedef struct \r
60 {\r
61         FGMPSMsgElementType     type;\r
62         void *                  data;\r
63 } FGMPSMsgElementEntry;\r
64 \r
65 #define FGMPSMsgElementArrayEnd {fgmps_null, 0}\r
66 \r
67 class FGMPSMessage;\r
68 \r
69 typedef FGMPSMessage* FGMPSMessagePtr;\r
70 typedef FGMPSMessagePtr (*FGMPSMsgInstanceFunc)(void);\r
71 \r
72 typedef map<unsigned int, FGMPSMsgInstanceFunc> FGMPSInstanceFuncMap;\r
73 \r
74 class FGMPSMessage\r
75 {\r
76 private:\r
77         static FGMPSInstanceFuncMap     funcmap;\r
78         FGMPSMsgElementEntry            elements[1];\r
79 protected:\r
80         FGMPSMessageBuf         buf;\r
81         unsigned int            msgid;\r
82 public:\r
83         static int registermsg(int msgid, FGMPSMsgInstanceFunc func)\r
84         {\r
85                 funcmap[msgid] = func;\r
86         }\r
87 \r
88         FGMPSMessage();\r
89         ~FGMPSMessage() {}\r
90 \r
91         string                  encodemsg();\r
92         static FGMPSMessage*    decodemsg(string msg);\r
93         unsigned int            getmessageid() { return msgid; }\r
94 \r
95         virtual FGMPSMsgElementEntry*   getelements() { return elements; }\r
96 };\r
97 \r
98 #endif\r