Equalizer 1.0
|
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* get() 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 invoke(); 00071 00072 private: 00073 friend class CommandCache; 00074 00075 explicit Command( base::a_int32_t& freeCounter ); 00076 ~Command(); 00077 00079 size_t _alloc( NodePtr node, LocalNodePtr localNode, 00080 const uint64_t size ); 00081 00090 void _clone( Command& from ); 00091 00092 Command& operator = ( Command& rhs ); // disable assignment 00093 Command( const Command& from ); // disable copy 00094 Command(); // disable default ctor 00095 00096 void _free(); 00097 00098 NodePtr _node; 00099 LocalNodePtr _localNode; 00100 Packet* _packet; 00101 00102 Packet* _data; 00103 uint64_t _dataSize; 00104 00105 base::a_int32_t* _refCountMaster; 00106 base::a_int32_t _refCount; 00107 base::a_int32_t& _freeCount; 00108 00109 Dispatcher::Func _func; 00110 friend CO_API std::ostream& operator << (std::ostream&, const Command&); 00111 00112 EQ_TS_VAR( _writeThread ); 00113 }; 00114 00115 CO_API std::ostream& operator << ( std::ostream& os, const Command& ); 00116 } 00117 #endif // CO_COMMAND_H