LCOV - code coverage report
Current view: top level - ucbhelper/source/client - interceptedinteraction.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 60 81.7 %
Date: 2012-08-25 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 27 65 41.5 %

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

Generated by: LCOV version 1.10