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