00001 /* 00002 * message.h 00003 * 00004 * Copyright (C) 2007,2008 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * 00031 * Game message objects. Any client/server message will be representable as a 00032 * message object. 00033 * 00034 * A aesop message is a serialized datahash (see the datahash_stream.h header in 00035 * the utility library). 00036 * 00037 * A aesop message must have a "header" subhash containing the namespace and 00038 * command. Then there must also be a "data" subhash containing the command 00039 * arguments. 00040 */ 00041 00042 #ifndef AESOP_AESOP_PROTO_MESSAGE_H__ 00043 #define AESOP_AESOP_PROTO_MESSAGE_H__ 00044 00045 // includes -------------------------------------------------------------------- 00046 #include "netlib/netlib.h" 00047 00048 00049 // forward declarations 00050 class Datahash; 00051 00052 00053 namespace aesop { 00054 00056 00059 00060 00061 struct tcp_payload_t { 00062 // constructor, manipulators 00063 tcp_payload_t(void) throw() { this->clear(); } 00064 void clear(void) throw() { 00065 namespace_.clear(); 00066 command.clear(); 00067 arguments = NULL; 00068 } 00069 bool is_empty(void) const throw() { 00070 return !arguments; 00071 } 00072 00073 // data fields 00074 std::string namespace_; 00075 std::string command; 00076 smart_ptr<Datahash> arguments; 00077 }; 00078 00079 00080 00082 void getTcpPayload(IN const char * data, 00083 OUT tcp_payload_t& payload); 00084 00085 00086 00087 }; // aesop namespace 00088 00089 #endif // AESOP_AESOP_PROTO_MESSAGE_H__ 00090