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_DISPATCHWATCHER_HXX 29 #define _DESKTOP_DISPATCHWATCHER_HXX 30 31 #include <cppuhelper/implbase1.hxx> 32 #include <com/sun/star/frame/XNotifyingDispatch.hpp> 33 #include <com/sun/star/frame/XDispatchResultListener.hpp> 34 35 #include "officeipcthread.hxx" 36 #include <hash_map> 37 #include <vector> 38 39 namespace desktop 40 { 41 42 /* 43 Class for controlls dispatching of command URL through office command line. There 44 are "dangerous" command URLs, that can result in a running office without UI. To prevent 45 this situation the implementation surveile all dispatches and looks for an open task if 46 there is arose a problem. If there is none the office will be shutdown to prevent a 47 running office without UI. 48 */ 49 50 struct OUStringHashCode 51 { 52 size_t operator()( const ::rtl::OUString& sString ) const 53 { 54 return sString.hashCode(); 55 } 56 }; 57 58 class DispatchWatcherHashMap : public ::std::hash_map< ::rtl::OUString, sal_Int32, OUStringHashCode, ::std::equal_to< ::rtl::OUString > > 59 { 60 public: 61 inline void free() 62 { 63 DispatchWatcherHashMap().swap( *this ); 64 } 65 }; 66 67 class DispatchWatcher : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XDispatchResultListener > 68 { 69 public: 70 enum RequestType 71 { 72 REQUEST_OPEN, 73 REQUEST_VIEW, 74 REQUEST_START, 75 REQUEST_PRINT, 76 REQUEST_PRINTTO, 77 REQUEST_FORCEOPEN, 78 REQUEST_FORCENEW 79 }; 80 81 struct DispatchRequest 82 { 83 DispatchRequest( RequestType aType, const ::rtl::OUString& aFile, boost::optional< rtl::OUString > const & cwdUrl, const ::rtl::OUString& aPrinter, const ::rtl::OUString& aFact ) : 84 aRequestType( aType ), aURL( aFile ), aCwdUrl( cwdUrl ), aPrinterName( aPrinter ), aPreselectedFactory( aFact ) {} 85 86 RequestType aRequestType; 87 rtl::OUString aURL; 88 boost::optional< rtl::OUString > aCwdUrl; 89 rtl::OUString aPrinterName; 90 rtl::OUString aPreselectedFactory; 91 }; 92 93 typedef std::vector< DispatchRequest > DispatchList; 94 95 virtual ~DispatchWatcher(); 96 97 // XEventListener 98 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) 99 throw(::com::sun::star::uno::RuntimeException); 100 101 // XDispachResultListener 102 virtual void SAL_CALL dispatchFinished( const com::sun::star::frame::DispatchResultEvent& aEvent ) throw( com::sun::star::uno::RuntimeException ); 103 104 // Access function to get a dispatcher watcher reference. There must be a global reference holder 105 static DispatchWatcher* GetDispatchWatcher(); 106 107 // execute new dispatch request 108 sal_Bool executeDispatchRequests( const DispatchList& aDispatches, bool bNoTerminate = false ); 109 110 private: 111 DispatchWatcher(); 112 113 static ::osl::Mutex& GetMutex(); 114 115 DispatchWatcherHashMap m_aRequestContainer; 116 117 static ::osl::Mutex* pWatcherMutex; 118 119 sal_Int16 m_nRequestCount; 120 }; 121 122 } 123 124 #endif // _DESKTOP_DISPATCHWATCHER_HXX 125