LCOV - code coverage report
Current view: top level - framework/inc/framework - preventduplicateinteraction.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 5 0.0 %
Date: 2012-08-25 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10