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 <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>
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
};
53 static OUString
ns_getImplementationName()
58 typedef std::unordered_map
< OUString
, Reference
<XInterface
> > HashMap_OWString_Interface
;
61 class NamingService_Impl
62 : public WeakImplHelper
< XServiceInfo
, XNamingService
>
65 HashMap_OWString_Interface aMap
;
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() {}
90 OUString
NamingService_Impl::getImplementationName()
92 return ns_getImplementationName();
96 sal_Bool
NamingService_Impl::supportsService( const OUString
& rServiceName
)
98 return cppu::supportsService(this, rServiceName
);
102 Sequence
< OUString
> NamingService_Impl::getSupportedServiceNames()
104 return ns_getSupportedServiceNames();
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
;
119 void NamingService_Impl::registerObject( const OUString
& Name
, const Reference
< XInterface
>& Object
)
121 Guard
< Mutex
> aGuard( aMutex
);
122 aMap
[ Name
] = Object
;
126 void NamingService_Impl::revokeObject( const OUString
& Name
)
128 Guard
< Mutex
> aGuard( aMutex
);
134 using namespace stoc_namingservice
;
135 static const struct ImplementationEntry g_entries
[] =
138 NamingService_Impl_create
, ns_getImplementationName
,
139 ns_getSupportedServiceNames
, createSingleComponentFactory
,
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: */