LCOV - code coverage report
Current view: top level - ucb/source/ucp/gio - gio_seekable.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 55 0.0 %
Date: 2014-11-03 Functions: 0 8 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 <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
      21             : #include <ucbhelper/cancelcommandexecution.hxx>
      22             : #include <string.h>
      23             : 
      24             : #include "gio_seekable.hxx"
      25             : #include "gio_content.hxx"
      26             : 
      27             : using namespace com::sun::star;
      28             : 
      29             : namespace gio
      30             : {
      31             : 
      32           0 : Seekable::Seekable(GSeekable *pStream) : mpStream(pStream)
      33             : {
      34           0 :     if (!mpStream)
      35           0 :         throw io::NotConnectedException();
      36           0 : }
      37             : 
      38           0 : Seekable::~Seekable( void )
      39             : {
      40           0 : }
      41             : 
      42           0 : void SAL_CALL Seekable::truncate( void )
      43             :     throw( io::IOException, uno::RuntimeException, std::exception )
      44             : {
      45           0 :     if (!mpStream)
      46           0 :         throw io::NotConnectedException();
      47             : 
      48           0 :     if (!g_seekable_can_truncate(mpStream))
      49             :         throw io::IOException("Truncate unsupported",
      50           0 :             static_cast< cppu::OWeakObject * >(this));
      51             : 
      52           0 :     GError *pError=NULL;
      53           0 :     if (!g_seekable_truncate(mpStream, 0, NULL, &pError))
      54           0 :         convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
      55           0 : }
      56             : 
      57           0 : void SAL_CALL Seekable::seek( sal_Int64 location )
      58             :     throw( lang::IllegalArgumentException, io::IOException, uno::RuntimeException, std::exception )
      59             : {
      60           0 :     if (!mpStream)
      61           0 :         throw io::NotConnectedException();
      62             : 
      63           0 :     if (!g_seekable_can_seek(mpStream))
      64             :         throw io::IOException("Seek unsupported",
      65           0 :             static_cast< cppu::OWeakObject * >(this));
      66             : 
      67           0 :     GError *pError=NULL;
      68           0 :     if (!g_seekable_seek(mpStream, location, G_SEEK_SET, NULL, &pError))
      69           0 :         convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
      70           0 : }
      71             : 
      72           0 : sal_Int64 SAL_CALL Seekable::getPosition() throw( io::IOException, uno::RuntimeException, std::exception )
      73             : {
      74           0 :     if (!mpStream)
      75           0 :         throw io::NotConnectedException();
      76             : 
      77           0 :     return g_seekable_tell(mpStream);
      78             : }
      79             : 
      80           0 : sal_Int64 SAL_CALL Seekable::getLength() throw( io::IOException, uno::RuntimeException, std::exception )
      81             : {
      82           0 :     if (!mpStream)
      83           0 :         throw io::NotConnectedException();
      84             : 
      85           0 :     bool bOk = false;
      86           0 :     sal_uInt64 nSize = 0;
      87             : 
      88           0 :     GFileInfo* pInfo = G_IS_FILE_INPUT_STREAM(mpStream)
      89           0 :         ? g_file_input_stream_query_info(G_FILE_INPUT_STREAM(mpStream), const_cast<char*>(G_FILE_ATTRIBUTE_STANDARD_SIZE), NULL, NULL)
      90           0 :         : g_file_output_stream_query_info(G_FILE_OUTPUT_STREAM(mpStream), const_cast<char*>(G_FILE_ATTRIBUTE_STANDARD_SIZE), NULL, NULL);
      91             : 
      92           0 :     if (pInfo)
      93             :     {
      94           0 :         if (g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE))
      95             :         {
      96           0 :             nSize = g_file_info_get_size(pInfo);
      97           0 :             bOk = true;
      98             :         }
      99           0 :         g_object_unref(pInfo);
     100             :     }
     101             : 
     102           0 :     if (!bOk)
     103             :     {
     104           0 :         GError *pError=NULL;
     105           0 :         sal_Int64 nCurr = getPosition();
     106           0 :         if (!g_seekable_seek(mpStream, 0, G_SEEK_END, NULL, &pError))
     107           0 :             convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
     108           0 :         nSize = getPosition();
     109           0 :         seek(nCurr);
     110           0 :         bOk = true;
     111             :     }
     112             : 
     113           0 :     return nSize;
     114             : }
     115             : 
     116           0 : uno::Any Seekable::queryInterface( const uno::Type &type ) throw( uno::RuntimeException, std::exception )
     117             : {
     118             :     uno::Any aRet = ::cppu::queryInterface ( type,
     119           0 :         static_cast< XSeekable * >( this ) );
     120             : 
     121           0 :     if (!aRet.hasValue() && g_seekable_can_truncate(mpStream))
     122           0 :         aRet = ::cppu::queryInterface ( type, static_cast< XTruncate * >( this ) );
     123             : 
     124           0 :     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
     125             : }
     126             : 
     127             : }
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10