Update ooo320-m1
[ooovba.git] / framework / inc / interaction / preventduplicateinteraction.hxx
blob5ba991bf3210cd6e14125b91e635c94a4f65b264
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: preventduplicateinteraction.hxx,v $
10 * $Revision: 1.5 $
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 __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_
32 #define __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
38 #include <vector>
40 //_________________________________________________________________________________________________________________
41 // interface includes
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/task/XInteractionHandler.hpp>
44 #include <com/sun/star/task/XInteractionRequest.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 //_________________________________________________________________________________________________________________
48 // other includes
49 //_________________________________________________________________________________________________________________
50 #include <cppuhelper/implbase1.hxx>
52 //_________________________________________________________________________________________________________________
53 // namespace
54 //_________________________________________________________________________________________________________________
56 namespace framework{
58 #ifdef css
59 #error "Conflict during define of namespace alias ..."
60 #else
61 #define css ::com::sun::star
62 #endif
64 //_________________________________________________________________________________________________________________
65 // exported const
66 //_________________________________________________________________________________________________________________
68 //_________________________________________________________________________________________________________________
69 // exported definitions
70 //_________________________________________________________________________________________________________________
72 /**
73 @short Prevent us from showing the same interaction more then once during
74 the same transaction.
76 @descr Every interaction provided to this helper will be safed ... handled by the internal
77 used UUIInteractionHandler (!) and never be handled a second time!
79 On the other side there exists some interactions, which allow a retry.
80 So this helper allow to set a list of interactions combined with a retry value.
82 struct ThreadHelpBase2
84 public:
85 mutable ::osl::Mutex m_aLock;
88 class PreventDuplicateInteraction : private ThreadHelpBase2
89 ,public ::cppu::WeakImplHelper1< css::task::XInteractionHandler >
91 //_____________________________________
92 // structs, types etcp.
93 public:
95 struct InteractionInfo
97 public:
98 /// describe the interaction.
99 css::uno::Type m_aInteraction;
100 /// after max count was reached this interaction will be blocked.
101 sal_Int32 m_nMaxCount;
102 /// count how often this interaction was called.
103 sal_Int32 m_nCallCount;
104 /** hold the last intercepted request (matching the set interaction type) alive
105 so it can be used for further checks */
106 css::uno::Reference< css::task::XInteractionRequest > m_xRequest;
108 public:
110 InteractionInfo(const css::uno::Type& aInteraction,
111 sal_Int32 nMaxCount )
112 : m_aInteraction(aInteraction)
113 , m_nMaxCount (nMaxCount )
114 , m_nCallCount (0 )
117 InteractionInfo(const InteractionInfo& aCopy)
118 : m_aInteraction(aCopy.m_aInteraction)
119 , m_nMaxCount (aCopy.m_nMaxCount )
120 , m_nCallCount (aCopy.m_nCallCount )
121 , m_xRequest (aCopy.m_xRequest )
125 typedef ::std::vector< InteractionInfo > InteractionList;
127 //_____________________________________
128 // member
129 private:
131 /// Used to create needed uno services at runtime.
132 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
134 /** The outside interaction handler, which is used to handle every incoming interaction,
135 if it's not blocked. */
136 css::uno::Reference< css::task::XInteractionHandler > m_xHandler;
138 /** This list describe which and how incoming interactions must be handled.
139 Further it contains all collected informations after this interaction
140 object was used.*/
141 InteractionList m_lInteractionRules;
143 //_____________________________________
144 // uno interface
145 public:
147 //_________________________________
149 @interface XInteractionHandler
150 @short called from outside to handle a problem
151 @descr We filter the incoming interactions. some of them
152 will be forwarded to the generic UI interaction handler.
153 So we must not implement it twice. Some other ones
154 will be aborted only.
156 @threadsafe yes
158 virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
159 throw(css::uno::RuntimeException);
161 //_____________________________________
162 // c++ interface
163 public:
165 //_________________________________
167 @short ctor to guarantee right initialized instances of this class
168 @descr It uses the given uno service manager to create the global
169 generic UI interaction handler for later internal using.
171 @param xSMGR
172 uno service manager for creating services internaly
174 @threadsafe not neccessary
176 PreventDuplicateInteraction(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
178 //_________________________________
180 @short dtor to free used memory.
182 virtual ~PreventDuplicateInteraction();
184 //_________________________________
186 @short set the outside interaction handler, which must be used internaly
187 if the interaction will not be blocked by the set list of rules.
189 @note This overwrites the settings of e.g. useDefaultUUIHandler()!
191 @param xHandler
192 the new interaction handler
194 virtual void setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler);
196 //_________________________________
198 @short instead of setting an outside interaction handler, this method
199 make sure the default UUI interaction handler of the office is used.
201 @note This overwrites the settings of e.g. setHandler()!
203 virtual void useDefaultUUIHandler();
205 //_________________________________
207 @short add a new interaction to the list of interactions, which
208 must be handled by this helper.
210 @descr This method must be called immediatly after a new instance of this helper was
211 created. Without such list of InteractionRules, this instances does nothing!
212 On the other side there is no possibility to remove rules.
213 So the same instance cant be used within different transactions.
214 It's a OneWay-object .-)
216 @param aInteractionInfo
217 describe the type of interaction, hos often it can be called etcpp.
219 @threadsafe yes
221 virtual void addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo);
223 //_________________________________
225 @short return the info struct for the specified interaction.
227 @param aInteraction
228 specify the interaction.
230 @param pReturn
231 provides informations about:
232 - the count how often this interaction was handled during the
233 lifetime of this helper.
234 - the interaction itself, so it can be analyzed further
236 @return [boolean]
237 TRUE if the queried interaction could be found.
238 FALSE otherwise.
240 @threadsafe yes
242 virtual sal_Bool getInteractionInfo(const css::uno::Type& aInteraction,
243 PreventDuplicateInteraction::InteractionInfo* pReturn ) const;
246 #undef css
248 } // namespace framework
250 #endif // #ifndef __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_