1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _FINALTHREADMANAGER_HXX
28 #define _FINALTHREADMANAGER_HXX
29 
30 #include "sal/config.h"
31 #include "cppuhelper/factory.hxx"
32 #include "cppuhelper/implementationentry.hxx"
33 #include "cppuhelper/implbase3.hxx"
34 #include "com/sun/star/lang/XServiceInfo.hpp"
35 #include "com/sun/star/util/XJobManager.hpp"
36 #include "com/sun/star/frame/XTerminateListener2.hpp"
37 
38 
39 #include <osl/mutex.hxx>
40 
41 #include <list>
42 
43 class CancelJobsThread;
44 class TerminateOfficeThread;
45 class SwPauseThreadStarting;
46 
47 // service helper namespace
48 namespace comp_FinalThreadManager {
49 
50 // component and service helper functions:
51 ::rtl::OUString SAL_CALL _getImplementationName();
52 com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames();
53 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL _create(
54     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context );
55 
56 } // closing service helper namespace
57 
58 
59 class FinalThreadManager : public ::cppu::WeakImplHelper3< com::sun::star::lang::XServiceInfo,
60                                                            com::sun::star::util::XJobManager,
61                                                            com::sun::star::frame::XTerminateListener2 >
62 {
63 public:
64     explicit FinalThreadManager(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context);
65 
66     // ::com::sun::star::lang::XServiceInfo:
67     virtual ::rtl::OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException);
68     virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (com::sun::star::uno::RuntimeException);
69     virtual com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
70 
71     // ::com::sun::star::util::XJobManager:
72     virtual void SAL_CALL registerJob(const com::sun::star::uno::Reference< com::sun::star::util::XCancellable > & Job) throw (com::sun::star::uno::RuntimeException);
73     virtual void SAL_CALL releaseJob(const com::sun::star::uno::Reference< com::sun::star::util::XCancellable > & Job) throw (com::sun::star::uno::RuntimeException);
74     virtual void SAL_CALL cancelAllJobs() throw (com::sun::star::uno::RuntimeException);
75 
76     // ::com::sun::star::frame::XTerminateListener2
77     virtual void SAL_CALL cancelTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException);
78 
79     // ::com::sun::star::frame::XTerminateListener (inherited via com::sun::star::frame::XTerminateListener2)
80     virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
81     virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException);
82 
83     // ::com::sun:star::lang::XEventListener (inherited via com::sun::star::frame::XTerminateListener)
84     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
85 
86 private:
87     FinalThreadManager(FinalThreadManager &); // not defined
88     void operator =(FinalThreadManager &); // not defined
89 
90     virtual ~FinalThreadManager();
91 
92     void registerAsListenerAtDesktop();
93 
94     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
95 
96     osl::Mutex maMutex;
97 
98     std::list< com::sun::star::uno::Reference< com::sun::star::util::XCancellable > > maThreads;
99     CancelJobsThread* mpCancelJobsThread;
100     TerminateOfficeThread* mpTerminateOfficeThread;
101     SwPauseThreadStarting* mpPauseThreadStarting;
102 
103     bool mbRegisteredAtDesktop;
104 };
105 #endif
106