1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*40df464eSAndrew Rist * distributed with this work for additional information
6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at
10*40df464eSAndrew Rist *
11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist *
13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist * software distributed under the License is distributed on an
15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the
17*40df464eSAndrew Rist * specific language governing permissions and limitations
18*40df464eSAndrew Rist * under the License.
19*40df464eSAndrew Rist *
20*40df464eSAndrew Rist *************************************************************/
21*40df464eSAndrew Rist
22*40df464eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "oinputstreamcontainer.hxx"
28cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir using namespace ::com::sun::star;
31cdf0e10cSrcweir
32cdf0e10cSrcweir //-----------------------------------------------
OFSInputStreamContainer(const uno::Reference<io::XInputStream> & xStream)33cdf0e10cSrcweir OFSInputStreamContainer::OFSInputStreamContainer( const uno::Reference< io::XInputStream >& xStream )
34cdf0e10cSrcweir : m_xInputStream( xStream )
35cdf0e10cSrcweir , m_xSeekable( xStream, uno::UNO_QUERY )
36cdf0e10cSrcweir , m_bSeekable( sal_False )
37cdf0e10cSrcweir , m_bDisposed( sal_False )
38cdf0e10cSrcweir , m_pListenersContainer( NULL )
39cdf0e10cSrcweir {
40cdf0e10cSrcweir m_bSeekable = m_xSeekable.is();
41cdf0e10cSrcweir }
42cdf0e10cSrcweir
43cdf0e10cSrcweir //-----------------------------------------------
~OFSInputStreamContainer()44cdf0e10cSrcweir OFSInputStreamContainer::~OFSInputStreamContainer()
45cdf0e10cSrcweir {
46cdf0e10cSrcweir if ( m_pListenersContainer )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir delete m_pListenersContainer;
49cdf0e10cSrcweir m_pListenersContainer = NULL;
50cdf0e10cSrcweir }
51cdf0e10cSrcweir }
52cdf0e10cSrcweir
53cdf0e10cSrcweir //-----------------------------------------------
getTypes()54cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
55cdf0e10cSrcweir throw ( uno::RuntimeException )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir static ::cppu::OTypeCollection* pTypeCollection = NULL ;
58cdf0e10cSrcweir
59cdf0e10cSrcweir if ( pTypeCollection == NULL )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ) ;
62cdf0e10cSrcweir
63cdf0e10cSrcweir if ( pTypeCollection == NULL )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir if ( m_bSeekable )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir static ::cppu::OTypeCollection aTypeCollection(
68cdf0e10cSrcweir ::getCppuType(( const uno::Reference< io::XStream >* )NULL ),
69cdf0e10cSrcweir ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ),
70cdf0e10cSrcweir ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ) );
71cdf0e10cSrcweir
72cdf0e10cSrcweir pTypeCollection = &aTypeCollection ;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir else
75cdf0e10cSrcweir {
76cdf0e10cSrcweir static ::cppu::OTypeCollection aTypeCollection(
77cdf0e10cSrcweir ::getCppuType(( const uno::Reference< io::XStream >* )NULL ),
78cdf0e10cSrcweir ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ) );
79cdf0e10cSrcweir
80cdf0e10cSrcweir pTypeCollection = &aTypeCollection ;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir }
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir return pTypeCollection->getTypes() ;
86cdf0e10cSrcweir
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
89cdf0e10cSrcweir //-----------------------------------------------
queryInterface(const uno::Type & rType)90cdf0e10cSrcweir uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType )
91cdf0e10cSrcweir throw( uno::RuntimeException )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir // Attention:
94cdf0e10cSrcweir // Don't use mutex or guard in this method!!! Is a method of XInterface.
95cdf0e10cSrcweir
96cdf0e10cSrcweir uno::Any aReturn;
97cdf0e10cSrcweir if ( m_bSeekable )
98cdf0e10cSrcweir aReturn = uno::Any( ::cppu::queryInterface( rType,
99cdf0e10cSrcweir static_cast< io::XStream* >( this ),
100cdf0e10cSrcweir static_cast< io::XInputStream* >( this ),
101cdf0e10cSrcweir static_cast< io::XSeekable* >( this ) ) );
102cdf0e10cSrcweir else
103cdf0e10cSrcweir aReturn = uno::Any( ::cppu::queryInterface( rType,
104cdf0e10cSrcweir static_cast< io::XStream* >( this ),
105cdf0e10cSrcweir static_cast< io::XInputStream* >( this ) ) );
106cdf0e10cSrcweir
107cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
108cdf0e10cSrcweir return aReturn ;
109cdf0e10cSrcweir
110cdf0e10cSrcweir return ::cppu::OWeakObject::queryInterface( rType ) ;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir //-----------------------------------------------
acquire()114cdf0e10cSrcweir void SAL_CALL OFSInputStreamContainer::acquire()
115cdf0e10cSrcweir throw()
116cdf0e10cSrcweir {
117cdf0e10cSrcweir ::cppu::OWeakObject::acquire();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir //-----------------------------------------------
release()121cdf0e10cSrcweir void SAL_CALL OFSInputStreamContainer::release()
122cdf0e10cSrcweir throw()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir ::cppu::OWeakObject::release();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
127cdf0e10cSrcweir //-----------------------------------------------
readBytes(uno::Sequence<sal_Int8> & aData,sal_Int32 nBytesToRead)128cdf0e10cSrcweir sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
129cdf0e10cSrcweir throw ( io::NotConnectedException,
130cdf0e10cSrcweir io::BufferSizeExceededException,
131cdf0e10cSrcweir io::IOException,
132cdf0e10cSrcweir uno::RuntimeException )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
135cdf0e10cSrcweir
136cdf0e10cSrcweir if ( m_bDisposed )
137cdf0e10cSrcweir throw lang::DisposedException();
138cdf0e10cSrcweir
139cdf0e10cSrcweir if ( !m_xInputStream.is() )
140cdf0e10cSrcweir throw uno::RuntimeException();
141cdf0e10cSrcweir
142cdf0e10cSrcweir return m_xInputStream->readBytes( aData, nBytesToRead );
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir //-----------------------------------------------
readSomeBytes(uno::Sequence<sal_Int8> & aData,sal_Int32 nMaxBytesToRead)146cdf0e10cSrcweir sal_Int32 SAL_CALL OFSInputStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
147cdf0e10cSrcweir throw ( io::NotConnectedException,
148cdf0e10cSrcweir io::BufferSizeExceededException,
149cdf0e10cSrcweir io::IOException,
150cdf0e10cSrcweir uno::RuntimeException )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
153cdf0e10cSrcweir
154cdf0e10cSrcweir if ( m_bDisposed )
155cdf0e10cSrcweir throw lang::DisposedException();
156cdf0e10cSrcweir
157cdf0e10cSrcweir if ( !m_xInputStream.is() )
158cdf0e10cSrcweir throw uno::RuntimeException();
159cdf0e10cSrcweir
160cdf0e10cSrcweir return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir //-----------------------------------------------
skipBytes(sal_Int32 nBytesToSkip)164cdf0e10cSrcweir void SAL_CALL OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
165cdf0e10cSrcweir throw ( io::NotConnectedException,
166cdf0e10cSrcweir io::BufferSizeExceededException,
167cdf0e10cSrcweir io::IOException,
168cdf0e10cSrcweir uno::RuntimeException )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
171cdf0e10cSrcweir
172cdf0e10cSrcweir if ( m_bDisposed )
173cdf0e10cSrcweir throw lang::DisposedException();
174cdf0e10cSrcweir
175cdf0e10cSrcweir if ( !m_xInputStream.is() )
176cdf0e10cSrcweir throw uno::RuntimeException();
177cdf0e10cSrcweir
178cdf0e10cSrcweir m_xInputStream->skipBytes( nBytesToSkip );
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
181cdf0e10cSrcweir //-----------------------------------------------
available()182cdf0e10cSrcweir sal_Int32 SAL_CALL OFSInputStreamContainer::available( )
183cdf0e10cSrcweir throw ( io::NotConnectedException,
184cdf0e10cSrcweir io::IOException,
185cdf0e10cSrcweir uno::RuntimeException )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
188cdf0e10cSrcweir
189cdf0e10cSrcweir if ( m_bDisposed )
190cdf0e10cSrcweir throw lang::DisposedException();
191cdf0e10cSrcweir
192cdf0e10cSrcweir if ( !m_xInputStream.is() )
193cdf0e10cSrcweir throw uno::RuntimeException();
194cdf0e10cSrcweir
195cdf0e10cSrcweir return m_xInputStream->available();
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
198cdf0e10cSrcweir //-----------------------------------------------
closeInput()199cdf0e10cSrcweir void SAL_CALL OFSInputStreamContainer::closeInput( )
200cdf0e10cSrcweir throw ( io::NotConnectedException,
201cdf0e10cSrcweir io::IOException,
202cdf0e10cSrcweir uno::RuntimeException )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
205cdf0e10cSrcweir
206cdf0e10cSrcweir if ( m_bDisposed )
207cdf0e10cSrcweir throw lang::DisposedException();
208cdf0e10cSrcweir
209cdf0e10cSrcweir if ( !m_xInputStream.is() )
210cdf0e10cSrcweir throw uno::RuntimeException();
211cdf0e10cSrcweir
212cdf0e10cSrcweir dispose();
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir //-----------------------------------------------
getInputStream()216cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream()
217cdf0e10cSrcweir throw ( uno::RuntimeException )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
220cdf0e10cSrcweir
221cdf0e10cSrcweir if ( m_bDisposed )
222cdf0e10cSrcweir throw lang::DisposedException();
223cdf0e10cSrcweir
224cdf0e10cSrcweir if ( !m_xInputStream.is() )
225cdf0e10cSrcweir return uno::Reference< io::XInputStream >();
226cdf0e10cSrcweir
227cdf0e10cSrcweir return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY );
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir //-----------------------------------------------
getOutputStream()231cdf0e10cSrcweir uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream()
232cdf0e10cSrcweir throw ( uno::RuntimeException )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
235cdf0e10cSrcweir
236cdf0e10cSrcweir if ( m_bDisposed )
237cdf0e10cSrcweir throw lang::DisposedException();
238cdf0e10cSrcweir
239cdf0e10cSrcweir return uno::Reference< io::XOutputStream >();
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
242cdf0e10cSrcweir //-----------------------------------------------
seek(sal_Int64 location)243cdf0e10cSrcweir void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location )
244cdf0e10cSrcweir throw ( lang::IllegalArgumentException,
245cdf0e10cSrcweir io::IOException,
246cdf0e10cSrcweir uno::RuntimeException )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
249cdf0e10cSrcweir
250cdf0e10cSrcweir if ( m_bDisposed )
251cdf0e10cSrcweir throw lang::DisposedException();
252cdf0e10cSrcweir
253cdf0e10cSrcweir if ( !m_xSeekable.is() )
254cdf0e10cSrcweir throw uno::RuntimeException();
255cdf0e10cSrcweir
256cdf0e10cSrcweir m_xSeekable->seek( location );
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir //-----------------------------------------------
getPosition()260cdf0e10cSrcweir sal_Int64 SAL_CALL OFSInputStreamContainer::getPosition()
261cdf0e10cSrcweir throw ( io::IOException,
262cdf0e10cSrcweir uno::RuntimeException)
263cdf0e10cSrcweir {
264cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
265cdf0e10cSrcweir
266cdf0e10cSrcweir if ( m_bDisposed )
267cdf0e10cSrcweir throw lang::DisposedException();
268cdf0e10cSrcweir
269cdf0e10cSrcweir if ( !m_xSeekable.is() )
270cdf0e10cSrcweir throw uno::RuntimeException();
271cdf0e10cSrcweir
272cdf0e10cSrcweir return m_xSeekable->getPosition();
273cdf0e10cSrcweir }
274cdf0e10cSrcweir
275cdf0e10cSrcweir //-----------------------------------------------
getLength()276cdf0e10cSrcweir sal_Int64 SAL_CALL OFSInputStreamContainer::getLength()
277cdf0e10cSrcweir throw ( io::IOException,
278cdf0e10cSrcweir uno::RuntimeException )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
281cdf0e10cSrcweir
282cdf0e10cSrcweir if ( m_bDisposed )
283cdf0e10cSrcweir throw lang::DisposedException();
284cdf0e10cSrcweir
285cdf0e10cSrcweir if ( !m_xSeekable.is() )
286cdf0e10cSrcweir throw uno::RuntimeException();
287cdf0e10cSrcweir
288cdf0e10cSrcweir return m_xSeekable->getLength();
289cdf0e10cSrcweir }
290cdf0e10cSrcweir
291cdf0e10cSrcweir //-----------------------------------------------
dispose()292cdf0e10cSrcweir void SAL_CALL OFSInputStreamContainer::dispose( )
293cdf0e10cSrcweir throw ( uno::RuntimeException )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
296cdf0e10cSrcweir
297cdf0e10cSrcweir if ( m_bDisposed )
298cdf0e10cSrcweir throw lang::DisposedException();
299cdf0e10cSrcweir
300cdf0e10cSrcweir if ( !m_xInputStream.is() )
301cdf0e10cSrcweir throw uno::RuntimeException();
302cdf0e10cSrcweir
303cdf0e10cSrcweir m_xInputStream->closeInput();
304cdf0e10cSrcweir
305cdf0e10cSrcweir if ( m_pListenersContainer )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
308cdf0e10cSrcweir m_pListenersContainer->disposeAndClear( aSource );
309cdf0e10cSrcweir }
310cdf0e10cSrcweir
311cdf0e10cSrcweir m_bDisposed = sal_True;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
314cdf0e10cSrcweir //-----------------------------------------------
addEventListener(const uno::Reference<lang::XEventListener> & xListener)315cdf0e10cSrcweir void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
316cdf0e10cSrcweir throw ( uno::RuntimeException )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
319cdf0e10cSrcweir
320cdf0e10cSrcweir if ( m_bDisposed )
321cdf0e10cSrcweir throw lang::DisposedException();
322cdf0e10cSrcweir
323cdf0e10cSrcweir if ( !m_pListenersContainer )
324cdf0e10cSrcweir m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
325cdf0e10cSrcweir
326cdf0e10cSrcweir m_pListenersContainer->addInterface( xListener );
327cdf0e10cSrcweir }
328cdf0e10cSrcweir
329cdf0e10cSrcweir //-----------------------------------------------
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)330cdf0e10cSrcweir void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
331cdf0e10cSrcweir throw ( uno::RuntimeException )
332cdf0e10cSrcweir {
333cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
334cdf0e10cSrcweir
335cdf0e10cSrcweir if ( m_bDisposed )
336cdf0e10cSrcweir throw lang::DisposedException();
337cdf0e10cSrcweir
338cdf0e10cSrcweir if ( m_pListenersContainer )
339cdf0e10cSrcweir m_pListenersContainer->removeInterface( xListener );
340cdf0e10cSrcweir }
341cdf0e10cSrcweir
342cdf0e10cSrcweir
343cdf0e10cSrcweir
344