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: preventduplicateinteraction.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 __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_
32 #define __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
40 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
49 //_________________________________________________________________________________________________________________
50 #include <cppuhelper/implbase1.hxx>
52 //_________________________________________________________________________________________________________________
54 //_________________________________________________________________________________________________________________
59 #error "Conflict during define of namespace alias ..."
61 #define css ::com::sun::star
64 //_________________________________________________________________________________________________________________
66 //_________________________________________________________________________________________________________________
68 //_________________________________________________________________________________________________________________
69 // exported definitions
70 //_________________________________________________________________________________________________________________
73 @short Prevent us from showing the same interaction more then once during
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
85 mutable ::osl::Mutex m_aLock
;
88 class PreventDuplicateInteraction
: private ThreadHelpBase2
89 ,public ::cppu::WeakImplHelper1
< css::task::XInteractionHandler
>
91 //_____________________________________
92 // structs, types etcp.
95 struct InteractionInfo
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
;
110 InteractionInfo(const css::uno::Type
& aInteraction
,
111 sal_Int32 nMaxCount
)
112 : m_aInteraction(aInteraction
)
113 , m_nMaxCount (nMaxCount
)
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 //_____________________________________
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
141 InteractionList m_lInteractionRules
;
143 //_____________________________________
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.
158 virtual void SAL_CALL
handle(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
159 throw(css::uno::RuntimeException
);
161 //_____________________________________
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.
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()!
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.
221 virtual void addInteractionRule(const PreventDuplicateInteraction::InteractionInfo
& aInteractionInfo
);
223 //_________________________________
225 @short return the info struct for the specified interaction.
228 specify the interaction.
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
237 TRUE if the queried interaction could be found.
242 virtual sal_Bool
getInteractionInfo(const css::uno::Type
& aInteraction
,
243 PreventDuplicateInteraction::InteractionInfo
* pReturn
) const;
248 } // namespace framework
250 #endif // #ifndef __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_