xref: /aoo42x/main/configmgr/source/update.cxx (revision 3a7cf181)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_configmgr.hxx"
25 #include "sal/config.h"
26 
27 #include <set>
28 
29 #include "boost/noncopyable.hpp"
30 #include "com/sun/star/configuration/XUpdate.hpp"
31 #include "com/sun/star/uno/Reference.hxx"
32 #include "com/sun/star/uno/RuntimeException.hpp"
33 #include "com/sun/star/uno/Sequence.hxx"
34 #include "com/sun/star/uno/XComponentContext.hpp"
35 #include "com/sun/star/uno/XInterface.hpp"
36 #include "cppuhelper/implbase1.hxx"
37 #include "cppuhelper/weak.hxx"
38 #include "osl/mutex.hxx"
39 #include "rtl/ref.hxx"
40 #include "rtl/ustring.h"
41 #include "rtl/ustring.hxx"
42 #include "sal/types.h"
43 
44 #include "broadcaster.hxx"
45 #include "components.hxx"
46 #include "lock.hxx"
47 #include "modifications.hxx"
48 #include "rootaccess.hxx"
49 #include "update.hxx"
50 
51 namespace configmgr { namespace update {
52 
53 namespace {
54 
55 namespace css = com::sun::star;
56 
seqToSet(css::uno::Sequence<rtl::OUString> const & sequence)57 std::set< rtl::OUString > seqToSet(
58     css::uno::Sequence< rtl::OUString > const & sequence)
59 {
60     return std::set< rtl::OUString >(
61         sequence.getConstArray(),
62         sequence.getConstArray() + sequence.getLength());
63 }
64 
65 class Service:
66     public cppu::WeakImplHelper1< css::configuration::XUpdate >,
67     private boost::noncopyable
68 {
69 public:
Service(css::uno::Reference<css::uno::XComponentContext> const context)70     Service(css::uno::Reference< css::uno::XComponentContext > const context):
71         context_(context)
72     {
73         OSL_ASSERT(context.is());
74     }
75 
76 private:
~Service()77     virtual ~Service() {}
78 
79     virtual void SAL_CALL insertExtensionXcsFile(
80         sal_Bool shared, rtl::OUString const & fileUri)
81         throw (css::uno::RuntimeException);
82 
83     virtual void SAL_CALL insertExtensionXcuFile(
84         sal_Bool shared, rtl::OUString const & fileUri)
85         throw (css::uno::RuntimeException);
86 
87     virtual void SAL_CALL removeExtensionXcuFile(rtl::OUString const & fileUri)
88         throw (css::uno::RuntimeException);
89 
90     virtual void SAL_CALL insertModificationXcuFile(
91         rtl::OUString const & fileUri,
92         css::uno::Sequence< rtl::OUString > const & includedPaths,
93         css::uno::Sequence< rtl::OUString > const & excludedPaths)
94         throw (css::uno::RuntimeException);
95 
96     css::uno::Reference< css::uno::XComponentContext > context_;
97 };
98 
insertExtensionXcsFile(sal_Bool shared,rtl::OUString const & fileUri)99 void Service::insertExtensionXcsFile(
100     sal_Bool shared, rtl::OUString const & fileUri)
101     throw (css::uno::RuntimeException)
102 {
103     osl::MutexGuard g(lock);
104     Components::getSingleton(context_).insertExtensionXcsFile(shared, fileUri);
105 }
106 
insertExtensionXcuFile(sal_Bool shared,rtl::OUString const & fileUri)107 void Service::insertExtensionXcuFile(
108     sal_Bool shared, rtl::OUString const & fileUri)
109     throw (css::uno::RuntimeException)
110 {
111     Broadcaster bc;
112     {
113         osl::MutexGuard g(lock);
114         Components & components = Components::getSingleton(context_);
115         Modifications mods;
116         components.insertExtensionXcuFile(shared, fileUri, &mods);
117         components.initGlobalBroadcaster(
118             mods, rtl::Reference< RootAccess >(), &bc);
119     }
120     bc.send();
121 }
122 
removeExtensionXcuFile(rtl::OUString const & fileUri)123 void Service::removeExtensionXcuFile(rtl::OUString const & fileUri)
124     throw (css::uno::RuntimeException)
125 {
126     Broadcaster bc;
127     {
128         osl::MutexGuard g(lock);
129         Components & components = Components::getSingleton(context_);
130         Modifications mods;
131         components.removeExtensionXcuFile(fileUri, &mods);
132         components.initGlobalBroadcaster(
133             mods, rtl::Reference< RootAccess >(), &bc);
134     }
135     bc.send();
136 }
137 
insertModificationXcuFile(rtl::OUString const & fileUri,css::uno::Sequence<rtl::OUString> const & includedPaths,css::uno::Sequence<rtl::OUString> const & excludedPaths)138 void Service::insertModificationXcuFile(
139     rtl::OUString const & fileUri,
140     css::uno::Sequence< rtl::OUString > const & includedPaths,
141     css::uno::Sequence< rtl::OUString > const & excludedPaths)
142     throw (css::uno::RuntimeException)
143 {
144     Broadcaster bc;
145     {
146         osl::MutexGuard g(lock);
147         Components & components = Components::getSingleton(context_);
148         Modifications mods;
149         components.insertModificationXcuFile(
150             fileUri, seqToSet(includedPaths), seqToSet(excludedPaths), &mods);
151         components.initGlobalBroadcaster(
152             mods, rtl::Reference< RootAccess >(), &bc);
153     }
154     bc.send();
155 }
156 
157 }
158 
create(css::uno::Reference<css::uno::XComponentContext> const & context)159 css::uno::Reference< css::uno::XInterface > create(
160     css::uno::Reference< css::uno::XComponentContext > const & context)
161 {
162     return static_cast< cppu::OWeakObject * >(new Service(context));
163 }
164 
getImplementationName()165 rtl::OUString getImplementationName() {
166     return rtl::OUString(
167         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.configuration.Update"));
168 }
169 
getSupportedServiceNames()170 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
171     rtl::OUString name(
172         RTL_CONSTASCII_USTRINGPARAM(
173             "com.sun.star.configuration.Update_Service"));
174     return css::uno::Sequence< rtl::OUString >(&name, 1);
175 }
176 
177 } }
178