LCOV - code coverage report
Current view: top level - include/framework - preventduplicateinteraction.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 8 0.0 %
Date: 2014-04-14 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 INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
      21             : #define INCLUDED_FRAMEWORK_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 com { namespace sun { namespace star { namespace uno {
      33             :     class XComponentContext;
      34             : } } } }
      35             : 
      36             : namespace framework{
      37             : 
      38             : /**
      39             :     @short      Prevent us from showing the same interaction more then once during
      40             :                 the same transaction.
      41             : 
      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!
      44             : 
      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.
      47             :  */
      48           0 : struct ThreadHelpBase2
      49             : {
      50             :     public:
      51             :         mutable ::osl::Mutex m_aLock;
      52             : };
      53             : 
      54             : class FWE_DLLPUBLIC PreventDuplicateInteraction : private ThreadHelpBase2
      55             :                                     ,public ::cppu::WeakImplHelper1< css::task::XInteractionHandler2 >
      56             : {
      57             : 
      58             :     // structs, types etcp.
      59             :     public:
      60             : 
      61           0 :         struct InteractionInfo
      62             :         {
      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;
      73             : 
      74             :             public:
      75             : 
      76           0 :                 InteractionInfo(const css::uno::Type& aInteraction,
      77             :                                       sal_Int32       nMaxCount   )
      78             :                     : m_aInteraction(aInteraction)
      79             :                     , m_nMaxCount   (nMaxCount   )
      80           0 :                     , m_nCallCount  (0           )
      81           0 :                 {}
      82             : 
      83           0 :                 InteractionInfo(const InteractionInfo& aCopy)
      84             :                     : m_aInteraction(aCopy.m_aInteraction)
      85             :                     , m_nMaxCount   (aCopy.m_nMaxCount   )
      86             :                     , m_nCallCount  (aCopy.m_nCallCount  )
      87           0 :                     , m_xRequest    (aCopy.m_xRequest    )
      88           0 :                 {}
      89             :         };
      90             : 
      91             :         typedef ::std::vector< InteractionInfo > InteractionList;
      92             : 
      93             : 
      94             :     // member
      95             :     private:
      96             : 
      97             :         /// Used to create needed uno services at runtime.
      98             :         css::uno::Reference< css::uno::XComponentContext > m_xContext;
      99             : 
     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;
     103             : 
     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;
     108             : 
     109             : 
     110             :     // uno interface
     111             :     public:
     112             : 
     113             : 
     114             :         /**
     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.
     121             : 
     122             :             @threadsafe yes
     123             :         */
     124             :         virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
     125             :             throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     126             : 
     127             : 
     128             :         /**
     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.
     135             : 
     136             :             @threadsafe yes
     137             :         */
     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;
     140             : 
     141             : 
     142             :         /**
     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.
     146             : 
     147             :             @threadsafe yes
     148             :         */
     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;
     151             : 
     152             :     // c++ interface
     153             :     public:
     154             : 
     155             : 
     156             :         /**
     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.
     160             : 
     161             :             @param      xSMGR
     162             :                             uno service manager for creating services internally
     163             : 
     164             :             @threadsafe not necessary
     165             :         */
     166             :         PreventDuplicateInteraction(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
     167             : 
     168             : 
     169             :         /**
     170             :             @short      dtor to free used memory.
     171             :          */
     172             :         virtual ~PreventDuplicateInteraction();
     173             : 
     174             : 
     175             :         /**
     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.
     178             : 
     179             :             @note       This overwrites the settings of e.g. useDefaultUUIHandler()!
     180             : 
     181             :             @param      xHandler
     182             :                         the new interaction handler
     183             :          */
     184             :         virtual void setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler);
     185             : 
     186             : 
     187             :         /**
     188             :             @short      instead of setting an outside interaction handler, this method
     189             :                         make sure the default UUI interaction handler of the office is used.
     190             : 
     191             :             @note       This overwrites the settings of e.g. setHandler()!
     192             :          */
     193             :         virtual void useDefaultUUIHandler();
     194             : 
     195             : 
     196             :         /**
     197             :             @short      add a new interaction to the list of interactions, which
     198             :                         must be handled by this helper.
     199             : 
     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 cant be used within different transactions.
     204             :                         It's a OneWay-object .-)
     205             : 
     206             :             @param      aInteractionInfo
     207             :                         describe the type of interaction, hos often it can be called etcpp.
     208             : 
     209             :             @threadsafe yes
     210             :         */
     211             :         virtual void addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo);
     212             : 
     213             : 
     214             :         /**
     215             :             @short      return the info struct for the specified interaction.
     216             : 
     217             :             @param      aInteraction
     218             :                         specify the interaction.
     219             : 
     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
     225             : 
     226             :             @return     [boolean]
     227             :                         true if the queried interaction could be found.
     228             :                         false otherwise.
     229             : 
     230             :             @threadsafe yes
     231             :         */
     232             :         virtual bool getInteractionInfo(const css::uno::Type&                               aInteraction,
     233             :                                                   PreventDuplicateInteraction::InteractionInfo* pReturn     ) const;
     234             : };
     235             : 
     236             : } // namespace framework
     237             : 
     238             : #endif // INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10