LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/framework - preventduplicateinteraction.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 8 0.0 %
Date: 2013-07-09 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_
      21             : #define __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_
      22             : 
      23             : #include <framework/fwedllapi.h>
      24             : 
      25             : #include <vector>
      26             : 
      27             : #include <com/sun/star/task/XInteractionHandler2.hpp>
      28             : #include <com/sun/star/task/XInteractionRequest.hpp>
      29             : 
      30             : #include <cppuhelper/implbase1.hxx>
      31             : 
      32             : namespace framework{
      33             : 
      34             : /**
      35             :     @short      Prevent us from showing the same interaction more then once during
      36             :                 the same transaction.
      37             : 
      38             :     @descr      Every interaction provided to this helper will be safed ... handled by the internal
      39             :                 used UUIInteractionHandler (!) and never be handled a second time!
      40             : 
      41             :                 On the other side there exists some interactions, which allow a retry.
      42             :                 So this helper allow to set a list of interactions combined with a retry value.
      43             :  */
      44           0 : struct ThreadHelpBase2
      45             : {
      46             :     public:
      47             :         mutable ::osl::Mutex m_aLock;
      48             : };
      49             : 
      50             : class FWE_DLLPUBLIC PreventDuplicateInteraction : private ThreadHelpBase2
      51             :                                     ,public ::cppu::WeakImplHelper1< css::task::XInteractionHandler2 >
      52             : {
      53             :     //_____________________________________
      54             :     // structs, types etcp.
      55             :     public:
      56             : 
      57           0 :         struct InteractionInfo
      58             :         {
      59             :             public:
      60             :                 /// describe the interaction.
      61             :                 css::uno::Type m_aInteraction;
      62             :                 /// after max count was reached this interaction will be blocked.
      63             :                 sal_Int32 m_nMaxCount;
      64             :                 /// count how often this interaction was called.
      65             :                 sal_Int32 m_nCallCount;
      66             :                 /** hold the last intercepted request (matching the set interaction type) alive
      67             :                 so it can be used for further checks */
      68             :                 css::uno::Reference< css::task::XInteractionRequest > m_xRequest;
      69             : 
      70             :             public:
      71             : 
      72           0 :                 InteractionInfo(const css::uno::Type& aInteraction,
      73             :                                       sal_Int32       nMaxCount   )
      74             :                     : m_aInteraction(aInteraction)
      75             :                     , m_nMaxCount   (nMaxCount   )
      76           0 :                     , m_nCallCount  (0           )
      77           0 :                 {}
      78             : 
      79           0 :                 InteractionInfo(const InteractionInfo& aCopy)
      80             :                     : m_aInteraction(aCopy.m_aInteraction)
      81             :                     , m_nMaxCount   (aCopy.m_nMaxCount   )
      82             :                     , m_nCallCount  (aCopy.m_nCallCount  )
      83           0 :                     , m_xRequest    (aCopy.m_xRequest    )
      84           0 :                 {}
      85             :         };
      86             : 
      87             :         typedef ::std::vector< InteractionInfo > InteractionList;
      88             : 
      89             :     //_____________________________________
      90             :     // member
      91             :     private:
      92             : 
      93             :         /// Used to create needed uno services at runtime.
      94             :         css::uno::Reference< css::uno::XComponentContext > m_xContext;
      95             : 
      96             :         /** The outside interaction handler, which is used to handle every incoming interaction,
      97             :             if it's not blocked. */
      98             :         css::uno::Reference< css::task::XInteractionHandler > m_xHandler;
      99             : 
     100             :         /** This list describe which and how incoming interactions must be handled.
     101             :             Further it contains all collected information after this interaction
     102             :             object was used.*/
     103             :         InteractionList m_lInteractionRules;
     104             : 
     105             :     //_____________________________________
     106             :     // uno interface
     107             :     public:
     108             : 
     109             :         //_________________________________
     110             :         /**
     111             :             @interface  XInteractionHandler
     112             :             @short      called from outside to handle a problem
     113             :             @descr      We filter the incoming interactions. some of them
     114             :                         will be forwarded to the generic UI interaction handler.
     115             :                         So we must not implement it twice. Some other ones
     116             :                         will be aborted only.
     117             : 
     118             :             @threadsafe yes
     119             :         */
     120             :         virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
     121             :             throw(css::uno::RuntimeException);
     122             : 
     123             :         //_________________________________
     124             :         /**
     125             :             @interface  XInteractionHandler2
     126             :             @short      called from outside to handle a problem
     127             :             @descr      We filter the incoming interactions. some of them
     128             :                         will be forwarded to the generic UI interaction handler.
     129             :                         So we must not implement it twice. Some other ones
     130             :                         will be aborted only.
     131             : 
     132             :             @threadsafe yes
     133             :         */
     134             :         virtual ::sal_Bool SAL_CALL handleInteractionRequest( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest )
     135             :             throw (::com::sun::star::uno::RuntimeException);
     136             : 
     137             :         //_________________________________
     138             :         /**
     139             :             @interface  XInterface
     140             :             @short      called to query another interface of the component
     141             :             @descr      Will allow to query for XInteractionHandler2 if and only if m_xHandler supports this interface, too.
     142             : 
     143             :             @threadsafe yes
     144             :         */
     145             :         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType )
     146             :             throw (::com::sun::star::uno::RuntimeException);
     147             :     //_____________________________________
     148             :     // c++ interface
     149             :     public:
     150             : 
     151             :         //_________________________________
     152             :         /**
     153             :             @short      ctor to guarantee right initialized instances of this class
     154             :             @descr      It uses the given uno service manager to create the global
     155             :                         generic UI interaction handler for later internal using.
     156             : 
     157             :             @param      xSMGR
     158             :                             uno service manager for creating services internaly
     159             : 
     160             :             @threadsafe not neccessary
     161             :         */
     162             :         PreventDuplicateInteraction(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
     163             : 
     164             :         //_________________________________
     165             :         /**
     166             :             @short      dtor to free used memory.
     167             :          */
     168             :         virtual ~PreventDuplicateInteraction();
     169             : 
     170             :         //_________________________________
     171             :         /**
     172             :             @short      set the outside interaction handler, which must be used internaly
     173             :                         if the interaction will not be blocked by the set list of rules.
     174             : 
     175             :             @note       This overwrites the settings of e.g. useDefaultUUIHandler()!
     176             : 
     177             :             @param      xHandler
     178             :                         the new interaction handler
     179             :          */
     180             :         virtual void setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler);
     181             : 
     182             :         //_________________________________
     183             :         /**
     184             :             @short      instead of setting an outside interaction handler, this method
     185             :                         make sure the default UUI interaction handler of the office is used.
     186             : 
     187             :             @note       This overwrites the settings of e.g. setHandler()!
     188             :          */
     189             :         virtual void useDefaultUUIHandler();
     190             : 
     191             :         //_________________________________
     192             :         /**
     193             :             @short      add a new interaction to the list of interactions, which
     194             :                         must be handled by this helper.
     195             : 
     196             :             @descr      This method must be called immediately after a new instance of this helper was
     197             :                         created. Without such list of InteractionRules, this instances does nothing!
     198             :                         On the other side there is no possibility to remove rules.
     199             :                         So the same instance cant be used within different transactions.
     200             :                         It's a OneWay-object .-)
     201             : 
     202             :             @param      aInteractionInfo
     203             :                         describe the type of interaction, hos often it can be called etcpp.
     204             : 
     205             :             @threadsafe yes
     206             :         */
     207             :         virtual void addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo);
     208             : 
     209             :         //_________________________________
     210             :         /**
     211             :             @short      return the info struct for the specified interaction.
     212             : 
     213             :             @param      aInteraction
     214             :                         specify the interaction.
     215             : 
     216             :             @param      pReturn
     217             :                         provides information about:
     218             :                         - the count how often this interaction was handled during the
     219             :                           lifetime of this helper.
     220             :                         - the interaction itself, so it can be analyzed further
     221             : 
     222             :             @return     [boolean]
     223             :                         sal_True if the queried interaction could be found.
     224             :                         sal_False otherwise.
     225             : 
     226             :             @threadsafe yes
     227             :         */
     228             :         virtual sal_Bool getInteractionInfo(const css::uno::Type&                               aInteraction,
     229             :                                                   PreventDuplicateInteraction::InteractionInfo* pReturn     ) const;
     230             : };
     231             : 
     232             : } // namespace framework
     233             : 
     234             : #endif // #ifndef __FRAMEWORK_INTERACTION_PREVENTDUPLICATEINTERACTION_HXX_
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10