LCOV - code coverage report
Current view: top level - svl/source/fsstor - oinputstreamcontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 30 135 22.2 %
Date: 2012-08-25 Functions: 8 20 40.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 266 7.1 %

           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                 :            : 
      21                 :            : #include "oinputstreamcontainer.hxx"
      22                 :            : #include <cppuhelper/typeprovider.hxx>
      23                 :            : 
      24                 :            : using namespace ::com::sun::star;
      25                 :            : 
      26                 :            : //-----------------------------------------------
      27                 :        412 : OFSInputStreamContainer::OFSInputStreamContainer( const uno::Reference< io::XInputStream >& xStream )
      28                 :            : : m_xInputStream( xStream )
      29                 :            : , m_xSeekable( xStream, uno::UNO_QUERY )
      30                 :            : , m_bSeekable( sal_False )
      31                 :            : , m_bDisposed( sal_False )
      32 [ +  - ][ +  - ]:        412 : , m_pListenersContainer( NULL )
      33                 :            : {
      34                 :        412 :     m_bSeekable = m_xSeekable.is();
      35                 :        412 : }
      36                 :            : 
      37                 :            : //-----------------------------------------------
      38         [ +  - ]:        412 : OFSInputStreamContainer::~OFSInputStreamContainer()
      39                 :            : {
      40         [ -  + ]:        412 :     if ( m_pListenersContainer )
      41                 :            :     {
      42 [ #  # ][ #  # ]:          0 :         delete m_pListenersContainer;
      43                 :          0 :         m_pListenersContainer = NULL;
      44                 :            :     }
      45         [ -  + ]:        824 : }
      46                 :            : 
      47                 :            : //-----------------------------------------------
      48                 :          0 : uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
      49                 :            :         throw ( uno::RuntimeException )
      50                 :            : {
      51                 :            :     static ::cppu::OTypeCollection* pTypeCollection = NULL ;
      52                 :            : 
      53         [ #  # ]:          0 :     if ( pTypeCollection == NULL )
      54                 :            :     {
      55         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_aMutex ) ;
      56                 :            : 
      57         [ #  # ]:          0 :         if ( pTypeCollection == NULL )
      58                 :            :         {
      59         [ #  # ]:          0 :             if ( m_bSeekable )
      60                 :            :             {
      61                 :            :                 static ::cppu::OTypeCollection aTypeCollection(
      62         [ #  # ]:          0 :                         ::getCppuType(( const uno::Reference< io::XStream >* )NULL ),
      63         [ #  # ]:          0 :                         ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ),
      64 [ #  # ][ #  # ]:          0 :                         ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      65                 :            : 
      66                 :          0 :                 pTypeCollection = &aTypeCollection ;
      67                 :            :             }
      68                 :            :             else
      69                 :            :             {
      70                 :            :                 static ::cppu::OTypeCollection aTypeCollection(
      71         [ #  # ]:          0 :                         ::getCppuType(( const uno::Reference< io::XStream >* )NULL ),
      72 [ #  # ][ #  # ]:          0 :                         ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      73                 :            : 
      74                 :          0 :                 pTypeCollection = &aTypeCollection ;
      75                 :            :             }
      76         [ #  # ]:          0 :         }
      77                 :            :     }
      78                 :            : 
      79                 :          0 :     return pTypeCollection->getTypes() ;
      80                 :            : 
      81                 :            : }
      82                 :            : 
      83                 :            : //-----------------------------------------------
      84                 :        412 : uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType )
      85                 :            :         throw( uno::RuntimeException )
      86                 :            : {
      87                 :            :     // Attention:
      88                 :            :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
      89                 :            : 
      90                 :        412 :     uno::Any aReturn;
      91         [ +  - ]:        412 :     if ( m_bSeekable )
      92                 :            :         aReturn = uno::Any( ::cppu::queryInterface( rType,
      93                 :            :                                            static_cast< io::XStream* >( this ),
      94                 :            :                                            static_cast< io::XInputStream* >( this ),
      95         [ +  - ]:        412 :                                            static_cast< io::XSeekable* >( this ) ) );
      96                 :            :     else
      97                 :            :         aReturn = uno::Any( ::cppu::queryInterface( rType,
      98                 :            :                                            static_cast< io::XStream* >( this ),
      99         [ #  # ]:          0 :                                            static_cast< io::XInputStream* >( this ) ) );
     100                 :            : 
     101         [ +  - ]:        412 :     if ( aReturn.hasValue() == sal_True )
     102                 :        412 :         return aReturn ;
     103                 :            : 
     104         [ #  # ]:        412 :     return ::cppu::OWeakObject::queryInterface( rType ) ;
     105                 :            : }
     106                 :            : 
     107                 :            : //-----------------------------------------------
     108                 :       3708 : void SAL_CALL OFSInputStreamContainer::acquire()
     109                 :            :         throw()
     110                 :            : {
     111                 :       3708 :     ::cppu::OWeakObject::acquire();
     112                 :       3708 : }
     113                 :            : 
     114                 :            : //-----------------------------------------------
     115                 :       3708 : void SAL_CALL OFSInputStreamContainer::release()
     116                 :            :         throw()
     117                 :            : {
     118                 :       3708 :     ::cppu::OWeakObject::release();
     119                 :       3708 : }
     120                 :            : 
     121                 :            : //-----------------------------------------------
     122                 :          0 : sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
     123                 :            :         throw ( io::NotConnectedException,
     124                 :            :                 io::BufferSizeExceededException,
     125                 :            :                 io::IOException,
     126                 :            :                 uno::RuntimeException )
     127                 :            : {
     128         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     129                 :            : 
     130         [ #  # ]:          0 :     if ( m_bDisposed )
     131         [ #  # ]:          0 :         throw lang::DisposedException();
     132                 :            : 
     133         [ #  # ]:          0 :     if ( !m_xInputStream.is() )
     134         [ #  # ]:          0 :         throw uno::RuntimeException();
     135                 :            : 
     136 [ #  # ][ #  # ]:          0 :     return m_xInputStream->readBytes( aData, nBytesToRead );
                 [ #  # ]
     137                 :            : }
     138                 :            : 
     139                 :            : //-----------------------------------------------
     140                 :        888 : sal_Int32 SAL_CALL OFSInputStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
     141                 :            :         throw ( io::NotConnectedException,
     142                 :            :                 io::BufferSizeExceededException,
     143                 :            :                 io::IOException,
     144                 :            :                 uno::RuntimeException )
     145                 :            : {
     146         [ +  - ]:        888 :     ::osl::MutexGuard aGuard( m_aMutex );
     147                 :            : 
     148         [ -  + ]:        888 :     if ( m_bDisposed )
     149         [ #  # ]:          0 :         throw lang::DisposedException();
     150                 :            : 
     151         [ -  + ]:        888 :     if ( !m_xInputStream.is() )
     152         [ #  # ]:          0 :         throw uno::RuntimeException();
     153                 :            : 
     154 [ +  - ][ +  - ]:        888 :     return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
                 [ +  - ]
     155                 :            : }
     156                 :            : 
     157                 :            : //-----------------------------------------------
     158                 :          0 : void SAL_CALL OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
     159                 :            :         throw ( io::NotConnectedException,
     160                 :            :                 io::BufferSizeExceededException,
     161                 :            :                 io::IOException,
     162                 :            :                 uno::RuntimeException )
     163                 :            : {
     164         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     165                 :            : 
     166         [ #  # ]:          0 :     if ( m_bDisposed )
     167         [ #  # ]:          0 :         throw lang::DisposedException();
     168                 :            : 
     169         [ #  # ]:          0 :     if ( !m_xInputStream.is() )
     170         [ #  # ]:          0 :         throw uno::RuntimeException();
     171                 :            : 
     172 [ #  # ][ #  # ]:          0 :     m_xInputStream->skipBytes( nBytesToSkip );
                 [ #  # ]
     173                 :          0 : }
     174                 :            : 
     175                 :            : //-----------------------------------------------
     176                 :          0 : sal_Int32 SAL_CALL OFSInputStreamContainer::available(  )
     177                 :            :         throw ( io::NotConnectedException,
     178                 :            :                 io::IOException,
     179                 :            :                 uno::RuntimeException )
     180                 :            : {
     181         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     182                 :            : 
     183         [ #  # ]:          0 :     if ( m_bDisposed )
     184         [ #  # ]:          0 :         throw lang::DisposedException();
     185                 :            : 
     186         [ #  # ]:          0 :     if ( !m_xInputStream.is() )
     187         [ #  # ]:          0 :         throw uno::RuntimeException();
     188                 :            : 
     189 [ #  # ][ #  # ]:          0 :     return m_xInputStream->available();
                 [ #  # ]
     190                 :            : }
     191                 :            : 
     192                 :            : //-----------------------------------------------
     193                 :          0 : void SAL_CALL OFSInputStreamContainer::closeInput(  )
     194                 :            :         throw ( io::NotConnectedException,
     195                 :            :                 io::IOException,
     196                 :            :                 uno::RuntimeException )
     197                 :            : {
     198         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     199                 :            : 
     200         [ #  # ]:          0 :     if ( m_bDisposed )
     201         [ #  # ]:          0 :         throw lang::DisposedException();
     202                 :            : 
     203         [ #  # ]:          0 :     if ( !m_xInputStream.is() )
     204         [ #  # ]:          0 :         throw uno::RuntimeException();
     205                 :            : 
     206 [ #  # ][ #  # ]:          0 :     dispose();
     207                 :          0 : }
     208                 :            : 
     209                 :            : //-----------------------------------------------
     210                 :        412 : uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream()
     211                 :            :         throw ( uno::RuntimeException )
     212                 :            : {
     213         [ +  - ]:        412 :     ::osl::MutexGuard aGuard( m_aMutex );
     214                 :            : 
     215         [ -  + ]:        412 :     if ( m_bDisposed )
     216         [ #  # ]:          0 :         throw lang::DisposedException();
     217                 :            : 
     218         [ -  + ]:        412 :     if ( !m_xInputStream.is() )
     219                 :          0 :         return uno::Reference< io::XInputStream >();
     220                 :            : 
     221 [ +  - ][ +  - ]:        412 :     return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY );
     222                 :            : }
     223                 :            : 
     224                 :            : //-----------------------------------------------
     225                 :          0 : uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream()
     226                 :            :         throw ( uno::RuntimeException )
     227                 :            : {
     228         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     229                 :            : 
     230         [ #  # ]:          0 :     if ( m_bDisposed )
     231         [ #  # ]:          0 :         throw lang::DisposedException();
     232                 :            : 
     233         [ #  # ]:          0 :     return uno::Reference< io::XOutputStream >();
     234                 :            : }
     235                 :            : 
     236                 :            : //-----------------------------------------------
     237                 :          0 : void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location )
     238                 :            :         throw ( lang::IllegalArgumentException,
     239                 :            :                 io::IOException,
     240                 :            :                 uno::RuntimeException )
     241                 :            : {
     242         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     243                 :            : 
     244         [ #  # ]:          0 :     if ( m_bDisposed )
     245         [ #  # ]:          0 :         throw lang::DisposedException();
     246                 :            : 
     247         [ #  # ]:          0 :     if ( !m_xSeekable.is() )
     248         [ #  # ]:          0 :         throw uno::RuntimeException();
     249                 :            : 
     250 [ #  # ][ #  # ]:          0 :     m_xSeekable->seek( location );
                 [ #  # ]
     251                 :          0 : }
     252                 :            : 
     253                 :            : //-----------------------------------------------
     254                 :          0 : sal_Int64 SAL_CALL OFSInputStreamContainer::getPosition()
     255                 :            :         throw ( io::IOException,
     256                 :            :                 uno::RuntimeException)
     257                 :            : {
     258         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     259                 :            : 
     260         [ #  # ]:          0 :     if ( m_bDisposed )
     261         [ #  # ]:          0 :         throw lang::DisposedException();
     262                 :            : 
     263         [ #  # ]:          0 :     if ( !m_xSeekable.is() )
     264         [ #  # ]:          0 :         throw uno::RuntimeException();
     265                 :            : 
     266 [ #  # ][ #  # ]:          0 :     return m_xSeekable->getPosition();
                 [ #  # ]
     267                 :            : }
     268                 :            : 
     269                 :            : //-----------------------------------------------
     270                 :          0 : sal_Int64 SAL_CALL OFSInputStreamContainer::getLength()
     271                 :            :         throw ( io::IOException,
     272                 :            :                 uno::RuntimeException )
     273                 :            : {
     274         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     275                 :            : 
     276         [ #  # ]:          0 :     if ( m_bDisposed )
     277         [ #  # ]:          0 :         throw lang::DisposedException();
     278                 :            : 
     279         [ #  # ]:          0 :     if ( !m_xSeekable.is() )
     280         [ #  # ]:          0 :         throw uno::RuntimeException();
     281                 :            : 
     282 [ #  # ][ #  # ]:          0 :     return m_xSeekable->getLength();
                 [ #  # ]
     283                 :            : }
     284                 :            : 
     285                 :            : //-----------------------------------------------
     286                 :          0 : void SAL_CALL OFSInputStreamContainer::dispose(  )
     287                 :            :         throw ( uno::RuntimeException )
     288                 :            : {
     289         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     290                 :            : 
     291         [ #  # ]:          0 :     if ( m_bDisposed )
     292         [ #  # ]:          0 :         throw lang::DisposedException();
     293                 :            : 
     294         [ #  # ]:          0 :     if ( !m_xInputStream.is() )
     295         [ #  # ]:          0 :         throw uno::RuntimeException();
     296                 :            : 
     297 [ #  # ][ #  # ]:          0 :     m_xInputStream->closeInput();
     298                 :            : 
     299         [ #  # ]:          0 :     if ( m_pListenersContainer )
     300                 :            :     {
     301 [ #  # ][ #  # ]:          0 :         lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
     302 [ #  # ][ #  # ]:          0 :         m_pListenersContainer->disposeAndClear( aSource );
     303                 :            :     }
     304                 :            : 
     305         [ #  # ]:          0 :     m_bDisposed = sal_True;
     306                 :          0 : }
     307                 :            : 
     308                 :            : //-----------------------------------------------
     309                 :          0 : void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
     310                 :            :         throw ( uno::RuntimeException )
     311                 :            : {
     312         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     313                 :            : 
     314         [ #  # ]:          0 :     if ( m_bDisposed )
     315         [ #  # ]:          0 :         throw lang::DisposedException();
     316                 :            : 
     317         [ #  # ]:          0 :     if ( !m_pListenersContainer )
     318         [ #  # ]:          0 :         m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
     319                 :            : 
     320 [ #  # ][ #  # ]:          0 :     m_pListenersContainer->addInterface( xListener );
     321                 :          0 : }
     322                 :            : 
     323                 :            : //-----------------------------------------------
     324                 :          0 : void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
     325                 :            :         throw ( uno::RuntimeException )
     326                 :            : {
     327         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     328                 :            : 
     329         [ #  # ]:          0 :     if ( m_bDisposed )
     330         [ #  # ]:          0 :         throw lang::DisposedException();
     331                 :            : 
     332         [ #  # ]:          0 :     if ( m_pListenersContainer )
     333 [ #  # ][ #  # ]:          0 :         m_pListenersContainer->removeInterface( xListener );
     334                 :          0 : }
     335                 :            : 
     336                 :            : 
     337                 :            : 
     338                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10