diff options
author | Jan Holesovsky <kendy@suse.cz> | 2010-10-24 16:53:14 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2010-10-24 16:53:14 +0200 |
commit | fc9171c1442b359d7e806767e90a18c5d6ca2e7e (patch) | |
tree | 4794331a9c05fe2b05b2d1d201a3084e222f0280 /configmgr | |
parent | efaabab96ab8f6b1b866f26e7c4478b846ac4a1d (diff) | |
parent | ba640a3477213a4d2f179f188fe80029969ef1bb (diff) |
Merge commit 'ooo/OOO330_m12'
Conflicts:
desktop/source/app/app.cxx
Diffstat (limited to 'configmgr')
-rw-r--r-- | configmgr/source/components.cxx | 84 | ||||
-rw-r--r-- | configmgr/source/components.hxx | 8 | ||||
-rw-r--r-- | configmgr/source/configurationprovider.cxx | 16 |
3 files changed, 106 insertions, 2 deletions
diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index f76f020089ae..2e073207250e 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -30,6 +30,7 @@ #include "sal/config.h" #include <algorithm> +#include <cstddef> #include <list> #include "com/sun/star/beans/Optional.hpp" @@ -44,8 +45,11 @@ #include "com/sun/star/uno/RuntimeException.hpp" #include "com/sun/star/uno/XComponentContext.hpp" #include "com/sun/star/uno/XInterface.hpp" +#include "osl/conditn.hxx" #include "osl/diagnose.h" #include "osl/file.hxx" +#include "osl/mutex.hxx" +#include "osl/thread.hxx" #include "rtl/bootstrap.hxx" #include "rtl/logfile.h" #include "rtl/ref.hxx" @@ -54,10 +58,12 @@ #include "rtl/ustring.h" #include "rtl/ustring.hxx" #include "sal/types.h" +#include "salhelper/simplereferenceobject.hxx" #include "additions.hxx" #include "components.hxx" #include "data.hxx" +#include "lock.hxx" #include "modifications.hxx" #include "node.hxx" #include "nodemap.hxx" @@ -149,6 +155,66 @@ static Components * singleton = 0; } +class Components::WriteThread: + public osl::Thread, public salhelper::SimpleReferenceObject +{ +public: + static void * operator new(std::size_t size) + { return Thread::operator new(size); } + + static void operator delete(void * pointer) + { Thread::operator delete(pointer); } + + WriteThread( + rtl::Reference< WriteThread > * reference, Components & components, + rtl::OUString const & url, Data const & data); + + void flush() { delay_.set(); } + +private: + virtual ~WriteThread() {} + + virtual void SAL_CALL run(); + + virtual void SAL_CALL onTerminated() { release(); } + + rtl::Reference< WriteThread > * reference_; + Components & components_; + rtl::OUString url_; + Data const & data_; + osl::Condition delay_; +}; + +Components::WriteThread::WriteThread( + rtl::Reference< WriteThread > * reference, Components & components, + rtl::OUString const & url, Data const & data): + reference_(reference), components_(components), url_(url), data_(data) +{ + OSL_ASSERT(reference != 0); + acquire(); +} + +void Components::WriteThread::run() { + TimeValue t = { 1, 0 }; // 1 sec + delay_.wait(&t); // must not throw; result_error is harmless and ignored + osl::MutexGuard g(lock); // must not throw + try { + try { + writeModFile(components_, url_, data_); + } catch (css::uno::RuntimeException & e) { + // Silently ignore write errors, instead of aborting: + OSL_TRACE( + "configmgr error writing modifications: %s", + rtl::OUStringToOString( + e.Message, RTL_TEXTENCODING_UTF8).getStr()); + } + } catch (...) { + reference_->clear(); + throw; + } + reference_->clear(); +} + void Components::initSingleton( css::uno::Reference< css::uno::XComponentContext > const & context) { @@ -239,7 +305,23 @@ void Components::addModification(Path const & path) { } void Components::writeModifications() { - writeModFile(*this, getModificationFileUrl(), data_); + if (!writeThread_.is()) { + writeThread_ = new WriteThread( + &writeThread_, *this, getModificationFileUrl(), data_); + writeThread_->create(); + } +} + +void Components::flushModifications() { + rtl::Reference< WriteThread > thread; + { + osl::MutexGuard g(lock); + thread = writeThread_; + } + if (thread.is()) { + thread->flush(); + thread->join(); + } } void Components::insertExtensionXcsFile( diff --git a/configmgr/source/components.hxx b/configmgr/source/components.hxx index 4fc47f791821..1c735efca6ba 100644 --- a/configmgr/source/components.hxx +++ b/configmgr/source/components.hxx @@ -94,6 +94,11 @@ public: void writeModifications(); + void flushModifications(); + // must be called with configmgr::lock unaquired; must be called before + // shutdown if writeModifications has ever been called (probably + // indirectly, via removeExtensionXcuFile) + void insertExtensionXcsFile(bool shared, rtl::OUString const & fileUri); void insertExtensionXcuFile( @@ -160,11 +165,14 @@ private: com::sun::star::beans::XPropertySet > > ExternalServices; + class WriteThread; + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > context_; Data data_; WeakRootSet roots_; ExternalServices externalServices_; + rtl::Reference< WriteThread > writeThread_; }; } diff --git a/configmgr/source/configurationprovider.cxx b/configmgr/source/configurationprovider.cxx index 273a803716c0..ed50642994d9 100644 --- a/configmgr/source/configurationprovider.cxx +++ b/configmgr/source/configurationprovider.cxx @@ -115,6 +115,8 @@ public: private: virtual ~Service() {} + virtual void SAL_CALL disposing() { flushModifications(); } + virtual rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException) { return configuration_provider::getImplementationName(); } @@ -167,6 +169,8 @@ private: virtual css::lang::Locale SAL_CALL getLocale() throw (css::uno::RuntimeException); + void flushModifications() const; + css::uno::Reference< css::uno::XComponentContext > context_; rtl::OUString locale_; }; @@ -327,7 +331,7 @@ void Service::removeRefreshListener( } void Service::flush() throw (css::uno::RuntimeException) { - //TODO + flushModifications(); cppu::OInterfaceContainerHelper * cont = rBHelper.getContainer( cppu::UnoType< css::util::XFlushListener >::get()); if (cont != 0) { @@ -381,6 +385,16 @@ css::lang::Locale Service::getLocale() throw (css::uno::RuntimeException) { return loc; } +void Service::flushModifications() const { + Components * components; + { + osl::MutexGuard guard(lock); + Components::initSingleton(context_); + components = &Components::getSingleton(); + } + components->flushModifications(); +} + class Factory: public cppu::WeakImplHelper1< css::lang::XSingleComponentFactory >, private boost::noncopyable |