LCOV - code coverage report
Current view: top level - comphelper/source/misc - stillreadwriteinteraction.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 43 50 86.0 %
Date: 2014-11-03 Functions: 4 4 100.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 <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       10553 : StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
      31             :              : m_bUsed                    (false)
      32             :              , m_bHandledByMySelf         (false)
      33       10553 :              , m_bHandledByInternalHandler(false)
      34             : {
      35       10553 :     ::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
      36       21106 :     ::ucbhelper::InterceptedInteraction::InterceptedRequest                  aInterceptedRequest;
      37             : 
      38       10553 :     aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
      39       10553 :     aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
      40       10553 :     aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
      41       10553 :     aInterceptedRequest.MatchExact = false;
      42       10553 :     lInterceptions.push_back(aInterceptedRequest);
      43             : 
      44       10553 :     aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
      45       10553 :     aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
      46       10553 :     aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
      47       10553 :     aInterceptedRequest.MatchExact = false;
      48       10553 :     lInterceptions.push_back(aInterceptedRequest);
      49             : 
      50       10553 :     setInterceptedHandler(xHandler);
      51       21106 :     setInterceptions(lInterceptions);
      52       10553 : }
      53             : 
      54        5883 : void StillReadWriteInteraction::resetInterceptions()
      55             : {
      56        5883 :     setInterceptions(::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
      57        5883 : }
      58             : 
      59        5883 : void StillReadWriteInteraction::resetErrorStates()
      60             : {
      61        5883 :     m_bUsed                     = false;
      62        5883 :     m_bHandledByMySelf          = false;
      63        5883 :     m_bHandledByInternalHandler = false;
      64        5883 : }
      65             : 
      66             : 
      67         386 : ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest&                         aRequest,
      68             :                                                                   const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
      69             : {
      70             :     // we are used!
      71         386 :     m_bUsed = true;
      72             : 
      73             :     // check if it's a real interception - might some parameters are not the right ones ...
      74         386 :     bool bAbort = false;
      75         386 :     switch(aRequest.Handle)
      76             :     {
      77             :     case HANDLE_INTERACTIVEIOEXCEPTION:
      78             :         {
      79         386 :             css::ucb::InteractiveIOException exIO;
      80         386 :             xRequest->getRequest() >>= exIO;
      81             :             bAbort = (
      82         386 :                 (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED     )
      83         386 :                 || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
      84         772 :                 || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
      85             : #ifdef MACOSX
      86             :                 // this is a workaround for MAC, on this platform if the file is locked
      87             :                 // the returned error code looks to be wrong
      88             :                 || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
      89             : #endif
      90         386 :                 );
      91             :         }
      92         386 :         break;
      93             : 
      94             :     case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
      95             :         {
      96           0 :             bAbort = true;
      97             :         }
      98           0 :         break;
      99             :     }
     100             : 
     101             :     // handle interaction by ourself
     102         386 :     if (bAbort)
     103             :     {
     104         386 :         m_bHandledByMySelf = true;
     105             :         css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
     106         386 :             xRequest->getContinuations(),
     107         772 :             cppu::UnoType<css::task::XInteractionAbort>::get() );
     108         386 :         if (!xAbort.is())
     109           0 :             return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
     110         386 :         xAbort->select();
     111         386 :         return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
     112             :     }
     113             : 
     114             :     // Otherwhise use internal handler.
     115           0 :     if (m_xInterceptedHandler.is())
     116             :     {
     117           0 :         m_bHandledByInternalHandler = true;
     118           0 :         m_xInterceptedHandler->handle(xRequest);
     119             :     }
     120           0 :     return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
     121             : }
     122             : }
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10