LCOV - code coverage report
Current view: top level - stoc/source/namingservice - namingservice.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 16 33 48.5 %
Date: 2015-06-13 12:38:46 Functions: 9 13 69.2 %
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             : 
      21             : #include <osl/mutex.hxx>
      22             : #include <osl/diagnose.h>
      23             : #include <uno/dispatcher.h>
      24             : #include <uno/mapping.hxx>
      25             : #include <cppuhelper/queryinterface.hxx>
      26             : #include <cppuhelper/weak.hxx>
      27             : #include <cppuhelper/factory.hxx>
      28             : #include <cppuhelper/component.hxx>
      29             : #include <cppuhelper/implbase2.hxx>
      30             : #include <cppuhelper/implementationentry.hxx>
      31             : #include <cppuhelper/supportsservice.hxx>
      32             : 
      33             : #include <com/sun/star/uno/XNamingService.hpp>
      34             : #include <com/sun/star/lang/XServiceInfo.hpp>
      35             : 
      36             : #include <unordered_map>
      37             : 
      38             : using namespace cppu;
      39             : using namespace osl;
      40             : using namespace std;
      41             : 
      42             : using namespace css::uno;
      43             : using namespace css::lang;
      44             : using namespace css::registry;
      45             : 
      46             : 
      47             : #define SERVICENAME "com.sun.star.uno.NamingService"
      48             : #define IMPLNAME    "com.sun.star.comp.stoc.NamingService"
      49             : 
      50             : namespace stoc_namingservice
      51             : {
      52             : 
      53           3 : static Sequence< OUString > ns_getSupportedServiceNames()
      54             : {
      55           3 :     Sequence< OUString > seqNames(1);
      56           3 :     seqNames.getArray()[0] = SERVICENAME;
      57           3 :     return seqNames;
      58             : }
      59             : 
      60           3 : static OUString ns_getImplementationName()
      61             : {
      62           3 :     return OUString(IMPLNAME);
      63             : }
      64             : 
      65             : typedef std::unordered_map
      66             : <
      67             :     OUString,
      68             :     Reference<XInterface >,
      69             :     OUStringHash
      70             : > HashMap_OWString_Interface;
      71             : 
      72             : 
      73             : class NamingService_Impl
      74             :     : public WeakImplHelper2 < XServiceInfo, XNamingService >
      75             : {
      76             :     Mutex                               aMutex;
      77             :     HashMap_OWString_Interface          aMap;
      78             : public:
      79             :     NamingService_Impl();
      80             :     virtual ~NamingService_Impl();
      81             : 
      82             :     // XServiceInfo
      83             :     virtual OUString SAL_CALL getImplementationName()
      84             :     throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      85             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
      86             :     throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      87             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
      88             :     throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      89             : 
      90             :     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRegisteredObject( const OUString& Name ) throw(Exception, RuntimeException, std::exception) SAL_OVERRIDE;
      91             :     virtual void SAL_CALL registerObject( const OUString& Name, const css::uno::Reference< css::uno::XInterface >& Object ) throw(Exception, RuntimeException, std::exception) SAL_OVERRIDE;
      92             :     virtual void SAL_CALL revokeObject( const OUString& Name ) throw(Exception, RuntimeException, std::exception) SAL_OVERRIDE;
      93             : };
      94             : 
      95             : 
      96           2 : static Reference<XInterface> SAL_CALL NamingService_Impl_create(
      97             :     SAL_UNUSED_PARAMETER const Reference<XComponentContext> & )
      98             : {
      99           2 :     return *new NamingService_Impl();
     100             : }
     101             : 
     102             : 
     103           2 : NamingService_Impl::NamingService_Impl() {}
     104             : 
     105             : 
     106           4 : NamingService_Impl::~NamingService_Impl() {}
     107             : 
     108             : // XServiceInfo
     109           1 : OUString NamingService_Impl::getImplementationName()
     110             :     throw(css::uno::RuntimeException, std::exception)
     111             : {
     112           1 :     return ns_getImplementationName();
     113             : }
     114             : 
     115             : // XServiceInfo
     116           0 : sal_Bool NamingService_Impl::supportsService( const OUString & rServiceName )
     117             :     throw(css::uno::RuntimeException, std::exception)
     118             : {
     119           0 :     return cppu::supportsService(this, rServiceName);
     120             : }
     121             : 
     122             : // XServiceInfo
     123           1 : Sequence< OUString > NamingService_Impl::getSupportedServiceNames()
     124             :     throw(css::uno::RuntimeException, std::exception)
     125             : {
     126           1 :     return ns_getSupportedServiceNames();
     127             : }
     128             : 
     129             : // XServiceInfo
     130           0 : Reference< XInterface > NamingService_Impl::getRegisteredObject( const OUString& Name ) throw(Exception, RuntimeException, std::exception)
     131             : {
     132           0 :     Guard< Mutex > aGuard( aMutex );
     133           0 :     Reference< XInterface > xRet;
     134           0 :     HashMap_OWString_Interface::iterator aIt = aMap.find( Name );
     135           0 :     if( aIt != aMap.end() )
     136           0 :         xRet = (*aIt).second;
     137           0 :     return xRet;
     138             : }
     139             : 
     140             : // XServiceInfo
     141           0 : void NamingService_Impl::registerObject( const OUString& Name, const Reference< XInterface >& Object ) throw(Exception, RuntimeException, std::exception)
     142             : {
     143           0 :     Guard< Mutex > aGuard( aMutex );
     144           0 :     aMap[ Name ] = Object;
     145           0 : }
     146             : 
     147             : // XServiceInfo
     148           0 : void NamingService_Impl::revokeObject( const OUString& Name ) throw(Exception, RuntimeException, std::exception)
     149             : {
     150           0 :     Guard< Mutex > aGuard( aMutex );
     151           0 :     aMap.erase( Name );
     152           0 : }
     153             : 
     154             : }
     155             : 
     156             : using namespace stoc_namingservice;
     157             : static const struct ImplementationEntry g_entries[] =
     158             : {
     159             :     {
     160             :         NamingService_Impl_create, ns_getImplementationName,
     161             :         ns_getSupportedServiceNames, createSingleComponentFactory,
     162             :         0, 0
     163             :     },
     164             :     { 0, 0, 0, 0, 0, 0 }
     165             : };
     166             : 
     167           2 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL namingservice_component_getFactory(
     168             :     const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
     169             : {
     170           2 :     return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
     171             : }
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11