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

           Branch data     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                 :            : #include "framework/preventduplicateinteraction.hxx"
      21                 :            : 
      22                 :            : #include <com/sun/star/task/XInteractionAbort.hpp>
      23                 :            : #include <com/sun/star/task/XInteractionRetry.hpp>
      24                 :            : 
      25                 :            : namespace framework{
      26                 :            : 
      27                 :            : namespace css = ::com::sun::star;
      28                 :            : 
      29                 :            : #define IMPLEMENTATIONNAME_UIINTERACTIONHANDLER                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.uui.UUIInteractionHandler"))
      30                 :            : 
      31                 :          0 : PreventDuplicateInteraction::PreventDuplicateInteraction(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
      32                 :            :     : ThreadHelpBase2()
      33 [ #  # ][ #  # ]:          0 :     , m_xSMGR(xSMGR)
      34                 :            : {
      35                 :          0 : }
      36                 :            : 
      37                 :            : //_________________________________________________________________________________________________________________
      38                 :            : 
      39         [ #  # ]:          0 : PreventDuplicateInteraction::~PreventDuplicateInteraction()
      40                 :            : {
      41         [ #  # ]:          0 : }
      42                 :            : 
      43                 :            : //_________________________________________________________________________________________________________________
      44                 :            : 
      45                 :          0 : void PreventDuplicateInteraction::setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
      46                 :            : {
      47                 :            :     // SAFE ->
      48         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      49         [ #  # ]:          0 :     m_xHandler = xHandler;
      50 [ #  # ][ #  # ]:          0 :     aLock.clear();
      51                 :            :     // <- SAFE
      52                 :          0 : }
      53                 :            : 
      54                 :            : //_________________________________________________________________________________________________________________
      55                 :            : 
      56                 :          0 : void PreventDuplicateInteraction::useDefaultUUIHandler()
      57                 :            : {
      58                 :            :     // SAFE ->
      59         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      60                 :          0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
      61         [ #  # ]:          0 :     aLock.clear();
      62                 :            :     // <- SAFE
      63                 :            : 
      64                 :            :     css::uno::Reference< css::task::XInteractionHandler > xHandler(
      65         [ #  # ]:          0 :                             xSMGR->createInstance(IMPLEMENTATIONNAME_UIINTERACTIONHANDLER),
      66 [ #  # ][ #  # ]:          0 :                             css::uno::UNO_QUERY_THROW);
                 [ #  # ]
      67                 :            : 
      68                 :            :     // SAFE ->
      69         [ #  # ]:          0 :     aLock.reset();
      70         [ #  # ]:          0 :     m_xHandler = xHandler;
      71 [ #  # ][ #  # ]:          0 :     aLock.clear();
      72                 :            :     // <- SAFE
      73                 :          0 : }
      74                 :            : 
      75                 :            : //_________________________________________________________________________________________________________________
      76                 :          0 : css::uno::Any SAL_CALL PreventDuplicateInteraction::queryInterface( const css::uno::Type& aType )
      77                 :            :     throw (css::uno::RuntimeException)
      78                 :            : {
      79         [ #  # ]:          0 :     if ( aType.equals( XInteractionHandler2::static_type() ) )
      80                 :            :     {
      81         [ #  # ]:          0 :         ::osl::ResettableMutexGuard aLock(m_aLock);
      82         [ #  # ]:          0 :         css::uno::Reference< css::task::XInteractionHandler2 > xHandler( m_xHandler, css::uno::UNO_QUERY );
      83         [ #  # ]:          0 :         if ( !xHandler.is() )
      84 [ #  # ][ #  # ]:          0 :             return css::uno::Any();
                 [ #  # ]
      85                 :            :     }
      86                 :          0 :     return ::cppu::WeakImplHelper1< css::task::XInteractionHandler2 >::queryInterface( aType );
      87                 :            : }
      88                 :            : 
      89                 :            : //_________________________________________________________________________________________________________________
      90                 :            : 
      91                 :          0 : void SAL_CALL PreventDuplicateInteraction::handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
      92                 :            :     throw(css::uno::RuntimeException)
      93                 :            : {
      94 [ #  # ][ #  # ]:          0 :     css::uno::Any aRequest  = xRequest->getRequest();
      95                 :          0 :     sal_Bool      bHandleIt = sal_True;
      96                 :            : 
      97                 :            :     // SAFE ->
      98         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      99                 :            : 
     100                 :          0 :     InteractionList::iterator pIt;
     101   [ #  #  #  # ]:          0 :     for (  pIt  = m_lInteractionRules.begin();
                 [ #  # ]
     102                 :          0 :            pIt != m_lInteractionRules.end()  ;
     103                 :            :          ++pIt                               )
     104                 :            :     {
     105         [ #  # ]:          0 :         InteractionInfo& rInfo = *pIt;
     106                 :            : 
     107         [ #  # ]:          0 :         if (aRequest.isExtractableTo(rInfo.m_aInteraction))
     108                 :            :         {
     109                 :          0 :             ++rInfo.m_nCallCount;
     110         [ #  # ]:          0 :             rInfo.m_xRequest = xRequest;
     111                 :          0 :             bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount);
     112                 :          0 :             break;
     113                 :            :         }
     114                 :            :     }
     115                 :            : 
     116                 :          0 :     css::uno::Reference< css::task::XInteractionHandler > xHandler = m_xHandler;
     117                 :            : 
     118         [ #  # ]:          0 :     aLock.clear();
     119                 :            :     // <- SAFE
     120                 :            : 
     121   [ #  #  #  # ]:          0 :     if (
                 [ #  # ]
     122                 :            :         (bHandleIt    ) &&
     123                 :          0 :         (xHandler.is())
     124                 :            :        )
     125                 :            :     {
     126 [ #  # ][ #  # ]:          0 :         xHandler->handle(xRequest);
     127                 :            :     }
     128                 :            :     else
     129                 :            :     {
     130 [ #  # ][ #  # ]:          0 :         const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
     131                 :          0 :         sal_Int32 c = lContinuations.getLength();
     132                 :          0 :         sal_Int32 i = 0;
     133         [ #  # ]:          0 :         for (i=0; i<c; ++i)
     134                 :            :         {
     135         [ #  # ]:          0 :             css::uno::Reference< css::task::XInteractionAbort > xAbort(lContinuations[i], css::uno::UNO_QUERY);
     136         [ #  # ]:          0 :             if (xAbort.is())
     137                 :            :             {
     138 [ #  # ][ #  # ]:          0 :                 xAbort->select();
     139                 :            :                 break;
     140                 :            :             }
     141 [ #  # ][ #  # ]:          0 :         }
     142         [ #  # ]:          0 :     }
     143                 :          0 : }
     144                 :            : 
     145                 :            : //_________________________________________________________________________________________________________________
     146                 :            : 
     147                 :          0 : ::sal_Bool SAL_CALL PreventDuplicateInteraction::handleInteractionRequest( const css::uno::Reference< css::task::XInteractionRequest >& xRequest )
     148                 :            :             throw (css::uno::RuntimeException)
     149                 :            : {
     150 [ #  # ][ #  # ]:          0 :     css::uno::Any aRequest  = xRequest->getRequest();
     151                 :          0 :     sal_Bool      bHandleIt = sal_True;
     152                 :            : 
     153                 :            :     // SAFE ->
     154         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     155                 :            : 
     156                 :          0 :     InteractionList::iterator pIt;
     157   [ #  #  #  # ]:          0 :     for (  pIt  = m_lInteractionRules.begin();
                 [ #  # ]
     158                 :          0 :            pIt != m_lInteractionRules.end()  ;
     159                 :            :          ++pIt                               )
     160                 :            :     {
     161         [ #  # ]:          0 :         InteractionInfo& rInfo = *pIt;
     162                 :            : 
     163         [ #  # ]:          0 :         if (aRequest.isExtractableTo(rInfo.m_aInteraction))
     164                 :            :         {
     165                 :          0 :             ++rInfo.m_nCallCount;
     166         [ #  # ]:          0 :             rInfo.m_xRequest = xRequest;
     167                 :          0 :             bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount);
     168                 :          0 :             break;
     169                 :            :         }
     170                 :            :     }
     171                 :            : 
     172         [ #  # ]:          0 :     css::uno::Reference< css::task::XInteractionHandler2 > xHandler( m_xHandler, css::uno::UNO_QUERY );
     173                 :            :     OSL_ENSURE( xHandler.is() || !m_xHandler.is(),
     174                 :            :         "PreventDuplicateInteraction::handleInteractionRequest: inconsistency!" );
     175                 :            : 
     176         [ #  # ]:          0 :     aLock.clear();
     177                 :            :     // <- SAFE
     178                 :            : 
     179   [ #  #  #  # ]:          0 :     if (
                 [ #  # ]
     180                 :            :         (bHandleIt    ) &&
     181                 :          0 :         (xHandler.is())
     182                 :            :        )
     183                 :            :     {
     184 [ #  # ][ #  # ]:          0 :         return xHandler->handleInteractionRequest(xRequest);
     185                 :            :     }
     186                 :            :     else
     187                 :            :     {
     188 [ #  # ][ #  # ]:          0 :         const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
     189                 :          0 :         sal_Int32 c = lContinuations.getLength();
     190                 :          0 :         sal_Int32 i = 0;
     191         [ #  # ]:          0 :         for (i=0; i<c; ++i)
     192                 :            :         {
     193         [ #  # ]:          0 :             css::uno::Reference< css::task::XInteractionAbort > xAbort(lContinuations[i], css::uno::UNO_QUERY);
     194         [ #  # ]:          0 :             if (xAbort.is())
     195                 :            :             {
     196 [ #  # ][ #  # ]:          0 :                 xAbort->select();
     197                 :            :                 break;
     198                 :            :             }
     199 [ #  # ][ #  # ]:          0 :         }
     200                 :            :     }
     201         [ #  # ]:          0 :     return false;
     202                 :            : }
     203                 :            : 
     204                 :            : //_________________________________________________________________________________________________________________
     205                 :            : 
     206                 :          0 : void PreventDuplicateInteraction::addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo)
     207                 :            : {
     208                 :            :     // SAFE ->
     209         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     210                 :            : 
     211                 :          0 :     InteractionList::iterator pIt;
     212   [ #  #  #  # ]:          0 :     for (  pIt  = m_lInteractionRules.begin();
                 [ #  # ]
     213                 :          0 :            pIt != m_lInteractionRules.end()  ;
     214                 :            :          ++pIt                               )
     215                 :            :     {
     216         [ #  # ]:          0 :         InteractionInfo& rInfo = *pIt;
     217         [ #  # ]:          0 :         if (rInfo.m_aInteraction == aInteractionInfo.m_aInteraction)
     218                 :            :         {
     219                 :          0 :             rInfo.m_nMaxCount  = aInteractionInfo.m_nMaxCount ;
     220                 :          0 :             rInfo.m_nCallCount = aInteractionInfo.m_nCallCount;
     221                 :          0 :             return;
     222                 :            :         }
     223                 :            :     }
     224                 :            : 
     225         [ #  # ]:          0 :     m_lInteractionRules.push_back(aInteractionInfo);
     226                 :            : 
     227 [ #  # ][ #  # ]:          0 :     aLock.clear();
                 [ #  # ]
     228                 :            :     // <- SAFE
     229                 :            : }
     230                 :            : 
     231                 :            : //_________________________________________________________________________________________________________________
     232                 :            : 
     233                 :          0 : sal_Bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type&                               aInteraction,
     234                 :            :                                                                PreventDuplicateInteraction::InteractionInfo* pReturn     ) const
     235                 :            : {
     236                 :            :     // SAFE ->
     237         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     238                 :            : 
     239                 :          0 :     PreventDuplicateInteraction::InteractionList::const_iterator pIt;
     240   [ #  #  #  # ]:          0 :     for (  pIt  = m_lInteractionRules.begin();
                 [ #  # ]
     241                 :          0 :            pIt != m_lInteractionRules.end()  ;
     242                 :            :          ++pIt                               )
     243                 :            :     {
     244         [ #  # ]:          0 :         const PreventDuplicateInteraction::InteractionInfo& rInfo = *pIt;
     245         [ #  # ]:          0 :         if (rInfo.m_aInteraction == aInteraction)
     246                 :            :         {
     247         [ #  # ]:          0 :             *pReturn = rInfo;
     248                 :          0 :             return sal_True;
     249                 :            :         }
     250                 :            :     }
     251                 :            : 
     252         [ #  # ]:          0 :     aLock.clear();
     253                 :            :     // <- SAFE
     254                 :            : 
     255         [ #  # ]:          0 :     return sal_False;
     256                 :            : }
     257                 :            : 
     258                 :            : } // namespace framework
     259                 :            : 
     260                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10