Equalizer  1.2.1
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                 , pad( 0 ) // valgrind: write points to uninitialised byte(s)
00071             {
00072                 type = PACKETTYPE_CO_OBJECT; 
00073             }
00074         base::UUID objectID;
00075         uint32_t instanceID;
00076         const uint32_t pad; // pad to multiple-of-eight
00077 
00078     private:
00079         ObjectPacket& operator= ( ObjectPacket const& );
00080     };
00081 
00082     //------------------------------------------------------------
00083     // ostream operators
00084     //------------------------------------------------------------
00085     inline std::ostream& operator << ( std::ostream& os, 
00086                                        const Packet* packet )
00087     {
00088         os << "packet dt " << packet->type << " cmd "
00089            << packet->command;
00090         return os;
00091     }
00092     inline std::ostream& operator << ( std::ostream& os, 
00093                                        const NodePacket* packet )
00094     {
00095         os << (Packet*)packet;
00096         return os;
00097     }
00098     inline std::ostream& operator << ( std::ostream& os, 
00099                                        const ObjectPacket* packet )
00100     {
00101         os << (NodePacket*)packet << " object " << packet->objectID
00102            << "." << packet->instanceID;
00103         return os;
00104     }
00105 }
00106 
00107 #endif // CO_PACKETS_H
00108 
Generated on Fri Jun 8 2012 15:44:32 for Equalizer 1.2.1 by  doxygen 1.8.0