INTEGRATION: CWS jl3 (1.6.12); FILE MERGED
2004/03/08 14:12:37 dbo 1.6.12.3: #114513# computing OID every time 2003/12/19 11:30:30 dbo 1.6.12.2: #114513# 2003/12/17 10:58:12 dbo 1.6.12.1: #114513# fixing proxy factory identity problem
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: proxyfac.cxx,v $
|
* $RCSfile: proxyfac.cxx,v $
|
||||||
*
|
*
|
||||||
* $Revision: 1.6 $
|
* $Revision: 1.7 $
|
||||||
*
|
*
|
||||||
* last change: $Author: obo $ $Date: 2003-09-04 09:07:36 $
|
* last change: $Author: kz $ $Date: 2004-03-25 14:47:19 $
|
||||||
*
|
*
|
||||||
* The Contents of this file are made available subject to the terms of
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -59,437 +59,517 @@
|
|||||||
*
|
*
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
#include <osl/diagnose.h>
|
#include "osl/diagnose.h"
|
||||||
#include <osl/interlck.h>
|
#include "osl/interlck.h"
|
||||||
|
#include "osl/doublecheckedlocking.h"
|
||||||
|
#include "osl/mutex.hxx"
|
||||||
|
#include "rtl/ref.hxx"
|
||||||
|
#include "uno/dispatcher.hxx"
|
||||||
|
#include "uno/data.h"
|
||||||
|
#include "uno/mapping.hxx"
|
||||||
|
#include "uno/environment.hxx"
|
||||||
|
#include "typelib/typedescription.hxx"
|
||||||
|
#include "cppuhelper/exc_hlp.hxx"
|
||||||
|
#include "cppuhelper/implbase2.hxx"
|
||||||
|
#include "cppuhelper/implementationentry.hxx"
|
||||||
|
#include "cppuhelper/factory.hxx"
|
||||||
|
#include "com/sun/star/lang/XServiceInfo.hpp"
|
||||||
|
#include "com/sun/star/registry/XRegistryKey.hpp"
|
||||||
|
#include "com/sun/star/reflection/XProxyFactory.hpp"
|
||||||
|
|
||||||
#include <uno/dispatcher.h>
|
#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
|
||||||
#include <uno/data.h>
|
#define SERVICE_NAME "com.sun.star.reflection.ProxyFactory"
|
||||||
#include <uno/any2.h>
|
#define IMPL_NAME "com.sun.star.comp.reflection.ProxyFactory"
|
||||||
#include <uno/mapping.hxx>
|
|
||||||
|
|
||||||
#include <cppuhelper/factory.hxx>
|
|
||||||
#include <cppuhelper/implbase2.hxx>
|
|
||||||
#include <cppuhelper/weakagg.hxx>
|
|
||||||
#include <cppuhelper/queryinterface.hxx>
|
|
||||||
#include <cppuhelper/implementationentry.hxx>
|
|
||||||
|
|
||||||
#include <vector>
|
using namespace ::com::sun::star;
|
||||||
|
using namespace ::com::sun::star::uno;
|
||||||
|
using ::rtl::OUString;
|
||||||
|
|
||||||
#include <com/sun/star/uno/XAggregation.hpp>
|
|
||||||
#include <com/sun/star/lang/XServiceInfo.hpp>
|
|
||||||
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
|
||||||
#include <com/sun/star/registry/XSimpleRegistry.hpp>
|
|
||||||
#include <com/sun/star/registry/XRegistryKey.hpp>
|
|
||||||
#include <com/sun/star/reflection/XProxyFactory.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
namespace
|
||||||
using namespace rtl;
|
|
||||||
using namespace osl;
|
|
||||||
using namespace cppu;
|
|
||||||
using namespace com::sun::star::uno;
|
|
||||||
using namespace com::sun::star::lang;
|
|
||||||
using namespace com::sun::star::reflection;
|
|
||||||
using namespace com::sun::star::registry;
|
|
||||||
|
|
||||||
#define SERVICENAME "com.sun.star.reflection.ProxyFactory"
|
|
||||||
#define IMPLNAME "com.sun.star.comp.reflection.ProxyFactory"
|
|
||||||
|
|
||||||
namespace stoc_proxyfac
|
|
||||||
{
|
{
|
||||||
|
|
||||||
static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
|
static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
|
||||||
|
|
||||||
static Sequence< OUString > proxyfac_getSupportedServiceNames()
|
|
||||||
{
|
|
||||||
static Sequence < OUString > *pNames = 0;
|
|
||||||
if( ! pNames )
|
|
||||||
{
|
|
||||||
MutexGuard guard( Mutex::getGlobalMutex() );
|
|
||||||
if( !pNames )
|
|
||||||
{
|
|
||||||
static Sequence< OUString > seqNames(1);
|
|
||||||
seqNames.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
|
|
||||||
pNames = &seqNames;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return *pNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
static OUString proxyfac_getImplementationName()
|
static OUString proxyfac_getImplementationName()
|
||||||
{
|
{
|
||||||
static OUString *pImplName = 0;
|
return OUSTR(IMPL_NAME);
|
||||||
if( ! pImplName )
|
|
||||||
{
|
|
||||||
MutexGuard guard( Mutex::getGlobalMutex() );
|
|
||||||
if( ! pImplName )
|
|
||||||
{
|
|
||||||
static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) );
|
|
||||||
pImplName = &implName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return *pImplName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
static Sequence< OUString > proxyfac_getSupportedServiceNames()
|
||||||
static inline uno_Interface * uno_queryInterface(
|
|
||||||
uno_Interface * pUnoI, typelib_InterfaceTypeDescription * pTypeDescr )
|
|
||||||
{
|
{
|
||||||
uno_Interface * pRet = 0;
|
OUString str_name = OUSTR(SERVICE_NAME);
|
||||||
|
return Sequence< OUString >( &str_name, 1 );
|
||||||
void * pArgs[1];
|
|
||||||
|
|
||||||
typelib_InterfaceTypeDescription * pTXInterfaceDescr = 0;
|
|
||||||
const Type & rXIType = ::getCppuType( (const Reference<XInterface > *)0 );
|
|
||||||
TYPELIB_DANGER_GET( (typelib_TypeDescription **)&pTXInterfaceDescr, rXIType.getTypeLibType() );
|
|
||||||
OSL_ASSERT( pTXInterfaceDescr->ppAllMembers );
|
|
||||||
typelib_TypeDescription * pMTqueryInterface = 0;
|
|
||||||
TYPELIB_DANGER_GET( &pMTqueryInterface, pTXInterfaceDescr->ppAllMembers[0] );
|
|
||||||
|
|
||||||
Type aType( ((typelib_TypeDescription *)pTypeDescr)->pWeakRef );
|
|
||||||
pArgs[0] = &aType;
|
|
||||||
|
|
||||||
uno_Any aRetI, aExc;
|
|
||||||
uno_Any * pExc = &aExc;
|
|
||||||
|
|
||||||
(*((uno_Interface *)pUnoI)->pDispatcher)(
|
|
||||||
(uno_Interface *)pUnoI, pMTqueryInterface, &aRetI, pArgs, &pExc );
|
|
||||||
|
|
||||||
OSL_ENSURE( !pExc, "### Exception occured during queryInterface()!" );
|
|
||||||
if (pExc) // cleanup exception
|
|
||||||
{
|
|
||||||
uno_any_destruct( pExc, 0 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (aRetI.pType->eTypeClass == typelib_TypeClass_INTERFACE)
|
|
||||||
{
|
|
||||||
pRet = *(uno_Interface **)aRetI.pData;
|
|
||||||
(*pRet->acquire)( pRet );
|
|
||||||
}
|
|
||||||
uno_any_destruct( &aRetI, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPELIB_DANGER_RELEASE( pMTqueryInterface );
|
|
||||||
TYPELIB_DANGER_RELEASE( (typelib_TypeDescription *)pTXInterfaceDescr );
|
|
||||||
return pRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProxyRoot;
|
//==============================================================================
|
||||||
struct FactoryImpl;
|
struct FactoryImpl : public ::cppu::WeakImplHelper2< lang::XServiceInfo,
|
||||||
|
reflection::XProxyFactory >
|
||||||
//==================================================================================================
|
|
||||||
struct uno_Proxy : public uno_Interface
|
|
||||||
{
|
{
|
||||||
ProxyRoot * pRoot;
|
Environment m_uno_env;
|
||||||
uno_Interface * pTarget;
|
Environment m_cpp_env;
|
||||||
typelib_InterfaceTypeDescription * pTypeDescr;
|
Mapping m_uno2cpp;
|
||||||
};
|
Mapping m_cpp2uno;
|
||||||
typedef vector< uno_Proxy * > t_InterfaceVector;
|
|
||||||
|
|
||||||
//==================================================================================================
|
UnoInterfaceReference binuno_queryInterface(
|
||||||
struct ProxyRoot : public OWeakAggObject
|
UnoInterfaceReference const & unoI,
|
||||||
{
|
typelib_InterfaceTypeDescription * pTypeDescr );
|
||||||
FactoryImpl * pFactory;
|
|
||||||
Mutex aMutex;
|
|
||||||
t_InterfaceVector aInterfaces;
|
|
||||||
|
|
||||||
uno_Interface * pTarget;
|
|
||||||
|
|
||||||
inline ProxyRoot( FactoryImpl * pFactory_, const Reference< XInterface > & xTarget_ );
|
|
||||||
virtual ~ProxyRoot();
|
|
||||||
|
|
||||||
virtual Any SAL_CALL queryAggregation( const Type & rType ) throw (RuntimeException);
|
|
||||||
};
|
|
||||||
//==================================================================================================
|
|
||||||
struct FactoryImpl : public WeakImplHelper2< XServiceInfo, XProxyFactory >
|
|
||||||
{
|
|
||||||
Mapping aUno2Cpp;
|
|
||||||
Mapping aCpp2Uno;
|
|
||||||
|
|
||||||
FactoryImpl();
|
FactoryImpl();
|
||||||
virtual ~FactoryImpl();
|
virtual ~FactoryImpl();
|
||||||
|
|
||||||
// XServiceInfo
|
// XServiceInfo
|
||||||
virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
|
virtual OUString SAL_CALL getImplementationName()
|
||||||
virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
|
throw (RuntimeException);
|
||||||
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
|
virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName )
|
||||||
|
throw (RuntimeException);
|
||||||
|
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
|
||||||
|
throw (RuntimeException);
|
||||||
|
|
||||||
// XProxyFactory
|
// XProxyFactory
|
||||||
virtual Reference< XAggregation > SAL_CALL createProxy( const Reference< XInterface > & xTarget ) throw (RuntimeException);
|
virtual Reference< XAggregation > SAL_CALL createProxy(
|
||||||
|
Reference< XInterface > const & xTarget )
|
||||||
|
throw (RuntimeException);
|
||||||
|
};
|
||||||
|
|
||||||
|
//______________________________________________________________________________
|
||||||
|
UnoInterfaceReference FactoryImpl::binuno_queryInterface(
|
||||||
|
UnoInterfaceReference const & unoI,
|
||||||
|
typelib_InterfaceTypeDescription * pTypeDescr )
|
||||||
|
{
|
||||||
|
// init queryInterface() td
|
||||||
|
static typelib_TypeDescription * s_pQITD = 0;
|
||||||
|
if (s_pQITD == 0)
|
||||||
|
{
|
||||||
|
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
|
||||||
|
if (s_pQITD == 0)
|
||||||
|
{
|
||||||
|
typelib_TypeDescription * pTXInterfaceDescr = 0;
|
||||||
|
TYPELIB_DANGER_GET(
|
||||||
|
&pTXInterfaceDescr,
|
||||||
|
::getCppuType( reinterpret_cast< Reference< XInterface >
|
||||||
|
const * >(0) ).getTypeLibType() );
|
||||||
|
typelib_TypeDescription * pQITD = 0;
|
||||||
|
typelib_typedescriptionreference_getDescription(
|
||||||
|
&pQITD, reinterpret_cast< typelib_InterfaceTypeDescription * >(
|
||||||
|
pTXInterfaceDescr )->ppAllMembers[ 0 ] );
|
||||||
|
TYPELIB_DANGER_RELEASE( pTXInterfaceDescr );
|
||||||
|
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
|
||||||
|
s_pQITD = pQITD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
|
||||||
|
}
|
||||||
|
|
||||||
|
void * args[ 1 ];
|
||||||
|
args[ 0 ] = &reinterpret_cast< typelib_TypeDescription * >(
|
||||||
|
pTypeDescr )->pWeakRef;
|
||||||
|
uno_Any ret_val, exc_space;
|
||||||
|
uno_Any * exc = &exc_space;
|
||||||
|
|
||||||
|
unoI.dispatch( s_pQITD, &ret_val, args, &exc );
|
||||||
|
|
||||||
|
if (exc == 0)
|
||||||
|
{
|
||||||
|
UnoInterfaceReference ret;
|
||||||
|
if (ret_val.pType->eTypeClass == typelib_TypeClass_INTERFACE)
|
||||||
|
{
|
||||||
|
ret.set( *reinterpret_cast< uno_Interface ** >(ret_val.pData),
|
||||||
|
SAL_NO_ACQUIRE );
|
||||||
|
typelib_typedescriptionreference_release( ret_val.pType );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uno_any_destruct( &ret_val, 0 );
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// exception occured:
|
||||||
|
OSL_ENSURE(
|
||||||
|
typelib_typedescriptionreference_isAssignableFrom(
|
||||||
|
::getCppuType( reinterpret_cast<
|
||||||
|
RuntimeException const * >(0) ).getTypeLibType(),
|
||||||
|
exc->pType ),
|
||||||
|
"### RuntimeException expected!" );
|
||||||
|
Any cpp_exc;
|
||||||
|
uno_type_copyAndConvertData(
|
||||||
|
&cpp_exc, exc, ::getCppuType( &cpp_exc ).getTypeLibType(),
|
||||||
|
m_uno2cpp.get() );
|
||||||
|
uno_any_destruct( exc, 0 );
|
||||||
|
::cppu::throwException( cpp_exc );
|
||||||
|
OSL_ASSERT( 0 ); // way of no return
|
||||||
|
return UnoInterfaceReference(); // for dummy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
struct ProxyRoot : public ::cppu::OWeakAggObject
|
||||||
|
{
|
||||||
|
// XAggregation
|
||||||
|
virtual Any SAL_CALL queryAggregation( Type const & rType )
|
||||||
|
throw (RuntimeException);
|
||||||
|
|
||||||
|
virtual ~ProxyRoot();
|
||||||
|
inline ProxyRoot( ::rtl::Reference< FactoryImpl > const & factory,
|
||||||
|
Reference< XInterface > const & xTarget );
|
||||||
|
|
||||||
|
::rtl::Reference< FactoryImpl > m_factory;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UnoInterfaceReference m_target;
|
||||||
|
};
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
struct binuno_Proxy : public uno_Interface
|
||||||
|
{
|
||||||
|
oslInterlockedCount m_nRefCount;
|
||||||
|
::rtl::Reference< ProxyRoot > m_root;
|
||||||
|
UnoInterfaceReference m_target;
|
||||||
|
OUString m_oid;
|
||||||
|
TypeDescription m_typeDescr;
|
||||||
|
|
||||||
|
inline binuno_Proxy(
|
||||||
|
::rtl::Reference< ProxyRoot > const & root,
|
||||||
|
UnoInterfaceReference const & target,
|
||||||
|
OUString const & oid, TypeDescription const & typeDescr );
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
//__________________________________________________________________________________________________
|
|
||||||
static void SAL_CALL uno_proxy_dispatch(
|
//------------------------------------------------------------------------------
|
||||||
|
static void SAL_CALL binuno_proxy_free(
|
||||||
|
uno_ExtEnvironment * pEnv, void * pProxy )
|
||||||
|
{
|
||||||
|
binuno_Proxy * proxy = static_cast< binuno_Proxy * >(
|
||||||
|
reinterpret_cast< uno_Interface * >( pProxy ) );
|
||||||
|
OSL_ASSERT( proxy->m_root->m_factory->m_uno_env.get()->pExtEnv == pEnv );
|
||||||
|
delete proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
static void SAL_CALL binuno_proxy_acquire( uno_Interface * pUnoI )
|
||||||
|
{
|
||||||
|
binuno_Proxy * that = static_cast< binuno_Proxy * >( pUnoI );
|
||||||
|
if (osl_incrementInterlockedCount( &that->m_nRefCount ) == 1)
|
||||||
|
{
|
||||||
|
// rebirth of zombie
|
||||||
|
uno_ExtEnvironment * uno_env =
|
||||||
|
that->m_root->m_factory->m_uno_env.get()->pExtEnv;
|
||||||
|
OSL_ASSERT( uno_env != 0 );
|
||||||
|
(*uno_env->registerProxyInterface)(
|
||||||
|
uno_env, reinterpret_cast< void ** >( &pUnoI ), binuno_proxy_free,
|
||||||
|
that->m_oid.pData,
|
||||||
|
reinterpret_cast< typelib_InterfaceTypeDescription * >(
|
||||||
|
that->m_typeDescr.get() ) );
|
||||||
|
OSL_ASSERT( that == static_cast< binuno_Proxy * >( pUnoI ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
static void SAL_CALL binuno_proxy_release( uno_Interface * pUnoI )
|
||||||
|
{
|
||||||
|
binuno_Proxy * that = static_cast< binuno_Proxy * >( pUnoI );
|
||||||
|
if (osl_decrementInterlockedCount( &that->m_nRefCount ) == 0)
|
||||||
|
{
|
||||||
|
uno_ExtEnvironment * uno_env =
|
||||||
|
that->m_root->m_factory->m_uno_env.get()->pExtEnv;
|
||||||
|
OSL_ASSERT( uno_env != 0 );
|
||||||
|
(*uno_env->revokeInterface)( uno_env, pUnoI );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
static void SAL_CALL binuno_proxy_dispatch(
|
||||||
uno_Interface * pUnoI, const typelib_TypeDescription * pMemberType,
|
uno_Interface * pUnoI, const typelib_TypeDescription * pMemberType,
|
||||||
void * pReturn, void * pArgs[], uno_Any ** ppException )
|
void * pReturn, void * pArgs [], uno_Any ** ppException )
|
||||||
{
|
{
|
||||||
uno_Proxy * pThis = static_cast< uno_Proxy * >( pUnoI );
|
binuno_Proxy * that = static_cast< binuno_Proxy * >( pUnoI );
|
||||||
|
switch (reinterpret_cast< typelib_InterfaceMemberTypeDescription const * >(
|
||||||
try
|
pMemberType )->nPosition)
|
||||||
{
|
{
|
||||||
switch (((typelib_InterfaceMemberTypeDescription *)pMemberType)->nPosition)
|
case 0: // queryInterface()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
case 0: // queryInterface()
|
Type const & rType =
|
||||||
{
|
*reinterpret_cast< Type const * >( pArgs[ 0 ] );
|
||||||
Any aRet( pThis->pRoot->queryInterface( * reinterpret_cast< const Type * >( pArgs[0] ) ) );
|
Any ret( that->m_root->queryInterface( rType ) );
|
||||||
const Type & rAnyType = ::getCppuType( &aRet );
|
|
||||||
uno_type_copyAndConvertData(
|
uno_type_copyAndConvertData(
|
||||||
pReturn, &aRet, rAnyType.getTypeLibType(), pThis->pRoot->pFactory->aCpp2Uno.get() );
|
pReturn, &ret, ::getCppuType( &ret ).getTypeLibType(),
|
||||||
|
that->m_root->m_factory->m_cpp2uno.get() );
|
||||||
*ppException = 0; // no exc
|
*ppException = 0; // no exc
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 1: // acquire()
|
catch (RuntimeException &)
|
||||||
pThis->pRoot->acquire();
|
{
|
||||||
*ppException = 0; // no exc
|
Any exc( ::cppu::getCaughtException() );
|
||||||
break;
|
uno_type_any_constructAndConvert(
|
||||||
case 2: // release()
|
*ppException, const_cast< void * >(exc.getValue()),
|
||||||
pThis->pRoot->release();
|
exc.getValueTypeRef(),
|
||||||
*ppException = 0; // no exc
|
that->m_root->m_factory->m_cpp2uno.get() );
|
||||||
break;
|
|
||||||
default:
|
|
||||||
(*pThis->pTarget->pDispatcher)( pThis->pTarget, pMemberType, pReturn, pArgs, ppException );
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
catch (Exception & exc)
|
case 1: // acquire()
|
||||||
{
|
binuno_proxy_acquire( pUnoI );
|
||||||
RuntimeException aExc;
|
*ppException = 0; // no exc
|
||||||
aExc.Message = OUString( RTL_CONSTASCII_USTRINGPARAM(
|
break;
|
||||||
"unexpected exception occured: " ) ) +
|
case 2: // release()
|
||||||
exc.Message;
|
binuno_proxy_release( pUnoI );
|
||||||
aExc.Context = exc.Context;
|
*ppException = 0; // no exc
|
||||||
const Type & rExcType = ::getCppuType( &aExc );
|
break;
|
||||||
uno_type_any_constructAndConvert(
|
default:
|
||||||
*ppException, &aExc, rExcType.getTypeLibType(),
|
that->m_target.dispatch( pMemberType, pReturn, pArgs, ppException );
|
||||||
pThis->pRoot->pFactory->aCpp2Uno.get() );
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
static void SAL_CALL uno_proxy_acquire( uno_Interface * pUnoI )
|
|
||||||
{
|
|
||||||
static_cast< uno_Proxy * >( pUnoI )->pRoot->acquire();
|
|
||||||
}
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
static void SAL_CALL uno_proxy_release( uno_Interface * pUnoI )
|
|
||||||
{
|
|
||||||
static_cast< uno_Proxy * >( pUnoI )->pRoot->release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//__________________________________________________________________________________________________
|
|
||||||
inline ProxyRoot::ProxyRoot( FactoryImpl * pFactory_, const Reference< XInterface > & xTarget_ )
|
|
||||||
: pFactory( pFactory_ )
|
|
||||||
, pTarget( 0 )
|
|
||||||
{
|
|
||||||
g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
|
|
||||||
pFactory->acquire();
|
|
||||||
pFactory->aCpp2Uno.mapInterface( (void **)&pTarget, xTarget_.get(), ::getCppuType( &xTarget_ ) );
|
|
||||||
OSL_ENSURE( pTarget, "### mapping interface failed!" );
|
|
||||||
aInterfaces.reserve( 8 );
|
|
||||||
}
|
}
|
||||||
//__________________________________________________________________________________________________
|
|
||||||
|
//______________________________________________________________________________
|
||||||
|
inline binuno_Proxy::binuno_Proxy(
|
||||||
|
::rtl::Reference< ProxyRoot > const & root,
|
||||||
|
UnoInterfaceReference const & target,
|
||||||
|
OUString const & oid, TypeDescription const & typeDescr )
|
||||||
|
: m_nRefCount( 1 ),
|
||||||
|
m_root( root ),
|
||||||
|
m_target( target ),
|
||||||
|
m_oid( oid ),
|
||||||
|
m_typeDescr( typeDescr )
|
||||||
|
{
|
||||||
|
uno_Interface::acquire = binuno_proxy_acquire;
|
||||||
|
uno_Interface::release = binuno_proxy_release;
|
||||||
|
uno_Interface::pDispatcher = binuno_proxy_dispatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
//______________________________________________________________________________
|
||||||
ProxyRoot::~ProxyRoot()
|
ProxyRoot::~ProxyRoot()
|
||||||
{
|
{
|
||||||
for ( t_InterfaceVector::const_iterator iPos( aInterfaces.begin() );
|
|
||||||
iPos != aInterfaces.end(); ++iPos )
|
|
||||||
{
|
|
||||||
uno_Proxy * p = *iPos;
|
|
||||||
(*p->pTarget->release)( p->pTarget );
|
|
||||||
typelib_typedescription_release( (typelib_TypeDescription *)p->pTypeDescr );
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
(*pTarget->release)( pTarget );
|
|
||||||
pFactory->release();
|
|
||||||
g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//______________________________________________________________________________
|
||||||
static inline sal_Bool type_equals(
|
inline ProxyRoot::ProxyRoot(
|
||||||
const Type & rType, typelib_InterfaceTypeDescription * pTypeDescr )
|
::rtl::Reference< FactoryImpl > const & factory,
|
||||||
|
Reference< XInterface > const & xTarget )
|
||||||
|
: m_factory( factory )
|
||||||
{
|
{
|
||||||
typelib_TypeDescriptionReference * p1 = rType.getTypeLibType();
|
m_factory->m_cpp2uno.mapInterface(
|
||||||
typelib_TypeDescriptionReference * p2 = (typelib_TypeDescriptionReference *)pTypeDescr;
|
reinterpret_cast< void ** >( &m_target.m_pUnoI ), xTarget.get(),
|
||||||
|
::getCppuType( &xTarget ) );
|
||||||
return (p1 == p2 ||
|
OSL_ENSURE( m_target.is(), "### mapping interface failed!" );
|
||||||
(p1->pTypeName->length == p2->pTypeName->length &&
|
|
||||||
rtl_ustr_compare( p1->pTypeName->buffer, p2->pTypeName->buffer ) == 0));
|
|
||||||
}
|
}
|
||||||
//__________________________________________________________________________________________________
|
|
||||||
Any ProxyRoot::queryAggregation( const Type & rType )
|
//______________________________________________________________________________
|
||||||
|
Any ProxyRoot::queryAggregation( Type const & rType )
|
||||||
throw (RuntimeException)
|
throw (RuntimeException)
|
||||||
{
|
{
|
||||||
Any aRet( OWeakAggObject::queryAggregation( rType ) );
|
Any ret( OWeakAggObject::queryAggregation( rType ) );
|
||||||
if (! aRet.hasValue())
|
if (! ret.hasValue())
|
||||||
{
|
{
|
||||||
// query existing interfaces
|
typelib_TypeDescription * pTypeDescr = 0;
|
||||||
MutexGuard aGuard( aMutex );
|
TYPELIB_DANGER_GET( &pTypeDescr, rType.getTypeLibType() );
|
||||||
for ( t_InterfaceVector::const_iterator iPos( aInterfaces.begin() );
|
try
|
||||||
iPos != aInterfaces.end(); ++iPos )
|
|
||||||
{
|
{
|
||||||
uno_Proxy * p = *iPos;
|
Reference< XInterface > xProxy;
|
||||||
typelib_InterfaceTypeDescription * pTypeDescr = p->pTypeDescr;
|
uno_ExtEnvironment * cpp_env = m_factory->m_cpp_env.get()->pExtEnv;
|
||||||
while (pTypeDescr)
|
OSL_ASSERT( cpp_env != 0 );
|
||||||
|
|
||||||
|
OUString oid;
|
||||||
|
(*cpp_env->getObjectIdentifier)(
|
||||||
|
cpp_env, &oid.pData,
|
||||||
|
static_cast< XInterface * >(
|
||||||
|
static_cast< ::cppu::OWeakObject * >(this) ) );
|
||||||
|
OSL_ASSERT( oid.getLength() > 0 );
|
||||||
|
|
||||||
|
(*cpp_env->getRegisteredInterface)(
|
||||||
|
cpp_env, reinterpret_cast< void ** >( &xProxy ),
|
||||||
|
oid.pData, reinterpret_cast<
|
||||||
|
typelib_InterfaceTypeDescription * >(pTypeDescr) );
|
||||||
|
if (! xProxy.is())
|
||||||
{
|
{
|
||||||
if (type_equals( rType, pTypeDescr ))
|
// perform query on target:
|
||||||
|
UnoInterfaceReference proxy_target(
|
||||||
|
m_factory->binuno_queryInterface(
|
||||||
|
m_target, reinterpret_cast<
|
||||||
|
typelib_InterfaceTypeDescription * >(pTypeDescr) ) );
|
||||||
|
if (proxy_target.is())
|
||||||
{
|
{
|
||||||
Reference< XInterface > xRet;
|
// ensure root's object entries:
|
||||||
pFactory->aUno2Cpp.mapInterface( (void **)&xRet, (uno_Interface *)p, pTypeDescr );
|
Reference< XInterface > xRoot(
|
||||||
aRet.setValue( &xRet, (typelib_TypeDescription *)pTypeDescr );
|
static_cast< OWeakObject * >(this), UNO_QUERY_THROW );
|
||||||
return aRet;
|
UnoInterfaceReference root;
|
||||||
|
m_factory->m_cpp2uno.mapInterface(
|
||||||
|
reinterpret_cast< void ** >( &root.m_pUnoI ),
|
||||||
|
xRoot.get(), ::getCppuType( &xRoot ) );
|
||||||
|
|
||||||
|
UnoInterfaceReference proxy(
|
||||||
|
// ref count initially 1:
|
||||||
|
new binuno_Proxy( this, proxy_target, oid, pTypeDescr ),
|
||||||
|
SAL_NO_ACQUIRE );
|
||||||
|
uno_ExtEnvironment * uno_env =
|
||||||
|
m_factory->m_uno_env.get()->pExtEnv;
|
||||||
|
OSL_ASSERT( uno_env != 0 );
|
||||||
|
(*uno_env->registerProxyInterface)(
|
||||||
|
uno_env, reinterpret_cast< void ** >( &proxy.m_pUnoI ),
|
||||||
|
binuno_proxy_free, oid.pData,
|
||||||
|
reinterpret_cast< typelib_InterfaceTypeDescription * >(
|
||||||
|
pTypeDescr ) );
|
||||||
|
|
||||||
|
m_factory->m_uno2cpp.mapInterface(
|
||||||
|
reinterpret_cast< void ** >( &xProxy ),
|
||||||
|
proxy.get(), pTypeDescr );
|
||||||
}
|
}
|
||||||
pTypeDescr = pTypeDescr->pBaseTypeDescription;
|
|
||||||
}
|
}
|
||||||
|
if (xProxy.is())
|
||||||
|
ret.setValue( &xProxy, pTypeDescr );
|
||||||
}
|
}
|
||||||
// else perform query
|
catch (...) // finally
|
||||||
typelib_InterfaceTypeDescription * pTypeDescr = 0;
|
|
||||||
TYPELIB_DANGER_GET( (typelib_TypeDescription **)&pTypeDescr, rType.getTypeLibType() );
|
|
||||||
uno_Interface * pProxyTarget = uno_queryInterface( pTarget, pTypeDescr );
|
|
||||||
if (pProxyTarget)
|
|
||||||
{
|
{
|
||||||
uno_Proxy * p = new uno_Proxy();
|
TYPELIB_DANGER_RELEASE( pTypeDescr );
|
||||||
p->acquire = uno_proxy_acquire;
|
throw;
|
||||||
p->release = uno_proxy_release;
|
|
||||||
p->pDispatcher = uno_proxy_dispatch;
|
|
||||||
//
|
|
||||||
p->pRoot = this;
|
|
||||||
p->pTarget = pProxyTarget;
|
|
||||||
typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr );
|
|
||||||
p->pTypeDescr = pTypeDescr;
|
|
||||||
|
|
||||||
Reference< XInterface > xRet;
|
|
||||||
pFactory->aUno2Cpp.mapInterface( (void **)&xRet, (uno_Interface *)p, pTypeDescr );
|
|
||||||
OSL_ENSURE( xRet.is(), "### mapping interface failed!" );
|
|
||||||
aInterfaces.push_back( p );
|
|
||||||
aRet.setValue( &xRet, (typelib_TypeDescription *)pTypeDescr );
|
|
||||||
}
|
}
|
||||||
TYPELIB_DANGER_RELEASE( (typelib_TypeDescription *)pTypeDescr );
|
TYPELIB_DANGER_RELEASE( pTypeDescr );
|
||||||
}
|
}
|
||||||
return aRet;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//##################################################################################################
|
//##############################################################################
|
||||||
//##################################################################################################
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//______________________________________________________________________________
|
||||||
inline static Sequence< OUString > getSupportedServiceNames()
|
|
||||||
{
|
|
||||||
OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
|
|
||||||
return Sequence< OUString >( &aName, 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
//__________________________________________________________________________________________________
|
|
||||||
FactoryImpl::FactoryImpl()
|
FactoryImpl::FactoryImpl()
|
||||||
: aUno2Cpp( OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ),
|
|
||||||
OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) )
|
|
||||||
, aCpp2Uno( OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ),
|
|
||||||
OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ) )
|
|
||||||
{
|
{
|
||||||
|
OUString uno = OUSTR(UNO_LB_UNO);
|
||||||
|
OUString cpp = OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
|
||||||
|
|
||||||
|
uno_getEnvironment(
|
||||||
|
reinterpret_cast< uno_Environment ** >( &m_uno_env ), uno.pData, 0 );
|
||||||
|
OSL_ENSURE( m_uno_env.is(), "### cannot get binary uno env!" );
|
||||||
|
|
||||||
|
uno_getEnvironment(
|
||||||
|
reinterpret_cast< uno_Environment ** >( &m_cpp_env ), cpp.pData, 0 );
|
||||||
|
OSL_ENSURE( m_cpp_env.is(), "### cannot get C++ uno env!" );
|
||||||
|
|
||||||
|
uno_getMapping(
|
||||||
|
reinterpret_cast< uno_Mapping ** >( &m_uno2cpp ),
|
||||||
|
m_uno_env.get(), m_cpp_env.get(), 0 );
|
||||||
|
OSL_ENSURE( m_uno2cpp.is(), "### cannot get bridge uno <-> C++!" );
|
||||||
|
|
||||||
|
uno_getMapping(
|
||||||
|
reinterpret_cast< uno_Mapping ** >( &m_cpp2uno ),
|
||||||
|
m_cpp_env.get(), m_uno_env.get(), 0 );
|
||||||
|
OSL_ENSURE( m_cpp2uno.is(), "### cannot get bridge C++ <-> uno!" );
|
||||||
|
|
||||||
g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
|
g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
|
||||||
OSL_ENSURE( aUno2Cpp.is(), "### cannot get bridge uno <-> C++!" );
|
|
||||||
OSL_ENSURE( aCpp2Uno.is(), "### cannot get bridge C++ <-> uno!" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//______________________________________________________________________________
|
||||||
FactoryImpl::~FactoryImpl()
|
FactoryImpl::~FactoryImpl()
|
||||||
{
|
{
|
||||||
g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
|
g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
|
||||||
}
|
}
|
||||||
|
|
||||||
// XProxyFactory
|
// XProxyFactory
|
||||||
//__________________________________________________________________________________________________
|
//______________________________________________________________________________
|
||||||
Reference< XAggregation > FactoryImpl::createProxy( const Reference< XInterface > & xTarget )
|
Reference< XAggregation > FactoryImpl::createProxy(
|
||||||
|
Reference< XInterface > const & xTarget )
|
||||||
throw (RuntimeException)
|
throw (RuntimeException)
|
||||||
{
|
{
|
||||||
return new ProxyRoot( this, xTarget );
|
return new ProxyRoot( this, xTarget );
|
||||||
}
|
}
|
||||||
|
|
||||||
// XServiceInfo
|
// XServiceInfo
|
||||||
//__________________________________________________________________________________________________
|
//______________________________________________________________________________
|
||||||
OUString FactoryImpl::getImplementationName()
|
OUString FactoryImpl::getImplementationName()
|
||||||
throw(::com::sun::star::uno::RuntimeException)
|
throw (RuntimeException)
|
||||||
{
|
{
|
||||||
return proxyfac_getImplementationName();
|
return proxyfac_getImplementationName();;
|
||||||
}
|
}
|
||||||
//__________________________________________________________________________________________________
|
|
||||||
|
//______________________________________________________________________________
|
||||||
sal_Bool FactoryImpl::supportsService( const OUString & rServiceName )
|
sal_Bool FactoryImpl::supportsService( const OUString & rServiceName )
|
||||||
throw(::com::sun::star::uno::RuntimeException)
|
throw (RuntimeException)
|
||||||
{
|
{
|
||||||
const Sequence< OUString > & rSNL = getSupportedServiceNames();
|
Sequence< OUString > const & rSNL = getSupportedServiceNames();
|
||||||
const OUString * pArray = rSNL.getConstArray();
|
OUString const * pArray = rSNL.getConstArray();
|
||||||
for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
|
for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
|
||||||
{
|
{
|
||||||
if (pArray[nPos] == rServiceName)
|
if (rServiceName.equals( pArray[ nPos ] ))
|
||||||
return sal_True;
|
return true;
|
||||||
}
|
}
|
||||||
return sal_False;
|
return false;
|
||||||
}
|
}
|
||||||
//__________________________________________________________________________________________________
|
|
||||||
|
//______________________________________________________________________________
|
||||||
Sequence< OUString > FactoryImpl::getSupportedServiceNames()
|
Sequence< OUString > FactoryImpl::getSupportedServiceNames()
|
||||||
throw(::com::sun::star::uno::RuntimeException)
|
throw(::com::sun::star::uno::RuntimeException)
|
||||||
{
|
{
|
||||||
return proxyfac_getSupportedServiceNames();
|
return proxyfac_getSupportedServiceNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
//==================================================================================================
|
//==============================================================================
|
||||||
static Reference< XInterface > SAL_CALL FactoryImpl_create(
|
static Reference< XInterface > SAL_CALL proxyfac_create(
|
||||||
const Reference< XComponentContext > & xMgr )
|
Reference< XComponentContext > const & )
|
||||||
throw(::com::sun::star::uno::Exception)
|
throw (Exception)
|
||||||
{
|
{
|
||||||
Reference< XInterface > rRet;
|
Reference< XInterface > xRet;
|
||||||
{
|
{
|
||||||
MutexGuard guard( Mutex::getGlobalMutex() );
|
::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
|
||||||
static WeakReference < XInterface > rwInstance;
|
static WeakReference < XInterface > rwInstance;
|
||||||
rRet = rwInstance;
|
xRet = rwInstance;
|
||||||
|
|
||||||
if( ! rRet.is() )
|
if (! xRet.is())
|
||||||
{
|
{
|
||||||
rRet = (OWeakObject*)new FactoryImpl();
|
xRet = static_cast< ::cppu::OWeakObject * >(new FactoryImpl);
|
||||||
rwInstance = rRet;
|
rwInstance = xRet;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return rRet;
|
}
|
||||||
|
return xRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
static ::cppu::ImplementationEntry g_entries [] =
|
||||||
|
|
||||||
|
|
||||||
//##################################################################################################
|
|
||||||
//##################################################################################################
|
|
||||||
//##################################################################################################
|
|
||||||
|
|
||||||
|
|
||||||
using namespace stoc_proxyfac;
|
|
||||||
|
|
||||||
static struct ImplementationEntry g_entries[] =
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
FactoryImpl_create, proxyfac_getImplementationName,
|
proxyfac_create, proxyfac_getImplementationName,
|
||||||
proxyfac_getSupportedServiceNames, createSingleComponentFactory,
|
proxyfac_getSupportedServiceNames, ::cppu::createSingleComponentFactory,
|
||||||
&g_moduleCount.modCnt , 0
|
&g_moduleCount.modCnt, 0
|
||||||
},
|
},
|
||||||
{ 0, 0, 0, 0, 0, 0 }
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
sal_Bool SAL_CALL component_canUnload( TimeValue *pTime )
|
|
||||||
{
|
|
||||||
return g_moduleCount.canUnload( &g_moduleCount , pTime );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==================================================================================================
|
extern "C"
|
||||||
|
{
|
||||||
|
|
||||||
|
sal_Bool SAL_CALL component_canUnload( TimeValue * pTime )
|
||||||
|
{
|
||||||
|
return g_moduleCount.canUnload( &g_moduleCount, pTime );
|
||||||
|
}
|
||||||
|
|
||||||
void SAL_CALL component_getImplementationEnvironment(
|
void SAL_CALL component_getImplementationEnvironment(
|
||||||
const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
|
const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
|
||||||
{
|
{
|
||||||
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
|
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
|
||||||
}
|
}
|
||||||
//==================================================================================================
|
|
||||||
sal_Bool SAL_CALL component_writeInfo(
|
sal_Bool SAL_CALL component_writeInfo(
|
||||||
void * pServiceManager, void * pRegistryKey )
|
void * pServiceManager, void * pRegistryKey )
|
||||||
{
|
{
|
||||||
return component_writeInfoHelper( pServiceManager, pRegistryKey, g_entries );
|
return ::cppu::component_writeInfoHelper(
|
||||||
|
pServiceManager, pRegistryKey, g_entries );
|
||||||
}
|
}
|
||||||
//==================================================================================================
|
|
||||||
void * SAL_CALL component_getFactory(
|
void * SAL_CALL component_getFactory(
|
||||||
const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
|
const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
|
||||||
{
|
{
|
||||||
return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
|
return ::cppu::component_getFactoryHelper(
|
||||||
|
pImplName, pServiceManager, pRegistryKey, g_entries );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user