Equalizer 1.0

serializable.h

00001 
00002 /* Copyright (c) 2009-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 EQFABRIC_SERIALIZABLE_H
00019 #define EQFABRIC_SERIALIZABLE_H
00020 
00021 #include <co/object.h>        // base class
00022 #include <eq/fabric/types.h>
00023 #include <co/dataOStream.h>   // used inline
00024 #include <co/dataIStream.h>   // used inline
00025 
00026 namespace eq
00027 {
00028 namespace fabric
00029 {
00038     class Serializable : public co::Object
00039     {
00040     public:
00042         uint64_t getDirty() const { return _dirty; }
00043 
00045         virtual bool isDirty() const { return ( _dirty != DIRTY_NONE ); }
00046 
00048         virtual bool isDirty( const uint64_t dirtyBits ) const
00049             { return (_dirty & dirtyBits) == dirtyBits; }
00050 
00051         virtual uint128_t commitSync( const uint32_t commitID )
00052             {
00053                 const uint128_t& result = co::Object::commitSync( commitID );
00054                 _dirty = DIRTY_NONE;
00055                 return result;
00056             }
00057 
00058     protected:
00060         Serializable() : _dirty( DIRTY_NONE ) {}
00061         
00066         Serializable( const Serializable& )
00067                 : co::Object(), _dirty ( DIRTY_NONE ) {}
00068         
00070         virtual ~Serializable() {}
00071 
00084         virtual void serialize( co::DataOStream&, const uint64_t ){};
00085 
00096         virtual void deserialize( co::DataIStream&, const uint64_t ){};
00097 
00098         virtual ChangeType getChangeType() const { return DELTA; }
00099 
00106         enum DirtyBits
00107         {
00108             DIRTY_NONE       = 0,
00109             DIRTY_CUSTOM     = 1,
00110             DIRTY_ALL        = 0xFFFFFFFFFFFFFFFFull
00111         };
00112 
00114         virtual void setDirty( const uint64_t bits ) { _dirty |= bits; }
00115 
00117         virtual void unsetDirty( const uint64_t bits ) { _dirty &= ~bits; }
00118 
00119         virtual void notifyAttached()
00120             {
00121                 if( isMaster( ))
00122                     _dirty = DIRTY_NONE;
00123             }
00124 
00125     private:
00126         virtual void getInstanceData( co::DataOStream& os )
00127             {
00128                 serialize( os, DIRTY_ALL );
00129             }
00130 
00131         virtual void applyInstanceData( co::DataIStream& is )
00132             {
00133                 if( is.getRemainingBufferSize() == 0 && 
00134                     is.nRemainingBuffers() == 0 )
00135                 {
00136                     return;
00137                 }
00138                 deserialize( is, DIRTY_ALL );
00139             }
00140 
00141         virtual void pack( co::DataOStream& os )
00142             {
00143                 if( _dirty == DIRTY_NONE )
00144                     return;
00145 
00146                 os << _dirty;
00147                 serialize( os, _dirty );
00148             }
00149 
00150         virtual void unpack( co::DataIStream& is )
00151             {
00152                 if( is.getRemainingBufferSize() == 0 && 
00153                     is.nRemainingBuffers() == 0 )
00154                 {
00155                     return;
00156                 }
00157                 uint64_t dirty;
00158                 is >> dirty;
00159                 deserialize( is, dirty );
00160             }
00161 
00163         uint64_t _dirty;
00164 
00165         struct Private;
00166         Private* _private; // placeholder for binary-compatible changes
00167     };
00168 }
00169 }
00170 #endif // EQFABRIC_SERIALIZABLE_H
Generated on Sun May 8 2011 19:11:07 for Equalizer 1.0 by  doxygen 1.7.3