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: officeipcthread.hxx,v $
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 #ifndef _DESKTOP_OFFICEIPCTHREAD_HXX_
32 #define _DESKTOP_OFFICEIPCTHREAD_HXX_
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/frame/XTerminateListener.hpp>
36 #include <vos/pipe.hxx>
37 #include <vos/security.hxx>
38 #include <vos/thread.hxx>
39 #include <vos/signal.hxx>
40 #include <rtl/ustring.hxx>
41 #ifndef _CPPUHELPER_WEAKBASE2_HXX_
42 #include <cppuhelper/implbase2.hxx>
44 #include <osl/conditn.hxx>
45 #include "boost/optional.hpp"
50 class SalMainPipeExchangeSignalHandler
: public vos::OSignalHandler
52 virtual TSignalAction SAL_CALL
signal(TSignalInfo
*pInfo
);
55 // A request for the current office
56 // that was given by command line or by IPC pipe communication.
57 struct ProcessDocumentsRequest
59 ProcessDocumentsRequest(boost::optional
< rtl::OUString
> const & cwdUrl
):
60 aCwdUrl(cwdUrl
), pcProcessed( NULL
) {}
62 boost::optional
< ::rtl::OUString
> aCwdUrl
;
63 ::rtl::OUString aModule
;
64 ::rtl::OUString aOpenList
; // Documents that should be opened in the default way
65 ::rtl::OUString aViewList
; // Documents that should be opened in viewmode
66 ::rtl::OUString aStartList
; // Documents/Presentations that should be started
67 ::rtl::OUString aPrintList
; // Documents that should be printed on default printer
68 ::rtl::OUString aForceOpenList
; // Documents that should be forced to open for editing (even templates)
69 ::rtl::OUString aForceNewList
; // Documents that should be forced to create a new document
70 ::rtl::OUString aPrinterName
; // The printer name that should be used for printing
71 ::rtl::OUString aPrintToList
; // Documents that should be printed on the given printer
72 ::osl::Condition
*pcProcessed
; // pointer condition to be set when the request has been processed
75 class DispatchWatcher
;
76 class OfficeIPCThread
: public vos::OThread
79 static OfficeIPCThread
* pGlobalOfficeIPCThread
;
80 static ::osl::Mutex
* pOfficeIPCThreadMutex
;
83 vos::OStreamPipe maStreamPipe
;
84 rtl::OUString maPipeIdent
;
86 bool mbRequestsEnabled
;
87 int mnPendingRequests
;
88 DispatchWatcher
* mpDispatchWatcher
;
90 /* condition to be set when the request has been processed */
91 ::osl::Condition cProcessed
;
93 /* condition to be set when the main event loop is ready
94 otherwise an error dialogs event loop could eat away
95 requests from a 2nd office */
96 ::osl::Condition cReady
;
98 static ::osl::Mutex
& GetMutex();
99 static const char *sc_aTerminationSequence
;
100 static const int sc_nTSeqLength
;
101 static const char *sc_aShowSequence
;
102 static const int sc_nShSeqLength
;
103 static const char *sc_aConfirmationSequence
;
104 static const int sc_nCSeqLength
;
109 /// Working method which should be overridden
110 virtual void SAL_CALL
run();
116 IPC_STATUS_2ND_OFFICE
,
117 IPC_STATUS_BOOTSTRAP_ERROR
120 virtual ~OfficeIPCThread();
122 // controlling pipe communication during shutdown
123 static void SetDowning();
124 static void EnableRequests( bool i_bEnable
= true );
125 static sal_Bool
AreRequestsPending();
126 static void RequestsCompleted( int n
= 1 );
127 static sal_Bool
ExecuteCmdLineRequests( ProcessDocumentsRequest
& );
129 // return FALSE if second office
130 static Status
EnableOfficeIPCThread();
131 static void DisableOfficeIPCThread();
132 // start dispatching events...
133 static void SetReady(OfficeIPCThread
* pThread
= NULL
);
135 bool AreRequestsEnabled() const { return mbRequestsEnabled
&& ! mbDowning
; }
139 class OfficeIPCThreadController
: public ::cppu::WeakImplHelper2
<
140 ::com::sun::star::lang::XServiceInfo
,
141 ::com::sun::star::frame::XTerminateListener
>
144 OfficeIPCThreadController() {}
145 virtual ~OfficeIPCThreadController() {}
148 virtual ::rtl::OUString SAL_CALL
getImplementationName()
149 throw ( ::com::sun::star::uno::RuntimeException
);
150 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
)
151 throw ( ::com::sun::star::uno::RuntimeException
);
152 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames()
153 throw ( ::com::sun::star::uno::RuntimeException
);
156 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
)
157 throw( ::com::sun::star::uno::RuntimeException
);
159 // XTerminateListener
160 virtual void SAL_CALL
queryTermination( const ::com::sun::star::lang::EventObject
& aEvent
)
161 throw( ::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
);
162 virtual void SAL_CALL
notifyTermination( const ::com::sun::star::lang::EventObject
& aEvent
)
163 throw( ::com::sun::star::uno::RuntimeException
);
168 #endif // _DESKTOP_OFFICEIPCTHREAD_HXX_