fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / unotools / source / streaming / streamhelper.cxx
blobda0a198565b109ac9571dc9b225423bd1d77b888
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 <unotools/streamhelper.hxx>
22 namespace utl
25 //------------------------------------------------------------------------------
26 void SAL_CALL OInputStreamHelper::acquire() throw ()
28 InputStreamHelper_Base::acquire();
31 //------------------------------------------------------------------------------
32 void SAL_CALL OInputStreamHelper::release() throw ()
34 InputStreamHelper_Base::release();
37 //------------------------------------------------------------------------------
38 sal_Int32 SAL_CALL OInputStreamHelper::readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
39 throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException)
41 if (!m_xLockBytes.Is())
42 throw stario::NotConnectedException(OUString(), static_cast<staruno::XWeak*>(this));
44 if (nBytesToRead < 0)
45 throw stario::BufferSizeExceededException(OUString(), static_cast<staruno::XWeak*>(this));
47 ::osl::MutexGuard aGuard( m_aMutex );
48 aData.realloc(nBytesToRead);
50 sal_Size nRead;
51 ErrCode nError = m_xLockBytes->ReadAt(m_nActPos, (void*)aData.getArray(), nBytesToRead, &nRead);
52 // FIXME nRead could be truncated on 64-bit arches
53 m_nActPos += (sal_uInt32)nRead;
55 if (nError != ERRCODE_NONE)
56 throw stario::IOException(OUString(), static_cast<staruno::XWeak*>(this));
58 // adjust sequence if data read is lower than the desired data
59 if (nRead < (sal_uInt32)nBytesToRead)
60 aData.realloc( nRead );
62 return nRead;
65 void SAL_CALL OInputStreamHelper::seek( sal_Int64 location ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
67 ::osl::MutexGuard aGuard( m_aMutex );
68 // cast is truncating, but position would be truncated as soon as
69 // put into SvLockBytes anyway
70 m_nActPos = sal::static_int_cast<sal_uInt32>(location);
73 sal_Int64 SAL_CALL OInputStreamHelper::getPosition( ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
75 return m_nActPos;
78 sal_Int64 SAL_CALL OInputStreamHelper::getLength( ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
80 if (!m_xLockBytes.Is())
81 return 0;
83 ::osl::MutexGuard aGuard( m_aMutex );
84 SvLockBytesStat aStat;
85 m_xLockBytes->Stat( &aStat, SVSTATFLAG_DEFAULT );
86 return aStat.nSize;
89 //------------------------------------------------------------------------------
90 sal_Int32 SAL_CALL OInputStreamHelper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData,
91 sal_Int32 nMaxBytesToRead)
92 throw (stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException)
94 // read all data desired
95 return readBytes(aData, nMaxBytesToRead);
98 //------------------------------------------------------------------------------
99 void SAL_CALL OInputStreamHelper::skipBytes(sal_Int32 nBytesToSkip)
100 throw (stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException)
102 ::osl::MutexGuard aGuard( m_aMutex );
103 if (!m_xLockBytes.Is())
104 throw stario::NotConnectedException(OUString(), static_cast<staruno::XWeak*>(this));
106 if (nBytesToSkip < 0)
107 throw stario::BufferSizeExceededException(OUString(), static_cast<staruno::XWeak*>(this));
109 m_nActPos += nBytesToSkip;
112 //------------------------------------------------------------------------------
113 sal_Int32 SAL_CALL OInputStreamHelper::available()
114 throw (stario::NotConnectedException, stario::IOException, staruno::RuntimeException)
116 ::osl::MutexGuard aGuard( m_aMutex );
117 if (!m_xLockBytes.Is())
118 throw stario::NotConnectedException(OUString(), static_cast<staruno::XWeak*>(this));
120 return m_nAvailable;
123 //------------------------------------------------------------------------------
124 void SAL_CALL OInputStreamHelper::closeInput()
125 throw (stario::NotConnectedException, stario::IOException, staruno::RuntimeException)
127 ::osl::MutexGuard aGuard( m_aMutex );
128 if (!m_xLockBytes.Is())
129 throw stario::NotConnectedException(OUString(), static_cast<staruno::XWeak*>(this));
131 m_xLockBytes = NULL;
134 } // namespace utl
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */