LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/misc - componentmodule.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 51 68.6 %
Date: 2012-12-27 Functions: 8 13 61.5 %
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             :     /** === being UNO using === **/
      34             :     using ::com::sun::star::uno::Sequence;
      35             :     using ::com::sun::star::uno::RuntimeException;
      36             :     using ::com::sun::star::uno::Reference;
      37             :     using ::com::sun::star::lang::XMultiServiceFactory;
      38             :     using ::com::sun::star::registry::XRegistryKey;
      39             :     using ::com::sun::star::uno::Exception;
      40             :     using ::com::sun::star::uno::XInterface;
      41             :     /** === end UNO using === **/
      42             : 
      43             :     typedef ::std::vector< ComponentDescription >   ComponentDescriptions;
      44             : 
      45             :     //=========================================================================
      46             :     //= OModuleImpl
      47             :     //=========================================================================
      48             :     /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
      49             :     */
      50             :     class OModuleImpl
      51             :     {
      52             :     public:
      53             :         ComponentDescriptions                           m_aRegisteredComponents;
      54             : 
      55             :         OModuleImpl();
      56             :         ~OModuleImpl();
      57             :     };
      58             : 
      59             :     //-------------------------------------------------------------------------
      60          27 :     OModuleImpl::OModuleImpl()
      61             :     {
      62          27 :     }
      63             : 
      64             :     //-------------------------------------------------------------------------
      65          25 :     OModuleImpl::~OModuleImpl()
      66             :     {
      67          25 :     }
      68             : 
      69             :     //=========================================================================
      70             :     //= OModule
      71             :     //=========================================================================
      72             :     //-------------------------------------------------------------------------
      73          27 :     OModule::OModule()
      74             :         : m_nClients(0)
      75          27 :         , m_pImpl(new OModuleImpl)
      76             :     {
      77          27 :     }
      78             : 
      79          50 :     OModule::~OModule()
      80             :     {
      81          25 :         delete m_pImpl;
      82          25 :     }
      83             : 
      84             :     //-------------------------------------------------------------------------
      85           0 :     void OModule::registerClient( OModule::ClientAccess )
      86             :     {
      87           0 :         ::osl::MutexGuard aGuard(m_aMutex);
      88           0 :         if ( 1 == osl_atomic_increment( &m_nClients ) )
      89           0 :             onFirstClient();
      90           0 :     }
      91             : 
      92             :     //-------------------------------------------------------------------------
      93           0 :     void OModule::revokeClient( OModule::ClientAccess )
      94             :     {
      95           0 :         ::osl::MutexGuard aGuard(m_aMutex);
      96           0 :         if ( 0 == osl_atomic_decrement( &m_nClients ) )
      97           0 :             onLastClient();
      98           0 :     }
      99             : 
     100             :     //--------------------------------------------------------------------------
     101           0 :     void OModule::onFirstClient()
     102             :     {
     103           0 :     }
     104             : 
     105             :     //--------------------------------------------------------------------------
     106           0 :     void OModule::onLastClient()
     107             :     {
     108           0 :     }
     109             : 
     110             :     //--------------------------------------------------------------------------
     111         230 :     void OModule::registerImplementation( const ComponentDescription& _rComp )
     112             :     {
     113         230 :         ::osl::MutexGuard aGuard( m_aMutex );
     114         230 :         if ( !m_pImpl )
     115           0 :             throw RuntimeException();
     116             : 
     117         230 :         m_pImpl->m_aRegisteredComponents.push_back( _rComp );
     118         230 :     }
     119             : 
     120             :     //--------------------------------------------------------------------------
     121         186 :     void OModule::registerImplementation( const ::rtl::OUString& _rImplementationName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames,
     122             :         ::cppu::ComponentFactoryFunc _pCreateFunction, FactoryInstantiation _pFactoryFunction )
     123             :     {
     124         186 :         ComponentDescription aComponent( _rImplementationName, _rServiceNames, ::rtl::OUString(), _pCreateFunction, _pFactoryFunction );
     125         186 :         registerImplementation( aComponent );
     126         186 :     }
     127             : 
     128             :     //--------------------------------------------------------------------------
     129          73 :     void* OModule::getComponentFactory( const sal_Char* _pImplementationName )
     130             :     {
     131             :         Reference< XInterface > xFactory( getComponentFactory(
     132          73 :             ::rtl::OUString::createFromAscii( _pImplementationName ) ) );
     133          73 :         return xFactory.get();
     134             :     }
     135             : 
     136             :     //--------------------------------------------------------------------------
     137          75 :     Reference< XInterface > OModule::getComponentFactory( const ::rtl::OUString& _rImplementationName )
     138             :     {
     139          75 :         Reference< XInterface > xReturn;
     140             : 
     141        1038 :         for (   ComponentDescriptions::const_iterator component = m_pImpl->m_aRegisteredComponents.begin();
     142         692 :                 component != m_pImpl->m_aRegisteredComponents.end();
     143             :                 ++component
     144             :             )
     145             :         {
     146         346 :             if ( component->sImplementationName == _rImplementationName )
     147             :             {
     148          75 :                 xReturn = component->pFactoryCreationFunc(
     149          75 :                     component->pComponentCreationFunc,
     150          75 :                     component->sImplementationName,
     151          75 :                     component->aSupportedServices,
     152             :                     NULL
     153         300 :                 );
     154          75 :                 if ( xReturn.is() )
     155             :                 {
     156          75 :                     xReturn->acquire();
     157          75 :                     return xReturn.get();
     158             :                 }
     159             :             }
     160             :         }
     161             : 
     162           0 :         return NULL;
     163             :     }
     164             : 
     165             : //........................................................................
     166             : } // namespace comphelper
     167             : //........................................................................
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10