1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dp_gui_updatability.cxx,v $
10 * $Revision: 1.6.86.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_desktop.hxx"
34 #include "sal/config.h"
38 #include "com/sun/star/deployment/DeploymentException.hpp"
39 #include "com/sun/star/deployment/UpdateInformationProvider.hpp"
40 #include "com/sun/star/deployment/XPackage.hpp"
41 #include "com/sun/star/deployment/XPackageManager.hpp"
42 #include "com/sun/star/deployment/XUpdateInformationProvider.hpp"
43 #include "com/sun/star/task/XAbortChannel.hpp"
44 #include "com/sun/star/ucb/CommandAbortedException.hpp"
45 #include "com/sun/star/ucb/CommandFailedException.hpp"
46 #include "com/sun/star/ucb/XCommandEnvironment.hpp"
47 #include "com/sun/star/uno/Reference.hxx"
48 #include "com/sun/star/uno/RuntimeException.hpp"
49 #include "com/sun/star/uno/Sequence.hxx"
50 #include "com/sun/star/uno/XInterface.hpp"
51 #include "osl/conditn.hxx"
52 #include "osl/diagnose.h"
53 #include "osl/mutex.hxx"
54 #include "rtl/ref.hxx"
55 #include "rtl/ustring.h"
56 #include "rtl/ustring.hxx"
57 #include "sal/types.h"
58 #include "vcl/svapp.hxx"
59 #include "vcl/window.hxx"
60 #include "vos/mutex.hxx"
63 #include "dp_gui_thread.hxx"
64 #include "dp_gui_updatability.hxx"
66 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{
67 class XComponentContext
;
70 using dp_gui::Updatability
;
74 namespace css
= com::sun::star
;
78 class Updatability::Thread
: public dp_gui::Thread
{
81 css::uno::Sequence
< css::uno::Reference
<
82 css::deployment::XPackageManager
> > const & packageManagers
,
90 Thread(Thread
&); // not defined
91 void operator =(Thread
&); // not defined
95 virtual void execute();
97 enum Input
{ NONE
, START
, STOP
};
99 bool m_predeterminedUpdateUrl
;
100 css::uno::Sequence
< css::uno::Reference
<
101 css::deployment::XPackageManager
> > m_packageManagers
;
103 osl::Condition m_wakeup
;
107 css::uno::Reference
< css::task::XAbortChannel
> m_abort
;
110 Updatability::Thread::Thread(
111 css::uno::Sequence
< css::uno::Reference
<
112 css::deployment::XPackageManager
> > const & packageManagers
,
114 m_predeterminedUpdateUrl(dp_misc::getExtensionDefaultUpdateURL().getLength() > 0),
115 m_packageManagers(packageManagers
),
120 void Updatability::Thread::start() {
121 css::uno::Reference
< css::task::XAbortChannel
> abort
;
123 osl::MutexGuard
g(m_mutex
);
134 void Updatability::Thread::stop() {
135 css::uno::Reference
< css::task::XAbortChannel
> abort
;
137 vos::OGuard
g1(Application::GetSolarMutex());
138 osl::MutexGuard
g2(m_mutex
);
150 Updatability::Thread::~Thread() {}
152 void Updatability::Thread::execute() {
155 if (m_wakeup
.wait() != osl::Condition::result_ok
) {
156 dp_misc::TRACE("dp_gui::Updatability::Thread::run: ignored \n");
157 dp_misc::TRACE("osl::Condition::wait failure\n");
162 osl::MutexGuard
g(m_mutex
);
173 bool enabled
= false;
174 for (sal_Int32 i
= 0; !enabled
&& i
< m_packageManagers
.getLength();
177 css::uno::Reference
< css::task::XAbortChannel
> abort(
178 m_packageManagers
[i
]->createAbortChannel());
180 osl::MutexGuard
g(m_mutex
);
184 //In case input would be STOP then we would later break out of the loop
185 //before further calls to the XPackageManger are done. That is, the abort
186 //channel would not be used anyway.
194 css::uno::Reference
< css::deployment::XPackage
> > ps
;
196 ps
= m_packageManagers
[i
]->getDeployedPackages(
198 css::uno::Reference
< css::ucb::XCommandEnvironment
>());
199 } catch (css::deployment::DeploymentException
&) {
200 // If there are any problematic package managers, enable the
201 // update button and let the update process report any problems
205 } catch (css::ucb::CommandFailedException
&) {
206 throw css::uno::RuntimeException(
208 RTL_CONSTASCII_USTRINGPARAM(
209 "CommandFailedException: cannot happen")),
210 css::uno::Reference
< css::uno::XInterface
>());
211 } catch (css::ucb::CommandAbortedException
&) {
212 osl::MutexGuard
g(m_mutex
);
215 OSL_ASSERT(input
!= NONE
);
217 } catch (css::lang::IllegalArgumentException
&) {
218 throw css::uno::RuntimeException(
220 RTL_CONSTASCII_USTRINGPARAM(
221 "IllegalArgumentException: cannot happen")),
222 css::uno::Reference
< css::uno::XInterface
>());
224 if (m_predeterminedUpdateUrl
&& ps
.getLength() != 0) {
227 for (sal_Int32 j
= 0; j
< ps
.getLength(); ++j
) {
228 if (ps
[j
]->getUpdateInformationURLs().getLength() != 0) {
233 osl::MutexGuard
g(m_mutex
);
243 vos::OGuard
g1(Application::GetSolarMutex());
246 osl::MutexGuard
g2(m_mutex
);
255 Updatability::Updatability(
257 css::uno::Reference
< css::deployment::XPackageManager
> > const &
260 m_thread(new Thread(packageManagers
, enabled
))
265 Updatability::~Updatability() {
269 void Updatability::start() {
273 void Updatability::stop() {
275 // Bad hack; m_thread calls Application::GetSolarMutex, which only works
276 // as long as DeInitVCL has not been called:
277 ULONG n
= Application::ReleaseSolarMutex();
279 Application::AcquireSolarMutex(n
);