LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/stoc/source/namingservice - namingservice.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 42 28.6 %
Date: 2013-07-09 Functions: 7 15 46.7 %
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             : 
      33             : #include <com/sun/star/uno/XNamingService.hpp>
      34             : #include <com/sun/star/lang/XServiceInfo.hpp>
      35             : 
      36             : using namespace cppu;
      37             : using namespace osl;
      38             : using namespace std;
      39             : 
      40             : using namespace com::sun::star::uno;
      41             : using namespace com::sun::star::lang;
      42             : using namespace com::sun::star::registry;
      43             : 
      44             : 
      45             : #define SERVICENAME "com.sun.star.uno.NamingService"
      46             : #define IMPLNAME    "com.sun.star.comp.stoc.NamingService"
      47             : 
      48             : namespace stoc_namingservice
      49             : {
      50             : 
      51           1 : static Sequence< OUString > ns_getSupportedServiceNames()
      52             : {
      53           1 :     Sequence< OUString > seqNames(1);
      54           1 :     seqNames.getArray()[0] = OUString(SERVICENAME);
      55           1 :     return seqNames;
      56             : }
      57             : 
      58           1 : static OUString ns_getImplementationName()
      59             : {
      60           1 :     return OUString(IMPLNAME);
      61             : }
      62             : 
      63             : struct equalOWString_Impl
      64             : {
      65           0 :   sal_Bool operator()(const OUString & s1, const OUString & s2) const
      66           0 :         { return s1 == s2; }
      67             : };
      68             : 
      69             : struct hashOWString_Impl
      70             : {
      71           0 :     size_t operator()(const OUString & rName) const
      72           0 :         { return rName.hashCode(); }
      73             : };
      74             : 
      75             : typedef boost::unordered_map
      76             : <
      77             :     OUString,
      78             :     Reference<XInterface >,
      79             :     hashOWString_Impl,
      80             :     equalOWString_Impl
      81             : > HashMap_OWString_Interface;
      82             : 
      83             : //==================================================================================================
      84             : class NamingService_Impl
      85             :     : public WeakImplHelper2 < XServiceInfo, XNamingService >
      86             : {
      87             :     Mutex                               aMutex;
      88             :     HashMap_OWString_Interface          aMap;
      89             : public:
      90             :     NamingService_Impl();
      91             :     ~NamingService_Impl();
      92             : 
      93             :     // XServiceInfo
      94             :     virtual OUString SAL_CALL getImplementationName()
      95             :     throw(::com::sun::star::uno::RuntimeException);
      96             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
      97             :     throw(::com::sun::star::uno::RuntimeException);
      98             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
      99             :     throw(::com::sun::star::uno::RuntimeException);
     100             :     static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static()
     101             :     {
     102             :         OUString aStr( OUString(SERVICENAME) );
     103             :         return Sequence< OUString >( &aStr, 1 );
     104             :     }
     105             : 
     106             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getRegisteredObject( const OUString& Name ) throw(Exception, RuntimeException);
     107             :     virtual void SAL_CALL registerObject( const OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Object ) throw(Exception, RuntimeException);
     108             :     virtual void SAL_CALL revokeObject( const OUString& Name ) throw(Exception, RuntimeException);
     109             : };
     110             : 
     111             : //==================================================================================================
     112           1 : static Reference<XInterface> SAL_CALL NamingService_Impl_create(
     113             :     SAL_UNUSED_PARAMETER const Reference<XComponentContext> & )
     114             : {
     115           1 :     return *new NamingService_Impl();
     116             : }
     117             : 
     118             : //==================================================================================================
     119           1 : NamingService_Impl::NamingService_Impl() {}
     120             : 
     121             : //==================================================================================================
     122           2 : NamingService_Impl::~NamingService_Impl() {}
     123             : 
     124             : // XServiceInfo
     125           0 : OUString NamingService_Impl::getImplementationName()
     126             :     throw(::com::sun::star::uno::RuntimeException)
     127             : {
     128           0 :     return ns_getImplementationName();
     129             : }
     130             : 
     131             : // XServiceInfo
     132           0 : sal_Bool NamingService_Impl::supportsService( const OUString & rServiceName )
     133             :     throw(::com::sun::star::uno::RuntimeException)
     134             : {
     135           0 :     const Sequence< OUString > & rSNL = getSupportedServiceNames();
     136           0 :     const OUString * pArray = rSNL.getConstArray();
     137           0 :     for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
     138             :     {
     139           0 :         if (pArray[nPos] == rServiceName)
     140           0 :             return sal_True;
     141             :     }
     142           0 :     return sal_False;
     143             : }
     144             : 
     145             : // XServiceInfo
     146           0 : Sequence< OUString > NamingService_Impl::getSupportedServiceNames()
     147             :     throw(::com::sun::star::uno::RuntimeException)
     148             : {
     149           0 :     return ns_getSupportedServiceNames();
     150             : }
     151             : 
     152             : // XServiceInfo
     153           0 : Reference< XInterface > NamingService_Impl::getRegisteredObject( const OUString& Name ) throw(Exception, RuntimeException)
     154             : {
     155           0 :     Guard< Mutex > aGuard( aMutex );
     156           0 :     Reference< XInterface > xRet;
     157           0 :     HashMap_OWString_Interface::iterator aIt = aMap.find( Name );
     158           0 :     if( aIt != aMap.end() )
     159           0 :         xRet = (*aIt).second;
     160           0 :     return xRet;
     161             : }
     162             : 
     163             : // XServiceInfo
     164           0 : void NamingService_Impl::registerObject( const OUString& Name, const Reference< XInterface >& Object ) throw(Exception, RuntimeException)
     165             : {
     166           0 :     Guard< Mutex > aGuard( aMutex );
     167           0 :     aMap[ Name ] = Object;
     168           0 : }
     169             : 
     170             : // XServiceInfo
     171           0 : void NamingService_Impl::revokeObject( const OUString& Name ) throw(Exception, RuntimeException)
     172             : {
     173           0 :     Guard< Mutex > aGuard( aMutex );
     174           0 :     aMap.erase( Name );
     175           0 : }
     176             : 
     177             : }
     178             : 
     179             : using namespace stoc_namingservice;
     180             : static struct ImplementationEntry g_entries[] =
     181             : {
     182             :     {
     183             :         NamingService_Impl_create, ns_getImplementationName,
     184             :         ns_getSupportedServiceNames, createSingleComponentFactory,
     185             :         0, 0
     186             :     },
     187             :     { 0, 0, 0, 0, 0, 0 }
     188             : };
     189             : 
     190           1 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL namingservice_component_getFactory(
     191             :     const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
     192             : {
     193           1 :     return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
     194             : }
     195             : 
     196             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10