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 #ifndef _FINALTHREADMANAGER_HXX
24 #define _FINALTHREADMANAGER_HXX
25 
26 #include "sal/config.h"
27 #include "cppuhelper/factory.hxx"
28 #include "cppuhelper/implementationentry.hxx"
29 #include "cppuhelper/implbase3.hxx"
30 #include "com/sun/star/lang/XServiceInfo.hpp"
31 #include "com/sun/star/util/XJobManager.hpp"
32 #include "com/sun/star/frame/XTerminateListener2.hpp"
33 
34 
35 #include <osl/mutex.hxx>
36 
37 #include <list>
38 
39 class CancelJobsThread;
40 class TerminateOfficeThread;
41 class SwPauseThreadStarting;
42 
43 // service helper namespace
44 namespace comp_FinalThreadManager {
45 
46 // component and service helper functions:
47 ::rtl::OUString SAL_CALL _getImplementationName();
48 com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames();
49 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL _create(
50     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context );
51 
52 } // closing service helper namespace
53 
54 
55 class FinalThreadManager : public ::cppu::WeakImplHelper3< com::sun::star::lang::XServiceInfo,
56                                                            com::sun::star::util::XJobManager,
57                                                            com::sun::star::frame::XTerminateListener2 >
58 {
59 public:
60     explicit FinalThreadManager(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context);
61 
62     // ::com::sun::star::lang::XServiceInfo:
63     virtual ::rtl::OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException);
64     virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (com::sun::star::uno::RuntimeException);
65     virtual com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
66 
67     // ::com::sun::star::util::XJobManager:
68     virtual void SAL_CALL registerJob(const com::sun::star::uno::Reference< com::sun::star::util::XCancellable > & Job) throw (com::sun::star::uno::RuntimeException);
69     virtual void SAL_CALL releaseJob(const com::sun::star::uno::Reference< com::sun::star::util::XCancellable > & Job) throw (com::sun::star::uno::RuntimeException);
70     virtual void SAL_CALL cancelAllJobs() throw (com::sun::star::uno::RuntimeException);
71 
72     // ::com::sun::star::frame::XTerminateListener2
73     virtual void SAL_CALL cancelTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException);
74 
75     // ::com::sun::star::frame::XTerminateListener (inherited via com::sun::star::frame::XTerminateListener2)
76     virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
77     virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException);
78 
79     // ::com::sun:star::lang::XEventListener (inherited via com::sun::star::frame::XTerminateListener)
80     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
81 
82 private:
83     FinalThreadManager(FinalThreadManager &); // not defined
84     void operator =(FinalThreadManager &); // not defined
85 
86     virtual ~FinalThreadManager();
87 
88     void registerAsListenerAtDesktop();
89 
90     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
91 
92     osl::Mutex maMutex;
93 
94     std::list< com::sun::star::uno::Reference< com::sun::star::util::XCancellable > > maThreads;
95     CancelJobsThread* mpCancelJobsThread;
96     TerminateOfficeThread* mpTerminateOfficeThread;
97     SwPauseThreadStarting* mpPauseThreadStarting;
98 
99     bool mbRegisteredAtDesktop;
100 };
101 #endif
102