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