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