Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _DESKTOP_OFFICEIPCTHREAD_HXX_
30 : : #define _DESKTOP_OFFICEIPCTHREAD_HXX_
31 : :
32 : : #include "sal/config.h"
33 : :
34 : : #include <vector>
35 : :
36 : : #include <com/sun/star/lang/XServiceInfo.hpp>
37 : : #include <com/sun/star/frame/XTerminateListener.hpp>
38 : : #include <osl/pipe.hxx>
39 : : #include <osl/security.hxx>
40 : : #include <osl/signal.h>
41 : : #include <rtl/ref.hxx>
42 : : #include <rtl/ustring.hxx>
43 : : #include <cppuhelper/implbase2.hxx>
44 : : #include <osl/conditn.hxx>
45 : : #include <salhelper/thread.hxx>
46 : : #include "boost/optional.hpp"
47 : :
48 : : namespace desktop
49 : : {
50 : :
51 : : oslSignalAction SAL_CALL SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSignalInfo* pInfo);
52 : :
53 : : // A request for the current office
54 : : // that was given by command line or by IPC pipe communication.
55 : 192 : struct ProcessDocumentsRequest
56 : : {
57 : 192 : ProcessDocumentsRequest(boost::optional< rtl::OUString > const & cwdUrl):
58 [ + - ][ + - ]: 192 : aCwdUrl(cwdUrl), pcProcessed( NULL ) {}
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
59 : :
60 : : boost::optional< ::rtl::OUString > aCwdUrl;
61 : : ::rtl::OUString aModule;
62 : : std::vector< rtl::OUString > aOpenList; // Documents that should be opened in the default way
63 : : std::vector< rtl::OUString > aViewList; // Documents that should be opened in viewmode
64 : : std::vector< rtl::OUString > aStartList; // Documents/Presentations that should be started
65 : : std::vector< rtl::OUString > aPrintList; // Documents that should be printed on default printer
66 : : std::vector< rtl::OUString > aForceOpenList; // Documents that should be forced to open for editing (even templates)
67 : : std::vector< rtl::OUString > aForceNewList; // Documents that should be forced to create a new document
68 : : ::rtl::OUString aPrinterName; // The printer name that should be used for printing
69 : : std::vector< rtl::OUString > aPrintToList; // Documents that should be printed on the given printer
70 : : std::vector< rtl::OUString > aConversionList;
71 : : ::rtl::OUString aConversionParams;
72 : : ::rtl::OUString aConversionOut;
73 : : std::vector< rtl::OUString > aInFilter;
74 : : ::osl::Condition *pcProcessed; // pointer condition to be set when the request has been processed
75 : : };
76 : :
77 : : class DispatchWatcher;
78 : : class OfficeIPCThread : public salhelper::Thread
79 : : {
80 : : private:
81 : : static rtl::Reference< OfficeIPCThread > pGlobalOfficeIPCThread;
82 : :
83 : : osl::Pipe maPipe;
84 : : osl::StreamPipe maStreamPipe;
85 : : rtl::OUString maPipeIdent;
86 : : bool mbDowning;
87 : : bool mbRequestsEnabled;
88 : : int mnPendingRequests;
89 : : DispatchWatcher* mpDispatchWatcher;
90 : :
91 : : /* condition to be set when the request has been processed */
92 : : ::osl::Condition cProcessed;
93 : :
94 : : /* condition to be set when the main event loop is ready
95 : : otherwise an error dialogs event loop could eat away
96 : : requests from a 2nd office */
97 : : ::osl::Condition cReady;
98 : :
99 : : static ::osl::Mutex& GetMutex();
100 : : static const char *sc_aTerminationSequence;
101 : : static const int sc_nTSeqLength;
102 : : static const char *sc_aShowSequence;
103 : : static const int sc_nShSeqLength;
104 : : static const char *sc_aConfirmationSequence;
105 : : static const int sc_nCSeqLength;
106 : :
107 : : OfficeIPCThread();
108 : :
109 : : virtual ~OfficeIPCThread();
110 : :
111 : : /// Working method which should be overridden
112 : : virtual void execute();
113 : :
114 : : public:
115 : : enum Status
116 : : {
117 : : IPC_STATUS_OK,
118 : : IPC_STATUS_2ND_OFFICE,
119 : : IPC_STATUS_BOOTSTRAP_ERROR
120 : : };
121 : :
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& );
128 : :
129 : : // return sal_False if second office
130 : : static Status EnableOfficeIPCThread();
131 : : static void DisableOfficeIPCThread(bool join = true);
132 : : // start dispatching events...
133 : : static void SetReady(
134 : : rtl::Reference< OfficeIPCThread > const & pThread =
135 : : rtl::Reference< OfficeIPCThread >());
136 : :
137 [ + - ][ + - ]: 96 : bool AreRequestsEnabled() const { return mbRequestsEnabled && ! mbDowning; }
138 : : };
139 : :
140 : :
141 : : class OfficeIPCThreadController : public ::cppu::WeakImplHelper2<
142 : : ::com::sun::star::lang::XServiceInfo,
143 : : ::com::sun::star::frame::XTerminateListener >
144 : : {
145 : : public:
146 : 96 : OfficeIPCThreadController() {}
147 [ - + ]: 192 : virtual ~OfficeIPCThreadController() {}
148 : :
149 : : // XServiceInfo
150 : : virtual ::rtl::OUString SAL_CALL getImplementationName()
151 : : throw ( ::com::sun::star::uno::RuntimeException );
152 : : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
153 : : throw ( ::com::sun::star::uno::RuntimeException );
154 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
155 : : throw ( ::com::sun::star::uno::RuntimeException );
156 : :
157 : : // XEventListener
158 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
159 : : throw( ::com::sun::star::uno::RuntimeException );
160 : :
161 : : // XTerminateListener
162 : : virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& aEvent )
163 : : throw( ::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException );
164 : : virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& aEvent )
165 : : throw( ::com::sun::star::uno::RuntimeException );
166 : : };
167 : :
168 : : }
169 : :
170 : : #endif // _DESKTOP_OFFICEIPCTHREAD_HXX_
171 : :
172 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|