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

Generated by: LCOV version 1.11