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 .
22 #include <sal/config.h>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/frame/XTerminateListener.hpp>
28 #include <osl/signal.h>
29 #include <rtl/ref.hxx>
30 #include <rtl/ustring.hxx>
31 #include <salhelper/simplereferenceobject.hxx>
32 #include <cppuhelper/implbase.hxx>
33 #include <osl/conditn.hxx>
39 oslSignalAction
SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSignalInfo
* pInfo
);
41 // A request for the current office
42 // that was given by command line or by IPC pipe communication.
43 struct ProcessDocumentsRequest
45 explicit ProcessDocumentsRequest(std::optional
< OUString
> const & cwdUrl
):
46 aCwdUrl(cwdUrl
), pcProcessed( nullptr ), bTextCat( false ), bScriptCat( false ) {}
48 std::optional
< OUString
> aCwdUrl
;
50 std::vector
< OUString
> aOpenList
; // Documents that should be opened in the default way
51 std::vector
< OUString
> aViewList
; // Documents that should be opened in viewmode
52 std::vector
< OUString
> aStartList
; // Documents/Presentations that should be started
53 std::vector
< OUString
> aPrintList
; // Documents that should be printed on default printer
54 std::vector
< OUString
> aForceOpenList
; // Documents that should be forced to open for editing (even templates)
55 std::vector
< OUString
> aForceNewList
; // Documents that should be forced to create a new document
56 OUString aPrinterName
; // The printer name that should be used for printing
57 std::vector
< OUString
> aPrintToList
; // Documents that should be printed on the given printer
58 std::vector
< OUString
> aConversionList
;
59 OUString aConversionParams
;
60 OUString aConversionOut
;
61 OUString aImageConversionType
;
62 std::vector
< OUString
> aInFilter
;
63 ::osl::Condition
*pcProcessed
; // pointer condition to be set when the request has been processed
64 bool* mpbSuccess
= nullptr; // pointer to boolean receiving if the processing was successful
65 bool bTextCat
; // boolean flag indicating whether to dump text content to console
66 bool bScriptCat
; // boolean flag indicating whether to dump script content to console
69 class DispatchWatcher
;
74 class RequestHandler
: public salhelper::SimpleReferenceObject
81 static rtl::Reference
< RequestHandler
> pGlobal
;
83 enum class State
{ Starting
, RequestsEnabled
, Downing
};
86 int mnPendingRequests
;
87 rtl::Reference
<DispatchWatcher
> mpDispatchWatcher
;
88 rtl::Reference
<IpcThread
> mIpcThread
;
90 /* condition to be set when the request has been processed */
91 ::osl::Condition cProcessed
;
92 /* receives if the processing was successful (may be false e.g. when shutting down) */
93 bool mbSuccess
= false;
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 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */