update credits
[LibreOffice.git] / package / source / xstor / oseekinstream.cxx
blob5f6be02ee23ca8d559befb7188b6c102114e8d67
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 <osl/diagnose.h>
24 #include "oseekinstream.hxx"
25 #include "owriteablestream.hxx"
27 using namespace ::com::sun::star;
29 OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl,
30 uno::Reference < io::XInputStream > xStream,
31 const uno::Sequence< beans::PropertyValue >& aProps,
32 sal_Int32 nStorageType )
33 : OInputCompStream( pImpl, xStream, aProps, nStorageType )
35 if ( m_xStream.is() )
37 m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
38 OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
42 OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream,
43 const uno::Sequence< beans::PropertyValue >& aProps,
44 sal_Int32 nStorageType )
45 : OInputCompStream( xStream, aProps, nStorageType )
47 if ( m_xStream.is() )
49 m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
50 OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
54 OInputSeekStream::~OInputSeekStream()
58 uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
59 throw ( uno::RuntimeException )
61 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
63 if ( pTypeCollection == NULL )
65 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
67 if ( pTypeCollection == NULL )
69 static ::cppu::OTypeCollection aTypeCollection(
70 ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ),
71 OInputCompStream::getTypes() );
73 pTypeCollection = &aTypeCollection ;
77 return pTypeCollection->getTypes() ;
80 uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
81 throw( uno::RuntimeException )
83 // Attention:
84 // Don't use mutex or guard in this method!!! Is a method of XInterface.
86 uno::Any aReturn( ::cppu::queryInterface( rType,
87 static_cast< io::XSeekable* >( this ) ) );
89 if ( aReturn.hasValue() == sal_True )
91 return aReturn ;
94 return OInputCompStream::queryInterface( rType ) ;
97 void SAL_CALL OInputSeekStream::acquire()
98 throw()
100 OInputCompStream::acquire();
103 void SAL_CALL OInputSeekStream::release()
104 throw()
106 OInputCompStream::release();
110 void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
111 throw ( lang::IllegalArgumentException,
112 io::IOException,
113 uno::RuntimeException )
115 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
116 if ( m_bDisposed )
118 ::package::StaticAddLog( OSL_LOG_PREFIX "Disposed!" );
119 throw lang::DisposedException();
122 if ( !m_xSeekable.is() )
124 ::package::StaticAddLog( OSL_LOG_PREFIX "No seekable!" );
125 throw uno::RuntimeException();
128 m_xSeekable->seek( location );
131 sal_Int64 SAL_CALL OInputSeekStream::getPosition()
132 throw ( io::IOException,
133 uno::RuntimeException)
135 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
136 if ( m_bDisposed )
138 ::package::StaticAddLog( OSL_LOG_PREFIX "Disposed!" );
139 throw lang::DisposedException();
142 if ( !m_xSeekable.is() )
144 ::package::StaticAddLog( OSL_LOG_PREFIX "No seekable!" );
145 throw uno::RuntimeException();
148 return m_xSeekable->getPosition();
151 sal_Int64 SAL_CALL OInputSeekStream::getLength()
152 throw ( io::IOException,
153 uno::RuntimeException )
155 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
156 if ( m_bDisposed )
158 ::package::StaticAddLog( OSL_LOG_PREFIX "Disposed!" );
159 throw lang::DisposedException();
162 if ( !m_xSeekable.is() )
164 ::package::StaticAddLog( OSL_LOG_PREFIX "No seekable!" );
165 throw uno::RuntimeException();
168 return m_xSeekable->getLength();
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */