154c06456SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 354c06456SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 454c06456SAndrew Rist * or more contributor license agreements. See the NOTICE file 554c06456SAndrew Rist * distributed with this work for additional information 654c06456SAndrew Rist * regarding copyright ownership. The ASF licenses this file 754c06456SAndrew Rist * to you under the Apache License, Version 2.0 (the 854c06456SAndrew Rist * "License"); you may not use this file except in compliance 954c06456SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1154c06456SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1354c06456SAndrew Rist * Unless required by applicable law or agreed to in writing, 1454c06456SAndrew Rist * software distributed under the License is distributed on an 1554c06456SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1654c06456SAndrew Rist * KIND, either express or implied. See the License for the 1754c06456SAndrew Rist * specific language governing permissions and limitations 1854c06456SAndrew Rist * under the License. 19cdf0e10cSrcweir * 2054c06456SAndrew Rist *************************************************************/ 2154c06456SAndrew Rist 2254c06456SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cli_ure.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #pragma warning(push, 1) 28cdf0e10cSrcweir #include "windows.h" 29cdf0e10cSrcweir #pragma warning(pop) 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <memory> 32cdf0e10cSrcweir 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include "rtl/ustring.hxx" 35cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 36cdf0e10cSrcweir #include "uno/sequence2.h" 37cdf0e10cSrcweir #include "typelib/typedescription.hxx" 38cdf0e10cSrcweir #include "cli_proxy.h" 39cdf0e10cSrcweir #include "cli_base.h" 40cdf0e10cSrcweir #include "cli_bridge.h" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #using <cli_uretypes.dll> 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir #undef VOID 46cdf0e10cSrcweir 47cdf0e10cSrcweir namespace css = com::sun::star; 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace sri = System::Runtime::InteropServices; 50cdf0e10cSrcweir namespace sr = System::Reflection; 51cdf0e10cSrcweir namespace st = System::Text; 52cdf0e10cSrcweir namespace ucss = unoidl::com::sun::star; 53cdf0e10cSrcweir 54cdf0e10cSrcweir using namespace rtl; 55cdf0e10cSrcweir using namespace std; 56cdf0e10cSrcweir 57cdf0e10cSrcweir 58cdf0e10cSrcweir namespace cli_uno 59cdf0e10cSrcweir { 60cdf0e10cSrcweir System::String* mapUnoPolymorphicName(System::String* unoName); 61cdf0e10cSrcweir OUString mapCliTypeName(System::String* typeName); 62cdf0e10cSrcweir System::String* mapCliPolymorphicName(System::String* unoName); 63cdf0e10cSrcweir System::String* mapPolymorphicName(System::String* unoName, bool bCliToUno); 64cdf0e10cSrcweir 65cdf0e10cSrcweir inline auto_ptr< rtl_mem > seq_allocate( sal_Int32 nElements, sal_Int32 nSize ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir auto_ptr< rtl_mem > seq( 68cdf0e10cSrcweir rtl_mem::allocate( SAL_SEQUENCE_HEADER_SIZE + (nElements * nSize) ) ); 69cdf0e10cSrcweir uno_Sequence * p = (uno_Sequence *)seq.get(); 70cdf0e10cSrcweir p->nRefCount = 1; 71cdf0e10cSrcweir p->nElements = nElements; 72cdf0e10cSrcweir return seq; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir 76cdf0e10cSrcweir System::Object* Bridge::map_uno2cli(uno_Interface * pUnoI, typelib_InterfaceTypeDescription *pTD) const 77cdf0e10cSrcweir { 78cdf0e10cSrcweir System::Object* retVal= NULL; 79cdf0e10cSrcweir // get oid 80cdf0e10cSrcweir rtl_uString * pOid = 0; 81cdf0e10cSrcweir (*m_uno_env->getObjectIdentifier)( m_uno_env, &pOid, pUnoI ); 82cdf0e10cSrcweir OSL_ASSERT( 0 != pOid ); 83cdf0e10cSrcweir OUString oid(pOid, SAL_NO_ACQUIRE); 84cdf0e10cSrcweir 85cdf0e10cSrcweir //see if the interface was already mapped 86cdf0e10cSrcweir System::Type* ifaceType= mapUnoType(reinterpret_cast<typelib_TypeDescription*>(pTD)); 87cdf0e10cSrcweir System::String* sOid= mapUnoString(oid.pData); 88cdf0e10cSrcweir 89cdf0e10cSrcweir System::Threading::Monitor::Enter( CliEnvHolder::g_cli_env ); 90cdf0e10cSrcweir try 91cdf0e10cSrcweir { 92cdf0e10cSrcweir retVal = CliEnvHolder::g_cli_env->getRegisteredInterface(sOid, ifaceType); 93cdf0e10cSrcweir if (retVal) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir // There is already an registered object. It can either be a proxy 96cdf0e10cSrcweir // for the UNO object or a real cli object. In the first case we 97cdf0e10cSrcweir // tell the proxy that it shall also represent the current UNO 98cdf0e10cSrcweir // interface. If it already does that, then it does nothing 99cdf0e10cSrcweir if (srr::RemotingServices::IsTransparentProxy(retVal)) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir UnoInterfaceProxy* p = static_cast<UnoInterfaceProxy*>( 102cdf0e10cSrcweir srr::RemotingServices::GetRealProxy(retVal)); 103cdf0e10cSrcweir p->addUnoInterface(pUnoI, pTD); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir else 107cdf0e10cSrcweir { 108cdf0e10cSrcweir retVal = UnoInterfaceProxy::create( 109cdf0e10cSrcweir (Bridge *) this, pUnoI, pTD, oid ); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir __finally 113cdf0e10cSrcweir { 114cdf0e10cSrcweir System::Threading::Monitor::Exit( CliEnvHolder::g_cli_env ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir return retVal; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir uno_Interface* Bridge::map_cli2uno(System::Object* cliObj, typelib_TypeDescription *pTD) const 121cdf0e10cSrcweir { 122cdf0e10cSrcweir uno_Interface* retIface = NULL; 123cdf0e10cSrcweir // get oid from dot net environment 124cdf0e10cSrcweir System::String* ds_oid = CliEnvHolder::g_cli_env->getObjectIdentifier( cliObj); 125cdf0e10cSrcweir OUString ousOid = mapCliString(ds_oid); 126cdf0e10cSrcweir // look if interface is already mapped 127cdf0e10cSrcweir m_uno_env->getRegisteredInterface(m_uno_env, (void**) &retIface, ousOid.pData, 128cdf0e10cSrcweir (typelib_InterfaceTypeDescription*) pTD); 129cdf0e10cSrcweir if ( ! retIface) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir System::Threading::Monitor::Enter(__typeof(Cli_environment)); 132cdf0e10cSrcweir try 133cdf0e10cSrcweir { 134cdf0e10cSrcweir m_uno_env->getRegisteredInterface(m_uno_env, (void**) &retIface, ousOid.pData, 135cdf0e10cSrcweir (typelib_InterfaceTypeDescription*) pTD); 136cdf0e10cSrcweir if ( ! retIface) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir retIface = CliProxy::create((Bridge*)this, cliObj, pTD, ousOid); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir __finally 142cdf0e10cSrcweir { 143cdf0e10cSrcweir System::Threading::Monitor::Exit(__typeof(Cli_environment)); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir } 146cdf0e10cSrcweir return retIface; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir inline System::Type* loadCliType(rtl_uString * unoName) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir return loadCliType(mapUnoTypeName(unoName)); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir System::Type* loadCliType(System::String * unoName) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir System::Type* retVal= NULL; 157cdf0e10cSrcweir try 158cdf0e10cSrcweir { 159cdf0e10cSrcweir //If unoName denotes a polymorphic type, e.g com.sun.star.beans.Defaulted<System.Char> 160cdf0e10cSrcweir //then we remove the type list, otherwise the type could not be loaded. 161cdf0e10cSrcweir bool bIsPolymorphic = false; 162cdf0e10cSrcweir 163cdf0e10cSrcweir System::String * loadName = unoName; 164cdf0e10cSrcweir int index = unoName->IndexOf('<'); 165cdf0e10cSrcweir if (index != -1) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir loadName = unoName->Substring(0, index); 168cdf0e10cSrcweir bIsPolymorphic = true; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir System::AppDomain* currentDomain = System::AppDomain::CurrentDomain; 171cdf0e10cSrcweir sr::Assembly* assems[] = currentDomain->GetAssemblies(); 172cdf0e10cSrcweir for (int i = 0; i < assems->Length; i++) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir retVal = assems[i]->GetType(loadName, false); 175cdf0e10cSrcweir if (retVal) 176cdf0e10cSrcweir break; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir if (retVal == NULL) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir System::String * msg = new System::String(S"A type could not be loaded: "); 182cdf0e10cSrcweir msg = System::String::Concat(msg, loadName); 183cdf0e10cSrcweir throw BridgeRuntimeError(mapCliString(msg)); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir if (bIsPolymorphic) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir retVal = uno::PolymorphicType::GetType(retVal, unoName); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir catch( System::Exception * e) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir rtl::OUString ouMessage(mapCliString(e->get_Message())); 194cdf0e10cSrcweir throw BridgeRuntimeError(ouMessage); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir return retVal; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir 200cdf0e10cSrcweir System::Type* mapUnoType(typelib_TypeDescription const * pTD) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir return mapUnoType(pTD->pWeakRef); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir System::Type* mapUnoType(typelib_TypeDescriptionReference const * pTD) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir System::Type * retVal = 0; 208cdf0e10cSrcweir switch (pTD->eTypeClass) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir case typelib_TypeClass_VOID: 211cdf0e10cSrcweir retVal= __typeof(void); break; 212cdf0e10cSrcweir case typelib_TypeClass_CHAR: 213cdf0e10cSrcweir retVal= __typeof(System::Char); break; 214cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 215cdf0e10cSrcweir retVal= __typeof(System::Boolean); break; 216cdf0e10cSrcweir case typelib_TypeClass_BYTE: 217cdf0e10cSrcweir retVal= __typeof(System::Byte); break; 218cdf0e10cSrcweir case typelib_TypeClass_SHORT: 219cdf0e10cSrcweir retVal= __typeof(System::Int16); break; 220cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 221cdf0e10cSrcweir retVal= __typeof(System::UInt16); break; 222cdf0e10cSrcweir case typelib_TypeClass_LONG: 223cdf0e10cSrcweir retVal= __typeof(System::Int32); break; 224cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 225cdf0e10cSrcweir retVal= __typeof(System::UInt32); break; 226cdf0e10cSrcweir case typelib_TypeClass_HYPER: 227cdf0e10cSrcweir retVal= __typeof(System::Int64); break; 228cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 229cdf0e10cSrcweir retVal= __typeof(System::UInt64); break; 230cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 231cdf0e10cSrcweir retVal= __typeof(System::Single); break; 232cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 233cdf0e10cSrcweir retVal= __typeof(System::Double); break; 234cdf0e10cSrcweir case typelib_TypeClass_STRING: 235cdf0e10cSrcweir retVal= __typeof(System::String); break; 236cdf0e10cSrcweir case typelib_TypeClass_TYPE: 237cdf0e10cSrcweir retVal= __typeof(System::Type); break; 238cdf0e10cSrcweir case typelib_TypeClass_ANY: 239cdf0e10cSrcweir retVal= __typeof(uno::Any); break; 240cdf0e10cSrcweir case typelib_TypeClass_ENUM: 241cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 242cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 243cdf0e10cSrcweir retVal= loadCliType(pTD->pTypeName); break; 244cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 245cdf0e10cSrcweir { 246cdf0e10cSrcweir //special handling for XInterface, since it does not exist in cli. 247cdf0e10cSrcweir rtl::OUString usXInterface(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface")); 248cdf0e10cSrcweir if (usXInterface.equals(pTD->pTypeName)) 249cdf0e10cSrcweir retVal= __typeof(System::Object); 250cdf0e10cSrcweir else 251cdf0e10cSrcweir retVal= loadCliType(pTD->pTypeName); 252cdf0e10cSrcweir break; 253cdf0e10cSrcweir } 254cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 255cdf0e10cSrcweir { 256cdf0e10cSrcweir css::uno::TypeDescription seqType( 257cdf0e10cSrcweir const_cast<typelib_TypeDescriptionReference*>(pTD)); 258cdf0e10cSrcweir typelib_TypeDescriptionReference* pElementTDRef= 259cdf0e10cSrcweir reinterpret_cast<typelib_IndirectTypeDescription*>(seqType.get())->pType; 260cdf0e10cSrcweir switch (pElementTDRef->eTypeClass) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir case typelib_TypeClass_CHAR: 263cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArChar)); break; 264cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 265cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArBoolean)); 266cdf0e10cSrcweir break; 267cdf0e10cSrcweir case typelib_TypeClass_BYTE: 268cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArByte)); 269cdf0e10cSrcweir break; 270cdf0e10cSrcweir case typelib_TypeClass_SHORT: 271cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArInt16)); 272cdf0e10cSrcweir break; 273cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 274cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArUInt16)); 275cdf0e10cSrcweir break; 276cdf0e10cSrcweir case typelib_TypeClass_LONG: 277cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArInt32)); 278cdf0e10cSrcweir break; 279cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 280cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArUInt32)); 281cdf0e10cSrcweir break; 282cdf0e10cSrcweir case typelib_TypeClass_HYPER: 283cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArInt64)); 284cdf0e10cSrcweir break; 285cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 286cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArUInt64)); 287cdf0e10cSrcweir break; 288cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 289cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArSingle)); 290cdf0e10cSrcweir break; 291cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 292cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArDouble)); 293cdf0e10cSrcweir break; 294cdf0e10cSrcweir case typelib_TypeClass_STRING: 295cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArString)); 296cdf0e10cSrcweir break; 297cdf0e10cSrcweir case typelib_TypeClass_TYPE: 298cdf0e10cSrcweir retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArType)); 299cdf0e10cSrcweir break; 300cdf0e10cSrcweir case typelib_TypeClass_ANY: 301cdf0e10cSrcweir case typelib_TypeClass_ENUM: 302cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 303cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 304cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 305cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 306cdf0e10cSrcweir { 307cdf0e10cSrcweir retVal= loadCliType(pTD->pTypeName); 308cdf0e10cSrcweir break; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir default: 311cdf0e10cSrcweir //All cases should be handled by the case statements above 312cdf0e10cSrcweir OSL_ASSERT(0); 313cdf0e10cSrcweir break; 314cdf0e10cSrcweir } 315cdf0e10cSrcweir break; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir default: 318cdf0e10cSrcweir OSL_ASSERT(false); 319cdf0e10cSrcweir break; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir return retVal; 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir /** Returns an acquired td. 325cdf0e10cSrcweir */ 326cdf0e10cSrcweir typelib_TypeDescriptionReference* mapCliType(System::Type* cliType) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir typelib_TypeDescriptionReference* retVal= NULL; 329cdf0e10cSrcweir if (cliType == NULL) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 332cdf0e10cSrcweir typelib_TypeClass_VOID ); 333cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 334cdf0e10cSrcweir return retVal; 335cdf0e10cSrcweir } 336cdf0e10cSrcweir //check for Enum first, 337cdf0e10cSrcweir //because otherwise case System::TypeCode::Int32 applies 338cdf0e10cSrcweir if (cliType->get_IsEnum()) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir OUString usTypeName= mapCliTypeName(cliType->get_FullName()); 341cdf0e10cSrcweir css::uno::Type unoType(css::uno::TypeClass_ENUM, usTypeName); 342cdf0e10cSrcweir retVal= unoType.getTypeLibType(); 343cdf0e10cSrcweir typelib_typedescriptionreference_acquire(retVal); 344cdf0e10cSrcweir } 345cdf0e10cSrcweir else 346cdf0e10cSrcweir { 347cdf0e10cSrcweir switch (System::Type::GetTypeCode(cliType)) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir case System::TypeCode::Boolean: 350cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 351cdf0e10cSrcweir typelib_TypeClass_BOOLEAN ); 352cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 353cdf0e10cSrcweir break; 354cdf0e10cSrcweir case System::TypeCode::Char: 355cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 356cdf0e10cSrcweir typelib_TypeClass_CHAR ); 357cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 358cdf0e10cSrcweir break; 359cdf0e10cSrcweir case System::TypeCode::Byte: 360cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 361cdf0e10cSrcweir typelib_TypeClass_BYTE ); 362cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 363cdf0e10cSrcweir break; 364cdf0e10cSrcweir case System::TypeCode::Int16: 365cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 366cdf0e10cSrcweir typelib_TypeClass_SHORT ); 367cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 368cdf0e10cSrcweir break; 369cdf0e10cSrcweir case System::TypeCode::Int32: 370cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 371cdf0e10cSrcweir typelib_TypeClass_LONG ); 372cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 373cdf0e10cSrcweir break; 374cdf0e10cSrcweir case System::TypeCode::Int64: 375cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 376cdf0e10cSrcweir typelib_TypeClass_HYPER ); 377cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 378cdf0e10cSrcweir break; 379cdf0e10cSrcweir case System::TypeCode::UInt16: 380cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 381cdf0e10cSrcweir typelib_TypeClass_UNSIGNED_SHORT ); 382cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 383cdf0e10cSrcweir break; 384cdf0e10cSrcweir case System::TypeCode::UInt32: 385cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 386cdf0e10cSrcweir typelib_TypeClass_UNSIGNED_LONG ); 387cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 388cdf0e10cSrcweir break; 389cdf0e10cSrcweir case System::TypeCode::UInt64: 390cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 391cdf0e10cSrcweir typelib_TypeClass_UNSIGNED_HYPER ); 392cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 393cdf0e10cSrcweir break; 394cdf0e10cSrcweir case System::TypeCode::Single: 395cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 396cdf0e10cSrcweir typelib_TypeClass_FLOAT ); 397cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 398cdf0e10cSrcweir break; 399cdf0e10cSrcweir case System::TypeCode::Double: 400cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 401cdf0e10cSrcweir typelib_TypeClass_DOUBLE ); 402cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 403cdf0e10cSrcweir break; 404cdf0e10cSrcweir case System::TypeCode::String: 405cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 406cdf0e10cSrcweir typelib_TypeClass_STRING ); 407cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 408cdf0e10cSrcweir break; 409cdf0e10cSrcweir default: 410cdf0e10cSrcweir break; 411cdf0e10cSrcweir } 412cdf0e10cSrcweir } 413cdf0e10cSrcweir if (retVal == NULL) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir System::String* cliTypeName= cliType->get_FullName(); 416cdf0e10cSrcweir // Void 417cdf0e10cSrcweir if (const_cast<System::String*>(Constants::sVoid)->Equals( 418cdf0e10cSrcweir cliTypeName)) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 421cdf0e10cSrcweir typelib_TypeClass_VOID ); 422cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir // Type 425cdf0e10cSrcweir else if (const_cast<System::String*>(Constants::sType)->Equals( 426cdf0e10cSrcweir cliTypeName)) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 429cdf0e10cSrcweir typelib_TypeClass_TYPE ); 430cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 431cdf0e10cSrcweir } 432cdf0e10cSrcweir // Any 433cdf0e10cSrcweir else if (const_cast<System::String*>(Constants::sAny)->Equals( 434cdf0e10cSrcweir cliTypeName)) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir retVal = * typelib_static_type_getByTypeClass( 437cdf0e10cSrcweir typelib_TypeClass_ANY ); 438cdf0e10cSrcweir typelib_typedescriptionreference_acquire( retVal ); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir //struct, interfaces, sequences 441cdf0e10cSrcweir else 442cdf0e10cSrcweir { 443cdf0e10cSrcweir OUString usTypeName; 444cdf0e10cSrcweir uno::PolymorphicType * poly = dynamic_cast<uno::PolymorphicType*>(cliType); 445cdf0e10cSrcweir if (poly != NULL) 446cdf0e10cSrcweir usTypeName = mapCliTypeName( poly->PolymorphicName); 447cdf0e10cSrcweir else 448cdf0e10cSrcweir usTypeName = mapCliTypeName(cliTypeName); 449cdf0e10cSrcweir typelib_TypeDescription* td = NULL; 450cdf0e10cSrcweir typelib_typedescription_getByName(&td, usTypeName.pData); 451cdf0e10cSrcweir if (td) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir retVal = td->pWeakRef; 454cdf0e10cSrcweir typelib_typedescriptionreference_acquire(retVal); 455cdf0e10cSrcweir typelib_typedescription_release(td); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir } 458cdf0e10cSrcweir } 459cdf0e10cSrcweir if (retVal == NULL) 460cdf0e10cSrcweir { 461cdf0e10cSrcweir OUStringBuffer buf( 128 ); 462cdf0e10cSrcweir buf.appendAscii( 463cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("[cli_uno bridge] mapCliType():" 464cdf0e10cSrcweir "could not map type: ") ); 465cdf0e10cSrcweir buf.append(mapCliString(cliType->get_FullName())); 466cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 467cdf0e10cSrcweir } 468cdf0e10cSrcweir return retVal; 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir /** 472cdf0e10cSrcweir Otherwise a leading "unoidl." is removed. 473cdf0e10cSrcweir */ 474cdf0e10cSrcweir System::String* mapUnoTypeName(rtl_uString const * typeName) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir OUString usUnoName( const_cast< rtl_uString * >( typeName ) ); 477cdf0e10cSrcweir st::StringBuilder* buf= new st::StringBuilder(); 478cdf0e10cSrcweir //determine if the type is a sequence and its dimensions 479cdf0e10cSrcweir int dims= 0; 480cdf0e10cSrcweir if (usUnoName[0] == '[') 481cdf0e10cSrcweir { 482cdf0e10cSrcweir sal_Int32 index= 1; 483cdf0e10cSrcweir while (true) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir if (usUnoName[index++] == ']') 486cdf0e10cSrcweir dims++; 487cdf0e10cSrcweir if (usUnoName[index++] != '[') 488cdf0e10cSrcweir break; 489cdf0e10cSrcweir } 490cdf0e10cSrcweir usUnoName = usUnoName.copy(index - 1); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir System::String * sUnoName = mapUnoString(usUnoName.pData); 493cdf0e10cSrcweir if (sUnoName->Equals(const_cast<System::String*>(Constants::usBool))) 494cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sBoolean)); 495cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usChar))) 496cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sChar)); 497cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usByte))) 498cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sByte)); 499cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usShort))) 500cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sInt16)); 501cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usUShort))) 502cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sUInt16)); 503cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usLong))) 504cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sInt32)); 505cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usULong))) 506cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sUInt32)); 507cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usHyper))) 508cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sInt64)); 509cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usUHyper))) 510cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sUInt64)); 511cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usFloat))) 512cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sSingle)); 513cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usDouble))) 514cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sDouble)); 515cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usString))) 516cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sString)); 517cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usVoid))) 518cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sVoid)); 519cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usType))) 520cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sType)); 521cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usXInterface))) 522cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sObject)); 523cdf0e10cSrcweir else if (sUnoName->Equals(const_cast<System::String*>(Constants::usAny))) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sAny)); 526cdf0e10cSrcweir } 527cdf0e10cSrcweir else 528cdf0e10cSrcweir { 529cdf0e10cSrcweir //put "unoidl." at the beginning 530cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sUnoidl)); 531cdf0e10cSrcweir //for polymorphic struct types remove the brackets, e.g mystruct<bool> -> mystruct 532cdf0e10cSrcweir System::String * sName = mapUnoPolymorphicName(sUnoName); 533cdf0e10cSrcweir buf->Append(sName); 534cdf0e10cSrcweir } 535cdf0e10cSrcweir // apend [] 536cdf0e10cSrcweir for (;dims--;) 537cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::sBrackets)); 538cdf0e10cSrcweir 539cdf0e10cSrcweir return buf->ToString(); 540cdf0e10cSrcweir } 541cdf0e10cSrcweir 542cdf0e10cSrcweir 543cdf0e10cSrcweir 544cdf0e10cSrcweir 545cdf0e10cSrcweir /** For example, there is a uno type 546cdf0e10cSrcweir com.sun.star.Foo<char, long>. 547cdf0e10cSrcweir The values in the type list 548cdf0e10cSrcweir are uno types and are replaced by cli types, such as System.Char, 549cdf0e10cSrcweir System.Int32, etc. 550cdf0e10cSrcweir The pr�fix unoidl is not added. 551cdf0e10cSrcweir */ 552cdf0e10cSrcweir inline System::String* mapUnoPolymorphicName(System::String* unoName) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir return mapPolymorphicName(unoName, false); 555cdf0e10cSrcweir } 556cdf0e10cSrcweir /** For example, there is a type name such as 557cdf0e10cSrcweir com.sun.star.Foo<System.Char, System.Int32>. 558cdf0e10cSrcweir The values in the type list 559cdf0e10cSrcweir are CLI types and are replaced by uno types, such as char, 560cdf0e10cSrcweir long, etc. 561cdf0e10cSrcweir The pr�fix unoidl remains. 562cdf0e10cSrcweir */ 563cdf0e10cSrcweir inline System::String* mapCliPolymorphicName(System::String* unoName) 564cdf0e10cSrcweir { 565cdf0e10cSrcweir return mapPolymorphicName(unoName, true); 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir System::String* mapPolymorphicName(System::String* unoName, bool bCliToUno) 569cdf0e10cSrcweir { 570cdf0e10cSrcweir int index = unoName->IndexOf('<'); 571cdf0e10cSrcweir if (index == -1) 572cdf0e10cSrcweir return unoName; 573cdf0e10cSrcweir 574cdf0e10cSrcweir System::Text::StringBuilder * builder = new System::Text::StringBuilder(256); 575cdf0e10cSrcweir builder->Append(unoName->Substring(0, index +1 )); 576cdf0e10cSrcweir 577cdf0e10cSrcweir //Find the first occurrence of ',' 578cdf0e10cSrcweir //If the parameter is a polymorphic struct then we neede to ignore everything 579cdf0e10cSrcweir //between the brackets because it can also contain commas 580cdf0e10cSrcweir //get the type list within < and > 581cdf0e10cSrcweir int endIndex = unoName->Length - 1; 582cdf0e10cSrcweir index++; 583cdf0e10cSrcweir int cur = index; 584cdf0e10cSrcweir int countParams = 0; 585cdf0e10cSrcweir while (cur <= endIndex) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir System::Char c = unoName->Chars[cur]; 588cdf0e10cSrcweir if (c == ',' || c == '>') 589cdf0e10cSrcweir { 590cdf0e10cSrcweir //insert a comma if needed 591cdf0e10cSrcweir if (countParams != 0) 592cdf0e10cSrcweir builder->Append(S","); 593cdf0e10cSrcweir countParams++; 594cdf0e10cSrcweir System::String * sParam = unoName->Substring(index, cur - index); 595cdf0e10cSrcweir //skip the comma 596cdf0e10cSrcweir cur++; 597*fb0b81f5Smseidel //the index to the beginning of the next param 598cdf0e10cSrcweir index = cur; 599cdf0e10cSrcweir if (bCliToUno) 600cdf0e10cSrcweir { 60124c56ab9SHerbert Dürr builder->Append( mapCliTypeName(sParam).getStr()); 602cdf0e10cSrcweir } 603cdf0e10cSrcweir else 604cdf0e10cSrcweir { 605cdf0e10cSrcweir OUString s = mapCliString(sParam); 606cdf0e10cSrcweir builder->Append(mapUnoTypeName(s.pData)); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir } 609cdf0e10cSrcweir else if (c == '<') 610cdf0e10cSrcweir { 611cdf0e10cSrcweir cur++; 612cdf0e10cSrcweir //continue until the matching '>' 613cdf0e10cSrcweir int numNested = 0; 614cdf0e10cSrcweir for (;;cur++) 615cdf0e10cSrcweir { 616cdf0e10cSrcweir System::Char curChar = unoName->Chars[cur]; 617cdf0e10cSrcweir if (curChar == '<') 618cdf0e10cSrcweir { 619cdf0e10cSrcweir numNested ++; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir else if (curChar == '>') 622cdf0e10cSrcweir { 623cdf0e10cSrcweir if (numNested > 0) 624cdf0e10cSrcweir numNested--; 625cdf0e10cSrcweir else 626cdf0e10cSrcweir break; 627cdf0e10cSrcweir } 628cdf0e10cSrcweir } 629cdf0e10cSrcweir } 630cdf0e10cSrcweir cur++; 631cdf0e10cSrcweir } 632cdf0e10cSrcweir 633cdf0e10cSrcweir builder->Append((System::Char) '>'); 634cdf0e10cSrcweir return builder->ToString(); 635cdf0e10cSrcweir } 636cdf0e10cSrcweir 637cdf0e10cSrcweir OUString mapCliTypeName(System::String* typeName) 638cdf0e10cSrcweir { 639cdf0e10cSrcweir int dims= 0; 640cdf0e10cSrcweir // Array? determine the "rank" (number of "[]") 641cdf0e10cSrcweir // move from the rightmost end to the left, for example 642cdf0e10cSrcweir // unoidl.PolymorphicStruct<System.Char[]>[] 643cdf0e10cSrcweir // has only a "dimension" of 1 644cdf0e10cSrcweir int cur = typeName->Length - 1; 645cdf0e10cSrcweir bool bRightBracket = false; 646cdf0e10cSrcweir while (cur >= 0) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir System::Char c = typeName->Chars[cur]; 649cdf0e10cSrcweir if (c == ']') 650cdf0e10cSrcweir { 651cdf0e10cSrcweir bRightBracket = true; 652cdf0e10cSrcweir } 653cdf0e10cSrcweir else if (c == '[') 654cdf0e10cSrcweir { 655cdf0e10cSrcweir if (!bRightBracket) 656cdf0e10cSrcweir throw BridgeRuntimeError( 657cdf0e10cSrcweir OUSTR("Typename is wrong. No matching brackets for sequence. Name is: ") + 658cdf0e10cSrcweir mapCliString(typeName)); 659cdf0e10cSrcweir bRightBracket = false; 660cdf0e10cSrcweir dims ++; 661cdf0e10cSrcweir } 662cdf0e10cSrcweir else 663cdf0e10cSrcweir { 664cdf0e10cSrcweir if (bRightBracket) 665cdf0e10cSrcweir throw BridgeRuntimeError( 666cdf0e10cSrcweir OUSTR("Typename is wrong. No matching brackets for sequence. Name is: ") + 667cdf0e10cSrcweir mapCliString(typeName)); 668cdf0e10cSrcweir break; 669cdf0e10cSrcweir } 670cdf0e10cSrcweir cur--; 671cdf0e10cSrcweir } 672cdf0e10cSrcweir 673cdf0e10cSrcweir if (bRightBracket || cur < 0) 674cdf0e10cSrcweir throw BridgeRuntimeError( 675cdf0e10cSrcweir OUSTR("Typename is wrong. ") + 676cdf0e10cSrcweir mapCliString(typeName)); 677cdf0e10cSrcweir 678cdf0e10cSrcweir typeName = typeName->Substring(0, cur + 1); 679cdf0e10cSrcweir 680cdf0e10cSrcweir System::Text::StringBuilder * buf = new System::Text::StringBuilder(512); 681cdf0e10cSrcweir 682cdf0e10cSrcweir //Put the "[]" at the beginning of the uno type name 683cdf0e10cSrcweir for (;dims--;) 684cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usBrackets)); 685cdf0e10cSrcweir 686cdf0e10cSrcweir if (typeName->Equals(const_cast<System::String*>(Constants::sBoolean))) 687cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usBool)); 688cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sChar))) 689cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usChar)); 690cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sByte))) 691cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usByte)); 692cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sInt16))) 693cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usShort)); 694cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sUInt16))) 695cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usUShort)); 696cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sInt32))) 697cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usLong)); 698cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sUInt32))) 699cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usULong)); 700cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sInt64))) 701cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usHyper)); 702cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sUInt64))) 703cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usUHyper)); 704cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sSingle))) 705cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usFloat)); 706cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sDouble))) 707cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usDouble)); 708cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sString))) 709cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usString)); 710cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sVoid))) 711cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usVoid)); 712cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sType))) 713cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usType)); 714cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sObject))) 715cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usXInterface)); 716cdf0e10cSrcweir else if (typeName->Equals(const_cast<System::String*>(Constants::sAny))) 717cdf0e10cSrcweir buf->Append(const_cast<System::String*>(Constants::usAny)); 718cdf0e10cSrcweir else 719cdf0e10cSrcweir { 720cdf0e10cSrcweir System::String * sName = mapCliPolymorphicName(typeName); 721cdf0e10cSrcweir int i= sName->IndexOf(L'.'); 722cdf0e10cSrcweir buf->Append(sName->Substring(i + 1)); 723cdf0e10cSrcweir } 724cdf0e10cSrcweir return mapCliString(buf->ToString()); 725cdf0e10cSrcweir } 726cdf0e10cSrcweir /** Maps uno types to dot net types. 727cdf0e10cSrcweir * If uno_data is null then the type description is converted to System::Type 728cdf0e10cSrcweir */ 729cdf0e10cSrcweir inline System::String* mapUnoString( rtl_uString const * data) 730cdf0e10cSrcweir { 731cdf0e10cSrcweir OSL_ASSERT(data); 732cdf0e10cSrcweir return new System::String((__wchar_t*) data->buffer, 0, data->length); 733cdf0e10cSrcweir } 734cdf0e10cSrcweir 735cdf0e10cSrcweir OUString mapCliString(System::String const * data) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir 738cdf0e10cSrcweir if (data != NULL) 739cdf0e10cSrcweir { 740cdf0e10cSrcweir OSL_ASSERT(sizeof(wchar_t) == sizeof(sal_Unicode)); 741cdf0e10cSrcweir wchar_t const __pin * pdata= PtrToStringChars(data); 742cdf0e10cSrcweir return OUString(pdata, const_cast<System::String*>(data)->get_Length()); 743cdf0e10cSrcweir } 744cdf0e10cSrcweir else 745cdf0e10cSrcweir { 746cdf0e10cSrcweir return OUString(); 747cdf0e10cSrcweir } 748cdf0e10cSrcweir } 749cdf0e10cSrcweir 750cdf0e10cSrcweir // ToDo convert cli types to expected types, e.g a long to a short where the uno type 751cdf0e10cSrcweir // is a sal_Int16. This could be necessary if a scripting language (typeless) is used 752cdf0e10cSrcweir // @param assign the uno_data has to be destructed (in/out args) 753cdf0e10cSrcweir void Bridge::map_to_uno(void * uno_data, System::Object* cli_data, 754cdf0e10cSrcweir typelib_TypeDescriptionReference * type, 755cdf0e10cSrcweir bool assign) const 756cdf0e10cSrcweir { 757cdf0e10cSrcweir try{ 758cdf0e10cSrcweir switch (type->eTypeClass) 759cdf0e10cSrcweir { 760cdf0e10cSrcweir case typelib_TypeClass_VOID: 761cdf0e10cSrcweir break; 762cdf0e10cSrcweir case typelib_TypeClass_CHAR: 763cdf0e10cSrcweir { 764cdf0e10cSrcweir System::Char aChar= *__try_cast<System::Char*>(cli_data); 765cdf0e10cSrcweir *(sal_Unicode*) uno_data= aChar; 766cdf0e10cSrcweir break; 767cdf0e10cSrcweir } 768cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 769cdf0e10cSrcweir { 770cdf0e10cSrcweir System::Boolean aBool= *__try_cast<System::Boolean*>(cli_data); 771cdf0e10cSrcweir *(sal_Bool*)uno_data= aBool == true ? sal_True : sal_False; 772cdf0e10cSrcweir break; 773cdf0e10cSrcweir } 774cdf0e10cSrcweir case typelib_TypeClass_BYTE: 775cdf0e10cSrcweir { 776cdf0e10cSrcweir System::Byte aByte= *__try_cast<System::Byte*>(cli_data); 777cdf0e10cSrcweir *(sal_Int8*) uno_data= aByte; 778cdf0e10cSrcweir break; 779cdf0e10cSrcweir } 780cdf0e10cSrcweir case typelib_TypeClass_SHORT: 781cdf0e10cSrcweir { 782cdf0e10cSrcweir System::Int16 aShort= *__try_cast<System::Int16*>(cli_data); 783cdf0e10cSrcweir *(sal_Int16*) uno_data= aShort; 784cdf0e10cSrcweir break; 785cdf0e10cSrcweir } 786cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 787cdf0e10cSrcweir { 788cdf0e10cSrcweir System::UInt16 aUShort= *__try_cast<System::UInt16*>(cli_data); 789cdf0e10cSrcweir *(sal_uInt16*) uno_data= aUShort; 790cdf0e10cSrcweir break; 791cdf0e10cSrcweir } 792cdf0e10cSrcweir case typelib_TypeClass_LONG: 793cdf0e10cSrcweir { 794cdf0e10cSrcweir System::Int32 aLong= *__try_cast<System::Int32*>(cli_data); 795cdf0e10cSrcweir *(sal_Int32*) uno_data= aLong; 796cdf0e10cSrcweir break; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 799cdf0e10cSrcweir { 800cdf0e10cSrcweir System::UInt32 aULong= *__try_cast<System::UInt32*>(cli_data); 801cdf0e10cSrcweir *(sal_uInt32*) uno_data= aULong; 802cdf0e10cSrcweir break; 803cdf0e10cSrcweir } 804cdf0e10cSrcweir case typelib_TypeClass_HYPER: 805cdf0e10cSrcweir { 806cdf0e10cSrcweir System::Int64 aHyper= *__try_cast<System::Int64*>(cli_data); 807cdf0e10cSrcweir *(sal_Int64*) uno_data= aHyper; 808cdf0e10cSrcweir break; 809cdf0e10cSrcweir } 810cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 811cdf0e10cSrcweir { 812cdf0e10cSrcweir System::UInt64 aLong= *__try_cast<System::UInt64*>(cli_data); 813cdf0e10cSrcweir *(sal_uInt64*) uno_data= aLong; 814cdf0e10cSrcweir break; 815cdf0e10cSrcweir } 816cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 817cdf0e10cSrcweir { 818cdf0e10cSrcweir System::Single aFloat= *__try_cast<System::Single*>(cli_data); 819cdf0e10cSrcweir *(float*) uno_data= aFloat; 820cdf0e10cSrcweir break; 821cdf0e10cSrcweir } 822cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 823cdf0e10cSrcweir { 824cdf0e10cSrcweir System::Double aDouble= *__try_cast<System::Double*>(cli_data); 825cdf0e10cSrcweir *(double*) uno_data= aDouble; 826cdf0e10cSrcweir break; 827cdf0e10cSrcweir } 828cdf0e10cSrcweir case typelib_TypeClass_STRING: 829cdf0e10cSrcweir { 830cdf0e10cSrcweir if (assign && *(rtl_uString**) uno_data) 831cdf0e10cSrcweir rtl_uString_release(*(rtl_uString**) uno_data); 832cdf0e10cSrcweir 833cdf0e10cSrcweir *(rtl_uString **)uno_data = 0; 834cdf0e10cSrcweir if (cli_data == NULL) 835cdf0e10cSrcweir { 836cdf0e10cSrcweir rtl_uString_new((rtl_uString**) uno_data); 837cdf0e10cSrcweir } 838cdf0e10cSrcweir else 839cdf0e10cSrcweir { 840cdf0e10cSrcweir System::String *s= __try_cast<System::String*>(cli_data); 841cdf0e10cSrcweir wchar_t const __pin * pdata= PtrToStringChars(s); 842cdf0e10cSrcweir rtl_uString_newFromStr_WithLength( (rtl_uString**) uno_data, 843cdf0e10cSrcweir pdata, s->get_Length() ); 844cdf0e10cSrcweir } 845cdf0e10cSrcweir break; 846cdf0e10cSrcweir } 847cdf0e10cSrcweir case typelib_TypeClass_TYPE: 848cdf0e10cSrcweir { 849cdf0e10cSrcweir typelib_TypeDescriptionReference* td= mapCliType(__try_cast<System::Type*>( 850cdf0e10cSrcweir cli_data)); 851cdf0e10cSrcweir if (assign) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir typelib_typedescriptionreference_release( 854cdf0e10cSrcweir *(typelib_TypeDescriptionReference **)uno_data ); 855cdf0e10cSrcweir } 856cdf0e10cSrcweir *(typelib_TypeDescriptionReference **)uno_data = td; 857cdf0e10cSrcweir break; 858cdf0e10cSrcweir } 859cdf0e10cSrcweir case typelib_TypeClass_ANY: 860cdf0e10cSrcweir { 861cdf0e10cSrcweir uno_Any * pAny = (uno_Any *)uno_data; 862cdf0e10cSrcweir if (cli_data == NULL) // null-ref or uninitialized any maps to empty any 863cdf0e10cSrcweir { 864cdf0e10cSrcweir if (assign) 865cdf0e10cSrcweir uno_any_destruct( pAny, 0 ); 866cdf0e10cSrcweir uno_any_construct( pAny, 0, 0, 0 ); 867cdf0e10cSrcweir break; 868cdf0e10cSrcweir } 869cdf0e10cSrcweir uno::Any aAny= *__try_cast<uno::Any*>(cli_data); 870cdf0e10cSrcweir css::uno::Type value_td( mapCliType(aAny.Type), SAL_NO_ACQUIRE); 871cdf0e10cSrcweir 872cdf0e10cSrcweir if (assign) 873cdf0e10cSrcweir uno_any_destruct( pAny, 0 ); 874cdf0e10cSrcweir 875cdf0e10cSrcweir try 876cdf0e10cSrcweir { 877cdf0e10cSrcweir switch (value_td.getTypeClass()) 878cdf0e10cSrcweir { 879cdf0e10cSrcweir case typelib_TypeClass_VOID: 880cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 881cdf0e10cSrcweir break; 882cdf0e10cSrcweir case typelib_TypeClass_CHAR: 883cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 884cdf0e10cSrcweir *(sal_Unicode*) &pAny->pReserved = *__try_cast<System::Char*>(aAny.Value); 885cdf0e10cSrcweir break; 886cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 887cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 888cdf0e10cSrcweir *(sal_Bool *) &pAny->pReserved = *__try_cast<System::Boolean*>(aAny.Value); 889cdf0e10cSrcweir break; 890cdf0e10cSrcweir case typelib_TypeClass_BYTE: 891cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 892cdf0e10cSrcweir *(sal_Int8*) &pAny->pReserved = *__try_cast<System::Byte*>(aAny.Value); 893cdf0e10cSrcweir break; 894cdf0e10cSrcweir case typelib_TypeClass_SHORT: 895cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 896cdf0e10cSrcweir *(sal_Int16*) &pAny->pReserved = *__try_cast<System::Int16*>(aAny.Value); 897cdf0e10cSrcweir break; 898cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 899cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 900cdf0e10cSrcweir *(sal_uInt16*) &pAny->pReserved = *__try_cast<System::UInt16*>(aAny.Value); 901cdf0e10cSrcweir break; 902cdf0e10cSrcweir case typelib_TypeClass_LONG: 903cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 904cdf0e10cSrcweir *(sal_Int32*) &pAny->pReserved = *__try_cast<System::Int32*>(aAny.Value); 905cdf0e10cSrcweir break; 906cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 907cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 908cdf0e10cSrcweir *(sal_uInt32*) &pAny->pReserved = *__try_cast<System::UInt32*>(aAny.Value); 909cdf0e10cSrcweir break; 910cdf0e10cSrcweir case typelib_TypeClass_HYPER: 911cdf0e10cSrcweir if (sizeof (sal_Int64) <= sizeof (void *)) 912cdf0e10cSrcweir { 913cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 914cdf0e10cSrcweir *(sal_Int64*) &pAny->pReserved = *__try_cast<System::Int64*>(aAny.Value); 915cdf0e10cSrcweir } 916cdf0e10cSrcweir else 917cdf0e10cSrcweir { 918cdf0e10cSrcweir auto_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (sal_Int64) ) ); 919cdf0e10cSrcweir *(sal_Int64 *) mem.get()= *__try_cast<System::Int64*>(aAny.Value); 920cdf0e10cSrcweir pAny->pData = mem.release(); 921cdf0e10cSrcweir } 922cdf0e10cSrcweir break; 923cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 924cdf0e10cSrcweir if (sizeof (sal_uInt64) <= sizeof (void *)) 925cdf0e10cSrcweir { 926cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 927cdf0e10cSrcweir *(sal_uInt64*) &pAny->pReserved = *__try_cast<System::UInt64*>(aAny.Value); 928cdf0e10cSrcweir } 929cdf0e10cSrcweir else 930cdf0e10cSrcweir { 931cdf0e10cSrcweir auto_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (sal_uInt64) ) ); 932cdf0e10cSrcweir *(sal_uInt64 *) mem.get()= *__try_cast<System::UInt64*>(aAny.Value); 933cdf0e10cSrcweir pAny->pData = mem.release(); 934cdf0e10cSrcweir } 935cdf0e10cSrcweir break; 936cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 937cdf0e10cSrcweir if (sizeof (float) <= sizeof (void *)) 938cdf0e10cSrcweir { 939cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 940cdf0e10cSrcweir *(float*) &pAny->pReserved = *__try_cast<System::Single*>(aAny.Value); 941cdf0e10cSrcweir } 942cdf0e10cSrcweir else 943cdf0e10cSrcweir { 944cdf0e10cSrcweir auto_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (float) ) ); 945cdf0e10cSrcweir *(float*) mem.get() = *__try_cast<System::Single*>(aAny.Value); 946cdf0e10cSrcweir pAny->pData = mem.release(); 947cdf0e10cSrcweir } 948cdf0e10cSrcweir break; 949cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 950cdf0e10cSrcweir if (sizeof (double) <= sizeof (void *)) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 953cdf0e10cSrcweir *(double*) &pAny->pReserved= *__try_cast<System::Double*>(aAny.Value); 954cdf0e10cSrcweir } 955cdf0e10cSrcweir else 956cdf0e10cSrcweir { 957cdf0e10cSrcweir auto_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (double) ) ); 958cdf0e10cSrcweir *(double*) mem.get()= *__try_cast<System::Double*>(aAny.Value); 959cdf0e10cSrcweir pAny->pData= mem.release(); 960cdf0e10cSrcweir } 961cdf0e10cSrcweir break; 962cdf0e10cSrcweir case typelib_TypeClass_STRING: // anies often contain strings; copy string directly 963cdf0e10cSrcweir { 964cdf0e10cSrcweir pAny->pData= &pAny->pReserved; 965cdf0e10cSrcweir OUString _s = mapCliString(static_cast<System::String*>(aAny.Value)); 966cdf0e10cSrcweir pAny->pReserved= _s.pData; 967cdf0e10cSrcweir rtl_uString_acquire(_s.pData); 968cdf0e10cSrcweir break; 969cdf0e10cSrcweir } 970cdf0e10cSrcweir case typelib_TypeClass_TYPE: 971cdf0e10cSrcweir case typelib_TypeClass_ENUM: //ToDo copy enum direct 972cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 973cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 974cdf0e10cSrcweir pAny->pData = &pAny->pReserved; 975cdf0e10cSrcweir pAny->pReserved = 0; 976cdf0e10cSrcweir map_to_uno( 977cdf0e10cSrcweir &pAny->pReserved, aAny.Value, value_td.getTypeLibType(), 978cdf0e10cSrcweir false /* no assign */); 979cdf0e10cSrcweir break; 980cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 981cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 982cdf0e10cSrcweir { 983cdf0e10cSrcweir css::uno::Type anyType(value_td); 984cdf0e10cSrcweir typelib_TypeDescription* td= NULL; 985cdf0e10cSrcweir anyType.getDescription(&td); 986cdf0e10cSrcweir auto_ptr< rtl_mem > mem(rtl_mem::allocate(td->nSize)); 987cdf0e10cSrcweir typelib_typedescription_release(td); 988cdf0e10cSrcweir map_to_uno( 989cdf0e10cSrcweir mem.get(), aAny.Value, value_td.getTypeLibType(), 990cdf0e10cSrcweir false /* no assign */); 991cdf0e10cSrcweir pAny->pData = mem.release(); 992cdf0e10cSrcweir break; 993cdf0e10cSrcweir } 994cdf0e10cSrcweir default: 995cdf0e10cSrcweir { 996cdf0e10cSrcweir OUStringBuffer buf( 128 ); 997cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") ); 998cdf0e10cSrcweir buf.append(value_td.getTypeName()); 999cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported value type of any!") ); 1000cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir } 1003cdf0e10cSrcweir } 1004cdf0e10cSrcweir catch(System::InvalidCastException* ) 1005cdf0e10cSrcweir { 1006cdf0e10cSrcweir // ToDo check this 1007cdf0e10cSrcweir if (assign) 1008cdf0e10cSrcweir uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any 1009cdf0e10cSrcweir OUStringBuffer buf( 256 ); 1010cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():Any") ); 1011cdf0e10cSrcweir buf.append(value_td.getTypeName()); 1012cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("]The Any type ")); 1013cdf0e10cSrcweir buf.append(value_td.getTypeName()); 1014cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" does not correspont " 1015cdf0e10cSrcweir "to its value type: ") ); 1016cdf0e10cSrcweir if(aAny.Value != NULL) 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir css::uno::Type td(mapCliType(aAny.Value->GetType()), SAL_NO_ACQUIRE); 1019cdf0e10cSrcweir buf.append(td.getTypeName()); 1020cdf0e10cSrcweir } 1021cdf0e10cSrcweir if (assign) 1022cdf0e10cSrcweir uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any 1023cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir catch (BridgeRuntimeError& ) 1026cdf0e10cSrcweir { 1027cdf0e10cSrcweir if (assign) 1028cdf0e10cSrcweir uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any 1029cdf0e10cSrcweir throw; 1030cdf0e10cSrcweir } 1031cdf0e10cSrcweir catch (...) 1032cdf0e10cSrcweir { 1033cdf0e10cSrcweir if (assign) 1034cdf0e10cSrcweir uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any 1035cdf0e10cSrcweir throw; 1036cdf0e10cSrcweir } 1037cdf0e10cSrcweir 1038cdf0e10cSrcweir pAny->pType = value_td.getTypeLibType(); 1039cdf0e10cSrcweir typelib_typedescriptionreference_acquire(pAny->pType); 1040cdf0e10cSrcweir break; 1041cdf0e10cSrcweir } 1042cdf0e10cSrcweir case typelib_TypeClass_ENUM: 1043cdf0e10cSrcweir { 1044cdf0e10cSrcweir // InvalidCastException is caught at the end of this method 1045cdf0e10cSrcweir System::Int32 aEnum= System::Convert::ToInt32((cli_data)); 1046cdf0e10cSrcweir *(sal_Int32*) uno_data = aEnum; 1047cdf0e10cSrcweir break; 1048cdf0e10cSrcweir } 1049cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 1050cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 1051cdf0e10cSrcweir { 1052cdf0e10cSrcweir css::uno::TypeDescription td(type); 1053cdf0e10cSrcweir typelib_CompoundTypeDescription * comp_td = 1054cdf0e10cSrcweir (typelib_CompoundTypeDescription*) td.get(); 1055cdf0e10cSrcweir 1056cdf0e10cSrcweir typelib_StructTypeDescription * struct_td = NULL; 1057cdf0e10cSrcweir if (type->eTypeClass == typelib_TypeClass_STRUCT) 1058cdf0e10cSrcweir struct_td = (typelib_StructTypeDescription*) td.get(); 1059cdf0e10cSrcweir 1060cdf0e10cSrcweir if ( ! ((typelib_TypeDescription*) comp_td)->bComplete) 1061cdf0e10cSrcweir ::typelib_typedescription_complete( 1062cdf0e10cSrcweir (typelib_TypeDescription**) & comp_td ); 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir sal_Int32 nMembers = comp_td->nMembers; 1065cdf0e10cSrcweir boolean bException= false; 1066cdf0e10cSrcweir System::Type* cliType = NULL; 1067cdf0e10cSrcweir if (cli_data) 1068cdf0e10cSrcweir cliType = cli_data->GetType(); 1069cdf0e10cSrcweir 1070cdf0e10cSrcweir if (0 != comp_td->pBaseTypeDescription) 1071cdf0e10cSrcweir { 1072cdf0e10cSrcweir map_to_uno( 1073cdf0e10cSrcweir uno_data, cli_data, 1074cdf0e10cSrcweir ((typelib_TypeDescription *)comp_td->pBaseTypeDescription)->pWeakRef, 1075cdf0e10cSrcweir assign); 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir sal_Int32 nPos = 0; 1078cdf0e10cSrcweir try 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir typelib_TypeDescriptionReference * member_type= NULL; 1081cdf0e10cSrcweir 1082cdf0e10cSrcweir rtl::OUString usUnoException(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception")); 1083cdf0e10cSrcweir for (; nPos < nMembers; ++nPos) 1084cdf0e10cSrcweir { 1085cdf0e10cSrcweir member_type= comp_td->ppTypeRefs[nPos]; 1086cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= 2 1087cdf0e10cSrcweir System::String* __s; 1088cdf0e10cSrcweir sr::FieldInfo* arFields[]; 1089cdf0e10cSrcweir __s = mapUnoString(comp_td->ppMemberNames[nPos]); 1090cdf0e10cSrcweir arFields = cliType != NULL ? cliType->GetFields() : NULL; 1091cdf0e10cSrcweir #endif 1092cdf0e10cSrcweir System::Object* val= NULL; 1093cdf0e10cSrcweir if (cli_data != NULL) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir sr::FieldInfo* aField= cliType->GetField( 1096cdf0e10cSrcweir mapUnoString(comp_td->ppMemberNames[nPos])); 1097cdf0e10cSrcweir // special case for Exception.Message property 1098cdf0e10cSrcweir // The com.sun.star.uno.Exception.Message field is mapped to the 1099cdf0e10cSrcweir // System.Exception property. Type.GetField("Message") returns null 1100cdf0e10cSrcweir if ( ! aField && usUnoException.equals(td.get()->pTypeName)) 1101cdf0e10cSrcweir {// get Exception.Message property 1102cdf0e10cSrcweir rtl::OUString usMessageMember(RTL_CONSTASCII_USTRINGPARAM("Message")); 1103cdf0e10cSrcweir if (usMessageMember.equals(comp_td->ppMemberNames[nPos])) 1104cdf0e10cSrcweir { 1105cdf0e10cSrcweir sr::PropertyInfo* pi= cliType->GetProperty( 1106cdf0e10cSrcweir mapUnoString(comp_td->ppMemberNames[nPos])); 1107cdf0e10cSrcweir val= pi->GetValue(cli_data, NULL); 1108cdf0e10cSrcweir } 1109cdf0e10cSrcweir else 1110cdf0e10cSrcweir { 1111cdf0e10cSrcweir OUStringBuffer buf(512); 1112cdf0e10cSrcweir buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("[map_to_uno(): Member: ")); 1113cdf0e10cSrcweir buf.append(comp_td->ppMemberNames[nPos]); 1114cdf0e10cSrcweir throw BridgeRuntimeError(buf.makeStringAndClear()); 1115cdf0e10cSrcweir } 1116cdf0e10cSrcweir } 1117cdf0e10cSrcweir else 1118cdf0e10cSrcweir { 1119cdf0e10cSrcweir val= aField->GetValue(cli_data); 1120cdf0e10cSrcweir } 1121cdf0e10cSrcweir } 1122cdf0e10cSrcweir void * p = (char *) uno_data + comp_td->pMemberOffsets[ nPos ]; 1123cdf0e10cSrcweir //When using polymorphic structs then the parameterized members can be null. 1124cdf0e10cSrcweir //Then we set a default value. 1125cdf0e10cSrcweir bool bDefault = ((struct_td != NULL 1126cdf0e10cSrcweir && struct_td->pParameterizedTypes != NULL 1127cdf0e10cSrcweir && struct_td->pParameterizedTypes[nPos] == sal_True 1128cdf0e10cSrcweir && val == NULL) 1129cdf0e10cSrcweir || cli_data == NULL) ? true : false; 1130cdf0e10cSrcweir switch (member_type->eTypeClass) 1131cdf0e10cSrcweir { 1132cdf0e10cSrcweir case typelib_TypeClass_CHAR: 1133cdf0e10cSrcweir if (bDefault) 1134cdf0e10cSrcweir *(sal_Unicode*) p = 0; 1135cdf0e10cSrcweir else 1136cdf0e10cSrcweir *(sal_Unicode*) p = *__try_cast<System::Char*>(val); 1137cdf0e10cSrcweir break; 1138cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 1139cdf0e10cSrcweir if (bDefault) 1140cdf0e10cSrcweir *(sal_Bool*) p = sal_False; 1141cdf0e10cSrcweir else 1142cdf0e10cSrcweir *(sal_Bool*) p = *__try_cast<System::Boolean*>(val); 1143cdf0e10cSrcweir break; 1144cdf0e10cSrcweir case typelib_TypeClass_BYTE: 1145cdf0e10cSrcweir if (bDefault) 1146cdf0e10cSrcweir *(sal_Int8*) p = 0; 1147cdf0e10cSrcweir else 1148cdf0e10cSrcweir *(sal_Int8*) p = *__try_cast<System::Byte*>(val); 1149cdf0e10cSrcweir break; 1150cdf0e10cSrcweir case typelib_TypeClass_SHORT: 1151cdf0e10cSrcweir if (bDefault) 1152cdf0e10cSrcweir *(sal_Int16*) p = 0; 1153cdf0e10cSrcweir else 1154cdf0e10cSrcweir *(sal_Int16*) p = *__try_cast<System::Int16*>(val); 1155cdf0e10cSrcweir break; 1156cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 1157cdf0e10cSrcweir if (bDefault) 1158cdf0e10cSrcweir *(sal_uInt16*) p = 0; 1159cdf0e10cSrcweir else 1160cdf0e10cSrcweir *(sal_uInt16*) p = *__try_cast<System::UInt16*>(val); 1161cdf0e10cSrcweir break; 1162cdf0e10cSrcweir case typelib_TypeClass_LONG: 1163cdf0e10cSrcweir if (bDefault) 1164cdf0e10cSrcweir *(sal_Int32*) p = 0; 1165cdf0e10cSrcweir else 1166cdf0e10cSrcweir *(sal_Int32*) p = *__try_cast<System::Int32*>(val); 1167cdf0e10cSrcweir break; 1168cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 1169cdf0e10cSrcweir if (bDefault) 1170cdf0e10cSrcweir *(sal_uInt32*) p = 0; 1171cdf0e10cSrcweir else 1172cdf0e10cSrcweir *(sal_uInt32*) p = *__try_cast<System::UInt32*>(val); 1173cdf0e10cSrcweir break; 1174cdf0e10cSrcweir case typelib_TypeClass_HYPER: 1175cdf0e10cSrcweir if (bDefault) 1176cdf0e10cSrcweir *(sal_Int64*) p = 0; 1177cdf0e10cSrcweir else 1178cdf0e10cSrcweir *(sal_Int64*) p = *__try_cast<System::Int64*>(val); 1179cdf0e10cSrcweir break; 1180cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 1181cdf0e10cSrcweir if (bDefault) 1182cdf0e10cSrcweir *(sal_uInt64*) p = 0; 1183cdf0e10cSrcweir else 1184cdf0e10cSrcweir *(sal_uInt64*) p= *__try_cast<System::UInt64*>(val); 1185cdf0e10cSrcweir break; 1186cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 1187cdf0e10cSrcweir if (bDefault) 1188cdf0e10cSrcweir *(float*) p = 0.; 1189cdf0e10cSrcweir else 1190cdf0e10cSrcweir *(float*) p = *__try_cast<System::Single*>(val); 1191cdf0e10cSrcweir break; 1192cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 1193cdf0e10cSrcweir if (bDefault) 1194cdf0e10cSrcweir *(double*) p = 0.; 1195cdf0e10cSrcweir else 1196cdf0e10cSrcweir *(double*) p = *__try_cast<System::Double*>(val); 1197cdf0e10cSrcweir break; 1198cdf0e10cSrcweir default: 1199cdf0e10cSrcweir { // ToDo enum, should be converted here 1200cdf0e10cSrcweir map_to_uno(p, val, member_type, assign); 1201cdf0e10cSrcweir break; 1202cdf0e10cSrcweir } 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir } 1205cdf0e10cSrcweir } 1206cdf0e10cSrcweir catch (BridgeRuntimeError& e) 1207cdf0e10cSrcweir { 1208cdf0e10cSrcweir bException= true; 1209cdf0e10cSrcweir OUStringBuffer buf(512); 1210cdf0e10cSrcweir buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("[map_to_uno():")); 1211cdf0e10cSrcweir if (cliType) 1212cdf0e10cSrcweir { 1213cdf0e10cSrcweir buf.append(mapCliString(cliType->get_FullName())); 1214cdf0e10cSrcweir buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(".")); 1215cdf0e10cSrcweir buf.append(comp_td->ppMemberNames[nPos]); 1216cdf0e10cSrcweir buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(" ")); 1217cdf0e10cSrcweir } 1218cdf0e10cSrcweir buf.append(e.m_message); 1219cdf0e10cSrcweir throw BridgeRuntimeError(buf.makeStringAndClear()); 1220cdf0e10cSrcweir } 1221cdf0e10cSrcweir catch (System::InvalidCastException* ) 1222cdf0e10cSrcweir { 1223cdf0e10cSrcweir bException= true; 1224cdf0e10cSrcweir OUStringBuffer buf( 256 ); 1225cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") ); 1226cdf0e10cSrcweir if (cliType) 1227cdf0e10cSrcweir { 1228cdf0e10cSrcweir buf.append(mapCliString(cliType->get_FullName())); 1229cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(".")); 1230cdf0e10cSrcweir buf.append(comp_td->ppMemberNames[nPos]); 1231cdf0e10cSrcweir } 1232cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] Value has not the required type.")); 1233cdf0e10cSrcweir throw BridgeRuntimeError(buf.makeStringAndClear()); 1234cdf0e10cSrcweir } 1235cdf0e10cSrcweir catch (...) 1236cdf0e10cSrcweir { 1237cdf0e10cSrcweir OSL_ASSERT(0); 1238cdf0e10cSrcweir bException= true; 1239cdf0e10cSrcweir throw; 1240cdf0e10cSrcweir } 1241cdf0e10cSrcweir __finally 1242cdf0e10cSrcweir { 1243cdf0e10cSrcweir if (bException && !assign) // if assign then caller cleans up 1244cdf0e10cSrcweir { 1245cdf0e10cSrcweir // cleanup the members which we have converted so far 1246cdf0e10cSrcweir for ( sal_Int32 nCleanup = 0; nCleanup < nPos; ++nCleanup ) 1247cdf0e10cSrcweir { 1248cdf0e10cSrcweir uno_type_destructData( 1249cdf0e10cSrcweir uno_data, comp_td->ppTypeRefs[ nCleanup ], 0 ); 1250cdf0e10cSrcweir } 1251cdf0e10cSrcweir if (0 != comp_td->pBaseTypeDescription) 1252cdf0e10cSrcweir { 1253cdf0e10cSrcweir uno_destructData( 1254cdf0e10cSrcweir uno_data, (typelib_TypeDescription *)comp_td->pBaseTypeDescription, 0 ); 1255cdf0e10cSrcweir } 1256cdf0e10cSrcweir } 1257cdf0e10cSrcweir } 1258cdf0e10cSrcweir break; 1259cdf0e10cSrcweir } 1260cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 1261cdf0e10cSrcweir { 1262cdf0e10cSrcweir TypeDescr td( type ); 1263cdf0e10cSrcweir typelib_TypeDescriptionReference * element_type = 1264cdf0e10cSrcweir ((typelib_IndirectTypeDescription *)td.get())->pType; 1265cdf0e10cSrcweir 1266cdf0e10cSrcweir auto_ptr< rtl_mem > seq; 1267cdf0e10cSrcweir 1268cdf0e10cSrcweir System::Array* ar = NULL; 1269cdf0e10cSrcweir if (cli_data != NULL) 1270cdf0e10cSrcweir { 1271cdf0e10cSrcweir ar = __try_cast<System::Array*>(cli_data); 1272cdf0e10cSrcweir sal_Int32 nElements = ar->GetLength(0); 1273cdf0e10cSrcweir 1274cdf0e10cSrcweir try 1275cdf0e10cSrcweir { 1276cdf0e10cSrcweir switch (element_type->eTypeClass) 1277cdf0e10cSrcweir { 1278cdf0e10cSrcweir case typelib_TypeClass_CHAR: 1279cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (sal_Unicode)); 1280cdf0e10cSrcweir sri::Marshal::Copy(__try_cast<System::Char[]>(cli_data), 0, 1281cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1282cdf0e10cSrcweir break; 1283cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 1284cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (sal_Bool)); 1285cdf0e10cSrcweir sri::Marshal::Copy(__try_cast<System::Boolean[]>(cli_data), 0, 1286cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1287cdf0e10cSrcweir break; 1288cdf0e10cSrcweir case typelib_TypeClass_BYTE: 1289cdf0e10cSrcweir seq = seq_allocate( nElements, sizeof (sal_Int8) ); 1290cdf0e10cSrcweir sri::Marshal::Copy(__try_cast<System::Byte[]>(cli_data), 0, 1291cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1292cdf0e10cSrcweir break; 1293cdf0e10cSrcweir case typelib_TypeClass_SHORT: 1294cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (sal_Int16)); 1295cdf0e10cSrcweir sri::Marshal::Copy(__try_cast<System::Int16[]>(cli_data), 0, 1296cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1297cdf0e10cSrcweir break; 1298cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 1299cdf0e10cSrcweir seq = seq_allocate( nElements, sizeof (sal_uInt16) ); 1300cdf0e10cSrcweir sri::Marshal::Copy(static_cast<System::Int16[]>( 1301cdf0e10cSrcweir __try_cast<System::UInt16[]>(cli_data)), 0, 1302cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1303cdf0e10cSrcweir break; 1304cdf0e10cSrcweir case typelib_TypeClass_LONG: 1305cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (sal_Int32)); 1306cdf0e10cSrcweir sri::Marshal::Copy(__try_cast<System::Int32[]>(cli_data), 0, 1307cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1308cdf0e10cSrcweir break; 1309cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 1310cdf0e10cSrcweir seq = seq_allocate( nElements, sizeof (sal_uInt32) ); 1311cdf0e10cSrcweir sri::Marshal::Copy(static_cast<System::Int32[]>( 1312cdf0e10cSrcweir __try_cast<System::UInt32[]>(cli_data)), 0, 1313cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1314cdf0e10cSrcweir break; 1315cdf0e10cSrcweir case typelib_TypeClass_HYPER: 1316cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (sal_Int64)); 1317cdf0e10cSrcweir sri::Marshal::Copy(__try_cast<System::Int64[]>(cli_data), 0, 1318cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1319cdf0e10cSrcweir break; 1320cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 1321cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (sal_uInt64)); 1322cdf0e10cSrcweir sri::Marshal::Copy(static_cast<System::Int64[]>( 1323cdf0e10cSrcweir __try_cast<System::UInt64[]>(cli_data)), 0, 1324cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1325cdf0e10cSrcweir break; 1326cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 1327cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (float)); 1328cdf0e10cSrcweir sri::Marshal::Copy(__try_cast<System::Single[]>(cli_data), 0, 1329cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1330cdf0e10cSrcweir break; 1331cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 1332cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (double)); 1333cdf0e10cSrcweir sri::Marshal::Copy(__try_cast<System::Double[]>(cli_data), 0, 1334cdf0e10cSrcweir & ((uno_Sequence*) seq.get())->elements, nElements); 1335cdf0e10cSrcweir break; 1336cdf0e10cSrcweir case typelib_TypeClass_STRING: 1337cdf0e10cSrcweir { 1338cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (rtl_uString*)); 1339cdf0e10cSrcweir System::String* arStr[]= __try_cast<System::String*[]>(cli_data); 1340cdf0e10cSrcweir for (int i= 0; i < nElements; i++) 1341cdf0e10cSrcweir { 1342cdf0e10cSrcweir wchar_t const __pin * pdata= PtrToStringChars(arStr[i]); 1343cdf0e10cSrcweir rtl_uString** pStr= & ((rtl_uString**) & 1344cdf0e10cSrcweir ((uno_Sequence*) seq.get())->elements)[i]; 1345cdf0e10cSrcweir *pStr= NULL; 1346cdf0e10cSrcweir rtl_uString_newFromStr_WithLength( pStr, pdata, 1347cdf0e10cSrcweir arStr[i]->get_Length()); 1348cdf0e10cSrcweir } 1349cdf0e10cSrcweir break; 1350cdf0e10cSrcweir } 1351cdf0e10cSrcweir case typelib_TypeClass_ENUM: 1352cdf0e10cSrcweir seq = seq_allocate(nElements, sizeof (sal_Int32)); 1353cdf0e10cSrcweir for (int i= 0; i < nElements; i++) 1354cdf0e10cSrcweir { 1355cdf0e10cSrcweir ((sal_Int32*) &((uno_Sequence*) seq.get())->elements)[i]= 1356cdf0e10cSrcweir System::Convert::ToInt32(ar->GetValue(i)); 1357cdf0e10cSrcweir } 1358cdf0e10cSrcweir break; 1359cdf0e10cSrcweir case typelib_TypeClass_TYPE: 1360cdf0e10cSrcweir case typelib_TypeClass_ANY: 1361cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 1362cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 1363cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 1364cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 1365cdf0e10cSrcweir { 1366cdf0e10cSrcweir TypeDescr element_td( element_type ); 1367cdf0e10cSrcweir seq = seq_allocate( nElements, element_td.get()->nSize ); 1368cdf0e10cSrcweir 1369cdf0e10cSrcweir for (sal_Int32 nPos = 0; nPos < nElements; ++nPos) 1370cdf0e10cSrcweir { 1371cdf0e10cSrcweir try 1372cdf0e10cSrcweir { 1373cdf0e10cSrcweir void * p= ((uno_Sequence *) seq.get())->elements + 1374cdf0e10cSrcweir (nPos * element_td.get()->nSize); 1375cdf0e10cSrcweir System::Object* elemData= dynamic_cast<System::Array*>(cli_data)->GetValue(nPos); 1376cdf0e10cSrcweir map_to_uno( 1377cdf0e10cSrcweir p, elemData, element_td.get()->pWeakRef, 1378cdf0e10cSrcweir false /* no assign */); 1379cdf0e10cSrcweir } 1380cdf0e10cSrcweir catch (...) 1381cdf0e10cSrcweir { 1382cdf0e10cSrcweir // cleanup 1383cdf0e10cSrcweir for ( sal_Int32 nCleanPos = 0; nCleanPos < nPos; ++nCleanPos ) 1384cdf0e10cSrcweir { 1385cdf0e10cSrcweir void * p = 1386cdf0e10cSrcweir ((uno_Sequence *)seq.get())->elements + 1387cdf0e10cSrcweir (nCleanPos * element_td.get()->nSize); 1388cdf0e10cSrcweir uno_destructData( p, element_td.get(), 0 ); 1389cdf0e10cSrcweir } 1390cdf0e10cSrcweir throw; 1391cdf0e10cSrcweir } 1392cdf0e10cSrcweir } 1393cdf0e10cSrcweir break; 1394cdf0e10cSrcweir } 1395cdf0e10cSrcweir default: 1396cdf0e10cSrcweir { 1397cdf0e10cSrcweir OUStringBuffer buf( 128 ); 1398cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") ); 1399cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) ); 1400cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported sequence element type: ") ); 1401cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &element_type->pTypeName ) ); 1402cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 1403cdf0e10cSrcweir } 1404cdf0e10cSrcweir } 1405cdf0e10cSrcweir } 1406cdf0e10cSrcweir catch (BridgeRuntimeError& e) 1407cdf0e10cSrcweir { 1408cdf0e10cSrcweir OUStringBuffer buf( 128 ); 1409cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") ); 1410cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName )); 1411cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] conversion failed\n ")); 1412cdf0e10cSrcweir buf.append(e.m_message); 1413cdf0e10cSrcweir throw BridgeRuntimeError(buf.makeStringAndClear()); 1414cdf0e10cSrcweir } 1415cdf0e10cSrcweir catch (System::InvalidCastException* ) 1416cdf0e10cSrcweir { 1417cdf0e10cSrcweir // Ok, checked 1418cdf0e10cSrcweir OUStringBuffer buf( 128 ); 1419cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") ); 1420cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName) ); 1421cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] could not convert sequence element type: ") ); 1422cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &element_type->pTypeName ) ); 1423cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 1424cdf0e10cSrcweir } 1425cdf0e10cSrcweir catch (...) 1426cdf0e10cSrcweir { 1427cdf0e10cSrcweir OSL_ASSERT(0); 1428cdf0e10cSrcweir throw; 1429cdf0e10cSrcweir } 1430cdf0e10cSrcweir __finally 1431cdf0e10cSrcweir { 1432cdf0e10cSrcweir if (assign) 1433cdf0e10cSrcweir uno_destructData( uno_data, td.get(), 0 ); 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir } 1436cdf0e10cSrcweir else 1437cdf0e10cSrcweir { 1438cdf0e10cSrcweir seq = seq_allocate(0, sizeof (sal_Int32)); 1439cdf0e10cSrcweir } 1440cdf0e10cSrcweir *(uno_Sequence **)uno_data = (uno_Sequence *)seq.release(); 1441cdf0e10cSrcweir break; 1442cdf0e10cSrcweir } 1443cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 1444cdf0e10cSrcweir { 1445cdf0e10cSrcweir if (assign) 1446cdf0e10cSrcweir { 1447cdf0e10cSrcweir uno_Interface * p = *(uno_Interface **)uno_data; 1448cdf0e10cSrcweir if (0 != p) 1449cdf0e10cSrcweir (*p->release)( p ); 1450cdf0e10cSrcweir } 1451cdf0e10cSrcweir if (0 == cli_data) // null-ref 1452cdf0e10cSrcweir { 1453cdf0e10cSrcweir *(uno_Interface **)uno_data = 0; 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir else 1456cdf0e10cSrcweir { 1457cdf0e10cSrcweir TypeDescr td( type ); 1458cdf0e10cSrcweir uno_Interface * pUnoI = map_cli2uno(cli_data, td.get()); 1459cdf0e10cSrcweir *(uno_Interface **)uno_data = pUnoI; 1460cdf0e10cSrcweir } 1461cdf0e10cSrcweir break; 1462cdf0e10cSrcweir } 1463cdf0e10cSrcweir default: 1464cdf0e10cSrcweir { 1465cdf0e10cSrcweir //ToDo check 1466cdf0e10cSrcweir OUStringBuffer buf( 128 ); 1467cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") ); 1468cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) ); 1469cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported type!") ); 1470cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 1471cdf0e10cSrcweir } 1472cdf0e10cSrcweir } 1473cdf0e10cSrcweir } 1474cdf0e10cSrcweir // BridgeRuntimeError are allowed to be thrown 1475cdf0e10cSrcweir catch (System::InvalidCastException* ) 1476cdf0e10cSrcweir { 1477cdf0e10cSrcweir //ToDo check 1478cdf0e10cSrcweir OUStringBuffer buf( 128 ); 1479cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") ); 1480cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) ); 1481cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] could not convert type!") ); 1482cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 1483cdf0e10cSrcweir } 1484cdf0e10cSrcweir catch (System::NullReferenceException * e) 1485cdf0e10cSrcweir { 1486cdf0e10cSrcweir OUStringBuffer buf(512); 1487cdf0e10cSrcweir buf.appendAscii(RTL_CONSTASCII_STRINGPARAM( 1488cdf0e10cSrcweir "[map_to_uno()] Illegal null reference passed!\n")); 1489cdf0e10cSrcweir buf.append(mapCliString(e->get_StackTrace())); 1490cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 1491cdf0e10cSrcweir } 1492cdf0e10cSrcweir catch (BridgeRuntimeError& ) 1493cdf0e10cSrcweir { 1494cdf0e10cSrcweir throw; 1495cdf0e10cSrcweir } 1496cdf0e10cSrcweir catch (...) 1497cdf0e10cSrcweir { 1498cdf0e10cSrcweir OSL_ASSERT(0); 1499cdf0e10cSrcweir throw; 1500cdf0e10cSrcweir } 1501cdf0e10cSrcweir 1502cdf0e10cSrcweir } 1503cdf0e10cSrcweir 1504cdf0e10cSrcweir /** 1505cdf0e10cSrcweir @param info 1506cdf0e10cSrcweir The expected target type. Currently info is provdided when this method is called 1507cdf0e10cSrcweir to convert the in/out and out parameters of a call from cli to uno. Then info 1508cdf0e10cSrcweir is always a byref type, e.g. "System.String&". info is used for Any and Enum conversion. 1509cdf0e10cSrcweir @param bDontCreateObj 1510cdf0e10cSrcweir false - a new object is created which holds the mapped uno value and is assigned to 1511cdf0e10cSrcweir cli_data. 1512cdf0e10cSrcweir true - cli_data already contains the newly constructed object. This is the case if 1513cdf0e10cSrcweir a struct is converted then on the first call to map_to_cli the new object is created. 1514cdf0e10cSrcweir If the struct inherits another struct then this function is called recursivly while the 1515cdf0e10cSrcweir newly created object is passed in cli_data. 1516cdf0e10cSrcweir */ 1517cdf0e10cSrcweir void Bridge::map_to_cli( 1518cdf0e10cSrcweir System::Object* *cli_data, void const * uno_data, 1519cdf0e10cSrcweir typelib_TypeDescriptionReference * type, System::Type* info, 1520cdf0e10cSrcweir bool bDontCreateObj) const 1521cdf0e10cSrcweir { 1522cdf0e10cSrcweir switch (type->eTypeClass) 1523cdf0e10cSrcweir { 1524cdf0e10cSrcweir case typelib_TypeClass_CHAR: 1525cdf0e10cSrcweir *cli_data= __box(*(__wchar_t const*)uno_data); 1526cdf0e10cSrcweir break; 1527cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 1528cdf0e10cSrcweir *cli_data = __box((*(bool const*)uno_data) == sal_True ? true : false); 1529cdf0e10cSrcweir break; 1530cdf0e10cSrcweir case typelib_TypeClass_BYTE: 1531cdf0e10cSrcweir *cli_data = __box(*(unsigned char const*) uno_data); 1532cdf0e10cSrcweir break; 1533cdf0e10cSrcweir case typelib_TypeClass_SHORT: 1534cdf0e10cSrcweir *cli_data= __box(*(short const*) uno_data); 1535cdf0e10cSrcweir break; 1536cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 1537cdf0e10cSrcweir *cli_data= __box(*(unsigned short const*) uno_data); 1538cdf0e10cSrcweir break; 1539cdf0e10cSrcweir case typelib_TypeClass_LONG: 1540cdf0e10cSrcweir *cli_data= __box(*(int const*) uno_data); 1541cdf0e10cSrcweir break; 1542cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 1543cdf0e10cSrcweir *cli_data= __box(*(unsigned int const*) uno_data); 1544cdf0e10cSrcweir break; 1545cdf0e10cSrcweir case typelib_TypeClass_HYPER: 1546cdf0e10cSrcweir *cli_data= __box(*(__int64 const*) uno_data); 1547cdf0e10cSrcweir break; 1548cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 1549cdf0e10cSrcweir *cli_data= __box(*(unsigned __int64 const*) uno_data); 1550cdf0e10cSrcweir break; 1551cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 1552cdf0e10cSrcweir *cli_data= __box(*(float const*) uno_data); 1553cdf0e10cSrcweir break; 1554cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 1555cdf0e10cSrcweir *cli_data= __box(*(double const*) uno_data); 1556cdf0e10cSrcweir break; 1557cdf0e10cSrcweir case typelib_TypeClass_STRING: 1558cdf0e10cSrcweir { 1559cdf0e10cSrcweir rtl_uString const* sVal= NULL; 1560cdf0e10cSrcweir sVal= *(rtl_uString* const*) uno_data; 1561cdf0e10cSrcweir *cli_data= new System::String((__wchar_t*) sVal->buffer,0, sVal->length); 1562cdf0e10cSrcweir break; 1563cdf0e10cSrcweir } 1564cdf0e10cSrcweir case typelib_TypeClass_TYPE: 1565cdf0e10cSrcweir { 1566cdf0e10cSrcweir *cli_data= mapUnoType( *(typelib_TypeDescriptionReference * const *)uno_data ); 1567cdf0e10cSrcweir break; 1568cdf0e10cSrcweir } 1569cdf0e10cSrcweir case typelib_TypeClass_ANY: 1570cdf0e10cSrcweir { 1571cdf0e10cSrcweir uno_Any const * pAny = (uno_Any const *)uno_data; 1572cdf0e10cSrcweir if (typelib_TypeClass_VOID != pAny->pType->eTypeClass) 1573cdf0e10cSrcweir { 1574cdf0e10cSrcweir System::Object* objCli= NULL; 1575cdf0e10cSrcweir map_to_cli( 1576cdf0e10cSrcweir &objCli, pAny->pData, pAny->pType, 0, 1577cdf0e10cSrcweir false); 1578cdf0e10cSrcweir 1579cdf0e10cSrcweir uno::Any anyVal(mapUnoType(pAny->pType), objCli); 1580cdf0e10cSrcweir *cli_data= __box(anyVal); 1581cdf0e10cSrcweir } 1582cdf0e10cSrcweir else 1583cdf0e10cSrcweir { // void any 1584cdf0e10cSrcweir *cli_data= __box(uno::Any::VOID); 1585cdf0e10cSrcweir } 1586cdf0e10cSrcweir break; 1587cdf0e10cSrcweir } 1588cdf0e10cSrcweir case typelib_TypeClass_ENUM: 1589cdf0e10cSrcweir { 1590cdf0e10cSrcweir if (info != NULL) 1591cdf0e10cSrcweir { 1592cdf0e10cSrcweir OSL_ASSERT(info->get_IsByRef()); 1593cdf0e10cSrcweir info= info->GetElementType(); 1594cdf0e10cSrcweir *cli_data= System::Enum::ToObject(info, *(System::Int32*) uno_data); 1595cdf0e10cSrcweir } 1596cdf0e10cSrcweir else 1597cdf0e10cSrcweir *cli_data= System::Enum::ToObject( 1598cdf0e10cSrcweir mapUnoType(type), *(System::Int32*) uno_data); 1599cdf0e10cSrcweir break; 1600cdf0e10cSrcweir } 1601cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 1602cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 1603cdf0e10cSrcweir { 1604cdf0e10cSrcweir TypeDescr td( type ); 1605cdf0e10cSrcweir typelib_CompoundTypeDescription * comp_td = 1606cdf0e10cSrcweir (typelib_CompoundTypeDescription *) td.get(); 1607cdf0e10cSrcweir if ( ! ((typelib_TypeDescription*) comp_td)->bComplete) 1608cdf0e10cSrcweir ::typelib_typedescription_complete( 1609cdf0e10cSrcweir (typelib_TypeDescription**) & comp_td ); 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir 1612cdf0e10cSrcweir //create the type 1613cdf0e10cSrcweir System::Type* cliType= loadCliType(td.get()->pTypeName); 1614cdf0e10cSrcweir //detect if we recursivly convert inherited structures 1615cdf0e10cSrcweir //If this point is reached because of a recursive call during convering a 1616cdf0e10cSrcweir //struct then we must not create a new object rather we use the one in 1617cdf0e10cSrcweir // cli_data argument. 1618cdf0e10cSrcweir System::Object* cliObj; 1619cdf0e10cSrcweir if (bDontCreateObj) 1620cdf0e10cSrcweir cliObj = *cli_data; // recursive call 1621cdf0e10cSrcweir else 1622cdf0e10cSrcweir { 1623cdf0e10cSrcweir //Special handling for Exception conversion. We must call constructor System::Exception 1624cdf0e10cSrcweir //to pass the message string 1625cdf0e10cSrcweir if (__typeof(ucss::uno::Exception)->IsAssignableFrom(cliType)) 1626cdf0e10cSrcweir { 1627cdf0e10cSrcweir //We need to get the Message field. Therefore we must obtain the offset from 1628cdf0e10cSrcweir //the typedescription. The base interface of all exceptions is 1629cdf0e10cSrcweir //com::sun::star::uno::Exception which contains the message 1630cdf0e10cSrcweir typelib_CompoundTypeDescription* pCTD = comp_td; 1631cdf0e10cSrcweir while (pCTD->pBaseTypeDescription) 1632cdf0e10cSrcweir pCTD = pCTD->pBaseTypeDescription; 1633cdf0e10cSrcweir int nPos = -1; 1634cdf0e10cSrcweir 1635cdf0e10cSrcweir rtl::OUString usMessageMember(RTL_CONSTASCII_USTRINGPARAM("Message")); 1636cdf0e10cSrcweir for (int i = 0; i < pCTD->nMembers; i ++) 1637cdf0e10cSrcweir { 1638cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= 2 1639cdf0e10cSrcweir System::String* sMember; 1640cdf0e10cSrcweir sMember = mapUnoString(pCTD->ppMemberNames[i]); 1641cdf0e10cSrcweir #endif 1642cdf0e10cSrcweir if (usMessageMember.equals(pCTD->ppMemberNames[i])) 1643cdf0e10cSrcweir { 1644cdf0e10cSrcweir nPos = i; 1645cdf0e10cSrcweir break; 1646cdf0e10cSrcweir } 1647cdf0e10cSrcweir } 1648cdf0e10cSrcweir OSL_ASSERT (nPos != -1); 1649cdf0e10cSrcweir int offset = pCTD->pMemberOffsets[nPos]; 165007a3d7f1SPedro Giffuni //With the offset within the exception we can get the message string 1651cdf0e10cSrcweir System::String* sMessage = mapUnoString(*(rtl_uString**) 1652cdf0e10cSrcweir ((char*) uno_data + offset)); 1653cdf0e10cSrcweir //We need to find a constructor for the exception that takes the message string 1654cdf0e10cSrcweir //We assume that the first argument is the message string 1655cdf0e10cSrcweir sr::ConstructorInfo* arCtorInfo[] = cliType->GetConstructors(); 1656cdf0e10cSrcweir sr::ConstructorInfo* ctorInfo = NULL; 1657cdf0e10cSrcweir int numCtors = arCtorInfo->get_Length(); 1658cdf0e10cSrcweir //Constructor must at least have 2 params for the base 1659cdf0e10cSrcweir //unoidl.com.sun.star.uno.Exception (String, Object); 1660cdf0e10cSrcweir sr::ParameterInfo * arParamInfo[]; 1661cdf0e10cSrcweir for (int i = 0; i < numCtors; i++) 1662cdf0e10cSrcweir { 1663cdf0e10cSrcweir arParamInfo = arCtorInfo[i]->GetParameters(); 1664cdf0e10cSrcweir if (arParamInfo->get_Length() < 2) 1665cdf0e10cSrcweir continue; 1666cdf0e10cSrcweir ctorInfo = arCtorInfo[i]; 1667cdf0e10cSrcweir break; 1668cdf0e10cSrcweir } 1669cdf0e10cSrcweir OSL_ASSERT(arParamInfo[0]->get_ParameterType()->Equals(__typeof(System::String)) 1670cdf0e10cSrcweir && arParamInfo[1]->get_ParameterType()->Equals(__typeof(System::Object)) 1671cdf0e10cSrcweir && arParamInfo[0]->get_Position() == 0 1672cdf0e10cSrcweir && arParamInfo[1]->get_Position() == 1); 1673cdf0e10cSrcweir //Prepare parameters for constructor 1674cdf0e10cSrcweir int numArgs = arParamInfo->get_Length(); 1675cdf0e10cSrcweir System::Object * args[] = new System::Object*[numArgs]; 1676cdf0e10cSrcweir //only initialize the first argument with the message 1677cdf0e10cSrcweir args[0] = sMessage; 1678cdf0e10cSrcweir cliObj = ctorInfo->Invoke(args); 1679cdf0e10cSrcweir } 1680cdf0e10cSrcweir else 1681cdf0e10cSrcweir cliObj = System::Activator::CreateInstance(cliType); 1682cdf0e10cSrcweir } 1683cdf0e10cSrcweir sal_Int32 * pMemberOffsets = comp_td->pMemberOffsets; 1684cdf0e10cSrcweir 1685cdf0e10cSrcweir if (comp_td->pBaseTypeDescription) 1686cdf0e10cSrcweir { 1687cdf0e10cSrcweir //convert inherited struct 1688cdf0e10cSrcweir //cliObj is passed inout (args in_param, out_param are true), hence the passed 1689cdf0e10cSrcweir // cliObj is used by the callee instead of a newly created struct 1690cdf0e10cSrcweir map_to_cli( 1691cdf0e10cSrcweir &cliObj, uno_data, 1692cdf0e10cSrcweir ((typelib_TypeDescription *)comp_td->pBaseTypeDescription)->pWeakRef, 0, 1693cdf0e10cSrcweir true); 1694cdf0e10cSrcweir } 1695cdf0e10cSrcweir rtl::OUString usUnoException(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception")); 1696cdf0e10cSrcweir for (sal_Int32 nPos = comp_td->nMembers; nPos--; ) 1697cdf0e10cSrcweir { 1698cdf0e10cSrcweir typelib_TypeDescriptionReference * member_type = comp_td->ppTypeRefs[ nPos ]; 1699cdf0e10cSrcweir System::String* sMemberName= mapUnoString(comp_td->ppMemberNames[nPos]); 1700cdf0e10cSrcweir sr::FieldInfo* aField= cliType->GetField(sMemberName); 1701cdf0e10cSrcweir // special case for Exception.Message. The field has already been 1702cdf0e10cSrcweir // set while constructing cli object 1703cdf0e10cSrcweir if ( ! aField && usUnoException.equals(td.get()->pTypeName)) 1704cdf0e10cSrcweir { 1705cdf0e10cSrcweir continue; 1706cdf0e10cSrcweir } 1707cdf0e10cSrcweir void const * p = (char const *)uno_data + pMemberOffsets[ nPos ]; 1708cdf0e10cSrcweir switch (member_type->eTypeClass) 1709cdf0e10cSrcweir { 1710cdf0e10cSrcweir case typelib_TypeClass_CHAR: 1711cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::Char*) p)); 1712cdf0e10cSrcweir break; 1713cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 1714cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::Boolean*) p)); 1715cdf0e10cSrcweir break; 1716cdf0e10cSrcweir case typelib_TypeClass_BYTE: 1717cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::Byte*) p)); 1718cdf0e10cSrcweir break; 1719cdf0e10cSrcweir case typelib_TypeClass_SHORT: 1720cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::Int16*) p)); 1721cdf0e10cSrcweir break; 1722cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 1723cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::UInt16*) p)); 1724cdf0e10cSrcweir break; 1725cdf0e10cSrcweir case typelib_TypeClass_LONG: 1726cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::Int32*) p)); 1727cdf0e10cSrcweir break; 1728cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 1729cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::UInt32*) p)); 1730cdf0e10cSrcweir break; 1731cdf0e10cSrcweir case typelib_TypeClass_HYPER: 1732cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::Int64*) p)); 1733cdf0e10cSrcweir break; 1734cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 1735cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::UInt64*) p)); 1736cdf0e10cSrcweir break; 1737cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 1738cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::Single*) p)); 1739cdf0e10cSrcweir break; 1740cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 1741cdf0e10cSrcweir aField->SetValue(cliObj, __box(*(System::Double*) p)); 1742cdf0e10cSrcweir break; 1743cdf0e10cSrcweir default: 1744cdf0e10cSrcweir { 1745cdf0e10cSrcweir System::Object* cli_val; 1746cdf0e10cSrcweir map_to_cli( 1747cdf0e10cSrcweir &cli_val, p, member_type, 0, 1748cdf0e10cSrcweir false); 1749cdf0e10cSrcweir aField->SetValue(cliObj, cli_val); 1750cdf0e10cSrcweir break; 1751cdf0e10cSrcweir } 1752cdf0e10cSrcweir } 1753cdf0e10cSrcweir } 1754cdf0e10cSrcweir *cli_data= cliObj; 1755cdf0e10cSrcweir break; 1756cdf0e10cSrcweir } 1757cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 1758cdf0e10cSrcweir { 1759cdf0e10cSrcweir sal_Int32 nElements; 1760cdf0e10cSrcweir uno_Sequence const * seq = 0; 1761cdf0e10cSrcweir seq = *(uno_Sequence * const *)uno_data; 1762cdf0e10cSrcweir nElements = seq->nElements; 1763cdf0e10cSrcweir 1764cdf0e10cSrcweir TypeDescr td( type ); 1765cdf0e10cSrcweir typelib_TypeDescriptionReference * element_type = 1766cdf0e10cSrcweir ((typelib_IndirectTypeDescription *)td.get())->pType; 1767cdf0e10cSrcweir 1768cdf0e10cSrcweir switch (element_type->eTypeClass) 1769cdf0e10cSrcweir { 1770cdf0e10cSrcweir case typelib_TypeClass_CHAR: 1771cdf0e10cSrcweir { 1772cdf0e10cSrcweir System::Char arChar[]= new System::Char[nElements]; 1773cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arChar, 0, nElements); 1774cdf0e10cSrcweir *cli_data= arChar; 1775cdf0e10cSrcweir break; 1776cdf0e10cSrcweir } 1777cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 1778cdf0e10cSrcweir { 1779cdf0e10cSrcweir System::Boolean arBool[]= new System::Boolean[nElements]; 1780cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arBool, 0, nElements); 1781cdf0e10cSrcweir *cli_data= arBool; 1782cdf0e10cSrcweir break; 1783cdf0e10cSrcweir } 1784cdf0e10cSrcweir case typelib_TypeClass_BYTE: 1785cdf0e10cSrcweir { 1786cdf0e10cSrcweir System::Byte arByte[]= new System::Byte[nElements]; 1787cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arByte, 0, nElements); 1788cdf0e10cSrcweir *cli_data= arByte; 1789cdf0e10cSrcweir break; 1790cdf0e10cSrcweir } 1791cdf0e10cSrcweir case typelib_TypeClass_SHORT: 1792cdf0e10cSrcweir { 1793cdf0e10cSrcweir System::Int16 arShort[]= new System::Int16[nElements]; 1794cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arShort, 0, nElements); 1795cdf0e10cSrcweir *cli_data= arShort; 1796cdf0e10cSrcweir break; 1797cdf0e10cSrcweir } 1798cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 1799cdf0e10cSrcweir { 1800cdf0e10cSrcweir System::UInt16 arUInt16[]= new System::UInt16[nElements]; 1801cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, static_cast<System::Int16[]>(arUInt16), 1802cdf0e10cSrcweir 0, nElements); 1803cdf0e10cSrcweir *cli_data= arUInt16; 1804cdf0e10cSrcweir break; 1805cdf0e10cSrcweir } 1806cdf0e10cSrcweir case typelib_TypeClass_LONG: 1807cdf0e10cSrcweir { 1808cdf0e10cSrcweir System::Int32 arInt32[]= new System::Int32[nElements]; 1809cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arInt32, 0, nElements); 1810cdf0e10cSrcweir *cli_data= arInt32; 1811cdf0e10cSrcweir break; 1812cdf0e10cSrcweir } 1813cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 1814cdf0e10cSrcweir { 1815cdf0e10cSrcweir System::UInt32 arUInt32[]= new System::UInt32[nElements]; 1816cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, static_cast<System::Int32[]>(arUInt32), 1817cdf0e10cSrcweir 0, nElements); 1818cdf0e10cSrcweir *cli_data= arUInt32; 1819cdf0e10cSrcweir break; 1820cdf0e10cSrcweir } 1821cdf0e10cSrcweir case typelib_TypeClass_HYPER: 1822cdf0e10cSrcweir { 1823cdf0e10cSrcweir System::Int64 arInt64[]= new System::Int64[nElements]; 1824cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arInt64, 0, nElements); 1825cdf0e10cSrcweir *cli_data= arInt64; 1826cdf0e10cSrcweir break; 1827cdf0e10cSrcweir } 1828cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 1829cdf0e10cSrcweir { 1830cdf0e10cSrcweir System::UInt64 arUInt64[]= new System::UInt64[nElements]; 1831cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arUInt64, 0, nElements); 1832cdf0e10cSrcweir *cli_data= arUInt64; 1833cdf0e10cSrcweir break; 1834cdf0e10cSrcweir } 1835cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 1836cdf0e10cSrcweir { 1837cdf0e10cSrcweir System::Single arSingle[]= new System::Single[nElements]; 1838cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arSingle, 0, nElements); 1839cdf0e10cSrcweir *cli_data= arSingle; 1840cdf0e10cSrcweir break; 1841cdf0e10cSrcweir } 1842cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 1843cdf0e10cSrcweir { 1844cdf0e10cSrcweir System::Double arDouble[]= new System::Double[nElements]; 1845cdf0e10cSrcweir sri::Marshal::Copy( (void*) &seq->elements, arDouble, 0, nElements); 1846cdf0e10cSrcweir *cli_data= arDouble; 1847cdf0e10cSrcweir break; 1848cdf0e10cSrcweir } 1849cdf0e10cSrcweir case typelib_TypeClass_STRING: 1850cdf0e10cSrcweir { 1851cdf0e10cSrcweir System::String* arString[]= new System::String*[nElements]; 1852cdf0e10cSrcweir for (int i= 0; i < nElements; i++) 1853cdf0e10cSrcweir { 1854cdf0e10cSrcweir rtl_uString *aStr= ((rtl_uString**)(&seq->elements))[i]; 1855cdf0e10cSrcweir arString[i]= new System::String( (__wchar_t *) &aStr->buffer, 0, aStr->length); 1856cdf0e10cSrcweir } 1857cdf0e10cSrcweir *cli_data= arString; 1858cdf0e10cSrcweir break; 1859cdf0e10cSrcweir } 1860cdf0e10cSrcweir case typelib_TypeClass_TYPE: 1861cdf0e10cSrcweir { 1862cdf0e10cSrcweir System::Type* arType[]= new System::Type*[nElements]; 1863cdf0e10cSrcweir for (int i= 0; i < nElements; i++) 1864cdf0e10cSrcweir { 1865cdf0e10cSrcweir arType[i]= 1866cdf0e10cSrcweir mapUnoType( ((typelib_TypeDescriptionReference**) seq->elements)[i]); 1867cdf0e10cSrcweir } 1868cdf0e10cSrcweir *cli_data= arType; 1869cdf0e10cSrcweir break; 1870cdf0e10cSrcweir } 1871cdf0e10cSrcweir case typelib_TypeClass_ANY: 1872cdf0e10cSrcweir { 1873cdf0e10cSrcweir uno::Any arCli[]= new uno::Any[nElements]; 1874cdf0e10cSrcweir uno_Any const * p = (uno_Any const *)seq->elements; 1875cdf0e10cSrcweir for (sal_Int32 nPos = 0; nPos < nElements; ++nPos ) 1876cdf0e10cSrcweir { 1877cdf0e10cSrcweir System::Object* cli_obj = NULL; 1878cdf0e10cSrcweir map_to_cli( 1879cdf0e10cSrcweir &cli_obj, &p[ nPos ], element_type, 0, false); 1880cdf0e10cSrcweir arCli[nPos]= *__try_cast<__box uno::Any*>(cli_obj); 1881cdf0e10cSrcweir } 1882cdf0e10cSrcweir *cli_data= arCli; 1883cdf0e10cSrcweir break; 1884cdf0e10cSrcweir } 1885cdf0e10cSrcweir case typelib_TypeClass_ENUM: 1886cdf0e10cSrcweir { 1887cdf0e10cSrcweir //get the Enum type 1888cdf0e10cSrcweir System::Type* enumType= NULL; 1889cdf0e10cSrcweir if (info != NULL) 1890cdf0e10cSrcweir { 1891cdf0e10cSrcweir //info is EnumType[]&, remove & 1892cdf0e10cSrcweir OSL_ASSERT(info->IsByRef); 1893cdf0e10cSrcweir enumType = info->GetElementType(); 1894cdf0e10cSrcweir //enumType is EnumType[], remove [] 1895cdf0e10cSrcweir enumType = enumType->GetElementType(); 1896cdf0e10cSrcweir } 1897cdf0e10cSrcweir else 1898cdf0e10cSrcweir enumType= mapUnoType(element_type); 1899cdf0e10cSrcweir 1900cdf0e10cSrcweir System::Array* arEnum = System::Array::CreateInstance( 1901cdf0e10cSrcweir enumType, nElements); 1902cdf0e10cSrcweir for (int i= 0; i < nElements; i++) 1903cdf0e10cSrcweir { 1904cdf0e10cSrcweir arEnum->SetValue(System::Enum::ToObject(enumType, 1905cdf0e10cSrcweir ((sal_Int32*) seq->elements)[i]), i); 1906cdf0e10cSrcweir } 1907cdf0e10cSrcweir *cli_data = arEnum; 1908cdf0e10cSrcweir break; 1909cdf0e10cSrcweir } 1910cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 1911cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 1912cdf0e10cSrcweir { 1913cdf0e10cSrcweir TypeDescr element_td( element_type ); 1914cdf0e10cSrcweir System::Array* ar= System::Array::CreateInstance( 1915cdf0e10cSrcweir mapUnoType(element_type),nElements); 1916cdf0e10cSrcweir if (0 < nElements) 1917cdf0e10cSrcweir { 1918cdf0e10cSrcweir // ToDo check this 1919cdf0e10cSrcweir char * p = (char *) &seq->elements; 1920cdf0e10cSrcweir sal_Int32 nSize = element_td.get()->nSize; 1921cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos ) 1922cdf0e10cSrcweir { 1923cdf0e10cSrcweir System::Object* val; 1924cdf0e10cSrcweir map_to_cli( 1925cdf0e10cSrcweir &val, p + (nSize * nPos), element_type, 0, false); 1926cdf0e10cSrcweir ar->SetValue(val, nPos); 1927cdf0e10cSrcweir } 1928cdf0e10cSrcweir } 1929cdf0e10cSrcweir *cli_data = ar; 1930cdf0e10cSrcweir break; 1931cdf0e10cSrcweir } 1932cdf0e10cSrcweir // ToDo, verify 1933cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 1934cdf0e10cSrcweir { 1935cdf0e10cSrcweir System::Array *ar= System::Array::CreateInstance( 1936cdf0e10cSrcweir mapUnoType(element_type), nElements); 1937cdf0e10cSrcweir if (0 < nElements) 1938cdf0e10cSrcweir { 1939cdf0e10cSrcweir TypeDescr element_td( element_type ); 1940cdf0e10cSrcweir uno_Sequence ** elements = (uno_Sequence**) seq->elements; 1941cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos ) 1942cdf0e10cSrcweir { 1943cdf0e10cSrcweir System::Object* val; 1944cdf0e10cSrcweir map_to_cli( 1945cdf0e10cSrcweir &val, &elements[nPos], element_type, 0, false); 1946cdf0e10cSrcweir ar->SetValue(val, nPos); 1947cdf0e10cSrcweir } 1948cdf0e10cSrcweir } 1949cdf0e10cSrcweir *cli_data = ar; 1950cdf0e10cSrcweir break; 1951cdf0e10cSrcweir } 1952cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 1953cdf0e10cSrcweir { 1954cdf0e10cSrcweir TypeDescr element_td( element_type ); 1955cdf0e10cSrcweir System::Type * ifaceType= mapUnoType(element_type); 1956cdf0e10cSrcweir System::Array* ar= System::Array::CreateInstance(ifaceType, nElements); 1957cdf0e10cSrcweir 1958cdf0e10cSrcweir char * p = (char *)seq->elements; 1959cdf0e10cSrcweir sal_Int32 nSize = element_td.get()->nSize; 1960cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos ) 1961cdf0e10cSrcweir { 1962cdf0e10cSrcweir System::Object* val; 1963cdf0e10cSrcweir map_to_cli( 1964cdf0e10cSrcweir &val, p + (nSize * nPos), element_type, NULL, false); 1965cdf0e10cSrcweir 1966cdf0e10cSrcweir ar->SetValue(val, nPos); 1967cdf0e10cSrcweir } 1968cdf0e10cSrcweir *cli_data= ar; 1969cdf0e10cSrcweir break; 1970cdf0e10cSrcweir } 1971cdf0e10cSrcweir default: 1972cdf0e10cSrcweir { 1973cdf0e10cSrcweir OUStringBuffer buf( 128 ); 1974cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_cli():") ); 1975cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) ); 1976cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported element type: ") ); 1977cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &element_type->pTypeName ) ); 1978cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 1979cdf0e10cSrcweir } 1980cdf0e10cSrcweir } 1981cdf0e10cSrcweir break; 1982cdf0e10cSrcweir } 1983cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 1984cdf0e10cSrcweir { 1985cdf0e10cSrcweir uno_Interface * pUnoI = *(uno_Interface * const *)uno_data; 1986cdf0e10cSrcweir if (0 != pUnoI) 1987cdf0e10cSrcweir { 1988cdf0e10cSrcweir TypeDescr td( type ); 1989cdf0e10cSrcweir *cli_data= map_uno2cli( pUnoI, reinterpret_cast< 1990cdf0e10cSrcweir typelib_InterfaceTypeDescription*>(td.get())) ; 1991cdf0e10cSrcweir } 1992cdf0e10cSrcweir else 1993cdf0e10cSrcweir *cli_data= NULL; 1994cdf0e10cSrcweir break; 1995cdf0e10cSrcweir } 1996cdf0e10cSrcweir default: 1997cdf0e10cSrcweir { 1998cdf0e10cSrcweir //ToDo check this exception. The String is probably crippled 1999cdf0e10cSrcweir OUStringBuffer buf( 128 ); 2000cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_cli():") ); 2001cdf0e10cSrcweir buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) ); 2002cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported type!") ); 2003cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 2004cdf0e10cSrcweir } 2005cdf0e10cSrcweir } 2006cdf0e10cSrcweir } 2007cdf0e10cSrcweir } 2008