Replace workaround of resize to invalidate with an explicit SfxHint
[LibreOffice.git] / svl / source / fsstor / oinputstreamcontainer.cxx
blobf3a3a68c8f76e023f4ab12e3cff25a34b8e2dd66
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 )
33 m_bSeekable = m_xSeekable.is();
36 OFSInputStreamContainer::~OFSInputStreamContainer()
40 uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
42 if (m_bSeekable)
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();
50 else
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 )
61 // Attention:
62 // Don't use mutex or guard in this method!!! Is a method of XInterface.
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 ) );
75 if ( aReturn.hasValue() )
76 return aReturn ;
78 return ::cppu::OWeakObject::queryInterface( rType ) ;
81 void SAL_CALL OFSInputStreamContainer::acquire()
82 noexcept
84 ::cppu::OWeakObject::acquire();
87 void SAL_CALL OFSInputStreamContainer::release()
88 noexcept
90 ::cppu::OWeakObject::release();
93 sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
95 std::scoped_lock aGuard( m_aMutex );
97 if ( m_bDisposed )
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 std::scoped_lock aGuard( m_aMutex );
110 if ( m_bDisposed )
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 std::scoped_lock aGuard( m_aMutex );
123 if ( m_bDisposed )
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 std::scoped_lock aGuard( m_aMutex );
136 if ( m_bDisposed )
137 throw lang::DisposedException();
139 if ( !m_xInputStream.is() )
140 throw uno::RuntimeException();
142 return m_xInputStream->available();
145 void SAL_CALL OFSInputStreamContainer::closeInput( )
148 std::scoped_lock aGuard( m_aMutex );
150 if ( m_bDisposed )
151 throw lang::DisposedException();
153 if ( !m_xInputStream.is() )
154 throw uno::RuntimeException();
156 dispose();
159 uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream()
161 std::scoped_lock aGuard( m_aMutex );
163 if ( m_bDisposed )
164 throw lang::DisposedException();
166 if ( !m_xInputStream.is() )
167 return uno::Reference< io::XInputStream >();
169 return this;
172 uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream()
174 std::scoped_lock aGuard( m_aMutex );
176 if ( m_bDisposed )
177 throw lang::DisposedException();
179 return uno::Reference< io::XOutputStream >();
182 void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location )
184 std::scoped_lock aGuard( m_aMutex );
186 if ( m_bDisposed )
187 throw lang::DisposedException();
189 if ( !m_xSeekable.is() )
190 throw uno::RuntimeException();
192 m_xSeekable->seek( location );
195 sal_Int64 SAL_CALL OFSInputStreamContainer::getPosition()
197 std::scoped_lock aGuard( m_aMutex );
199 if ( m_bDisposed )
200 throw lang::DisposedException();
202 if ( !m_xSeekable.is() )
203 throw uno::RuntimeException();
205 return m_xSeekable->getPosition();
208 sal_Int64 SAL_CALL OFSInputStreamContainer::getLength()
210 std::scoped_lock aGuard( m_aMutex );
212 if ( m_bDisposed )
213 throw lang::DisposedException();
215 if ( !m_xSeekable.is() )
216 throw uno::RuntimeException();
218 return m_xSeekable->getLength();
221 void SAL_CALL OFSInputStreamContainer::dispose( )
223 std::unique_lock aGuard( m_aMutex );
225 if ( m_bDisposed )
226 return;
228 if ( !m_xInputStream.is() )
229 throw uno::RuntimeException();
231 m_xInputStream->closeInput();
233 lang::EventObject aSource( getXWeak() );
234 m_aListenersContainer.disposeAndClear( aGuard, aSource );
236 m_bDisposed = true;
239 void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
241 std::unique_lock aGuard( m_aMutex );
243 if ( m_bDisposed )
244 throw lang::DisposedException();
246 m_aListenersContainer.addInterface( aGuard, xListener );
249 void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
251 std::unique_lock aGuard( m_aMutex );
253 if ( m_bDisposed )
254 throw lang::DisposedException();
256 m_aListenersContainer.removeInterface( aGuard, xListener );
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */