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

Generated by: LCOV version 1.10