Line data Source code
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 : #include <sal/config.h>
21 :
22 : #include <cassert>
23 : #include <memory>
24 : #include <set>
25 :
26 : #include <com/sun/star/configuration/XUpdate.hpp>
27 : #include <com/sun/star/uno/Reference.hxx>
28 : #include <com/sun/star/uno/RuntimeException.hpp>
29 : #include <com/sun/star/uno/Sequence.hxx>
30 : #include <com/sun/star/uno/XComponentContext.hpp>
31 : #include <com/sun/star/uno/XInterface.hpp>
32 : #include <cppuhelper/implbase1.hxx>
33 : #include <cppuhelper/weak.hxx>
34 : #include <osl/mutex.hxx>
35 : #include <rtl/ref.hxx>
36 : #include <rtl/ustring.h>
37 : #include <rtl/ustring.hxx>
38 : #include <sal/types.h>
39 :
40 : #include "broadcaster.hxx"
41 : #include "components.hxx"
42 : #include "lock.hxx"
43 : #include "modifications.hxx"
44 : #include "rootaccess.hxx"
45 : #include "update.hxx"
46 :
47 : namespace configmgr { namespace update {
48 :
49 : namespace {
50 :
51 0 : std::set< OUString > seqToSet(
52 : css::uno::Sequence< OUString > const & sequence)
53 : {
54 : return std::set< OUString >(
55 : sequence.getConstArray(),
56 0 : sequence.getConstArray() + sequence.getLength());
57 : }
58 :
59 : class Service:
60 : public cppu::WeakImplHelper1< css::configuration::XUpdate >
61 : {
62 : public:
63 0 : explicit Service(css::uno::Reference< css::uno::XComponentContext > const context):
64 0 : context_(context)
65 : {
66 : assert(context.is());
67 0 : lock_ = lock();
68 0 : }
69 :
70 : private:
71 : Service(const Service&) SAL_DELETED_FUNCTION;
72 : Service& operator=(const Service&) SAL_DELETED_FUNCTION;
73 :
74 0 : virtual ~Service() {}
75 :
76 : virtual void SAL_CALL insertExtensionXcsFile(
77 : sal_Bool shared, OUString const & fileUri)
78 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
79 :
80 : virtual void SAL_CALL insertExtensionXcuFile(
81 : sal_Bool shared, OUString const & fileUri)
82 : throw (css::uno::RuntimeException,
83 : std::exception) SAL_OVERRIDE;
84 :
85 : virtual void SAL_CALL removeExtensionXcuFile(OUString const & fileUri)
86 : throw (css::uno::RuntimeException,
87 : std::exception) SAL_OVERRIDE;
88 :
89 : virtual void SAL_CALL insertModificationXcuFile(
90 : OUString const & fileUri,
91 : css::uno::Sequence< OUString > const & includedPaths,
92 : css::uno::Sequence< OUString > const & excludedPaths)
93 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
94 :
95 : std::shared_ptr<osl::Mutex> lock_;
96 : css::uno::Reference< css::uno::XComponentContext > context_;
97 : };
98 :
99 0 : void Service::insertExtensionXcsFile(
100 : sal_Bool shared, OUString const & fileUri)
101 : throw (css::uno::RuntimeException, std::exception)
102 : {
103 0 : osl::MutexGuard g(*lock_);
104 0 : Components::getSingleton(context_).insertExtensionXcsFile(shared, fileUri);
105 0 : }
106 :
107 0 : void Service::insertExtensionXcuFile(
108 : sal_Bool shared, OUString const & fileUri)
109 : throw (css::uno::RuntimeException,
110 : std::exception)
111 : {
112 0 : Broadcaster bc;
113 : {
114 0 : osl::MutexGuard g(*lock_);
115 0 : Components & components = Components::getSingleton(context_);
116 0 : Modifications mods;
117 0 : components.insertExtensionXcuFile(shared, fileUri, &mods);
118 : components.initGlobalBroadcaster(
119 0 : mods, rtl::Reference< RootAccess >(), &bc);
120 : }
121 0 : bc.send();
122 0 : }
123 :
124 0 : void Service::removeExtensionXcuFile(OUString const & fileUri)
125 : throw (css::uno::RuntimeException, std::exception)
126 : {
127 0 : Broadcaster bc;
128 : {
129 0 : osl::MutexGuard g(*lock_);
130 0 : Components & components = Components::getSingleton(context_);
131 0 : Modifications mods;
132 0 : components.removeExtensionXcuFile(fileUri, &mods);
133 : components.initGlobalBroadcaster(
134 0 : mods, rtl::Reference< RootAccess >(), &bc);
135 : }
136 0 : bc.send();
137 0 : }
138 :
139 0 : void Service::insertModificationXcuFile(
140 : OUString const & fileUri,
141 : css::uno::Sequence< OUString > const & includedPaths,
142 : css::uno::Sequence< OUString > const & excludedPaths)
143 : throw (css::uno::RuntimeException, std::exception)
144 : {
145 0 : Broadcaster bc;
146 : {
147 0 : osl::MutexGuard g(*lock_);
148 0 : Components & components = Components::getSingleton(context_);
149 0 : Modifications mods;
150 : components.insertModificationXcuFile(
151 0 : fileUri, seqToSet(includedPaths), seqToSet(excludedPaths), &mods);
152 : components.initGlobalBroadcaster(
153 0 : mods, rtl::Reference< RootAccess >(), &bc);
154 : }
155 0 : bc.send();
156 0 : }
157 :
158 : }
159 :
160 0 : css::uno::Reference< css::uno::XInterface > create(
161 : css::uno::Reference< css::uno::XComponentContext > const & context)
162 : {
163 0 : return static_cast< cppu::OWeakObject * >(new Service(context));
164 : }
165 :
166 686 : OUString getImplementationName() {
167 686 : return OUString("com.sun.star.comp.configuration.Update");
168 : }
169 :
170 0 : css::uno::Sequence< OUString > getSupportedServiceNames() {
171 0 : OUString name("com.sun.star.configuration.Update_Service");
172 0 : return css::uno::Sequence< OUString >(&name, 1);
173 : }
174 :
175 : } }
176 :
177 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|