http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/RegionEvent.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/RegionEvent.cpp b/src/clicache/src/RegionEvent.cpp index ff3bb9d..3ee64d2 100644 --- a/src/clicache/src/RegionEvent.cpp +++ b/src/clicache/src/RegionEvent.cpp @@ -15,7 +15,6 @@ * limitations under the License. */ -//#include "geode_includes.hpp" #include "RegionEvent.hpp" #include "Region.hpp" #include "IGeodeSerializable.hpp" @@ -30,42 +29,23 @@ namespace Apache { generic<class TKey, class TValue> - RegionEvent<TKey, TValue>::RegionEvent(Client::IRegion<TKey, TValue>^ region, - Object^ aCallbackArgument, bool remoteOrigin) - : UMWrap( ) - { - //TODO:: do we neeed this - /*if ( region == nullptr ) { - throw gcnew IllegalArgumentException( "RegionEvent.ctor(): " - "null region passed" ); - } - - apache::geode::client::UserDataPtr callbackptr(SafeMSerializableConvert( - aCallbackArgument)); - - SetPtr(new apache::geode::client::RegionEvent(apache::geode::client::RegionPtr(region->_NativePtr), - callbackptr, remoteOrigin), true);*/ - } - - generic<class TKey, class TValue> IRegion<TKey, TValue>^ RegionEvent<TKey, TValue>::Region::get( ) { - apache::geode::client::RegionPtr& regionptr( NativePtr->getRegion( ) ); - - return Client::Region<TKey, TValue>::Create( regionptr.ptr( ) ); + auto regionptr = m_nativeptr->getRegion( ); + return Client::Region<TKey, TValue>::Create( regionptr ); } generic<class TKey, class TValue> Object^ RegionEvent<TKey, TValue>::CallbackArgument::get() { - apache::geode::client::UserDataPtr& valptr(NativePtr->getCallbackArgument()); + apache::geode::client::UserDataPtr& valptr(m_nativeptr->getCallbackArgument()); return Serializable::GetManagedValueGeneric<Object^>( valptr ); } generic<class TKey, class TValue> bool RegionEvent<TKey, TValue>::RemoteOrigin::get( ) { - return NativePtr->remoteOrigin( ); + return m_nativeptr->remoteOrigin( ); } // namespace Client } // namespace Geode } // namespace Apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/RegionEvent.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/RegionEvent.hpp b/src/clicache/src/RegionEvent.hpp index 1d9f23d..7554c13 100644 --- a/src/clicache/src/RegionEvent.hpp +++ b/src/clicache/src/RegionEvent.hpp @@ -18,8 +18,10 @@ #pragma once #include "geode_defs.hpp" +#include "begin_native.hpp" #include <geode/RegionEvent.hpp> -//#include "impl/NativeWrapper.hpp" +#include "end_native.hpp" + #include "IGeodeSerializable.hpp" #include "IRegion.hpp" #include "Region.hpp" @@ -32,6 +34,7 @@ namespace Apache { namespace Client { + namespace native = apache::geode::client; //ref class Region; @@ -40,20 +43,10 @@ namespace Apache /// </summary> generic<class TKey, class TValue> public ref class RegionEvent sealed - : public Client::Internal::UMWrap<apache::geode::client::RegionEvent> { public: /// <summary> - /// Constructor to create a <c>RegionEvent</c> for a given region. - /// </summary> - /// <exception cref="IllegalArgumentException"> - /// if region is null - /// </exception> - RegionEvent(IRegion<TKey, TValue>^ region, Object^ aCallbackArgument, - bool remoteOrigin); - - /// <summary> /// Return the region this event occurred in. /// </summary> property IRegion<TKey, TValue>^ Region @@ -82,13 +75,22 @@ namespace Apache internal: + const native::RegionEvent* GetNative() + { + return m_nativeptr; + } + /// <summary> /// Internal constructor to wrap a native object pointer /// </summary> /// <param name="nativeptr">The native object pointer</param> - inline Apache::Geode::Client::RegionEvent<TKey, TValue>( const apache::geode::client::RegionEvent* nativeptr ) - : Apache::Geode::Client::Internal::UMWrap<apache::geode::client::RegionEvent>( - const_cast<apache::geode::client::RegionEvent*>( nativeptr ), false ) { } + inline Apache::Geode::Client::RegionEvent<TKey, TValue>( const native::RegionEvent* nativeptr ) + : m_nativeptr( nativeptr ) + { + } + + private: + const native::RegionEvent* m_nativeptr; }; } // namespace Client } // namespace Geode http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/RegionFactory.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/RegionFactory.cpp b/src/clicache/src/RegionFactory.cpp index 93a5e7a..f662a7c 100644 --- a/src/clicache/src/RegionFactory.cpp +++ b/src/clicache/src/RegionFactory.cpp @@ -17,9 +17,7 @@ #pragma once -//#include "geode_includes.hpp" #include "RegionFactory.hpp" -//#include "AttributesFactory.hpp" #include "RegionAttributes.hpp" #include "impl/SafeConvert.hpp" @@ -49,6 +47,7 @@ namespace Apache { namespace Client { + namespace native = apache::geode::client; RegionFactory^ RegionFactory::SetCacheLoader( String^ libPath, String^ factoryFunctionName ) { @@ -56,8 +55,14 @@ namespace Apache ManagedString mg_libpath( libPath ); ManagedString mg_factoryFunctionName( factoryFunctionName ); - NativePtr->setCacheLoader( mg_libpath.CharPtr, - mg_factoryFunctionName.CharPtr ); + try + { + m_nativeptr->get()->setCacheLoader( mg_libpath.CharPtr, mg_factoryFunctionName.CharPtr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } @@ -67,8 +72,14 @@ namespace Apache ManagedString mg_libpath( libPath ); ManagedString mg_factoryFunctionName( factoryFunctionName ); - NativePtr->setCacheWriter( mg_libpath.CharPtr, - mg_factoryFunctionName.CharPtr ); + try + { + m_nativeptr->get()->setCacheWriter( mg_libpath.CharPtr, mg_factoryFunctionName.CharPtr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } @@ -78,8 +89,14 @@ namespace Apache ManagedString mg_libpath( libPath ); ManagedString mg_factoryFunctionName( factoryFunctionName ); - NativePtr->setCacheListener( mg_libpath.CharPtr, - mg_factoryFunctionName.CharPtr ); + try + { + m_nativeptr->get()->setCacheListener( mg_libpath.CharPtr, mg_factoryFunctionName.CharPtr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } @@ -89,8 +106,14 @@ namespace Apache ManagedString mg_libpath( libPath ); ManagedString mg_factoryFunctionName( factoryFunctionName ); - NativePtr->setPartitionResolver( mg_libpath.CharPtr, - mg_factoryFunctionName.CharPtr ); + try + { + m_nativeptr->get()->setPartitionResolver( mg_libpath.CharPtr, mg_factoryFunctionName.CharPtr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } @@ -98,29 +121,53 @@ namespace Apache RegionFactory^ RegionFactory::SetEntryIdleTimeout( ExpirationAction action, System::UInt32 idleTimeout ) { - NativePtr->setEntryIdleTimeout( - static_cast<apache::geode::client::ExpirationAction::Action>( action ), idleTimeout ); + try + { + m_nativeptr->get()->setEntryIdleTimeout( static_cast<native::ExpirationAction::Action>( action ), idleTimeout ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } RegionFactory^ RegionFactory::SetEntryTimeToLive( ExpirationAction action, System::UInt32 timeToLive ) { - NativePtr->setEntryTimeToLive( - static_cast<apache::geode::client::ExpirationAction::Action>( action ), timeToLive ); + try + { + m_nativeptr->get()->setEntryTimeToLive(static_cast<native::ExpirationAction::Action>( action ), timeToLive ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } RegionFactory^ RegionFactory::SetRegionIdleTimeout( ExpirationAction action, System::UInt32 idleTimeout ) { - NativePtr->setRegionIdleTimeout( - static_cast<apache::geode::client::ExpirationAction::Action>( action ), idleTimeout ); + try + { + m_nativeptr->get()->setRegionIdleTimeout(static_cast<native::ExpirationAction::Action>( action ), idleTimeout ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } RegionFactory^ RegionFactory::SetRegionTimeToLive( ExpirationAction action, System::UInt32 timeToLive ) { - NativePtr->setRegionTimeToLive( - static_cast<apache::geode::client::ExpirationAction::Action>( action ), timeToLive ); + try + { + m_nativeptr->get()->setRegionTimeToLive(static_cast<native::ExpirationAction::Action>( action ), timeToLive ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } @@ -130,15 +177,21 @@ namespace Apache RegionFactory^ RegionFactory::SetPersistenceManager( Client::IPersistenceManager<TKey, TValue>^ persistenceManager, Properties<String^, String^>^ config) { - apache::geode::client::PersistenceManagerPtr persistenceManagerptr; + native::PersistenceManagerPtr persistenceManagerptr; if ( persistenceManager != nullptr ) { PersistenceManagerGeneric<TKey, TValue>^ clg = gcnew PersistenceManagerGeneric<TKey, TValue>(); clg->SetPersistenceManager(persistenceManager); - persistenceManagerptr = new apache::geode::client::ManagedPersistenceManagerGeneric( /*clg,*/ persistenceManager); - ((apache::geode::client::ManagedPersistenceManagerGeneric*)persistenceManagerptr.get())->setptr(clg); + persistenceManagerptr = std::shared_ptr<native::ManagedPersistenceManagerGeneric>(new native::ManagedPersistenceManagerGeneric(persistenceManager)); + ((native::ManagedPersistenceManagerGeneric*)persistenceManagerptr.get())->setptr(clg); + } + try + { + m_nativeptr->get()->setPersistenceManager( persistenceManagerptr, config->GetNative() ); + } + finally + { + GC::KeepAlive(m_nativeptr); } - apache::geode::client::PropertiesPtr configptr(GetNativePtr<apache::geode::client::Properties>( config ) ); - NativePtr->setPersistenceManager( persistenceManagerptr, configptr ); return this; } @@ -160,12 +213,15 @@ namespace Apache { ManagedString mg_libpath( libPath ); ManagedString mg_factoryFunctionName( factoryFunctionName ); - //TODO:split - apache::geode::client::PropertiesPtr configptr( - GetNativePtr<apache::geode::client::Properties>( config ) ); - NativePtr->setPersistenceManager( mg_libpath.CharPtr, - mg_factoryFunctionName.CharPtr, configptr ); + try + { + m_nativeptr->get()->setPersistenceManager( mg_libpath.CharPtr, mg_factoryFunctionName.CharPtr, config->GetNative() ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } @@ -173,7 +229,14 @@ namespace Apache { ManagedString mg_poolName( poolName ); - NativePtr->setPoolName( mg_poolName.CharPtr ); + try + { + m_nativeptr->get()->setPoolName( mg_poolName.CharPtr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } @@ -183,7 +246,14 @@ namespace Apache { _GF_MG_EXCEPTION_TRY2 - NativePtr->setInitialCapacity( initialCapacity ); + try + { + m_nativeptr->get()->setInitialCapacity( initialCapacity ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; _GF_MG_EXCEPTION_CATCH_ALL2 @@ -193,7 +263,14 @@ namespace Apache { _GF_MG_EXCEPTION_TRY2 - NativePtr->setLoadFactor( loadFactor ); + try + { + m_nativeptr->get()->setLoadFactor( loadFactor ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; _GF_MG_EXCEPTION_CATCH_ALL2 @@ -203,7 +280,14 @@ namespace Apache { _GF_MG_EXCEPTION_TRY2 - NativePtr->setConcurrencyLevel( concurrencyLevel ); + try + { + m_nativeptr->get()->setConcurrencyLevel( concurrencyLevel ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; _GF_MG_EXCEPTION_CATCH_ALL2 @@ -211,32 +295,66 @@ namespace Apache RegionFactory^ RegionFactory::SetLruEntriesLimit( System::UInt32 entriesLimit ) { - NativePtr->setLruEntriesLimit( entriesLimit ); + try + { + m_nativeptr->get()->setLruEntriesLimit( entriesLimit ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } RegionFactory^ RegionFactory::SetDiskPolicy( DiskPolicyType diskPolicy ) { - NativePtr->setDiskPolicy( - static_cast<apache::geode::client::DiskPolicyType::PolicyType>( diskPolicy ) ); + try + { + m_nativeptr->get()->setDiskPolicy(static_cast<native::DiskPolicyType::PolicyType>( diskPolicy ) ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } RegionFactory^ RegionFactory::SetCachingEnabled( bool cachingEnabled ) { - NativePtr->setCachingEnabled( cachingEnabled ); + try + { + m_nativeptr->get()->setCachingEnabled( cachingEnabled ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } RegionFactory^ RegionFactory::SetCloningEnabled( bool cloningEnabled ) { - NativePtr->setCloningEnabled( cloningEnabled ); + try + { + m_nativeptr->get()->setCloningEnabled( cloningEnabled ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } RegionFactory^ RegionFactory::SetConcurrencyChecksEnabled( bool concurrencyChecksEnabled ) { - NativePtr->setConcurrencyChecksEnabled( concurrencyChecksEnabled ); + try + { + m_nativeptr->get()->setConcurrencyChecksEnabled( concurrencyChecksEnabled ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } // NEW GENERIC APIs: @@ -246,11 +364,16 @@ namespace Apache { _GF_MG_EXCEPTION_TRY2/* due to auto replace */ - ManagedString mg_name( regionName ); - - apache::geode::client::RegionPtr& nativeptr( NativePtr->create( - mg_name.CharPtr ) ); - return Client::Region<TKey,TValue>::Create( nativeptr.ptr( ) ); + try + { + ManagedString mg_name( regionName ); + auto nativeptr = m_nativeptr->get()->create( mg_name.CharPtr ); + return Client::Region<TKey,TValue>::Create( nativeptr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ } @@ -258,73 +381,101 @@ namespace Apache generic <class TKey, class TValue> RegionFactory^ RegionFactory::SetCacheLoader( Client::ICacheLoader<TKey, TValue>^ cacheLoader ) { - apache::geode::client::CacheLoaderPtr loaderptr; + native::CacheLoaderPtr loaderptr; if ( cacheLoader != nullptr ) { CacheLoaderGeneric<TKey, TValue>^ clg = gcnew CacheLoaderGeneric<TKey, TValue>(); clg->SetCacheLoader(cacheLoader); - loaderptr = new apache::geode::client::ManagedCacheLoaderGeneric( /*clg,*/ cacheLoader ); - ((apache::geode::client::ManagedCacheLoaderGeneric*)loaderptr.get())->setptr(clg); + loaderptr = std::shared_ptr<native::ManagedCacheLoaderGeneric>(new native::ManagedCacheLoaderGeneric(cacheLoader)); + ((native::ManagedCacheLoaderGeneric*)loaderptr.get())->setptr(clg); + } + try + { + m_nativeptr->get()->setCacheLoader( loaderptr ); + } + finally + { + GC::KeepAlive(m_nativeptr); } - NativePtr->setCacheLoader( loaderptr ); return this; } generic <class TKey, class TValue> RegionFactory^ RegionFactory::SetCacheWriter( Client::ICacheWriter<TKey, TValue>^ cacheWriter ) { - apache::geode::client::CacheWriterPtr writerptr; + native::CacheWriterPtr writerptr; if ( cacheWriter != nullptr ) { CacheWriterGeneric<TKey, TValue>^ cwg = gcnew CacheWriterGeneric<TKey, TValue>(); cwg->SetCacheWriter(cacheWriter); - writerptr = new apache::geode::client::ManagedCacheWriterGeneric( /*cwg,*/ cacheWriter ); - ((apache::geode::client::ManagedCacheWriterGeneric*)writerptr.get())->setptr(cwg); + writerptr = std::shared_ptr<native::ManagedCacheWriterGeneric>(new native::ManagedCacheWriterGeneric(cacheWriter)); + ((native::ManagedCacheWriterGeneric*)writerptr.get())->setptr(cwg); + } + try + { + m_nativeptr->get()->setCacheWriter( writerptr ); + } + finally + { + GC::KeepAlive(m_nativeptr); } - NativePtr->setCacheWriter( writerptr ); return this; } generic <class TKey, class TValue> RegionFactory^ RegionFactory::SetCacheListener( Client::ICacheListener<TKey, TValue>^ cacheListener ) { - apache::geode::client::CacheListenerPtr listenerptr; + native::CacheListenerPtr listenerptr; if ( cacheListener != nullptr ) { CacheListenerGeneric<TKey, TValue>^ clg = gcnew CacheListenerGeneric<TKey, TValue>(); clg->SetCacheListener(cacheListener); - listenerptr = new apache::geode::client::ManagedCacheListenerGeneric( /*clg,*/ cacheListener ); - ((apache::geode::client::ManagedCacheListenerGeneric*)listenerptr.get())->setptr(clg); + listenerptr = std::shared_ptr<native::ManagedCacheListenerGeneric>(new native::ManagedCacheListenerGeneric(cacheListener)); + ((native::ManagedCacheListenerGeneric*)listenerptr.get())->setptr(clg); /* - listenerptr = new apache::geode::client::ManagedCacheListenerGeneric( + listenerptr = new native::ManagedCacheListenerGeneric( (Client::ICacheListener<Object^, Object^>^)cacheListener); */ } - NativePtr->setCacheListener( listenerptr ); + try + { + m_nativeptr->get()->setCacheListener( listenerptr ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } return this; } generic <class TKey, class TValue> - RegionFactory^ RegionFactory::SetPartitionResolver( Client::IPartitionResolver<TKey, TValue>^ partitionresolver ) + RegionFactory^ RegionFactory::SetPartitionResolver(Client::IPartitionResolver<TKey, TValue>^ partitionresolver) { - apache::geode::client::PartitionResolverPtr resolverptr; - if ( partitionresolver != nullptr ) { - Client::IFixedPartitionResolver<TKey, TValue>^ resolver = + native::PartitionResolverPtr resolverptr; + if (partitionresolver != nullptr) { + Client::IFixedPartitionResolver<TKey, TValue>^ resolver = dynamic_cast<Client::IFixedPartitionResolver<TKey, TValue>^>(partitionresolver); - if (resolver != nullptr) { + if (resolver != nullptr) { FixedPartitionResolverGeneric<TKey, TValue>^ prg = gcnew FixedPartitionResolverGeneric<TKey, TValue>(); prg->SetPartitionResolver(resolver); - resolverptr = new apache::geode::client::ManagedFixedPartitionResolverGeneric( resolver ); - ((apache::geode::client::ManagedFixedPartitionResolverGeneric*)resolverptr.get())->setptr(prg); + resolverptr = std::shared_ptr<native::ManagedFixedPartitionResolverGeneric>(new native::ManagedFixedPartitionResolverGeneric(resolver)); + ((native::ManagedFixedPartitionResolverGeneric*)resolverptr.get())->setptr(prg); } - else { + else { PartitionResolverGeneric<TKey, TValue>^ prg = gcnew PartitionResolverGeneric<TKey, TValue>(); prg->SetPartitionResolver(partitionresolver); - resolverptr = new apache::geode::client::ManagedPartitionResolverGeneric( partitionresolver ); - ((apache::geode::client::ManagedPartitionResolverGeneric*)resolverptr.get())->setptr(prg); - } + resolverptr = std::shared_ptr<native::ManagedPartitionResolverGeneric>(new native::ManagedPartitionResolverGeneric(partitionresolver)); + ((native::ManagedPartitionResolverGeneric*)resolverptr.get())->setptr(prg); + } + } + try + { + m_nativeptr->get()->setPartitionResolver(resolverptr); + } + finally + { + GC::KeepAlive(m_nativeptr); } - NativePtr->setPartitionResolver( resolverptr ); return this; + } } // namespace Client } // namespace Geode } // namespace Apache -} http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/RegionFactory.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/RegionFactory.hpp b/src/clicache/src/RegionFactory.hpp index 337e2da..af79747 100644 --- a/src/clicache/src/RegionFactory.hpp +++ b/src/clicache/src/RegionFactory.hpp @@ -18,12 +18,18 @@ #pragma once #include "geode_defs.hpp" +#include "begin_native.hpp" #include <geode/AttributesFactory.hpp> -//#include "impl/NativeWrapper.hpp" +#include "end_native.hpp" + + #include "ExpirationAction.hpp" #include "DiskPolicyType.hpp" //#include "ScopeType.hpp" +#include "begin_native.hpp" #include <geode/RegionFactory.hpp> +#include "end_native.hpp" + #include "RegionShortcut.hpp" #include "ICacheLoader.hpp" @@ -46,12 +52,12 @@ namespace Apache { namespace Client { + namespace native = apache::geode::client; /// <summary> /// This interface provides for the configuration and creation of instances of Region. /// </summary> public ref class RegionFactory sealed - : public Internal::SBWrap<apache::geode::client::RegionFactory> { public: /// <summary> @@ -428,10 +434,15 @@ namespace Apache /// <returns> /// The managed wrapper object; null if the native pointer is null. /// </returns> - inline static RegionFactory^ Create( apache::geode::client::RegionFactory* nativeptr ) + inline static RegionFactory^ Create(native::RegionFactoryPtr nativeptr ) { - return ( nativeptr != nullptr ? - gcnew RegionFactory( nativeptr ) : nullptr ); + return __nullptr == nativeptr ? nullptr : + gcnew RegionFactory( nativeptr ); + } + + std::shared_ptr<native::RegionFactory> GetNative() + { + return m_nativeptr->get_shared_ptr(); } private: @@ -440,8 +451,12 @@ namespace Apache /// Private constructor to wrap a native object pointer /// </summary> /// <param name="nativeptr">The native object pointer</param> - inline RegionFactory( apache::geode::client::RegionFactory* nativeptr ) - : Internal::SBWrap<apache::geode::client::RegionFactory>( nativeptr ) { } + inline RegionFactory(native::RegionFactoryPtr nativeptr ) + { + m_nativeptr = gcnew native_shared_ptr<native::RegionFactory>(nativeptr); + } + + native_shared_ptr<native::RegionFactory>^ m_nativeptr; }; } // namespace Client } // namespace Geode http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/ResultCollector.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/ResultCollector.cpp b/src/clicache/src/ResultCollector.cpp index 13220eb..9b0e249 100644 --- a/src/clicache/src/ResultCollector.cpp +++ b/src/clicache/src/ResultCollector.cpp @@ -31,13 +31,22 @@ namespace Apache namespace Client { + namespace native = apache::geode::client; + generic<class TResult> void ResultCollector<TResult>::AddResult( TResult rs ) { _GF_MG_EXCEPTION_TRY2/* due to auto replace */ - apache::geode::client::Serializable * result = SafeGenericMSerializableConvert((IGeodeSerializable^)rs); - NativePtr->addResult( result==NULL ? (nullptr) : (apache::geode::client::CacheablePtr(result)) ); + try + { + auto result = std::shared_ptr<native::Cacheable>(SafeGenericMSerializableConvert((IGeodeSerializable^)rs)); + m_nativeptr->get()->addResult(result); + } + finally + { + GC::KeepAlive(m_nativeptr); + } _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ } @@ -52,17 +61,22 @@ namespace Apache System::Collections::Generic::ICollection<TResult>^ ResultCollector<TResult>::GetResult(UInt32 timeout) { _GF_MG_EXCEPTION_TRY2/* due to auto replace */ - apache::geode::client::CacheableVectorPtr results = NativePtr->getResult(timeout); - array<TResult>^ rs = - gcnew array<TResult>( results->size( ) ); - for( System::Int32 index = 0; index < results->size( ); index++ ) - { - apache::geode::client::CacheablePtr& nativeptr(results->operator[](index)); - - rs[ index] = Serializable::GetManagedValueGeneric<TResult>( nativeptr); - } - ICollection<TResult>^ collectionlist = (ICollection<TResult>^)rs; - return collectionlist; + try + { + auto results = m_nativeptr->get()->getResult(timeout); + auto rs = gcnew array<TResult>(results->size()); + for (System::Int32 index = 0; index < results->size(); index++) + { + auto nativeptr = results->operator[](index); + rs[index] = Serializable::GetManagedValueGeneric<TResult>(nativeptr); + } + auto collectionlist = (ICollection<TResult>^)rs; + return collectionlist; + } + finally + { + GC::KeepAlive(m_nativeptr); + } _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ } @@ -71,7 +85,14 @@ namespace Apache void ResultCollector<TResult>::EndResults() { _GF_MG_EXCEPTION_TRY2/* due to auto replace */ - NativePtr->endResults(); + try + { + m_nativeptr->get()->endResults(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */ } @@ -79,10 +100,16 @@ namespace Apache void ResultCollector<TResult>::ClearResults(/*bool*/) { _GF_MG_EXCEPTION_TRY2/* due to auto replace */ - NativePtr->clearResults(); + try + { + m_nativeptr->get()->clearResults(); + } + 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/ResultCollector.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/ResultCollector.hpp b/src/clicache/src/ResultCollector.hpp index 3b8067d..f75ffdc 100644 --- a/src/clicache/src/ResultCollector.hpp +++ b/src/clicache/src/ResultCollector.hpp @@ -20,8 +20,11 @@ #include "geode_defs.hpp" #include "IResultCollector.hpp" +#include "begin_native.hpp" #include <geode/ResultCollector.hpp> -#include "impl/NativeWrapper.hpp" +#include "end_native.hpp" + +#include "native_shared_ptr.hpp" using namespace System; @@ -33,6 +36,7 @@ namespace Apache { namespace Client { + namespace native = apache::geode::client; generic<class TResult> interface class IResultCollector; @@ -42,7 +46,7 @@ namespace Apache /// </summary> generic<class TResult> public ref class ResultCollector - : public Internal::SBWrap<apache::geode::client::ResultCollector>, public IResultCollector<TResult> + : public IResultCollector<TResult> { public: @@ -74,45 +78,15 @@ namespace Apache internal: /// <summary> - /// Default constructor. - /// </summary> - inline ResultCollector( ): - SBWrap( ){ } - - //~ResultCollector<TKey>( ) { } - - /// <summary> /// Internal constructor to wrap a native object pointer /// </summary> /// <param name="nativeptr">The native object pointer</param> - inline ResultCollector( apache::geode::client::ResultCollector* nativeptr ): - SBWrap( nativeptr ){ } - - /// <summary> - /// Used to assign the native Serializable pointer to a new object. - /// </summary> - /// <remarks> - /// Note the order of preserveSB() and releaseSB(). This handles the - /// corner case when <c>m_nativeptr</c> is same as <c>nativeptr</c>. - /// </remarks> - inline void AssignSPGeneric( apache::geode::client::ResultCollector* nativeptr ) + inline ResultCollector( native::ResultCollectorPtr nativeptr ) { - AssignPtr( nativeptr ); + m_nativeptr = gcnew native_shared_ptr<native::ResultCollector>(nativeptr); } - /// <summary> - /// Used to assign the native CqListener pointer to a new object. - /// </summary> - inline void SetSPGeneric( apache::geode::client::ResultCollector* nativeptr ) - { - if ( nativeptr != nullptr ) { - nativeptr->preserveSB( ); - } - _SetNativePtr( nativeptr ); - } - - //void Silence_LNK2022_BUG() { }; - + native_shared_ptr<native::ResultCollector>^ m_nativeptr; }; } // namespace Client } // namespace Geode http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/ResultSet.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/ResultSet.cpp b/src/clicache/src/ResultSet.cpp index d3a83e7..8e512cc 100644 --- a/src/clicache/src/ResultSet.cpp +++ b/src/clicache/src/ResultSet.cpp @@ -34,44 +34,67 @@ namespace Apache generic<class TResult> bool ResultSet<TResult>::IsModifiable::get( ) { - return NativePtr->isModifiable( ); + try + { + return m_nativeptr->get()->isModifiable( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } } generic<class TResult> System::Int32 ResultSet<TResult>::Size::get( ) { - return NativePtr->size( ); + try + { + return m_nativeptr->get()->size( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } } generic<class TResult> - /*IGeodeSerializable^*/TResult ResultSet<TResult>::default::get( size_t index ) + TResult ResultSet<TResult>::default::get( size_t index ) { - //return SafeUMSerializableConvertGeneric(NativePtr->operator[](static_cast<System::Int32>(index)).get()); - return (Serializable::GetManagedValueGeneric<TResult>(NativePtr->operator[](static_cast<System::Int32>(index)))); + try + { + return (Serializable::GetManagedValueGeneric<TResult>(m_nativeptr->get()->operator[](static_cast<System::Int32>(index)))); + } + finally + { + GC::KeepAlive(m_nativeptr); + } } generic<class TResult> - SelectResultsIterator<TResult>^ ResultSet<TResult>::GetIterator( ) + SelectResultsIterator<TResult>^ ResultSet<TResult>::GetIterator() { - apache::geode::client::SelectResultsIterator* nativeptr = - new apache::geode::client::SelectResultsIterator( NativePtr->getIterator( ) ); - - return SelectResultsIterator<TResult>::Create( nativeptr ); + try + { + return SelectResultsIterator<TResult>::Create(std::make_unique<apache::geode::client::SelectResultsIterator>( + m_nativeptr->get()->getIterator())); + } + finally + { + GC::KeepAlive(m_nativeptr); + } } generic<class TResult> - System::Collections::Generic::IEnumerator</*IGeodeSerializable^*/TResult>^ - ResultSet<TResult>::GetEnumerator( ) + System::Collections::Generic::IEnumerator<TResult>^ ResultSet<TResult>::GetEnumerator( ) { return GetIterator( ); } generic<class TResult> - System::Collections::IEnumerator^ ResultSet<TResult>::GetIEnumerator( ) + System::Collections::IEnumerator^ ResultSet<TResult>::GetIEnumerator() { - return GetIterator( ); + return GetIterator(); + } } // namespace Client } // namespace Geode } // namespace Apache - - } //namespace http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/ResultSet.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/ResultSet.hpp b/src/clicache/src/ResultSet.hpp index e4990cc..bc64ede 100644 --- a/src/clicache/src/ResultSet.hpp +++ b/src/clicache/src/ResultSet.hpp @@ -18,8 +18,11 @@ #pragma once #include "geode_defs.hpp" +#include "begin_native.hpp" #include <geode/ResultSet.hpp> -#include "impl/NativeWrapper.hpp" +#include "end_native.hpp" + +#include "native_shared_ptr.hpp" #include "ISelectResults.hpp" @@ -31,6 +34,7 @@ namespace Apache { namespace Client { + namespace native = apache::geode::client; interface class IGeodeSerializable; @@ -43,7 +47,7 @@ namespace Apache /// </summary> generic<class TResult> public ref class ResultSet sealed - : public Internal::SBWrap<apache::geode::client::ResultSet>, public ISelectResults<TResult> + : public ISelectResults<TResult> { public: @@ -97,9 +101,10 @@ namespace Apache /// <returns> /// The managed wrapper object; null if the native pointer is null. /// </returns> - inline static ResultSet<TResult>^ Create(apache::geode::client::ResultSet* nativeptr) + inline static ResultSet<TResult>^ Create(native::ResultSetPtr nativeptr) { - return (nativeptr != nullptr ? gcnew ResultSet(nativeptr) : nullptr); + return __nullptr == nativeptr ? nullptr : + gcnew ResultSet<TResult>( nativeptr ); } @@ -112,8 +117,12 @@ namespace Apache /// Private constructor to wrap a native object pointer /// </summary> /// <param name="nativeptr">The native object pointer</param> - inline ResultSet(apache::geode::client::ResultSet* nativeptr) - : SBWrap(nativeptr) { } + inline ResultSet(native::ResultSetPtr nativeptr) + { + m_nativeptr = gcnew native_shared_ptr<native::ResultSet>(nativeptr); + } + + native_shared_ptr<native::ResultSet>^ m_nativeptr; }; } // namespace Client } // namespace Geode http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/SelectResultsIterator.cpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/SelectResultsIterator.cpp b/src/clicache/src/SelectResultsIterator.cpp index 0a241e0..0ac7edc 100644 --- a/src/clicache/src/SelectResultsIterator.cpp +++ b/src/clicache/src/SelectResultsIterator.cpp @@ -15,51 +15,81 @@ * limitations under the License. */ -//#include "geode_includes.hpp" #include "SelectResultsIterator.hpp" - #include "impl/SafeConvert.hpp" -using namespace System; namespace Apache { namespace Geode { namespace Client { + using namespace System; generic<class TResult> - /*Apache::Geode::Client::IGeodeSerializable^*/TResult SelectResultsIterator<TResult>::Current::get( ) + TResult SelectResultsIterator<TResult>::Current::get( ) { - //return SafeUMSerializableConvertGeneric( NativePtr->current( ).ptr( ) ); - return Serializable::GetManagedValueGeneric<TResult>(NativePtr->current( )); + try + { + return Serializable::GetManagedValueGeneric<TResult>(m_nativeptr->get()->current( )); + } + finally + { + GC::KeepAlive(m_nativeptr); + } } generic<class TResult> bool SelectResultsIterator<TResult>::MoveNext( ) { - return NativePtr->moveNext( ); + try + { + return m_nativeptr->get()->moveNext( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } } generic<class TResult> void SelectResultsIterator<TResult>::Reset( ) { - NativePtr->reset( ); + try + { + m_nativeptr->get()->reset( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } } generic<class TResult> - /*Apache::Geode::Client::IGeodeSerializable^*/TResult SelectResultsIterator<TResult>::Next( ) + TResult SelectResultsIterator<TResult>::Next( ) { - //return SafeUMSerializableConvertGeneric( NativePtr->next( ).ptr( ) ); - return Serializable::GetManagedValueGeneric<TResult>(NativePtr->next( )); + try + { + return Serializable::GetManagedValueGeneric<TResult>(m_nativeptr->get()->next( )); + } + finally + { + GC::KeepAlive(m_nativeptr); + } } generic<class TResult> - bool SelectResultsIterator<TResult>::HasNext::get( ) + bool SelectResultsIterator<TResult>::HasNext::get() { - return NativePtr->hasNext( ); + try + { + return m_nativeptr->get()->hasNext(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } } // namespace Client } // namespace Geode } // namespace Apache - - } //namespace http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/SelectResultsIterator.hpp ---------------------------------------------------------------------- diff --git a/src/clicache/src/SelectResultsIterator.hpp b/src/clicache/src/SelectResultsIterator.hpp index 1784529..0bb6191 100644 --- a/src/clicache/src/SelectResultsIterator.hpp +++ b/src/clicache/src/SelectResultsIterator.hpp @@ -18,8 +18,11 @@ #pragma once #include "geode_defs.hpp" +#include "begin_native.hpp" #include <geode/SelectResultsIterator.hpp> -#include "impl/NativeWrapper.hpp" +#include "end_native.hpp" + +#include "native_unique_ptr.hpp" using namespace System; @@ -30,6 +33,7 @@ namespace Apache { namespace Client { + namespace native = apache::geode::client; interface class IGeodeSerializable; @@ -38,8 +42,7 @@ namespace Apache /// </summary> generic<class TResult> public ref class SelectResultsIterator sealed - : public Internal::UMWrap<apache::geode::client::SelectResultsIterator>, - public System::Collections::Generic::IEnumerator</*Apache::Geode::Client::IGeodeSerializable^*/TResult> + : public System::Collections::Generic::IEnumerator</*Apache::Geode::Client::IGeodeSerializable^*/TResult> { public: @@ -85,6 +88,7 @@ namespace Apache bool get( ); } + ~SelectResultsIterator() {}; internal: @@ -97,10 +101,10 @@ namespace Apache /// The managed wrapper object; null if the native pointer is null. /// </returns> inline static Apache::Geode::Client::SelectResultsIterator<TResult>^ Create( - apache::geode::client::SelectResultsIterator* nativeptr ) + std::unique_ptr<native::SelectResultsIterator> nativeptr ) { return ( nativeptr != nullptr ? - gcnew Apache::Geode::Client::SelectResultsIterator<TResult>( nativeptr ) : nullptr ); + gcnew Apache::Geode::Client::SelectResultsIterator<TResult>( std::move(nativeptr) ) : nullptr ); } @@ -120,8 +124,12 @@ namespace Apache /// </summary> /// <param name="nativeptr">The native object pointer</param> inline SelectResultsIterator( - apache::geode::client::SelectResultsIterator* nativeptr ) - : UMWrap( nativeptr, true ) { } + std::unique_ptr<native::SelectResultsIterator> nativeptr ) + { + m_nativeptr = gcnew native_unique_ptr<native::SelectResultsIterator>(std::move(nativeptr)); + } + + native_unique_ptr<native::SelectResultsIterator>^ m_nativeptr; }; } // namespace Client } // namespace Geode
