LCOV - code coverage report
Current view: top level - comphelper/source/misc - stillreadwriteinteraction.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 49 87.8 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 35 73 47.9 %

           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 <comphelper/stillreadwriteinteraction.hxx>
      21                 :            : 
      22                 :            : #include <com/sun/star/ucb/InteractiveIOException.hpp>
      23                 :            : 
      24                 :            : #include <com/sun/star/task/XInteractionAbort.hpp>
      25                 :            : 
      26                 :            : #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
      27                 :            : 
      28                 :            : namespace comphelper{
      29                 :            : 
      30                 :            :     namespace css = ::com::sun::star;
      31                 :            : 
      32                 :       2138 : StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
      33                 :            :              : m_bUsed                    (sal_False)
      34                 :            :              , m_bHandledByMySelf         (sal_False)
      35                 :       2138 :              , m_bHandledByInternalHandler(sal_False)
      36                 :            : {
      37         [ +  - ]:       2138 :     ::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
      38                 :       2138 :     ::ucbhelper::InterceptedInteraction::InterceptedRequest                  aInterceptedRequest;
      39                 :            : 
      40                 :       2138 :     aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
      41 [ +  - ][ +  - ]:       2138 :     aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
                 [ +  - ]
      42         [ +  - ]:       2138 :     aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
      43                 :       2138 :     aInterceptedRequest.MatchExact = sal_False;
      44         [ +  - ]:       2138 :     lInterceptions.push_back(aInterceptedRequest);
      45                 :            : 
      46                 :       2138 :     aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
      47 [ +  - ][ +  - ]:       2138 :     aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
                 [ +  - ]
      48         [ +  - ]:       2138 :     aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
      49                 :       2138 :     aInterceptedRequest.MatchExact = sal_False;
      50         [ +  - ]:       2138 :     lInterceptions.push_back(aInterceptedRequest);
      51                 :            : 
      52         [ +  - ]:       2138 :     setInterceptedHandler(xHandler);
      53 [ +  - ][ +  - ]:       2138 :     setInterceptions(lInterceptions);
      54                 :       2138 : }
      55                 :            : 
      56                 :       1204 : void StillReadWriteInteraction::resetInterceptions()
      57                 :            : {
      58         [ +  - ]:       1204 :     setInterceptions(::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
      59                 :       1204 : }
      60                 :            : 
      61                 :       1204 : void StillReadWriteInteraction::resetErrorStates()
      62                 :            : {
      63                 :       1204 :     m_bUsed                     = sal_False;
      64                 :       1204 :     m_bHandledByMySelf          = sal_False;
      65                 :       1204 :     m_bHandledByInternalHandler = sal_False;
      66                 :       1204 : }
      67                 :            : 
      68                 :         20 : sal_Bool StillReadWriteInteraction::wasWriteError()
      69                 :            : {
      70 [ +  - ][ +  - ]:         20 :     return (m_bUsed && m_bHandledByMySelf);
      71                 :            : }
      72                 :            : 
      73                 :         38 : ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest&                         aRequest,
      74                 :            :                                                                   const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
      75                 :            : {
      76                 :            :     // we are used!
      77                 :         38 :     m_bUsed = sal_True;
      78                 :            : 
      79                 :            :     // check if its a real interception - might some parameters are not the right ones ...
      80                 :         38 :     sal_Bool bAbort = sal_False;
      81      [ +  -  - ]:         38 :     switch(aRequest.Handle)
      82                 :            :     {
      83                 :            :     case HANDLE_INTERACTIVEIOEXCEPTION:
      84                 :            :         {
      85         [ +  - ]:         38 :             css::ucb::InteractiveIOException exIO;
      86 [ +  - ][ +  - ]:         38 :             xRequest->getRequest() >>= exIO;
                 [ +  - ]
      87                 :            :             bAbort = (
      88                 :            :                 (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED     )
      89                 :            :                 || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
      90                 :            :                 || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
      91                 :            : #ifdef MACOSX
      92                 :            :                 // this is a workaround for MAC, on this platform if the file is locked
      93                 :            :                 // the returned error code looks to be wrong
      94                 :            :                 || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
      95                 :            : #endif
      96 [ +  - ][ +  - ]:         38 :                 );
         [ +  - ][ +  - ]
      97                 :            :         }
      98                 :         38 :         break;
      99                 :            : 
     100                 :            :     case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
     101                 :            :         {
     102                 :          0 :             bAbort = sal_True;
     103                 :            :         }
     104                 :          0 :         break;
     105                 :            :     }
     106                 :            : 
     107                 :            :     // handle interaction by ourself
     108         [ +  - ]:         38 :     if (bAbort)
     109                 :            :     {
     110                 :         38 :         m_bHandledByMySelf = sal_True;
     111                 :            :         css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
     112         [ +  - ]:         38 :             xRequest->getContinuations(),
     113 [ +  - ][ +  - ]:         76 :             ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0)));
         [ +  - ][ +  - ]
     114         [ -  + ]:         38 :         if (!xAbort.is())
     115                 :          0 :             return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
     116 [ +  - ][ +  - ]:         38 :         xAbort->select();
     117                 :         38 :         return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
     118                 :            :     }
     119                 :            : 
     120                 :            :     // Otherwhise use internal handler.
     121         [ #  # ]:          0 :     if (m_xInterceptedHandler.is())
     122                 :            :     {
     123                 :          0 :         m_bHandledByInternalHandler = sal_True;
     124                 :          0 :         m_xInterceptedHandler->handle(xRequest);
     125                 :            :     }
     126                 :         38 :     return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
     127                 :            : }
     128                 :            : }
     129                 :            : 
     130                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10