LCOV - code coverage report
Current view: top level - dbaccess/source/shared - registrationhelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 51 0.0 %
Date: 2014-04-14 Functions: 0 6 0.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           0 : void OModuleRegistration::registerComponent(
      36             :     const OUString& _rImplementationName,
      37             :     const uno::Sequence< OUString >& _rServiceNames,
      38             :     ComponentInstantiation _pCreateFunction,
      39             :     FactoryInstantiation _pFactoryFunction)
      40             : {
      41           0 :     if (!s_pImplementationNames)
      42             :     {
      43             :         OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
      44             :             "OModuleRegistration::registerComponent : inconsistent state (the pointers (1)) !");
      45           0 :         s_pImplementationNames = new uno::Sequence< OUString >;
      46           0 :         s_pSupportedServices = new uno::Sequence< uno::Sequence< OUString > >;
      47           0 :         s_pCreationFunctionPointers = new uno::Sequence< sal_Int64 >;
      48           0 :         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           0 :     sal_Int32 nOldLen = s_pImplementationNames->getLength();
      59           0 :     s_pImplementationNames->realloc(nOldLen + 1);
      60           0 :     s_pSupportedServices->realloc(nOldLen + 1);
      61           0 :     s_pCreationFunctionPointers->realloc(nOldLen + 1);
      62           0 :     s_pFactoryFunctionPointers->realloc(nOldLen + 1);
      63             : 
      64           0 :     s_pImplementationNames->getArray()[nOldLen] = _rImplementationName;
      65           0 :     s_pSupportedServices->getArray()[nOldLen] = _rServiceNames;
      66           0 :     s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction);
      67           0 :     s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction);
      68           0 : }
      69             : 
      70           0 : void OModuleRegistration::revokeComponent(const OUString& _rImplementationName)
      71             : {
      72           0 :     if (!s_pImplementationNames)
      73             :     {
      74             :         OSL_FAIL("OModuleRegistration::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
      75           0 :         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           0 :     sal_Int32 nLen = s_pImplementationNames->getLength();
      85           0 :     const OUString* pImplNames = s_pImplementationNames->getConstArray();
      86           0 :     for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames)
      87             :     {
      88           0 :         if (pImplNames->equals(_rImplementationName))
      89             :         {
      90           0 :             removeElementAt(*s_pImplementationNames, i);
      91           0 :             removeElementAt(*s_pSupportedServices, i);
      92           0 :             removeElementAt(*s_pCreationFunctionPointers, i);
      93           0 :             removeElementAt(*s_pFactoryFunctionPointers, i);
      94           0 :             break;
      95             :         }
      96             :     }
      97             : 
      98           0 :     if (s_pImplementationNames->getLength() == 0)
      99             :     {
     100           0 :         delete s_pImplementationNames; s_pImplementationNames = NULL;
     101           0 :         delete s_pSupportedServices; s_pSupportedServices = NULL;
     102           0 :         delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL;
     103           0 :         delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL;
     104             :     }
     105             : }
     106             : 
     107           0 : 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           0 :     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           0 :     uno::Reference< uno::XInterface > xReturn;
     127             : 
     128           0 :     sal_Int32 nLen = s_pImplementationNames->getLength();
     129           0 :     const OUString* pImplName = s_pImplementationNames->getConstArray();
     130           0 :     const uno::Sequence< OUString >* pServices = s_pSupportedServices->getConstArray();
     131           0 :     const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray();
     132           0 :     const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray();
     133             : 
     134           0 :     for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction)
     135             :     {
     136           0 :         if (pImplName->equals(_rImplementationName))
     137             :         {
     138           0 :             const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction);
     139           0 :             const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction);
     140             : 
     141           0 :             xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL);
     142           0 :             if (xReturn.is())
     143             :             {
     144           0 :                 xReturn->acquire();
     145           0 :                 return xReturn.get();
     146             :             }
     147             :         }
     148             :     }
     149             : 
     150           0 :     return NULL;
     151             : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10