/src/libreoffice/configmgr/source/readwriteaccess.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
10 | | #include <sal/config.h> |
11 | | |
12 | | #include <com/sun/star/configuration/XReadWriteAccess.hpp> |
13 | | #include <com/sun/star/lang/IllegalArgumentException.hpp> |
14 | | #include <com/sun/star/lang/NotInitializedException.hpp> |
15 | | #include <com/sun/star/lang/XInitialization.hpp> |
16 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
17 | | #include <com/sun/star/uno/Any.hxx> |
18 | | #include <com/sun/star/uno/Reference.hxx> |
19 | | #include <com/sun/star/uno/RuntimeException.hpp> |
20 | | #include <com/sun/star/uno/Sequence.hxx> |
21 | | #include <com/sun/star/uno/XInterface.hpp> |
22 | | #include <cppuhelper/implbase.hxx> |
23 | | #include <cppuhelper/supportsservice.hxx> |
24 | | #include <cppuhelper/weak.hxx> |
25 | | #include <rtl/ref.hxx> |
26 | | #include <rtl/ustring.hxx> |
27 | | #include <mutex> |
28 | | #include <utility> |
29 | | #include <sal/types.h> |
30 | | |
31 | | #include "components.hxx" |
32 | | #include "lock.hxx" |
33 | | #include "rootaccess.hxx" |
34 | | |
35 | | namespace configmgr::read_write_access { |
36 | | |
37 | | namespace { |
38 | | |
39 | | class Service: |
40 | | public cppu::WeakImplHelper< |
41 | | css::lang::XServiceInfo, css::lang::XInitialization, |
42 | | css::configuration::XReadWriteAccess > |
43 | | { |
44 | | public: |
45 | | explicit Service( |
46 | | css::uno::Reference< css::uno::XComponentContext > context): |
47 | 7 | context_(std::move(context)) {} |
48 | | |
49 | | private: |
50 | | Service(const Service&) = delete; |
51 | | Service& operator=(const Service&) = delete; |
52 | | |
53 | 7 | virtual ~Service() override {} |
54 | | |
55 | | virtual OUString SAL_CALL getImplementationName() override |
56 | 0 | { return u"com.sun.star.comp.configuration.ReadWriteAccess"_ustr; } |
57 | | |
58 | | virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override |
59 | 0 | { return cppu::supportsService(this, ServiceName); } |
60 | | |
61 | | virtual css::uno::Sequence< OUString > SAL_CALL |
62 | | getSupportedServiceNames() override |
63 | 0 | { return { u"com.sun.star.configuration.ReadWriteAccess"_ustr }; } |
64 | | |
65 | | virtual void SAL_CALL initialize( |
66 | | css::uno::Sequence< css::uno::Any > const & aArguments) override; |
67 | | |
68 | | virtual css::uno::Any SAL_CALL getByHierarchicalName( |
69 | | OUString const & aName) override |
70 | 0 | { return getRoot()->getByHierarchicalName(aName); } |
71 | | |
72 | | virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName) override |
73 | 0 | { return getRoot()->hasByHierarchicalName(aName); } |
74 | | |
75 | | virtual void SAL_CALL replaceByHierarchicalName( |
76 | | OUString const & aName, css::uno::Any const & aElement) override |
77 | 0 | { getRoot()->replaceByHierarchicalName(aName, aElement); } |
78 | | |
79 | | virtual void SAL_CALL commitChanges() override |
80 | 0 | { getRoot()->commitChanges(); } |
81 | | |
82 | | virtual sal_Bool SAL_CALL hasPendingChanges() override |
83 | 0 | { return getRoot()->hasPendingChanges(); } |
84 | | |
85 | | virtual css::uno::Sequence< ::css::util::ElementChange > SAL_CALL getPendingChanges() override |
86 | 0 | { return getRoot()->getPendingChanges(); } |
87 | | |
88 | | css::beans::Property SAL_CALL getPropertyByHierarchicalName( |
89 | | OUString const & aHierarchicalName) |
90 | | override |
91 | 0 | { return getRoot()->getPropertyByHierarchicalName(aHierarchicalName); } |
92 | | |
93 | | sal_Bool SAL_CALL hasPropertyByHierarchicalName( |
94 | | OUString const & aHierarchicalName) override |
95 | 0 | { return getRoot()->hasPropertyByHierarchicalName(aHierarchicalName); } |
96 | | |
97 | | rtl::Reference< RootAccess > getRoot(); |
98 | | |
99 | | css::uno::Reference< css::uno::XComponentContext > context_; |
100 | | |
101 | | std::mutex mutex_; |
102 | | rtl::Reference< RootAccess > root_; |
103 | | }; |
104 | | |
105 | | void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments) |
106 | 7 | { |
107 | 7 | OUString locale; |
108 | 7 | if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) { |
109 | 0 | throw css::lang::IllegalArgumentException( |
110 | 0 | u"not exactly one string argument"_ustr, |
111 | 0 | getXWeak(), -1); |
112 | 0 | } |
113 | 7 | std::unique_lock g1(mutex_); |
114 | 7 | if (root_.is()) { |
115 | 0 | throw css::uno::RuntimeException( |
116 | 0 | u"already initialized"_ustr, getXWeak()); |
117 | 0 | } |
118 | 7 | osl::MutexGuard g2(*lock()); |
119 | 7 | Components & components = Components::getSingleton(context_); |
120 | 7 | root_ = new RootAccess(components, u"/"_ustr, locale, true); |
121 | 7 | components.addRootAccess(root_); |
122 | 7 | } |
123 | | |
124 | 0 | rtl::Reference< RootAccess > Service::getRoot() { |
125 | 0 | std::unique_lock g(mutex_); |
126 | 0 | if (!root_.is()) { |
127 | 0 | throw css::lang::NotInitializedException( |
128 | 0 | u"not initialized"_ustr, getXWeak()); |
129 | 0 | } |
130 | 0 | return root_; |
131 | 0 | } |
132 | | |
133 | | } |
134 | | } |
135 | | |
136 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
137 | | com_sun_star_comp_configuration_ReadWriteAccess_get_implementation( |
138 | | css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& ) |
139 | 7 | { |
140 | 7 | return cppu::acquire(new configmgr::read_write_access::Service(context)); |
141 | 7 | } |
142 | | |
143 | | |
144 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |