Branch libreoffice-5-0-4
[LibreOffice.git] / package / source / xstor / oseekinstream.cxx
blob53bf7a3db989d0a537cfa8ce69c6f5e30cc46061
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/lang/DisposedException.hpp>
21 #include <cppuhelper/typeprovider.hxx>
22 #include <cppuhelper/queryinterface.hxx>
23 #include <osl/diagnose.h>
25 #include "oseekinstream.hxx"
26 #include "owriteablestream.hxx"
28 using namespace ::com::sun::star;
30 OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl,
31 uno::Reference < io::XInputStream > xStream,
32 const uno::Sequence< beans::PropertyValue >& aProps,
33 sal_Int32 nStorageType )
34 : OInputCompStream( pImpl, xStream, aProps, nStorageType )
36 m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
37 OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
40 OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream,
41 const uno::Sequence< beans::PropertyValue >& aProps,
42 sal_Int32 nStorageType )
43 : OInputCompStream( xStream, aProps, nStorageType )
45 m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
46 OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
49 OInputSeekStream::~OInputSeekStream()
53 uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
54 throw ( uno::RuntimeException, std::exception )
56 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
58 if ( pTypeCollection == NULL )
60 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
62 if ( pTypeCollection == NULL )
64 static ::cppu::OTypeCollection aTypeCollection(
65 cppu::UnoType<io::XSeekable>::get(),
66 OInputCompStream::getTypes() );
68 pTypeCollection = &aTypeCollection ;
72 return pTypeCollection->getTypes() ;
75 uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
76 throw( uno::RuntimeException, std::exception )
78 // Attention:
79 // Don't use mutex or guard in this method!!! Is a method of XInterface.
81 uno::Any aReturn( ::cppu::queryInterface( rType,
82 static_cast< io::XSeekable* >( this ) ) );
84 if ( aReturn.hasValue() )
86 return aReturn ;
89 return OInputCompStream::queryInterface( rType ) ;
92 void SAL_CALL OInputSeekStream::acquire()
93 throw()
95 OInputCompStream::acquire();
98 void SAL_CALL OInputSeekStream::release()
99 throw()
101 OInputCompStream::release();
104 void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
105 throw ( lang::IllegalArgumentException,
106 io::IOException,
107 uno::RuntimeException, std::exception )
109 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
110 if ( m_bDisposed )
112 SAL_INFO("package.xstor", "Disposed!");
113 throw lang::DisposedException();
116 if ( !m_xSeekable.is() )
118 SAL_INFO("package.xstor", "No seekable!");
119 throw uno::RuntimeException();
122 m_xSeekable->seek( location );
125 sal_Int64 SAL_CALL OInputSeekStream::getPosition()
126 throw ( io::IOException,
127 uno::RuntimeException, std::exception)
129 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
130 if ( m_bDisposed )
132 SAL_INFO("package.xstor", "Disposed!");
133 throw lang::DisposedException();
136 if ( !m_xSeekable.is() )
138 SAL_INFO("package.xstor", "No seekable!");
139 throw uno::RuntimeException();
142 return m_xSeekable->getPosition();
145 sal_Int64 SAL_CALL OInputSeekStream::getLength()
146 throw ( io::IOException,
147 uno::RuntimeException, std::exception )
149 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
150 if ( m_bDisposed )
152 SAL_INFO("package.xstor", "Disposed!");
153 throw lang::DisposedException();
156 if ( !m_xSeekable.is() )
158 SAL_INFO("package.xstor", "No seekable!");
159 throw uno::RuntimeException();
162 return m_xSeekable->getLength();
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */