1*2123d757SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2123d757SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2123d757SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2123d757SAndrew Rist * distributed with this work for additional information 6*2123d757SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2123d757SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2123d757SAndrew Rist * "License"); you may not use this file except in compliance 9*2123d757SAndrew Rist * with the License. You may obtain a copy of the License at 10*2123d757SAndrew Rist * 11*2123d757SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2123d757SAndrew Rist * 13*2123d757SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2123d757SAndrew Rist * software distributed under the License is distributed on an 15*2123d757SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2123d757SAndrew Rist * KIND, either express or implied. See the License for the 17*2123d757SAndrew Rist * specific language governing permissions and limitations 18*2123d757SAndrew Rist * under the License. 19*2123d757SAndrew Rist * 20*2123d757SAndrew Rist *************************************************************/ 21*2123d757SAndrew Rist 22*2123d757SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #if ! defined INCLUDED_CLI_BASE_H 25cdf0e10cSrcweir #define INCLUDED_CLI_BASE_H 26cdf0e10cSrcweir 27cdf0e10cSrcweir #pragma unmanaged 28cdf0e10cSrcweir // Workaround: osl/mutex.h contains only a forward declaration of _oslMutexImpls. 29cdf0e10cSrcweir // When using the inline class in Mutex in osl/mutex.hxx, the loader needs to find 30cdf0e10cSrcweir // a declaration for the struct. If not found a TypeLoadException is being thrown. 31cdf0e10cSrcweir struct _oslMutexImpl 32cdf0e10cSrcweir { 33cdf0e10cSrcweir }; 34cdf0e10cSrcweir #pragma managed 35cdf0e10cSrcweir #include <memory> 36cdf0e10cSrcweir #include "rtl/ustring.hxx" 37cdf0e10cSrcweir #include "typelib/typedescription.hxx" 38cdf0e10cSrcweir 39cdf0e10cSrcweir #using <mscorlib.dll> 40cdf0e10cSrcweir #using <system.dll> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace cli_uno 45cdf0e10cSrcweir { 46cdf0e10cSrcweir System::Type* loadCliType(System::String * typeName); 47cdf0e10cSrcweir System::Type* mapUnoType(typelib_TypeDescription const * pTD); 48cdf0e10cSrcweir System::Type* mapUnoType(typelib_TypeDescriptionReference const * pTD); 49cdf0e10cSrcweir typelib_TypeDescriptionReference* mapCliType(System::Type* cliType); 50cdf0e10cSrcweir rtl::OUString mapCliString(System::String const * data); 51cdf0e10cSrcweir System::String* mapUnoString(rtl_uString const * data); 52cdf0e10cSrcweir System::String* mapUnoTypeName(rtl_uString const * typeName); 53cdf0e10cSrcweir 54cdf0e10cSrcweir __gc struct Constants 55cdf0e10cSrcweir { 56cdf0e10cSrcweir static const System::String* sXInterfaceName= new System::String( 57cdf0e10cSrcweir S"unoidl.com.sun.star.uno.XInterface"); 58cdf0e10cSrcweir static const System::String* sObject= new System::String(S"System.Object"); 59cdf0e10cSrcweir static const System::String* sType= new System::String(S"System.Type"); 60cdf0e10cSrcweir static const System::String* sUnoidl= new System::String(S"unoidl."); 61cdf0e10cSrcweir static const System::String* sVoid= new System::String(S"System.Void"); 62cdf0e10cSrcweir static const System::String* sAny= new System::String(S"uno.Any"); 63cdf0e10cSrcweir static const System::String* sArArray= new System::String(S"System.Array[]"); 64cdf0e10cSrcweir static const System::String* sBoolean= new System::String(S"System.Boolean"); 65cdf0e10cSrcweir static const System::String* sChar= new System::String(S"System.Char"); 66cdf0e10cSrcweir static const System::String* sByte= new System::String(S"System.Byte"); 67cdf0e10cSrcweir static const System::String* sInt16= new System::String(S"System.Int16"); 68cdf0e10cSrcweir static const System::String* sUInt16= new System::String(S"System.UInt16"); 69cdf0e10cSrcweir static const System::String* sInt32= new System::String(S"System.Int32"); 70cdf0e10cSrcweir static const System::String* sUInt32= new System::String(S"System.UInt32"); 71cdf0e10cSrcweir static const System::String* sInt64= new System::String(S"System.Int64"); 72cdf0e10cSrcweir static const System::String* sUInt64= new System::String(S"System.UInt64"); 73cdf0e10cSrcweir static const System::String* sString= new System::String(S"System.String"); 74cdf0e10cSrcweir static const System::String* sSingle= new System::String(S"System.Single"); 75cdf0e10cSrcweir static const System::String* sDouble= new System::String(S"System.Double"); 76cdf0e10cSrcweir static const System::String* sArBoolean= new System::String(S"System.Boolean[]"); 77cdf0e10cSrcweir static const System::String* sArChar= new System::String(S"System.Char[]"); 78cdf0e10cSrcweir static const System::String* sArByte= new System::String(S"System.Byte[]"); 79cdf0e10cSrcweir static const System::String* sArInt16= new System::String(S"System.Int16[]"); 80cdf0e10cSrcweir static const System::String* sArUInt16= new System::String(S"System.UInt16[]"); 81cdf0e10cSrcweir static const System::String* sArInt32= new System::String(S"System.Int32[]"); 82cdf0e10cSrcweir static const System::String* sArUInt32= new System::String(S"System.UInt32[]"); 83cdf0e10cSrcweir static const System::String* sArInt64= new System::String(S"System.Int64[]"); 84cdf0e10cSrcweir static const System::String* sArUInt64= new System::String(S"System.UInt64[]"); 85cdf0e10cSrcweir static const System::String* sArString= new System::String(S"System.String[]"); 86cdf0e10cSrcweir static const System::String* sArSingle= new System::String(S"System.Single[]"); 87cdf0e10cSrcweir static const System::String* sArDouble= new System::String(S"System.Double[]"); 88cdf0e10cSrcweir static const System::String* sArType= new System::String(S"System.Type[]"); 89cdf0e10cSrcweir static const System::String* sArObject= new System::String(S"System.Object[]"); 90cdf0e10cSrcweir static const System::String* sBrackets= new System::String(S"[]"); 91cdf0e10cSrcweir static const System::String* sAttributeSet= new System::String(S"set_"); 92cdf0e10cSrcweir static const System::String* sAttributeGet= new System::String(S"get_"); 93cdf0e10cSrcweir 94cdf0e10cSrcweir static const System::String* usXInterface = S"com.sun.star.uno.XInterface"; 95cdf0e10cSrcweir static const System::String* usVoid = S"void"; 96cdf0e10cSrcweir static const System::String* usType = S"type"; 97cdf0e10cSrcweir static const System::String* usAny = S"any"; 98cdf0e10cSrcweir static const System::String* usBrackets = S"[]"; 99cdf0e10cSrcweir static const System::String* usBool = S"boolean"; 100cdf0e10cSrcweir static const System::String* usByte = S"byte"; 101cdf0e10cSrcweir static const System::String* usChar = S"char"; 102cdf0e10cSrcweir static const System::String* usShort = S"short"; 103cdf0e10cSrcweir static const System::String* usUShort = S"unsigned short"; 104cdf0e10cSrcweir static const System::String* usLong = S"long"; 105cdf0e10cSrcweir static const System::String* usULong = S"unsigned long"; 106cdf0e10cSrcweir static const System::String* usHyper = S"hyper"; 107cdf0e10cSrcweir static const System::String* usUHyper = S"unsigned hyper"; 108cdf0e10cSrcweir static const System::String* usString = S"string"; 109cdf0e10cSrcweir static const System::String* usFloat = S"float"; 110cdf0e10cSrcweir static const System::String* usDouble = S"double"; 111cdf0e10cSrcweir }; 112cdf0e10cSrcweir 113cdf0e10cSrcweir struct BridgeRuntimeError 114cdf0e10cSrcweir { 115cdf0e10cSrcweir ::rtl::OUString m_message; 116cdf0e10cSrcweir BridgeRuntimeErrorcli_uno::BridgeRuntimeError117cdf0e10cSrcweir inline BridgeRuntimeError( ::rtl::OUString const & message ) 118cdf0e10cSrcweir : m_message( message ) 119cdf0e10cSrcweir {} 120cdf0e10cSrcweir }; 121cdf0e10cSrcweir 122cdf0e10cSrcweir //================================================================================================== 123cdf0e10cSrcweir struct rtl_mem 124cdf0e10cSrcweir { operator newcli_uno::rtl_mem125cdf0e10cSrcweir inline static void * operator new ( size_t nSize ) 126cdf0e10cSrcweir { return rtl_allocateMemory( nSize ); } operator deletecli_uno::rtl_mem127cdf0e10cSrcweir inline static void operator delete ( void * mem ) 128cdf0e10cSrcweir { if (mem) rtl_freeMemory( mem ); } operator newcli_uno::rtl_mem129cdf0e10cSrcweir inline static void * operator new ( size_t, void * mem ) 130cdf0e10cSrcweir { return mem; } operator deletecli_uno::rtl_mem131cdf0e10cSrcweir inline static void operator delete ( void *, void * ) 132cdf0e10cSrcweir {} 133cdf0e10cSrcweir 134cdf0e10cSrcweir static inline ::std::auto_ptr< rtl_mem > allocate( ::std::size_t bytes ); 135cdf0e10cSrcweir }; 136cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- allocate(::std::size_t bytes)137cdf0e10cSrcweirinline ::std::auto_ptr< rtl_mem > rtl_mem::allocate( ::std::size_t bytes ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir void * p = rtl_allocateMemory( bytes ); 140cdf0e10cSrcweir if (0 == p) 141cdf0e10cSrcweir throw BridgeRuntimeError(OUSTR("out of memory!") ); 142cdf0e10cSrcweir return ::std::auto_ptr< rtl_mem >( (rtl_mem *)p ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir //================================================================================================== 146cdf0e10cSrcweir class TypeDescr 147cdf0e10cSrcweir { 148cdf0e10cSrcweir typelib_TypeDescription * m_td; 149cdf0e10cSrcweir 150cdf0e10cSrcweir TypeDescr( TypeDescr & ); // not impl 151cdf0e10cSrcweir void operator = ( TypeDescr ); // not impl 152cdf0e10cSrcweir 153cdf0e10cSrcweir public: 154cdf0e10cSrcweir inline explicit TypeDescr( typelib_TypeDescriptionReference * td_ref ); 155cdf0e10cSrcweir inline ~TypeDescr() SAL_THROW( () ) 156cdf0e10cSrcweir { TYPELIB_DANGER_RELEASE( m_td ); } 157cdf0e10cSrcweir get() const158cdf0e10cSrcweir inline typelib_TypeDescription * get() const 159cdf0e10cSrcweir { return m_td; } 160cdf0e10cSrcweir }; 161cdf0e10cSrcweir TypeDescr(typelib_TypeDescriptionReference * td_ref)162cdf0e10cSrcweirinline TypeDescr::TypeDescr( typelib_TypeDescriptionReference * td_ref ) 163cdf0e10cSrcweir : m_td( 0 ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir TYPELIB_DANGER_GET( &m_td, td_ref ); 166cdf0e10cSrcweir if (0 == m_td) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir throw BridgeRuntimeError( 169cdf0e10cSrcweir OUSTR("cannot get comprehensive type description for ") + 170cdf0e10cSrcweir *reinterpret_cast< ::rtl::OUString const * >( &td_ref->pTypeName ) ); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir 175cdf0e10cSrcweir } //end namespace cli_uno 176cdf0e10cSrcweir #endif 177