Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / desktop / source / app / officeipcthread.hxx
bloba233c18e012b10541491cd3f5902645cd162cbd4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <sal/config.h>
24 #include <utility>
25 #include <vector>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/frame/XTerminateListener.hpp>
29 #include <osl/signal.h>
30 #include <rtl/ref.hxx>
31 #include <rtl/ustring.hxx>
32 #include <salhelper/simplereferenceobject.hxx>
33 #include <cppuhelper/implbase.hxx>
34 #include <osl/conditn.hxx>
35 #include <optional>
37 namespace desktop
40 oslSignalAction SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSignalInfo* pInfo);
42 // A request for the current office
43 // that was given by command line or by IPC pipe communication.
44 struct ProcessDocumentsRequest
46 explicit ProcessDocumentsRequest(std::optional< OUString > cwdUrl):
47 aCwdUrl(std::move(cwdUrl)), pcProcessed( nullptr ), bTextCat( false ), bScriptCat( false ) {}
49 std::optional< OUString > aCwdUrl;
50 OUString aModule;
51 std::vector< OUString > aOpenList; // Documents that should be opened in the default way
52 std::vector< OUString > aViewList; // Documents that should be opened in viewmode
53 std::vector< OUString > aStartList; // Documents/Presentations that should be started
54 std::vector< OUString > aPrintList; // Documents that should be printed on default printer
55 std::vector< OUString > aForceOpenList; // Documents that should be forced to open for editing (even templates)
56 std::vector< OUString > aForceNewList; // Documents that should be forced to create a new document
57 OUString aPrinterName; // The printer name that should be used for printing
58 std::vector< OUString > aPrintToList; // Documents that should be printed on the given printer
59 std::vector< OUString > aConversionList;
60 OUString aConversionParams;
61 OUString aConversionOut;
62 OUString aImageConversionType;
63 std::vector< OUString > aInFilter;
64 ::osl::Condition *pcProcessed; // pointer condition to be set when the request has been processed
65 bool* mpbSuccess = nullptr; // pointer to boolean receiving if the processing was successful
66 bool bTextCat; // boolean flag indicating whether to dump text content to console
67 bool bScriptCat; // boolean flag indicating whether to dump script content to console
70 class DispatchWatcher;
71 class IpcThread;
72 class PipeIpcThread;
73 class DbusIpcThread;
75 class RequestHandler: public salhelper::SimpleReferenceObject
77 friend IpcThread;
78 friend PipeIpcThread;
79 friend DbusIpcThread;
81 private:
82 static rtl::Reference< RequestHandler > pGlobal;
84 enum class State { Starting, RequestsEnabled, Downing };
86 State mState;
87 int mnPendingRequests;
88 rtl::Reference<DispatchWatcher> mpDispatchWatcher;
89 rtl::Reference<IpcThread> mIpcThread;
91 /* condition to be set when the request has been processed */
92 ::osl::Condition cProcessed;
93 /* receives if the processing was successful (may be false e.g. when shutting down) */
94 bool mbSuccess = false;
96 /* condition to be set when the main event loop is ready
97 otherwise an error dialogs event loop could eat away
98 requests from a 2nd office */
99 ::osl::Condition cReady;
101 static ::osl::Mutex& GetMutex();
103 RequestHandler();
105 virtual ~RequestHandler() override;
107 public:
108 enum Status
110 IPC_STATUS_OK,
111 IPC_STATUS_2ND_OFFICE,
112 IPC_STATUS_PIPE_ERROR,
113 IPC_STATUS_BOOTSTRAP_ERROR
116 // controlling pipe communication during shutdown
117 static void SetDowning();
118 static void EnableRequests();
119 static bool AreRequestsPending();
120 static void RequestsCompleted();
121 static bool ExecuteCmdLineRequests(
122 ProcessDocumentsRequest&, bool noTerminate);
124 // return sal_False if second office
125 static Status Enable(bool ipc);
126 static void Disable();
127 // start dispatching events...
128 static void SetReady(bool bIsReady);
129 static void WaitForReady();
131 bool AreRequestsEnabled() const { return mState == State::RequestsEnabled; }
135 class RequestHandlerController : public ::cppu::WeakImplHelper<
136 css::lang::XServiceInfo,
137 css::frame::XTerminateListener >
139 public:
140 RequestHandlerController() {}
142 // XServiceInfo
143 virtual OUString SAL_CALL getImplementationName() override;
144 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
145 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
147 // XEventListener
148 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
150 // XTerminateListener
151 virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override;
152 virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override;
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */