Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A0A042004F5 for ; Sat, 12 Aug 2017 01:52:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9EF3E16E476; Fri, 11 Aug 2017 23:52:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7F18916E462 for ; Sat, 12 Aug 2017 01:52:20 +0200 (CEST) Received: (qmail 71961 invoked by uid 500); 11 Aug 2017 23:52:18 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 71749 invoked by uid 99); 11 Aug 2017 23:52:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Aug 2017 23:52:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 60A0AF5666; Fri, 11 Aug 2017 23:52:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jbarrett@apache.org To: commits@geode.apache.org Date: Fri, 11 Aug 2017 23:52:26 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [10/52] [partial] geode-native git commit: GEODE-3165: Reogranized sources relative to the root for better CMake IDE integration. archived-at: Fri, 11 Aug 2017 23:52:22 -0000 http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/SelectResultsIterator.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/SelectResultsIterator.cpp b/clicache/src/SelectResultsIterator.cpp new file mode 100644 index 0000000..0ac7edc --- /dev/null +++ b/clicache/src/SelectResultsIterator.cpp @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SelectResultsIterator.hpp" +#include "impl/SafeConvert.hpp" + +namespace Apache +{ + namespace Geode + { + namespace Client + { + using namespace System; + + generic + TResult SelectResultsIterator::Current::get( ) + { + try + { + return Serializable::GetManagedValueGeneric(m_nativeptr->get()->current( )); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic + bool SelectResultsIterator::MoveNext( ) + { + try + { + return m_nativeptr->get()->moveNext( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic + void SelectResultsIterator::Reset( ) + { + try + { + m_nativeptr->get()->reset( ); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic + TResult SelectResultsIterator::Next( ) + { + try + { + return Serializable::GetManagedValueGeneric(m_nativeptr->get()->next( )); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + generic + bool SelectResultsIterator::HasNext::get() + { + try + { + return m_nativeptr->get()->hasNext(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + } // namespace Client + } // namespace Geode +} // namespace Apache http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/SelectResultsIterator.hpp ---------------------------------------------------------------------- diff --git a/clicache/src/SelectResultsIterator.hpp b/clicache/src/SelectResultsIterator.hpp new file mode 100644 index 0000000..0bb6191 --- /dev/null +++ b/clicache/src/SelectResultsIterator.hpp @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "geode_defs.hpp" +#include "begin_native.hpp" +#include +#include "end_native.hpp" + +#include "native_unique_ptr.hpp" + + +using namespace System; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + interface class IGeodeSerializable; + + /// + /// Iterator for a query result. + /// + generic + public ref class SelectResultsIterator sealed + : public System::Collections::Generic::IEnumerator + { + public: + + /// + /// Gets the element in the collection at the current + /// position of the enumerator. + /// + /// + /// The element in the collection at the current position + /// of the enumerator. + /// + virtual property /*Apache::Geode::Client::IGeodeSerializable^*/TResult Current + { + virtual /*Apache::Geode::Client::IGeodeSerializable^*/TResult get( ); + } + + /// + /// Advances the enumerator to the next element of the collection. + /// + /// + /// true if the enumerator was successfully advanced to the next + /// element; false if the enumerator has passed the end of + /// the collection. + /// + virtual bool MoveNext( ); + + /// + /// Sets the enumerator to its initial position, which is before + /// the first element in the collection. + /// + virtual void Reset( ); + + /// + /// Get the current element and move to the next one. + /// + /*Apache::Geode::Client::IGeodeSerializable^*/TResult Next( ); + + /// + /// Check if there is a next element. + /// + property bool HasNext + { + bool get( ); + } + + ~SelectResultsIterator() {}; + + internal: + + /// + /// Internal factory function to wrap a native object pointer inside + /// this managed class with null pointer check. + /// + /// The native object pointer + /// + /// The managed wrapper object; null if the native pointer is null. + /// + inline static Apache::Geode::Client::SelectResultsIterator^ Create( + std::unique_ptr nativeptr ) + { + return ( nativeptr != nullptr ? + gcnew Apache::Geode::Client::SelectResultsIterator( std::move(nativeptr) ) : nullptr ); + } + + + private: + + virtual property Object^ ICurrent + { + virtual Object^ get( ) sealed + = System::Collections::IEnumerator::Current::get + { + return Current; + } + } + + /// + /// Private constructor to wrap a native object pointer + /// + /// The native object pointer + inline SelectResultsIterator( + std::unique_ptr nativeptr ) + { + m_nativeptr = gcnew native_unique_ptr(std::move(nativeptr)); + } + + native_unique_ptr^ m_nativeptr; + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/src/Serializable.cpp ---------------------------------------------------------------------- diff --git a/clicache/src/Serializable.cpp b/clicache/src/Serializable.cpp new file mode 100644 index 0000000..8760bab --- /dev/null +++ b/clicache/src/Serializable.cpp @@ -0,0 +1,1480 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "begin_native.hpp" +#include +#include +#include +#include +#include "CacheRegionHelper.hpp" +#include "end_native.hpp" + +#include + +#include "Serializable.hpp" +#include "impl/DelegateWrapper.hpp" +#include "DataOutput.hpp" +#include "DataInput.hpp" +#include "CacheableStringArray.hpp" + +#include "CacheableBuiltins.hpp" +#include "impl/SafeConvert.hpp" +#include "CacheableHashTable.hpp" +#include "Struct.hpp" +#include "CacheableUndefined.hpp" +#include "CacheableObject.hpp" +#include "CacheableStack.hpp" +#include "CacheableObjectXml.hpp" +#include "CacheableHashSet.hpp" +#include "CacheableObjectArray.hpp" +#include "CacheableLinkedList.hpp" +#include "CacheableFileName.hpp" +#include "CacheableIdentityHashMap.hpp" +#include "IPdxSerializer.hpp" +#include "impl/DotNetTypes.hpp" +#include "CacheRegionHelper.hpp" +#include "Cache.hpp" + +#pragma warning(disable:4091) + +using namespace System::Reflection; +using namespace System::Reflection::Emit; + +using namespace System; +using namespace System::Collections::Generic; +using namespace Runtime::InteropServices; +using namespace apache::geode::client; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + namespace native = apache::geode::client; + + void Apache::Geode::Client::Serializable::ToData( + Apache::Geode::Client::DataOutput^ output) + { + if (output->IsManagedObject()) { + output->WriteBytesToUMDataOutput(); + } + try + { + auto nativeOutput = output->GetNative(); + m_nativeptr->get()->toData(*nativeOutput); + } + finally + { + GC::KeepAlive(output); + GC::KeepAlive(m_nativeptr); + } + if (output->IsManagedObject()) { + output->SetBuffer(); + } + } + + Apache::Geode::Client::IGeodeSerializable^ + Apache::Geode::Client::Serializable::FromData( + Apache::Geode::Client::DataInput^ input) + { + if (input->IsManagedObject()) { + input->AdvanceUMCursor(); + } + auto* nativeInput = input->GetNative(); + + try + { + auto temp = m_nativeptr->get()->fromData(*nativeInput); + if (temp != m_nativeptr->get()) + { + m_nativeptr->get_shared_ptr().reset(temp); + } + + if (input->IsManagedObject()) { + input->SetBuffer(); + } + return this; + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + System::UInt32 Apache::Geode::Client::Serializable::ObjectSize::get() + { + try + { + return m_nativeptr->get()->objectSize(); + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + System::UInt32 Apache::Geode::Client::Serializable::ClassId::get() + { + try + { + auto n = m_nativeptr->get(); + int8_t typeId = n->typeId(); + if (typeId == native::GeodeTypeIdsImpl::CacheableUserData || + typeId == native::GeodeTypeIdsImpl::CacheableUserData2 || + typeId == native::GeodeTypeIdsImpl::CacheableUserData4) { + return n->classId(); + } + else { + return typeId + 0x80000000 + (0x20000000 * n->DSFID()); + } + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + String^ Apache::Geode::Client::Serializable::ToString() + { + try + { + auto cStr = m_nativeptr->get()->toString(); + if (cStr->isWideString()) { + return ManagedString::Get(cStr->asWChar()); + } + else { + return ManagedString::Get(cStr->asChar()); + } + } + finally + { + GC::KeepAlive(m_nativeptr); + } + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (Byte value) + { + return (Apache::Geode::Client::Serializable^) CacheableByte::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (bool value) + { + return (Apache::Geode::Client::Serializable^)CacheableBoolean::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (array^ value) + { + // return (Apache::Geode::Client::Serializable^)Apache::Geode::Client::CacheableBooleanArray::Create(value); + //TODO:split + return nullptr; + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (array^ value) + { + return (Apache::Geode::Client::Serializable^)CacheableBytes::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (Char value) + { + return (Apache::Geode::Client::Serializable^)CacheableCharacter::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (array^ value) + { + //return (Apache::Geode::Client::Serializable^)Apache::Geode::Client::CacheableCharArray::Create(value); + //TODO:split + return nullptr; + + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (Double value) + { + return (Apache::Geode::Client::Serializable^)CacheableDouble::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (array^ value) + { + return (Apache::Geode::Client::Serializable^)CacheableDoubleArray::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (Single value) + { + return (Apache::Geode::Client::Serializable^)CacheableFloat::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (array^ value) + { + return (Apache::Geode::Client::Serializable^)CacheableFloatArray::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (System::Int16 value) + { + return (Apache::Geode::Client::Serializable^)CacheableInt16::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (array^ value) + { + return (Apache::Geode::Client::Serializable^)CacheableInt16Array::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (System::Int32 value) + { + return (Apache::Geode::Client::Serializable^)CacheableInt32::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (array^ value) + { + return (Apache::Geode::Client::Serializable^)CacheableInt32Array::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (System::Int64 value) + { + return (Apache::Geode::Client::Serializable^)CacheableInt64::Create(value); + } + + /*Apache::Geode::Client::*/Serializable::operator /*Apache::Geode::Client::*/Serializable ^ (array^ value) + { + return (Apache::Geode::Client::Serializable^)Apache::Geode::Client::CacheableInt64Array::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (String^ value) + { + return (Apache::Geode::Client::Serializable^)CacheableString::Create(value); + } + + Apache::Geode::Client::Serializable::operator Apache::Geode::Client::Serializable ^ (array^ value) + { + return (Apache::Geode::Client::Serializable^)CacheableStringArray::Create(value); + } + + System::Int32 Serializable::GetPDXIdForType(const char* poolName, IGeodeSerializable^ pdxType, const native::Cache* cache) + { + native::CacheablePtr kPtr(SafeMSerializableConvertGeneric(pdxType)); + return CacheRegionHelper::getCacheImpl(cache)->getSerializationRegistry()->GetPDXIdForType(cache->getPoolManager().find(poolName), kPtr); + } + + IGeodeSerializable^ Serializable::GetPDXTypeById(const char* poolName, System::Int32 typeId, const native::Cache* cache) + { + SerializablePtr sPtr = CacheRegionHelper::getCacheImpl(cache)->getSerializationRegistry()->GetPDXTypeById(cache->getPoolManager().find(poolName), typeId); + return SafeUMSerializableConvertGeneric(sPtr); + } + + int Serializable::GetEnumValue(Internal::EnumInfo^ ei, const native::Cache* cache) + { + native::CacheablePtr kPtr(SafeMSerializableConvertGeneric(ei)); + return CacheRegionHelper::getCacheImpl(cache)->getSerializationRegistry()->GetEnumValue(cache->getPoolManager().getAll().begin()->second, kPtr); + } + + Internal::EnumInfo^ Serializable::GetEnum(int val, const native::Cache* cache) + { + SerializablePtr sPtr = CacheRegionHelper::getCacheImpl(cache)->getSerializationRegistry()->GetEnum(cache->getPoolManager().getAll().begin()->second, val); + return (Internal::EnumInfo^)SafeUMSerializableConvertGeneric(sPtr); + } + + void Serializable::RegisterPdxType(PdxTypeFactoryMethod^ creationMethod) + { + if (creationMethod == nullptr) { + throw gcnew IllegalArgumentException("Serializable.RegisterPdxType(): " + "null PdxTypeFactoryMethod delegate passed"); + } + IPdxSerializable^ obj = creationMethod(); + PdxDelegateMap[obj->GetType()->FullName] = creationMethod; + Log::Debug("RegisterPdxType: class registered: " + obj->GetType()->FullName); + } + + Object^ Serializable::CreateObject(String^ className) + { + + Object^ retVal = CreateObjectEx(className); + + if (retVal == nullptr) + { + Type^ t = GetType(className); + if (t) + { + retVal = t->GetConstructor(Type::EmptyTypes)->Invoke(nullptr); + return retVal; + } + } + return retVal; + } + + Object^ Serializable::CreateObjectEx(String^ className) + { + CreateNewObjectDelegate^ del = nullptr; + Dictionary^ tmp = ClassNameVsCreateNewObjectDelegate; + + tmp->TryGetValue(className, del); + + if (del != nullptr) + { + return del(); + } + + Type^ t = GetType(className); + if (t) + { + msclr::lock lockInstance(ClassNameVsTypeLockObj); + { + tmp = ClassNameVsCreateNewObjectDelegate; + tmp->TryGetValue(className, del); + if (del != nullptr) + return del(); + del = CreateNewObjectDelegateF(t); + tmp = gcnew Dictionary(ClassNameVsCreateNewObjectDelegate); + tmp[className] = del; + ClassNameVsCreateNewObjectDelegate = tmp; + return del(); + } + } + return nullptr; + } + + Object^ Serializable::GetArrayObject(String^ className, int len) + { + Object^ retArr = GetArrayObjectEx(className, len); + if (retArr == nullptr) + { + Type^ t = GetType(className); + if (t) + { + retArr = t->MakeArrayType()->GetConstructor(singleIntType)->Invoke(gcnew array(1) { len }); + return retArr; + } + } + return retArr; + } + + Object^ Serializable::GetArrayObjectEx(String^ className, int len) + { + CreateNewObjectArrayDelegate^ del = nullptr; + Dictionary^ tmp = ClassNameVsCreateNewObjectArrayDelegate; + + tmp->TryGetValue(className, del); + + if (del != nullptr) + { + return del(len); + } + + Type^ t = GetType(className); + if (t) + { + msclr::lock lockInstance(ClassNameVsTypeLockObj); + { + tmp = ClassNameVsCreateNewObjectArrayDelegate; + tmp->TryGetValue(className, del); + if (del != nullptr) + return del(len); + del = CreateNewObjectArrayDelegateF(t); + tmp = gcnew Dictionary(ClassNameVsCreateNewObjectArrayDelegate); + tmp[className] = del; + ClassNameVsCreateNewObjectArrayDelegate = tmp; + return del(len); + } + } + return nullptr; + } + + //delegate Object^ CreateNewObject(); + //static CreateNewObjectDelegate^ CreateNewObjectDelegateF(Type^ type); + Serializable::CreateNewObjectDelegate^ Serializable::CreateNewObjectDelegateF(Type^ type) + { + DynamicMethod^ dynam = gcnew DynamicMethod("", Internal::DotNetTypes::ObjectType, Type::EmptyTypes, type, true); + ILGenerator^ il = dynam->GetILGenerator(); + + ConstructorInfo^ ctorInfo = type->GetConstructor(Type::EmptyTypes); + if (ctorInfo == nullptr) { + Log::Error("Object missing public no arg constructor"); + throw gcnew IllegalStateException("Object missing public no arg constructor"); + } + + il->Emit(OpCodes::Newobj, ctorInfo); + il->Emit(OpCodes::Ret); + + return (Serializable::CreateNewObjectDelegate^)dynam->CreateDelegate(createNewObjectDelegateType); + } + + //delegate Object^ CreateNewObjectArray(int len); + Serializable::CreateNewObjectArrayDelegate^ Serializable::CreateNewObjectArrayDelegateF(Type^ type) + { + DynamicMethod^ dynam = gcnew DynamicMethod("", Internal::DotNetTypes::ObjectType, singleIntTypeA, type, true); + ILGenerator^ il = dynam->GetILGenerator(); + + il->Emit(OpCodes::Ldarg_0); + + il->Emit(OpCodes::Newarr, type); + il->Emit(OpCodes::Ret); + + return (Serializable::CreateNewObjectArrayDelegate^)dynam->CreateDelegate(createNewObjectArrayDelegateType); + } + + Type^ Serializable::getTypeFromRefrencedAssemblies(String^ className, Dictionary^ referedAssembly, Assembly^ currentAsm) + { + Type^ t = currentAsm->GetType(className); + if (t != nullptr) + { + Dictionary^ tmp = gcnew Dictionary(ClassNameVsType); + tmp[className] = t; + ClassNameVsType = tmp; + return t; + } + //already touched + if (referedAssembly->ContainsKey(currentAsm)) + return nullptr; + referedAssembly[currentAsm] = true; + + //get all refrenced assembly + array^ ReferencedAssemblies = currentAsm->GetReferencedAssemblies(); + for each(AssemblyName^ tmpAsm in ReferencedAssemblies) + { + try + { + Assembly^ la = Assembly::Load(tmpAsm); + if (la != nullptr && (!referedAssembly->ContainsKey(la))) + { + t = getTypeFromRefrencedAssemblies(className, referedAssembly, la); + if (!t) + return t; + } + } + catch (System::Exception^){//ignore + } + } + return nullptr; + } + + Type^ Serializable::GetType(String^ className) + { + Type^ retVal = nullptr; + Dictionary^ tmp = ClassNameVsType; + tmp->TryGetValue(className, retVal); + + if (retVal != nullptr) + return retVal; + msclr::lock lockInstance(ClassNameVsTypeLockObj); + { + tmp = ClassNameVsType; + tmp->TryGetValue(className, retVal); + + if (retVal != nullptr) + return retVal; + + Dictionary^ referedAssembly = gcnew Dictionary(); + AppDomain^ MyDomain = AppDomain::CurrentDomain; + array^ AssembliesLoaded = MyDomain->GetAssemblies(); + for each(Assembly^ tmpAsm in AssembliesLoaded) + { + retVal = getTypeFromRefrencedAssemblies(className, referedAssembly, tmpAsm); + if (retVal) + return retVal; + } + } + return retVal; + } + + IPdxSerializable^ Serializable::GetPdxType(String^ className) + { + PdxTypeFactoryMethod^ retVal = nullptr; + PdxDelegateMap->TryGetValue(className, retVal); + + if (retVal == nullptr){ + + if (PdxSerializer != nullptr) + { + return gcnew PdxWrapper(className); + } + try + { + Object^ retObj = CreateObject(className); + + IPdxSerializable^ retPdx = dynamic_cast(retObj); + if (retPdx != nullptr) + return retPdx; + } + catch (System::Exception^ ex) + { + Log::Error("Unable to create object usqing reflection for class: " + className + " : " + ex->Message); + } + throw gcnew IllegalStateException("Pdx factory method (or PdxSerializer ) not registered (or don't have zero arg constructor)" + " to create default instance for class: " + className); + } + + return retVal(); + } + + void Serializable::RegisterPDXManagedCacheableKey(bool appDomainEnable, Cache^ cache) + { + CacheImpl *cacheImpl = CacheRegionHelper::getCacheImpl(cache->GetNative().get()); + if (!appDomainEnable) + { + cacheImpl->getSerializationRegistry()->addType(native::GeodeTypeIdsImpl::PDX, + &native::PdxManagedCacheableKey::CreateDeserializable); + } + else + { + cacheImpl->getSerializationRegistry()->addType(native::GeodeTypeIdsImpl::PDX, + std::bind(native::PdxManagedCacheableKeyBytes::CreateDeserializable, cache->GetNative().get())); + } + } + + void Apache::Geode::Client::Serializable::RegisterTypeGeneric(TypeFactoryMethodGeneric^ creationMethod, Cache^ cache) + { + if (creationMethod == nullptr) { + throw gcnew IllegalArgumentException("Serializable.RegisterType(): " + "null TypeFactoryMethod delegate passed"); + } + + //-------------------------------------------------------------- + + //adding user type as well in global builtin hashmap + System::Int64 classId = ((System::Int64)creationMethod()->ClassId); + if (!ManagedDelegatesGeneric->ContainsKey(classId)) + ManagedDelegatesGeneric->Add(classId, creationMethod); + + DelegateWrapperGeneric^ delegateObj = gcnew DelegateWrapperGeneric(creationMethod, cache); + TypeFactoryNativeMethodGeneric^ nativeDelegate = + gcnew TypeFactoryNativeMethodGeneric(delegateObj, + &DelegateWrapperGeneric::NativeDelegateGeneric); + + // this is avoid object being Gced + NativeDelegatesGeneric->Add(nativeDelegate); + + // register the type in the DelegateMap, this is pure c# for create domain object + IGeodeSerializable^ tmp = creationMethod(); + Log::Fine("Registering serializable class ID " + tmp->ClassId + + ", AppDomain ID " + System::Threading::Thread::GetDomainID()); + DelegateMapGeneric[tmp->ClassId] = creationMethod; + + _GF_MG_EXCEPTION_TRY2 + CacheImpl *cacheImpl = CacheRegionHelper::getCacheImpl(cache->GetNative().get()); + cacheImpl->getSerializationRegistry()->addType((native::Serializable*(*)())System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(nativeDelegate).ToPointer()); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + void Apache::Geode::Client::Serializable::RegisterTypeGeneric(Byte typeId, + TypeFactoryMethodGeneric^ creationMethod, Type^ type, Cache^ cache) + { + if (creationMethod == nullptr) { + throw gcnew IllegalArgumentException("Serializable.RegisterType(): " + "null TypeFactoryMethod delegate passed"); + } + DelegateWrapperGeneric^ delegateObj = gcnew DelegateWrapperGeneric(creationMethod, cache); + TypeFactoryNativeMethodGeneric^ nativeDelegate = + gcnew TypeFactoryNativeMethodGeneric(delegateObj, + &DelegateWrapperGeneric::NativeDelegateGeneric); + + BuiltInDelegatesGeneric[typeId] = nativeDelegate; + + if (type != nullptr) + ManagedTypeMappingGeneric[type] = typeId; + + //This is hashmap for manged builtin objects + if (!ManagedDelegatesGeneric->ContainsKey(typeId + 0x80000000)) + ManagedDelegatesGeneric->Add(typeId + 0x80000000, creationMethod); + + // register the type in the DelegateMap + IGeodeSerializable^ tmp = creationMethod(); + Log::Finer("Registering(,) serializable class ID " + tmp->ClassId + + ", AppDomain ID " + System::Threading::Thread::GetDomainID()); + DelegateMapGeneric[tmp->ClassId] = creationMethod; + + try + { + CacheImpl *cacheImpl = CacheRegionHelper::getCacheImpl(cache->GetNative().get()); + if (tmp->ClassId < 0xa0000000) + { + cacheImpl->getSerializationRegistry()->addType(typeId, + (native::Serializable*(*)())System::Runtime::InteropServices:: + Marshal::GetFunctionPointerForDelegate( + nativeDelegate).ToPointer()); + } + else + {//special case for CacheableUndefined type + cacheImpl->getSerializationRegistry()->addType2(typeId, + (native::Serializable*(*)())System::Runtime::InteropServices:: + Marshal::GetFunctionPointerForDelegate( + nativeDelegate).ToPointer()); + } + + } + catch (native::IllegalStateException&) + { + //ignore it as this is internal only + } + } + + void Apache::Geode::Client::Serializable::UnregisterTypeGeneric(Byte typeId, Cache^ cache) + { + BuiltInDelegatesGeneric->Remove(typeId); + _GF_MG_EXCEPTION_TRY2 + + CacheRegionHelper::getCacheImpl(cache->GetNative().get())->getSerializationRegistry()->removeType(typeId); + + _GF_MG_EXCEPTION_CATCH_ALL2 + } + + void Apache::Geode::Client::Serializable::RegisterWrapperGeneric( + WrapperDelegateGeneric^ wrapperMethod, Byte typeId, System::Type^ type) + { + if (typeId < 0 || typeId > WrapperEndGeneric) + { + throw gcnew GeodeException("The TypeID (" + typeId + ") being " + "registered is beyond acceptable range of 0-" + WrapperEndGeneric); + } + NativeWrappersGeneric[typeId] = wrapperMethod; + ManagedTypeMappingGeneric[type] = typeId; + } + + void Apache::Geode::Client::Serializable::UnregisterNativesGeneric() + { + BuiltInDelegatesGeneric->Clear(); + for (Byte typeId = 0; typeId <= WrapperEndGeneric; ++typeId) { + NativeWrappersGeneric[typeId] = nullptr; + } + //TODO:: unregister from managed hashmap as well. + // ManagedDelegates->Clear(); + } + + generic + TValue Serializable::GetManagedValueGeneric(native::SerializablePtr val) + { + if (val == nullptr) + { + return TValue(); + } + + Byte typeId = val->typeId(); + //Log::Debug("Serializable::GetManagedValueGeneric typeid = " + typeId); + switch (typeId) + { + case native::GeodeTypeIds::CacheableByte: + { + return (TValue)(int8_t)safe_cast(Serializable::getByte(val)); + /* if (TValue::typeid == System::SByte::typeid) { + return (TValue)(int8_t)safe_cast(Serializable::getByte(val)); + } + else { + return (TValue)(System::Byte)safe_cast(Serializable::getByte(val)); + } + return safe_cast(Serializable::getByte(val));*/ + } + case native::GeodeTypeIds::CacheableBoolean: + { + return safe_cast(Serializable::getBoolean(val)); + } + case native::GeodeTypeIds::CacheableWideChar: + { + return safe_cast(Serializable::getChar(val)); + } + case native::GeodeTypeIds::CacheableDouble: + { + return safe_cast(Serializable::getDouble(val)); + } + case native::GeodeTypeIds::CacheableASCIIString: + case native::GeodeTypeIds::CacheableASCIIStringHuge: + case native::GeodeTypeIds::CacheableString: + case native::GeodeTypeIds::CacheableStringHuge: + { + //TODO: need to look all strings types + return safe_cast(Serializable::getASCIIString(val)); + } + case native::GeodeTypeIds::CacheableFloat: + { + return safe_cast(Serializable::getFloat(val)); + } + case native::GeodeTypeIds::CacheableInt16: + { + /* if (TValue::typeid == System::Int16::typeid) { + return (TValue)(System::Int16)safe_cast(Serializable::getInt16(val)); + } + else { + return (TValue)(System::UInt16)safe_cast(Serializable::getInt16(val)); + }*/ + return safe_cast(Serializable::getInt16(val)); + } + case native::GeodeTypeIds::CacheableInt32: + { + /* if (TValue::typeid == System::Int32::typeid) { + return (TValue)(System::Int32)safe_cast(Serializable::getInt32(val)); + } + else { + return (TValue)(System::UInt32)safe_cast(Serializable::getInt32(val)); + } */ + return safe_cast(Serializable::getInt32(val)); + } + case native::GeodeTypeIds::CacheableInt64: + { + /*if (TValue::typeid == System::Int64::typeid) { + return (TValue)(System::Int64)safe_cast(Serializable::getInt64(val)); + } + else { + return (TValue)(System::UInt64)safe_cast(Serializable::getInt64(val)); + }*/ + return safe_cast(Serializable::getInt64(val)); + } + case native::GeodeTypeIds::CacheableDate: + { + //TODO:: + Apache::Geode::Client::CacheableDate^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + + System::DateTime dt(ret->Value.Ticks); + return safe_cast(dt); + } + case native::GeodeTypeIdsImpl::CacheableUserData: + case native::GeodeTypeIdsImpl::CacheableUserData2: + case native::GeodeTypeIdsImpl::CacheableUserData4: + { + //TODO::split + IGeodeSerializable^ ret = SafeUMSerializableConvertGeneric(val); + return safe_cast(ret); + //return TValue(); + } + case native::GeodeTypeIdsImpl::PDX: + { + IPdxSerializable^ ret = SafeUMSerializablePDXConvert(val); + + PdxWrapper^ pdxWrapper = dynamic_cast(ret); + + if (pdxWrapper != nullptr) + { + return safe_cast(pdxWrapper->GetObject()); + } + + return safe_cast(ret); + } + case native::GeodeTypeIds::CacheableBytes: + { + Apache::Geode::Client::CacheableBytes^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableDoubleArray: + { + Apache::Geode::Client::CacheableDoubleArray^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableFloatArray: + { + Apache::Geode::Client::CacheableFloatArray^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableInt16Array: + { + Apache::Geode::Client::CacheableInt16Array^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableInt32Array: + { + Apache::Geode::Client::CacheableInt32Array^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableInt64Array: + { + Apache::Geode::Client::CacheableInt64Array^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableStringArray: + { + Apache::Geode::Client::CacheableStringArray^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + /* array^ str = gcnew array(ret->GetValues()->Length); + for(int i=0; iGetValues()->Length; i++ ) { + str[i] = ret->GetValues()[i]; + }*/ + + return safe_cast(ret->GetValues()); + } + case native::GeodeTypeIds::CacheableArrayList://Ilist generic + { + Apache::Geode::Client::CacheableArrayList^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableLinkedList://LinkedList generic + { + Apache::Geode::Client::CacheableLinkedList^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableHashTable://collection::hashtable + { + Apache::Geode::Client::CacheableHashTable^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableHashMap://generic dictionary + { + Apache::Geode::Client::CacheableHashMap^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableIdentityHashMap: + { + Apache::Geode::Client::CacheableIdentityHashMap^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableHashSet://no need of it, default case should work + { + Apache::Geode::Client::CacheableHashSet^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret); + } + case native::GeodeTypeIds::CacheableLinkedHashSet://no need of it, default case should work + { + Apache::Geode::Client::CacheableLinkedHashSet^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret); + } + case native::GeodeTypeIds::CacheableFileName: + { + Apache::Geode::Client::CacheableFileName^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret); + } + case native::GeodeTypeIds::CacheableObjectArray: + { + Apache::Geode::Client::CacheableObjectArray^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret); + } + case native::GeodeTypeIds::CacheableVector://collection::arraylist + { + Apache::Geode::Client::CacheableVector^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CacheableUndefined: + { + Apache::Geode::Client::CacheableUndefined^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret); + } + case native::GeodeTypeIds::Struct: + { + return safe_cast(Apache::Geode::Client::Struct::Create(val)); + } + case native::GeodeTypeIds::CacheableStack: + { + Apache::Geode::Client::CacheableStack^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret->Value); + } + case 7: //GeodeClassIds::CacheableManagedObject + { + Apache::Geode::Client::CacheableObject^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret); + } + case 8://GeodeClassIds::CacheableManagedObjectXml + { + Apache::Geode::Client::CacheableObjectXml^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret); + } + /* TODO: replace with IDictionary + case native::GeodeTypeIds::Properties: + { + Apache::Geode::Client::Properties^ ret = safe_cast + ( SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret); + }*/ + + case native::GeodeTypeIds::BooleanArray: + { + Apache::Geode::Client::BooleanArray^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case native::GeodeTypeIds::CharArray: + { + Apache::Geode::Client::CharArray^ ret = safe_cast + (SafeGenericUMSerializableConvert(val)); + + return safe_cast(ret->Value); + } + case 0://UserFunctionExecutionException unregistered + { + Apache::Geode::Client::UserFunctionExecutionException^ ret = static_cast + (SafeGenericUMSerializableConvert(val)); + return safe_cast(ret); + } + default: + throw gcnew System::Exception("not found typeid"); + } + throw gcnew System::Exception("not found typeid"); + } + + generic + native::CacheableKeyPtr Serializable::GetUnmanagedValueGeneric(TKey key, native::Cache* cache) + { + //System::Type^ managedType = TKey::typeid; + if (key != nullptr) { + //System::Type^ managedType = key->GetType(); + return GetUnmanagedValueGeneric(key->GetType(), key, cache); + } + return nullptr; + } + + generic + native::CacheableKeyPtr Serializable::GetUnmanagedValueGeneric(TKey key, bool isAciiChar, native::Cache* cache) + { + //System::Type^ managedType = TKey::typeid; + if (key != nullptr) { + //System::Type^ managedType = key->GetType(); + return GetUnmanagedValueGeneric(key->GetType(), key, isAciiChar, cache); + } + return nullptr; + } + + void Serializable::RegisterPdxSerializer(IPdxSerializer^ pdxSerializer) + { + /*if(PdxSerializer != nullptr ) + { + throw gcnew IllegalStateException("IPdxSerializer is already registered: " + PdxSerializer->GetType()); + }*/ + PdxSerializer = pdxSerializer; + } + + void Serializable::SetPdxTypeMapper(IPdxTypeMapper^ pdxTypeMapper) + { + if (pdxTypeMapper != nullptr) + PdxTypeMapper = pdxTypeMapper; + } + + String^ Serializable::GetPdxTypeName(String^ localTypeName) + { + if (PdxTypeMapper == nullptr) + return localTypeName; + IDictionary^ tmp = LocalTypeNameToPdx; + String^ pdxTypeName = nullptr; + tmp->TryGetValue(localTypeName, pdxTypeName); + + if (pdxTypeName != nullptr) + return pdxTypeName; + + { + msclr::lock lockInstance(LockObj); + tmp->TryGetValue(localTypeName, pdxTypeName); + + if (pdxTypeName != nullptr) + return pdxTypeName; + if (PdxTypeMapper != nullptr) + { + pdxTypeName = PdxTypeMapper->ToPdxTypeName(localTypeName); + if (pdxTypeName == nullptr) + { + throw gcnew IllegalStateException("PdxTypeName should not be null for local type " + localTypeName); + } + + Dictionary^ localToPdx = gcnew Dictionary(LocalTypeNameToPdx); + localToPdx[localTypeName] = pdxTypeName; + LocalTypeNameToPdx = localToPdx; + Dictionary^ pdxToLocal = gcnew Dictionary(PdxTypeNameToLocal); + localToPdx[pdxTypeName] = localTypeName; + PdxTypeNameToLocal = pdxToLocal; + } + } + return pdxTypeName; + } + + String^ Serializable::GetLocalTypeName(String^ pdxTypeName) + { + if (PdxTypeMapper == nullptr) + return pdxTypeName; + + IDictionary^ tmp = PdxTypeNameToLocal; + String^ localTypeName = nullptr; + tmp->TryGetValue(pdxTypeName, localTypeName); + + if (localTypeName != nullptr) + return localTypeName; + + { + msclr::lock lockInstance(LockObj); + tmp->TryGetValue(pdxTypeName, localTypeName); + + if (localTypeName != nullptr) + return localTypeName; + if (PdxTypeMapper != nullptr) + { + localTypeName = PdxTypeMapper->FromPdxTypeName(pdxTypeName); + if (localTypeName == nullptr) + { + throw gcnew IllegalStateException("LocalTypeName should not be null for pdx type " + pdxTypeName); + } + + Dictionary^ localToPdx = gcnew Dictionary(LocalTypeNameToPdx); + localToPdx[localTypeName] = pdxTypeName; + LocalTypeNameToPdx = localToPdx; + Dictionary^ pdxToLocal = gcnew Dictionary(PdxTypeNameToLocal); + localToPdx[pdxTypeName] = localTypeName; + PdxTypeNameToLocal = pdxToLocal; + } + } + return localTypeName; + } + + void Serializable::Clear() + { + PdxTypeMapper = nullptr; + LocalTypeNameToPdx->Clear(); + PdxTypeNameToLocal->Clear(); + ClassNameVsCreateNewObjectDelegate->Clear(); + ClassNameVsType->Clear(); + ClassNameVsCreateNewObjectArrayDelegate->Clear(); + } + + IPdxSerializer^ Serializable::GetPdxSerializer() + { + return PdxSerializer; + } + + bool Serializable::IsObjectAndPdxSerializerRegistered(String^ className) + { + return PdxSerializer != nullptr; + } + + generic + native::CacheableKeyPtr Serializable::GetUnmanagedValueGeneric( + Type^ managedType, TKey key, native::Cache* cache) + { + return GetUnmanagedValueGeneric(managedType, key, false, cache); + } + + generic + native::CacheableKeyPtr Serializable::GetUnmanagedValueGeneric( + Type^ managedType, TKey key, bool isAsciiChar, native::Cache* cache) + { + Byte typeId = Apache::Geode::Client::Serializable::GetManagedTypeMappingGeneric(managedType); + + switch (typeId) + { + case native::GeodeTypeIds::CacheableByte: { + return Serializable::getCacheableByte((SByte)key); + } + case native::GeodeTypeIds::CacheableBoolean: + return Serializable::getCacheableBoolean((bool)key); + case native::GeodeTypeIds::CacheableWideChar: + return Serializable::getCacheableWideChar((Char)key); + case native::GeodeTypeIds::CacheableDouble: + return Serializable::getCacheableDouble((double)key); + case native::GeodeTypeIds::CacheableASCIIString: { + if (isAsciiChar) + return Serializable::getCacheableASCIIString2((String^)key); + else + return Serializable::getCacheableASCIIString((String^)key); + } + case native::GeodeTypeIds::CacheableFloat: + return Serializable::getCacheableFloat((float)key); + case native::GeodeTypeIds::CacheableInt16: { + return Serializable::getCacheableInt16((System::Int16)key); + } + case native::GeodeTypeIds::CacheableInt32: { + return Serializable::getCacheableInt32((System::Int32)key); + } + case native::GeodeTypeIds::CacheableInt64: { + return Serializable::getCacheableInt64((System::Int64)key); + } + case native::GeodeTypeIds::CacheableBytes: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableBytes::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableDoubleArray: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableDoubleArray::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableFloatArray: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableFloatArray::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableInt16Array: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableInt16Array::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableInt32Array: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableInt32Array::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableInt64Array: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableInt64Array::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableStringArray: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableStringArray::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableFileName: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)(Apache::Geode::Client::CacheableFileName^)key, cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableHashTable://collection::hashtable + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableHashTable::Create((System::Collections::Hashtable^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableHashMap://generic dictionary + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableHashMap::Create((System::Collections::IDictionary^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableVector://collection::arraylist + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)CacheableVector::Create((System::Collections::IList^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableArrayList://generic ilist + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableArrayList::Create((System::Collections::IList^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableLinkedList://generic linked list + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableLinkedList::Create((System::Collections::Generic::LinkedList^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableStack: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert(Apache::Geode::Client::CacheableStack::Create((System::Collections::ICollection^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case 7: //GeodeClassIds::CacheableManagedObject + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((Apache::Geode::Client::CacheableObject^)key, cache)); + return std::dynamic_pointer_cast(kPtr); + } + case 8://GeodeClassIds::CacheableManagedObjectXml + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((Apache::Geode::Client::CacheableObjectXml^)key, cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableObjectArray: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((Apache::Geode::Client::CacheableObjectArray^)key, cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableIdentityHashMap: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert(Apache::Geode::Client::CacheableIdentityHashMap::Create((System::Collections::IDictionary^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableHashSet://no need of it, default case should work + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((Apache::Geode::Client::CacheableHashSet^)key, cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableLinkedHashSet://no need of it, default case should work + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((Apache::Geode::Client::CacheableLinkedHashSet^)key, cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CacheableDate: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CacheableDate::Create((System::DateTime)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::BooleanArray: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::BooleanArray::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + case native::GeodeTypeIds::CharArray: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert((IGeodeSerializable^)Apache::Geode::Client::CharArray::Create((array^)key), cache)); + return std::dynamic_pointer_cast(kPtr); + } + default: + { + native::CacheablePtr kPtr(SafeGenericMSerializableConvert(key, cache)); + return std::dynamic_pointer_cast(kPtr); + } + } + } // + + String^ Serializable::GetString(native::CacheableStringPtr cStr)//native::CacheableString* + { + if (cStr == nullptr) { + return nullptr; + } + else if (cStr->isWideString()) { + return ManagedString::Get(cStr->asWChar()); + } + else { + return ManagedString::Get(cStr->asChar()); + } + } + + // These are the new static methods to get/put data from c++ + + //byte + Byte Serializable::getByte(native::SerializablePtr nativeptr) + { + native::CacheableByte* ci = static_cast(nativeptr.get()); + return ci->value(); + } + + native::CacheableKeyPtr Serializable::getCacheableByte(SByte val) + { + return native::CacheableByte::create(val); + } + + //boolean + bool Serializable::getBoolean(native::SerializablePtr nativeptr) + { + native::CacheableBoolean* ci = static_cast(nativeptr.get()); + return ci->value(); + } + + native::CacheableKeyPtr Serializable::getCacheableBoolean(bool val) + { + return native::CacheableBoolean::create(val); + } + + //widechar + Char Serializable::getChar(native::SerializablePtr nativeptr) + { + native::CacheableWideChar* ci = static_cast(nativeptr.get()); + return ci->value(); + } + + native::CacheableKeyPtr Serializable::getCacheableWideChar(Char val) + { + return native::CacheableWideChar::create(val); + } + + //double + double Serializable::getDouble(native::SerializablePtr nativeptr) + { + native::CacheableDouble* ci = static_cast(nativeptr.get()); + return ci->value(); + } + + native::CacheableKeyPtr Serializable::getCacheableDouble(double val) + { + return native::CacheableDouble::create(val); + } + + //float + float Serializable::getFloat(native::SerializablePtr nativeptr) + { + native::CacheableFloat* ci = static_cast(nativeptr.get()); + return ci->value(); + } + + native::CacheableKeyPtr Serializable::getCacheableFloat(float val) + { + return native::CacheableFloat::create(val); + } + + //int16 + System::Int16 Serializable::getInt16(native::SerializablePtr nativeptr) + { + native::CacheableInt16* ci = static_cast(nativeptr.get()); + return ci->value(); + } + + native::CacheableKeyPtr Serializable::getCacheableInt16(int val) + { + return native::CacheableInt16::create(val); + } + + //int32 + System::Int32 Serializable::getInt32(native::SerializablePtr nativeptr) + { + native::CacheableInt32* ci = static_cast(nativeptr.get()); + return ci->value(); + } + + native::CacheableKeyPtr Serializable::getCacheableInt32(System::Int32 val) + { + return native::CacheableInt32::create(val); + } + + //int64 + System::Int64 Serializable::getInt64(native::SerializablePtr nativeptr) + { + native::CacheableInt64* ci = static_cast(nativeptr.get()); + return ci->value(); + } + + native::CacheableKeyPtr Serializable::getCacheableInt64(System::Int64 val) + { + return native::CacheableInt64::create(val); + } + + //cacheable ascii string + String^ Serializable::getASCIIString(native::SerializablePtr nativeptr) + { + return GetString(nativeptr->toString()); + } + + native::CacheableKeyPtr Serializable::getCacheableASCIIString(String^ val) + { + return GetCacheableString(val); + } + + native::CacheableKeyPtr Serializable::getCacheableASCIIString2(String^ val) + { + return GetCacheableString2(val); + } + + //cacheable ascii string huge + String^ Serializable::getASCIIStringHuge(native::SerializablePtr nativeptr) + { + return GetString(nativeptr->toString()); + } + + native::CacheableKeyPtr Serializable::getCacheableASCIIStringHuge(String^ val) + { + return GetCacheableString(val); + } + + //cacheable string + String^ Serializable::getUTFString(native::SerializablePtr nativeptr) + { + return GetString(nativeptr->toString()); + } + + native::CacheableKeyPtr Serializable::getCacheableUTFString(String^ val) + { + return GetCacheableString(val); + } + + //cacheable string huge + String^ Serializable::getUTFStringHuge(native::SerializablePtr nativeptr) + { + return GetString(nativeptr->toString()); + } + + native::CacheableKeyPtr Serializable::getCacheableUTFStringHuge(String^ val) + { + return GetCacheableString(val); + } + + native::CacheableStringPtr Serializable::GetCacheableString(String^ value) + { + native::CacheableStringPtr cStr; + size_t len = 0; + if (value != nullptr) { + len = value->Length; + pin_ptr pin_value = PtrToStringChars(value); + cStr = native::CacheableString::create(pin_value, Convert::ToInt32(len)); + } + else { + cStr.reset(static_cast( + native::CacheableString::createDeserializable())); + } + + return cStr; + } + + native::CacheableStringPtr Serializable::GetCacheableString2(String^ value) + { + native::CacheableStringPtr cStr; + size_t len = 0; + if (value != nullptr) { + len = value->Length; + const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(value)).ToPointer(); + try + { + cStr = native::CacheableString::create(chars, Convert::ToInt32(len)); + } + finally + { + Marshal::FreeHGlobal(IntPtr((void*)chars)); + } + } + else { + cStr.reset(static_cast( + native::CacheableString::createDeserializable())); + } + + return cStr; + } + + array^ Serializable::getSByteArray(array^ sArray) + { + array^ dArray = gcnew array(sArray->Length); + for (int index = 0; index < dArray->Length; index++) + { + dArray[index] = sArray[index]; + } + return dArray; + } + + array^ Serializable::getInt16Array(array^ sArray) + { + array^ dArray = gcnew array(sArray->Length); + for (int index = 0; index < dArray->Length; index++) + { + dArray[index] = sArray[index]; + } + return dArray; + } + + array^ Serializable::getInt32Array(array^ sArray) + { + array^ dArray = gcnew array(sArray->Length); + for (int index = 0; index < dArray->Length; index++) + { + dArray[index] = sArray[index]; + } + return dArray; + } + + array^ Serializable::getInt64Array(array^ sArray) + { + array^ dArray = gcnew array(sArray->Length); + for (int index = 0; index < dArray->Length; index++) + { + dArray[index] = sArray[index]; + } + return dArray; + } + } // namespace Client + } // namespace Geode +} // namespace Apache