From b63609ba5478ed9b020c113f5704f7ea8447dec8 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 21 Sep 2017 15:42:49 +0200 Subject: loplugin:flatten in framework..package Change-Id: Ide8a97eae6e2fdc7d2dcccba1480ac55a9b555bc Reviewed-on: https://gerrit.libreoffice.org/42593 Tested-by: Jenkins Reviewed-by: Noel Grandin --- io/source/acceptor/acc_pipe.cxx | 37 +++---- io/source/connector/ctr_pipe.cxx | 25 ++--- io/source/stm/odata.cxx | 89 +++++----------- io/source/stm/omark.cxx | 216 +++++++++++++++++++-------------------- io/source/stm/opump.cxx | 13 ++- 5 files changed, 161 insertions(+), 219 deletions(-) (limited to 'io') diff --git a/io/source/acceptor/acc_pipe.cxx b/io/source/acceptor/acc_pipe.cxx index b1395946d936..06570022aebc 100644 --- a/io/source/acceptor/acc_pipe.cxx +++ b/io/source/acceptor/acc_pipe.cxx @@ -70,35 +70,32 @@ namespace io_acceptor sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead ) { - if( ! m_nStatus ) + if( m_nStatus ) { - if( aReadBytes.getLength() < nBytesToRead ) - { - aReadBytes.realloc( nBytesToRead ); - } - sal_Int32 n = m_pipe.read( aReadBytes.getArray(), nBytesToRead ); - OSL_ASSERT( n >= 0 && n <= aReadBytes.getLength() ); - if( n < aReadBytes.getLength() ) - { - aReadBytes.realloc( n ); - } - return n; - } - else { throw IOException(); } + if( aReadBytes.getLength() < nBytesToRead ) + { + aReadBytes.realloc( nBytesToRead ); + } + sal_Int32 n = m_pipe.read( aReadBytes.getArray(), nBytesToRead ); + OSL_ASSERT( n >= 0 && n <= aReadBytes.getLength() ); + if( n < aReadBytes.getLength() ) + { + aReadBytes.realloc( n ); + } + return n; + } void PipeConnection::write( const Sequence < sal_Int8 > &seq ) { - if( ! m_nStatus ) + if( m_nStatus ) { - if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() ) - { - throw IOException(); - } + throw IOException(); } - else { + if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() ) + { throw IOException(); } } diff --git a/io/source/connector/ctr_pipe.cxx b/io/source/connector/ctr_pipe.cxx index aacfa48aa6e5..993836236d90 100644 --- a/io/source/connector/ctr_pipe.cxx +++ b/io/source/connector/ctr_pipe.cxx @@ -48,29 +48,26 @@ namespace stoc_connector { sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead ) { - if( ! m_nStatus ) + if( m_nStatus ) { - if( aReadBytes.getLength() != nBytesToRead ) - { - aReadBytes.realloc( nBytesToRead ); - } - return m_pipe.read( aReadBytes.getArray() , aReadBytes.getLength() ); - } - else { throw IOException(); } + if( aReadBytes.getLength() != nBytesToRead ) + { + aReadBytes.realloc( nBytesToRead ); + } + return m_pipe.read( aReadBytes.getArray() , aReadBytes.getLength() ); + } void PipeConnection::write( const Sequence < sal_Int8 > &seq ) { - if( ! m_nStatus ) + if( m_nStatus ) { - if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() ) - { - throw IOException(); - } + throw IOException(); } - else { + if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() ) + { throw IOException(); } } diff --git a/io/source/stm/odata.cxx b/io/source/stm/odata.cxx index 618d52ffa3f7..47a3694407ae 100644 --- a/io/source/stm/odata.cxx +++ b/io/source/stm/odata.cxx @@ -109,72 +109,46 @@ protected: // XInputStream sal_Int32 ODataInputStream::readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) { - sal_Int32 nRead; - - if( m_bValidStream ) - { - nRead = m_input->readBytes( aData , nBytesToRead ); - } - else - { + if( !m_bValidStream ) + { throw NotConnectedException( ); } - + sal_Int32 nRead = m_input->readBytes( aData , nBytesToRead ); return nRead; } sal_Int32 ODataInputStream::readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) { - sal_Int32 nRead; - if( m_bValidStream ) { - nRead = m_input->readSomeBytes( aData , nMaxBytesToRead ); - } - else { + if( !m_bValidStream ) throw NotConnectedException( ); - } - + sal_Int32 nRead = m_input->readSomeBytes( aData , nMaxBytesToRead ); return nRead; } void ODataInputStream::skipBytes(sal_Int32 nBytesToSkip) { - if( m_bValidStream ) { - m_input->skipBytes( nBytesToSkip ); - } - else - { + if( !m_bValidStream ) throw NotConnectedException( ); - } + m_input->skipBytes( nBytesToSkip ); } sal_Int32 ODataInputStream::available() { - sal_Int32 nAvail; - - if( m_bValidStream ) - { - nAvail = m_input->available( ); - } - else - { + if( !m_bValidStream ) throw NotConnectedException( ); - } + sal_Int32 nAvail = m_input->available( ); return nAvail; } void ODataInputStream::closeInput() { - if( m_bValidStream ) { - m_input->closeInput( ); - setInputStream( Reference< XInputStream > () ); - setPredecessor( Reference < XConnectable >() ); - setSuccessor( Reference < XConnectable >() ); - m_bValidStream = false; - } - else - { + if( !m_bValidStream ) throw NotConnectedException( ); - } + m_input->closeInput( ); + setInputStream( Reference< XInputStream > () ); + setPredecessor( Reference < XConnectable >() ); + setSuccessor( Reference < XConnectable >() ); + m_bValidStream = false; } @@ -509,42 +483,27 @@ protected: // XOutputStream void ODataOutputStream::writeBytes(const Sequence< sal_Int8 >& aData) { - if( m_bValidStream ) - { - m_output->writeBytes( aData ); - } - else { + if( !m_bValidStream ) throw NotConnectedException( ); - } + m_output->writeBytes( aData ); } void ODataOutputStream::flush() { - if( m_bValidStream ) - { - m_output->flush(); - } - else - { + if( !m_bValidStream ) throw NotConnectedException(); - } - + m_output->flush(); } void ODataOutputStream::closeOutput() { - if( m_bValidStream ) - { - m_output->closeOutput(); - setOutputStream( Reference< XOutputStream > () ); - setPredecessor( Reference < XConnectable >() ); - setSuccessor( Reference < XConnectable >() ); - } - else - { + if( !m_bValidStream ) throw NotConnectedException(); - } + m_output->closeOutput(); + setOutputStream( Reference< XOutputStream > () ); + setPredecessor( Reference < XConnectable >() ); + setSuccessor( Reference < XConnectable >() ); } // XDataOutputStream diff --git a/io/source/stm/omark.cxx b/io/source/stm/omark.cxx index 4dff49e4c0de..33cc84bfdf8d 100644 --- a/io/source/stm/omark.cxx +++ b/io/source/stm/omark.cxx @@ -137,22 +137,21 @@ OMarkableOutputStream::OMarkableOutputStream( ) // XOutputStream void OMarkableOutputStream::writeBytes(const Sequence< sal_Int8 >& aData) { - if( m_bValidStream ) { - if( m_mapMarks.empty() && ( m_pBuffer->getSize() == 0 ) ) { - // no mark and buffer active, simple write through - m_output->writeBytes( aData ); - } - else { - MutexGuard guard( m_mutex ); - // new data must be buffered - m_pBuffer->writeAt( m_nCurrentPos , aData ); - m_nCurrentPos += aData.getLength(); - checkMarksAndFlush(); - } + if( !m_bValidStream ) { + throw NotConnectedException(); + } + if( m_mapMarks.empty() && ( m_pBuffer->getSize() == 0 ) ) { + // no mark and buffer active, simple write through + m_output->writeBytes( aData ); } else { - throw NotConnectedException(); + MutexGuard guard( m_mutex ); + // new data must be buffered + m_pBuffer->writeAt( m_nCurrentPos , aData ); + m_nCurrentPos += aData.getLength(); + checkMarksAndFlush(); } + } void OMarkableOutputStream::flush() @@ -174,26 +173,25 @@ void OMarkableOutputStream::flush() void OMarkableOutputStream::closeOutput() { - if( m_bValidStream ) { - MutexGuard guard( m_mutex ); - // all marks must be cleared and all + if( !m_bValidStream ) { + throw NotConnectedException(); + } + MutexGuard guard( m_mutex ); + // all marks must be cleared and all - if( ! m_mapMarks.empty() ) - { - m_mapMarks.clear(); - } - m_nCurrentPos = m_pBuffer->getSize(); - checkMarksAndFlush(); + if( ! m_mapMarks.empty() ) + { + m_mapMarks.clear(); + } + m_nCurrentPos = m_pBuffer->getSize(); + checkMarksAndFlush(); - m_output->closeOutput(); + m_output->closeOutput(); + + setOutputStream( Reference< XOutputStream > () ); + setPredecessor( Reference < XConnectable >() ); + setSuccessor( Reference< XConnectable > () ); - setOutputStream( Reference< XOutputStream > () ); - setPredecessor( Reference < XConnectable >() ); - setSuccessor( Reference< XConnectable > () ); - } - else { - throw NotConnectedException(); - } } @@ -474,43 +472,42 @@ sal_Int32 OMarkableInputStream::readBytes(Sequence< sal_Int8 >& aData, sal_Int32 { sal_Int32 nBytesRead; - if( m_bValidStream ) { - MutexGuard guard( m_mutex ); - if( m_mapMarks.empty() && ! m_pBuffer->getSize() ) { - // normal read ! - nBytesRead = m_input->readBytes( aData, nBytesToRead ); - } - else { - // read from buffer - sal_Int32 nRead; + if( !m_bValidStream ) { + throw NotConnectedException( + "MarkableInputStream::readBytes NotConnectedException", + *this ); + } + MutexGuard guard( m_mutex ); + if( m_mapMarks.empty() && ! m_pBuffer->getSize() ) { + // normal read ! + nBytesRead = m_input->readBytes( aData, nBytesToRead ); + } + else { + // read from buffer + sal_Int32 nRead; - // read enough bytes into buffer - if( m_pBuffer->getSize() - m_nCurrentPos < nBytesToRead ) { - sal_Int32 nToRead = nBytesToRead - ( m_pBuffer->getSize() - m_nCurrentPos ); - nRead = m_input->readBytes( aData , nToRead ); + // read enough bytes into buffer + if( m_pBuffer->getSize() - m_nCurrentPos < nBytesToRead ) { + sal_Int32 nToRead = nBytesToRead - ( m_pBuffer->getSize() - m_nCurrentPos ); + nRead = m_input->readBytes( aData , nToRead ); - OSL_ASSERT( aData.getLength() == nRead ); + OSL_ASSERT( aData.getLength() == nRead ); - m_pBuffer->writeAt( m_pBuffer->getSize() , aData ); + m_pBuffer->writeAt( m_pBuffer->getSize() , aData ); - if( nRead < nToRead ) { - nBytesToRead = nBytesToRead - (nToRead-nRead); - } + if( nRead < nToRead ) { + nBytesToRead = nBytesToRead - (nToRead-nRead); } + } - OSL_ASSERT( m_pBuffer->getSize() - m_nCurrentPos >= nBytesToRead ); + OSL_ASSERT( m_pBuffer->getSize() - m_nCurrentPos >= nBytesToRead ); - m_pBuffer->readAt( m_nCurrentPos , aData , nBytesToRead ); + m_pBuffer->readAt( m_nCurrentPos , aData , nBytesToRead ); - m_nCurrentPos += nBytesToRead; - nBytesRead = nBytesToRead; - } - } - else { - throw NotConnectedException( - "MarkableInputStream::readBytes NotConnectedException", - *this ); + m_nCurrentPos += nBytesToRead; + nBytesRead = nBytesToRead; } + return nBytesRead; } @@ -519,46 +516,45 @@ sal_Int32 OMarkableInputStream::readSomeBytes(Sequence< sal_Int8 >& aData, sal_I { sal_Int32 nBytesRead; - if( m_bValidStream ) { - MutexGuard guard( m_mutex ); - if( m_mapMarks.empty() && ! m_pBuffer->getSize() ) { - // normal read ! - nBytesRead = m_input->readSomeBytes( aData, nMaxBytesToRead ); + if( !m_bValidStream ) { + throw NotConnectedException( + "MarkableInputStream::readSomeBytes NotConnectedException", + *this ); + } + + MutexGuard guard( m_mutex ); + if( m_mapMarks.empty() && ! m_pBuffer->getSize() ) { + // normal read ! + nBytesRead = m_input->readSomeBytes( aData, nMaxBytesToRead ); + } + else { + // read from buffer + sal_Int32 nRead = 0; + sal_Int32 nInBuffer = m_pBuffer->getSize() - m_nCurrentPos; + sal_Int32 nAdditionalBytesToRead = Min(nMaxBytesToRead-nInBuffer,m_input->available()); + nAdditionalBytesToRead = Max(0 , nAdditionalBytesToRead ); + + // read enough bytes into buffer + if( 0 == nInBuffer ) { + nRead = m_input->readSomeBytes( aData , nMaxBytesToRead ); + } + else if( nAdditionalBytesToRead ) { + nRead = m_input->readBytes( aData , nAdditionalBytesToRead ); } - else { - // read from buffer - sal_Int32 nRead = 0; - sal_Int32 nInBuffer = m_pBuffer->getSize() - m_nCurrentPos; - sal_Int32 nAdditionalBytesToRead = Min(nMaxBytesToRead-nInBuffer,m_input->available()); - nAdditionalBytesToRead = Max(0 , nAdditionalBytesToRead ); - - // read enough bytes into buffer - if( 0 == nInBuffer ) { - nRead = m_input->readSomeBytes( aData , nMaxBytesToRead ); - } - else if( nAdditionalBytesToRead ) { - nRead = m_input->readBytes( aData , nAdditionalBytesToRead ); - } - if( nRead ) { - aData.realloc( nRead ); - m_pBuffer->writeAt( m_pBuffer->getSize() , aData ); - } + if( nRead ) { + aData.realloc( nRead ); + m_pBuffer->writeAt( m_pBuffer->getSize() , aData ); + } - nBytesRead = Min( nMaxBytesToRead , nInBuffer + nRead ); + nBytesRead = Min( nMaxBytesToRead , nInBuffer + nRead ); - // now take everything from buffer ! - m_pBuffer->readAt( m_nCurrentPos , aData , nBytesRead ); + // now take everything from buffer ! + m_pBuffer->readAt( m_nCurrentPos , aData , nBytesRead ); - m_nCurrentPos += nBytesRead; - } - } - else - { - throw NotConnectedException( - "MarkableInputStream::readSomeBytes NotConnectedException", - *this ); + m_nCurrentPos += nBytesRead; } + return nBytesRead; @@ -580,42 +576,36 @@ void OMarkableInputStream::skipBytes(sal_Int32 nBytesToSkip) sal_Int32 OMarkableInputStream::available() { - sal_Int32 nAvail; - if( m_bValidStream ) { - MutexGuard guard( m_mutex ); - nAvail = m_input->available() + ( m_pBuffer->getSize() - m_nCurrentPos ); - } - else - { + if( !m_bValidStream ) { throw NotConnectedException( "MarkableInputStream::available NotConnectedException", *this ); } + MutexGuard guard( m_mutex ); + sal_Int32 nAvail = m_input->available() + ( m_pBuffer->getSize() - m_nCurrentPos ); return nAvail; } void OMarkableInputStream::closeInput() { - if( m_bValidStream ) { - MutexGuard guard( m_mutex ); - - m_input->closeInput(); - - setInputStream( Reference< XInputStream > () ); - setPredecessor( Reference< XConnectable > () ); - setSuccessor( Reference< XConnectable >() ); - - m_pBuffer.reset(); - m_nCurrentPos = 0; - m_nCurrentMark = 0; - } - else { + if( !m_bValidStream ) { throw NotConnectedException( "MarkableInputStream::closeInput NotConnectedException", *this ); } + MutexGuard guard( m_mutex ); + + m_input->closeInput(); + + setInputStream( Reference< XInputStream > () ); + setPredecessor( Reference< XConnectable > () ); + setSuccessor( Reference< XConnectable >() ); + + m_pBuffer.reset(); + m_nCurrentPos = 0; + m_nCurrentMark = 0; } // XMarkable diff --git a/io/source/stm/opump.cxx b/io/source/stm/opump.cxx index b00ccf3319d9..cf8a356901e8 100644 --- a/io/source/stm/opump.cxx +++ b/io/source/stm/opump.cxx @@ -354,18 +354,17 @@ void Pump::start() { Guard< Mutex > aGuard( m_aMutex ); m_aThread = osl_createSuspendedThread(Pump::static_run,this); - if( m_aThread ) - { - // will be released by OPump::static_run - acquire(); - osl_resumeThread( m_aThread ); - } - else + if( !m_aThread ) { throw RuntimeException( "Pump::start Couldn't create worker thread", *this); } + + // will be released by OPump::static_run + acquire(); + osl_resumeThread( m_aThread ); + } -- cgit v1.2.3