LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/shared - registrationhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 51 0.0 %
Date: 2012-12-27 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< ::rtl::OUString >*                   OModuleRegistration::s_pImplementationNames = NULL;
      31             : uno::Sequence< uno::Sequence< ::rtl::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             : //--------------------------------------------------------------------------
      36           0 : void OModuleRegistration::registerComponent(
      37             :     const ::rtl::OUString& _rImplementationName,
      38             :     const uno::Sequence< ::rtl::OUString >& _rServiceNames,
      39             :     ComponentInstantiation _pCreateFunction,
      40             :     FactoryInstantiation _pFactoryFunction)
      41             : {
      42           0 :     if (!s_pImplementationNames)
      43             :     {
      44             :         OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
      45             :             "OModuleRegistration::registerComponent : inconsistent state (the pointers (1)) !");
      46           0 :         s_pImplementationNames = new uno::Sequence< ::rtl::OUString >;
      47           0 :         s_pSupportedServices = new uno::Sequence< uno::Sequence< ::rtl::OUString > >;
      48           0 :         s_pCreationFunctionPointers = new uno::Sequence< sal_Int64 >;
      49           0 :         s_pFactoryFunctionPointers = new uno::Sequence< sal_Int64 >;
      50             :     }
      51             :     OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
      52             :         "OModuleRegistration::registerComponent : inconsistent state (the pointers (2)) !");
      53             : 
      54             :     OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
      55             :                 &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
      56             :                 &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
      57             :         "OModuleRegistration::registerComponent : inconsistent state !");
      58             : 
      59           0 :     sal_Int32 nOldLen = s_pImplementationNames->getLength();
      60           0 :     s_pImplementationNames->realloc(nOldLen + 1);
      61           0 :     s_pSupportedServices->realloc(nOldLen + 1);
      62           0 :     s_pCreationFunctionPointers->realloc(nOldLen + 1);
      63           0 :     s_pFactoryFunctionPointers->realloc(nOldLen + 1);
      64             : 
      65           0 :     s_pImplementationNames->getArray()[nOldLen] = _rImplementationName;
      66           0 :     s_pSupportedServices->getArray()[nOldLen] = _rServiceNames;
      67           0 :     s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction);
      68           0 :     s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction);
      69           0 : }
      70             : 
      71             : //--------------------------------------------------------------------------
      72           0 : void OModuleRegistration::revokeComponent(const ::rtl::OUString& _rImplementationName)
      73             : {
      74           0 :     if (!s_pImplementationNames)
      75             :     {
      76             :         OSL_FAIL("OModuleRegistration::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
      77           0 :         return;
      78             :     }
      79             :     OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
      80             :         "OModuleRegistration::revokeComponent : inconsistent state (the pointers) !");
      81             :     OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
      82             :                 &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
      83             :                 &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
      84             :         "OModuleRegistration::revokeComponent : inconsistent state !");
      85             : 
      86           0 :     sal_Int32 nLen = s_pImplementationNames->getLength();
      87           0 :     const ::rtl::OUString* pImplNames = s_pImplementationNames->getConstArray();
      88           0 :     for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames)
      89             :     {
      90           0 :         if (pImplNames->equals(_rImplementationName))
      91             :         {
      92           0 :             removeElementAt(*s_pImplementationNames, i);
      93           0 :             removeElementAt(*s_pSupportedServices, i);
      94           0 :             removeElementAt(*s_pCreationFunctionPointers, i);
      95           0 :             removeElementAt(*s_pFactoryFunctionPointers, i);
      96           0 :             break;
      97             :         }
      98             :     }
      99             : 
     100           0 :     if (s_pImplementationNames->getLength() == 0)
     101             :     {
     102           0 :         delete s_pImplementationNames; s_pImplementationNames = NULL;
     103           0 :         delete s_pSupportedServices; s_pSupportedServices = NULL;
     104           0 :         delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL;
     105           0 :         delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL;
     106             :     }
     107             : }
     108             : 
     109             : //--------------------------------------------------------------------------
     110           0 : uno::Reference< uno::XInterface > OModuleRegistration::getComponentFactory(
     111             :     const ::rtl::OUString& _rImplementationName,
     112             :     const uno::Reference< lang::XMultiServiceFactory >& _rxServiceManager)
     113             : {
     114             :     OSL_ENSURE(_rxServiceManager.is(), "OModuleRegistration::getComponentFactory : invalid argument (service manager) !");
     115             :     OSL_ENSURE(!_rImplementationName.isEmpty(), "OModuleRegistration::getComponentFactory : invalid argument (implementation name) !");
     116             : 
     117           0 :     if (!s_pImplementationNames)
     118             :     {
     119             :         OSL_FAIL("OModuleRegistration::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
     120           0 :         return NULL;
     121             :     }
     122             :     OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
     123             :         "OModuleRegistration::getComponentFactory : inconsistent state (the pointers) !");
     124             :     OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
     125             :                 &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
     126             :                 &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
     127             :         "OModuleRegistration::getComponentFactory : inconsistent state !");
     128             : 
     129             : 
     130           0 :     uno::Reference< uno::XInterface > xReturn;
     131             : 
     132             : 
     133           0 :     sal_Int32 nLen = s_pImplementationNames->getLength();
     134           0 :     const ::rtl::OUString* pImplName = s_pImplementationNames->getConstArray();
     135           0 :     const uno::Sequence< ::rtl::OUString >* pServices = s_pSupportedServices->getConstArray();
     136           0 :     const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray();
     137           0 :     const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray();
     138             : 
     139           0 :     for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction)
     140             :     {
     141           0 :         if (pImplName->equals(_rImplementationName))
     142             :         {
     143           0 :             const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction);
     144           0 :             const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction);
     145             : 
     146           0 :             xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL);
     147           0 :             if (xReturn.is())
     148             :             {
     149           0 :                 xReturn->acquire();
     150           0 :                 return xReturn.get();
     151             :             }
     152             :         }
     153             :     }
     154             : 
     155           0 :     return NULL;
     156             : }
     157             : 
     158             : 
     159             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10