Equalizer  1.2.1
command.h
00001 
00002 /* Copyright (c) 2006-2011, 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 CO_COMMAND_H
00019 #define CO_COMMAND_H
00020 
00021 #include <co/api.h>
00022 #include <co/localNode.h> // NodePtr members
00023 
00024 #include <co/base/atomic.h> // member
00025 #include <co/base/refPtr.h> // NodePtr
00026 
00027 namespace co
00028 {    
00029     struct Packet;
00030 
00038     class Command 
00039     {
00040     public:
00043         template< class P > P* getModifiable()
00044             { EQASSERT( _packet ); return static_cast<P*>( _packet ); }
00045         template< class P > const P* get() const
00046             { EQASSERT( _packet ); return static_cast<P*>( _packet ); }
00047 
00048         NodePtr getNode()      const { return _node; }
00049         LocalNodePtr getLocalNode() const { return _localNode; }
00050 
00051         bool          operator ! () const { return ( _packet==0 ); }
00052         Packet*       operator->()       { EQASSERT(_packet); return _packet; }
00053         const Packet* operator->() const { EQASSERT(_packet); return _packet; }
00054 
00055         bool isValid() const { return ( _packet!=0 ); }
00056         uint64_t getAllocationSize() const { return _dataSize; }
00057 
00058         void setDispatchFunction( const Dispatcher::Func& func )
00059             { EQASSERT( !_func.isValid( )); _func = func; }
00061 
00064         bool isFree() const { return ( _refCount==0 ); }
00065         CO_API void retain();
00066         CO_API void release();
00068 
00070         CO_API bool operator()();
00071 
00072         explicit Command( base::a_int32_t& freeCounter ); 
00073         ~Command(); 
00074 
00076         size_t alloc_( NodePtr node, LocalNodePtr localNode,
00077                        const uint64_t size );
00078 
00087         void clone_( Command& from );
00088 
00089     private:
00090         Command& operator = ( Command& rhs ); // disable assignment
00091         Command( const Command& from );       // disable copy
00092         Command();                            // disable default ctor
00093 
00094         void _free();
00095 
00096         NodePtr       _node;      
00097         LocalNodePtr  _localNode; 
00098         Packet*       _packet;    
00099 
00100         Packet*  _data;     
00101         uint64_t _dataSize; 
00102 
00103         base::a_int32_t* _refCountMaster;
00104         base::a_int32_t  _refCount;
00105         base::a_int32_t& _freeCount;
00106 
00107         Dispatcher::Func _func;
00108         friend CO_API std::ostream& operator << (std::ostream&, const Command&);
00109 
00110         EQ_TS_VAR( _writeThread );
00111     };
00112 
00113     CO_API std::ostream& operator << ( std::ostream& os, const Command& );
00114 }
00115 #endif // CO_COMMAND_H
Generated on Fri Jun 8 2012 15:44:29 for Equalizer 1.2.1 by  doxygen 1.8.0