xref: /AOO41X/main/desktop/source/app/officeipcthread.hxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 {
52     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     };
112 
113     virtual ~OfficeIPCThread();
114 
115     // controlling pipe communication during shutdown
116     static void                 SetDowning();
117     static void                 EnableRequests( bool i_bEnable = true );
118     static sal_Bool             AreRequestsPending();
119     static void                 RequestsCompleted( int n = 1 );
120     static sal_Bool             ExecuteCmdLineRequests( ProcessDocumentsRequest& );
121 
122     // return sal_False if second office
123     static Status               EnableOfficeIPCThread();
124     static void                 DisableOfficeIPCThread();
125     // start dispatching events...
126     static void                 SetReady(OfficeIPCThread* pThread = NULL);
127 
128     bool                        AreRequestsEnabled() const { return mbRequestsEnabled && ! mbDowning; }
129 };
130 
131 
132 class OfficeIPCThreadController : public ::cppu::WeakImplHelper2<
133                                             ::com::sun::star::lang::XServiceInfo,
134                                             ::com::sun::star::frame::XTerminateListener >
135 {
136     public:
137         OfficeIPCThreadController() {}
138         virtual ~OfficeIPCThreadController() {}
139 
140         // XServiceInfo
141         virtual ::rtl::OUString SAL_CALL getImplementationName()
142             throw ( ::com::sun::star::uno::RuntimeException );
143         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
144             throw ( ::com::sun::star::uno::RuntimeException );
145         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
146             throw ( ::com::sun::star::uno::RuntimeException );
147 
148         // XEventListener
149         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
150             throw( ::com::sun::star::uno::RuntimeException );
151 
152         // XTerminateListener
153         virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& aEvent )
154             throw( ::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException );
155         virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& aEvent )
156             throw( ::com::sun::star::uno::RuntimeException );
157 };
158 
159 }
160 
161 #endif // _DESKTOP_OFFICEIPCTHREAD_HXX_
162