2003-11-07 23:38:18 +00:00
|
|
|
// message.hxx -- Multiplayer Client/Server message base class
|
|
|
|
//
|
|
|
|
// Written by John Barrett, started November 2003.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _FG_MPS_MESSAGE_HXX
|
|
|
|
#define _FG_MPS_MESSAGE_HXX
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
|
|
|
#include STL_STRING
|
|
|
|
#include <stdexcept>
|
2003-11-08 20:11:14 +00:00
|
|
|
#include <map>
|
2003-11-07 23:38:18 +00:00
|
|
|
|
|
|
|
SG_USING_STD(string);
|
|
|
|
SG_USING_STD(invalid_argument);
|
2003-11-08 20:11:14 +00:00
|
|
|
SG_USING_STD(map);
|
2003-11-07 23:38:18 +00:00
|
|
|
|
|
|
|
#include "messagebuf.hxx"
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
fgmps_null = 0x00,
|
|
|
|
fgmps_uchar = 0xf0,
|
|
|
|
fgmps_uint = 0xf1,
|
|
|
|
fgmps_ulong = 0xf2,
|
|
|
|
fgmps_ulonglong = 0xf3,
|
|
|
|
fgmps_char = 0xf4,
|
|
|
|
fgmps_int = 0xf5,
|
|
|
|
fgmps_long = 0xf6,
|
|
|
|
fgmps_longlong = 0xf7,
|
|
|
|
fgmps_float = 0xf8,
|
|
|
|
fgmps_double = 0xf9,
|
|
|
|
fgmps_string = 0xfa,
|
|
|
|
fgmps_reserved = 0xfb,
|
|
|
|
fgmps_eom = 0xfc,
|
|
|
|
fgmps_som8 = 0xfd,
|
|
|
|
fgmps_som16 = 0xfe,
|
|
|
|
fgmps_esc = 0xfe
|
|
|
|
} FGMPSMsgElementType;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
FGMPSMsgElementType type;
|
|
|
|
void * data;
|
|
|
|
} FGMPSMsgElementEntry;
|
|
|
|
|
|
|
|
#define FGMPSMsgElementArrayEnd {fgmps_null, 0}
|
|
|
|
|
2003-11-08 20:11:14 +00:00
|
|
|
class FGMPSMessage;
|
|
|
|
|
|
|
|
typedef FGMPSMessage* FGMPSMessagePtr;
|
|
|
|
typedef FGMPSMessagePtr (*FGMPSMsgInstanceFunc)(void);
|
|
|
|
|
|
|
|
typedef map<unsigned int, FGMPSMsgInstanceFunc> FGMPSInstanceFuncMap;
|
|
|
|
|
2003-11-07 23:38:18 +00:00
|
|
|
class FGMPSMessage
|
|
|
|
{
|
|
|
|
private:
|
2003-11-08 20:11:14 +00:00
|
|
|
static FGMPSInstanceFuncMap funcmap;
|
2003-11-07 23:38:18 +00:00
|
|
|
FGMPSMsgElementEntry elements[1];
|
|
|
|
protected:
|
2003-11-08 20:11:14 +00:00
|
|
|
FGMPSMessageBuf buf;
|
|
|
|
unsigned int msgid;
|
2003-11-07 23:38:18 +00:00
|
|
|
public:
|
2003-11-08 20:11:14 +00:00
|
|
|
static int registermsg(int msgid, FGMPSMsgInstanceFunc func)
|
|
|
|
{
|
|
|
|
funcmap[msgid] = func;
|
|
|
|
}
|
|
|
|
|
2003-11-07 23:38:18 +00:00
|
|
|
FGMPSMessage();
|
|
|
|
~FGMPSMessage() {}
|
|
|
|
|
2003-11-08 20:11:14 +00:00
|
|
|
string encodemsg();
|
|
|
|
static FGMPSMessage* decodemsg(string msg);
|
|
|
|
unsigned int getmessageid() { return msgid; }
|
2003-11-07 23:38:18 +00:00
|
|
|
|
2003-11-08 20:11:14 +00:00
|
|
|
virtual FGMPSMsgElementEntry* getelements() { return elements; }
|
2003-11-07 23:38:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|