LibreOffice Module svl (master) 1
oinputstreamcontainer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
24
25using namespace ::com::sun::star;
26
27OFSInputStreamContainer::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{
34}
35
37{
38}
39
40uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
41{
42 if (m_bSeekable)
43 {
47
48 return aTypeCollection.getTypes();
49 }
50 else
51 {
54
55 return aTypeCollection.getTypes();
56 }
57}
58
60{
61 // Attention:
62 // Don't use mutex or guard in this method!!! Is a method of XInterface.
63
64 uno::Any aReturn;
65 if ( m_bSeekable )
66 aReturn = ::cppu::queryInterface( rType,
67 static_cast< io::XStream* >( this ),
68 static_cast< io::XInputStream* >( this ),
69 static_cast< io::XSeekable* >( this ) );
70 else
71 aReturn = ::cppu::queryInterface( rType,
72 static_cast< io::XStream* >( this ),
73 static_cast< io::XInputStream* >( this ) );
74
75 if ( aReturn.hasValue() )
76 return aReturn ;
77
78 return ::cppu::OWeakObject::queryInterface( rType ) ;
79}
80
82 noexcept
83{
85}
86
88 noexcept
89{
91}
92
93sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
94{
95 std::scoped_lock aGuard( m_aMutex );
96
97 if ( m_bDisposed )
98 throw lang::DisposedException();
99
100 if ( !m_xInputStream.is() )
101 throw uno::RuntimeException();
102
103 return m_xInputStream->readBytes( aData, nBytesToRead );
104}
105
106sal_Int32 SAL_CALL OFSInputStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
107{
108 std::scoped_lock aGuard( m_aMutex );
109
110 if ( m_bDisposed )
111 throw lang::DisposedException();
112
113 if ( !m_xInputStream.is() )
114 throw uno::RuntimeException();
115
116 return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
117}
118
119void SAL_CALL OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
120{
121 std::scoped_lock aGuard( m_aMutex );
122
123 if ( m_bDisposed )
124 throw lang::DisposedException();
125
126 if ( !m_xInputStream.is() )
127 throw uno::RuntimeException();
128
129 m_xInputStream->skipBytes( nBytesToSkip );
130}
131
133{
134 std::scoped_lock aGuard( m_aMutex );
135
136 if ( m_bDisposed )
137 throw lang::DisposedException();
138
139 if ( !m_xInputStream.is() )
140 throw uno::RuntimeException();
141
142 return m_xInputStream->available();
143}
144
146{
147 {
148 std::scoped_lock aGuard( m_aMutex );
149
150 if ( m_bDisposed )
151 throw lang::DisposedException();
152
153 if ( !m_xInputStream.is() )
154 throw uno::RuntimeException();
155 }
156 dispose();
157}
158
159uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream()
160{
161 std::scoped_lock aGuard( m_aMutex );
162
163 if ( m_bDisposed )
164 throw lang::DisposedException();
165
166 if ( !m_xInputStream.is() )
167 return uno::Reference< io::XInputStream >();
168
169 return this;
170}
171
172uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream()
173{
174 std::scoped_lock aGuard( m_aMutex );
175
176 if ( m_bDisposed )
177 throw lang::DisposedException();
178
179 return uno::Reference< io::XOutputStream >();
180}
181
182void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location )
183{
184 std::scoped_lock aGuard( m_aMutex );
185
186 if ( m_bDisposed )
187 throw lang::DisposedException();
188
189 if ( !m_xSeekable.is() )
190 throw uno::RuntimeException();
191
192 m_xSeekable->seek( location );
193}
194
196{
197 std::scoped_lock aGuard( m_aMutex );
198
199 if ( m_bDisposed )
200 throw lang::DisposedException();
201
202 if ( !m_xSeekable.is() )
203 throw uno::RuntimeException();
204
205 return m_xSeekable->getPosition();
206}
207
209{
210 std::scoped_lock aGuard( m_aMutex );
211
212 if ( m_bDisposed )
213 throw lang::DisposedException();
214
215 if ( !m_xSeekable.is() )
216 throw uno::RuntimeException();
217
218 return m_xSeekable->getLength();
219}
220
222{
223 std::unique_lock aGuard( m_aMutex );
224
225 if ( m_bDisposed )
226 return;
227
228 if ( !m_xInputStream.is() )
229 throw uno::RuntimeException();
230
231 m_xInputStream->closeInput();
232
233 lang::EventObject aSource( getXWeak() );
234 m_aListenersContainer.disposeAndClear( aGuard, aSource );
235
236 m_bDisposed = true;
237}
238
239void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
240{
241 std::unique_lock aGuard( m_aMutex );
242
243 if ( m_bDisposed )
244 throw lang::DisposedException();
245
246 m_aListenersContainer.addInterface( aGuard, xListener );
247}
248
249void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
250{
251 std::unique_lock aGuard( m_aMutex );
252
253 if ( m_bDisposed )
254 throw lang::DisposedException();
255
256 m_aListenersContainer.removeInterface( aGuard, xListener );
257}
258
259
260/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XInputStream > xStream
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override
virtual sal_Int64 SAL_CALL getPosition() override
virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nBytesToRead) override
OFSInputStreamContainer(const css::uno::Reference< css::io::XInputStream > &xStream)
virtual sal_Int64 SAL_CALL getLength() override
css::uno::Reference< css::io::XSeekable > m_xSeekable
virtual void SAL_CALL seek(sal_Int64 location) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual sal_Int32 SAL_CALL available() override
virtual void SAL_CALL closeInput() override
::comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aListenersContainer
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nMaxBytesToRead) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL dispose() override
virtual ~OFSInputStreamContainer() override
virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream() override
css::uno::Reference< css::io::XInputStream > m_xInputStream
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream() override
virtual void SAL_CALL acquire() noexcept override
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
bool m_bDisposed
uno::Reference< io::XSeekable > m_xSeekable
constexpr OUStringLiteral aData
bool hasValue()