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 
24 #ifndef ODMA_INPUTSTREAM_HXX
25 #define ODMA_INPUTSTREAM_HXX
26 
27 #include <osl/mutex.hxx>
28 #include <com/sun/star/io/XInputStream.hpp>
29 #include <com/sun/star/io/XStream.hpp>
30 #include <com/sun/star/io/XOutputStream.hpp>
31 #include <com/sun/star/io/XTruncate.hpp>
32 #include <com/sun/star/io/XSeekable.hpp>
33 #include <cppuhelper/implbase5.hxx>
34 
35 #include "rtl/ref.hxx"
36 
37 namespace ucbhelper
38 {
39 	class Content;
40 }
41 namespace odma
42 {
43 	typedef ::cppu::WeakImplHelper5<	::com::sun::star::io::XInputStream,
44 										::com::sun::star::io::XStream,
45 										::com::sun::star::io::XTruncate,
46 										::com::sun::star::io::XSeekable,
47 										::com::sun::star::io::XOutputStream> OOdmaStreamBase;
48 
49 	class ContentProvider;
50 	class ContentProperties;
51 	class OOdmaStream : public OOdmaStreamBase
52 	{
53 		::osl::Mutex	m_aMutex;
54 		::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream>	m_xOutput;
55 		::com::sun::star::uno::Reference< ::com::sun::star::io::XTruncate>		m_xTruncate;
56 		::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream>	m_xInput;
57 		::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable>		m_xInputSeek;
58 
59 		::rtl::Reference<ContentProperties>	m_aProp;
60 		::ucbhelper::Content*		        m_pContent;
61 		ContentProvider*				    m_pProvider;
62 		sal_Bool						    m_bInputStreamCalled;
63 		sal_Bool						    m_bOutputStreamCalled;
64 		sal_Bool						    m_bModified;
65 
66 		void ensureInputStream()  throw( ::com::sun::star::io::IOException );
67 		void ensureOutputStream()  throw( ::com::sun::star::io::IOException );
68 		void SAL_CALL closeStream() throw(	::com::sun::star::io::NotConnectedException,
69 											::com::sun::star::io::IOException,
70 											::com::sun::star::uno::RuntimeException );
71 	public:
72 		OOdmaStream(::ucbhelper::Content* _pContent,
73 					ContentProvider* _pProvider,
74 					const ::rtl::Reference<ContentProperties>& _rProp);
75 		virtual ~OOdmaStream();
76 		// com::sun::star::io::XInputStream
77 		virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead )
78 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException,
79 				  ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
80 
81 		virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead )
82 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException,
83 				  ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
84 
85 		virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
86 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException,
87 				  ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
88 
89 		virtual sal_Int32 SAL_CALL available(  )
90 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
91 
92 		virtual void SAL_CALL closeInput(  )
93 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
94 
95 		// com::sun::star::io::XStream
96 		virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getInputStream(  ) throw( com::sun::star::uno::RuntimeException );
97 		virtual com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > SAL_CALL getOutputStream(  ) throw( com::sun::star::uno::RuntimeException );
98 
99 		// com::sun::star::io::XOutputStream
100 		void SAL_CALL writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& aData )
101 					throw( com::sun::star::io::NotConnectedException,
102 						   com::sun::star::io::BufferSizeExceededException,
103 						   com::sun::star::io::IOException,
104 						   com::sun::star::uno::RuntimeException);
105 
106 		void SAL_CALL flush()
107 					throw( com::sun::star::io::NotConnectedException,
108 						   com::sun::star::io::BufferSizeExceededException,
109 						   com::sun::star::io::IOException,
110 						   com::sun::star::uno::RuntimeException);
111         void SAL_CALL closeOutput()
112 					throw( com::sun::star::io::NotConnectedException,
113 						   com::sun::star::io::IOException,
114 						   com::sun::star::uno::RuntimeException );
115 		// XTruncate
116 		virtual void SAL_CALL truncate( void )
117 			throw( com::sun::star::io::IOException,
118 				   com::sun::star::uno::RuntimeException );
119 		// XSeekable
120 		void SAL_CALL seek(sal_Int64 location )
121 			throw( com::sun::star::lang::IllegalArgumentException,
122 				   com::sun::star::io::IOException,
123 				   com::sun::star::uno::RuntimeException );
124 
125 		sal_Int64 SAL_CALL getPosition()
126 			throw( com::sun::star::io::IOException,
127 				   com::sun::star::uno::RuntimeException );
128 
129 		sal_Int64 SAL_CALL getLength()
130 			throw( com::sun::star::io::IOException,
131 				   com::sun::star::uno::RuntimeException );
132 	};
133 }
134 #endif // ODMA_INPUTSTREAM_HXX
135