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

Generated by: LCOV version 1.10