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 SAL_CALL
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 bTextCat
; // boolean flag indicating whether to dump text content to console
68 bool bScriptCat
; // boolean flag indicating whether to dump script content to console
71 class DispatchWatcher
;
76 class RequestHandler
: public salhelper::SimpleReferenceObject
83 static rtl::Reference
< RequestHandler
> pGlobal
;
85 enum class State
{ Starting
, RequestsEnabled
, Downing
};
88 int mnPendingRequests
;
89 rtl::Reference
<DispatchWatcher
> mpDispatchWatcher
;
90 rtl::Reference
<IpcThread
> mIpcThread
;
92 /* condition to be set when the request has been processed */
93 ::osl::Condition cProcessed
;
95 /* condition to be set when the main event loop is ready
96 otherwise an error dialogs event loop could eat away
97 requests from a 2nd office */
98 ::osl::Condition cReady
;
100 static ::osl::Mutex
& GetMutex();
104 virtual ~RequestHandler() override
;
110 IPC_STATUS_2ND_OFFICE
,
111 IPC_STATUS_PIPE_ERROR
,
112 IPC_STATUS_BOOTSTRAP_ERROR
115 // controlling pipe communication during shutdown
116 static void SetDowning();
117 static void EnableRequests();
118 static bool AreRequestsPending();
119 static void RequestsCompleted();
120 static bool ExecuteCmdLineRequests(
121 ProcessDocumentsRequest
&, bool noTerminate
);
123 // return sal_False if second office
124 static Status
Enable(bool ipc
);
125 static void Disable();
126 // start dispatching events...
127 static void SetReady(bool bIsReady
);
128 static void WaitForReady();
130 bool AreRequestsEnabled() const { return mState
== State::RequestsEnabled
; }
134 class RequestHandlerController
: public ::cppu::WeakImplHelper
<
135 css::lang::XServiceInfo
,
136 css::frame::XTerminateListener
>
139 RequestHandlerController() {}
142 virtual OUString SAL_CALL
getImplementationName() override
;
143 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
144 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
147 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
149 // XTerminateListener
150 virtual void SAL_CALL
queryTermination( const css::lang::EventObject
& aEvent
) override
;
151 virtual void SAL_CALL
notifyTermination( const css::lang::EventObject
& aEvent
) override
;
156 #endif // INCLUDED_DESKTOP_SOURCE_APP_OFFICEIPCTHREAD_HXX
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */