1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_ 25 #define __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_ 26 27 #include <framework/fwedllapi.h> 28 //_________________________________________________________________________________________________________________ 29 // my own includes 30 //_________________________________________________________________________________________________________________ 31 32 #include <vector> 33 34 //_________________________________________________________________________________________________________________ 35 // interface includes 36 //_________________________________________________________________________________________________________________ 37 #include <com/sun/star/task/XInteractionHandler2.hpp> 38 #include <com/sun/star/task/XInteractionRequest.hpp> 39 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 40 41 //_________________________________________________________________________________________________________________ 42 // other includes 43 //_________________________________________________________________________________________________________________ 44 #include <cppuhelper/implbase1.hxx> 45 46 //_________________________________________________________________________________________________________________ 47 // namespace 48 //_________________________________________________________________________________________________________________ 49 50 namespace framework{ 51 52 #ifdef css 53 #error "Conflict during define of namespace alias ..." 54 #else 55 #define css ::com::sun::star 56 #endif 57 58 //_________________________________________________________________________________________________________________ 59 // exported const 60 //_________________________________________________________________________________________________________________ 61 62 //_________________________________________________________________________________________________________________ 63 // exported definitions 64 //_________________________________________________________________________________________________________________ 65 66 /** 67 @short Prevent us from showing the same interaction more then once during 68 the same transaction. 69 70 @descr Every interaction provided to this helper will be safed ... handled by the internal 71 used UUIInteractionHandler (!) and never be handled a second time! 72 73 On the other side there exists some interactions, which allow a retry. 74 So this helper allow to set a list of interactions combined with a retry value. 75 */ 76 struct ThreadHelpBase2 77 { 78 public: 79 mutable ::osl::Mutex m_aLock; 80 }; 81 82 class FWE_DLLPUBLIC PreventDuplicateInteraction : private ThreadHelpBase2 83 ,public ::cppu::WeakImplHelper1< css::task::XInteractionHandler2 > 84 { 85 //_____________________________________ 86 // structs, types etcp. 87 public: 88 89 struct InteractionInfo 90 { 91 public: 92 /// describe the interaction. 93 css::uno::Type m_aInteraction; 94 /// after max count was reached this interaction will be blocked. 95 sal_Int32 m_nMaxCount; 96 /// count how often this interaction was called. 97 sal_Int32 m_nCallCount; 98 /** hold the last intercepted request (matching the set interaction type) alive 99 so it can be used for further checks */ 100 css::uno::Reference< css::task::XInteractionRequest > m_xRequest; 101 102 public: 103 104 InteractionInfo(const css::uno::Type& aInteraction, 105 sal_Int32 nMaxCount ) 106 : m_aInteraction(aInteraction) 107 , m_nMaxCount (nMaxCount ) 108 , m_nCallCount (0 ) 109 {} 110 111 InteractionInfo(const InteractionInfo& aCopy) 112 : m_aInteraction(aCopy.m_aInteraction) 113 , m_nMaxCount (aCopy.m_nMaxCount ) 114 , m_nCallCount (aCopy.m_nCallCount ) 115 , m_xRequest (aCopy.m_xRequest ) 116 {} 117 }; 118 119 typedef ::std::vector< InteractionInfo > InteractionList; 120 121 //_____________________________________ 122 // member 123 private: 124 125 /// Used to create needed uno services at runtime. 126 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 127 128 /** The outside interaction handler, which is used to handle every incoming interaction, 129 if it's not blocked. */ 130 css::uno::Reference< css::task::XInteractionHandler > m_xHandler; 131 132 /** This list describe which and how incoming interactions must be handled. 133 Further it contains all collected informations after this interaction 134 object was used.*/ 135 InteractionList m_lInteractionRules; 136 137 //_____________________________________ 138 // uno interface 139 public: 140 141 //_________________________________ 142 /** 143 @interface XInteractionHandler 144 @short called from outside to handle a problem 145 @descr We filter the incoming interactions. some of them 146 will be forwarded to the generic UI interaction handler. 147 So we must not implement it twice. Some other ones 148 will be aborted only. 149 150 @threadsafe yes 151 */ 152 virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest) 153 throw(css::uno::RuntimeException); 154 155 //_________________________________ 156 /** 157 @interface XInteractionHandler2 158 @short called from outside to handle a problem 159 @descr We filter the incoming interactions. some of them 160 will be forwarded to the generic UI interaction handler. 161 So we must not implement it twice. Some other ones 162 will be aborted only. 163 164 @threadsafe yes 165 */ 166 virtual ::sal_Bool SAL_CALL handleInteractionRequest( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest ) 167 throw (::com::sun::star::uno::RuntimeException); 168 169 //_________________________________ 170 /** 171 @interface XInterface 172 @short called to query another interface of the component 173 @descr Will allow to query for XInteractionHandler2 if and only if m_xHandler supports this interface, too. 174 175 @threadsafe yes 176 */ 177 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) 178 throw (::com::sun::star::uno::RuntimeException); 179 //_____________________________________ 180 // c++ interface 181 public: 182 183 //_________________________________ 184 /** 185 @short ctor to guarantee right initialized instances of this class 186 @descr It uses the given uno service manager to create the global 187 generic UI interaction handler for later internal using. 188 189 @param xSMGR 190 uno service manager for creating services internaly 191 192 @threadsafe not necessary 193 */ 194 PreventDuplicateInteraction(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); 195 196 //_________________________________ 197 /** 198 @short dtor to free used memory. 199 */ 200 virtual ~PreventDuplicateInteraction(); 201 202 //_________________________________ 203 /** 204 @short set the outside interaction handler, which must be used internaly 205 if the interaction will not be blocked by the set list of rules. 206 207 @note This overwrites the settings of e.g. useDefaultUUIHandler()! 208 209 @param xHandler 210 the new interaction handler 211 */ 212 virtual void setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler); 213 214 //_________________________________ 215 /** 216 @short instead of setting an outside interaction handler, this method 217 make sure the default UUI interaction handler of the office is used. 218 219 @note This overwrites the settings of e.g. setHandler()! 220 */ 221 virtual void useDefaultUUIHandler(); 222 223 //_________________________________ 224 /** 225 @short add a new interaction to the list of interactions, which 226 must be handled by this helper. 227 228 @descr This method must be called immediately after a new instance of this helper was 229 created. Without such list of InteractionRules, this instances does nothing! 230 On the other side there is no possibility to remove rules. 231 So the same instance can't be used within different transactions. 232 It's a OneWay-object .-) 233 234 @param aInteractionInfo 235 describe the type of interaction, hos often it can be called etcpp. 236 237 @threadsafe yes 238 */ 239 virtual void addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo); 240 241 //_________________________________ 242 /** 243 @short return the info struct for the specified interaction. 244 245 @param aInteraction 246 specify the interaction. 247 248 @param pReturn 249 provides informations about: 250 - the count how often this interaction was handled during the 251 lifetime of this helper. 252 - the interaction itself, so it can be analyzed further 253 254 @return [boolean] 255 sal_True if the queried interaction could be found. 256 sal_False otherwise. 257 258 @threadsafe yes 259 */ 260 virtual sal_Bool getInteractionInfo(const css::uno::Type& aInteraction, 261 PreventDuplicateInteraction::InteractionInfo* pReturn ) const; 262 }; 263 264 #undef css 265 266 } // namespace framework 267 268 #endif // #ifndef __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_ 269