/* -*- 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 #include #include #include #include #include #include #include #include #include #include #include #if defined ( UNX ) #include #define _MAX_PATH PATH_MAX #endif #define IMPLEMENTATION_NAME "com.sun.star.DummyService.V10" #define SERVICE_NAME "com.sun.star.ts.TestManagerImpl" using namespace css::uno; using namespace css::registry; using namespace css::lang; using namespace css::container; using namespace osl; using namespace cppu; Reference getProcessServiceManager() { Reference s_x; if (! s_x.is()) { MutexGuard aGuard( Mutex::getGlobalMutex() ); if (! s_x.is()) s_x = createRegistryServiceFactory( OUString("stoctest.rdb"), sal_False ); } return s_x; } Reference< XMultiServiceFactory > createRegistryServiceManager( const OUString& registryName ) { return createRegistryServiceFactory( registryName ); } /********************************** * The service, that is used to test the Service manager * * * *************************************/ static sal_uInt32 nInstanceCount = 0; class Test_Manager_Impl : public WeakImplHelper1< XServiceInfo > { public: Test_Manager_Impl(){ nInstanceCount++;} ~Test_Manager_Impl(); // XServiceInfo OUString SAL_CALL getImplementationName() throw(); sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(); Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw(); static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static(void) throw(); private: // static XIdlClassRef getStaticIdlClass(); }; Test_Manager_Impl::~Test_Manager_Impl() { nInstanceCount--; } // old, is no longer needed by the new Mimic Reference< XInterface > SAL_CALL Test_Manager_Impl_CreateInstance_Impl() { return (OWeakObject *)new Test_Manager_Impl(); } // Test_Manager_Impl_CreateInstance() Reference < XInterface > SAL_CALL Test_Manager_Impl_CreateInstance( const Reference< XMultiServiceFactory > & /*rSMgr*/ ) throw (Exception) { Reference < XInterface > xService = (XWeak *)(OWeakObject *)new Test_Manager_Impl( ); return xService; } // Test_Manager_Impl::getImplementationName OUString Test_Manager_Impl::getImplementationName() throw() { return OUString(IMPLEMENTATION_NAME); } // Test_Manager_Impl::supportsService sal_Bool Test_Manager_Impl::supportsService( const OUString& ServiceName ) throw() { return cppu::supportsService(this, ServiceName); } // Test_Manager_Impl::getSupportedServiceNames Sequence< OUString > Test_Manager_Impl::getSupportedServiceNames(void) throw () { return getSupportedServiceNames_Static(); } // Test_Manager_Impl::getSupportedServiceNames_Static Sequence< OUString > Test_Manager_Impl::getSupportedServiceNames_Static(void) throw () { Sequence< OUString > aSNS( 2 ); aSNS.getArray()[0] = SERVICE_NAME; aSNS.getArray()[1] = "com.sun.star.bridge.Bridge"; return aSNS; } /**** * * * This routine performs the test of the process service manager ( getProcessServiceManager is called ) * * * ****/ #include extern "C" void SAL_CALL test_ServiceManager() { #if ! defined SAL_DLLPREFIX #define SAL_DLLPREFIX "" #endif OUString atUModule2 = SAL_DLLPREFIX "testsmgr_component" SAL_DLLEXTENSION ; // expand shared library name OString atModule2( OUStringToOString(atUModule2, RTL_TEXTENCODING_ASCII_US) ); // get the process servicemanager Reference xSMgr = getProcessServiceManager(); OSL_ENSURE( xSMgr.is() , "query on XServiceManager failed" ); Reference xContEnum(xSMgr, UNO_QUERY); OSL_ENSURE( xContEnum.is() , "query on XContentEnumerationAccess failed" ); Reference xEnum(xContEnum->createContentEnumeration(OUString("com.sun.star.registry.SimpleRegistry"))); OSL_ENSURE( xEnum.is() , "createContentEnumeration failed" ); sal_Int32 nLen = 0; while( xEnum->hasMoreElements() ) { nLen++; xEnum->nextElement(); } OSL_ENSURE( nLen == 1, "more than one implementation for SimpleRegistry" ); Reference xImplEnum(xSMgr, UNO_QUERY); OSL_ENSURE( xImplEnum.is() , "query on XEnumeration failed" ); xEnum = Reference(xImplEnum->createEnumeration()); OSL_ENSURE( xEnum.is() , "createEnumeration failed" ); nLen = 0; while( xEnum->hasMoreElements() ) { nLen++; Reference< XServiceInfo > sf( xEnum->nextElement(), UNO_QUERY ); OString str( OUStringToOString( sf->getImplementationName(), RTL_TEXTENCODING_ASCII_US ) ); ::fprintf( stderr, "> implementation name: %s\n", str.getStr() ); } OSL_ENSURE( nLen == 8, "more than 6 factories" ); // try to get an instance for a unknown service OSL_VERIFY( !xSMgr->createInstance("bla.blup.Q").is() ); // First test : register service via the internal function of the component itself { Reference< XImplementationRegistration > xInst( xSMgr->createInstance("com.sun.star.registry.ImplementationRegistration"), UNO_QUERY ); OSL_ENSURE( xInst.is(), "no ImplementationRegistration" ); try { // register the services via writeComponentRegInfo (see at end of this file) xInst->registerImplementation(OUString("com.sun.star.loader.SharedLibrary"), atUModule2, Reference< XSimpleRegistry >() ); } catch(const CannotRegisterImplementationException &) { OSL_ENSURE( 0, "register implementation failed" ); } // getImplementations() check Sequence seqImpl = xInst->getImplementations(OUString("com.sun.star.loader.SharedLibrary"), atUModule2); OSL_ENSURE( seqImpl.getLength() == 1, "count of implementantions is wrong" ); OSL_ENSURE( seqImpl.getConstArray()[0] == "com.sun.star.DummyService.V10", "implementation name is not equal" ); // tests, if a service provider can be instantiated. Reference< XInterface > xIFace(xSMgr->createInstance("com.sun.star.ts.TestManagerImpl")); OSL_ENSURE( xIFace.is(), "loadable service not found" ); // remove the service OSL_VERIFY( xInst->revokeImplementation(atUModule2, Reference< XSimpleRegistry > ()) ); } Reference xComp(xSMgr, UNO_QUERY); xComp->dispose(); xComp.clear(); xSMgr.clear(); } extern "C" { sal_Bool SAL_CALL component_writeInfo( void * /*pServiceManager*/, void * pRegistryKey ) { if (pRegistryKey) { try { Reference< XRegistryKey > xNewKey( reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( OUString( "/" IMPLEMENTATION_NAME "/UNO/SERVICES" ) ) ); const Sequence< OUString > & rSNL = Test_Manager_Impl::getSupportedServiceNames_Static(); const OUString * pArray = rSNL.getConstArray(); for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) xNewKey->createKey( pArray[nPos] ); return sal_True; } catch (InvalidRegistryException &) { OSL_FAIL( "### InvalidRegistryException!" ); } } return sal_False; } SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) { void * pRet = 0; if (rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0) { Reference< XSingleServiceFactory > xFactory( createSingleFactory( reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), OUString( IMPLEMENTATION_NAME ), Test_Manager_Impl_CreateInstance, Test_Manager_Impl::getSupportedServiceNames_Static() ) ); if (xFactory.is()) { xFactory->acquire(); pRet = xFactory.get(); } } return pRet; } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ re/RotGrfFlyFrame LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2019-10-30loplugin:finalclasses toolsNoel Grandin
2019-08-23Mark move ctors/assignments noexceptMike Kaganski
2019-07-20Fix typosAndrea Gelmini
2018-07-10tdf#79877 perf loading docx file, writerfilter/ improvementsNoel Grandin
2017-06-06add COVERITY_NOEXCEPT_FALSECaolán McNamara
2017-04-22revert bits of "remove some old MSVC workarounds"Noel Grandin
2017-04-21remove some old MSVC workaroundsNoel Grandin
2017-03-03Remove redundant 'inline' keywordStephan Bergmann
2017-02-02convert method names in tools::SvRef to be more like our other..Noel Grandin
2017-01-26add 'explicit operator bool' to our reference classesNoel Grandin
2016-11-16new loplugin finalprotectedNoel Grandin
2016-10-18tdf#89307: Removed T* SvRef::opeartor &()Jacek Fraczek
2016-10-12use more 'nullptr' in SvRef templatesJochen Nitschke
2016-10-11Demonstrate that SvRef ==/!= are acceptable as member functionsStephan Bergmann
2016-10-10tdf#89307: Removed SvRef::operator T*()Jacek Fraczek
2016-08-29cid#1371154 Missing move assignment operatorNoel Grandin
2016-02-22BASIC : Add tools::make_ref and simplify SvRef usageArnaud Versini
2016-01-15loplugin:unusedmethods unused return value in include/toolsNoel Grandin
2015-12-10More loplugin:nullptr automatic rewrite (within templates)Stephan Bergmann
2015-11-24add SAL_WARN_UNUSED to css::uno::WeakReference and SvCompatWeakRefNoel Grandin
2015-11-04tools: re-order members of SvRefBase to work around clang 3.5 bugMichael Stahl
2015-10-27move SvRefMemberList into idlNoel Grandin
2015-10-27loplugin:unusedmethodsNoel Grandin
2015-08-20afl-clang-fast apparently miscompiles thisCaolán McNamara
2015-02-05fdo#39440: replace C-style cast'sJuan Picca
2015-01-26Visible function type RTTI for Clang -fsanitize=functionStephan Bergmann
2014-10-09remove SvRefBase::QueryDeleteNoel Grandin
2014-10-03rename SvRef::AddRef to AddFirstRefNoel Grandin
2014-07-29simplify "no delete" logic in SvRefBaseNoel Grandin
2014-07-25convert the weak reference macro in tools into a templateNoel Grandin
2014-07-22remove dead codeNoel Grandin
2014-07-17rename the Weak stuff in tools/ref.hxx to WeakRefNoel Grandin
2014-07-15Revert "remove unused SvRefBase constructor"Michael Stahl
2014-07-14add some comments to include/tools/ref.hxxNoel Grandin
2014-07-14inline SvCompatWeakHdlRef typedefNoel Grandin
2014-07-14inline tools::SvRefBaseRef typedefNoel Grandin
2014-07-14remove unused SvRefBase constructorNoel Grandin
2014-07-14include/tools/ref.hxx - cleanup formattingNoel Grandin
2014-07-14fix spelling in commentNoel Grandin
2014-07-10remove SvRefBase::ReleaseReferenceNoel Grandin
2014-06-19Catch illegal null pointer dereferences earlyStephan Bergmann
2014-04-07Replace SV_DECL/IMPL_REF macros with SvRef templateStephan Bergmann
2014-04-07Unroll sole use of SV_IMPL/DECL_LOCKStephan Bergmann
2014-02-18tools: sal_Bool -> boolStephan Bergmann
2014-01-28bool improvementsStephan Bergmann
2013-11-09fdo#65108 inter-module includes <> include/toolsNorbert Thiebaud
2013-10-23fixincludeguards.sh: include/{toolkit,tools}Thomas Arnhold
2013-10-15Some clean-upStephan Bergmann
2013-04-23execute move of global headersBjoern Michaelsen