1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_DESKTOP_SOURCE_APP_OFFICEIPCTHREAD_HXX
21 #define INCLUDED_DESKTOP_SOURCE_APP_OFFICEIPCTHREAD_HXX
23 #include <sal/config.h>
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/implbase.hxx>
35 #include <osl/conditn.hxx>
36 #include <salhelper/thread.hxx>
37 #include <boost/optional.hpp>
42 oslSignalAction
SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSignalInfo
* pInfo
);
44 // A request for the current office
45 // that was given by command line or by IPC pipe communication.
46 struct ProcessDocumentsRequest
48 explicit ProcessDocumentsRequest(boost::optional
< OUString
> const & cwdUrl
):
49 aCwdUrl(cwdUrl
), pcProcessed( nullptr ), bTextCat( false ), bScriptCat( false ) {}
51 boost::optional
< OUString
> aCwdUrl
;
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 OUString aImageConversionType
;
65 std::vector
< OUString
> aInFilter
;
66 ::osl::Condition
*pcProcessed
; // pointer condition to be set when the request has been processed
67 bool* mpbSuccess
= nullptr; // pointer to boolean receiving if the processing was successful
68 bool bTextCat
; // boolean flag indicating whether to dump text content to console
69 bool bScriptCat
; // boolean flag indicating whether to dump script content to console
72 class DispatchWatcher
;
77 class RequestHandler
: public salhelper::SimpleReferenceObject
84 static rtl::Reference
< RequestHandler
> pGlobal
;
86 enum class State
{ Starting
, RequestsEnabled
, Downing
};
89 int mnPendingRequests
;
90 rtl::Reference
<DispatchWatcher
> mpDispatchWatcher
;
91 rtl::Reference
<IpcThread
> mIpcThread
;
93 /* condition to be set when the request has been processed */
94 ::osl::Condition cProcessed
;
95 /* receives if the processing was successful (may be false e.g. when shutting down) */
96 bool mbSuccess
= false;
98 /* condition to be set when the main event loop is ready
99 otherwise an error dialogs event loop could eat away
100 requests from a 2nd office */
101 ::osl::Condition cReady
;
103 static ::osl::Mutex
& GetMutex();
107 virtual ~RequestHandler() override
;
113 IPC_STATUS_2ND_OFFICE
,
114 IPC_STATUS_PIPE_ERROR
,
115 IPC_STATUS_BOOTSTRAP_ERROR
118 // controlling pipe communication during shutdown
119 static void SetDowning();
120 static void EnableRequests();
121 static bool AreRequestsPending();
122 static void RequestsCompleted();
123 static bool ExecuteCmdLineRequests(
124 ProcessDocumentsRequest
&, bool noTerminate
);
126 // return sal_False if second office
127 static Status
Enable(bool ipc
);
128 static void Disable();
129 // start dispatching events...
130 static void SetReady(bool bIsReady
);
131 static void WaitForReady();
133 bool AreRequestsEnabled() const { return mState
== State::RequestsEnabled
; }
137 class RequestHandlerController
: public ::cppu::WeakImplHelper
<
138 css::lang::XServiceInfo
,
139 css::frame::XTerminateListener
>
142 RequestHandlerController() {}
145 virtual OUString SAL_CALL
getImplementationName() override
;
146 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
147 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
150 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
152 // XTerminateListener
153 virtual void SAL_CALL
queryTermination( const css::lang::EventObject
& aEvent
) override
;
154 virtual void SAL_CALL
notifyTermination( const css::lang::EventObject
& aEvent
) override
;
159 #endif // INCLUDED_DESKTOP_SOURCE_APP_OFFICEIPCTHREAD_HXX
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */