Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / stoc / source / namingservice / namingservice.cxx
blobacabb7370c6b97d67224ece67afb111e1126eda0
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 <cppuhelper/factory.hxx>
22 #include <cppuhelper/implbase.hxx>
23 #include <cppuhelper/supportsservice.hxx>
25 #include <com/sun/star/uno/XNamingService.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <mutex>
29 #include <unordered_map>
31 using namespace cppu;
32 using namespace osl;
34 using namespace css::uno;
35 using namespace css::lang;
36 using namespace css::registry;
39 namespace stoc_namingservice
42 typedef std::unordered_map< OUString, Reference<XInterface > > HashMap_OWString_Interface;
44 namespace {
46 class NamingService_Impl
47 : public WeakImplHelper < XServiceInfo, XNamingService >
49 std::mutex aMutex;
50 HashMap_OWString_Interface aMap;
51 public:
52 NamingService_Impl();
54 // XServiceInfo
55 virtual OUString SAL_CALL getImplementationName() override;
56 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
57 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
59 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRegisteredObject( const OUString& Name ) override;
60 virtual void SAL_CALL registerObject( const OUString& Name, const css::uno::Reference< css::uno::XInterface >& Object ) override;
61 virtual void SAL_CALL revokeObject( const OUString& Name ) override;
68 NamingService_Impl::NamingService_Impl() {}
70 // XServiceInfo
71 OUString NamingService_Impl::getImplementationName()
73 return "com.sun.star.comp.stoc.NamingService";
76 // XServiceInfo
77 sal_Bool NamingService_Impl::supportsService( const OUString & rServiceName )
79 return cppu::supportsService(this, rServiceName);
82 // XServiceInfo
83 Sequence< OUString > NamingService_Impl::getSupportedServiceNames()
85 return { "com.sun.star.uno.NamingService" };
88 // XServiceInfo
89 Reference< XInterface > NamingService_Impl::getRegisteredObject( const OUString& Name )
91 std::scoped_lock aGuard( aMutex );
92 Reference< XInterface > xRet;
93 HashMap_OWString_Interface::iterator aIt = aMap.find( Name );
94 if( aIt != aMap.end() )
95 xRet = (*aIt).second;
96 return xRet;
99 // XServiceInfo
100 void NamingService_Impl::registerObject( const OUString& Name, const Reference< XInterface >& Object )
102 std::scoped_lock aGuard( aMutex );
103 aMap[ Name ] = Object;
106 // XServiceInfo
107 void NamingService_Impl::revokeObject( const OUString& Name )
109 std::scoped_lock aGuard( aMutex );
110 aMap.erase( Name );
115 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
116 stoc_NamingService_Impl_get_implementation(
117 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
119 return cppu::acquire(new stoc_namingservice::NamingService_Impl());
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */