Branch data Line data Source code
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 : : #include <osl/diagnose.h>
21 : :
22 : : #include "wrapstreamforshare.hxx"
23 : :
24 : : using namespace ::com::sun::star;
25 : :
26 : :
27 : 1276 : WrapStreamForShare::WrapStreamForShare( const uno::Reference< io::XInputStream >& xInStream,
28 : : const SotMutexHolderRef& rMutexRef )
29 : : : m_rMutexRef( rMutexRef )
30 : : , m_xInStream( xInStream )
31 : 1276 : , m_nCurPos( 0 )
32 : : {
33 [ + - ][ + - ]: 1276 : m_xSeekable = uno::Reference< io::XSeekable >( m_xInStream, uno::UNO_QUERY );
34 [ + - ][ - + ]: 1276 : if ( !m_rMutexRef.Is() || !m_xInStream.is() || !m_xSeekable.is() )
[ - + ][ + - ]
35 : : {
36 : : OSL_FAIL( "Wrong initialization of wrapping stream!\n" );
37 [ # # ]: 0 : throw uno::RuntimeException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
38 : : }
39 : 1276 : }
40 : :
41 [ + - ]: 1276 : WrapStreamForShare::~WrapStreamForShare()
42 : : {
43 [ - + ]: 2552 : }
44 : :
45 : : // XInputStream
46 : 1380 : 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 )
51 : : {
52 [ + - ]: 1380 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
53 : :
54 [ - + ]: 1380 : if ( !m_xInStream.is() )
55 [ # # ]: 0 : throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
56 : :
57 [ + - ][ + - ]: 1380 : m_xSeekable->seek( m_nCurPos );
58 : :
59 [ + - ][ + - ]: 1380 : sal_Int32 nRead = m_xInStream->readBytes( aData, nBytesToRead );
60 : 1380 : m_nCurPos += nRead;
61 : :
62 [ + - ]: 1380 : return nRead;
63 : : }
64 : :
65 : 0 : 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 )
70 : : {
71 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
72 : :
73 [ # # ]: 0 : if ( !m_xInStream.is() )
74 [ # # ]: 0 : throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
75 : :
76 [ # # ][ # # ]: 0 : m_xSeekable->seek( m_nCurPos );
77 : :
78 [ # # ][ # # ]: 0 : sal_Int32 nRead = m_xInStream->readSomeBytes( aData, nMaxBytesToRead );
79 : 0 : m_nCurPos += nRead;
80 : :
81 [ # # ]: 0 : return nRead;
82 : : }
83 : :
84 : 0 : void SAL_CALL WrapStreamForShare::skipBytes( sal_Int32 nBytesToSkip )
85 : : throw ( io::NotConnectedException,
86 : : io::BufferSizeExceededException,
87 : : io::IOException,
88 : : uno::RuntimeException )
89 : : {
90 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
91 : :
92 [ # # ]: 0 : if ( !m_xInStream.is() )
93 [ # # ]: 0 : throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
94 : :
95 [ # # ][ # # ]: 0 : m_xSeekable->seek( m_nCurPos );
96 : :
97 [ # # ][ # # ]: 0 : m_xInStream->skipBytes( nBytesToSkip );
98 [ # # ][ # # ]: 0 : m_nCurPos = m_xSeekable->getPosition();
[ # # ]
99 : 0 : }
100 : :
101 : 0 : sal_Int32 SAL_CALL WrapStreamForShare::available()
102 : : throw ( io::NotConnectedException,
103 : : io::IOException,
104 : : uno::RuntimeException )
105 : : {
106 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
107 : :
108 [ # # ]: 0 : if ( !m_xInStream.is() )
109 [ # # ]: 0 : throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
110 : :
111 [ # # ][ # # ]: 0 : return m_xInStream->available();
[ # # ]
112 : : }
113 : :
114 : 28 : void SAL_CALL WrapStreamForShare::closeInput()
115 : : throw ( io::NotConnectedException,
116 : : io::IOException,
117 : : uno::RuntimeException )
118 : : {
119 [ + - ]: 28 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
120 : :
121 [ - + ]: 28 : if ( !m_xInStream.is() )
122 [ # # ]: 0 : throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
123 : :
124 : : // the package is the owner so it will close the stream
125 : : // m_xInStream->closeInput();
126 [ + - ]: 28 : m_xInStream = uno::Reference< io::XInputStream >();
127 [ + - ][ + - ]: 28 : m_xSeekable = uno::Reference< io::XSeekable >();
128 : 28 : }
129 : :
130 : : // XSeekable
131 : 1258 : void SAL_CALL WrapStreamForShare::seek( sal_Int64 location )
132 : : throw ( lang::IllegalArgumentException,
133 : : io::IOException,
134 : : uno::RuntimeException )
135 : : {
136 [ + - ]: 1258 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
137 : :
138 [ - + ]: 1258 : if ( !m_xInStream.is() )
139 [ # # ]: 0 : throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
140 : :
141 : : // let stream implementation do all the checking
142 [ + - ][ + - ]: 1258 : m_xSeekable->seek( location );
143 : :
144 [ + - ][ + - ]: 1258 : m_nCurPos = m_xSeekable->getPosition();
[ + - ]
145 : 1258 : }
146 : :
147 : 0 : sal_Int64 SAL_CALL WrapStreamForShare::getPosition()
148 : : throw ( io::IOException,
149 : : uno::RuntimeException)
150 : : {
151 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
152 : :
153 [ # # ]: 0 : if ( !m_xInStream.is() )
154 [ # # ]: 0 : throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
155 : :
156 [ # # ]: 0 : return m_nCurPos;
157 : : }
158 : :
159 : 0 : sal_Int64 SAL_CALL WrapStreamForShare::getLength()
160 : : throw ( io::IOException,
161 : : uno::RuntimeException )
162 : : {
163 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
164 : :
165 [ # # ]: 0 : if ( !m_xInStream.is() )
166 [ # # ]: 0 : throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
167 : :
168 [ # # ][ # # ]: 0 : return m_xSeekable->getLength();
[ # # ]
169 : : }
170 : :
171 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|