1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 #include <unordered_map>
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
;
46 class NamingService_Impl
47 : public WeakImplHelper
< XServiceInfo
, XNamingService
>
50 HashMap_OWString_Interface aMap
;
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() {}
71 OUString
NamingService_Impl::getImplementationName()
73 return "com.sun.star.comp.stoc.NamingService";
77 sal_Bool
NamingService_Impl::supportsService( const OUString
& rServiceName
)
79 return cppu::supportsService(this, rServiceName
);
83 Sequence
< OUString
> NamingService_Impl::getSupportedServiceNames()
85 return { "com.sun.star.uno.NamingService" };
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() )
100 void NamingService_Impl::registerObject( const OUString
& Name
, const Reference
< XInterface
>& Object
)
102 std::scoped_lock
aGuard( aMutex
);
103 aMap
[ Name
] = Object
;
107 void NamingService_Impl::revokeObject( const OUString
& Name
)
109 std::scoped_lock
aGuard( aMutex
);
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: */