/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include using namespace ::osl; using namespace ::cppu; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; namespace { using cppuhelper::detail::XExceptionThrower; struct ExceptionThrower : public uno_Interface, XExceptionThrower { inline ExceptionThrower(); virtual ~ExceptionThrower() {} static Type const & getCppuType() { return cppu::UnoType::get(); } // XInterface virtual Any SAL_CALL queryInterface( Type const & type ) override; virtual void SAL_CALL acquire() throw () override; virtual void SAL_CALL release() throw () override; // XExceptionThrower virtual void SAL_CALL throwException( Any const & exc ) override; virtual void SAL_CALL rethrowException() override; }; extern "C" { void SAL_CALL ExceptionThrower_acquire_release_nop( SAL_UNUSED_PARAMETER uno_Interface * ) {} void SAL_CALL ExceptionThrower_dispatch( uno_Interface * pUnoI, typelib_TypeDescription const * pMemberType, void * pReturn, void * pArgs [], uno_Any ** ppException ) { OSL_ASSERT( pMemberType->eTypeClass == typelib_TypeClass_INTERFACE_METHOD ); switch (reinterpret_cast< typelib_InterfaceMemberTypeDescription * >( const_cast< typelib_TypeDescription * >( pMemberType ) )-> nPosition) { case 0: // queryInterface() { Type const & rType_demanded = *static_cast< Type const * >( pArgs[ 0 ] ); if (rType_demanded.equals( cppu::UnoType::get() ) || rType_demanded.equals( ExceptionThrower::getCppuType() )) { typelib_TypeDescription * pTD = nullptr; TYPELIB_DANGER_GET( &pTD, rType_demanded.getTypeLibType() ); uno_any_construct( static_cast< uno_Any * >( pReturn ), &pUnoI, pTD, nullptr ); TYPELIB_DANGER_RELEASE( pTD ); } else { uno_any_construct( static_cast< uno_Any * >( pReturn ), nullptr, nullptr, nullptr ); } *ppException = nullptr; break; } case 1: // acquire() case 2: // release() *ppException = nullptr; break; case 3: // throwException() { uno_Any * pAny = static_cast< uno_Any * >( pArgs[ 0 ] ); OSL_ASSERT( pAny->pType->eTypeClass == typelib_TypeClass_EXCEPTION ); uno_type_any_construct( *ppException, pAny->pData, pAny->pType, nullptr ); break; } default: { OSL_ASSERT( false ); RuntimeException exc( "not implemented!" ); uno_type_any_construct( *ppException, &exc, cppu::UnoType::get().getTypeLibType(), nullptr ); break; } } } } // extern "C" Any ExceptionThrower::queryInterface( Type const & type ) { if (type.equals( cppu::UnoType::get() ) || type.equals( ExceptionThrower::getCppuType() )) { XExceptionThrower * that = static_cast< XExceptionThrower * >( this ); return Any( &that, type ); } return Any(); } void ExceptionThrower::acquire() throw () { } void ExceptionThrower::release() throw () { } void ExceptionThrower::throwException( Any const & exc ) { OSL_FAIL( "unexpected!" ); cppu::throwException( exc ); } void ExceptionThrower::rethrowException() { throw; } inline ExceptionThrower::ExceptionThrower() { uno_Interface::acquire = ExceptionThrower_acquire_release_nop; uno_Interface::release = ExceptionThrower_acquire_release_nop; uno_Interface::pDispatcher = ExceptionThrower_dispatch; } class theExceptionThrower : public rtl::Static {}; } // anonymous namespace namespace cppu { void SAL_CALL throwException( Any const & exc ) { if (exc.getValueTypeClass() != TypeClass_EXCEPTION) { throw RuntimeException( "no UNO exception given " "(must be derived from com::sun::star::uno::Exception)!" ); } Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent()); if (! uno2cpp.is()) { throw RuntimeException( "cannot get binary UNO to C++ mapping!" ); } Reference< XExceptionThrower > xThrower; uno2cpp.mapInterface( reinterpret_cast< void ** >( &xThrower ), static_cast< uno_Interface * >( &theExceptionThrower::get() ), ExceptionThrower::getCppuType() ); OSL_ASSERT( xThrower.is() ); xThrower->throwException( exc ); } Any SAL_CALL getCaughtException() { Mapping cpp2uno(Environment::getCurrent(), Environment(UNO_LB_UNO)); if (! cpp2uno.is()) { throw RuntimeException( "cannot get C++ to binary UNO mapping!" ); } Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent()); if (! uno2cpp.is()) { throw RuntimeException( "cannot get binary UNO to C++ mapping!" ); } typelib_TypeDescription * pTD = nullptr; TYPELIB_DANGER_GET( &pTD, ExceptionThrower::getCppuType().getTypeLibType() ); UnoInterfaceReference unoI; cpp2uno.mapInterface( reinterpret_cast< void ** >( &unoI.m_pUnoI ), static_cast< XExceptionThrower * >( &theExceptionThrower::get() ), pTD ); OSL_ASSERT( unoI.is() ); typelib_TypeDescription * pMemberTD = nullptr; TYPELIB_DANGER_GET( &pMemberTD, reinterpret_cast< typelib_InterfaceTypeDescription * >( pTD )-> ppMembers[ 1 ] /* rethrowException() */ ); uno_Any exc_mem; uno_Any * exc = &exc_mem; unoI.dispatch( pMemberTD, nullptr, nullptr, &exc ); TYPELIB_DANGER_RELEASE( pMemberTD ); TYPELIB_DANGER_RELEASE( pTD ); if (exc == nullptr) { throw RuntimeException( "rethrowing C++ exception failed!" ); } Any ret; uno_any_destruct( &ret, reinterpret_cast< uno_ReleaseFunc >(cpp_release) ); uno_type_any_constructAndConvert( &ret, exc->pData, exc->pType, uno2cpp.get() ); uno_any_destruct( exc, nullptr ); return ret; } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 7-4 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2015-10-15cppcheck:variableScopeNoel Grandin
2015-10-14cid#1326679 DLS: Dead local storeNoel Grandin
2015-10-12Replace "SAL_OVERRIDE" with "override" in LIBO_INTERNAL_ONLY codeStephan Bergmann
2015-10-12Replace "SAL_DELETED_FUNCTION" with "= delete" in LIBO_INTERNAL_ONLY codeStephan Bergmann
2015-09-29Fix typosAndrea Gelmini
2015-09-09testtools: tdf#88206 replace cppu::WeakImplHelper*Takeshi Abe
2015-07-10ppc64: using a fp register also consumes a gp register slotCaolan McNamara
2015-07-08loplugin:stringconstantStephan Bergmann
2015-06-11java:regulatize the order of 'final' and public/privateNoel Grandin
2015-06-08loplugin:cstylecast: deal with remaining pointer castsStephan Bergmann
2015-05-26cppcheck: noExplicitConstructorCaolán McNamara
2015-05-08Clean up checks of sal_Bool valuesStephan Bergmann
2015-04-27More loplugin:simplifyboolStephan Bergmann
2015-04-01Replace remaining getCppuType et al with cppu::UnoTypeStephan Bergmann
2015-03-31Reduce to static_cast any reinterpret_cast from void pointersStephan Bergmann
2015-03-04V813: Decreased performanceCaolán McNamara
2015-02-27testtools: mark CurrentContextChecker as DLLPRIVATEMichael Stahl
2015-02-07loplugin:deletedspecialStephan Bergmann
2015-01-20Some more loplugin:cstylecast: testtoolsStephan Bergmann
2015-01-02boost::unordered_map->std::unordered_mapCaolán McNamara
2014-12-18testtools: Use appropriate OUString functions on string constantsStephan Bergmann
2014-12-16testtools: Use appropriate OUString functions on string constantsStephan Bergmann
2014-12-12testtools: Use appropriate OUString functions on string constantsStephan Bergmann
2014-12-11java: reduce visibility of fields and methodsNoel Grandin
2014-12-05java: remove some unused fieldsNoel Grandin
2014-11-27Remove dead dmake makefile.mkStephan Bergmann
2014-11-06Revert "use the new OUString::fromUtf8 method"Stephan Bergmann
2014-11-06use the new OUString::fromUtf8 methodNoel Grandin
2014-10-16java: when rethrowing, store the original exceptionNoel Grandin
2014-10-07java: remove unnecessary adding of empty stringsNoel Grandin
2014-09-18Use instsetoo_native-generated uno ini-file for both instdir and instsetsStephan Bergmann
2014-09-16Missing dependency on uno ini-fileStephan Bergmann
2014-08-20remove more unnecessary constructor declarationsNoel Grandin
2014-08-20java: don't catch and then just rethrow an exceptionNoel Grandin
2014-08-19java: use 'Byte.valueOf' instead of 'new Byte'Noel Grandin
2014-08-19java: use 'Short.valueOf' instead of 'new Short'Noel Grandin
2014-08-19java: use 'Long.valueOf' instead of 'new Long'Noel Grandin
2014-08-19java: use 'Integer.valueOf' instead of 'new Integer'Noel Grandin
2014-08-19java: use Boolean.valueOf instead of instantiating Boolean objectsNoel Grandin
2014-08-14java: remove commented out codeNoel Grandin
2014-08-12java: add @Override annotation to overriding methodsNoel Grandin
2014-08-08java: use an empty block rather than an empty statementNoel Grandin
2014-08-08java: remove unused variablesNoel Grandin
2014-08-05java: remove commented out codeNoel Grandin
2014-06-05various: remove SAL_THROW macroNoel Grandin
2014-05-23remove boilerplate in UNO Exception constructor callsNoel Grandin
2014-05-15Resolves fdo#70681: fixincludeguards.pl: all that's leftThomas Arnhold
2014-05-08various: sal_Bool->boolNoel Grandin
2014-04-28prefer makefile-gmake-modeTakeshi Abe
2014-04-09Clean up function declarationsStephan Bergmann