LCOV - code coverage report
Current view: top level - comphelper/source/misc - componentmodule.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 50 51 98.0 %
Date: 2015-06-13 12:38:46 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             :     /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by its owner
      44             :     */
      45             :     class OModuleImpl
      46             :     {
      47             :     public:
      48             :         ComponentDescriptions                           m_aRegisteredComponents;
      49             : 
      50             :         OModuleImpl();
      51             :         ~OModuleImpl();
      52             :     };
      53             : 
      54             : 
      55         227 :     OModuleImpl::OModuleImpl()
      56             :     {
      57         227 :     }
      58             : 
      59             : 
      60         204 :     OModuleImpl::~OModuleImpl()
      61             :     {
      62         204 :     }
      63             : 
      64         227 :     OModule::OModule()
      65             :         : m_nClients(0)
      66         227 :         , m_pImpl(new OModuleImpl)
      67             :     {
      68         227 :     }
      69             : 
      70         408 :     OModule::~OModule()
      71             :     {
      72         204 :         delete m_pImpl;
      73         204 :     }
      74             : 
      75             : 
      76          72 :     void OModule::registerClient( OModule::ClientAccess )
      77             :     {
      78          72 :         ::osl::MutexGuard aGuard(m_aMutex);
      79          72 :         if ( 1 == osl_atomic_increment( &m_nClients ) )
      80           2 :             onFirstClient();
      81          72 :     }
      82             : 
      83             : 
      84          72 :     void OModule::revokeClient( OModule::ClientAccess )
      85             :     {
      86          72 :         ::osl::MutexGuard aGuard(m_aMutex);
      87          72 :         if ( 0 == osl_atomic_decrement( &m_nClients ) )
      88           2 :             onLastClient();
      89          72 :     }
      90             : 
      91             : 
      92           2 :     void OModule::onFirstClient()
      93             :     {
      94           2 :     }
      95             : 
      96             : 
      97           2 :     void OModule::onLastClient()
      98             :     {
      99           2 :     }
     100             : 
     101             : 
     102        2880 :     void OModule::registerImplementation( const ComponentDescription& _rComp )
     103             :     {
     104        2880 :         ::osl::MutexGuard aGuard( m_aMutex );
     105        2880 :         if ( !m_pImpl )
     106           0 :             throw RuntimeException();
     107             : 
     108        2880 :         m_pImpl->m_aRegisteredComponents.push_back( _rComp );
     109        2880 :     }
     110             : 
     111             : 
     112        2274 :     void OModule::registerImplementation( const OUString& _rImplementationName, const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames,
     113             :         ::cppu::ComponentFactoryFunc _pCreateFunction, FactoryInstantiation _pFactoryFunction )
     114             :     {
     115        2274 :         ComponentDescription aComponent( _rImplementationName, _rServiceNames, OUString(), _pCreateFunction, _pFactoryFunction );
     116        2274 :         registerImplementation( aComponent );
     117        2274 :     }
     118             : 
     119             : 
     120         632 :     void* OModule::getComponentFactory( const sal_Char* _pImplementationName )
     121             :     {
     122             :         Reference< XInterface > xFactory( getComponentFactory(
     123         632 :             OUString::createFromAscii( _pImplementationName ) ) );
     124         632 :         return xFactory.get();
     125             :     }
     126             : 
     127             : 
     128         698 :     Reference< XInterface > OModule::getComponentFactory( const OUString& _rImplementationName )
     129             :     {
     130         698 :         Reference< XInterface > xReturn;
     131             : 
     132       14295 :         for (   ComponentDescriptions::const_iterator component = m_pImpl->m_aRegisteredComponents.begin();
     133        9530 :                 component != m_pImpl->m_aRegisteredComponents.end();
     134             :                 ++component
     135             :             )
     136             :         {
     137        4745 :             if ( component->sImplementationName == _rImplementationName )
     138             :             {
     139        3390 :                 xReturn = component->pFactoryCreationFunc(
     140         678 :                     component->pComponentCreationFunc,
     141         678 :                     component->sImplementationName,
     142         678 :                     component->aSupportedServices,
     143             :                     NULL
     144         678 :                 );
     145         678 :                 if ( xReturn.is() )
     146             :                 {
     147         678 :                     xReturn->acquire();
     148         678 :                     return xReturn.get();
     149             :                 }
     150             :             }
     151             :         }
     152             : 
     153          20 :         return NULL;
     154             :     }
     155             : 
     156             : 
     157             : } // namespace comphelper
     158             : 
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11