GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / fsstor / oinputstreamcontainer.cxx
blob3c4caa674fd7507e965fdfffe114ac6c28912ae8
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>
24 using namespace ::com::sun::star;
26 OFSInputStreamContainer::OFSInputStreamContainer( const uno::Reference< io::XInputStream >& xStream )
27 : m_xInputStream( xStream )
28 , m_xSeekable( xStream, uno::UNO_QUERY )
29 , m_bSeekable( false )
30 , m_bDisposed( false )
31 , m_pListenersContainer( NULL )
33 m_bSeekable = m_xSeekable.is();
36 OFSInputStreamContainer::~OFSInputStreamContainer()
38 if ( m_pListenersContainer )
40 delete m_pListenersContainer;
41 m_pListenersContainer = NULL;
45 uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
46 throw ( uno::RuntimeException )
48 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
50 if ( pTypeCollection == NULL )
52 ::osl::MutexGuard aGuard( m_aMutex ) ;
54 if ( pTypeCollection == NULL )
56 if ( m_bSeekable )
58 static ::cppu::OTypeCollection aTypeCollection(
59 ::getCppuType(( const uno::Reference< io::XStream >* )NULL ),
60 ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ),
61 ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ) );
63 pTypeCollection = &aTypeCollection ;
65 else
67 static ::cppu::OTypeCollection aTypeCollection(
68 ::getCppuType(( const uno::Reference< io::XStream >* )NULL ),
69 ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ) );
71 pTypeCollection = &aTypeCollection ;
76 return pTypeCollection->getTypes() ;
80 uno::Any SAL_CALL OFSInputStreamContainer::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;
87 if ( m_bSeekable )
88 aReturn = uno::Any( ::cppu::queryInterface( rType,
89 static_cast< io::XStream* >( this ),
90 static_cast< io::XInputStream* >( this ),
91 static_cast< io::XSeekable* >( this ) ) );
92 else
93 aReturn = uno::Any( ::cppu::queryInterface( rType,
94 static_cast< io::XStream* >( this ),
95 static_cast< io::XInputStream* >( this ) ) );
97 if ( aReturn.hasValue() == sal_True )
98 return aReturn ;
100 return ::cppu::OWeakObject::queryInterface( rType ) ;
103 void SAL_CALL OFSInputStreamContainer::acquire()
104 throw()
106 ::cppu::OWeakObject::acquire();
109 void SAL_CALL OFSInputStreamContainer::release()
110 throw()
112 ::cppu::OWeakObject::release();
115 sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
116 throw ( io::NotConnectedException,
117 io::BufferSizeExceededException,
118 io::IOException,
119 uno::RuntimeException )
121 ::osl::MutexGuard aGuard( m_aMutex );
123 if ( m_bDisposed )
124 throw lang::DisposedException();
126 if ( !m_xInputStream.is() )
127 throw uno::RuntimeException();
129 return m_xInputStream->readBytes( aData, nBytesToRead );
132 sal_Int32 SAL_CALL OFSInputStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
133 throw ( io::NotConnectedException,
134 io::BufferSizeExceededException,
135 io::IOException,
136 uno::RuntimeException )
138 ::osl::MutexGuard aGuard( m_aMutex );
140 if ( m_bDisposed )
141 throw lang::DisposedException();
143 if ( !m_xInputStream.is() )
144 throw uno::RuntimeException();
146 return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
149 void SAL_CALL OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
150 throw ( io::NotConnectedException,
151 io::BufferSizeExceededException,
152 io::IOException,
153 uno::RuntimeException )
155 ::osl::MutexGuard aGuard( m_aMutex );
157 if ( m_bDisposed )
158 throw lang::DisposedException();
160 if ( !m_xInputStream.is() )
161 throw uno::RuntimeException();
163 m_xInputStream->skipBytes( nBytesToSkip );
166 sal_Int32 SAL_CALL OFSInputStreamContainer::available( )
167 throw ( io::NotConnectedException,
168 io::IOException,
169 uno::RuntimeException )
171 ::osl::MutexGuard aGuard( m_aMutex );
173 if ( m_bDisposed )
174 throw lang::DisposedException();
176 if ( !m_xInputStream.is() )
177 throw uno::RuntimeException();
179 return m_xInputStream->available();
182 void SAL_CALL OFSInputStreamContainer::closeInput( )
183 throw ( io::NotConnectedException,
184 io::IOException,
185 uno::RuntimeException )
187 ::osl::MutexGuard aGuard( m_aMutex );
189 if ( m_bDisposed )
190 throw lang::DisposedException();
192 if ( !m_xInputStream.is() )
193 throw uno::RuntimeException();
195 dispose();
198 uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream()
199 throw ( uno::RuntimeException )
201 ::osl::MutexGuard aGuard( m_aMutex );
203 if ( m_bDisposed )
204 throw lang::DisposedException();
206 if ( !m_xInputStream.is() )
207 return uno::Reference< io::XInputStream >();
209 return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY );
212 uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream()
213 throw ( uno::RuntimeException )
215 ::osl::MutexGuard aGuard( m_aMutex );
217 if ( m_bDisposed )
218 throw lang::DisposedException();
220 return uno::Reference< io::XOutputStream >();
223 void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location )
224 throw ( lang::IllegalArgumentException,
225 io::IOException,
226 uno::RuntimeException )
228 ::osl::MutexGuard aGuard( m_aMutex );
230 if ( m_bDisposed )
231 throw lang::DisposedException();
233 if ( !m_xSeekable.is() )
234 throw uno::RuntimeException();
236 m_xSeekable->seek( location );
239 sal_Int64 SAL_CALL OFSInputStreamContainer::getPosition()
240 throw ( io::IOException,
241 uno::RuntimeException)
243 ::osl::MutexGuard aGuard( m_aMutex );
245 if ( m_bDisposed )
246 throw lang::DisposedException();
248 if ( !m_xSeekable.is() )
249 throw uno::RuntimeException();
251 return m_xSeekable->getPosition();
254 sal_Int64 SAL_CALL OFSInputStreamContainer::getLength()
255 throw ( io::IOException,
256 uno::RuntimeException )
258 ::osl::MutexGuard aGuard( m_aMutex );
260 if ( m_bDisposed )
261 throw lang::DisposedException();
263 if ( !m_xSeekable.is() )
264 throw uno::RuntimeException();
266 return m_xSeekable->getLength();
269 void SAL_CALL OFSInputStreamContainer::dispose( )
270 throw ( uno::RuntimeException )
272 ::osl::MutexGuard aGuard( m_aMutex );
274 if ( m_bDisposed )
275 throw lang::DisposedException();
277 if ( !m_xInputStream.is() )
278 throw uno::RuntimeException();
280 m_xInputStream->closeInput();
282 if ( m_pListenersContainer )
284 lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
285 m_pListenersContainer->disposeAndClear( aSource );
288 m_bDisposed = true;
291 void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
292 throw ( uno::RuntimeException )
294 ::osl::MutexGuard aGuard( m_aMutex );
296 if ( m_bDisposed )
297 throw lang::DisposedException();
299 if ( !m_pListenersContainer )
300 m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
302 m_pListenersContainer->addInterface( xListener );
305 void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
306 throw ( uno::RuntimeException )
308 ::osl::MutexGuard aGuard( m_aMutex );
310 if ( m_bDisposed )
311 throw lang::DisposedException();
313 if ( m_pListenersContainer )
314 m_pListenersContainer->removeInterface( xListener );
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */