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

Generated by: LCOV version 1.11