Branch libreoffice-5-0-4
[LibreOffice.git] / include / framework / preventduplicateinteraction.hxx
blobbfc9ff6f9102851eaa9a2a4a9d933e67bedd474d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
21 #define INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
23 #include <framework/fwedllapi.h>
25 #include <vector>
27 #include <com/sun/star/task/XInteractionHandler2.hpp>
28 #include <com/sun/star/task/XInteractionRequest.hpp>
30 #include <cppuhelper/implbase1.hxx>
32 namespace com { namespace sun { namespace star { namespace uno {
33 class XComponentContext;
34 } } } }
36 namespace framework{
38 /**
39 @short Prevent us from showing the same interaction more than once during
40 the same transaction.
42 @descr Every interaction provided to this helper will be safed ... handled by the internal
43 used UUIInteractionHandler (!) and never be handled a second time!
45 On the other side there exists some interactions, which allow a retry.
46 So this helper allow to set a list of interactions combined with a retry value.
48 struct ThreadHelpBase2
50 public:
51 mutable ::osl::Mutex m_aLock;
54 class FWE_DLLPUBLIC PreventDuplicateInteraction : private ThreadHelpBase2
55 ,public ::cppu::WeakImplHelper1< css::task::XInteractionHandler2 >
58 // structs, types etcp.
59 public:
61 struct InteractionInfo
63 public:
64 /// describe the interaction.
65 css::uno::Type m_aInteraction;
66 /// after max count was reached this interaction will be blocked.
67 sal_Int32 m_nMaxCount;
68 /// count how often this interaction was called.
69 sal_Int32 m_nCallCount;
70 /** hold the last intercepted request (matching the set interaction type) alive
71 so it can be used for further checks */
72 css::uno::Reference< css::task::XInteractionRequest > m_xRequest;
74 public:
76 InteractionInfo(const css::uno::Type& aInteraction,
77 sal_Int32 nMaxCount )
78 : m_aInteraction(aInteraction)
79 , m_nMaxCount (nMaxCount )
80 , m_nCallCount (0 )
83 InteractionInfo(const InteractionInfo& aCopy)
84 : m_aInteraction(aCopy.m_aInteraction)
85 , m_nMaxCount (aCopy.m_nMaxCount )
86 , m_nCallCount (aCopy.m_nCallCount )
87 , m_xRequest (aCopy.m_xRequest )
91 typedef ::std::vector< InteractionInfo > InteractionList;
94 // member
95 private:
97 /// Used to create needed uno services at runtime.
98 css::uno::Reference< css::uno::XComponentContext > m_xContext;
100 /** The outside interaction handler, which is used to handle every incoming interaction,
101 if it's not blocked. */
102 css::uno::Reference< css::task::XInteractionHandler > m_xHandler;
104 /** This list describe which and how incoming interactions must be handled.
105 Further it contains all collected information after this interaction
106 object was used.*/
107 InteractionList m_lInteractionRules;
110 // uno interface
111 public:
115 @interface XInteractionHandler
116 @short called from outside to handle a problem
117 @descr We filter the incoming interactions. some of them
118 will be forwarded to the generic UI interaction handler.
119 So we must not implement it twice. Some other ones
120 will be aborted only.
122 @threadsafe yes
124 virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
125 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
129 @interface XInteractionHandler2
130 @short called from outside to handle a problem
131 @descr We filter the incoming interactions. some of them
132 will be forwarded to the generic UI interaction handler.
133 So we must not implement it twice. Some other ones
134 will be aborted only.
136 @threadsafe yes
138 virtual sal_Bool SAL_CALL handleInteractionRequest( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest )
139 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 @interface XInterface
144 @short called to query another interface of the component
145 @descr Will allow to query for XInteractionHandler2 if and only if m_xHandler supports this interface, too.
147 @threadsafe yes
149 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType )
150 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 // c++ interface
153 public:
157 @short ctor to guarantee right initialized instances of this class
158 @descr It uses the given uno service manager to create the global
159 generic UI interaction handler for later internal using.
161 @param xSMGR
162 uno service manager for creating services internally
164 @threadsafe not necessary
166 PreventDuplicateInteraction(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
170 @short dtor to free used memory.
172 virtual ~PreventDuplicateInteraction();
176 @short set the outside interaction handler, which must be used internally
177 if the interaction will not be blocked by the set list of rules.
179 @note This overwrites the settings of e.g. useDefaultUUIHandler()!
181 @param xHandler
182 the new interaction handler
184 void setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler);
188 @short instead of setting an outside interaction handler, this method
189 make sure the default UUI interaction handler of the office is used.
191 @note This overwrites the settings of e.g. setHandler()!
193 void useDefaultUUIHandler();
197 @short add a new interaction to the list of interactions, which
198 must be handled by this helper.
200 @descr This method must be called immediately after a new instance of this helper was
201 created. Without such list of InteractionRules, this instances does nothing!
202 On the other side there is no possibility to remove rules.
203 So the same instance can't be used within different transactions.
204 It's a OneWay-object .-)
206 @param aInteractionInfo
207 describe the type of interaction, hos often it can be called etcpp.
209 @threadsafe yes
211 void addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo);
215 @short return the info struct for the specified interaction.
217 @param aInteraction
218 specify the interaction.
220 @param pReturn
221 provides information about:
222 - the count how often this interaction was handled during the
223 lifetime of this helper.
224 - the interaction itself, so it can be analyzed further
226 @return [boolean]
227 true if the queried interaction could be found.
228 false otherwise.
230 @threadsafe yes
232 bool getInteractionInfo(const css::uno::Type& aInteraction,
233 PreventDuplicateInteraction::InteractionInfo* pReturn ) const;
236 } // namespace framework
238 #endif // INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */