1*6df1ea1fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6df1ea1fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6df1ea1fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6df1ea1fSAndrew Rist  * distributed with this work for additional information
6*6df1ea1fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6df1ea1fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6df1ea1fSAndrew Rist  * "License"); you may not use this file except in compliance
9*6df1ea1fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6df1ea1fSAndrew Rist  *
11*6df1ea1fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6df1ea1fSAndrew Rist  *
13*6df1ea1fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6df1ea1fSAndrew Rist  * software distributed under the License is distributed on an
15*6df1ea1fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6df1ea1fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*6df1ea1fSAndrew Rist  * specific language governing permissions and limitations
18*6df1ea1fSAndrew Rist  * under the License.
19*6df1ea1fSAndrew Rist  *
20*6df1ea1fSAndrew Rist  *************************************************************/
21*6df1ea1fSAndrew Rist 
22*6df1ea1fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef ODMA_INPUTSTREAM_HXX
25cdf0e10cSrcweir #define ODMA_INPUTSTREAM_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <osl/mutex.hxx>
28cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
29cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
31cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp>
32cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
33cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "rtl/ref.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace ucbhelper
38cdf0e10cSrcweir {
39cdf0e10cSrcweir 	class Content;
40cdf0e10cSrcweir }
41cdf0e10cSrcweir namespace odma
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	typedef ::cppu::WeakImplHelper5<	::com::sun::star::io::XInputStream,
44cdf0e10cSrcweir 										::com::sun::star::io::XStream,
45cdf0e10cSrcweir 										::com::sun::star::io::XTruncate,
46cdf0e10cSrcweir 										::com::sun::star::io::XSeekable,
47cdf0e10cSrcweir 										::com::sun::star::io::XOutputStream> OOdmaStreamBase;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	class ContentProvider;
50cdf0e10cSrcweir 	class ContentProperties;
51cdf0e10cSrcweir 	class OOdmaStream : public OOdmaStreamBase
52cdf0e10cSrcweir 	{
53cdf0e10cSrcweir 		::osl::Mutex	m_aMutex;
54cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream>	m_xOutput;
55cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::io::XTruncate>		m_xTruncate;
56cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream>	m_xInput;
57cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable>		m_xInputSeek;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 		::rtl::Reference<ContentProperties>	m_aProp;
60cdf0e10cSrcweir 		::ucbhelper::Content*		        m_pContent;
61cdf0e10cSrcweir 		ContentProvider*				    m_pProvider;
62cdf0e10cSrcweir 		sal_Bool						    m_bInputStreamCalled;
63cdf0e10cSrcweir 		sal_Bool						    m_bOutputStreamCalled;
64cdf0e10cSrcweir 		sal_Bool						    m_bModified;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 		void ensureInputStream()  throw( ::com::sun::star::io::IOException );
67cdf0e10cSrcweir 		void ensureOutputStream()  throw( ::com::sun::star::io::IOException );
68cdf0e10cSrcweir 		void SAL_CALL closeStream() throw(	::com::sun::star::io::NotConnectedException,
69cdf0e10cSrcweir 											::com::sun::star::io::IOException,
70cdf0e10cSrcweir 											::com::sun::star::uno::RuntimeException );
71cdf0e10cSrcweir 	public:
72cdf0e10cSrcweir 		OOdmaStream(::ucbhelper::Content* _pContent,
73cdf0e10cSrcweir 					ContentProvider* _pProvider,
74cdf0e10cSrcweir 					const ::rtl::Reference<ContentProperties>& _rProp);
75cdf0e10cSrcweir 		virtual ~OOdmaStream();
76cdf0e10cSrcweir 		// com::sun::star::io::XInputStream
77cdf0e10cSrcweir 		virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead )
78cdf0e10cSrcweir 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException,
79cdf0e10cSrcweir 				  ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead )
82cdf0e10cSrcweir 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException,
83cdf0e10cSrcweir 				  ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 		virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
86cdf0e10cSrcweir 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException,
87cdf0e10cSrcweir 				  ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 		virtual sal_Int32 SAL_CALL available(  )
90cdf0e10cSrcweir 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 		virtual void SAL_CALL closeInput(  )
93cdf0e10cSrcweir 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 		// com::sun::star::io::XStream
96cdf0e10cSrcweir 		virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getInputStream(  ) throw( com::sun::star::uno::RuntimeException );
97cdf0e10cSrcweir 		virtual com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > SAL_CALL getOutputStream(  ) throw( com::sun::star::uno::RuntimeException );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		// com::sun::star::io::XOutputStream
100cdf0e10cSrcweir 		void SAL_CALL writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& aData )
101cdf0e10cSrcweir 					throw( com::sun::star::io::NotConnectedException,
102cdf0e10cSrcweir 						   com::sun::star::io::BufferSizeExceededException,
103cdf0e10cSrcweir 						   com::sun::star::io::IOException,
104cdf0e10cSrcweir 						   com::sun::star::uno::RuntimeException);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 		void SAL_CALL flush()
107cdf0e10cSrcweir 					throw( com::sun::star::io::NotConnectedException,
108cdf0e10cSrcweir 						   com::sun::star::io::BufferSizeExceededException,
109cdf0e10cSrcweir 						   com::sun::star::io::IOException,
110cdf0e10cSrcweir 						   com::sun::star::uno::RuntimeException);
111cdf0e10cSrcweir         void SAL_CALL closeOutput()
112cdf0e10cSrcweir 					throw( com::sun::star::io::NotConnectedException,
113cdf0e10cSrcweir 						   com::sun::star::io::IOException,
114cdf0e10cSrcweir 						   com::sun::star::uno::RuntimeException );
115cdf0e10cSrcweir 		// XTruncate
116cdf0e10cSrcweir 		virtual void SAL_CALL truncate( void )
117cdf0e10cSrcweir 			throw( com::sun::star::io::IOException,
118cdf0e10cSrcweir 				   com::sun::star::uno::RuntimeException );
119cdf0e10cSrcweir 		// XSeekable
120cdf0e10cSrcweir 		void SAL_CALL seek(sal_Int64 location )
121cdf0e10cSrcweir 			throw( com::sun::star::lang::IllegalArgumentException,
122cdf0e10cSrcweir 				   com::sun::star::io::IOException,
123cdf0e10cSrcweir 				   com::sun::star::uno::RuntimeException );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		sal_Int64 SAL_CALL getPosition()
126cdf0e10cSrcweir 			throw( com::sun::star::io::IOException,
127cdf0e10cSrcweir 				   com::sun::star::uno::RuntimeException );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		sal_Int64 SAL_CALL getLength()
130cdf0e10cSrcweir 			throw( com::sun::star::io::IOException,
131cdf0e10cSrcweir 				   com::sun::star::uno::RuntimeException );
132cdf0e10cSrcweir 	};
133cdf0e10cSrcweir }
134cdf0e10cSrcweir #endif // ODMA_INPUTSTREAM_HXX
135