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 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: 70 Service(css::uno::Reference< css::uno::XComponentContext > const context): 71 context_(context) 72 { 73 OSL_ASSERT(context.is()); 74 } 75 76 private: 77 virtual ~Service() {} 78 79 virtual void SAL_CALL insertExtensionXcsFile( 80 sal_Bool shared, rtl::OUString const & fileUri); 81 82 virtual void SAL_CALL insertExtensionXcuFile( 83 sal_Bool shared, rtl::OUString const & fileUri); 84 85 virtual void SAL_CALL removeExtensionXcuFile(rtl::OUString const & fileUri); 86 87 virtual void SAL_CALL insertModificationXcuFile( 88 rtl::OUString const & fileUri, 89 css::uno::Sequence< rtl::OUString > const & includedPaths, 90 css::uno::Sequence< rtl::OUString > const & excludedPaths); 91 92 css::uno::Reference< css::uno::XComponentContext > context_; 93 }; 94 95 void Service::insertExtensionXcsFile( 96 sal_Bool shared, rtl::OUString const & fileUri) 97 { 98 osl::MutexGuard g(lock); 99 Components::getSingleton(context_).insertExtensionXcsFile(shared, fileUri); 100 } 101 102 void Service::insertExtensionXcuFile( 103 sal_Bool shared, rtl::OUString const & fileUri) 104 { 105 Broadcaster bc; 106 { 107 osl::MutexGuard g(lock); 108 Components & components = Components::getSingleton(context_); 109 Modifications mods; 110 components.insertExtensionXcuFile(shared, fileUri, &mods); 111 components.initGlobalBroadcaster( 112 mods, rtl::Reference< RootAccess >(), &bc); 113 } 114 bc.send(); 115 } 116 117 void Service::removeExtensionXcuFile(rtl::OUString const & fileUri) 118 { 119 Broadcaster bc; 120 { 121 osl::MutexGuard g(lock); 122 Components & components = Components::getSingleton(context_); 123 Modifications mods; 124 components.removeExtensionXcuFile(fileUri, &mods); 125 components.initGlobalBroadcaster( 126 mods, rtl::Reference< RootAccess >(), &bc); 127 } 128 bc.send(); 129 } 130 131 void Service::insertModificationXcuFile( 132 rtl::OUString const & fileUri, 133 css::uno::Sequence< rtl::OUString > const & includedPaths, 134 css::uno::Sequence< rtl::OUString > const & excludedPaths) 135 { 136 Broadcaster bc; 137 { 138 osl::MutexGuard g(lock); 139 Components & components = Components::getSingleton(context_); 140 Modifications mods; 141 components.insertModificationXcuFile( 142 fileUri, seqToSet(includedPaths), seqToSet(excludedPaths), &mods); 143 components.initGlobalBroadcaster( 144 mods, rtl::Reference< RootAccess >(), &bc); 145 } 146 bc.send(); 147 } 148 149 } 150 151 css::uno::Reference< css::uno::XInterface > create( 152 css::uno::Reference< css::uno::XComponentContext > const & context) 153 { 154 return static_cast< cppu::OWeakObject * >(new Service(context)); 155 } 156 157 rtl::OUString getImplementationName() { 158 return rtl::OUString( 159 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.configuration.Update")); 160 } 161 162 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() { 163 rtl::OUString name( 164 RTL_CONSTASCII_USTRINGPARAM( 165 "com.sun.star.configuration.Update_Service")); 166 return css::uno::Sequence< rtl::OUString >(&name, 1); 167 } 168 169 } } 170