Equalizer 1.0

co/packets.h

00001 
00002 /* Copyright (c) 2005-2011, 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 
00026 namespace co
00027 {
00028     enum PacketType
00029     {
00030         PACKETTYPE_CO_NODE,
00031         PACKETTYPE_CO_OBJECT,
00032         PACKETTYPE_CO_CUSTOM = 1<<7
00033     };
00034 
00036     struct Packet
00037     {
00038         uint64_t size; 
00039         uint32_t type; 
00040         uint32_t command; 
00041         
00042 #if 0
00043         union
00044         {
00045             Foo foo;
00046             uint64_t paddingPacket; // pad to multiple-of-8
00047         };
00048 #endif
00049 
00050         static size_t minSize;
00051         bool exceedsMinSize() const { return (size > minSize); }
00052     };
00053 
00054     // String transmission: the packets define a 8-char string at the end of the
00055     // packet. When the packet is sent using Node::send( Packet&, string& ), the
00056     // whole string is appended to the packet, so that the receiver has to do
00057     // nothing special to receive and use the full packet.
00058 
00060     struct NodePacket: public Packet
00061     {
00062         NodePacket(){ type = PACKETTYPE_CO_NODE; }
00063     };
00064 
00066     struct ObjectPacket : public NodePacket
00067     {
00068         ObjectPacket()
00069                 : instanceID( EQ_INSTANCE_ALL )
00070 #ifndef NDEBUG
00071                 , pad( 0 ) // valgrind: write points to uninitialised byte(s)
00072 #endif
00073             {
00074                 type = PACKETTYPE_CO_OBJECT; 
00075             }
00076         base::UUID objectID;
00077         uint32_t instanceID;
00078         uint32_t pad; // pad to multiple-of-eight
00079     };
00080 
00081     //------------------------------------------------------------
00082     // ostream operators
00083     //------------------------------------------------------------
00084     inline std::ostream& operator << ( std::ostream& os, 
00085                                        const Packet* packet )
00086     {
00087         os << "packet dt " << packet->type << " cmd "
00088            << packet->command;
00089         return os;
00090     }
00091     inline std::ostream& operator << ( std::ostream& os, 
00092                                        const NodePacket* packet )
00093     {
00094         os << (Packet*)packet;
00095         return os;
00096     }
00097     inline std::ostream& operator << ( std::ostream& os, 
00098                                        const ObjectPacket* packet )
00099     {
00100         os << (NodePacket*)packet << " object " << packet->objectID
00101            << "." << packet->instanceID;
00102         return os;
00103     }
00104 }
00105 
00106 #endif // CO_PACKETS_H
00107 
Generated on Sun May 8 2011 19:11:07 for Equalizer 1.0 by  doxygen 1.7.3