Collage
0.6.1
|
00001 00002 /* Copyright (c) 2005-2012, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 2010, Cedric Stalder <cedric.stalder@gmail.com> 00004 * 00005 * This library is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Lesser General Public License version 2.1 as published 00007 * by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this library; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00017 */ 00018 00019 #ifndef CO_PACKETS_H 00020 #define CO_PACKETS_H 00021 00022 #include <co/commands.h> // used for CMD_ enums 00023 #include <co/types.h> 00024 #include <co/version.h> // enum 00025 #include <lunchbox/uuid.h> // member 00026 00027 namespace co 00028 { 00029 enum PacketType 00030 { 00031 PACKETTYPE_CO_NODE, 00032 PACKETTYPE_CO_OBJECT, 00033 PACKETTYPE_CO_CUSTOM = 1<<7 00034 }; 00035 00037 struct Packet 00038 { 00039 uint64_t size; 00040 uint32_t type; 00041 uint32_t command; 00042 00043 #if 0 00044 union 00045 { 00046 Foo foo; 00047 uint64_t paddingPacket; // pad to multiple-of-8 00048 }; 00049 #endif 00050 00051 static size_t minSize; 00052 bool exceedsMinSize() const { return (size > minSize); } 00053 }; 00054 00055 // String transmission: the packets define a 8-char string at the end of the 00056 // packet. When the packet is sent using Node::send( Packet&, string& ), the 00057 // whole string is appended to the packet, so that the receiver has to do 00058 // nothing special to receive and use the full packet. 00059 00061 struct NodePacket: public Packet 00062 { 00063 NodePacket() { type = PACKETTYPE_CO_NODE; } 00064 }; 00065 00067 struct NodeCommandPacket : public NodePacket 00068 { 00069 NodeCommandPacket() 00070 { 00071 command = CMD_NODE_COMMAND; 00072 size = sizeof( NodeCommandPacket ); 00073 } 00074 uint128_t commandID; 00075 }; 00076 00078 struct ObjectPacket : public NodePacket 00079 { 00080 ObjectPacket() 00081 : instanceID( EQ_INSTANCE_ALL ) 00082 , pad( 0 ) // valgrind: write points to uninitialised byte(s) 00083 { 00084 type = PACKETTYPE_CO_OBJECT; 00085 } 00086 UUID objectID; 00087 uint32_t instanceID; 00088 const uint32_t pad; // pad to multiple-of-eight 00089 00090 private: 00091 ObjectPacket& operator= ( ObjectPacket const& ); 00092 }; 00093 00094 //------------------------------------------------------------ 00095 // ostream operators 00096 //------------------------------------------------------------ 00097 inline std::ostream& operator << ( std::ostream& os, 00098 const Packet* packet ) 00099 { 00100 os << "packet dt " << packet->type << " cmd " 00101 << packet->command; 00102 return os; 00103 } 00104 inline std::ostream& operator << ( std::ostream& os, 00105 const NodePacket* packet ) 00106 { 00107 os << (Packet*)packet; 00108 return os; 00109 } 00110 inline std::ostream& operator << ( std::ostream& os, 00111 const ObjectPacket* packet ) 00112 { 00113 os << (NodePacket*)packet << " object " << packet->objectID 00114 << "." << packet->instanceID; 00115 return os; 00116 } 00117 } 00118 00119 #endif // CO_PACKETS_H 00120