http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCacheableDelta.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCacheableDelta.cpp b/src/clicache/src/impl/ManagedCacheableDelta.cpp index 805a96c..228cdac 100644 --- a/src/clicache/src/impl/ManagedCacheableDelta.cpp +++ b/src/clicache/src/impl/ManagedCacheableDelta.cpp @@ -27,248 +27,254 @@ using namespace System; -namespace gemfire +namespace apache { - - void ManagedCacheableDeltaGeneric::toData( DataOutput& output ) const + namespace geode { - try { - uint32 pos = (int)output.getBufferLength(); - GemStone::GemFire::Cache::Generic::DataOutput mg_output( &output, true ); - m_managedSerializableptr->ToData( %mg_output ); - //this will move the cursor in c++ layer - mg_output.WriteBytesToUMDataOutput(); - ManagedCacheableDeltaGeneric* tmp = const_cast<ManagedCacheableDeltaGeneric*>(this); - tmp->m_objectSize = (int)(output.getBufferLength() - pos); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - } + namespace client + { - Serializable* ManagedCacheableDeltaGeneric::fromData( DataInput& input ) - { - try { - int pos = input.getBytesRead(); - GemStone::GemFire::Cache::Generic::DataInput mg_input( &input, true ); - m_managedSerializableptr->FromData( %mg_input ); + void ManagedCacheableDeltaGeneric::toData(DataOutput& output) const + { + try { + uint32 pos = (int)output.getBufferLength(); + GemStone::GemFire::Cache::Generic::DataOutput mg_output(&output, true); + m_managedSerializableptr->ToData(%mg_output); + //this will move the cursor in c++ layer + mg_output.WriteBytesToUMDataOutput(); + ManagedCacheableDeltaGeneric* tmp = const_cast<ManagedCacheableDeltaGeneric*>(this); + tmp->m_objectSize = (int)(output.getBufferLength() - pos); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + } - //this will move the cursor in c++ layer - input.advanceCursor(mg_input.BytesReadInternally); + Serializable* ManagedCacheableDeltaGeneric::fromData(DataInput& input) + { + try { + int pos = input.getBytesRead(); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&input, true); + m_managedSerializableptr->FromData(%mg_input); - m_objectSize = input.getBytesRead() - pos; + //this will move the cursor in c++ layer + input.advanceCursor(mg_input.BytesReadInternally); - if(m_hashcode == 0) - m_hashcode = m_managedptr->GetHashCode(); - - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return this; - } + m_objectSize = input.getBytesRead() - pos; - uint32_t ManagedCacheableDeltaGeneric::objectSize( ) const - { - try { - int ret = m_managedSerializableptr->ObjectSize; - if(ret > m_objectSize) - return ret; - else - return m_objectSize; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } + if (m_hashcode == 0) + m_hashcode = m_managedptr->GetHashCode(); - int32_t ManagedCacheableDeltaGeneric::classId() const - { - uint32_t classId; - try { - classId = m_managedSerializableptr->ClassId; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return (classId >= 0x80000000 ? 0 : classId); - } - - int8_t ManagedCacheableDeltaGeneric::typeId() const - { - try { - uint32_t classId = m_classId; - if (classId >= 0x80000000) { - return (int8_t)((classId - 0x80000000) % 0x20000000); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return this; } - else if (classId <= 0x7F) { - return (int8_t)GemfireTypeIdsImpl::CacheableUserData; - } - else if (classId <= 0x7FFF) { - return (int8_t)GemfireTypeIdsImpl::CacheableUserData2; + + uint32_t ManagedCacheableDeltaGeneric::objectSize() const + { + try { + int ret = m_managedSerializableptr->ObjectSize; + if (ret > m_objectSize) + return ret; + else + return m_objectSize; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; } - else { - return (int8_t)GemfireTypeIdsImpl::CacheableUserData4; + + int32_t ManagedCacheableDeltaGeneric::classId() const + { + uint32_t classId; + try { + classId = m_managedSerializableptr->ClassId; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return (classId >= 0x80000000 ? 0 : classId); } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } - int8_t ManagedCacheableDeltaGeneric::DSFID() const - { - // convention that [0x8000000, 0xa0000000) is for FixedIDDefault, - // [0xa000000, 0xc0000000) is for FixedIDByte, - // [0xc0000000, 0xe0000000) is for FixedIDShort - // and [0xe0000000, 0xffffffff] is for FixedIDInt - // Note: depends on fact that FixedIDByte is 1, FixedIDShort is 2 - // and FixedIDInt is 3; if this changes then correct this accordingly - uint32_t classId = m_managedSerializableptr->ClassId; - if (classId >= 0x80000000) { - return (int8_t)((classId - 0x80000000) / 0x20000000); - } - return 0; - } + int8_t ManagedCacheableDeltaGeneric::typeId() const + { + try { + uint32_t classId = m_classId; + if (classId >= 0x80000000) { + return (int8_t)((classId - 0x80000000) % 0x20000000); + } + else if (classId <= 0x7F) { + return (int8_t)GemfireTypeIdsImpl::CacheableUserData; + } + else if (classId <= 0x7FFF) { + return (int8_t)GemfireTypeIdsImpl::CacheableUserData2; + } + else { + return (int8_t)GemfireTypeIdsImpl::CacheableUserData4; + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; + } - bool ManagedCacheableDeltaGeneric::hasDelta() - { - return m_managedptr->HasDelta(); - } + int8_t ManagedCacheableDeltaGeneric::DSFID() const + { + // convention that [0x8000000, 0xa0000000) is for FixedIDDefault, + // [0xa000000, 0xc0000000) is for FixedIDByte, + // [0xc0000000, 0xe0000000) is for FixedIDShort + // and [0xe0000000, 0xffffffff] is for FixedIDInt + // Note: depends on fact that FixedIDByte is 1, FixedIDShort is 2 + // and FixedIDInt is 3; if this changes then correct this accordingly + uint32_t classId = m_managedSerializableptr->ClassId; + if (classId >= 0x80000000) { + return (int8_t)((classId - 0x80000000) / 0x20000000); + } + return 0; + } - void ManagedCacheableDeltaGeneric::toDelta( DataOutput& output) const - { - try { - GemStone::GemFire::Cache::Generic::DataOutput mg_output( &output, true ); - m_managedptr->ToDelta( %mg_output ); - //this will move the cursor in c++ layer - mg_output.WriteBytesToUMDataOutput(); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - } + bool ManagedCacheableDeltaGeneric::hasDelta() + { + return m_managedptr->HasDelta(); + } - void ManagedCacheableDeltaGeneric::fromDelta( DataInput& input ) - { - try { - GemStone::GemFire::Cache::Generic::DataInput mg_input( &input, true ); - m_managedptr->FromDelta( %mg_input ); + void ManagedCacheableDeltaGeneric::toDelta(DataOutput& output) const + { + try { + GemStone::GemFire::Cache::Generic::DataOutput mg_output(&output, true); + m_managedptr->ToDelta(%mg_output); + //this will move the cursor in c++ layer + mg_output.WriteBytesToUMDataOutput(); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + } - //this will move the cursor in c++ layer - input.advanceCursor(mg_input.BytesReadInternally); + void ManagedCacheableDeltaGeneric::fromDelta(DataInput& input) + { + try { + GemStone::GemFire::Cache::Generic::DataInput mg_input(&input, true); + m_managedptr->FromDelta(%mg_input); - m_hashcode = m_managedptr->GetHashCode(); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - } + //this will move the cursor in c++ layer + input.advanceCursor(mg_input.BytesReadInternally); - DeltaPtr ManagedCacheableDeltaGeneric::clone() - { - try { - ICloneable^ cloneable = dynamic_cast< ICloneable^ >( ( - GemStone::GemFire::Cache::Generic::IGFDelta^ ) m_managedptr ); - if ( cloneable ) { - GemStone::GemFire::Cache::Generic::IGFSerializable^ Mclone = - dynamic_cast< GemStone::GemFire::Cache::Generic::IGFSerializable^ >( cloneable->Clone( ) ); - return DeltaPtr( static_cast< ManagedCacheableDeltaGeneric* >( - SafeMSerializableConvertGeneric( Mclone ) ) ); + m_hashcode = m_managedptr->GetHashCode(); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } } - else { - return Delta::clone( ); + + DeltaPtr ManagedCacheableDeltaGeneric::clone() + { + try { + ICloneable^ cloneable = dynamic_cast<ICloneable^>(( + GemStone::GemFire::Cache::Generic::IGFDelta^) m_managedptr); + if (cloneable) { + GemStone::GemFire::Cache::Generic::IGFSerializable^ Mclone = + dynamic_cast<GemStone::GemFire::Cache::Generic::IGFSerializable^>(cloneable->Clone()); + return DeltaPtr(static_cast<ManagedCacheableDeltaGeneric*>( + SafeMSerializableConvertGeneric(Mclone))); + } + else { + return Delta::clone(); + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return NULLPTR; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return NULLPTR; - } - bool ManagedCacheableDeltaGeneric::operator ==(const gemfire::CacheableKey& other) const - { - try { - // now checking classId(), typeId(), DSFID() etc. will be much more - // expensive than just a dynamic_cast - const ManagedCacheableDeltaGeneric* p_other = - dynamic_cast<const ManagedCacheableDeltaGeneric*>(&other); - if (p_other != NULL) { - return m_managedptr->Equals(p_other->ptr()); + bool ManagedCacheableDeltaGeneric::operator ==(const apache::geode::client::CacheableKey& other) const + { + try { + // now checking classId(), typeId(), DSFID() etc. will be much more + // expensive than just a dynamic_cast + const ManagedCacheableDeltaGeneric* p_other = + dynamic_cast<const ManagedCacheableDeltaGeneric*>(&other); + if (p_other != NULL) { + return m_managedptr->Equals(p_other->ptr()); + } + return false; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return false; } - return false; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return false; - } - bool ManagedCacheableDeltaGeneric::operator == ( const ManagedCacheableDeltaGeneric& other ) const - { - try { - return m_managedptr->Equals(other.ptr()); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return false; - - } + bool ManagedCacheableDeltaGeneric::operator == (const ManagedCacheableDeltaGeneric& other) const + { + try { + return m_managedptr->Equals(other.ptr()); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return false; - uint32_t ManagedCacheableDeltaGeneric::hashcode( ) const - { - throw gcnew System::NotSupportedException; - } + } - size_t ManagedCacheableDeltaGeneric::logString( char* buffer, size_t maxLength ) const - { - try { - if ( maxLength > 0 ) { - String^ logstr = m_managedptr->GetType( )->Name + '(' + - m_managedptr->ToString( ) + ')'; - GemStone::GemFire::Cache::Generic::ManagedString mg_str( logstr ); - return snprintf( buffer, maxLength, "%s", mg_str.CharPtr ); + uint32_t ManagedCacheableDeltaGeneric::hashcode() const + { + throw gcnew System::NotSupportedException; + } + + size_t ManagedCacheableDeltaGeneric::logString(char* buffer, size_t maxLength) const + { + try { + if (maxLength > 0) { + String^ logstr = m_managedptr->GetType()->Name + '(' + + m_managedptr->ToString() + ')'; + GemStone::GemFire::Cache::Generic::ManagedString mg_str(logstr); + return snprintf(buffer, maxLength, "%s", mg_str.CharPtr); + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } -} + } // namespace client + } // namespace geode +} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCacheableDelta.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCacheableDelta.hpp b/src/clicache/src/impl/ManagedCacheableDelta.hpp index d629041..58da1e4 100644 --- a/src/clicache/src/impl/ManagedCacheableDelta.hpp +++ b/src/clicache/src/impl/ManagedCacheableDelta.hpp @@ -25,7 +25,7 @@ using namespace System; -//using namespace gemfire; +//using namespace apache::geode::client; namespace GemStone { @@ -40,140 +40,146 @@ namespace GemStone } } -namespace gemfire +namespace apache { - - /// <summary> - /// Wraps the managed <see cref="GemStone.GemFire.Cache.IGFDelta" /> - /// object and implements the native <c>gemfire::CacheableKey</c> interface. - /// </summary> - class ManagedCacheableDeltaGeneric - : public gemfire::CacheableKey, public gemfire::Delta + namespace geode { - private : - int m_hashcode; - int m_classId; - int m_objectSize; - public: - - /// <summary> - /// Constructor to initialize with the provided managed object. - /// </summary> - /// <param name="managedptr"> - /// The managed object. - /// </param> - inline ManagedCacheableDeltaGeneric( - GemStone::GemFire::Cache::Generic::IGFDelta^ managedptr ) - : m_managedptr( managedptr ) + namespace client { - m_managedSerializableptr = dynamic_cast <GemStone::GemFire::Cache::Generic::IGFSerializable^> ( managedptr ); - m_classId = m_managedSerializableptr->ClassId; - m_objectSize = 0; - } - - inline ManagedCacheableDeltaGeneric( - GemStone::GemFire::Cache::Generic::IGFDelta^ managedptr, int hashcode, int classId ) - : m_managedptr( managedptr ) { - m_hashcode = hashcode; - m_classId = classId; - m_managedSerializableptr = dynamic_cast <GemStone::GemFire::Cache::Generic::IGFSerializable^> ( managedptr ); - m_objectSize = 0; - } - /// <summary> - /// serialize this object - /// </summary> - virtual void toData( gemfire::DataOutput& output ) const; - - /// <summary> - /// deserialize this object, typical implementation should return - /// the 'this' pointer. - /// </summary> - virtual gemfire::Serializable* fromData( gemfire::DataInput& input ); - - virtual void toDelta( gemfire::DataOutput& output) const; - - virtual void fromDelta( gemfire::DataInput& input ); - - /// <summary> - /// return the size of this object in bytes - /// </summary> - virtual uint32_t objectSize() const; - - /// <summary> - /// return the classId of the instance being serialized. - /// This is used by deserialization to determine what instance - /// type to create and deserialize into. - /// </summary> - virtual int32_t classId( ) const; - - /// <summary> - /// return the typeId of the instance being serialized. - /// This is used by deserialization to determine what instance - /// type to create and deserialize into. - /// </summary> - virtual int8_t typeId( ) const; - - /// <summary> - /// return the Data Serialization Fixed ID type. - /// This is used to determine what instance type to create - /// and deserialize into. - /// - /// Note that this should not be overridden by custom implementations - /// and is reserved only for builtin types. - /// </summary> - virtual int8_t DSFID() const; - - virtual bool hasDelta(); - - virtual gemfire::DeltaPtr clone(); - - /// <summary> - /// return the hashcode for this key. - /// </summary> - virtual uint32_t hashcode( ) const; - - /// <summary> - /// return true if this key matches other CacheableKey - /// </summary> - virtual bool operator == ( const CacheableKey& other ) const; - - /// <summary> - /// return true if this key matches other ManagedCacheableDeltaGeneric - /// </summary> - virtual bool operator == ( const ManagedCacheableDeltaGeneric& other ) const; - - /// <summary> - /// Copy the string form of a key into a char* buffer for logging purposes. - /// implementations should only generate a string as long as maxLength chars, - /// and return the number of chars written. buffer is expected to be large - /// enough to hold at least maxLength chars. - /// The default implementation renders the classname and instance address. - /// </summary> - virtual size_t logString( char* buffer, size_t maxLength ) const; - - /// <summary> - /// Returns the wrapped managed object reference. - /// </summary> - inline GemStone::GemFire::Cache::Generic::IGFDelta^ ptr( ) const - { - return m_managedptr; - } - - - private: - - /// <summary> - /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). - /// Note: not using auto_gcroot since it will result in 'Dispose' of the IGFDelta - /// to be called which is not what is desired when this object is destroyed. Normally this - /// managed object may be created by the user and will be handled automatically by the GC. - /// </summary> - gcroot<GemStone::GemFire::Cache::Generic::IGFDelta^> m_managedptr; - gcroot<GemStone::GemFire::Cache::Generic::IGFSerializable^> m_managedSerializableptr; - // Disable the copy and assignment constructors - ManagedCacheableDeltaGeneric( const ManagedCacheableDeltaGeneric& ); - ManagedCacheableDeltaGeneric& operator = ( const ManagedCacheableDeltaGeneric& ); - }; - -} + /// <summary> + /// Wraps the managed <see cref="GemStone.GemFire.Cache.IGFDelta" /> + /// object and implements the native <c>apache::geode::client::CacheableKey</c> interface. + /// </summary> + class ManagedCacheableDeltaGeneric + : public apache::geode::client::CacheableKey, public apache::geode::client::Delta + { + private: + int m_hashcode; + int m_classId; + int m_objectSize; + public: + + /// <summary> + /// Constructor to initialize with the provided managed object. + /// </summary> + /// <param name="managedptr"> + /// The managed object. + /// </param> + inline ManagedCacheableDeltaGeneric( + GemStone::GemFire::Cache::Generic::IGFDelta^ managedptr) + : m_managedptr(managedptr) + { + m_managedSerializableptr = dynamic_cast <GemStone::GemFire::Cache::Generic::IGFSerializable^> (managedptr); + m_classId = m_managedSerializableptr->ClassId; + m_objectSize = 0; + } + + inline ManagedCacheableDeltaGeneric( + GemStone::GemFire::Cache::Generic::IGFDelta^ managedptr, int hashcode, int classId) + : m_managedptr(managedptr) { + m_hashcode = hashcode; + m_classId = classId; + m_managedSerializableptr = dynamic_cast <GemStone::GemFire::Cache::Generic::IGFSerializable^> (managedptr); + m_objectSize = 0; + } + + /// <summary> + /// serialize this object + /// </summary> + virtual void toData(apache::geode::client::DataOutput& output) const; + + /// <summary> + /// deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + virtual apache::geode::client::Serializable* fromData(apache::geode::client::DataInput& input); + + virtual void toDelta(apache::geode::client::DataOutput& output) const; + + virtual void fromDelta(apache::geode::client::DataInput& input); + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual uint32_t objectSize() const; + + /// <summary> + /// return the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + virtual int32_t classId() const; + + /// <summary> + /// return the typeId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + virtual int8_t typeId() const; + + /// <summary> + /// return the Data Serialization Fixed ID type. + /// This is used to determine what instance type to create + /// and deserialize into. + /// + /// Note that this should not be overridden by custom implementations + /// and is reserved only for builtin types. + /// </summary> + virtual int8_t DSFID() const; + + virtual bool hasDelta(); + + virtual apache::geode::client::DeltaPtr clone(); + + /// <summary> + /// return the hashcode for this key. + /// </summary> + virtual uint32_t hashcode() const; + + /// <summary> + /// return true if this key matches other CacheableKey + /// </summary> + virtual bool operator == (const CacheableKey& other) const; + + /// <summary> + /// return true if this key matches other ManagedCacheableDeltaGeneric + /// </summary> + virtual bool operator == (const ManagedCacheableDeltaGeneric& other) const; + + /// <summary> + /// Copy the string form of a key into a char* buffer for logging purposes. + /// implementations should only generate a string as long as maxLength chars, + /// and return the number of chars written. buffer is expected to be large + /// enough to hold at least maxLength chars. + /// The default implementation renders the classname and instance address. + /// </summary> + virtual size_t logString(char* buffer, size_t maxLength) const; + + /// <summary> + /// Returns the wrapped managed object reference. + /// </summary> + inline GemStone::GemFire::Cache::Generic::IGFDelta^ ptr() const + { + return m_managedptr; + } + + + private: + + /// <summary> + /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). + /// Note: not using auto_gcroot since it will result in 'Dispose' of the IGFDelta + /// to be called which is not what is desired when this object is destroyed. Normally this + /// managed object may be created by the user and will be handled automatically by the GC. + /// </summary> + gcroot<GemStone::GemFire::Cache::Generic::IGFDelta^> m_managedptr; + gcroot<GemStone::GemFire::Cache::Generic::IGFSerializable^> m_managedSerializableptr; + // Disable the copy and assignment constructors + ManagedCacheableDeltaGeneric(const ManagedCacheableDeltaGeneric&); + ManagedCacheableDeltaGeneric& operator = (const ManagedCacheableDeltaGeneric&); + }; + + } // namespace client + } // namespace geode +} // namespace apache http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCacheableDeltaBytes.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCacheableDeltaBytes.cpp b/src/clicache/src/impl/ManagedCacheableDeltaBytes.cpp index 5f91961..ce4597a 100644 --- a/src/clicache/src/impl/ManagedCacheableDeltaBytes.cpp +++ b/src/clicache/src/impl/ManagedCacheableDeltaBytes.cpp @@ -27,303 +27,309 @@ using namespace System; -namespace gemfire +namespace apache { - - void ManagedCacheableDeltaBytesGeneric::toData( DataOutput& output ) const + namespace geode { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::toData: current domain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its domain ID: " + m_domainId ); - try { - output.writeBytesOnly(m_bytes, m_size); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - } + namespace client + { - Serializable* ManagedCacheableDeltaBytesGeneric::fromData( DataInput& input ) - { - try { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromData: classid " + m_classId); - GemStone::GemFire::Cache::Generic::DataInput mg_input( &input, true ); - const uint8_t* objStartPos = input.currentBufferPosition(); - - GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = - GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); - obj->FromData(%mg_input); - input.advanceCursor(mg_input.BytesReadInternally); - - m_hashCode = obj->GetHashCode(); + void ManagedCacheableDeltaBytesGeneric::toData(DataOutput& output) const + { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::toData: current domain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its domain ID: " + m_domainId); + try { + output.writeBytesOnly(m_bytes, m_size); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + } - const uint8_t* objEndPos = input.currentBufferPosition(); - - //m_size = mg_input.BytesRead; - m_size = (uint32_t)(objEndPos - objStartPos); - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromData: objectSize = " + m_size + " m_hashCode = " + m_hashCode); - m_bytes = input.getBufferCopyFrom(objStartPos, m_size); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return this; - } + Serializable* ManagedCacheableDeltaBytesGeneric::fromData(DataInput& input) + { + try { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromData: classid " + m_classId); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&input, true); + const uint8_t* objStartPos = input.currentBufferPosition(); - uint32_t ManagedCacheableDeltaBytesGeneric::objectSize( ) const - { - try { - return m_size; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } + GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = + GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); + obj->FromData(%mg_input); + input.advanceCursor(mg_input.BytesReadInternally); - int32_t ManagedCacheableDeltaBytesGeneric::classId() const - { - uint32_t classId; - try { - classId = m_classId; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return (classId >= 0x80000000 ? 0 : classId); - } + m_hashCode = obj->GetHashCode(); - int8_t ManagedCacheableDeltaBytesGeneric::typeId() const - { - try { - uint32_t classId = m_classId; - if (classId >= 0x80000000) { - return (int8_t)((classId - 0x80000000) % 0x20000000); - } - else if (classId <= 0x7F) { - return (int8_t)GemfireTypeIdsImpl::CacheableUserData; + const uint8_t* objEndPos = input.currentBufferPosition(); + + //m_size = mg_input.BytesRead; + m_size = (uint32_t)(objEndPos - objStartPos); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromData: objectSize = " + m_size + " m_hashCode = " + m_hashCode); + m_bytes = input.getBufferCopyFrom(objStartPos, m_size); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return this; } - else if (classId <= 0x7FFF) { - return (int8_t)GemfireTypeIdsImpl::CacheableUserData2; + + uint32_t ManagedCacheableDeltaBytesGeneric::objectSize() const + { + try { + return m_size; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; } - else { - return (int8_t)GemfireTypeIdsImpl::CacheableUserData4; + + int32_t ManagedCacheableDeltaBytesGeneric::classId() const + { + uint32_t classId; + try { + classId = m_classId; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return (classId >= 0x80000000 ? 0 : classId); } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } - int8_t ManagedCacheableDeltaBytesGeneric::DSFID() const - { - // convention that [0x8000000, 0xa0000000) is for FixedIDDefault, - // [0xa000000, 0xc0000000) is for FixedIDByte, - // [0xc0000000, 0xe0000000) is for FixedIDShort - // and [0xe0000000, 0xffffffff] is for FixedIDInt - // Note: depends on fact that FixedIDByte is 1, FixedIDShort is 2 - // and FixedIDInt is 3; if this changes then correct this accordingly - uint32_t classId = m_classId; - if (classId >= 0x80000000) { - return (int8_t)((classId - 0x80000000) / 0x20000000); - } - return 0; - } + int8_t ManagedCacheableDeltaBytesGeneric::typeId() const + { + try { + uint32_t classId = m_classId; + if (classId >= 0x80000000) { + return (int8_t)((classId - 0x80000000) % 0x20000000); + } + else if (classId <= 0x7F) { + return (int8_t)GemfireTypeIdsImpl::CacheableUserData; + } + else if (classId <= 0x7FFF) { + return (int8_t)GemfireTypeIdsImpl::CacheableUserData2; + } + else { + return (int8_t)GemfireTypeIdsImpl::CacheableUserData4; + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; + } - bool ManagedCacheableDeltaBytesGeneric::hasDelta() - { - //GemStone::GemFire::Cache::IGFDelta^ deltaObj = this->getManagedObject(); - //return deltaObj->HasDelta(); - return m_hasDelta; - } + int8_t ManagedCacheableDeltaBytesGeneric::DSFID() const + { + // convention that [0x8000000, 0xa0000000) is for FixedIDDefault, + // [0xa000000, 0xc0000000) is for FixedIDByte, + // [0xc0000000, 0xe0000000) is for FixedIDShort + // and [0xe0000000, 0xffffffff] is for FixedIDInt + // Note: depends on fact that FixedIDByte is 1, FixedIDShort is 2 + // and FixedIDInt is 3; if this changes then correct this accordingly + uint32_t classId = m_classId; + if (classId >= 0x80000000) { + return (int8_t)((classId - 0x80000000) / 0x20000000); + } + return 0; + } - void ManagedCacheableDeltaBytesGeneric::toDelta( DataOutput& output) const - { - try { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::toDelta: current domain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its domain ID: " + m_domainId); - GemStone::GemFire::Cache::Generic::IGFDelta^ deltaObj = this->getManagedObject(); - GemStone::GemFire::Cache::Generic::DataOutput mg_output( &output, true ); - deltaObj->ToDelta( %mg_output ); - mg_output.WriteBytesToUMDataOutput(); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - } + bool ManagedCacheableDeltaBytesGeneric::hasDelta() + { + //GemStone::GemFire::Cache::IGFDelta^ deltaObj = this->getManagedObject(); + //return deltaObj->HasDelta(); + return m_hasDelta; + } - void ManagedCacheableDeltaBytesGeneric::fromDelta( DataInput& input ) - { - try { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromDelta:"); - GemStone::GemFire::Cache::Generic::IGFDelta^ deltaObj = this->getManagedObject(); - GemStone::GemFire::Cache::Generic::DataInput mg_input( &input, true ); - deltaObj->FromDelta( %mg_input ); + void ManagedCacheableDeltaBytesGeneric::toDelta(DataOutput& output) const + { + try { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::toDelta: current domain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its domain ID: " + m_domainId); + GemStone::GemFire::Cache::Generic::IGFDelta^ deltaObj = this->getManagedObject(); + GemStone::GemFire::Cache::Generic::DataOutput mg_output(&output, true); + deltaObj->ToDelta(%mg_output); + mg_output.WriteBytesToUMDataOutput(); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + } - GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr = - dynamic_cast <GemStone::GemFire::Cache::Generic::IGFSerializable^> ( deltaObj ); - if(managedptr != nullptr) + void ManagedCacheableDeltaBytesGeneric::fromDelta(DataInput& input) { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromDelta: current domain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its domain ID: " + m_domainId); - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromDelta: classid " + managedptr->ClassId + " : " + managedptr->ToString()); - gemfire::DataOutput dataOut; - GemStone::GemFire::Cache::Generic::DataOutput mg_output( &dataOut, true); - managedptr->ToData( %mg_output ); + try { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromDelta:"); + GemStone::GemFire::Cache::Generic::IGFDelta^ deltaObj = this->getManagedObject(); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&input, true); + deltaObj->FromDelta(%mg_input); - //move cursor - //dataOut.advanceCursor(mg_output.BufferLength); - mg_output.WriteBytesToUMDataOutput(); + GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr = + dynamic_cast <GemStone::GemFire::Cache::Generic::IGFSerializable^> (deltaObj); + if (managedptr != nullptr) + { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromDelta: current domain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its domain ID: " + m_domainId); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromDelta: classid " + managedptr->ClassId + " : " + managedptr->ToString()); + apache::geode::client::DataOutput dataOut; + GemStone::GemFire::Cache::Generic::DataOutput mg_output(&dataOut, true); + managedptr->ToData(%mg_output); - GF_SAFE_DELETE(m_bytes); - m_bytes = dataOut.getBufferCopy(); - m_size = dataOut.getBufferLength(); - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromDelta objectSize = " + m_size + " m_hashCode = " + m_hashCode); - m_hashCode = managedptr->GetHashCode(); - } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - } + //move cursor + //dataOut.advanceCursor(mg_output.BufferLength); + mg_output.WriteBytesToUMDataOutput(); - DeltaPtr ManagedCacheableDeltaBytesGeneric::clone() - { - try { - GemStone::GemFire::Cache::Generic::IGFDelta^ deltaObj = this->getManagedObject(); - ICloneable^ cloneable = dynamic_cast< ICloneable^ >( ( GemStone::GemFire::Cache::Generic::IGFDelta^ ) deltaObj ); - if ( cloneable ) { - GemStone::GemFire::Cache::Generic::IGFSerializable^ Mclone = - dynamic_cast< GemStone::GemFire::Cache::Generic::IGFSerializable^ >( cloneable->Clone( ) ); - return DeltaPtr( static_cast< ManagedCacheableDeltaBytesGeneric* >( - SafeMSerializableConvertGeneric( Mclone ) ) ); + GF_SAFE_DELETE(m_bytes); + m_bytes = dataOut.getBufferCopy(); + m_size = dataOut.getBufferLength(); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::fromDelta objectSize = " + m_size + " m_hashCode = " + m_hashCode); + m_hashCode = managedptr->GetHashCode(); + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } } - else { - return Delta::clone( ); + + DeltaPtr ManagedCacheableDeltaBytesGeneric::clone() + { + try { + GemStone::GemFire::Cache::Generic::IGFDelta^ deltaObj = this->getManagedObject(); + ICloneable^ cloneable = dynamic_cast<ICloneable^>((GemStone::GemFire::Cache::Generic::IGFDelta^) deltaObj); + if (cloneable) { + GemStone::GemFire::Cache::Generic::IGFSerializable^ Mclone = + dynamic_cast<GemStone::GemFire::Cache::Generic::IGFSerializable^>(cloneable->Clone()); + return DeltaPtr(static_cast<ManagedCacheableDeltaBytesGeneric*>( + SafeMSerializableConvertGeneric(Mclone))); + } + else { + return Delta::clone(); + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return NULLPTR; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return NULLPTR; - } - GemStone::GemFire::Cache::Generic::IGFDelta^ - ManagedCacheableDeltaBytesGeneric::getManagedObject() const - { + GemStone::GemFire::Cache::Generic::IGFDelta^ + ManagedCacheableDeltaBytesGeneric::getManagedObject() const + { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::getManagedObject"); - - gemfire::DataInput dinp(m_bytes, m_size); - GemStone::GemFire::Cache::Generic::DataInput mg_dinp(&dinp, true); - GemStone::GemFire::Cache::Generic::TypeFactoryMethodGeneric^ creationMethod = - GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId); - GemStone::GemFire::Cache::Generic::IGFSerializable^ newObj = creationMethod(); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytes::getManagedObject"); - GemStone::GemFire::Cache::Generic::IGFDelta^ managedDeltaptr = - dynamic_cast <GemStone::GemFire::Cache::Generic::IGFDelta^> ( newObj->FromData(%mg_dinp) ); - return managedDeltaptr; - } + apache::geode::client::DataInput dinp(m_bytes, m_size); + GemStone::GemFire::Cache::Generic::DataInput mg_dinp(&dinp, true); + GemStone::GemFire::Cache::Generic::TypeFactoryMethodGeneric^ creationMethod = + GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId); + GemStone::GemFire::Cache::Generic::IGFSerializable^ newObj = creationMethod(); - bool ManagedCacheableDeltaBytesGeneric::operator ==(const gemfire::CacheableKey& other) const - { - try { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal"); - // now checking classId(), typeId(), DSFID() etc. will be much more - // expensive than just a dynamic_cast - const ManagedCacheableDeltaBytesGeneric* p_other = - dynamic_cast<const ManagedCacheableDeltaBytesGeneric*>(&other); - if (p_other != NULL) { - gemfire::DataInput di(m_bytes, m_size); - GemStone::GemFire::Cache::Generic::DataInput mg_input(&di, true); - GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = - GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); - obj->FromData(%mg_input); - bool ret = obj->Equals(p_other->ptr()); - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal return VAL = " + ret); - return ret; + GemStone::GemFire::Cache::Generic::IGFDelta^ managedDeltaptr = + dynamic_cast <GemStone::GemFire::Cache::Generic::IGFDelta^> (newObj->FromData(%mg_dinp)); + return managedDeltaptr; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal returns false"); - return false; - } - bool ManagedCacheableDeltaBytesGeneric::operator ==(const ManagedCacheableDeltaBytesGeneric& other) const - { - try { - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal. "); - gemfire::DataInput di(m_bytes, m_size); - GemStone::GemFire::Cache::Generic::DataInput mg_input(&di, true); - GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = - GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); - obj->FromData(%mg_input); - bool ret = obj->Equals(other.ptr()); - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal return VAL = " + ret); - return ret; - //return obj->Equals(other.ptr()); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal return false"); - return false; - } + bool ManagedCacheableDeltaBytesGeneric::operator ==(const apache::geode::client::CacheableKey& other) const + { + try { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal"); + // now checking classId(), typeId(), DSFID() etc. will be much more + // expensive than just a dynamic_cast + const ManagedCacheableDeltaBytesGeneric* p_other = + dynamic_cast<const ManagedCacheableDeltaBytesGeneric*>(&other); + if (p_other != NULL) { + apache::geode::client::DataInput di(m_bytes, m_size); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&di, true); + GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = + GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); + obj->FromData(%mg_input); + bool ret = obj->Equals(p_other->ptr()); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal return VAL = " + ret); + return ret; + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal returns false"); + return false; + } - uint32_t ManagedCacheableDeltaBytesGeneric::hashcode( ) const - { - throw gcnew System::NotSupportedException; - } + bool ManagedCacheableDeltaBytesGeneric::operator ==(const ManagedCacheableDeltaBytesGeneric& other) const + { + try { + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal. "); + apache::geode::client::DataInput di(m_bytes, m_size); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&di, true); + GemStone::GemFire::Cache::Generic::IGFSerializable^ obj = + GemStone::GemFire::Cache::Generic::Serializable::GetTypeFactoryMethodGeneric(m_classId)(); + obj->FromData(%mg_input); + bool ret = obj->Equals(other.ptr()); + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal return VAL = " + ret); + return ret; + //return obj->Equals(other.ptr()); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableDeltaBytesGeneric::equal return false"); + return false; + } - size_t ManagedCacheableDeltaBytesGeneric::logString( char* buffer, size_t maxLength ) const - { - try { - GemStone::GemFire::Cache::Generic::IGFDelta^ manageObject = getManagedObject(); - if(manageObject != nullptr) + uint32_t ManagedCacheableDeltaBytesGeneric::hashcode() const { - if ( maxLength > 0 ) { - String^ logstr = manageObject->GetType( )->Name + '(' + - manageObject->ToString( ) + ')'; - GemStone::GemFire::Cache::Generic::ManagedString mg_str( logstr ); - return snprintf( buffer, maxLength, "%s", mg_str.CharPtr ); + throw gcnew System::NotSupportedException; + } + + size_t ManagedCacheableDeltaBytesGeneric::logString(char* buffer, size_t maxLength) const + { + try { + GemStone::GemFire::Cache::Generic::IGFDelta^ manageObject = getManagedObject(); + if (manageObject != nullptr) + { + if (maxLength > 0) { + String^ logstr = manageObject->GetType()->Name + '(' + + manageObject->ToString() + ')'; + GemStone::GemFire::Cache::Generic::ManagedString mg_str(logstr); + return snprintf(buffer, maxLength, "%s", mg_str.CharPtr); + } + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); } + return 0; } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } -} + } // namespace client + } // namespace geode +} // namespace apache http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCacheableDeltaBytes.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCacheableDeltaBytes.hpp b/src/clicache/src/impl/ManagedCacheableDeltaBytes.hpp index 41f9cf2..0ce6bde 100644 --- a/src/clicache/src/impl/ManagedCacheableDeltaBytes.hpp +++ b/src/clicache/src/impl/ManagedCacheableDeltaBytes.hpp @@ -38,193 +38,200 @@ namespace GemStone } } -namespace gemfire +namespace apache { - - /// <summary> - /// Wraps the managed <see cref="GemStone.GemFire.Cache.IGFDelta" /> - /// object and implements the native <c>gemfire::CacheableKey</c> interface. - /// </summary> - class ManagedCacheableDeltaBytesGeneric - : public CacheableKey, public Delta + namespace geode { - public: - - /// <summary> - /// Constructor to initialize with the provided managed object. - /// </summary> - /// <param name="managedDeltaptr"> - /// The managed object. - /// </param> - inline ManagedCacheableDeltaBytesGeneric( - GemStone::GemFire::Cache::Generic::IGFDelta^ managedDeltaptr, bool storeBytes ) - : m_domainId(System::Threading::Thread::GetDomainID()), - m_classId(0), - m_bytes(NULL), - m_size(0), - m_hasDelta(false), - m_hashCode(0) + namespace client { - if(storeBytes) - m_hasDelta = managedDeltaptr->HasDelta(); - GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr = - dynamic_cast <GemStone::GemFire::Cache::Generic::IGFSerializable^> ( managedDeltaptr ); - if(managedptr != nullptr) + + + /// <summary> + /// Wraps the managed <see cref="GemStone.GemFire.Cache.IGFDelta" /> + /// object and implements the native <c>apache::geode::client::CacheableKey</c> interface. + /// </summary> + class ManagedCacheableDeltaBytesGeneric + : public CacheableKey, public Delta { - m_classId = managedptr->ClassId; - GemStone::GemFire::Cache::Generic::Log::Finer("ManagedCacheableDeltaBytes::Constructor: current AppDomain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its AppDomain ID: " + m_domainId); - GemStone::GemFire::Cache::Generic::Log::Finer("ManagedCacheableDeltaBytes::Constructor: class ID " + managedptr->ClassId + " : " + managedptr->ToString() + " storeBytes:" + storeBytes); - if(storeBytes) + public: + + /// <summary> + /// Constructor to initialize with the provided managed object. + /// </summary> + /// <param name="managedDeltaptr"> + /// The managed object. + /// </param> + inline ManagedCacheableDeltaBytesGeneric( + GemStone::GemFire::Cache::Generic::IGFDelta^ managedDeltaptr, bool storeBytes) + : m_domainId(System::Threading::Thread::GetDomainID()), + m_classId(0), + m_bytes(NULL), + m_size(0), + m_hasDelta(false), + m_hashCode(0) { - gemfire::DataOutput dataOut; - GemStone::GemFire::Cache::Generic::DataOutput mg_output( &dataOut, true); - managedptr->ToData( %mg_output ); - - //move cursor - //dataOut.advanceCursor(mg_output.BufferLength); - mg_output.WriteBytesToUMDataOutput(); - - m_bytes = dataOut.getBufferCopy(); - m_size = dataOut.getBufferLength(); - m_hashCode = managedptr->GetHashCode(); - GemStone::GemFire::Cache::Generic::Log::Finer("ManagedCacheableDeltaBytes::Constructor objectSize = " + m_size + " m_hashCode = " + m_hashCode); + if (storeBytes) + m_hasDelta = managedDeltaptr->HasDelta(); + GemStone::GemFire::Cache::Generic::IGFSerializable^ managedptr = + dynamic_cast <GemStone::GemFire::Cache::Generic::IGFSerializable^> (managedDeltaptr); + if (managedptr != nullptr) + { + m_classId = managedptr->ClassId; + GemStone::GemFire::Cache::Generic::Log::Finer("ManagedCacheableDeltaBytes::Constructor: current AppDomain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its AppDomain ID: " + m_domainId); + GemStone::GemFire::Cache::Generic::Log::Finer("ManagedCacheableDeltaBytes::Constructor: class ID " + managedptr->ClassId + " : " + managedptr->ToString() + " storeBytes:" + storeBytes); + if (storeBytes) + { + apache::geode::client::DataOutput dataOut; + GemStone::GemFire::Cache::Generic::DataOutput mg_output(&dataOut, true); + managedptr->ToData(%mg_output); + + //move cursor + //dataOut.advanceCursor(mg_output.BufferLength); + mg_output.WriteBytesToUMDataOutput(); + + m_bytes = dataOut.getBufferCopy(); + m_size = dataOut.getBufferLength(); + m_hashCode = managedptr->GetHashCode(); + GemStone::GemFire::Cache::Generic::Log::Finer("ManagedCacheableDeltaBytes::Constructor objectSize = " + m_size + " m_hashCode = " + m_hashCode); + } + } + } + /* + inline ManagedCacheableDeltaBytes( + GemStone::GemFire::Cache::IGFDelta^ managedDeltaptr, bool storeBytes) + : m_domainId(System::Threading::Thread::GetDomainID()), + m_classId(0), + m_bytes(NULL), + m_size(0), + m_hashCode(0) + { + GemStone::GemFire::Cache::Log::Fine("ManagedCacheableDeltaBytes::Constructor: not storing bytes "); + GemStone::GemFire::Cache::IGFSerializable^ managedptr = dynamic_cast <GemStone::GemFire::Cache::IGFSerializable^> ( managedDeltaptr ); + if(managedptr != nullptr) + { + m_classId = managedptr->ClassId; + GemStone::GemFire::Cache::Log::Fine("ManagedCacheableDeltaBytes::Constructor: current AppDomain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its AppDomain ID: " + m_domainId); + GemStone::GemFire::Cache::Log::Fine("ManagedCacheableDeltaBytes::Constructor: class ID " + managedptr->ClassId + " : " + managedptr->ToString()); + apache::geode::client::DataOutput dataOut; + GemStone::GemFire::Cache::DataOutput mg_output( &dataOut); + managedptr->ToData( %mg_output ); + m_bytes = dataOut.getBufferCopy(); + m_size = dataOut.getBufferLength(); + GemStone::GemFire::Cache::Log::Fine("ManagedCacheableDeltaBytes::Constructor objectSize = " + m_size + " m_hashCode = " + m_hashCode); + m_hashCode = managedptr->GetHashCode(); + } + }*/ + + + /// <summary> + /// serialize this object + /// </summary> + virtual void toData(apache::geode::client::DataOutput& output) const; + + /// <summary> + /// deserialize this object, typical implementation should return + /// the 'this' pointer. + /// </summary> + virtual apache::geode::client::Serializable* fromData(apache::geode::client::DataInput& input); + + virtual void toDelta(apache::geode::client::DataOutput& output) const; + + virtual void fromDelta(apache::geode::client::DataInput& input); + + /// <summary> + /// return the size of this object in bytes + /// </summary> + virtual uint32_t objectSize() const; + + /// <summary> + /// return the classId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + virtual int32_t classId() const; + + /// <summary> + /// return the typeId of the instance being serialized. + /// This is used by deserialization to determine what instance + /// type to create and deserialize into. + /// </summary> + virtual int8_t typeId() const; + + /// <summary> + /// return the Data Serialization Fixed ID type. + /// This is used to determine what instance type to create + /// and deserialize into. + /// + /// Note that this should not be overridden by custom implementations + /// and is reserved only for builtin types. + /// </summary> + virtual int8_t DSFID() const; + + virtual bool hasDelta(); + + virtual apache::geode::client::DeltaPtr clone(); + + /// <summary> + /// return the hashcode for this key. + /// </summary> + virtual uint32_t hashcode() const; + + /// <summary> + /// return true if this key matches other CacheableKey + /// </summary> + virtual bool operator == (const CacheableKey& other) const; + + /// <summary> + /// return true if this key matches other ManagedCacheableDeltaBytesGeneric + /// </summary> + virtual bool operator == (const ManagedCacheableDeltaBytesGeneric& other) const; + + /// <summary> + /// Copy the string form of a key into a char* buffer for logging purposes. + /// implementations should only generate a string as long as maxLength chars, + /// and return the number of chars written. buffer is expected to be large + /// enough to hold at least maxLength chars. + /// The default implementation renders the classname and instance address. + /// </summary> + virtual size_t logString(char* buffer, size_t maxLength) const; + + /// <summary> + /// Returns the wrapped managed object reference. + /// </summary> + inline GemStone::GemFire::Cache::Generic::IGFDelta^ ptr() const + { + return getManagedObject(); } - } - } -/* - inline ManagedCacheableDeltaBytes( - GemStone::GemFire::Cache::IGFDelta^ managedDeltaptr, bool storeBytes) - : m_domainId(System::Threading::Thread::GetDomainID()), - m_classId(0), - m_bytes(NULL), - m_size(0), - m_hashCode(0) - { - GemStone::GemFire::Cache::Log::Fine("ManagedCacheableDeltaBytes::Constructor: not storing bytes "); - GemStone::GemFire::Cache::IGFSerializable^ managedptr = dynamic_cast <GemStone::GemFire::Cache::IGFSerializable^> ( managedDeltaptr ); - if(managedptr != nullptr) - { - m_classId = managedptr->ClassId; - GemStone::GemFire::Cache::Log::Fine("ManagedCacheableDeltaBytes::Constructor: current AppDomain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its AppDomain ID: " + m_domainId); - GemStone::GemFire::Cache::Log::Fine("ManagedCacheableDeltaBytes::Constructor: class ID " + managedptr->ClassId + " : " + managedptr->ToString()); - gemfire::DataOutput dataOut; - GemStone::GemFire::Cache::DataOutput mg_output( &dataOut); - managedptr->ToData( %mg_output ); - m_bytes = dataOut.getBufferCopy(); - m_size = dataOut.getBufferLength(); - GemStone::GemFire::Cache::Log::Fine("ManagedCacheableDeltaBytes::Constructor objectSize = " + m_size + " m_hashCode = " + m_hashCode); - m_hashCode = managedptr->GetHashCode(); - } - }*/ - - - /// <summary> - /// serialize this object - /// </summary> - virtual void toData( gemfire::DataOutput& output ) const; - - /// <summary> - /// deserialize this object, typical implementation should return - /// the 'this' pointer. - /// </summary> - virtual gemfire::Serializable* fromData( gemfire::DataInput& input ); - - virtual void toDelta( gemfire::DataOutput& output) const; - - virtual void fromDelta( gemfire::DataInput& input ); - - /// <summary> - /// return the size of this object in bytes - /// </summary> - virtual uint32_t objectSize() const; - - /// <summary> - /// return the classId of the instance being serialized. - /// This is used by deserialization to determine what instance - /// type to create and deserialize into. - /// </summary> - virtual int32_t classId( ) const; - - /// <summary> - /// return the typeId of the instance being serialized. - /// This is used by deserialization to determine what instance - /// type to create and deserialize into. - /// </summary> - virtual int8_t typeId( ) const; - - /// <summary> - /// return the Data Serialization Fixed ID type. - /// This is used to determine what instance type to create - /// and deserialize into. - /// - /// Note that this should not be overridden by custom implementations - /// and is reserved only for builtin types. - /// </summary> - virtual int8_t DSFID() const; - - virtual bool hasDelta(); - - virtual gemfire::DeltaPtr clone(); - - /// <summary> - /// return the hashcode for this key. - /// </summary> - virtual uint32_t hashcode( ) const; - - /// <summary> - /// return true if this key matches other CacheableKey - /// </summary> - virtual bool operator == ( const CacheableKey& other ) const; - - /// <summary> - /// return true if this key matches other ManagedCacheableDeltaBytesGeneric - /// </summary> - virtual bool operator == ( const ManagedCacheableDeltaBytesGeneric& other ) const; - - /// <summary> - /// Copy the string form of a key into a char* buffer for logging purposes. - /// implementations should only generate a string as long as maxLength chars, - /// and return the number of chars written. buffer is expected to be large - /// enough to hold at least maxLength chars. - /// The default implementation renders the classname and instance address. - /// </summary> - virtual size_t logString( char* buffer, size_t maxLength ) const; - - /// <summary> - /// Returns the wrapped managed object reference. - /// </summary> - inline GemStone::GemFire::Cache::Generic::IGFDelta^ ptr( ) const - { - return getManagedObject(); - } - inline ~ManagedCacheableDeltaBytesGeneric() - { - GemStone::GemFire::Cache::Generic::Log::Finer("ManagedCacheableDeltaBytes::Destructor current AppDomain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its AppDomain ID: " + m_domainId); - GF_SAFE_DELETE(m_bytes); - } + inline ~ManagedCacheableDeltaBytesGeneric() + { + GemStone::GemFire::Cache::Generic::Log::Finer("ManagedCacheableDeltaBytes::Destructor current AppDomain ID: " + System::Threading::Thread::GetDomainID() + " for object: " + System::Convert::ToString((int)this) + " with its AppDomain ID: " + m_domainId); + GF_SAFE_DELETE(m_bytes); + } - private: - GemStone::GemFire::Cache::Generic::IGFDelta^ getManagedObject() const; - /// <summary> - /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). - /// Note: not using auto_gcroot since it will result in 'Dispose' of the IGFDelta - /// to be called which is not what is desired when this object is destroyed. Normally this - /// managed object may be created by the user and will be handled automatically by the GC. - /// </summary> - //gcroot<GemStone::GemFire::Cache::IGFDelta^> m_managedptr; - //gcroot<GemStone::GemFire::Cache::IGFSerializable^> m_managedSerializableptr; - - int m_domainId; - UInt32 m_classId; - uint8_t * m_bytes; - uint32_t m_size; - uint32_t m_hashCode; - bool m_hasDelta; - - // Disable the copy and assignment constructors - ManagedCacheableDeltaBytesGeneric( const ManagedCacheableDeltaBytesGeneric& ); - ManagedCacheableDeltaBytesGeneric& operator = ( const ManagedCacheableDeltaBytesGeneric& ); - }; + private: + GemStone::GemFire::Cache::Generic::IGFDelta^ getManagedObject() const; + /// <summary> + /// Using gcroot to hold the managed delegate pointer (since it cannot be stored directly). + /// Note: not using auto_gcroot since it will result in 'Dispose' of the IGFDelta + /// to be called which is not what is desired when this object is destroyed. Normally this + /// managed object may be created by the user and will be handled automatically by the GC. + /// </summary> + //gcroot<GemStone::GemFire::Cache::IGFDelta^> m_managedptr; + //gcroot<GemStone::GemFire::Cache::IGFSerializable^> m_managedSerializableptr; + + int m_domainId; + UInt32 m_classId; + uint8_t * m_bytes; + uint32_t m_size; + uint32_t m_hashCode; + bool m_hasDelta; + + // Disable the copy and assignment constructors + ManagedCacheableDeltaBytesGeneric(const ManagedCacheableDeltaBytesGeneric&); + ManagedCacheableDeltaBytesGeneric& operator = (const ManagedCacheableDeltaBytesGeneric&); + }; -} + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode/blob/e4fd74fb/src/clicache/src/impl/ManagedCacheableKey.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/impl/ManagedCacheableKey.cpp b/src/clicache/src/impl/ManagedCacheableKey.cpp index 500a280..5e69b35 100644 --- a/src/clicache/src/impl/ManagedCacheableKey.cpp +++ b/src/clicache/src/impl/ManagedCacheableKey.cpp @@ -27,215 +27,221 @@ using namespace System; -namespace gemfire +namespace apache { - - void ManagedCacheableKeyGeneric::toData( gemfire::DataOutput& output ) const - { - try { - uint32 pos = (int)output.getBufferLength(); - //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::toData"); - GemStone::GemFire::Cache::Generic::DataOutput mg_output( &output, true ); - m_managedptr->ToData( %mg_output ); - //this will move the cursor in c++ layer - mg_output.WriteBytesToUMDataOutput(); - - ManagedCacheableKeyGeneric* tmp = const_cast<ManagedCacheableKeyGeneric*>(this); - tmp->m_objectSize = (int)(output.getBufferLength() - pos); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - } - - gemfire::Serializable* ManagedCacheableKeyGeneric::fromData( gemfire::DataInput& input ) - { - try { - int pos = input.getBytesRead(); - //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::fromData"); - GemStone::GemFire::Cache::Generic::DataInput mg_input (&input, true); - m_managedptr = m_managedptr->FromData( %mg_input ); - - //this will move the cursor in c++ layer - input.advanceCursor(mg_input.BytesReadInternally); - m_objectSize = input.getBytesRead() - pos; - //if(m_hashcode == 0) - //m_hashcode = m_managedptr->GetHashCode(); - - - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return this; - } - - uint32_t ManagedCacheableKeyGeneric::objectSize( ) const - { - try { - int ret = m_managedptr->ObjectSize; - if(ret > m_objectSize) - return ret; - else - return m_objectSize; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } - - int32_t ManagedCacheableKeyGeneric::classId() const - { - //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::classid " + m_classId); - /*uint32_t classId; - try { - classId = m_managedptr->ClassId; - } - catch (GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemFireException::ThrowNative(ex); - }*/ - return (m_classId >= 0x80000000 ? 0 : m_classId); - } - - int8_t ManagedCacheableKeyGeneric::typeId() const - { - //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::typeId " + m_classId); - if (m_classId >= 0x80000000) { - return (int8_t)((m_classId - 0x80000000) % 0x20000000); - } - else if (m_classId <= 0x7F) { - //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::typeId inin"); - return (int8_t)GemfireTypeIdsImpl::CacheableUserData; - } - else if (m_classId <= 0x7FFF) { - return (int8_t)GemfireTypeIdsImpl::CacheableUserData2; - } - else { - return (int8_t)GemfireTypeIdsImpl::CacheableUserData4; - } - } - - int8_t ManagedCacheableKeyGeneric::DSFID() const - { - // convention that [0x8000000, 0xa0000000) is for FixedIDDefault, - // [0xa000000, 0xc0000000) is for FixedIDByte, - // [0xc0000000, 0xe0000000) is for FixedIDShort - // and [0xe0000000, 0xffffffff] is for FixedIDInt - // Note: depends on fact that FixedIDByte is 1, FixedIDShort is 2 - // and FixedIDInt is 3; if this changes then correct this accordingly - if (m_classId >= 0x80000000) { - return (int8_t)((m_classId - 0x80000000) / 0x20000000); - } - return 0; - } - - gemfire::CacheableStringPtr ManagedCacheableKeyGeneric::toString( ) const - { - try { - gemfire::CacheableStringPtr cStr; - GemStone::GemFire::Cache::Generic::CacheableString::GetCacheableString( - m_managedptr->ToString( ), cStr ); - return cStr; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return NULLPTR; - } - - bool ManagedCacheableKeyGeneric::operator ==(const gemfire::CacheableKey& other) const + namespace geode { - try { - // now checking classId(), typeId(), DSFID() etc. will be much more - // expensive than just a dynamic_cast - const ManagedCacheableKeyGeneric* p_other = - dynamic_cast<const ManagedCacheableKeyGeneric*>(&other); - if (p_other != NULL) { - return static_cast<GemStone::GemFire::Cache::Generic::ICacheableKey^>( - (static_cast<GemStone::GemFire::Cache::Generic::IGFSerializable^>((GemStone::GemFire::Cache::Generic::IGFSerializable^)m_managedptr)))->Equals( - static_cast<GemStone::GemFire::Cache::Generic::ICacheableKey^>(p_other->ptr())); + namespace client + { + + void ManagedCacheableKeyGeneric::toData(apache::geode::client::DataOutput& output) const + { + try { + uint32 pos = (int)output.getBufferLength(); + //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::toData"); + GemStone::GemFire::Cache::Generic::DataOutput mg_output(&output, true); + m_managedptr->ToData(%mg_output); + //this will move the cursor in c++ layer + mg_output.WriteBytesToUMDataOutput(); + + ManagedCacheableKeyGeneric* tmp = const_cast<ManagedCacheableKeyGeneric*>(this); + tmp->m_objectSize = (int)(output.getBufferLength() - pos); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } } - return false; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return false; - } - - bool ManagedCacheableKeyGeneric::operator ==(const ManagedCacheableKeyGeneric& other) const - { - try { - return static_cast<GemStone::GemFire::Cache::Generic::ICacheableKey^>( - (GemStone::GemFire::Cache::Generic::IGFSerializable^)(GemStone::GemFire::Cache::Generic::IGFSerializable^)m_managedptr)->Equals( - static_cast<GemStone::GemFire::Cache::Generic::ICacheableKey^>(other.ptr())); - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return false; - } - - uint32_t ManagedCacheableKeyGeneric::hashcode( ) const - { - if (m_hashcode != 0) - return m_hashcode; - try { - - ManagedCacheableKeyGeneric* tmp = const_cast<ManagedCacheableKeyGeneric*>(this); - tmp->m_hashcode = ((GemStone::GemFire::Cache::Generic::ICacheableKey^) - (GemStone::GemFire::Cache::Generic::IGFSerializable^)m_managedptr) - ->GetHashCode( ); - return m_hashcode ; - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } - - size_t ManagedCacheableKeyGeneric::logString( char* buffer, size_t maxLength ) const - { - try { - if ( maxLength > 0 ) { - String^ logstr = m_managedptr->GetType( )->Name + '(' + - m_managedptr->ToString( ) + ')'; - GemStone::GemFire::Cache::Generic::ManagedString mg_str( logstr ); - return snprintf( buffer, maxLength, "%s", mg_str.CharPtr ); + + apache::geode::client::Serializable* ManagedCacheableKeyGeneric::fromData(apache::geode::client::DataInput& input) + { + try { + int pos = input.getBytesRead(); + //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::fromData"); + GemStone::GemFire::Cache::Generic::DataInput mg_input(&input, true); + m_managedptr = m_managedptr->FromData(%mg_input); + + //this will move the cursor in c++ layer + input.advanceCursor(mg_input.BytesReadInternally); + m_objectSize = input.getBytesRead() - pos; + //if(m_hashcode == 0) + //m_hashcode = m_managedptr->GetHashCode(); + + + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return this; + } + + uint32_t ManagedCacheableKeyGeneric::objectSize() const + { + try { + int ret = m_managedptr->ObjectSize; + if (ret > m_objectSize) + return ret; + else + return m_objectSize; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; + } + + int32_t ManagedCacheableKeyGeneric::classId() const + { + //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::classid " + m_classId); + /*uint32_t classId; + try { + classId = m_managedptr->ClassId; + } + catch (GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemFireException::ThrowNative(ex); + }*/ + return (m_classId >= 0x80000000 ? 0 : m_classId); } - } - catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { - ex->ThrowNative(); - } - catch (System::Exception^ ex) { - GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); - } - return 0; - } - -} + + int8_t ManagedCacheableKeyGeneric::typeId() const + { + //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::typeId " + m_classId); + if (m_classId >= 0x80000000) { + return (int8_t)((m_classId - 0x80000000) % 0x20000000); + } + else if (m_classId <= 0x7F) { + //GemStone::GemFire::Cache::Generic::Log::Debug("ManagedCacheableKeyGeneric::typeId inin"); + return (int8_t)GemfireTypeIdsImpl::CacheableUserData; + } + else if (m_classId <= 0x7FFF) { + return (int8_t)GemfireTypeIdsImpl::CacheableUserData2; + } + else { + return (int8_t)GemfireTypeIdsImpl::CacheableUserData4; + } + } + + int8_t ManagedCacheableKeyGeneric::DSFID() const + { + // convention that [0x8000000, 0xa0000000) is for FixedIDDefault, + // [0xa000000, 0xc0000000) is for FixedIDByte, + // [0xc0000000, 0xe0000000) is for FixedIDShort + // and [0xe0000000, 0xffffffff] is for FixedIDInt + // Note: depends on fact that FixedIDByte is 1, FixedIDShort is 2 + // and FixedIDInt is 3; if this changes then correct this accordingly + if (m_classId >= 0x80000000) { + return (int8_t)((m_classId - 0x80000000) / 0x20000000); + } + return 0; + } + + apache::geode::client::CacheableStringPtr ManagedCacheableKeyGeneric::toString() const + { + try { + apache::geode::client::CacheableStringPtr cStr; + GemStone::GemFire::Cache::Generic::CacheableString::GetCacheableString( + m_managedptr->ToString(), cStr); + return cStr; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return NULLPTR; + } + + bool ManagedCacheableKeyGeneric::operator ==(const apache::geode::client::CacheableKey& other) const + { + try { + // now checking classId(), typeId(), DSFID() etc. will be much more + // expensive than just a dynamic_cast + const ManagedCacheableKeyGeneric* p_other = + dynamic_cast<const ManagedCacheableKeyGeneric*>(&other); + if (p_other != NULL) { + return static_cast<GemStone::GemFire::Cache::Generic::ICacheableKey^>( + (static_cast<GemStone::GemFire::Cache::Generic::IGFSerializable^>((GemStone::GemFire::Cache::Generic::IGFSerializable^)m_managedptr)))->Equals( + static_cast<GemStone::GemFire::Cache::Generic::ICacheableKey^>(p_other->ptr())); + } + return false; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return false; + } + + bool ManagedCacheableKeyGeneric::operator ==(const ManagedCacheableKeyGeneric& other) const + { + try { + return static_cast<GemStone::GemFire::Cache::Generic::ICacheableKey^>( + (GemStone::GemFire::Cache::Generic::IGFSerializable^)(GemStone::GemFire::Cache::Generic::IGFSerializable^)m_managedptr)->Equals( + static_cast<GemStone::GemFire::Cache::Generic::ICacheableKey^>(other.ptr())); + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return false; + } + + uint32_t ManagedCacheableKeyGeneric::hashcode() const + { + if (m_hashcode != 0) + return m_hashcode; + try { + + ManagedCacheableKeyGeneric* tmp = const_cast<ManagedCacheableKeyGeneric*>(this); + tmp->m_hashcode = ((GemStone::GemFire::Cache::Generic::ICacheableKey^) + (GemStone::GemFire::Cache::Generic::IGFSerializable^)m_managedptr) + ->GetHashCode(); + return m_hashcode; + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; + } + + size_t ManagedCacheableKeyGeneric::logString(char* buffer, size_t maxLength) const + { + try { + if (maxLength > 0) { + String^ logstr = m_managedptr->GetType()->Name + '(' + + m_managedptr->ToString() + ')'; + GemStone::GemFire::Cache::Generic::ManagedString mg_str(logstr); + return snprintf(buffer, maxLength, "%s", mg_str.CharPtr); + } + } + catch (GemStone::GemFire::Cache::Generic::GemFireException^ ex) { + ex->ThrowNative(); + } + catch (System::Exception^ ex) { + GemStone::GemFire::Cache::Generic::GemFireException::ThrowNative(ex); + } + return 0; + } + + } // namespace client + } // namespace geode +} // namespace apache