You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/05/17 17:50:18 UTC
[36/46] geode-native git commit: GEODE-2741: Remove custom shared
pointer from clicache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/Properties.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/Properties.cpp b/src/clicache/src/Properties.cpp
index e7b43c6..53a86ee 100644
--- a/src/clicache/src/Properties.cpp
+++ b/src/clicache/src/Properties.cpp
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-//#include "geode_includes.hpp"
#include "Properties.hpp"
#include "impl/ManagedVisitor.hpp"
#include "impl/ManagedString.hpp"
@@ -33,6 +32,8 @@ namespace Apache
namespace Client
{
+ namespace native = apache::geode::client;
+
// Visitor class to get string representations of a property object
ref class PropertyToString
{
@@ -62,351 +63,80 @@ namespace Apache
generic<class TPropKey, class TPropValue>
TPropValue Properties<TPropKey, TPropValue>::Find( TPropKey key)
{
- //ManagedString mg_key( key );
- apache::geode::client::CacheableKeyPtr keyptr( Serializable::GetUnmanagedValueGeneric<TPropKey>( key ) );
-
- //_GF_MG_EXCEPTION_TRY2
-
- apache::geode::client::CacheablePtr nativeptr(NativePtr->find( keyptr ));
- TPropValue returnVal = Serializable::GetManagedValueGeneric<TPropValue>( nativeptr );
- return returnVal;
-
- //apache::geode::client::CacheablePtr& value = NativePtr->find( keyptr );
- //return SafeUMSerializableConvert( value.ptr( ) );
-
- //apache::geode::client::CacheableStringPtr value = NativePtr->find( mg_key.CharPtr );
- //return CacheableString::GetString( value.ptr( ) );
-
- // _GF_MG_EXCEPTION_CATCH_ALL2
- }
-
- /*IGeodeSerializable^ Properties::Find( Apache::Geode::Client::ICacheableKey^ key)
- {
- CacheableString^ cStr = dynamic_cast<CacheableString ^>(key);
-
- if ( key != nullptr) {
- _GF_MG_EXCEPTION_TRY2
-
- apache::geode::client::CacheableStringPtr csPtr;
-
- CacheableString::GetCacheableString(cStr->Value, csPtr);
-
- apache::geode::client::CacheablePtr& value = NativePtr->find( csPtr );
-
- return ConvertCacheableString(value);
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- else {
- apache::geode::client::CacheableKeyPtr keyptr( SafeMKeyConvert( key ) );
-
- _GF_MG_EXCEPTION_TRY2
-
- apache::geode::client::CacheablePtr& value = NativePtr->find( keyptr );
- return SafeUMSerializableConvert( value.ptr( ) );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- return nullptr;
- }*/
-
- /*
- generic<class TPropKey, class TPropValue>
- IGeodeSerializable^ Properties<TPropKey, TPropValue>::ConvertCacheableString(apache::geode::client::CacheablePtr& value)
- {
- apache::geode::client::CacheableString * cs = dynamic_cast<apache::geode::client::CacheableString *>( value.get() );
- if ( cs == NULL) {
- return SafeUMSerializableConvert( value.ptr( ) );
- }
- else {
- if(cs->typeId() == (int8_t)apache::geode::client::GeodeTypeIds::CacheableASCIIString
- || cs->typeId() == (int8_t)apache::geode::client::GeodeTypeIds::CacheableASCIIStringHuge) {
- String^ str = gcnew String(cs->asChar());
- return CacheableString::Create(str);
- }
- else {
- String^ str = gcnew String(cs->asWChar());
- return CacheableString::Create(str);
- }
- }
- return nullptr;
- }
- */
-
- /*IGeodeSerializable^ Properties::Find( CacheableKey^ key)
- {
- CacheableString^ cStr = dynamic_cast<CacheableString ^>(key);
-
- if ( key != nullptr) {
- _GF_MG_EXCEPTION_TRY2
-
- apache::geode::client::CacheableStringPtr csPtr;
-
- CacheableString::GetCacheableString(cStr->Value, csPtr);
-
- apache::geode::client::CacheablePtr& value = NativePtr->find( csPtr );
-
- return ConvertCacheableString(value);
-
- _GF_MG_EXCEPTION_CATCH_ALL2
+ try
+ {
+ native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TPropKey>(key);
+ auto nativeptr = m_nativeptr->get()->find(keyptr);
+ return Serializable::GetManagedValueGeneric<TPropValue>(nativeptr);
}
- else {
- apache::geode::client::CacheableKeyPtr keyptr(
- (apache::geode::client::CacheableKey*)GetNativePtr<apache::geode::client::Cacheable>( key ) );
-
- _GF_MG_EXCEPTION_TRY2
-
- apache::geode::client::CacheablePtr& value = NativePtr->find( keyptr );
- return SafeUMSerializableConvert( value.ptr( ) );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
}
- return nullptr;
- }*/
+ }
generic<class TPropKey, class TPropValue>
void Properties<TPropKey, TPropValue>::Insert( TPropKey key, TPropValue value )
{
- apache::geode::client::CacheableKeyPtr keyptr( Serializable::GetUnmanagedValueGeneric<TPropKey>( key, true ) );
- apache::geode::client::CacheablePtr valueptr( Serializable::GetUnmanagedValueGeneric<TPropValue>( value, true ) );
-
- //ManagedString mg_key( key );
- //ManagedString mg_value( value );
-
- _GF_MG_EXCEPTION_TRY2
-
- //NativePtr->insert( mg_key.CharPtr, mg_value.CharPtr );
- NativePtr->insert( keyptr, valueptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
-
- /*void Properties::Insert( String^ key, const System::Int32 value)
- {
- //TODO::
- ManagedString mg_key( key );
+ native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TPropKey>(key, true);
+ auto valueptr = Serializable::GetUnmanagedValueGeneric<TPropValue>(value, true);
_GF_MG_EXCEPTION_TRY2
- NativePtr->insert( mg_key.CharPtr, value );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }*/
-
- /*void Properties::Insert( Apache::Geode::Client::ICacheableKey^ key, IGeodeSerializable^ value)
- {
- CacheableString^ cStr = dynamic_cast<CacheableString ^>(key);
- if (cStr != nullptr) {
- _GF_MG_EXCEPTION_TRY2
- apache::geode::client::CacheableKeyPtr keyptr(ConvertCacheableStringKey(cStr));
- CacheableString^ cValueStr = dynamic_cast<CacheableString ^>(value);
-
- if (cValueStr != nullptr) {
- apache::geode::client::CacheablePtr valueptr(ConvertCacheableStringKey(cValueStr));
- NativePtr->insert( keyptr, valueptr );
- }
- else {
- apache::geode::client::CacheablePtr valueptr( SafeMSerializableConvert( value ) );
- NativePtr->insert( keyptr, valueptr );
- }
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- else {
- apache::geode::client::CacheableKeyPtr keyptr( SafeMKeyConvert( key ) );
- apache::geode::client::CacheablePtr valueptr( SafeMSerializableConvert( value ) );
-
- _GF_MG_EXCEPTION_TRY2
-
- NativePtr->insert( keyptr, valueptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- }*/
-
- /*void Properties::Insert( CacheableKey^ key, IGeodeSerializable^ value)
- {
- CacheableString^ cStr = dynamic_cast<CacheableString ^>(key);
- if (cStr != nullptr) {
- _GF_MG_EXCEPTION_TRY2
- apache::geode::client::CacheableKeyPtr keyptr(ConvertCacheableStringKey(cStr));
- CacheableString^ cValueStr = dynamic_cast<CacheableString ^>(value);
-
- if (cValueStr != nullptr) {
- apache::geode::client::CacheablePtr valueptr(ConvertCacheableStringKey(cValueStr));
- NativePtr->insert( keyptr, valueptr );
+ try
+ {
+ m_nativeptr->get()->insert(keyptr, valueptr);
}
- else {
- apache::geode::client::CacheablePtr valueptr( SafeMSerializableConvert( value ) );
- NativePtr->insert( keyptr, valueptr );
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
}
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- else {
- apache::geode::client::CacheableKeyPtr keyptr(
- (apache::geode::client::CacheableKey*)GetNativePtr<apache::geode::client::Cacheable>( key ) );
- apache::geode::client::CacheablePtr valueptr( SafeMSerializableConvert( value ) );
-
- _GF_MG_EXCEPTION_TRY2
-
- NativePtr->insert( keyptr, valueptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- }*/
-
- /*
- generic<class TPropKey, class TPropValue>
- apache::geode::client::CacheableKey * Properties<TPropKey, TPropValue>::ConvertCacheableStringKey(CacheableString^ cStr)
- {
- apache::geode::client::CacheableStringPtr csPtr;
- CacheableString::GetCacheableString(cStr->Value, csPtr);
- return csPtr.get();
+ _GF_MG_EXCEPTION_CATCH_ALL2
}
- */
-
- /*void Properties::Insert( Apache::Geode::Client::ICacheableKey^ key, Serializable^ value)
- {
- CacheableString^ cStr = dynamic_cast<CacheableString ^>(key);
- if (cStr != nullptr) {
- _GF_MG_EXCEPTION_TRY2
- apache::geode::client::CacheableKeyPtr keyptr(ConvertCacheableStringKey(cStr));
- CacheableString^ cValueStr = dynamic_cast<CacheableString ^>(value);
-
- if (cValueStr != nullptr) {
- apache::geode::client::CacheablePtr valueptr(ConvertCacheableStringKey(cValueStr));
- NativePtr->insert( keyptr, valueptr );
- }
- else {
- apache::geode::client::CacheablePtr valueptr(
- GetNativePtr<apache::geode::client::Cacheable>( value ) );
- NativePtr->insert( keyptr, valueptr );
- }
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- else {
- apache::geode::client::CacheableKeyPtr keyptr( SafeMKeyConvert( key ) );
- apache::geode::client::CacheablePtr valueptr(
- GetNativePtr<apache::geode::client::Cacheable>( value ) );
-
- _GF_MG_EXCEPTION_TRY2
-
- NativePtr->insert( keyptr, valueptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- }*/
-
- /*void Properties::Insert( CacheableKey^ key, Serializable^ value)
- {
- CacheableString^ cStr = dynamic_cast<CacheableString ^>(key);
- if (cStr != nullptr) {
- _GF_MG_EXCEPTION_TRY2
- apache::geode::client::CacheableKeyPtr keyptr(ConvertCacheableStringKey(cStr));
- CacheableString^ cValueStr = dynamic_cast<CacheableString ^>(value);
-
- if (cValueStr != nullptr) {
- apache::geode::client::CacheablePtr valueptr(ConvertCacheableStringKey(cValueStr));
- NativePtr->insert( keyptr, valueptr );
- }
- else {
- apache::geode::client::CacheablePtr valueptr(
- GetNativePtr<apache::geode::client::Cacheable>( value ) );
- NativePtr->insert( keyptr, valueptr );
- }
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- else {
- apache::geode::client::CacheableKeyPtr keyptr(
- (apache::geode::client::CacheableKey*)GetNativePtr<apache::geode::client::Cacheable>( key ) );
- apache::geode::client::CacheablePtr valueptr(
- GetNativePtr<apache::geode::client::Cacheable>( value ) );
-
- _GF_MG_EXCEPTION_TRY2
-
- NativePtr->insert( keyptr, valueptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- }*/
generic<class TPropKey, class TPropValue>
void Properties<TPropKey, TPropValue>::Remove( TPropKey key)
{
- //ManagedString mg_key( key );
- apache::geode::client::CacheableKeyPtr keyptr( Serializable::GetUnmanagedValueGeneric<TPropKey>( key ) );
+ native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TPropKey>(key);
_GF_MG_EXCEPTION_TRY2
- //NativePtr->remove( mg_key.CharPtr );
- NativePtr->remove( keyptr );
+ try
+ {
+ m_nativeptr->get()->remove( keyptr );
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2
}
- /*void Properties::Remove( Apache::Geode::Client::ICacheableKey^ key)
- {
- CacheableString^ cStr = dynamic_cast<CacheableString ^>(key);
- if (cStr != nullptr) {
- _GF_MG_EXCEPTION_TRY2
-
- apache::geode::client::CacheableKeyPtr keyptr(ConvertCacheableStringKey(cStr));
-
- NativePtr->remove( keyptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- else {
- apache::geode::client::CacheableKeyPtr keyptr( SafeMKeyConvert( key ) );
-
- _GF_MG_EXCEPTION_TRY2
-
- NativePtr->remove( keyptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- }*/
-
- /*void Properties::Remove( CacheableKey^ key)
- {
- CacheableString^ cStr = dynamic_cast<CacheableString ^>(key);
- if (cStr != nullptr) {
- _GF_MG_EXCEPTION_TRY2
-
- apache::geode::client::CacheableKeyPtr keyptr(ConvertCacheableStringKey(cStr));
-
- NativePtr->remove( keyptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- else {
- apache::geode::client::CacheableKeyPtr keyptr(
- (apache::geode::client::CacheableKey*)GetNativePtr<apache::geode::client::Cacheable>( key ) );
-
- _GF_MG_EXCEPTION_TRY2
-
- NativePtr->remove( keyptr );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
- }*/
-
generic<class TPropKey, class TPropValue>
void Properties<TPropKey, TPropValue>::ForEach( PropertyVisitorGeneric<TPropKey, TPropValue>^ visitor )
{
if (visitor != nullptr)
{
- apache::geode::client::ManagedVisitorGeneric mg_visitor( visitor );
+ native::ManagedVisitorGeneric mg_visitor( visitor );
- PropertyVisitorProxy<TPropKey, TPropValue>^ proxy = gcnew PropertyVisitorProxy<TPropKey, TPropValue>();
+ auto proxy = gcnew PropertyVisitorProxy<TPropKey, TPropValue>();
proxy->SetPropertyVisitorGeneric(visitor);
- PropertyVisitor^ otherVisitor = gcnew PropertyVisitor(proxy, &PropertyVisitorProxy<TPropKey, TPropValue>::Visit);
+ auto otherVisitor = gcnew PropertyVisitor(proxy, &PropertyVisitorProxy<TPropKey, TPropValue>::Visit);
mg_visitor.setptr(otherVisitor);
_GF_MG_EXCEPTION_TRY2
- NativePtr->foreach( mg_visitor );
+ try
+ {
+ m_nativeptr->get()->foreach( mg_visitor );
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2
}
@@ -417,7 +147,14 @@ namespace Apache
{
_GF_MG_EXCEPTION_TRY2
- return NativePtr->getSize( );
+ try
+ {
+ return m_nativeptr->get()->getSize( );
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2
}
@@ -425,15 +162,16 @@ namespace Apache
generic<class TPropKey, class TPropValue>
void Properties<TPropKey, TPropValue>::AddAll( Properties<TPropKey, TPropValue>^ other )
{
- /*apache::geode::client::PropertiesPtr p_other(
- GetNativePtr<apache::geode::client::Properties>( other ) );*/
-
- apache::geode::client::PropertiesPtr p_other(
- GetNativePtrFromSBWrapGeneric<apache::geode::client::Properties>( other ) );
-
_GF_MG_EXCEPTION_TRY2
- NativePtr->addAll( p_other );
+ try
+ {
+ m_nativeptr->get()->addAll( other->GetNative() );
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2
}
@@ -445,7 +183,14 @@ namespace Apache
_GF_MG_EXCEPTION_TRY2
- NativePtr->load( mg_fname.CharPtr );
+ try
+ {
+ m_nativeptr->get()->load( mg_fname.CharPtr );
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2
}
@@ -453,11 +198,6 @@ namespace Apache
generic<class TPropKey, class TPropValue>
String^ Properties<TPropKey, TPropValue>::ToString( )
{
- /* PropertyToString^ propStr = gcnew PropertyToString( );
- this->ForEach( gcnew PropertyVisitorGeneric( propStr,
- &PropertyToString::Visit ) );
- String^ str = propStr->ToString( );
- return ( str + "}" );*/
return "";
}
@@ -471,20 +211,26 @@ namespace Apache
output->WriteBytesToUMDataOutput();
}
- apache::geode::client::DataOutput* nativeOutput =
- GetNativePtr<apache::geode::client::DataOutput>(output);
-
- if (nativeOutput != nullptr)
+ try
{
- _GF_MG_EXCEPTION_TRY2
+ auto nativeOutput = output->GetNative();
+ if (nativeOutput != nullptr)
+ {
+ _GF_MG_EXCEPTION_TRY2
- NativePtr->toData( *nativeOutput );
+ m_nativeptr->get()->toData(*nativeOutput);
- _GF_MG_EXCEPTION_CATCH_ALL2
- }
+ _GF_MG_EXCEPTION_CATCH_ALL2
+ }
- if (output->IsManagedObject()) {
- output->SetBuffer();
+ if (output->IsManagedObject()) {
+ output->SetBuffer();
+ }
+ }
+ finally
+ {
+ GC::KeepAlive(output);
+ GC::KeepAlive(m_nativeptr);
}
}
@@ -494,17 +240,11 @@ namespace Apache
if(input->IsManagedObject()) {
input->AdvanceUMCursor();
}
- //TODO::??
- apache::geode::client::DataInput* nativeInput =
- GetNativePtr<apache::geode::client::DataInput>( input );
+
+ auto nativeInput = input->GetNative();
if (nativeInput != nullptr)
{
- _GF_MG_EXCEPTION_TRY2
-
- AssignPtr( static_cast<apache::geode::client::Properties*>(
- NativePtr->fromData( *nativeInput ) ) );
-
- _GF_MG_EXCEPTION_CATCH_ALL2
+ FromData(*nativeInput);
}
if(input->IsManagedObject()) {
@@ -515,12 +255,39 @@ namespace Apache
}
generic<class TPropKey, class TPropValue>
+ void Properties<TPropKey, TPropValue>::FromData( native::DataInput& input )
+ {
+ _GF_MG_EXCEPTION_TRY2
+
+ try
+ {
+ auto p = static_cast<native::Properties*>(m_nativeptr->get()->fromData(input));
+ if (m_nativeptr->get() != p) {
+ m_nativeptr->get_shared_ptr().reset(p);
+ }
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
+
+ _GF_MG_EXCEPTION_CATCH_ALL2
+ }
+
+ generic<class TPropKey, class TPropValue>
System::UInt32 Properties<TPropKey, TPropValue>::ObjectSize::get( )
{
//TODO::
_GF_MG_EXCEPTION_TRY2
- return NativePtr->objectSize( );
+ try
+ {
+ return m_nativeptr->get()->objectSize( );
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2
}
@@ -531,29 +298,34 @@ namespace Apache
void Properties<TPropKey, TPropValue>::GetObjectData( SerializationInfo^ info,
StreamingContext context )
{
- if (_NativePtr != NULL) {
- apache::geode::client::DataOutput output;
-
- _GF_MG_EXCEPTION_TRY2
-
- NativePtr->toData( output );
+ native::DataOutput output;
- _GF_MG_EXCEPTION_CATCH_ALL2
+ _GF_MG_EXCEPTION_TRY2
- array<Byte>^ bytes = gcnew array<Byte>( output.getBufferLength( ) );
+ try
+ {
+ m_nativeptr->get()->toData( output );
+ }
+ finally
{
- pin_ptr<const Byte> pin_bytes = &bytes[0];
- memcpy( (System::Byte*)pin_bytes, output.getBuffer( ),
- output.getBufferLength( ) );
+ GC::KeepAlive(m_nativeptr);
}
- info->AddValue( "bytes", bytes, array<Byte>::typeid );
+
+ _GF_MG_EXCEPTION_CATCH_ALL2
+
+ auto bytes = gcnew array<Byte>( output.getBufferLength( ) );
+ {
+ pin_ptr<const Byte> pin_bytes = &bytes[0];
+ memcpy( (System::Byte*)pin_bytes, output.getBuffer( ),
+ output.getBufferLength( ) );
}
+ info->AddValue( "bytes", bytes, array<Byte>::typeid );
}
generic<class TPropKey, class TPropValue>
Properties<TPropKey, TPropValue>::Properties( SerializationInfo^ info,
StreamingContext context )
- : SBWrap( apache::geode::client::Properties::create( ).ptr( ) )
+ : Properties()
{
array<Byte>^ bytes = nullptr;
try {
@@ -568,14 +340,11 @@ namespace Apache
_GF_MG_EXCEPTION_TRY2
- apache::geode::client::DataInput input( (System::Byte*)pin_bytes, bytes->Length );
- AssignPtr( static_cast<apache::geode::client::Properties*>(
- NativePtr->fromData( input ) ) );
-
+ native::DataInput input( (System::Byte*)pin_bytes, bytes->Length );
+ FromData(input);
_GF_MG_EXCEPTION_CATCH_ALL2
+ }
+ }
} // namespace Client
} // namespace Geode
} // namespace Apache
-
- }
-}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/Properties.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/Properties.hpp b/src/clicache/src/Properties.hpp
index 4d32558..cf798b6 100644
--- a/src/clicache/src/Properties.hpp
+++ b/src/clicache/src/Properties.hpp
@@ -19,16 +19,19 @@
#include "geode_defs.hpp"
-//#include "impl/NativeWrapper.hpp"
+#include "begin_native.hpp"
+#include <geode/Properties.hpp>
+#include "end_native.hpp"
+
#include "IGeodeSerializable.hpp"
#include "ICacheableKey.hpp"
#include "DataInput.hpp"
#include "DataOutput.hpp"
#include "CacheableString.hpp"
-
-#include "geode/Properties.hpp"
+#include "native_shared_ptr.hpp"
#include "impl/SafeConvert.hpp"
#include "Serializable.hpp"
+#include "native_shared_ptr.hpp"
using namespace System;
using namespace System::Runtime::Serialization;
@@ -40,6 +43,7 @@ namespace Apache
{
namespace Client
{
+ namespace native = apache::geode::client;
delegate void PropertyVisitor(Apache::Geode::Client::ICacheableKey^ key, Apache::Geode::Client::IGeodeSerializable^ value);
@@ -67,7 +71,7 @@ namespace Apache
/// or an integer.
/// </summary>
public ref class Properties sealed
- : public Internal::SBWrap<apache::geode::client::Properties>, public IGeodeSerializable,
+ : public IGeodeSerializable,
public ISerializable
{
public:
@@ -76,7 +80,8 @@ namespace Apache
/// Default constructor: returns an empty collection.
/// </summary>
inline Properties( )
- : SBWrap( apache::geode::client::Properties::create( ).ptr( ) ) { }
+ : Properties(native::Properties::create())
+ {}
/// <summary>
/// Factory method to create an empty collection of properties.
@@ -204,40 +209,6 @@ namespace Apache
// End: ISerializable members
- /// <summary>
- /// Get the underlying native unmanaged pointer.
- /// </summary>
- property void* NativeIntPtr
- {
- inline void* get()
- {
- return _NativePtr;
- }
- }
-
- /*
- inline static IGeodeSerializable^ ConvertCacheableString(apache::geode::client::CacheablePtr& value);
- inline static apache::geode::client::CacheableKey * ConvertCacheableStringKey(CacheableString^ cStr);
- */
-
-
- /// <summary>
- /// Internal factory function to wrap a native object pointer inside
- /// this managed class with null pointer check.
- /// </summary>
- /// <param name="ptr">The native IntPtr pointer</param>
- /// <returns>
- /// The managed wrapper object; null if the native pointer is null.
- /// </returns>
- generic<class TPropKey, class TPropValue>
- static Properties<TPropKey, TPropValue>^ CreateFromVoidPtr(void* ptr)
- {
- apache::geode::client::Properties* nativeptr = (apache::geode::client::Properties*)ptr;
- return ( nativeptr != nullptr ?
- gcnew Properties<TPropKey, TPropValue>( nativeptr ) : nullptr );
- }
-
-
protected:
// For deserialization using the .NET serialization (ISerializable)
@@ -254,35 +225,37 @@ namespace Apache
/// <returns>
/// The managed wrapper object; null if the native pointer is null.
/// </returns>
- generic<class TPropKey, class TPropValue>
- static Properties<TPropKey, TPropValue>^ Create( apache::geode::client::Serializable* nativeptr )
+ //generic<class TPropKey, class TPropValue>
+ static Properties<TPropKey, TPropValue>^ Create( native::PropertiesPtr nativeptr )
{
- return ( nativeptr != nullptr ?
- gcnew Properties<TPropKey, TPropValue>( nativeptr ) : nullptr );
+ return __nullptr == nativeptr ? nullptr :
+ gcnew Properties<TPropKey, TPropValue>( nativeptr );
}
- inline static IGeodeSerializable^ CreateDeserializable( )
+ std::shared_ptr<native::Properties> GetNative()
{
- return Create<String^, String^>( );
+ return m_nativeptr->get_shared_ptr();
}
- /// <summary>
- /// Factory function to register wrapper
- /// </summary>
- inline static IGeodeSerializable^ CreateDeserializable(
- apache::geode::client::Serializable* nativeptr )
+ inline static IGeodeSerializable^ CreateDeserializable( )
{
- return Create<String^, String^>( nativeptr );
+ return Create<String^, String^>();
}
- internal:
+ private:
/// <summary>
/// Private constructor to wrap a native object pointer
/// </summary>
/// <param name="nativeptr">The native object pointer</param>
- inline Properties( apache::geode::client::Serializable* nativeptr )
- : SBWrap( (apache::geode::client::Properties*)nativeptr ) { }
+ inline Properties( native::PropertiesPtr nativeptr )
+ {
+ m_nativeptr = gcnew native_shared_ptr<native::Properties>(nativeptr);
+ }
+
+ native_shared_ptr<native::Properties>^ m_nativeptr;
+
+ void FromData(native::DataInput & input);
};
generic <class TPropKey, class TPropValue>
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/Query.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/Query.cpp b/src/clicache/src/Query.cpp
index 4723b3f..f1041f8 100644
--- a/src/clicache/src/Query.cpp
+++ b/src/clicache/src/Query.cpp
@@ -44,25 +44,14 @@ namespace Apache
{
_GF_MG_EXCEPTION_TRY2/* due to auto replace */
- apache::geode::client::SelectResultsPtr& nativeptr = NativePtr->execute( timeout );
- if ( nativeptr.ptr( ) == NULL ) return nullptr;
-
- apache::geode::client::ResultSet* resultptr = dynamic_cast<apache::geode::client::ResultSet*>(
- nativeptr.ptr( ) );
- if ( resultptr == NULL )
+ try
{
- apache::geode::client::StructSet* structptr = dynamic_cast<apache::geode::client::StructSet*>(
- nativeptr.ptr( ) );
- if ( structptr == NULL )
- {
- return nullptr;
- }
- return StructSet<TResult>::Create(structptr);
+ return WrapResults( m_nativeptr->get()->execute( timeout ));
}
- else
+ finally
{
- return ResultSet<TResult>::Create(resultptr);
- }
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
}
@@ -78,40 +67,53 @@ namespace Apache
{
_GF_MG_EXCEPTION_TRY2/* due to auto replace */
- apache::geode::client::CacheableVectorPtr rsptr = apache::geode::client::CacheableVector::create();
- for( int index = 0; index < paramList->Length; index++ )
- {
- apache::geode::client::CacheablePtr valueptr( Serializable::GetUnmanagedValueGeneric<Object^>(paramList[index]->GetType(), (Object^)paramList[index]) ) ;
- rsptr->push_back(valueptr);
- }
-
- apache::geode::client::SelectResultsPtr& nativeptr = NativePtr->execute(rsptr, timeout );
- if ( nativeptr.ptr( ) == NULL ) return nullptr;
-
- apache::geode::client::ResultSet* resultptr = dynamic_cast<apache::geode::client::ResultSet*>(
- nativeptr.ptr( ) );
- if ( resultptr == NULL )
- {
- apache::geode::client::StructSet* structptr = dynamic_cast<apache::geode::client::StructSet*>(
- nativeptr.ptr( ) );
- if ( structptr == NULL )
+ auto rsptr = apache::geode::client::CacheableVector::create();
+ for( int index = 0; index < paramList->Length; index++ )
{
- return nullptr;
+ auto valueptr = Serializable::GetUnmanagedValueGeneric<Object^>(paramList[index]->GetType(), (Object^)paramList[index]);
+ rsptr->push_back(valueptr);
+ }
+
+ try
+ {
+ return WrapResults( m_nativeptr->get()->execute(rsptr, timeout ));
}
- return StructSet<TResult>::Create(structptr);
- }
- else
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
+
+ _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+ }
+
+ generic<class TResult>
+ ISelectResults<TResult>^ Query<TResult>::WrapResults(const apache::geode::client::SelectResultsPtr& selectResults)
+ {
+ if ( __nullptr == selectResults ) return nullptr;
+
+ if (auto resultptr = std::dynamic_pointer_cast<apache::geode::client::ResultSet>(selectResults))
{
return ResultSet<TResult>::Create(resultptr);
}
+ else if (auto structptr = std::dynamic_pointer_cast<apache::geode::client::StructSet>(selectResults))
+ {
+ return StructSet<TResult>::Create(structptr);
+ }
- _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+ return nullptr;
}
generic<class TResult>
String^ Query<TResult>::QueryString::get( )
{
- return ManagedString::Get( NativePtr->getQueryString( ) );
+ try
+ {
+ return ManagedString::Get( m_nativeptr->get()->getQueryString( ) );
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TResult>
@@ -119,21 +121,34 @@ namespace Apache
{
_GF_MG_EXCEPTION_TRY2/* due to auto replace */
- NativePtr->compile( );
+ try
+ {
+ m_nativeptr->get()->compile( );
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
}
generic<class TResult>
- bool Query<TResult>::IsCompiled::get( )
+ bool Query<TResult>::IsCompiled::get()
{
_GF_MG_EXCEPTION_TRY2/* due to auto replace */
- return NativePtr->isCompiled( );
+ try
+ {
+ return m_nativeptr->get()->isCompiled();
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
_GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+ }
} // namespace Client
} // namespace Geode
} // namespace Apache
-
- } //namespace
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/Query.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/Query.hpp b/src/clicache/src/Query.hpp
index 2166911..951cd2c 100644
--- a/src/clicache/src/Query.hpp
+++ b/src/clicache/src/Query.hpp
@@ -18,8 +18,11 @@
#pragma once
#include "geode_defs.hpp"
+#include "begin_native.hpp"
#include <geode/Query.hpp>
-#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+
+#include "native_shared_ptr.hpp"
#include "IGeodeSerializable.hpp"
@@ -31,6 +34,7 @@ namespace Apache
{
namespace Client
{
+ namespace native = apache::geode::client;
generic<class TResult>
interface class ISelectResults;
@@ -50,7 +54,6 @@ namespace Apache
/// </remarks>
generic<class TResult>
public ref class Query sealed
- : public Internal::SBWrap<apache::geode::client::Query>
{
public:
@@ -188,10 +191,10 @@ namespace Apache
/// <returns>
/// The managed wrapper object; null if the native pointer is null.
/// </returns>
- inline static Query<TResult>^ Create( apache::geode::client::Query* nativeptr )
+ inline static Query<TResult>^ Create( apache::geode::client::QueryPtr nativeptr )
{
- return ( nativeptr != nullptr ?
- gcnew Query<TResult>( nativeptr ) : nullptr );
+ return __nullptr == nativeptr ? nullptr :
+ gcnew Query<TResult>( nativeptr );
}
@@ -201,8 +204,14 @@ namespace Apache
/// Private constructor to wrap a native object pointer
/// </summary>
/// <param name="nativeptr">The native object pointer</param>
- inline Query( apache::geode::client::Query* nativeptr )
- : SBWrap( nativeptr ) { }
+ inline Query( apache::geode::client::QueryPtr nativeptr )
+ {
+ m_nativeptr = gcnew native_shared_ptr<native::Query>(nativeptr);
+ }
+
+ ISelectResults<TResult>^ WrapResults(const apache::geode::client::SelectResultsPtr& selectResults);
+
+ native_shared_ptr<native::Query>^ m_nativeptr;
};
} // namespace Client
} // namespace Geode
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/QueryService.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/QueryService.cpp b/src/clicache/src/QueryService.cpp
index f4301e8..c5b328a 100644
--- a/src/clicache/src/QueryService.cpp
+++ b/src/clicache/src/QueryService.cpp
@@ -40,29 +40,38 @@ namespace Apache
Query<TResult>^ QueryService<TKey, TResult>::NewQuery(String^ query)
{
ManagedString mg_queryStr(query);
-
- _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-
- return Query<TResult>::Create(NativePtr->newQuery(
- mg_queryStr.CharPtr).get());
-
- _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+ try
+ {
+ return Query<TResult>::Create(m_nativeptr->get()->newQuery(
+ mg_queryStr.CharPtr));
+ }
+ catch (const apache::geode::client::Exception& ex)
+ {
+ throw GeodeException::Get(ex);
+ }
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
CqQuery<TKey, TResult>^ QueryService<TKey, TResult>::NewCq(String^ query, CqAttributes<TKey, TResult>^ cqAttr, bool isDurable)
{
ManagedString mg_queryStr(query);
- apache::geode::client::CqAttributesPtr attr(GetNativePtrFromSBWrapGeneric<apache::geode::client::CqAttributes>(cqAttr));
try
{
- return CqQuery<TKey, TResult>::Create(NativePtr->newCq(
- mg_queryStr.CharPtr, attr, isDurable).get());
+ return CqQuery<TKey, TResult>::Create(m_nativeptr->get()->newCq(
+ mg_queryStr.CharPtr, cqAttr->GetNative(), isDurable));
}
catch (const apache::geode::client::Exception& ex)
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
@@ -70,16 +79,19 @@ namespace Apache
{
ManagedString mg_queryStr(query);
ManagedString mg_nameStr(name);
- apache::geode::client::CqAttributesPtr attr(GetNativePtrFromSBWrapGeneric<apache::geode::client::CqAttributes>(cqAttr));
try
{
- return CqQuery<TKey, TResult>::Create(NativePtr->newCq(
- mg_nameStr.CharPtr, mg_queryStr.CharPtr, attr, isDurable).get());
+ return CqQuery<TKey, TResult>::Create(m_nativeptr->get()->newCq(
+ mg_nameStr.CharPtr, mg_queryStr.CharPtr, cqAttr->GetNative(), isDurable));
}
catch (const apache::geode::client::Exception& ex)
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
@@ -87,12 +99,16 @@ namespace Apache
{
try
{
- NativePtr->closeCqs();
+ m_nativeptr->get()->closeCqs();
}
catch (const apache::geode::client::Exception& ex)
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
@@ -100,13 +116,13 @@ namespace Apache
{
try
{
- apache::geode::client::VectorOfCqQuery vrr;
- NativePtr->getCqs(vrr);
- array<CqQuery<TKey, TResult>^>^ cqs = gcnew array<CqQuery<TKey, TResult>^>(vrr.size());
+ apache::geode::client::QueryService::query_container_type vrr;
+ m_nativeptr->get()->getCqs(vrr);
+ auto cqs = gcnew array<CqQuery<TKey, TResult>^>(vrr.size());
for (System::Int32 index = 0; index < vrr.size(); index++)
{
- cqs[index] = CqQuery<TKey, TResult>::Create(vrr[index].get());
+ cqs[index] = CqQuery<TKey, TResult>::Create(vrr[index]);
}
return cqs;
}
@@ -114,6 +130,10 @@ namespace Apache
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
@@ -122,13 +142,17 @@ namespace Apache
ManagedString mg_queryStr(name);
try
{
- return CqQuery<TKey, TResult>::Create(NativePtr->getCq(
- mg_queryStr.CharPtr).get());
+ return CqQuery<TKey, TResult>::Create(m_nativeptr->get()->getCq(
+ mg_queryStr.CharPtr));
}
catch (const apache::geode::client::Exception& ex)
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
@@ -136,12 +160,16 @@ namespace Apache
{
try
{
- NativePtr->executeCqs();
+ m_nativeptr->get()->executeCqs();
}
catch (const apache::geode::client::Exception& ex)
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
@@ -149,12 +177,16 @@ namespace Apache
{
try
{
- NativePtr->stopCqs();
+ m_nativeptr->get()->stopCqs();
}
catch (const apache::geode::client::Exception& ex)
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
@@ -162,12 +194,16 @@ namespace Apache
{
try
{
- return CqServiceStatistics::Create(NativePtr->getCqServiceStatistics().get());
+ return CqServiceStatistics::Create(m_nativeptr->get()->getCqServiceStatistics());
}
catch (const apache::geode::client::Exception& ex)
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
generic<class TKey, class TResult>
@@ -175,15 +211,12 @@ namespace Apache
{
try
{
- apache::geode::client::CacheableArrayListPtr durableCqsArrayListPtr = NativePtr->getAllDurableCqsFromServer();
+ auto durableCqsArrayListPtr = m_nativeptr->get()->getAllDurableCqsFromServer();
int length = durableCqsArrayListPtr != nullptr ? durableCqsArrayListPtr->length() : 0;
- System::Collections::Generic::List<String^>^ durableCqsList = gcnew System::Collections::Generic::List<String^>();
- if (length > 0)
+ auto durableCqsList = gcnew System::Collections::Generic::List<String^>();
+ for (int i = 0; i < length; i++)
{
- for (int i = 0; i < length; i++)
- {
- durableCqsList->Add(CacheableString::GetString(durableCqsArrayListPtr->at(i)));
- }
+ durableCqsList->Add(CacheableString::GetString(std::static_pointer_cast<apache::geode::client::CacheableString>(durableCqsArrayListPtr->at(i))));
}
return durableCqsList;
}
@@ -191,6 +224,10 @@ namespace Apache
{
throw GeodeException::Get(ex);
}
+ finally
+ {
+ GC::KeepAlive(m_nativeptr);
+ }
}
} // namespace Client
} // namespace Geode
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/QueryService.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/QueryService.hpp b/src/clicache/src/QueryService.hpp
index 6845ee1..78d29ef 100644
--- a/src/clicache/src/QueryService.hpp
+++ b/src/clicache/src/QueryService.hpp
@@ -18,8 +18,11 @@
#pragma once
#include "geode_defs.hpp"
-#include "impl/NativeWrapper.hpp"
+#include "native_shared_ptr.hpp"
+#include "begin_native.hpp"
#include <geode/QueryService.hpp>
+#include "end_native.hpp"
+
@@ -32,6 +35,8 @@ namespace Apache
namespace Client
{
+ namespace native = apache::geode::client;
+
generic<class TResult>
ref class Query;
@@ -48,7 +53,6 @@ namespace Apache
/// </summary>
generic<class TKey, class TResult>
public ref class QueryService sealed
- : public Internal::SBWrap<apache::geode::client::QueryService>
{
public:
@@ -132,10 +136,10 @@ namespace Apache
/// <returns>
/// The managed wrapper object; null if the native pointer is null.
/// </returns>
- inline static Apache::Geode::Client::QueryService<TKey, TResult>^ Create( apache::geode::client::QueryService* nativeptr )
+ inline static QueryService<TKey, TResult>^ Create(native::QueryServicePtr nativeptr )
{
- return ( nativeptr != nullptr ?
- gcnew Apache::Geode::Client::QueryService<TKey, TResult>( nativeptr ) : nullptr );
+ return __nullptr == nativeptr ? nullptr :
+ gcnew QueryService<TKey, TResult>( nativeptr );
}
@@ -145,8 +149,12 @@ namespace Apache
/// Private constructor to wrap a native object pointer
/// </summary>
/// <param name="nativeptr">The native object pointer</param>
- inline QueryService( apache::geode::client::QueryService* nativeptr )
- : SBWrap( nativeptr ) { }
+ inline QueryService(native::QueryServicePtr nativeptr)
+ {
+ m_nativeptr = gcnew native_shared_ptr<native::QueryService>(nativeptr);
+ }
+
+ native_shared_ptr<native::QueryService>^ m_nativeptr;
};
} // namespace Client
} // namespace Geode