LCOV - code coverage report
Current view: top level - dbaccess/source/shared - registrationhelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 48 50 96.0 %
Date: 2014-11-03 Functions: 6 6 100.0 %
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             : // be included in other cxx files
      21             : 
      22             : #ifndef _REGISTRATIONHELPER_CXX_INCLUDED_INDIRECTLY_
      23             : #error "don't build this file directly! use dbu_reghelper.cxx instead!"
      24             : #endif
      25             : 
      26             : using namespace ::com::sun::star;
      27             : using namespace ::comphelper;
      28             : using namespace ::cppu;
      29             : 
      30             : uno::Sequence< OUString >*                   OModuleRegistration::s_pImplementationNames = NULL;
      31             : uno::Sequence< uno::Sequence< OUString > >*  OModuleRegistration::s_pSupportedServices = NULL;
      32             : uno::Sequence< sal_Int64 >*                 OModuleRegistration::s_pCreationFunctionPointers = NULL;
      33             : uno::Sequence< sal_Int64 >*                 OModuleRegistration::s_pFactoryFunctionPointers = NULL;
      34             : 
      35         816 : void OModuleRegistration::registerComponent(
      36             :     const OUString& _rImplementationName,
      37             :     const uno::Sequence< OUString >& _rServiceNames,
      38             :     ComponentInstantiation _pCreateFunction,
      39             :     FactoryInstantiation _pFactoryFunction)
      40             : {
      41         816 :     if (!s_pImplementationNames)
      42             :     {
      43             :         OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
      44             :             "OModuleRegistration::registerComponent : inconsistent state (the pointers (1)) !");
      45          52 :         s_pImplementationNames = new uno::Sequence< OUString >;
      46          52 :         s_pSupportedServices = new uno::Sequence< uno::Sequence< OUString > >;
      47          52 :         s_pCreationFunctionPointers = new uno::Sequence< sal_Int64 >;
      48          52 :         s_pFactoryFunctionPointers = new uno::Sequence< sal_Int64 >;
      49             :     }
      50             :     OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
      51             :         "OModuleRegistration::registerComponent : inconsistent state (the pointers (2)) !");
      52             : 
      53             :     OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
      54             :                 &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
      55             :                 &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
      56             :         "OModuleRegistration::registerComponent : inconsistent state !");
      57             : 
      58         816 :     sal_Int32 nOldLen = s_pImplementationNames->getLength();
      59         816 :     s_pImplementationNames->realloc(nOldLen + 1);
      60         816 :     s_pSupportedServices->realloc(nOldLen + 1);
      61         816 :     s_pCreationFunctionPointers->realloc(nOldLen + 1);
      62         816 :     s_pFactoryFunctionPointers->realloc(nOldLen + 1);
      63             : 
      64         816 :     s_pImplementationNames->getArray()[nOldLen] = _rImplementationName;
      65         816 :     s_pSupportedServices->getArray()[nOldLen] = _rServiceNames;
      66         816 :     s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction);
      67         816 :     s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction);
      68         816 : }
      69             : 
      70         816 : void OModuleRegistration::revokeComponent(const OUString& _rImplementationName)
      71             : {
      72         816 :     if (!s_pImplementationNames)
      73             :     {
      74             :         OSL_FAIL("OModuleRegistration::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
      75         816 :         return;
      76             :     }
      77             :     OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
      78             :         "OModuleRegistration::revokeComponent : inconsistent state (the pointers) !");
      79             :     OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
      80             :                 &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
      81             :                 &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
      82             :         "OModuleRegistration::revokeComponent : inconsistent state !");
      83             : 
      84         816 :     sal_Int32 nLen = s_pImplementationNames->getLength();
      85         816 :     const OUString* pImplNames = s_pImplementationNames->getConstArray();
      86        9660 :     for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames)
      87             :     {
      88        9660 :         if (pImplNames->equals(_rImplementationName))
      89             :         {
      90         816 :             removeElementAt(*s_pImplementationNames, i);
      91         816 :             removeElementAt(*s_pSupportedServices, i);
      92         816 :             removeElementAt(*s_pCreationFunctionPointers, i);
      93         816 :             removeElementAt(*s_pFactoryFunctionPointers, i);
      94         816 :             break;
      95             :         }
      96             :     }
      97             : 
      98         816 :     if (s_pImplementationNames->getLength() == 0)
      99             :     {
     100          52 :         delete s_pImplementationNames; s_pImplementationNames = NULL;
     101          52 :         delete s_pSupportedServices; s_pSupportedServices = NULL;
     102          52 :         delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL;
     103          52 :         delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL;
     104             :     }
     105             : }
     106             : 
     107         118 : uno::Reference< uno::XInterface > OModuleRegistration::getComponentFactory(
     108             :     const OUString& _rImplementationName,
     109             :     const uno::Reference< lang::XMultiServiceFactory >& _rxServiceManager)
     110             : {
     111             :     OSL_ENSURE(_rxServiceManager.is(), "OModuleRegistration::getComponentFactory : invalid argument (service manager) !");
     112             :     OSL_ENSURE(!_rImplementationName.isEmpty(), "OModuleRegistration::getComponentFactory : invalid argument (implementation name) !");
     113             : 
     114         118 :     if (!s_pImplementationNames)
     115             :     {
     116             :         OSL_FAIL("OModuleRegistration::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
     117           0 :         return NULL;
     118             :     }
     119             :     OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
     120             :         "OModuleRegistration::getComponentFactory : inconsistent state (the pointers) !");
     121             :     OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
     122             :                 &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
     123             :                 &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
     124             :         "OModuleRegistration::getComponentFactory : inconsistent state !");
     125             : 
     126         118 :     uno::Reference< uno::XInterface > xReturn;
     127             : 
     128         118 :     sal_Int32 nLen = s_pImplementationNames->getLength();
     129         118 :     const OUString* pImplName = s_pImplementationNames->getConstArray();
     130         118 :     const uno::Sequence< OUString >* pServices = s_pSupportedServices->getConstArray();
     131         118 :     const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray();
     132         118 :     const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray();
     133             : 
     134         738 :     for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction)
     135             :     {
     136         738 :         if (pImplName->equals(_rImplementationName))
     137             :         {
     138         118 :             const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction);
     139         118 :             const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction);
     140             : 
     141         118 :             xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL);
     142         118 :             if (xReturn.is())
     143             :             {
     144         118 :                 return xReturn.get();
     145             :             }
     146             :         }
     147             :     }
     148             : 
     149           0 :     return NULL;
     150             : }
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10