xref: /AOO41X/main/desktop/source/app/officeipcthread.hxx (revision aa94018d58c9ca9f4f31d38a566134dc9a894d4e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DESKTOP_OFFICEIPCTHREAD_HXX_
25 #define _DESKTOP_OFFICEIPCTHREAD_HXX_
26 
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/frame/XTerminateListener.hpp>
29 #include <vos/pipe.hxx>
30 #include <vos/security.hxx>
31 #include <vos/thread.hxx>
32 #include <vos/signal.hxx>
33 #include <rtl/ustring.hxx>
34 #ifndef _CPPUHELPER_WEAKBASE2_HXX_
35 #include <cppuhelper/implbase2.hxx>
36 #endif
37 #include <osl/conditn.hxx>
38 #include "boost/optional.hpp"
39 
40 namespace desktop
41 {
42 
43 class SalMainPipeExchangeSignalHandler : public vos::OSignalHandler
44 {
45     virtual TSignalAction SAL_CALL signal(TSignalInfo *pInfo);
46 };
47 
48 // A request for the current office
49 // that was given by command line or by IPC pipe communication.
50 struct ProcessDocumentsRequest
51 {
ProcessDocumentsRequestdesktop::ProcessDocumentsRequest52     ProcessDocumentsRequest(boost::optional< rtl::OUString > const & cwdUrl):
53         aCwdUrl(cwdUrl), pcProcessed( NULL ) {}
54 
55     boost::optional< ::rtl::OUString > aCwdUrl;
56     ::rtl::OUString aModule;
57     ::rtl::OUString aOpenList;      // Documents that should be opened in the default way
58     ::rtl::OUString aViewList;      // Documents that should be opened in viewmode
59     ::rtl::OUString aStartList;     // Documents/Presentations that should be started
60     ::rtl::OUString aPrintList;     // Documents that should be printed on default printer
61     ::rtl::OUString aForceOpenList; // Documents that should be forced to open for editing (even templates)
62     ::rtl::OUString aForceNewList;  // Documents that should be forced to create a new document
63     ::rtl::OUString aPrinterName;   // The printer name that should be used for printing
64     ::rtl::OUString aPrintToList;   // Documents that should be printed on the given printer
65     ::osl::Condition *pcProcessed;  // pointer condition to be set when the request has been processed
66 };
67 
68 class DispatchWatcher;
69 class OfficeIPCThread : public vos::OThread
70 {
71   private:
72     static OfficeIPCThread*     pGlobalOfficeIPCThread;
73     static ::osl::Mutex*        pOfficeIPCThreadMutex;
74 
75     vos::OPipe                  maPipe;
76     vos::OStreamPipe            maStreamPipe;
77     rtl::OUString               maPipeIdent;
78     bool                        mbDowning;
79     bool                        mbRequestsEnabled;
80     int                         mnPendingRequests;
81     DispatchWatcher*            mpDispatchWatcher;
82 
83     /* condition to be set when the request has been processed */
84     ::osl::Condition cProcessed;
85 
86     /* condition to be set when the main event loop is ready
87        otherwise an error dialogs event loop could eat away
88        requests from a 2nd office */
89     ::osl::Condition cReady;
90 
91     static ::osl::Mutex&        GetMutex();
92     static const char *sc_aTerminationSequence;
93     static const int sc_nTSeqLength;
94     static const char *sc_aShowSequence;
95     static const int sc_nShSeqLength;
96     static const char *sc_aConfirmationSequence;
97     static const int sc_nCSeqLength;
98 
99     OfficeIPCThread();
100 
101   protected:
102     /// Working method which should be overridden
103     virtual void SAL_CALL run();
104 
105   public:
106     enum Status
107     {
108         IPC_STATUS_OK,
109         IPC_STATUS_2ND_OFFICE,
110         IPC_STATUS_BOOTSTRAP_ERROR,
111         IPC_STATUS_MULTI_TS_ERROR
112     };
113 
114     virtual ~OfficeIPCThread();
115 
116     // controlling pipe communication during shutdown
117     static void                 SetDowning();
118     static void                 EnableRequests( bool i_bEnable = true );
119     static sal_Bool             AreRequestsPending();
120     static void                 RequestsCompleted( int n = 1 );
121     static sal_Bool             ExecuteCmdLineRequests( ProcessDocumentsRequest& );
122 
123     // return sal_False if second office
124     static Status               EnableOfficeIPCThread();
125     static void                 DisableOfficeIPCThread();
126     // start dispatching events...
127     static void                 SetReady(OfficeIPCThread* pThread = NULL);
128 
AreRequestsEnabled() const129     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:
OfficeIPCThreadController()138         OfficeIPCThreadController() {}
~OfficeIPCThreadController()139         virtual ~OfficeIPCThreadController() {}
140 
141         // XServiceInfo
142         virtual ::rtl::OUString SAL_CALL getImplementationName()
143             throw ( ::com::sun::star::uno::RuntimeException );
144         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
145             throw ( ::com::sun::star::uno::RuntimeException );
146         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
147             throw ( ::com::sun::star::uno::RuntimeException );
148 
149         // XEventListener
150         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
151             throw( ::com::sun::star::uno::RuntimeException );
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 );
156         virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& aEvent )
157             throw( ::com::sun::star::uno::RuntimeException );
158 };
159 
160 }
161 
162 #endif // _DESKTOP_OFFICEIPCTHREAD_HXX_
163