1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 )
33 m_bSeekable
= m_xSeekable
.is();
36 OFSInputStreamContainer::~OFSInputStreamContainer()
40 uno::Sequence
< uno::Type
> SAL_CALL
OFSInputStreamContainer::getTypes()
44 static cppu::OTypeCollection
aTypeCollection(cppu::UnoType
<io::XStream
>::get(),
45 cppu::UnoType
<io::XInputStream
>::get(),
46 cppu::UnoType
<io::XSeekable
>::get());
48 return aTypeCollection
.getTypes();
52 static cppu::OTypeCollection
aTypeCollection(cppu::UnoType
<io::XStream
>::get(),
53 cppu::UnoType
<io::XInputStream
>::get());
55 return aTypeCollection
.getTypes();
59 uno::Any SAL_CALL
OFSInputStreamContainer::queryInterface( const uno::Type
& rType
)
62 // Don't use mutex or guard in this method!!! Is a method of XInterface.
66 aReturn
= ::cppu::queryInterface( rType
,
67 static_cast< io::XStream
* >( this ),
68 static_cast< io::XInputStream
* >( this ),
69 static_cast< io::XSeekable
* >( this ) );
71 aReturn
= ::cppu::queryInterface( rType
,
72 static_cast< io::XStream
* >( this ),
73 static_cast< io::XInputStream
* >( this ) );
75 if ( aReturn
.hasValue() )
78 return ::cppu::OWeakObject::queryInterface( rType
) ;
81 void SAL_CALL
OFSInputStreamContainer::acquire()
84 ::cppu::OWeakObject::acquire();
87 void SAL_CALL
OFSInputStreamContainer::release()
90 ::cppu::OWeakObject::release();
93 sal_Int32 SAL_CALL
OFSInputStreamContainer::readBytes( uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
95 ::osl::MutexGuard
aGuard( m_aMutex
);
98 throw lang::DisposedException();
100 if ( !m_xInputStream
.is() )
101 throw uno::RuntimeException();
103 return m_xInputStream
->readBytes( aData
, nBytesToRead
);
106 sal_Int32 SAL_CALL
OFSInputStreamContainer::readSomeBytes( uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
108 ::osl::MutexGuard
aGuard( m_aMutex
);
111 throw lang::DisposedException();
113 if ( !m_xInputStream
.is() )
114 throw uno::RuntimeException();
116 return m_xInputStream
->readSomeBytes( aData
, nMaxBytesToRead
);
119 void SAL_CALL
OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip
)
121 ::osl::MutexGuard
aGuard( m_aMutex
);
124 throw lang::DisposedException();
126 if ( !m_xInputStream
.is() )
127 throw uno::RuntimeException();
129 m_xInputStream
->skipBytes( nBytesToSkip
);
132 sal_Int32 SAL_CALL
OFSInputStreamContainer::available( )
134 ::osl::MutexGuard
aGuard( m_aMutex
);
137 throw lang::DisposedException();
139 if ( !m_xInputStream
.is() )
140 throw uno::RuntimeException();
142 return m_xInputStream
->available();
145 void SAL_CALL
OFSInputStreamContainer::closeInput( )
147 ::osl::MutexGuard
aGuard( m_aMutex
);
150 throw lang::DisposedException();
152 if ( !m_xInputStream
.is() )
153 throw uno::RuntimeException();
158 uno::Reference
< io::XInputStream
> SAL_CALL
OFSInputStreamContainer::getInputStream()
160 ::osl::MutexGuard
aGuard( m_aMutex
);
163 throw lang::DisposedException();
165 if ( !m_xInputStream
.is() )
166 return uno::Reference
< io::XInputStream
>();
168 return uno::Reference
< io::XInputStream
>( static_cast< io::XInputStream
* >( this ), uno::UNO_QUERY
);
171 uno::Reference
< io::XOutputStream
> SAL_CALL
OFSInputStreamContainer::getOutputStream()
173 ::osl::MutexGuard
aGuard( m_aMutex
);
176 throw lang::DisposedException();
178 return uno::Reference
< io::XOutputStream
>();
181 void SAL_CALL
OFSInputStreamContainer::seek( sal_Int64 location
)
183 ::osl::MutexGuard
aGuard( m_aMutex
);
186 throw lang::DisposedException();
188 if ( !m_xSeekable
.is() )
189 throw uno::RuntimeException();
191 m_xSeekable
->seek( location
);
194 sal_Int64 SAL_CALL
OFSInputStreamContainer::getPosition()
196 ::osl::MutexGuard
aGuard( m_aMutex
);
199 throw lang::DisposedException();
201 if ( !m_xSeekable
.is() )
202 throw uno::RuntimeException();
204 return m_xSeekable
->getPosition();
207 sal_Int64 SAL_CALL
OFSInputStreamContainer::getLength()
209 ::osl::MutexGuard
aGuard( m_aMutex
);
212 throw lang::DisposedException();
214 if ( !m_xSeekable
.is() )
215 throw uno::RuntimeException();
217 return m_xSeekable
->getLength();
220 void SAL_CALL
OFSInputStreamContainer::dispose( )
222 ::osl::MutexGuard
aGuard( m_aMutex
);
225 throw lang::DisposedException();
227 if ( !m_xInputStream
.is() )
228 throw uno::RuntimeException();
230 m_xInputStream
->closeInput();
232 if ( m_pListenersContainer
)
234 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
*>( this ) );
235 m_pListenersContainer
->disposeAndClear( aSource
);
241 void SAL_CALL
OFSInputStreamContainer::addEventListener( const uno::Reference
< lang::XEventListener
>& xListener
)
243 ::osl::MutexGuard
aGuard( m_aMutex
);
246 throw lang::DisposedException();
248 if ( !m_pListenersContainer
)
249 m_pListenersContainer
.reset( new ::comphelper::OInterfaceContainerHelper2( m_aMutex
) );
251 m_pListenersContainer
->addInterface( xListener
);
254 void SAL_CALL
OFSInputStreamContainer::removeEventListener( const uno::Reference
< lang::XEventListener
>& xListener
)
256 ::osl::MutexGuard
aGuard( m_aMutex
);
259 throw lang::DisposedException();
261 if ( m_pListenersContainer
)
262 m_pListenersContainer
->removeInterface( xListener
);
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */