LibreOffice Module stoc (master) 1
namingservice.cxx
Go to the documentation of this file.
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
24
25#include <com/sun/star/uno/XNamingService.hpp>
26#include <com/sun/star/lang/XServiceInfo.hpp>
27
28#include <mutex>
29#include <unordered_map>
30
31using namespace cppu;
32using namespace osl;
33
34using namespace css::uno;
35using namespace css::lang;
36using namespace css::registry;
37
38
40{
41
42typedef std::unordered_map< OUString, Reference<XInterface > > HashMap_OWString_Interface;
43
44namespace {
45
46class NamingService_Impl
47 : public WeakImplHelper < XServiceInfo, XNamingService >
48{
49 std::mutex aMutex;
51public:
52 NamingService_Impl();
53
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;
58
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;
62};
63
64}
65
66
67
68NamingService_Impl::NamingService_Impl() {}
69
70// XServiceInfo
71OUString NamingService_Impl::getImplementationName()
72{
73 return "com.sun.star.comp.stoc.NamingService";
74}
75
76// XServiceInfo
77sal_Bool NamingService_Impl::supportsService( const OUString & rServiceName )
78{
79 return cppu::supportsService(this, rServiceName);
80}
81
82// XServiceInfo
83Sequence< OUString > NamingService_Impl::getSupportedServiceNames()
84{
85 return { "com.sun.star.uno.NamingService" };
86}
87
88// XServiceInfo
89Reference< XInterface > NamingService_Impl::getRegisteredObject( const OUString& Name )
90{
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;
97}
98
99// XServiceInfo
100void NamingService_Impl::registerObject( const OUString& Name, const Reference< XInterface >& Object )
101{
102 std::scoped_lock aGuard( aMutex );
103 aMap[ Name ] = Object;
104}
105
106// XServiceInfo
107void NamingService_Impl::revokeObject( const OUString& Name )
108{
109 std::scoped_lock aGuard( aMutex );
110 aMap.erase( Name );
111}
112
113}
114
115extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
117 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
118{
119 return cppu::acquire(new stoc_namingservice::NamingService_Impl());
120}
121
122
123/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::unordered_map< OUString, Reference< XInterface > > HashMap_OWString_Interface
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stoc_NamingService_Impl_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
HashMap_OWString_Interface aMap
std::mutex aMutex
OUString Name
unsigned char sal_Bool