Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_DESKTOP_SOURCE_APP_OFFICEIPCTHREAD_HXX
21 : #define INCLUDED_DESKTOP_SOURCE_APP_OFFICEIPCTHREAD_HXX
22 :
23 : #include "sal/config.h"
24 :
25 : #include <vector>
26 :
27 : #include <com/sun/star/lang/XServiceInfo.hpp>
28 : #include <com/sun/star/frame/XTerminateListener.hpp>
29 : #include <osl/pipe.hxx>
30 : #include <osl/security.hxx>
31 : #include <osl/signal.h>
32 : #include <rtl/ref.hxx>
33 : #include <rtl/ustring.hxx>
34 : #include <cppuhelper/implbase2.hxx>
35 : #include <osl/conditn.hxx>
36 : #include <salhelper/thread.hxx>
37 : #include "boost/optional.hpp"
38 :
39 : namespace desktop
40 : {
41 :
42 : oslSignalAction SAL_CALL SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSignalInfo* pInfo);
43 :
44 : // A request for the current office
45 : // that was given by command line or by IPC pipe communication.
46 0 : struct ProcessDocumentsRequest
47 : {
48 0 : ProcessDocumentsRequest(boost::optional< OUString > const & cwdUrl):
49 0 : aCwdUrl(cwdUrl), pcProcessed( NULL ) {}
50 :
51 : boost::optional< OUString > aCwdUrl;
52 : OUString aModule;
53 : std::vector< OUString > aOpenList; // Documents that should be opened in the default way
54 : std::vector< OUString > aViewList; // Documents that should be opened in viewmode
55 : std::vector< OUString > aStartList; // Documents/Presentations that should be started
56 : std::vector< OUString > aPrintList; // Documents that should be printed on default printer
57 : std::vector< OUString > aForceOpenList; // Documents that should be forced to open for editing (even templates)
58 : std::vector< OUString > aForceNewList; // Documents that should be forced to create a new document
59 : OUString aPrinterName; // The printer name that should be used for printing
60 : std::vector< OUString > aPrintToList; // Documents that should be printed on the given printer
61 : std::vector< OUString > aConversionList;
62 : OUString aConversionParams;
63 : OUString aConversionOut;
64 : std::vector< OUString > aInFilter;
65 : ::osl::Condition *pcProcessed; // pointer condition to be set when the request has been processed
66 : };
67 :
68 : class DispatchWatcher;
69 : class OfficeIPCThread : public salhelper::Thread
70 : {
71 : private:
72 : static rtl::Reference< OfficeIPCThread > pGlobalOfficeIPCThread;
73 :
74 : osl::Pipe maPipe;
75 : bool mbDowning;
76 : bool mbRequestsEnabled;
77 : int mnPendingRequests;
78 : DispatchWatcher* mpDispatchWatcher;
79 :
80 : /* condition to be set when the request has been processed */
81 : ::osl::Condition cProcessed;
82 :
83 : /* condition to be set when the main event loop is ready
84 : otherwise an error dialogs event loop could eat away
85 : requests from a 2nd office */
86 : ::osl::Condition cReady;
87 :
88 : static ::osl::Mutex& GetMutex();
89 : static const char *sc_aTerminationSequence;
90 : static const int sc_nTSeqLength;
91 : static const char *sc_aShowSequence;
92 : static const int sc_nShSeqLength;
93 : static const char *sc_aConfirmationSequence;
94 : static const int sc_nCSeqLength;
95 : static const char *sc_aSendArgumentsSequence;
96 : static const int sc_nCSASeqLength;
97 :
98 : OfficeIPCThread();
99 :
100 : virtual ~OfficeIPCThread();
101 :
102 : /// Working method which should be overridden
103 : virtual void execute() SAL_OVERRIDE;
104 :
105 : public:
106 : enum Status
107 : {
108 : IPC_STATUS_OK,
109 : IPC_STATUS_2ND_OFFICE,
110 : IPC_STATUS_PIPE_ERROR,
111 : IPC_STATUS_BOOTSTRAP_ERROR
112 : };
113 :
114 : // controlling pipe communication during shutdown
115 : static void SetDowning();
116 : static void EnableRequests( bool i_bEnable = true );
117 : static sal_Bool AreRequestsPending();
118 : static void RequestsCompleted( int n = 1 );
119 : static sal_Bool ExecuteCmdLineRequests( ProcessDocumentsRequest& );
120 :
121 : // return sal_False if second office
122 : static Status EnableOfficeIPCThread();
123 : static void DisableOfficeIPCThread(bool join = true);
124 : // start dispatching events...
125 : static void SetReady(
126 : rtl::Reference< OfficeIPCThread > const & pThread =
127 : rtl::Reference< OfficeIPCThread >());
128 :
129 0 : bool AreRequestsEnabled() const { return mbRequestsEnabled && ! mbDowning; }
130 : };
131 :
132 :
133 : class OfficeIPCThreadController : public ::cppu::WeakImplHelper2<
134 : ::com::sun::star::lang::XServiceInfo,
135 : ::com::sun::star::frame::XTerminateListener >
136 : {
137 : public:
138 0 : OfficeIPCThreadController() {}
139 0 : virtual ~OfficeIPCThreadController() {}
140 :
141 : // XServiceInfo
142 : virtual OUString SAL_CALL getImplementationName()
143 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
144 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
145 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
146 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
147 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
148 :
149 : // XEventListener
150 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
151 : throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
152 :
153 : // XTerminateListener
154 : virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& aEvent )
155 : throw( ::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
156 : virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& aEvent )
157 : throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
158 : };
159 :
160 : }
161 :
162 : #endif // INCLUDED_DESKTOP_SOURCE_APP_OFFICEIPCTHREAD_HXX
163 :
164 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|