LCOV - code coverage report
Current view: top level - package/source/zippackage - wrapstreamforshare.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 61 0.0 %
Date: 2014-04-14 Functions: 0 11 0.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 <osl/diagnose.h>
      21             : 
      22             : #include "wrapstreamforshare.hxx"
      23             : 
      24             : using namespace ::com::sun::star;
      25             : 
      26             : #if OSL_DEBUG_LEVEL > 0
      27             : #define THROW_WHERE SAL_WHERE
      28             : #else
      29             : #define THROW_WHERE ""
      30             : #endif
      31             : 
      32           0 : WrapStreamForShare::WrapStreamForShare( const uno::Reference< io::XInputStream >& xInStream,
      33             :                                         const SotMutexHolderRef& rMutexRef )
      34             : : m_rMutexRef( rMutexRef )
      35             : , m_xInStream( xInStream )
      36           0 : , m_nCurPos( 0 )
      37             : {
      38           0 :     m_xSeekable = uno::Reference< io::XSeekable >( m_xInStream, uno::UNO_QUERY );
      39           0 :     if ( !m_rMutexRef.Is() || !m_xInStream.is() || !m_xSeekable.is() )
      40             :     {
      41             :         OSL_FAIL( "Wrong initialization of wrapping stream!\n" );
      42           0 :         throw uno::RuntimeException(THROW_WHERE, uno::Reference< uno::XInterface >() );
      43             :     }
      44           0 : }
      45             : 
      46           0 : WrapStreamForShare::~WrapStreamForShare()
      47             : {
      48           0 : }
      49             : 
      50             : // XInputStream
      51           0 : sal_Int32 SAL_CALL WrapStreamForShare::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
      52             :         throw ( io::NotConnectedException,
      53             :                 io::BufferSizeExceededException,
      54             :                 io::IOException,
      55             :                 uno::RuntimeException, std::exception )
      56             : {
      57           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
      58             : 
      59           0 :     if ( !m_xInStream.is() )
      60           0 :         throw io::IOException(THROW_WHERE, uno::Reference< uno::XInterface >() );
      61             : 
      62           0 :     m_xSeekable->seek( m_nCurPos );
      63             : 
      64           0 :     sal_Int32 nRead = m_xInStream->readBytes( aData, nBytesToRead );
      65           0 :     m_nCurPos += nRead;
      66             : 
      67           0 :     return nRead;
      68             : }
      69             : 
      70           0 : sal_Int32 SAL_CALL WrapStreamForShare::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
      71             :         throw ( io::NotConnectedException,
      72             :                 io::BufferSizeExceededException,
      73             :                 io::IOException,
      74             :                 uno::RuntimeException, std::exception )
      75             : {
      76           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
      77             : 
      78           0 :     if ( !m_xInStream.is() )
      79           0 :         throw io::IOException(THROW_WHERE, uno::Reference< uno::XInterface >() );
      80             : 
      81           0 :     m_xSeekable->seek( m_nCurPos );
      82             : 
      83           0 :     sal_Int32 nRead = m_xInStream->readSomeBytes( aData, nMaxBytesToRead );
      84           0 :     m_nCurPos += nRead;
      85             : 
      86           0 :     return nRead;
      87             : }
      88             : 
      89           0 : void SAL_CALL WrapStreamForShare::skipBytes( sal_Int32 nBytesToSkip )
      90             :         throw ( io::NotConnectedException,
      91             :                 io::BufferSizeExceededException,
      92             :                 io::IOException,
      93             :                 uno::RuntimeException, std::exception )
      94             : {
      95           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
      96             : 
      97           0 :     if ( !m_xInStream.is() )
      98           0 :         throw io::IOException(THROW_WHERE, uno::Reference< uno::XInterface >() );
      99             : 
     100           0 :     m_xSeekable->seek( m_nCurPos );
     101             : 
     102           0 :     m_xInStream->skipBytes( nBytesToSkip );
     103           0 :     m_nCurPos = m_xSeekable->getPosition();
     104           0 : }
     105             : 
     106           0 : sal_Int32 SAL_CALL WrapStreamForShare::available()
     107             :         throw ( io::NotConnectedException,
     108             :                 io::IOException,
     109             :                 uno::RuntimeException, std::exception )
     110             : {
     111           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     112             : 
     113           0 :     if ( !m_xInStream.is() )
     114           0 :         throw io::IOException(THROW_WHERE, uno::Reference< uno::XInterface >() );
     115             : 
     116           0 :     return m_xInStream->available();
     117             : }
     118             : 
     119           0 : void SAL_CALL WrapStreamForShare::closeInput()
     120             :         throw ( io::NotConnectedException,
     121             :                 io::IOException,
     122             :                 uno::RuntimeException, std::exception )
     123             : {
     124           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     125             : 
     126           0 :     if ( !m_xInStream.is() )
     127           0 :         throw io::IOException(THROW_WHERE, uno::Reference< uno::XInterface >() );
     128             : 
     129             :     // the package is the owner so it will close the stream
     130             :     // m_xInStream->closeInput();
     131           0 :     m_xInStream = uno::Reference< io::XInputStream >();
     132           0 :     m_xSeekable = uno::Reference< io::XSeekable >();
     133           0 : }
     134             : 
     135             : // XSeekable
     136           0 : void SAL_CALL WrapStreamForShare::seek( sal_Int64 location )
     137             :         throw ( lang::IllegalArgumentException,
     138             :                 io::IOException,
     139             :                 uno::RuntimeException, std::exception )
     140             : {
     141           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     142             : 
     143           0 :     if ( !m_xInStream.is() )
     144           0 :         throw io::IOException(THROW_WHERE, uno::Reference< uno::XInterface >() );
     145             : 
     146             :     // let stream implementation do all the checking
     147           0 :     m_xSeekable->seek( location );
     148             : 
     149           0 :     m_nCurPos = m_xSeekable->getPosition();
     150           0 : }
     151             : 
     152           0 : sal_Int64 SAL_CALL WrapStreamForShare::getPosition()
     153             :         throw ( io::IOException,
     154             :                 uno::RuntimeException, std::exception)
     155             : {
     156           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     157             : 
     158           0 :     if ( !m_xInStream.is() )
     159           0 :         throw io::IOException(THROW_WHERE, uno::Reference< uno::XInterface >() );
     160             : 
     161           0 :     return m_nCurPos;
     162             : }
     163             : 
     164           0 : sal_Int64 SAL_CALL WrapStreamForShare::getLength()
     165             :         throw ( io::IOException,
     166             :                 uno::RuntimeException, std::exception )
     167             : {
     168           0 :     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
     169             : 
     170           0 :     if ( !m_xInStream.is() )
     171           0 :         throw io::IOException(THROW_WHERE, uno::Reference< uno::XInterface >() );
     172             : 
     173           0 :     return m_xSeekable->getLength();
     174             : }
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10