bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / fsstor / oinputstreamcontainer.cxx
blob948b44c8dc8738cd2314da1d8b30dba79a854887
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 .
21 #include "oinputstreamcontainer.hxx"
22 #include <cppuhelper/typeprovider.hxx>
23 #include <cppuhelper/queryinterface.hxx>
25 using namespace ::com::sun::star;
27 OFSInputStreamContainer::OFSInputStreamContainer( const uno::Reference< io::XInputStream >& xStream )
28 : m_xInputStream( xStream )
29 , m_xSeekable( xStream, uno::UNO_QUERY )
30 , m_bSeekable( false )
31 , m_bDisposed( false )
32 , m_pListenersContainer( NULL )
34 m_bSeekable = m_xSeekable.is();
37 OFSInputStreamContainer::~OFSInputStreamContainer()
39 if ( m_pListenersContainer )
41 delete m_pListenersContainer;
42 m_pListenersContainer = NULL;
46 uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
47 throw ( uno::RuntimeException, std::exception )
49 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
51 if ( pTypeCollection == NULL )
53 ::osl::MutexGuard aGuard( m_aMutex ) ;
55 if ( pTypeCollection == NULL )
57 if ( m_bSeekable )
59 static ::cppu::OTypeCollection aTypeCollection(
60 cppu::UnoType<io::XStream>::get(),
61 cppu::UnoType<io::XInputStream>::get(),
62 cppu::UnoType<io::XSeekable>::get());
64 pTypeCollection = &aTypeCollection ;
66 else
68 static ::cppu::OTypeCollection aTypeCollection(
69 cppu::UnoType<io::XStream>::get(),
70 cppu::UnoType<io::XInputStream>::get());
72 pTypeCollection = &aTypeCollection ;
77 return pTypeCollection->getTypes() ;
81 uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType )
82 throw( uno::RuntimeException, std::exception )
84 // Attention:
85 // Don't use mutex or guard in this method!!! Is a method of XInterface.
87 uno::Any aReturn;
88 if ( m_bSeekable )
89 aReturn = uno::Any( ::cppu::queryInterface( rType,
90 static_cast< io::XStream* >( this ),
91 static_cast< io::XInputStream* >( this ),
92 static_cast< io::XSeekable* >( this ) ) );
93 else
94 aReturn = uno::Any( ::cppu::queryInterface( rType,
95 static_cast< io::XStream* >( this ),
96 static_cast< io::XInputStream* >( this ) ) );
98 if ( aReturn.hasValue() )
99 return aReturn ;
101 return ::cppu::OWeakObject::queryInterface( rType ) ;
104 void SAL_CALL OFSInputStreamContainer::acquire()
105 throw()
107 ::cppu::OWeakObject::acquire();
110 void SAL_CALL OFSInputStreamContainer::release()
111 throw()
113 ::cppu::OWeakObject::release();
116 sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
117 throw ( io::NotConnectedException,
118 io::BufferSizeExceededException,
119 io::IOException,
120 uno::RuntimeException, std::exception )
122 ::osl::MutexGuard aGuard( m_aMutex );
124 if ( m_bDisposed )
125 throw lang::DisposedException();
127 if ( !m_xInputStream.is() )
128 throw uno::RuntimeException();
130 return m_xInputStream->readBytes( aData, nBytesToRead );
133 sal_Int32 SAL_CALL OFSInputStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
134 throw ( io::NotConnectedException,
135 io::BufferSizeExceededException,
136 io::IOException,
137 uno::RuntimeException, std::exception )
139 ::osl::MutexGuard aGuard( m_aMutex );
141 if ( m_bDisposed )
142 throw lang::DisposedException();
144 if ( !m_xInputStream.is() )
145 throw uno::RuntimeException();
147 return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
150 void SAL_CALL OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
151 throw ( io::NotConnectedException,
152 io::BufferSizeExceededException,
153 io::IOException,
154 uno::RuntimeException, std::exception )
156 ::osl::MutexGuard aGuard( m_aMutex );
158 if ( m_bDisposed )
159 throw lang::DisposedException();
161 if ( !m_xInputStream.is() )
162 throw uno::RuntimeException();
164 m_xInputStream->skipBytes( nBytesToSkip );
167 sal_Int32 SAL_CALL OFSInputStreamContainer::available( )
168 throw ( io::NotConnectedException,
169 io::IOException,
170 uno::RuntimeException, std::exception )
172 ::osl::MutexGuard aGuard( m_aMutex );
174 if ( m_bDisposed )
175 throw lang::DisposedException();
177 if ( !m_xInputStream.is() )
178 throw uno::RuntimeException();
180 return m_xInputStream->available();
183 void SAL_CALL OFSInputStreamContainer::closeInput( )
184 throw ( io::NotConnectedException,
185 io::IOException,
186 uno::RuntimeException, std::exception )
188 ::osl::MutexGuard aGuard( m_aMutex );
190 if ( m_bDisposed )
191 throw lang::DisposedException();
193 if ( !m_xInputStream.is() )
194 throw uno::RuntimeException();
196 dispose();
199 uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream()
200 throw ( uno::RuntimeException, std::exception )
202 ::osl::MutexGuard aGuard( m_aMutex );
204 if ( m_bDisposed )
205 throw lang::DisposedException();
207 if ( !m_xInputStream.is() )
208 return uno::Reference< io::XInputStream >();
210 return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY );
213 uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream()
214 throw ( uno::RuntimeException, std::exception )
216 ::osl::MutexGuard aGuard( m_aMutex );
218 if ( m_bDisposed )
219 throw lang::DisposedException();
221 return uno::Reference< io::XOutputStream >();
224 void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location )
225 throw ( lang::IllegalArgumentException,
226 io::IOException,
227 uno::RuntimeException, std::exception )
229 ::osl::MutexGuard aGuard( m_aMutex );
231 if ( m_bDisposed )
232 throw lang::DisposedException();
234 if ( !m_xSeekable.is() )
235 throw uno::RuntimeException();
237 m_xSeekable->seek( location );
240 sal_Int64 SAL_CALL OFSInputStreamContainer::getPosition()
241 throw ( io::IOException,
242 uno::RuntimeException, std::exception)
244 ::osl::MutexGuard aGuard( m_aMutex );
246 if ( m_bDisposed )
247 throw lang::DisposedException();
249 if ( !m_xSeekable.is() )
250 throw uno::RuntimeException();
252 return m_xSeekable->getPosition();
255 sal_Int64 SAL_CALL OFSInputStreamContainer::getLength()
256 throw ( io::IOException,
257 uno::RuntimeException, std::exception )
259 ::osl::MutexGuard aGuard( m_aMutex );
261 if ( m_bDisposed )
262 throw lang::DisposedException();
264 if ( !m_xSeekable.is() )
265 throw uno::RuntimeException();
267 return m_xSeekable->getLength();
270 void SAL_CALL OFSInputStreamContainer::dispose( )
271 throw ( uno::RuntimeException, std::exception )
273 ::osl::MutexGuard aGuard( m_aMutex );
275 if ( m_bDisposed )
276 throw lang::DisposedException();
278 if ( !m_xInputStream.is() )
279 throw uno::RuntimeException();
281 m_xInputStream->closeInput();
283 if ( m_pListenersContainer )
285 lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
286 m_pListenersContainer->disposeAndClear( aSource );
289 m_bDisposed = true;
292 void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
293 throw ( uno::RuntimeException, std::exception )
295 ::osl::MutexGuard aGuard( m_aMutex );
297 if ( m_bDisposed )
298 throw lang::DisposedException();
300 if ( !m_pListenersContainer )
301 m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
303 m_pListenersContainer->addInterface( xListener );
306 void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
307 throw ( uno::RuntimeException, std::exception )
309 ::osl::MutexGuard aGuard( m_aMutex );
311 if ( m_bDisposed )
312 throw lang::DisposedException();
314 if ( m_pListenersContainer )
315 m_pListenersContainer->removeInterface( xListener );
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */