LCOV - code coverage report
Current view: top level - comphelper/source/misc - componentmodule.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 50 51 98.0 %
Date: 2014-11-03 Functions: 12 13 92.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <comphelper/componentmodule.hxx>
      21             : 
      22             : #include <comphelper/sequence.hxx>
      23             : #include <osl/diagnose.h>
      24             : 
      25             : #include <vector>
      26             : 
      27             : 
      28             : namespace comphelper
      29             : {
      30             : 
      31             : 
      32             :     using namespace ::cppu;
      33             :     using ::com::sun::star::uno::Sequence;
      34             :     using ::com::sun::star::uno::RuntimeException;
      35             :     using ::com::sun::star::uno::Reference;
      36             :     using ::com::sun::star::lang::XMultiServiceFactory;
      37             :     using ::com::sun::star::registry::XRegistryKey;
      38             :     using ::com::sun::star::uno::Exception;
      39             :     using ::com::sun::star::uno::XInterface;
      40             : 
      41             :     typedef ::std::vector< ComponentDescription >   ComponentDescriptions;
      42             : 
      43             : 
      44             :     //= OModuleImpl
      45             : 
      46             :     /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by its owner
      47             :     */
      48             :     class OModuleImpl
      49             :     {
      50             :     public:
      51             :         ComponentDescriptions                           m_aRegisteredComponents;
      52             : 
      53             :         OModuleImpl();
      54             :         ~OModuleImpl();
      55             :     };
      56             : 
      57             : 
      58         522 :     OModuleImpl::OModuleImpl()
      59             :     {
      60         522 :     }
      61             : 
      62             : 
      63         466 :     OModuleImpl::~OModuleImpl()
      64             :     {
      65         466 :     }
      66             : 
      67             : 
      68             :     //= OModule
      69             : 
      70             : 
      71         522 :     OModule::OModule()
      72             :         : m_nClients(0)
      73         522 :         , m_pImpl(new OModuleImpl)
      74             :     {
      75         522 :     }
      76             : 
      77         932 :     OModule::~OModule()
      78             :     {
      79         466 :         delete m_pImpl;
      80         466 :     }
      81             : 
      82             : 
      83           6 :     void OModule::registerClient( OModule::ClientAccess )
      84             :     {
      85           6 :         ::osl::MutexGuard aGuard(m_aMutex);
      86           6 :         if ( 1 == osl_atomic_increment( &m_nClients ) )
      87           4 :             onFirstClient();
      88           6 :     }
      89             : 
      90             : 
      91           6 :     void OModule::revokeClient( OModule::ClientAccess )
      92             :     {
      93           6 :         ::osl::MutexGuard aGuard(m_aMutex);
      94           6 :         if ( 0 == osl_atomic_decrement( &m_nClients ) )
      95           4 :             onLastClient();
      96           6 :     }
      97             : 
      98             : 
      99           4 :     void OModule::onFirstClient()
     100             :     {
     101           4 :     }
     102             : 
     103             : 
     104           4 :     void OModule::onLastClient()
     105             :     {
     106           4 :     }
     107             : 
     108             : 
     109        4774 :     void OModule::registerImplementation( const ComponentDescription& _rComp )
     110             :     {
     111        4774 :         ::osl::MutexGuard aGuard( m_aMutex );
     112        4774 :         if ( !m_pImpl )
     113           0 :             throw RuntimeException();
     114             : 
     115        4774 :         m_pImpl->m_aRegisteredComponents.push_back( _rComp );
     116        4774 :     }
     117             : 
     118             : 
     119        3856 :     void OModule::registerImplementation( const OUString& _rImplementationName, const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames,
     120             :         ::cppu::ComponentFactoryFunc _pCreateFunction, FactoryInstantiation _pFactoryFunction )
     121             :     {
     122        3856 :         ComponentDescription aComponent( _rImplementationName, _rServiceNames, OUString(), _pCreateFunction, _pFactoryFunction );
     123        3856 :         registerImplementation( aComponent );
     124        3856 :     }
     125             : 
     126             : 
     127        1174 :     void* OModule::getComponentFactory( const sal_Char* _pImplementationName )
     128             :     {
     129             :         Reference< XInterface > xFactory( getComponentFactory(
     130        1174 :             OUString::createFromAscii( _pImplementationName ) ) );
     131        1174 :         return xFactory.get();
     132             :     }
     133             : 
     134             : 
     135        1292 :     Reference< XInterface > OModule::getComponentFactory( const OUString& _rImplementationName )
     136             :     {
     137        1292 :         Reference< XInterface > xReturn;
     138             : 
     139       22218 :         for (   ComponentDescriptions::const_iterator component = m_pImpl->m_aRegisteredComponents.begin();
     140       14812 :                 component != m_pImpl->m_aRegisteredComponents.end();
     141             :                 ++component
     142             :             )
     143             :         {
     144        7378 :             if ( component->sImplementationName == _rImplementationName )
     145             :             {
     146        6320 :                 xReturn = component->pFactoryCreationFunc(
     147        1264 :                     component->pComponentCreationFunc,
     148        1264 :                     component->sImplementationName,
     149        1264 :                     component->aSupportedServices,
     150             :                     NULL
     151        1264 :                 );
     152        1264 :                 if ( xReturn.is() )
     153             :                 {
     154        1264 :                     xReturn->acquire();
     155        1264 :                     return xReturn.get();
     156             :                 }
     157             :             }
     158             :         }
     159             : 
     160          28 :         return NULL;
     161             :     }
     162             : 
     163             : 
     164             : } // namespace comphelper
     165             : 
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10