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 
00041     class Command 
00042     {
00043     public:
00044         Packet*       getPacket()              { return _packet; }
00045         const Packet* getPacket() const        { return _packet; }
00046 
00047         template< class P > P* getPacket()
00048             { EQASSERT( _packet ); return reinterpret_cast<P*>( _packet ); }
00049         template< class P > const P* getPacket() const
00050             { EQASSERT( _packet ); return reinterpret_cast<P*>( _packet ); }
00051 
00052         NodePtr getNode()      const { return _node; }
00053         NodePtr getLocalNode() const { return _localNode; }
00054 
00055         bool     operator ! () const     { return ( _packet==0 ); }
00056 
00057         Packet*       operator->()       { EQASSERT(_packet); return _packet; }
00058         const Packet* operator->() const { EQASSERT(_packet); return _packet; }
00059 
00062         bool isFree() const { return ( _refCount==0 ); }
00063         void retain()  { ++_refCount; }
00064         void release() 
00065             {
00066                 EQASSERT( _refCount != 0 );
00067 #ifdef NDEBUG
00068                 --_refCount;
00069 #else
00070                 if( --_refCount==0 )
00071                 {
00072                     // Unref nodes in command to keep node ref counts easier for
00073                     // debugging.  Release builds will unref the nodes at
00074                     // receiver thread exit.
00075                     _node = 0;
00076                     _localNode = 0;
00077                 }
00078 #endif
00079             }
00081 
00082         bool isValid() const { return ( _packet!=0 ); }
00083         uint64_t getAllocationSize() const { return _packetAllocSize; }
00084 
00085     private:
00086         Command();
00087         ~Command();
00088         void alloc( NodePtr node, NodePtr localNode, const uint64_t size );
00089         friend class CommandCache;
00090 
00091         Command& operator = ( Command& rhs ); // disable assignment
00092         Command( const Command& from );       // disable copy
00093 
00094         void _free();
00095 
00096         NodePtr  _node;
00097         NodePtr  _localNode;
00098         Packet*  _packet;
00099         base::mtLong _refCount;
00100         uint64_t _packetAllocSize;
00101     };
00102 
00103     EQ_EXPORT std::ostream& operator << ( std::ostream& os, const Command& );
00104 }
00105 }
00106 #endif // EQNET_COMMAND_H
Generated on Mon Aug 10 18:58:31 2009 for Equalizer 0.9 by  doxygen 1.5.8