LCOV - code coverage report
Current view: top level - ucbhelper/source/client - interceptedinteraction.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 45 61 73.8 %
Date: 2014-11-03 Functions: 7 8 87.5 %
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 <ucbhelper/interceptedinteraction.hxx>
      21             : 
      22             : 
      23             : namespace ucbhelper{
      24             : 
      25       10553 : InterceptedInteraction::InterceptedInteraction()
      26             : {
      27       10553 : }
      28             : 
      29       10553 : void InterceptedInteraction::setInterceptedHandler(const css::uno::Reference< css::task::XInteractionHandler >& xInterceptedHandler)
      30             : {
      31       10553 :     m_xInterceptedHandler = xInterceptedHandler;
      32       10553 : }
      33             : 
      34       16436 : void InterceptedInteraction::setInterceptions(const ::std::vector< InterceptedRequest >& lInterceptions)
      35             : {
      36       16436 :     m_lInterceptions = lInterceptions;
      37       16436 : }
      38             : 
      39           0 : InterceptedInteraction::EInterceptionState InterceptedInteraction::intercepted(
      40             :     const InterceptedRequest&,
      41             :     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >&)
      42             : {
      43             :     // default behaviour! see impl_interceptRequest() for further information ...
      44           0 :     return E_NOT_INTERCEPTED;
      45             : }
      46             : 
      47         386 : css::uno::Reference< css::task::XInteractionContinuation > InterceptedInteraction::extractContinuation(const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >& lContinuations,
      48             :                                                                                                        const css::uno::Type&                                                                   aType         )
      49             : {
      50         386 :     const css::uno::Reference< css::task::XInteractionContinuation >* pContinuations = lContinuations.getConstArray();
      51             : 
      52         386 :     sal_Int32 c = lContinuations.getLength();
      53         386 :     sal_Int32 i = 0;
      54             : 
      55         386 :     for (i=0; i<c; ++i)
      56             :     {
      57         386 :         css::uno::Reference< css::uno::XInterface > xCheck(pContinuations[i], css::uno::UNO_QUERY);
      58         386 :         if (xCheck->queryInterface(aType).hasValue())
      59         386 :             return pContinuations[i];
      60           0 :     }
      61             : 
      62           0 :     return css::uno::Reference< css::task::XInteractionContinuation >();
      63             : }
      64             : 
      65         828 : void SAL_CALL InterceptedInteraction::handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
      66             :     throw(css::uno::RuntimeException, std::exception)
      67             : {
      68         828 :     impl_handleDefault(xRequest);
      69         828 : }
      70             : 
      71         828 : void InterceptedInteraction::impl_handleDefault(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
      72             : {
      73         828 :     EInterceptionState eState = impl_interceptRequest(xRequest);
      74             : 
      75         828 :     switch(eState)
      76             :     {
      77             :         case E_NOT_INTERCEPTED:
      78             :         {
      79             :             // Non of the intercepted requests match to the given one.
      80             :             // => forward request to the internal wrapped handler - if there is one.
      81         442 :             if (m_xInterceptedHandler.is())
      82           0 :                 m_xInterceptedHandler->handle(xRequest);
      83             :         }
      84         442 :         break;
      85             : 
      86             :         case E_NO_CONTINUATION_FOUND:
      87             :         {
      88             :             // Runtime error! The defined continuation could not be located
      89             :             // inside the set of available containuations of the incoming request.
      90             :             // Whats wrong - the interception list or the request?
      91             :             OSL_FAIL("InterceptedInteraction::handle()\nCould intercept this interaction request - but can't locate the right continuation!");
      92             :         }
      93           0 :         break;
      94             : 
      95             :         case E_INTERCEPTED:
      96         386 :         break;
      97             :     }
      98         828 : }
      99             : 
     100         828 : InterceptedInteraction::EInterceptionState InterceptedInteraction::impl_interceptRequest(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
     101             : {
     102         828 :     css::uno::Any                                                                    aRequest       = xRequest->getRequest();
     103        1656 :     css::uno::Type                                                                   aRequestType   = aRequest.getValueType();
     104        1656 :     css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
     105             : 
     106             :     // check against the list of static requests
     107         828 :     sal_Int32 nHandle = 0;
     108         828 :     ::std::vector< InterceptedRequest >::const_iterator pIt;
     109        2484 :     for (  pIt  = m_lInterceptions.begin();
     110        1656 :            pIt != m_lInterceptions.end()  ;
     111             :          ++pIt                            )
     112             :     {
     113         386 :         const InterceptedRequest& rInterception = *pIt;
     114         386 :         css::uno::Type aInterceptedType = rInterception.Request.getValueType();
     115             : 
     116             :         // check the request
     117         386 :         bool bMatch = false;
     118         386 :         if (rInterception.MatchExact)
     119           0 :             bMatch = aInterceptedType.equals(aRequestType);
     120             :         else
     121         386 :             bMatch = aInterceptedType.isAssignableFrom(aRequestType); // dont change intercepted and request type here -> it will check the wrong direction!
     122             : 
     123             :         // intercepted ...
     124             :         // Call they might existing derived class, so they can handle that by its own.
     125             :         // If its not interested on that (may be its not overwritten and the default implementation
     126             :         // returns E_NOT_INTERCEPTED as default) -> break this loop and search for the right continuation.
     127         386 :         if (bMatch)
     128             :         {
     129         386 :             EInterceptionState eState = intercepted(rInterception, xRequest);
     130         386 :             if (eState == E_NOT_INTERCEPTED)
     131           0 :                 break;
     132         386 :             return eState;
     133             :         }
     134             : 
     135           0 :         ++nHandle;
     136           0 :     }
     137             : 
     138         442 :     if (pIt != m_lInterceptions.end()) // => can be true only if bMatch=TRUE!
     139             :     {
     140             :         // match -> search required continuation
     141           0 :         const InterceptedRequest& rInterception = *pIt;
     142           0 :         css::uno::Reference< css::task::XInteractionContinuation > xContinuation = InterceptedInteraction::extractContinuation(lContinuations, rInterception.Continuation);
     143           0 :         if (xContinuation.is())
     144             :         {
     145           0 :             xContinuation->select();
     146           0 :             return E_INTERCEPTED;
     147             :         }
     148             : 
     149             :         // Can be reached only, if the request does not support the given continuation!
     150             :         // => RuntimeError!?
     151           0 :         return E_NO_CONTINUATION_FOUND;
     152             :     }
     153             : 
     154        1270 :     return E_NOT_INTERCEPTED;
     155             : }
     156             : 
     157             : } // namespace ucbhelper
     158             : 
     159             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10