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

Generated by: LCOV version 1.10