1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _DESKTOP_OFFICEIPCTHREAD_HXX_ 29 #define _DESKTOP_OFFICEIPCTHREAD_HXX_ 30 31 #include <com/sun/star/lang/XServiceInfo.hpp> 32 #include <com/sun/star/frame/XTerminateListener.hpp> 33 #include <vos/pipe.hxx> 34 #include <vos/security.hxx> 35 #include <vos/thread.hxx> 36 #include <vos/signal.hxx> 37 #include <rtl/ustring.hxx> 38 #ifndef _CPPUHELPER_WEAKBASE2_HXX_ 39 #include <cppuhelper/implbase2.hxx> 40 #endif 41 #include <osl/conditn.hxx> 42 #include "boost/optional.hpp" 43 44 namespace desktop 45 { 46 47 class SalMainPipeExchangeSignalHandler : public vos::OSignalHandler 48 { 49 virtual TSignalAction SAL_CALL signal(TSignalInfo *pInfo); 50 }; 51 52 // A request for the current office 53 // that was given by command line or by IPC pipe communication. 54 struct ProcessDocumentsRequest 55 { 56 ProcessDocumentsRequest(boost::optional< rtl::OUString > const & cwdUrl): 57 aCwdUrl(cwdUrl), pcProcessed( NULL ) {} 58 59 boost::optional< ::rtl::OUString > aCwdUrl; 60 ::rtl::OUString aModule; 61 ::rtl::OUString aOpenList; // Documents that should be opened in the default way 62 ::rtl::OUString aViewList; // Documents that should be opened in viewmode 63 ::rtl::OUString aStartList; // Documents/Presentations that should be started 64 ::rtl::OUString aPrintList; // Documents that should be printed on default printer 65 ::rtl::OUString aForceOpenList; // Documents that should be forced to open for editing (even templates) 66 ::rtl::OUString aForceNewList; // Documents that should be forced to create a new document 67 ::rtl::OUString aPrinterName; // The printer name that should be used for printing 68 ::rtl::OUString aPrintToList; // Documents that should be printed on the given printer 69 ::osl::Condition *pcProcessed; // pointer condition to be set when the request has been processed 70 }; 71 72 class DispatchWatcher; 73 class OfficeIPCThread : public vos::OThread 74 { 75 private: 76 static OfficeIPCThread* pGlobalOfficeIPCThread; 77 static ::osl::Mutex* pOfficeIPCThreadMutex; 78 79 vos::OPipe maPipe; 80 vos::OStreamPipe maStreamPipe; 81 rtl::OUString maPipeIdent; 82 bool mbDowning; 83 bool mbRequestsEnabled; 84 int mnPendingRequests; 85 DispatchWatcher* mpDispatchWatcher; 86 87 /* condition to be set when the request has been processed */ 88 ::osl::Condition cProcessed; 89 90 /* condition to be set when the main event loop is ready 91 otherwise an error dialogs event loop could eat away 92 requests from a 2nd office */ 93 ::osl::Condition cReady; 94 95 static ::osl::Mutex& GetMutex(); 96 static const char *sc_aTerminationSequence; 97 static const int sc_nTSeqLength; 98 static const char *sc_aShowSequence; 99 static const int sc_nShSeqLength; 100 static const char *sc_aConfirmationSequence; 101 static const int sc_nCSeqLength; 102 103 OfficeIPCThread(); 104 105 protected: 106 /// Working method which should be overridden 107 virtual void SAL_CALL run(); 108 109 public: 110 enum Status 111 { 112 IPC_STATUS_OK, 113 IPC_STATUS_2ND_OFFICE, 114 IPC_STATUS_BOOTSTRAP_ERROR 115 }; 116 117 virtual ~OfficeIPCThread(); 118 119 // controlling pipe communication during shutdown 120 static void SetDowning(); 121 static void EnableRequests( bool i_bEnable = true ); 122 static sal_Bool AreRequestsPending(); 123 static void RequestsCompleted( int n = 1 ); 124 static sal_Bool ExecuteCmdLineRequests( ProcessDocumentsRequest& ); 125 126 // return sal_False if second office 127 static Status EnableOfficeIPCThread(); 128 static void DisableOfficeIPCThread(); 129 // start dispatching events... 130 static void SetReady(OfficeIPCThread* pThread = NULL); 131 132 bool AreRequestsEnabled() const { return mbRequestsEnabled && ! mbDowning; } 133 }; 134 135 136 class OfficeIPCThreadController : public ::cppu::WeakImplHelper2< 137 ::com::sun::star::lang::XServiceInfo, 138 ::com::sun::star::frame::XTerminateListener > 139 { 140 public: 141 OfficeIPCThreadController() {} 142 virtual ~OfficeIPCThreadController() {} 143 144 // XServiceInfo 145 virtual ::rtl::OUString SAL_CALL getImplementationName() 146 throw ( ::com::sun::star::uno::RuntimeException ); 147 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 148 throw ( ::com::sun::star::uno::RuntimeException ); 149 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() 150 throw ( ::com::sun::star::uno::RuntimeException ); 151 152 // XEventListener 153 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) 154 throw( ::com::sun::star::uno::RuntimeException ); 155 156 // XTerminateListener 157 virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& aEvent ) 158 throw( ::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException ); 159 virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& aEvent ) 160 throw( ::com::sun::star::uno::RuntimeException ); 161 }; 162 163 } 164 165 #endif // _DESKTOP_OFFICEIPCTHREAD_HXX_ 166