command.h

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 #ifndef EQNET_COMMAND_H
00019 #define EQNET_COMMAND_H
00020 
00021 #include <eq/net/node.h> // NodePtr members
00022 
00023 #include <eq/base/base.h>
00024 #include <eq/base/refPtr.h>
00025 
00026 namespace eq
00027 {
00028 namespace net
00029 {    
00030     struct Packet;
00031 
00038     class Command 
00039     {
00040     public:
00041         Packet*       getPacket()              { return _packet; }
00042         const Packet* getPacket() const        { return _packet; }
00043 
00044         template< class P > P* getPacket()
00045             { EQASSERT( _packet ); return static_cast<P*>( _packet ); }
00046         template< class P > const P* getPacket() const
00047             { EQASSERT( _packet ); return static_cast<P*>( _packet ); }
00048 
00049         NodePtr getNode()      const { return _node; }
00050         NodePtr getLocalNode() const { return _localNode; }
00051 
00052         bool     operator ! () const     { return ( _packet==0 ); }
00053 
00054         Packet*       operator->()       { EQASSERT(_packet); return _packet; }
00055         const Packet* operator->() const { EQASSERT(_packet); return _packet; }
00056 
00059         bool isFree() const { return ( _refCount==0 ); }
00060         void retain()  { ++_refCount; }
00061         void release() 
00062             {
00063                 EQASSERT( _refCount != 0 );
00064 #ifdef NDEBUG
00065                 --_refCount;
00066 #else
00067                 if( --_refCount == 0 )
00068                 {
00069                     // Unref nodes in command to keep node ref counts easier for
00070                     // debugging.  Release builds will unref the nodes at
00071                     // receiver thread exit.
00072                     _node = 0;
00073                     _localNode = 0;
00074                 }
00075 #endif
00076             }
00078 
00079         bool isValid() const { return ( _packet!=0 ); }
00080         uint64_t getAllocationSize() const { return _packetAllocSize; }
00081 
00082     private:
00083         Command();
00084         ~Command();
00085         void alloc( NodePtr node, NodePtr localNode, const uint64_t size );
00086         friend class CommandCache;
00087 
00088         Command& operator = ( Command& rhs ); // disable assignment
00089         Command( const Command& from );       // disable copy
00090 
00091         void _free();
00092 
00093         NodePtr  _node;
00094         NodePtr  _localNode;
00095         Packet*  _packet;
00096         base::a_int32_t _refCount;
00097         uint64_t _packetAllocSize;
00098     };
00099 
00100     EQ_EXPORT std::ostream& operator << ( std::ostream& os, const Command& );
00101 }
00102 }
00103 #endif // EQNET_COMMAND_H
Generated on Sat Feb 6 12:59:46 2010 for Equalizer 0.9.1 by  doxygen 1.6.1