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