fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / package / source / zippackage / wrapstreamforshare.cxx
blob171faad914569462f8f062102239528c64e293bb
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 .
20 #include <osl/diagnose.h>
22 #include "wrapstreamforshare.hxx"
24 using namespace ::com::sun::star;
27 WrapStreamForShare::WrapStreamForShare( const uno::Reference< io::XInputStream >& xInStream,
28 const SotMutexHolderRef& rMutexRef )
29 : m_rMutexRef( rMutexRef )
30 , m_xInStream( xInStream )
31 , m_nCurPos( 0 )
33 m_xSeekable = uno::Reference< io::XSeekable >( m_xInStream, uno::UNO_QUERY );
34 if ( !m_rMutexRef.Is() || !m_xInStream.is() || !m_xSeekable.is() )
36 OSL_FAIL( "Wrong initialization of wrapping stream!\n" );
37 throw uno::RuntimeException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
41 WrapStreamForShare::~WrapStreamForShare()
45 // XInputStream
46 sal_Int32 SAL_CALL WrapStreamForShare::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
47 throw ( io::NotConnectedException,
48 io::BufferSizeExceededException,
49 io::IOException,
50 uno::RuntimeException )
52 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
54 if ( !m_xInStream.is() )
55 throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
57 m_xSeekable->seek( m_nCurPos );
59 sal_Int32 nRead = m_xInStream->readBytes( aData, nBytesToRead );
60 m_nCurPos += nRead;
62 return nRead;
65 sal_Int32 SAL_CALL WrapStreamForShare::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
66 throw ( io::NotConnectedException,
67 io::BufferSizeExceededException,
68 io::IOException,
69 uno::RuntimeException )
71 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
73 if ( !m_xInStream.is() )
74 throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
76 m_xSeekable->seek( m_nCurPos );
78 sal_Int32 nRead = m_xInStream->readSomeBytes( aData, nMaxBytesToRead );
79 m_nCurPos += nRead;
81 return nRead;
84 void SAL_CALL WrapStreamForShare::skipBytes( sal_Int32 nBytesToSkip )
85 throw ( io::NotConnectedException,
86 io::BufferSizeExceededException,
87 io::IOException,
88 uno::RuntimeException )
90 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
92 if ( !m_xInStream.is() )
93 throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
95 m_xSeekable->seek( m_nCurPos );
97 m_xInStream->skipBytes( nBytesToSkip );
98 m_nCurPos = m_xSeekable->getPosition();
101 sal_Int32 SAL_CALL WrapStreamForShare::available()
102 throw ( io::NotConnectedException,
103 io::IOException,
104 uno::RuntimeException )
106 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
108 if ( !m_xInStream.is() )
109 throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
111 return m_xInStream->available();
114 void SAL_CALL WrapStreamForShare::closeInput()
115 throw ( io::NotConnectedException,
116 io::IOException,
117 uno::RuntimeException )
119 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
121 if ( !m_xInStream.is() )
122 throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
124 // the package is the owner so it will close the stream
125 // m_xInStream->closeInput();
126 m_xInStream = uno::Reference< io::XInputStream >();
127 m_xSeekable = uno::Reference< io::XSeekable >();
130 // XSeekable
131 void SAL_CALL WrapStreamForShare::seek( sal_Int64 location )
132 throw ( lang::IllegalArgumentException,
133 io::IOException,
134 uno::RuntimeException )
136 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
138 if ( !m_xInStream.is() )
139 throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
141 // let stream implementation do all the checking
142 m_xSeekable->seek( location );
144 m_nCurPos = m_xSeekable->getPosition();
147 sal_Int64 SAL_CALL WrapStreamForShare::getPosition()
148 throw ( io::IOException,
149 uno::RuntimeException)
151 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
153 if ( !m_xInStream.is() )
154 throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
156 return m_nCurPos;
159 sal_Int64 SAL_CALL WrapStreamForShare::getLength()
160 throw ( io::IOException,
161 uno::RuntimeException )
163 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
165 if ( !m_xInStream.is() )
166 throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
168 return m_xSeekable->getLength();
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */