LCOV - code coverage report
Current view: top level - forms/source/inc - forms_module_impl.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 51 0.0 %
Date: 2014-04-14 Functions: 0 3 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             : #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           0 :     void OFormsModule::registerComponent(
      56             :         const OUString& _rImplementationName,
      57             :         const Sequence< OUString >& _rServiceNames,
      58             :         ComponentInstantiation _pCreateFunction,
      59             :         FactoryInstantiation _pFactoryFunction)
      60             :     {
      61           0 :         if (!s_pImplementationNames)
      62             :         {
      63             :             OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
      64             :                 "OFormsModule::registerComponent : inconsistent state (the pointers (1)) !");
      65           0 :             s_pImplementationNames = new Sequence< OUString >;
      66           0 :             s_pSupportedServices = new Sequence< Sequence< OUString > >;
      67           0 :             s_pCreationFunctionPointers = new Sequence< sal_Int64 >;
      68           0 :             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           0 :         sal_Int32 nOldLen = s_pImplementationNames->getLength();
      79           0 :         s_pImplementationNames->realloc(nOldLen + 1);
      80           0 :         s_pSupportedServices->realloc(nOldLen + 1);
      81           0 :         s_pCreationFunctionPointers->realloc(nOldLen + 1);
      82           0 :         s_pFactoryFunctionPointers->realloc(nOldLen + 1);
      83             : 
      84           0 :         s_pImplementationNames->getArray()[nOldLen] = _rImplementationName;
      85           0 :         s_pSupportedServices->getArray()[nOldLen] = _rServiceNames;
      86           0 :         s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction);
      87           0 :         s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction);
      88           0 :     }
      89             : 
      90             : 
      91           0 :     void OFormsModule::revokeComponent(const OUString& _rImplementationName)
      92             :     {
      93           0 :         if (!s_pImplementationNames)
      94             :         {
      95             :             OSL_FAIL("OFormsModule::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
      96           0 :             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           0 :         sal_Int32 nLen = s_pImplementationNames->getLength();
     106           0 :         const OUString* pImplNames = s_pImplementationNames->getConstArray();
     107           0 :         for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames)
     108             :         {
     109           0 :             if (pImplNames->equals(_rImplementationName))
     110             :             {
     111           0 :                 removeElementAt(*s_pImplementationNames, i);
     112           0 :                 removeElementAt(*s_pSupportedServices, i);
     113           0 :                 removeElementAt(*s_pCreationFunctionPointers, i);
     114           0 :                 removeElementAt(*s_pFactoryFunctionPointers, i);
     115           0 :                 break;
     116             :             }
     117             :         }
     118             : 
     119           0 :         if (s_pImplementationNames->getLength() == 0)
     120             :         {
     121           0 :             delete s_pImplementationNames; s_pImplementationNames = NULL;
     122           0 :             delete s_pSupportedServices; s_pSupportedServices = NULL;
     123           0 :             delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL;
     124           0 :             delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL;
     125             :         }
     126             :     }
     127             : 
     128             : 
     129           0 :     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           0 :         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           0 :         Reference< XInterface > xReturn;
     150             : 
     151             : 
     152           0 :         sal_Int32 nLen = s_pImplementationNames->getLength();
     153           0 :         const OUString* pImplName = s_pImplementationNames->getConstArray();
     154           0 :         const Sequence< OUString >* pServices = s_pSupportedServices->getConstArray();
     155           0 :         const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray();
     156           0 :         const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray();
     157             : 
     158           0 :         for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction)
     159             :         {
     160           0 :             if (pImplName->equals(_rImplementationName))
     161             :             {
     162           0 :                 const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction);
     163           0 :                 const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction);
     164             : 
     165           0 :                 xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL);
     166           0 :                 if (xReturn.is())
     167             :                 {
     168           0 :                     xReturn->acquire();
     169           0 :                     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