command.cpp

00001 
00002 /* Copyright (c) 2006-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "command.h"
00019 
00020 #include "node.h"
00021 #include "packets.h"
00022 
00023 using namespace std;
00024 
00025 namespace eq
00026 {
00027 namespace net
00028 {
00029 
00030 Command::Command() 
00031   : _packet( 0 )
00032   , _packetAllocSize( 0 )
00033 {
00034 }
00035 
00036 Command::~Command() 
00037 {
00038     EQASSERTINFO( _refCount == 0, _refCount );
00039     _free(); 
00040 }
00041 
00042 void Command::alloc( NodePtr node, NodePtr localNode, const uint64_t size )
00043 {
00044     if( !_packet )
00045     {
00046         _packetAllocSize = EQ_MAX( Packet::minSize, size );
00047         _packet = static_cast<Packet*>( malloc( _packetAllocSize ));
00048     }
00049     else if( size > _packetAllocSize )
00050     {
00051         _packetAllocSize = EQ_MAX( Packet::minSize, size );
00052         free( _packet );
00053         _packet = static_cast<Packet*>( malloc( _packetAllocSize ));
00054     }
00055 
00056     _node         = node;
00057     _localNode    = localNode;
00058     _packet->size = size;
00059 }
00060 
00061 void Command::_free()
00062 {
00063     if( _packet )
00064         free( _packet );
00065 
00066     _packet    = 0;
00067     _node      = 0;
00068     _localNode = 0;
00069     _packetAllocSize = 0;
00070 }        
00071 
00072 EQ_EXPORT std::ostream& operator << ( std::ostream& os, const Command& command )
00073 {
00074     if( command.isValid( ))
00075     {
00076         os << base::disableFlush << "command< ";
00077         const Packet* packet = command.getPacket() ;
00078         switch( packet->datatype )
00079         {
00080             case DATATYPE_EQNET_SESSION:
00081                 os << static_cast< const SessionPacket* >( packet );
00082                 break;
00083 
00084             case DATATYPE_EQNET_OBJECT:
00085                 os << static_cast< const ObjectPacket* >( packet );
00086                 break;
00087 
00088             default:
00089                 os << packet;
00090         }
00091 
00092         os << ", " << command.getNode() << " >" << base::enableFlush;
00093     }
00094     else
00095         os << "command< empty >";
00096     
00097     return os;
00098 }
00099 }
00100 }
Generated on Mon Aug 10 18:58:31 2009 for Equalizer 0.9 by  doxygen 1.5.8