Collage
0.6.1
|
00001 00002 /* Copyright (c) 2006-2012, 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 <lunchbox/atomic.h> // member 00025 #include <lunchbox/refPtr.h> // NodePtr 00026 00027 namespace co 00028 { 00036 class Command 00037 { 00038 public: 00041 template< class P > P* getModifiable() 00042 { LBASSERT( _packet ); return static_cast<P*>( _packet ); } 00043 template< class P > const P* get() const 00044 { LBASSERT( _packet ); return static_cast<P*>( _packet ); } 00045 00046 NodePtr getNode() const { return _node; } 00047 LocalNodePtr getLocalNode() const { return _localNode; } 00048 00049 bool operator ! () const { return ( _packet==0 ); } 00050 Packet* operator->() { LBASSERT(_packet); return _packet; } 00051 const Packet* operator->() const { LBASSERT(_packet); return _packet; } 00052 00053 bool isValid() const { return ( _packet!=0 ); } 00054 uint64_t getAllocationSize() const { return _dataSize; } 00055 00056 void setDispatchFunction( const Dispatcher::Func& func ) 00057 { LBASSERT( !_func.isValid( )); _func = func; } 00059 00062 bool isFree() const { return ( _refCount==0 ); } 00063 CO_API void retain(); 00064 CO_API void release(); 00066 00068 CO_API bool operator()(); 00069 00070 explicit Command( lunchbox::a_int32_t& freeCounter ); 00071 ~Command(); 00072 00074 size_t alloc_( NodePtr node, LocalNodePtr localNode, 00075 const uint64_t size ); 00076 00085 void clone_( Command& from ); 00086 00087 private: 00088 Command& operator = ( Command& rhs ); // disable assignment 00089 Command( const Command& from ); // disable copy 00090 Command(); // disable default ctor 00091 00092 void _free(); 00093 00094 NodePtr _node; 00095 LocalNodePtr _localNode; 00096 Packet* _packet; 00097 00098 Packet* _data; 00099 uint64_t _dataSize; 00100 00101 lunchbox::a_int32_t* _refCountMaster; 00102 lunchbox::a_int32_t _refCount; 00103 lunchbox::a_int32_t& _freeCount; 00104 00105 Dispatcher::Func _func; 00106 friend CO_API std::ostream& operator << (std::ostream&, const Command&); 00107 00108 LB_TS_VAR( _writeThread ); 00109 }; 00110 00111 CO_API std::ostream& operator << ( std::ostream& os, const Command& ); 00112 } 00113 #endif // CO_COMMAND_H