Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _DESKTOP_DISPATCHWATCHER_HXX
30 : : #define _DESKTOP_DISPATCHWATCHER_HXX
31 : :
32 : : #include <cppuhelper/implbase1.hxx>
33 : : #include <com/sun/star/frame/XNotifyingDispatch.hpp>
34 : : #include <com/sun/star/frame/XDispatchResultListener.hpp>
35 : :
36 : : #include "officeipcthread.hxx"
37 : : #include <boost/unordered_map.hpp>
38 : : #include <vector>
39 : :
40 : : namespace desktop
41 : : {
42 : :
43 : : /*
44 : : Class for controlls dispatching of command URL through office command line. There
45 : : are "dangerous" command URLs, that can result in a running office without UI. To prevent
46 : : this situation the implementation surveile all dispatches and looks for an open task if
47 : : there is arose a problem. If there is none the office will be shutdown to prevent a
48 : : running office without UI.
49 : : */
50 : :
51 : : struct OUStringHashCode
52 : : {
53 : 0 : size_t operator()( const ::rtl::OUString& sString ) const
54 : : {
55 : 0 : return sString.hashCode();
56 : : }
57 : : };
58 : :
59 [ + - ]: 192 : class DispatchWatcherHashMap : public ::boost::unordered_map< ::rtl::OUString, sal_Int32, OUStringHashCode, ::std::equal_to< ::rtl::OUString > >
60 : : {
61 : : public:
62 : : inline void free()
63 : : {
64 : : DispatchWatcherHashMap().swap( *this );
65 : : }
66 : : };
67 : :
68 : : class DispatchWatcher : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XDispatchResultListener >
69 : : {
70 : : public:
71 : : enum RequestType
72 : : {
73 : : REQUEST_OPEN,
74 : : REQUEST_VIEW,
75 : : REQUEST_START,
76 : : REQUEST_PRINT,
77 : : REQUEST_PRINTTO,
78 : : REQUEST_FORCEOPEN,
79 : : REQUEST_FORCENEW,
80 : : REQUEST_CONVERSION,
81 : : REQUEST_INFILTER,
82 : : REQUEST_BATCHPRINT
83 : : };
84 : :
85 [ # # ][ # # ]: 0 : struct DispatchRequest
86 : : {
87 : 0 : DispatchRequest( RequestType aType, const ::rtl::OUString& aFile, boost::optional< rtl::OUString > const & cwdUrl, const ::rtl::OUString& aPrinter, const ::rtl::OUString& aFact ) :
88 [ # # ]: 0 : aRequestType( aType ), aURL( aFile ), aCwdUrl( cwdUrl ), aPrinterName( aPrinter ), aPreselectedFactory( aFact ) {}
89 : :
90 : : RequestType aRequestType;
91 : : rtl::OUString aURL;
92 : : boost::optional< rtl::OUString > aCwdUrl;
93 : : rtl::OUString aPrinterName; // also conversion params
94 : : rtl::OUString aPreselectedFactory;
95 : : };
96 : :
97 : : typedef std::vector< DispatchRequest > DispatchList;
98 : :
99 : : virtual ~DispatchWatcher();
100 : :
101 : : // XEventListener
102 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
103 : : throw(::com::sun::star::uno::RuntimeException);
104 : :
105 : : // XDispachResultListener
106 : : virtual void SAL_CALL dispatchFinished( const com::sun::star::frame::DispatchResultEvent& aEvent ) throw( com::sun::star::uno::RuntimeException );
107 : :
108 : : // Access function to get a dispatcher watcher reference. There must be a global reference holder
109 : : static DispatchWatcher* GetDispatchWatcher();
110 : :
111 : : // execute new dispatch request
112 : : sal_Bool executeDispatchRequests( const DispatchList& aDispatches, bool bNoTerminate = false );
113 : :
114 : : private:
115 : : DispatchWatcher();
116 : :
117 : : static ::osl::Mutex& GetMutex();
118 : :
119 : : DispatchWatcherHashMap m_aRequestContainer;
120 : :
121 : : sal_Int16 m_nRequestCount;
122 : : };
123 : :
124 : : }
125 : :
126 : : #endif // _DESKTOP_DISPATCHWATCHER_HXX
127 : :
128 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|