1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "unotools/unotoolsdllapi.h"
24 
25 #ifndef _UNOTOOLS_STREAMHELPER_HXX_
26 #define _UNOTOOLS_STREAMHELPER_HXX_
27 #include <com/sun/star/io/XOutputStream.hpp>
28 #include <com/sun/star/io/XInputStream.hpp>
29 #include <com/sun/star/io/XSeekable.hpp>
30 #include <osl/mutex.hxx>
31 #include <cppuhelper/implbase1.hxx>
32 #include <cppuhelper/implbase2.hxx>
33 #include <tools/stream.hxx>
34 
35 namespace utl
36 {
37 	namespace stario	= ::com::sun::star::io;
38 	namespace staruno	= ::com::sun::star::uno;
39 
40 /**
41  * The helper implementation for a using input streams based on SvLockBytes.
42  *
43  * @author	Dirk Grobler
44  * @since	00/28/03
45  */
46     typedef ::cppu::WeakImplHelper2<stario::XInputStream, stario::XSeekable> InputStreamHelper_Base;
47 	// needed for some compilers
48 class UNOTOOLS_DLLPUBLIC OInputStreamHelper : public InputStreamHelper_Base
49 {
50 	::osl::Mutex	m_aMutex;
51 	SvLockBytesRef	m_xLockBytes;
52 	sal_uInt32		m_nActPos;
53 	sal_Int32		m_nAvailable;	// this is typically the chunk(buffer) size
54 
55 public:
OInputStreamHelper(const SvLockBytesRef & _xLockBytes,sal_uInt32 _nAvailable,sal_uInt32 _nPos=0)56 	OInputStreamHelper(const SvLockBytesRef& _xLockBytes,
57 					   sal_uInt32 _nAvailable,
58 					   sal_uInt32 _nPos = 0)
59 		:m_xLockBytes(_xLockBytes)
60 		,m_nActPos(_nPos)
61 		,m_nAvailable(_nAvailable){}
62 
63 // staruno::XInterface
64 	virtual void SAL_CALL acquire() throw ();
65 	virtual void SAL_CALL release() throw ();
66 
67 // stario::XInputStream
68     virtual sal_Int32 SAL_CALL readBytes( staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException);
69     virtual sal_Int32 SAL_CALL readSomeBytes( staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException);
70     virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException);
71     virtual sal_Int32 SAL_CALL available(  ) throw(stario::NotConnectedException, stario::IOException, staruno::RuntimeException);
72     virtual void SAL_CALL closeInput(  ) throw (stario::NotConnectedException, stario::IOException, staruno::RuntimeException);
73 
74     virtual void SAL_CALL seek( sal_Int64 location ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
75     virtual sal_Int64 SAL_CALL getPosition(  ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
76     virtual sal_Int64 SAL_CALL getLength(  ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
77 };
78 
79 /**
80  * The helper implementation for a using output streams based on SvLockBytes.
81  *
82  * @author	Dirk Grobler
83  * @since	00/28/03
84  */
85 typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamHelper_Base;
86 	// needed for some compilers
87 class UNOTOOLS_DLLPUBLIC OOutputStreamHelper : public OutputStreamHelper_Base
88 {
89 	::osl::Mutex	m_aMutex;
90 	SvLockBytesRef	m_xLockBytes;
91 	sal_uInt32		m_nActPos;
92 
93 public:
OOutputStreamHelper(const SvLockBytesRef & _xLockBytes,sal_uInt32 _nPos=0)94 	OOutputStreamHelper(const SvLockBytesRef& _xLockBytes, sal_uInt32 _nPos = 0)
95 		:m_xLockBytes(_xLockBytes)
96 		,m_nActPos(_nPos){}
97 
98 // staruno::XInterface
99 	virtual void SAL_CALL acquire() throw ();
100 	virtual void SAL_CALL release() throw ();
101 
102 // stario::XOutputStream
103     virtual void SAL_CALL writeBytes( const staruno::Sequence< sal_Int8 >& aData ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException);
104     virtual void SAL_CALL flush(  ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException);
105     virtual void SAL_CALL closeOutput(  ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException);
106 };
107 
108 }	// namespace utl
109 
110 
111 #endif // _UNOTOOLS_STREAM_WRAPPER_HXX_
112 
113