diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-18 14:15:02 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-18 21:47:45 +0200 |
commit | eab4993eab9a2a9e0660a827ed60f0125cf20d53 (patch) | |
tree | f65d10159f2d8776453cef43cb5b5e174786d43e /bridges | |
parent | 4f3f61a621a0e66fd0eab4886a3aa51e10513ad3 (diff) |
loplugin:flatten in bridges
Change-Id: I736032df48cb491508c27cbe773b964d1d2359b0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92482
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'bridges')
-rw-r--r-- | bridges/source/cpp_uno/shared/bridge.cxx | 152 | ||||
-rw-r--r-- | bridges/source/cpp_uno/shared/component.cxx | 152 | ||||
-rw-r--r-- | bridges/source/cpp_uno/shared/unointerfaceproxy.cxx | 26 | ||||
-rw-r--r-- | bridges/source/jni_uno/jni_bridge.cxx | 86 |
4 files changed, 208 insertions, 208 deletions
diff --git a/bridges/source/cpp_uno/shared/bridge.cxx b/bridges/source/cpp_uno/shared/bridge.cxx index 007373448bb3..3753341ccde2 100644 --- a/bridges/source/cpp_uno/shared/bridge.cxx +++ b/bridges/source/cpp_uno/shared/bridge.cxx @@ -59,39 +59,39 @@ void cpp2unoMapping( static_cast< uno_Interface * >( *ppUnoI ) ); *ppUnoI = nullptr; } - if (pCppI) + if (!pCppI) + return; + + Bridge * pBridge = static_cast< Bridge::Mapping * >( pMapping )->pBridge; + + // get object id of interface to be wrapped + rtl_uString * pOId = nullptr; + (*pBridge->pCppEnv->getObjectIdentifier)( + pBridge->pCppEnv, &pOId, pCppI ); + assert(pOId); + + // try to get any known interface from target environment + (*pBridge->pUnoEnv->getRegisteredInterface)( + pBridge->pUnoEnv, ppUnoI, pOId, pTypeDescr ); + + if (! *ppUnoI) // no existing interface, register new proxy interface { - Bridge * pBridge = static_cast< Bridge::Mapping * >( pMapping )->pBridge; - - // get object id of interface to be wrapped - rtl_uString * pOId = nullptr; - (*pBridge->pCppEnv->getObjectIdentifier)( - pBridge->pCppEnv, &pOId, pCppI ); - assert(pOId); - - // try to get any known interface from target environment - (*pBridge->pUnoEnv->getRegisteredInterface)( - pBridge->pUnoEnv, ppUnoI, pOId, pTypeDescr ); - - if (! *ppUnoI) // no existing interface, register new proxy interface - { - // try to publish a new proxy (refcount initially 1) - uno_Interface * pSurrogate - = bridges::cpp_uno::shared::UnoInterfaceProxy::create( - pBridge, - static_cast< ::com::sun::star::uno::XInterface * >( pCppI ), - pTypeDescr, pOId ); - - // proxy may be exchanged during registration - (*pBridge->pUnoEnv->registerProxyInterface)( - pBridge->pUnoEnv, reinterpret_cast< void ** >( &pSurrogate ), - freeUnoInterfaceProxy, pOId, - pTypeDescr ); - - *ppUnoI = pSurrogate; - } - ::rtl_uString_release( pOId ); + // try to publish a new proxy (refcount initially 1) + uno_Interface * pSurrogate + = bridges::cpp_uno::shared::UnoInterfaceProxy::create( + pBridge, + static_cast< ::com::sun::star::uno::XInterface * >( pCppI ), + pTypeDescr, pOId ); + + // proxy may be exchanged during registration + (*pBridge->pUnoEnv->registerProxyInterface)( + pBridge->pUnoEnv, reinterpret_cast< void ** >( &pSurrogate ), + freeUnoInterfaceProxy, pOId, + pTypeDescr ); + + *ppUnoI = pSurrogate; } + ::rtl_uString_release( pOId ); } void uno2cppMapping( @@ -105,38 +105,38 @@ void uno2cppMapping( release(); *ppCppI = nullptr; } - if (pUnoI) + if (!pUnoI) + return; + + Bridge * pBridge = static_cast< Bridge::Mapping * >( pMapping )->pBridge; + + // get object id of uno interface to be wrapped + rtl_uString * pOId = nullptr; + (*pBridge->pUnoEnv->getObjectIdentifier)( + pBridge->pUnoEnv, &pOId, pUnoI ); + assert(pOId); + + // try to get any known interface from target environment + (*pBridge->pCppEnv->getRegisteredInterface)( + pBridge->pCppEnv, ppCppI, pOId, pTypeDescr ); + + if (! *ppCppI) // no existing interface, register new proxy interface { - Bridge * pBridge = static_cast< Bridge::Mapping * >( pMapping )->pBridge; - - // get object id of uno interface to be wrapped - rtl_uString * pOId = nullptr; - (*pBridge->pUnoEnv->getObjectIdentifier)( - pBridge->pUnoEnv, &pOId, pUnoI ); - assert(pOId); - - // try to get any known interface from target environment - (*pBridge->pCppEnv->getRegisteredInterface)( - pBridge->pCppEnv, ppCppI, pOId, pTypeDescr ); - - if (! *ppCppI) // no existing interface, register new proxy interface - { - // try to publish a new proxy (ref count initially 1) - com::sun::star::uno::XInterface * pProxy - = bridges::cpp_uno::shared::CppInterfaceProxy::create( - pBridge, static_cast< uno_Interface * >( pUnoI ), - pTypeDescr, pOId ); - - // proxy may be exchanged during registration - (*pBridge->pCppEnv->registerProxyInterface)( - pBridge->pCppEnv, reinterpret_cast< void ** >( &pProxy ), - freeCppInterfaceProxy, pOId, - pTypeDescr ); - - *ppCppI = pProxy; - } - ::rtl_uString_release( pOId ); + // try to publish a new proxy (ref count initially 1) + com::sun::star::uno::XInterface * pProxy + = bridges::cpp_uno::shared::CppInterfaceProxy::create( + pBridge, static_cast< uno_Interface * >( pUnoI ), + pTypeDescr, pOId ); + + // proxy may be exchanged during registration + (*pBridge->pCppEnv->registerProxyInterface)( + pBridge->pCppEnv, reinterpret_cast< void ** >( &pProxy ), + freeCppInterfaceProxy, pOId, + pTypeDescr ); + + *ppCppI = pProxy; } + ::rtl_uString_release( pOId ); } uno_Mapping * Bridge::createMapping( @@ -150,22 +150,22 @@ uno_Mapping * Bridge::createMapping( void Bridge::acquire() { - if (++nRef == 1) + if (++nRef != 1) + return; + + if (bExportCpp2Uno) + { + uno_Mapping * pMapping = &aCpp2Uno; + ::uno_registerMapping( + &pMapping, freeMapping, &pCppEnv->aBase, + &pUnoEnv->aBase, nullptr ); + } + else { - if (bExportCpp2Uno) - { - uno_Mapping * pMapping = &aCpp2Uno; - ::uno_registerMapping( - &pMapping, freeMapping, &pCppEnv->aBase, - &pUnoEnv->aBase, nullptr ); - } - else - { - uno_Mapping * pMapping = &aUno2Cpp; - ::uno_registerMapping( - &pMapping, freeMapping, &pUnoEnv->aBase, - &pCppEnv->aBase, nullptr ); - } + uno_Mapping * pMapping = &aUno2Cpp; + ::uno_registerMapping( + &pMapping, freeMapping, &pUnoEnv->aBase, + &pCppEnv->aBase, nullptr ); } } diff --git a/bridges/source/cpp_uno/shared/component.cxx b/bridges/source/cpp_uno/shared/component.cxx index 9cd2b5ba5f36..5bdb0bb561eb 100644 --- a/bridges/source/cpp_uno/shared/component.cxx +++ b/bridges/source/cpp_uno/shared/component.cxx @@ -67,48 +67,48 @@ static void s_stub_computeObjectIdentifier(va_list * pParam) assert(pEnv && ppOId && pInterface); - if (pEnv && ppOId && pInterface) + if (!(pEnv && ppOId && pInterface)) + return; + + if (*ppOId) { - if (*ppOId) - { - rtl_uString_release( *ppOId ); - *ppOId = nullptr; - } + rtl_uString_release( *ppOId ); + *ppOId = nullptr; + } - try - { - ::com::sun::star::uno::Reference< - ::com::sun::star::uno::XInterface > xHome( - static_cast< ::com::sun::star::uno::XInterface * >( - pInterface ), - ::com::sun::star::uno::UNO_QUERY ); - assert(xHome.is() && "### query to XInterface failed!"); - if (xHome.is()) - { - // interface - OUStringBuffer oid( 64 ); - oid.append( reinterpret_cast< sal_Int64 >(xHome.get()), 16 ); - oid.append( ';' ); - // ;environment[context] - oid.append( OUString::unacquired(&pEnv->aBase.pTypeName) ); - oid.append( '[' ); - oid.append( - reinterpret_cast< sal_Int64 >(pEnv->aBase.pContext), - 16 ); - // ];good guid - oid.append( cppu_cppenv_getStaticOIdPart() ); - OUString aRet( oid.makeStringAndClear() ); - *ppOId = aRet.pData; - ::rtl_uString_acquire( *ppOId ); - } - } - catch (const ::com::sun::star::uno::RuntimeException & e) + try + { + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface > xHome( + static_cast< ::com::sun::star::uno::XInterface * >( + pInterface ), + ::com::sun::star::uno::UNO_QUERY ); + assert(xHome.is() && "### query to XInterface failed!"); + if (xHome.is()) { - SAL_WARN("bridges", - "### RuntimeException occurred during queryInterface(): " - << e.Message); + // interface + OUStringBuffer oid( 64 ); + oid.append( reinterpret_cast< sal_Int64 >(xHome.get()), 16 ); + oid.append( ';' ); + // ;environment[context] + oid.append( OUString::unacquired(&pEnv->aBase.pTypeName) ); + oid.append( '[' ); + oid.append( + reinterpret_cast< sal_Int64 >(pEnv->aBase.pContext), + 16 ); + // ];good guid + oid.append( cppu_cppenv_getStaticOIdPart() ); + OUString aRet( oid.makeStringAndClear() ); + *ppOId = aRet.pData; + ::rtl_uString_acquire( *ppOId ); } } + catch (const ::com::sun::star::uno::RuntimeException & e) + { + SAL_WARN("bridges", + "### RuntimeException occurred during queryInterface(): " + << e.Message); + } } static void computeObjectIdentifier( @@ -177,49 +177,49 @@ SAL_DLLPUBLIC_EXPORT void uno_ext_getMapping( SAL_THROW_EXTERN_C() { assert(ppMapping && pFrom && pTo); - if (ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv) - { - uno_Mapping * pMapping = nullptr; + if (!(ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv)) + return; - OUString from_envTypeName(cppu::EnvDcp::getTypeName(pFrom->pTypeName)); - OUString to_envTypeName(cppu::EnvDcp::getTypeName(pTo->pTypeName)); + uno_Mapping * pMapping = nullptr; - if (rtl_ustr_ascii_compare( - from_envTypeName.pData->buffer, - CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 && - rtl_ustr_ascii_compare( - to_envTypeName.pData->buffer, UNO_LB_UNO ) == 0) - { - // ref count initially 1 - pMapping = bridges::cpp_uno::shared::Bridge::createMapping( - pFrom->pExtEnv, pTo->pExtEnv, true ); - ::uno_registerMapping( - &pMapping, bridges::cpp_uno::shared::freeMapping, - &pFrom->pExtEnv->aBase, - &pTo->pExtEnv->aBase, nullptr ); - } - else if (rtl_ustr_ascii_compare( - to_envTypeName.pData->buffer, - CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 && - rtl_ustr_ascii_compare( - from_envTypeName.pData->buffer, UNO_LB_UNO ) == 0) - { - // ref count initially 1 - pMapping = bridges::cpp_uno::shared::Bridge::createMapping( - pTo->pExtEnv, pFrom->pExtEnv, false ); - ::uno_registerMapping( - &pMapping, bridges::cpp_uno::shared::freeMapping, - &pFrom->pExtEnv->aBase, - &pTo->pExtEnv->aBase, nullptr ); - } + OUString from_envTypeName(cppu::EnvDcp::getTypeName(pFrom->pTypeName)); + OUString to_envTypeName(cppu::EnvDcp::getTypeName(pTo->pTypeName)); - if (*ppMapping) - { - (*(*ppMapping)->release)( *ppMapping ); - } - if (pMapping) - *ppMapping = pMapping; + if (rtl_ustr_ascii_compare( + from_envTypeName.pData->buffer, + CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 && + rtl_ustr_ascii_compare( + to_envTypeName.pData->buffer, UNO_LB_UNO ) == 0) + { + // ref count initially 1 + pMapping = bridges::cpp_uno::shared::Bridge::createMapping( + pFrom->pExtEnv, pTo->pExtEnv, true ); + ::uno_registerMapping( + &pMapping, bridges::cpp_uno::shared::freeMapping, + &pFrom->pExtEnv->aBase, + &pTo->pExtEnv->aBase, nullptr ); + } + else if (rtl_ustr_ascii_compare( + to_envTypeName.pData->buffer, + CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 && + rtl_ustr_ascii_compare( + from_envTypeName.pData->buffer, UNO_LB_UNO ) == 0) + { + // ref count initially 1 + pMapping = bridges::cpp_uno::shared::Bridge::createMapping( + pTo->pExtEnv, pFrom->pExtEnv, false ); + ::uno_registerMapping( + &pMapping, bridges::cpp_uno::shared::freeMapping, + &pFrom->pExtEnv->aBase, + &pTo->pExtEnv->aBase, nullptr ); + } + + if (*ppMapping) + { + (*(*ppMapping)->release)( *ppMapping ); } + if (pMapping) + *ppMapping = pMapping; } } diff --git a/bridges/source/cpp_uno/shared/unointerfaceproxy.cxx b/bridges/source/cpp_uno/shared/unointerfaceproxy.cxx index c3c560acb7de..91578e9999d1 100644 --- a/bridges/source/cpp_uno/shared/unointerfaceproxy.cxx +++ b/bridges/source/cpp_uno/shared/unointerfaceproxy.cxx @@ -50,23 +50,23 @@ void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy) void acquireProxy(uno_Interface * pUnoI) { - if (++static_cast< UnoInterfaceProxy * >( pUnoI )->nRef == 1) - { - // rebirth of proxy zombie - // register at uno env + if (++static_cast< UnoInterfaceProxy * >( pUnoI )->nRef != 1) + return; + + // rebirth of proxy zombie + // register at uno env #if OSL_DEBUG_LEVEL > 1 - void * pThis = pUnoI; + void * pThis = pUnoI; #endif - (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()-> - registerProxyInterface)( - static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(), - reinterpret_cast< void ** >( &pUnoI ), freeUnoInterfaceProxy, - static_cast< UnoInterfaceProxy * >( pUnoI )->oid.pData, - static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr ); + (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()-> + registerProxyInterface)( + static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(), + reinterpret_cast< void ** >( &pUnoI ), freeUnoInterfaceProxy, + static_cast< UnoInterfaceProxy * >( pUnoI )->oid.pData, + static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr ); #if OSL_DEBUG_LEVEL > 1 - assert(pThis == pUnoI); + assert(pThis == pUnoI); #endif - } } void releaseProxy(uno_Interface * pUnoI) diff --git a/bridges/source/jni_uno/jni_bridge.cxx b/bridges/source/jni_uno/jni_bridge.cxx index 6ff327a1eb06..341c466aa90c 100644 --- a/bridges/source/jni_uno/jni_bridge.cxx +++ b/bridges/source/jni_uno/jni_bridge.cxx @@ -195,22 +195,22 @@ namespace jni_uno void Bridge::acquire() const { - if (++m_ref == 1) + if (++m_ref != 1) + return; + + if (m_registered_java2uno) { - if (m_registered_java2uno) - { - uno_Mapping * mapping = const_cast< Mapping * >( &m_java2uno ); - uno_registerMapping( - &mapping, Bridge_free, - m_java_env, &m_uno_env->aBase, nullptr ); - } - else - { - uno_Mapping * mapping = const_cast< Mapping * >( &m_uno2java ); - uno_registerMapping( - &mapping, Bridge_free, - &m_uno_env->aBase, m_java_env, nullptr ); - } + uno_Mapping * mapping = const_cast< Mapping * >( &m_java2uno ); + uno_registerMapping( + &mapping, Bridge_free, + m_java_env, &m_uno_env->aBase, nullptr ); + } + else + { + uno_Mapping * mapping = const_cast< Mapping * >( &m_uno2java ); + uno_registerMapping( + &mapping, Bridge_free, + &m_uno_env->aBase, m_java_env, nullptr ); } } @@ -425,34 +425,34 @@ extern "C" { static void java_env_dispose(uno_Environment * env) { auto * envData = static_cast<jni_uno::JniUnoEnvironmentData *>(env->pContext); - if (envData != nullptr) { - jobject async; - { - osl::MutexGuard g(envData->mutex); - async = envData->asynchronousFinalizer; - envData->asynchronousFinalizer = nullptr; - } - if (async != nullptr) { - try { - JNI_guarded_context jni(envData->info, envData->machine); - jni->CallObjectMethodA( - async, envData->info->m_method_AsynchronousFinalizer_drain, - nullptr); - jni.ensure_no_exception(); - jni->DeleteGlobalRef(async); - } catch (const BridgeRuntimeError & e) { - SAL_WARN( - "bridges", - "ignoring BridgeRuntimeError \"" << e.m_message << "\""); - } catch ( - jvmaccess::VirtualMachine::AttachGuard::CreationException &) - { - SAL_WARN( - "bridges", - ("ignoring jvmaccess::VirtualMachine::AttachGuard" - "::CreationException")); - } - } + if (envData == nullptr) return; + + jobject async; + { + osl::MutexGuard g(envData->mutex); + async = envData->asynchronousFinalizer; + envData->asynchronousFinalizer = nullptr; + } + if (async == nullptr) return; + + try { + JNI_guarded_context jni(envData->info, envData->machine); + jni->CallObjectMethodA( + async, envData->info->m_method_AsynchronousFinalizer_drain, + nullptr); + jni.ensure_no_exception(); + jni->DeleteGlobalRef(async); + } catch (const BridgeRuntimeError & e) { + SAL_WARN( + "bridges", + "ignoring BridgeRuntimeError \"" << e.m_message << "\""); + } catch ( + jvmaccess::VirtualMachine::AttachGuard::CreationException &) + { + SAL_WARN( + "bridges", + ("ignoring jvmaccess::VirtualMachine::AttachGuard" + "::CreationException")); } } |