bump product version to 6.4.0.3
[LibreOffice.git] / stoc / source / namingservice / namingservice.cxx
blob8b35ec58b3c549ac2c06d3c6f61dfd93c87cf69a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <osl/mutex.hxx>
22 #include <cppuhelper/factory.hxx>
23 #include <cppuhelper/implbase.hxx>
24 #include <cppuhelper/implementationentry.hxx>
25 #include <cppuhelper/supportsservice.hxx>
27 #include <com/sun/star/uno/XNamingService.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <unordered_map>
32 using namespace cppu;
33 using namespace osl;
34 using namespace std;
36 using namespace css::uno;
37 using namespace css::lang;
38 using namespace css::registry;
41 #define SERVICENAME "com.sun.star.uno.NamingService"
42 #define IMPLNAME "com.sun.star.comp.stoc.NamingService"
44 namespace stoc_namingservice
47 static Sequence< OUString > ns_getSupportedServiceNames()
49 Sequence< OUString > seqNames { SERVICENAME };
50 return seqNames;
53 static OUString ns_getImplementationName()
55 return IMPLNAME;
58 typedef std::unordered_map< OUString, Reference<XInterface > > HashMap_OWString_Interface;
61 class NamingService_Impl
62 : public WeakImplHelper < XServiceInfo, XNamingService >
64 Mutex aMutex;
65 HashMap_OWString_Interface aMap;
66 public:
67 NamingService_Impl();
69 // XServiceInfo
70 virtual OUString SAL_CALL getImplementationName() override;
71 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
72 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
74 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRegisteredObject( const OUString& Name ) override;
75 virtual void SAL_CALL registerObject( const OUString& Name, const css::uno::Reference< css::uno::XInterface >& Object ) override;
76 virtual void SAL_CALL revokeObject( const OUString& Name ) override;
80 static Reference<XInterface> NamingService_Impl_create(
81 SAL_UNUSED_PARAMETER const Reference<XComponentContext> & )
83 return *new NamingService_Impl();
87 NamingService_Impl::NamingService_Impl() {}
89 // XServiceInfo
90 OUString NamingService_Impl::getImplementationName()
92 return ns_getImplementationName();
95 // XServiceInfo
96 sal_Bool NamingService_Impl::supportsService( const OUString & rServiceName )
98 return cppu::supportsService(this, rServiceName);
101 // XServiceInfo
102 Sequence< OUString > NamingService_Impl::getSupportedServiceNames()
104 return ns_getSupportedServiceNames();
107 // XServiceInfo
108 Reference< XInterface > NamingService_Impl::getRegisteredObject( const OUString& Name )
110 Guard< Mutex > aGuard( aMutex );
111 Reference< XInterface > xRet;
112 HashMap_OWString_Interface::iterator aIt = aMap.find( Name );
113 if( aIt != aMap.end() )
114 xRet = (*aIt).second;
115 return xRet;
118 // XServiceInfo
119 void NamingService_Impl::registerObject( const OUString& Name, const Reference< XInterface >& Object )
121 Guard< Mutex > aGuard( aMutex );
122 aMap[ Name ] = Object;
125 // XServiceInfo
126 void NamingService_Impl::revokeObject( const OUString& Name )
128 Guard< Mutex > aGuard( aMutex );
129 aMap.erase( Name );
134 using namespace stoc_namingservice;
135 static const struct ImplementationEntry g_entries[] =
138 NamingService_Impl_create, ns_getImplementationName,
139 ns_getSupportedServiceNames, createSingleComponentFactory,
140 nullptr, 0
142 { nullptr, nullptr, nullptr, nullptr, nullptr, 0 }
145 extern "C" SAL_DLLPUBLIC_EXPORT void * namingservice_component_getFactory(
146 const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
148 return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */