LCOV - code coverage report
Current view: top level - forms/source/inc - forms_module_impl.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 49 51 96.1 %
Date: 2014-11-03 Functions: 3 3 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             : #ifndef FORMS_MODULE_IMPLEMENTATION_INCLUDE_CONTEXT
      21             :     #error "not to be included directly! use 'foo_module.hxx instead'!"
      22             : #endif
      23             : 
      24             : #ifndef FORMS_MODULE_NAMESPACE
      25             :     #error "set FORMS_MODULE_NAMESPACE to your namespace identifier!"
      26             : #endif
      27             : 
      28             : #include <comphelper/sequence.hxx>
      29             : 
      30             : 
      31             : namespace FORMS_MODULE_NAMESPACE
      32             : {
      33             : 
      34             : 
      35             :     using namespace ::com::sun::star::uno;
      36             :     using namespace ::com::sun::star::lang;
      37             :     using namespace ::com::sun::star::registry;
      38             :     using namespace ::comphelper;
      39             :     using namespace ::cppu;
      40             : 
      41             : 
      42             :     //= OFormsModule
      43             : 
      44             : 
      45             : 
      46             :     //- registration helper
      47             : 
      48             : 
      49             :     Sequence< OUString >*                OFormsModule::s_pImplementationNames = NULL;
      50             :     Sequence< Sequence< OUString > >*    OFormsModule::s_pSupportedServices = NULL;
      51             :     Sequence< sal_Int64 >*                      OFormsModule::s_pCreationFunctionPointers = NULL;
      52             :     Sequence< sal_Int64 >*                      OFormsModule::s_pFactoryFunctionPointers = NULL;
      53             : 
      54             : 
      55         400 :     void OFormsModule::registerComponent(
      56             :         const OUString& _rImplementationName,
      57             :         const Sequence< OUString >& _rServiceNames,
      58             :         ComponentInstantiation _pCreateFunction,
      59             :         FactoryInstantiation _pFactoryFunction)
      60             :     {
      61         400 :         if (!s_pImplementationNames)
      62             :         {
      63             :             OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
      64             :                 "OFormsModule::registerComponent : inconsistent state (the pointers (1)) !");
      65          40 :             s_pImplementationNames = new Sequence< OUString >;
      66          40 :             s_pSupportedServices = new Sequence< Sequence< OUString > >;
      67          40 :             s_pCreationFunctionPointers = new Sequence< sal_Int64 >;
      68          40 :             s_pFactoryFunctionPointers = new Sequence< sal_Int64 >;
      69             :         }
      70             :         OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
      71             :             "OFormsModule::registerComponent : inconsistent state (the pointers (2)) !");
      72             : 
      73             :         OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
      74             :                     &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
      75             :                     &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
      76             :             "OFormsModule::registerComponent : inconsistent state !");
      77             : 
      78         400 :         sal_Int32 nOldLen = s_pImplementationNames->getLength();
      79         400 :         s_pImplementationNames->realloc(nOldLen + 1);
      80         400 :         s_pSupportedServices->realloc(nOldLen + 1);
      81         400 :         s_pCreationFunctionPointers->realloc(nOldLen + 1);
      82         400 :         s_pFactoryFunctionPointers->realloc(nOldLen + 1);
      83             : 
      84         400 :         s_pImplementationNames->getArray()[nOldLen] = _rImplementationName;
      85         400 :         s_pSupportedServices->getArray()[nOldLen] = _rServiceNames;
      86         400 :         s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction);
      87         400 :         s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction);
      88         400 :     }
      89             : 
      90             : 
      91         400 :     void OFormsModule::revokeComponent(const OUString& _rImplementationName)
      92             :     {
      93         400 :         if (!s_pImplementationNames)
      94             :         {
      95             :             OSL_FAIL("OFormsModule::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
      96         400 :             return;
      97             :         }
      98             :         OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
      99             :             "OFormsModule::revokeComponent : inconsistent state (the pointers) !");
     100             :         OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
     101             :                     &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
     102             :                     &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
     103             :             "OFormsModule::revokeComponent : inconsistent state !");
     104             : 
     105         400 :         sal_Int32 nLen = s_pImplementationNames->getLength();
     106         400 :         const OUString* pImplNames = s_pImplementationNames->getConstArray();
     107        2200 :         for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames)
     108             :         {
     109        2200 :             if (pImplNames->equals(_rImplementationName))
     110             :             {
     111         400 :                 removeElementAt(*s_pImplementationNames, i);
     112         400 :                 removeElementAt(*s_pSupportedServices, i);
     113         400 :                 removeElementAt(*s_pCreationFunctionPointers, i);
     114         400 :                 removeElementAt(*s_pFactoryFunctionPointers, i);
     115         400 :                 break;
     116             :             }
     117             :         }
     118             : 
     119         400 :         if (s_pImplementationNames->getLength() == 0)
     120             :         {
     121          40 :             delete s_pImplementationNames; s_pImplementationNames = NULL;
     122          40 :             delete s_pSupportedServices; s_pSupportedServices = NULL;
     123          40 :             delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL;
     124          40 :             delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL;
     125             :         }
     126             :     }
     127             : 
     128             : 
     129          90 :     Reference< XInterface > OFormsModule::getComponentFactory(
     130             :         const OUString& _rImplementationName,
     131             :         const Reference< XMultiServiceFactory >& _rxServiceManager)
     132             :     {
     133             :         OSL_ENSURE(_rxServiceManager.is(), "OFormsModule::getComponentFactory : invalid argument (service manager) !");
     134             :         OSL_ENSURE(!_rImplementationName.isEmpty(), "OFormsModule::getComponentFactory : invalid argument (implementation name) !");
     135             : 
     136          90 :         if (!s_pImplementationNames)
     137             :         {
     138             :             OSL_FAIL("OFormsModule::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
     139           0 :             return NULL;
     140             :         }
     141             :         OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
     142             :             "OFormsModule::getComponentFactory : inconsistent state (the pointers) !");
     143             :         OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
     144             :                     &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
     145             :                     &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
     146             :             "OFormsModule::getComponentFactory : inconsistent state !");
     147             : 
     148             : 
     149          90 :         Reference< XInterface > xReturn;
     150             : 
     151             : 
     152          90 :         sal_Int32 nLen = s_pImplementationNames->getLength();
     153          90 :         const OUString* pImplName = s_pImplementationNames->getConstArray();
     154          90 :         const Sequence< OUString >* pServices = s_pSupportedServices->getConstArray();
     155          90 :         const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray();
     156          90 :         const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray();
     157             : 
     158         408 :         for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction)
     159             :         {
     160         408 :             if (pImplName->equals(_rImplementationName))
     161             :             {
     162          90 :                 const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction);
     163          90 :                 const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction);
     164             : 
     165          90 :                 xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL);
     166          90 :                 if (xReturn.is())
     167             :                 {
     168          90 :                     xReturn->acquire();
     169          90 :                     return xReturn.get();
     170             :                 }
     171             :             }
     172             :         }
     173             : 
     174           0 :         return NULL;
     175             :     }
     176             : 
     177             : 
     178             : }   // namespace FORMS_MODULE_NAMESPACE
     179             : 
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10