LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - facreg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 36 91.7 %
Date: 2015-06-13 12:38:46 Functions: 4 4 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             : #include <com/sun/star/registry/XRegistryKey.hpp>
      21             : 
      22             : #include "facreg.hxx"
      23             : #include "sddll.hxx"
      24             : 
      25             : #include <cppuhelper/factory.hxx>
      26             : #include <sfx2/sfxmodelfactory.hxx>
      27             : #include "osl/diagnose.h"
      28             : #include "sal/types.h"
      29             : 
      30             : #include <string.h>
      31             : #include <boost/shared_ptr.hpp>
      32             : #include <unordered_map>
      33             : 
      34             : using namespace com::sun::star;
      35             : 
      36             : // Declaration and initialization of a map from service names to locally
      37             : // unique factory identifiers.
      38             : 
      39             : enum FactoryId
      40             : {
      41             :     SdDrawingDocumentFactoryId,
      42             :     SdPresentationDocumentFactoryId,
      43             : 
      44             :     ModuleControllerFactoryId,
      45             : };
      46             : typedef std::unordered_map<OUString, FactoryId, OUStringHash> FactoryMap;
      47             : 
      48             : namespace {
      49          22 : static ::boost::shared_ptr<FactoryMap> spFactoryMap;
      50          25 : ::boost::shared_ptr<FactoryMap> GetFactoryMap()
      51             : {
      52          25 :     if (spFactoryMap.get() == NULL)
      53             :     {
      54          20 :         spFactoryMap.reset(new FactoryMap);
      55          20 :         (*spFactoryMap)[SdDrawingDocument_getImplementationName()] = SdDrawingDocumentFactoryId;
      56          20 :         (*spFactoryMap)[SdPresentationDocument_getImplementationName()] = SdPresentationDocumentFactoryId;
      57             :     }
      58          25 :     return spFactoryMap;
      59             : };
      60             : } // end of anonymous namespace
      61             : 
      62             : extern "C"
      63             : {
      64             : 
      65          25 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL sd_component_getFactory(
      66             :     const sal_Char * pImplName,
      67             :     void           * pServiceManager,
      68             :     void           *  )
      69             : {
      70          25 :     void * pRet = 0;
      71             : 
      72          25 :     if( pServiceManager )
      73             :     {
      74          25 :         uno::Reference< lang::XMultiServiceFactory > xMSF( static_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
      75             : 
      76          50 :         uno::Reference<lang::XSingleServiceFactory> xFactory;
      77          50 :         uno::Reference<lang::XSingleComponentFactory> xComponentFactory;
      78             : 
      79          50 :         ::boost::shared_ptr<FactoryMap> pFactoryMap (GetFactoryMap());
      80          50 :         OUString sImplementationName (OUString::createFromAscii(pImplName));
      81          25 :         FactoryMap::const_iterator iFactory (pFactoryMap->find(sImplementationName));
      82          25 :         if (iFactory != pFactoryMap->end())
      83             :         {
      84          25 :             switch (iFactory->second)
      85             :             {
      86             :                 case SdDrawingDocumentFactoryId:
      87          24 :                     xFactory = ::sfx2::createSfxModelFactory(
      88             :                         xMSF,
      89             :                         SdDrawingDocument_getImplementationName(),
      90             :                         SdDrawingDocument_createInstance,
      91          12 :                         SdDrawingDocument_getSupportedServiceNames());
      92          12 :                     break;
      93             : 
      94             :                 case SdPresentationDocumentFactoryId:
      95          26 :                     xFactory = ::sfx2::createSfxModelFactory(
      96             :                         xMSF,
      97             :                         SdPresentationDocument_getImplementationName(),
      98             :                         SdPresentationDocument_createInstance,
      99          13 :                         SdPresentationDocument_getSupportedServiceNames());
     100          13 :                     break;
     101             : 
     102             :                 default:
     103           0 :                     break;
     104             :             }
     105          25 :             if (xComponentFactory.is())
     106             :             {
     107           0 :                 xComponentFactory->acquire();
     108           0 :                 pRet = xComponentFactory.get();
     109             :             }
     110          25 :             else if (xFactory.is())
     111             :             {
     112          25 :                 xFactory->acquire();
     113          25 :                 pRet = xFactory.get();
     114             :             }
     115          25 :         }
     116             :     }
     117             : 
     118          25 :     if (pRet != NULL)
     119          25 :         SdDLL::Init();
     120          25 :     return pRet;
     121             : }
     122             : 
     123          66 : } // end of extern "C"
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11