LCOV - code coverage report
Current view: top level - connectivity/source/drivers/firebird - Services.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 19 26 73.1 %
Date: 2014-04-11 Functions: 5 6 83.3 %
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 "Driver.hxx"
      21             : 
      22             : #include <cppuhelper/factory.hxx>
      23             : #include <osl/diagnose.h>
      24             : #include <sal/types.h>
      25             : 
      26             : using namespace connectivity::firebird;
      27             : using ::rtl::OUString;
      28             : using ::com::sun::star::uno::Reference;
      29             : using ::com::sun::star::uno::Sequence;
      30             : using ::com::sun::star::registry::XRegistryKey;
      31             : using ::com::sun::star::lang::XSingleServiceFactory;
      32             : using ::com::sun::star::lang::XMultiServiceFactory;
      33             : 
      34             : typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
      35             :         (
      36             :             const Reference< XMultiServiceFactory > & rServiceManager,
      37             :             const OUString & rComponentName,
      38             :             ::cppu::ComponentInstantiation pCreateFunction,
      39             :             const Sequence< OUString > & rServiceNames,
      40             :             rtl_ModuleCount* _pTemp
      41             :         );
      42             : 
      43             : 
      44             : 
      45             : // The required C-Api must be provided!
      46             : // It contains of 3 special functions that have to be exported.
      47             : 
      48             : 
      49             : 
      50           0 : void REGISTER_PROVIDER(
      51             :         const OUString& aServiceImplName,
      52             :         const Sequence< OUString>& Services,
      53             :         const Reference< ::com::sun::star::registry::XRegistryKey > & xKey)
      54             : {
      55           0 :     OUString aMainKeyName = "/" + aServiceImplName + "/UNO/SERVICES";
      56             : 
      57           0 :     Reference< ::com::sun::star::registry::XRegistryKey >  xNewKey( xKey->createKey(aMainKeyName) );
      58             :     OSL_ENSURE(xNewKey.is(), "FIREBIRD::component_writeInfo : could not create a registry key !");
      59             : 
      60           0 :     for (sal_Int32 i=0; i<Services.getLength(); ++i)
      61           0 :         xNewKey->createKey(Services[i]);
      62           0 : }
      63             : 
      64             : 
      65             : 
      66           1 : struct ProviderRequest
      67             : {
      68             :     Reference< XSingleServiceFactory > xRet;
      69             :     Reference< XMultiServiceFactory > const xServiceManager;
      70             :     OUString const sImplementationName;
      71             : 
      72           1 :     ProviderRequest(
      73             :         void* pServiceManager,
      74             :         sal_Char const* pImplementationName
      75             :     )
      76             :     : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
      77           1 :     , sImplementationName(OUString::createFromAscii(pImplementationName))
      78             :     {
      79           1 :     }
      80             : 
      81             :     inline
      82           1 :     sal_Bool CREATE_PROVIDER(
      83             :                 const OUString& Implname,
      84             :                 const Sequence< OUString > & Services,
      85             :                 ::cppu::ComponentInstantiation Factory,
      86             :                 createFactoryFunc creator
      87             :             )
      88             :     {
      89           1 :         if (!xRet.is() && (Implname == sImplementationName))
      90             :         {
      91             :             try
      92             :             {
      93           1 :                 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
      94             :             }
      95           0 :             catch(...)
      96             :             {
      97             :             }
      98             :         }
      99           1 :         return xRet.is();
     100             :     }
     101             : 
     102           1 :     void* getProvider() const { return xRet.get(); }
     103             : };
     104             : 
     105             : 
     106           1 : extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL firebird_sdbc_component_getFactory(
     107             :                     const sal_Char* pImplementationName,
     108             :                     void* pServiceManager,
     109             :                     void* pRegistryKey)
     110             : {
     111             :     (void) pRegistryKey;
     112           1 :     void* pRet = 0;
     113           1 :     if (pServiceManager)
     114             :     {
     115           1 :         ProviderRequest aReq(pServiceManager,pImplementationName);
     116             : 
     117             :         aReq.CREATE_PROVIDER(
     118             :             FirebirdDriver::getImplementationName_Static(),
     119             :             FirebirdDriver::getSupportedServiceNames_Static(),
     120           2 :             FirebirdDriver_CreateInstance, ::cppu::createSingleFactory)
     121           1 :         ;
     122             : 
     123           1 :         if(aReq.xRet.is())
     124           1 :             aReq.xRet->acquire();
     125             : 
     126           1 :         pRet = aReq.getProvider();
     127             :     }
     128             : 
     129           1 :     return pRet;
     130             : };
     131             : 
     132             : 
     133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10