INTEGRATION: CWS bunoexttm (1.26.4); FILE MERGED

2007/02/08 11:06:54 kr 1.26.4.3: fixed: linkage
2007/01/30 15:48:27 kr 1.26.4.2: adapted: joined from UTF2 - add purposed env. support
2006/12/19 12:02:19 kr 1.26.4.1: fixed: backed out hotfix
This commit is contained in:
Kurt Zenker 2007-05-09 12:26:03 +00:00
parent 74ea3aa803
commit bf8b46e6cb

View File

@ -4,9 +4,9 @@
* *
* $RCSfile: shlib.cxx,v $ * $RCSfile: shlib.cxx,v $
* *
* $Revision: 1.26 $ * $Revision: 1.27 $
* *
* last change: $Author: rt $ $Date: 2006-12-11 12:58:28 $ * last change: $Author: kz $ $Date: 2007-05-09 13:26:03 $
* *
* The Contents of this file are made available subject to * The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
@ -278,6 +278,61 @@ static OUString makeComponentPath(
} }
//============================================================================== //==============================================================================
static OUString getLibEnv(OUString const & aModulePath,
oslModule lib,
uno::Environment * pEnv,
OUString * pSourceEnv_name,
uno::Environment const & cTargetEnv,
OUString const & cImplName = OUString())
{
OUString aExcMsg;
sal_Char const * pEnvTypeName = NULL;
OUString aGetEnvNameExt = OUSTR(COMPONENT_GETENVEXT);
component_getImplementationEnvironmentExtFunc pGetImplEnvExt =
(component_getImplementationEnvironmentExtFunc)osl_getFunctionSymbol(lib, aGetEnvNameExt.pData);
if (pGetImplEnvExt)
{
OString implName(OUStringToOString(cImplName, RTL_TEXTENCODING_ASCII_US));
pGetImplEnvExt(&pEnvTypeName, (uno_Environment **)pEnv, implName.getStr(), cTargetEnv.get());
}
else
{
OUString aGetEnvName = OUSTR(COMPONENT_GETENV);
component_getImplementationEnvironmentFunc pGetImplEnv =
(component_getImplementationEnvironmentFunc)osl_getFunctionSymbol(
lib, aGetEnvName.pData );
if (pGetImplEnv)
pGetImplEnv(&pEnvTypeName, (uno_Environment **)pEnv);
else
{
aExcMsg = aModulePath;
aExcMsg += OUSTR(": cannot get symbol: ");
aExcMsg += aGetEnvName;
aExcMsg += OUSTR("- nor: ");
}
}
if (!pEnv->is() && pEnvTypeName)
*pSourceEnv_name = OUString::createFromAscii(pEnvTypeName);
return aExcMsg;
}
extern "C" {static void s_getFactory(va_list param)
{
component_getFactoryFunc pSym = va_arg(param, component_getFactoryFunc);
OString const * pImplName = va_arg(param, OString const *);
void * pSMgr = va_arg(param, void *);
void * pKey = va_arg(param, void *);
void ** ppSSF = va_arg(param, void **);
*ppSSF = pSym(pImplName->getStr(), pSMgr, pKey);
}}
Reference< XInterface > SAL_CALL loadSharedLibComponentFactory( Reference< XInterface > SAL_CALL loadSharedLibComponentFactory(
OUString const & rLibName, OUString const & rPath, OUString const & rLibName, OUString const & rPath,
OUString const & rImplName, OUString const & rImplName,
@ -303,119 +358,89 @@ Reference< XInterface > SAL_CALL loadSharedLibComponentFactory(
Reference< XInterface >() ); Reference< XInterface >() );
} }
OUString aExcMsg;
Reference< XInterface > xRet; Reference< XInterface > xRet;
oslGenericFunction pSym; uno::Environment currentEnv(Environment::getCurrent());
OUString aGetEnvName = OUSTR(COMPONENT_GETENV); uno::Environment env;
pSym = osl_getFunctionSymbol( lib, aGetEnvName.pData );
if (pSym != 0) OUString aEnvTypeName;
OUString aExcMsg = getLibEnv(aModulePath, lib, &env, &aEnvTypeName, currentEnv, rImplName);
if (!aExcMsg.getLength())
{ {
uno_Environment * pEnv = 0;
const sal_Char * pEnvTypeName = 0;
(*((component_getImplementationEnvironmentFunc) pSym))(
&pEnvTypeName, &pEnv );
OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
OUString aGetFactoryName = OUSTR(COMPONENT_GETFACTORY); OUString aGetFactoryName = OUSTR(COMPONENT_GETFACTORY);
pSym = osl_getFunctionSymbol( lib, aGetFactoryName.pData ); oslGenericFunction pSym = osl_getFunctionSymbol( lib, aGetFactoryName.pData );
if (pSym != 0) if (pSym != 0)
{ {
OString aImplName( OString aImplName(
OUStringToOString( rImplName, RTL_TEXTENCODING_ASCII_US ) ); OUStringToOString( rImplName, RTL_TEXTENCODING_ASCII_US ) );
if (pEnv == NULL &&aEnvTypeName.equalsAsciiL( if (!env.is())
RTL_CONSTASCII_STRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME))) env = uno::Environment(aEnvTypeName);
if (env.is() && currentEnv.is())
{ {
XInterface * pRet = #if OSL_DEBUG_LEVEL > 1
(XInterface *) (*((component_getFactoryFunc) pSym))(
aImplName.getStr(), xMgr.get(), xKey.get() );
if (pRet)
{ {
xRet = pRet; rtl::OString libName(rtl::OUStringToOString(rLibName, RTL_TEXTENCODING_ASCII_US));
pRet->release(); rtl::OString implName(rtl::OUStringToOString(rImplName, RTL_TEXTENCODING_ASCII_US));
rtl::OString envDcp(rtl::OUStringToOString(env.getTypeName(), RTL_TEXTENCODING_ASCII_US));
fprintf(stderr, "loadSharedLibComponentFactory envDcp: %-12.12s implName: %30.30s libName: %-15.15s\n", envDcp.getStr(), implName.getStr() + (implName.getLength() > 30 ? implName.getLength() - 30 : 0), libName.getStr());
}
#endif
Mapping aCurrent2Env( currentEnv, env );
Mapping aEnv2Current( env, currentEnv );
if (aCurrent2Env.is() && aEnv2Current.is())
{
void * pSMgr = aCurrent2Env.mapInterface(
xMgr.get(), ::getCppuType( &xMgr ) );
void * pKey = aCurrent2Env.mapInterface(
xKey.get(), ::getCppuType( &xKey ) );
void * pSSF = NULL;
env.invoke(s_getFactory, pSym, &aImplName, pSMgr, pKey, &pSSF);
if (pKey)
{
(env.get()->pExtEnv->releaseInterface)(
env.get()->pExtEnv, pKey );
}
if (pSMgr)
{
(*env.get()->pExtEnv->releaseInterface)(
env.get()->pExtEnv, pSMgr );
}
if (pSSF)
{
aEnv2Current.mapInterface(
reinterpret_cast< void ** >( &xRet ),
pSSF, ::getCppuType( &xRet ) );
(env.get()->pExtEnv->releaseInterface)(
env.get()->pExtEnv, pSSF );
}
else
{
aExcMsg = aModulePath;
aExcMsg += OUSTR(": cannot get factory of "
"demanded implementation: ");
aExcMsg += OStringToOUString(
aImplName, RTL_TEXTENCODING_ASCII_US );
}
} }
else else
{ {
aExcMsg = aModulePath; aExcMsg =
aExcMsg += OUSTR(": cannot get factory of demanded " OUSTR("cannot get uno mappings: C++ <=> UNO!");
"implementation: ");
aExcMsg += OStringToOUString(
aImplName, RTL_TEXTENCODING_ASCII_US );
} }
} }
else else
{ {
if (!pEnv) aExcMsg = OUSTR("cannot get uno environments!");
uno_getEnvironment( &pEnv, aEnvTypeName.pData, 0 );
uno_Environment * pCurrentEnv = 0;
if (pEnv)
{
OUString aCppEnvTypeName =
OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
uno_getEnvironment( &pCurrentEnv, aCppEnvTypeName.pData, 0 );
}
if (pEnv && pCurrentEnv)
{
Mapping aCurrent2Env( pCurrentEnv, pEnv );
Mapping aEnv2Current( pEnv, pCurrentEnv );
if (aCurrent2Env.is() && aEnv2Current.is())
{
void * pSMgr = aCurrent2Env.mapInterface(
xMgr.get(), ::getCppuType( &xMgr ) );
void * pKey = aCurrent2Env.mapInterface(
xKey.get(), ::getCppuType( &xKey ) );
void * pSSF =
(*((component_getFactoryFunc) pSym))(
aImplName.getStr(), pSMgr, pKey );
if (pKey)
{
(*pEnv->pExtEnv->releaseInterface)(
pEnv->pExtEnv, pKey );
}
if (pSMgr)
{
(*pEnv->pExtEnv->releaseInterface)(
pEnv->pExtEnv, pSMgr );
}
if (pSSF)
{
aEnv2Current.mapInterface(
reinterpret_cast< void ** >( &xRet ),
pSSF, ::getCppuType( &xRet ) );
(*pEnv->pExtEnv->releaseInterface)(
pEnv->pExtEnv, pSSF );
}
else
{
aExcMsg = aModulePath;
aExcMsg += OUSTR(": cannot get factory of "
"demanded implementation: ");
aExcMsg += OStringToOUString(
aImplName, RTL_TEXTENCODING_ASCII_US );
}
}
else
{
aExcMsg =
OUSTR("cannot get uno mappings: C++ <=> UNO!");
}
}
else
{
aExcMsg = OUSTR("cannot get uno environments!");
}
if (pCurrentEnv)
(*pCurrentEnv->release)( pCurrentEnv );
} }
} }
else else
@ -424,15 +449,6 @@ Reference< XInterface > SAL_CALL loadSharedLibComponentFactory(
aExcMsg += OUSTR(": cannot get symbol: "); aExcMsg += OUSTR(": cannot get symbol: ");
aExcMsg += aGetFactoryName; aExcMsg += aGetFactoryName;
} }
if (pEnv)
(*pEnv->release)( pEnv );
}
else
{
aExcMsg = aModulePath;
aExcMsg += OUSTR(": cannot get symbol: ");
aExcMsg += aGetEnvName;
} }
if (! xRet.is()) if (! xRet.is())
@ -453,6 +469,17 @@ Reference< XInterface > SAL_CALL loadSharedLibComponentFactory(
} }
//============================================================================== //==============================================================================
extern "C" { static void s_writeInfo(va_list param)
{
component_writeInfoFunc pSym = va_arg(param, component_writeInfoFunc);
void * pSMgr = va_arg(param, void *);
void * pKey = va_arg(param, void *);
sal_Bool * pbRet = va_arg(param, sal_Bool *);
*pbRet = pSym(pSMgr, pKey);
}}
void SAL_CALL writeSharedLibComponentInfo( void SAL_CALL writeSharedLibComponentInfo(
OUString const & rLibName, OUString const & rPath, OUString const & rLibName, OUString const & rPath,
Reference< lang::XMultiServiceFactory > const & xMgr, Reference< lang::XMultiServiceFactory > const & xMgr,
@ -461,8 +488,6 @@ void SAL_CALL writeSharedLibComponentInfo(
{ {
OUString aModulePath( makeComponentPath( rLibName, rPath ) ); OUString aModulePath( makeComponentPath( rLibName, rPath ) );
OUString aExcMsg;
if (! checkAccessPath( &aModulePath )) if (! checkAccessPath( &aModulePath ))
{ {
throw registry::CannotRegisterImplementationException( throw registry::CannotRegisterImplementationException(
@ -482,104 +507,65 @@ void SAL_CALL writeSharedLibComponentInfo(
sal_Bool bRet = sal_False; sal_Bool bRet = sal_False;
oslGenericFunction pSym; uno::Environment currentEnv(Environment::getCurrent());
OUString aGetEnvName = OUSTR(COMPONENT_GETENV); uno::Environment env;
pSym = osl_getFunctionSymbol( lib, aGetEnvName.pData );
if (pSym != 0) OUString aEnvTypeName;
OUString aExcMsg = getLibEnv(aModulePath, lib, &env, &aEnvTypeName, currentEnv);
if (!aExcMsg.getLength())
{ {
uno_Environment * pEnv = 0;
const sal_Char * pEnvTypeName = 0;
(*((component_getImplementationEnvironmentFunc) pSym))(
&pEnvTypeName, &pEnv );
OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
OUString aWriteInfoName = OUSTR(COMPONENT_WRITEINFO); OUString aWriteInfoName = OUSTR(COMPONENT_WRITEINFO);
pSym = osl_getFunctionSymbol( lib, aWriteInfoName.pData ); oslGenericFunction pSym = osl_getFunctionSymbol( lib, aWriteInfoName.pData );
if (pSym != 0) if (pSym != 0)
{ {
if (pEnv == NULL && aEnvTypeName.equalsAsciiL( if (!env.is())
RTL_CONSTASCII_STRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME))) env = uno::Environment(aEnvTypeName);
{
if (xKey.is())
{
bRet = (*((component_writeInfoFunc) pSym))(
xMgr.get(), xKey.get() );
if (! bRet)
{
aExcMsg = aModulePath;
aExcMsg += OUSTR(": component_writeInfo() returned "
"false!");
}
}
else
{
// key is mandatory
aExcMsg = aModulePath;
aExcMsg += OUSTR(": registry is mandatory to invoke "
"component_writeInfo()!");
}
}
else
{
if (!pEnv)
uno_getEnvironment( &pEnv, aEnvTypeName.pData, 0 );
uno_Environment * pCurrentEnv = 0; if (env.is() && currentEnv.is())
if (pEnv) {
Mapping aCurrent2Env( currentEnv, env );
if (aCurrent2Env.is())
{ {
OUString aCppEnvTypeName = void * pSMgr = aCurrent2Env.mapInterface(
OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME); xMgr.get(), ::getCppuType( &xMgr ) );
uno_getEnvironment( &pCurrentEnv, aCppEnvTypeName.pData, 0 ); void * pKey = aCurrent2Env.mapInterface(
} xKey.get(), ::getCppuType( &xKey ) );
if (pKey)
if (pEnv && pCurrentEnv)
{
Mapping aCurrent2Env( pCurrentEnv, pEnv );
if (aCurrent2Env.is())
{ {
void * pSMgr = aCurrent2Env.mapInterface( env.invoke(s_writeInfo, pSym, pSMgr, pKey, &bRet);
xMgr.get(), ::getCppuType( &xMgr ) );
void * pKey = aCurrent2Env.mapInterface(
xKey.get(), ::getCppuType( &xKey ) ); (*env.get()->pExtEnv->releaseInterface)(
if (pKey) env.get()->pExtEnv, pKey );
if (! bRet)
{ {
bRet = (*((component_writeInfoFunc) pSym))(
pSMgr, pKey );
(*pEnv->pExtEnv->releaseInterface)(
pEnv->pExtEnv, pKey );
if (! bRet)
{
aExcMsg = aModulePath;
aExcMsg += OUSTR(": component_writeInfo() "
"returned false!");
}
}
else
{
// key is mandatory
aExcMsg = aModulePath; aExcMsg = aModulePath;
aExcMsg += OUSTR(": registry is mandatory to invoke" aExcMsg += OUSTR(": component_writeInfo() "
" component_writeInfo()!"); "returned false!");
}
if (pSMgr)
{
(*pEnv->pExtEnv->releaseInterface)(
pEnv->pExtEnv, pSMgr );
} }
} }
else else
{ {
aExcMsg = OUSTR("cannot get uno mapping: C++ <=> UNO!"); // key is mandatory
aExcMsg = aModulePath;
aExcMsg += OUSTR(": registry is mandatory to invoke"
" component_writeInfo()!");
}
if (pSMgr)
{
(*env.get()->pExtEnv->releaseInterface)(
env.get()->pExtEnv, pSMgr );
} }
} }
else else
{ {
aExcMsg = OUSTR("cannot get uno environments!"); aExcMsg = OUSTR("cannot get uno mapping: C++ <=> UNO!");
} }
if (pCurrentEnv) }
(*pCurrentEnv->release)( pCurrentEnv ); else
{
aExcMsg = OUSTR("cannot get uno environments!");
} }
} }
else else
@ -588,17 +574,7 @@ void SAL_CALL writeSharedLibComponentInfo(
aExcMsg += OUSTR(": cannot get symbol: "); aExcMsg += OUSTR(": cannot get symbol: ");
aExcMsg += aWriteInfoName; aExcMsg += aWriteInfoName;
} }
if (pEnv)
(*pEnv->release)( pEnv );
} }
else
{
aExcMsg = aModulePath;
aExcMsg += OUSTR(": cannot get symbol: ");
aExcMsg += aGetEnvName;
}
//! //!
//! OK: please look at #88219# //! OK: please look at #88219#