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

Generated by: LCOV version 1.10