1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dispatchwatcher.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DESKTOP_DISPATCHWATCHER_HXX
32 #define _DESKTOP_DISPATCHWATCHER_HXX
34 #include <cppuhelper/implbase1.hxx>
35 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
36 #include <com/sun/star/frame/XDispatchResultListener.hpp>
38 #include "officeipcthread.hxx"
46 Class for controlls dispatching of command URL through office command line. There
47 are "dangerous" command URLs, that can result in a running office without UI. To prevent
48 this situation the implementation surveile all dispatches and looks for an open task if
49 there is arose a problem. If there is none the office will be shutdown to prevent a
50 running office without UI.
53 struct OUStringHashCode
55 size_t operator()( const ::rtl::OUString
& sString
) const
57 return sString
.hashCode();
61 class DispatchWatcherHashMap
: public ::std::hash_map
< ::rtl::OUString
, sal_Int32
, OUStringHashCode
, ::std::equal_to
< ::rtl::OUString
> >
66 DispatchWatcherHashMap().swap( *this );
70 class DispatchWatcher
: public ::cppu::WeakImplHelper1
< ::com::sun::star::frame::XDispatchResultListener
>
84 struct DispatchRequest
86 DispatchRequest( RequestType aType
, const ::rtl::OUString
& aFile
, boost::optional
< rtl::OUString
> const & cwdUrl
, const ::rtl::OUString
& aPrinter
, const ::rtl::OUString
& aFact
) :
87 aRequestType( aType
), aURL( aFile
), aCwdUrl( cwdUrl
), aPrinterName( aPrinter
), aPreselectedFactory( aFact
) {}
89 RequestType aRequestType
;
91 boost::optional
< rtl::OUString
> aCwdUrl
;
92 rtl::OUString aPrinterName
;
93 rtl::OUString aPreselectedFactory
;
96 typedef std::vector
< DispatchRequest
> DispatchList
;
98 virtual ~DispatchWatcher();
101 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
)
102 throw(::com::sun::star::uno::RuntimeException
);
104 // XDispachResultListener
105 virtual void SAL_CALL
dispatchFinished( const com::sun::star::frame::DispatchResultEvent
& aEvent
) throw( com::sun::star::uno::RuntimeException
);
107 // Access function to get a dispatcher watcher reference. There must be a global reference holder
108 static DispatchWatcher
* GetDispatchWatcher();
110 // execute new dispatch request
111 sal_Bool
executeDispatchRequests( const DispatchList
& aDispatches
, bool bNoTerminate
= false );
116 static ::osl::Mutex
& GetMutex();
118 DispatchWatcherHashMap m_aRequestContainer
;
120 static ::osl::Mutex
* pWatcherMutex
;
122 sal_Int16 m_nRequestCount
;
127 #endif // _DESKTOP_DISPATCHWATCHER_HXX