1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef ODMA_INPUTSTREAM_HXX
29 #define ODMA_INPUTSTREAM_HXX
30 
31 #include <osl/mutex.hxx>
32 #include <com/sun/star/io/XInputStream.hpp>
33 #include <com/sun/star/io/XStream.hpp>
34 #include <com/sun/star/io/XOutputStream.hpp>
35 #include <com/sun/star/io/XTruncate.hpp>
36 #include <com/sun/star/io/XSeekable.hpp>
37 #include <cppuhelper/implbase5.hxx>
38 
39 #include "rtl/ref.hxx"
40 
41 namespace ucbhelper
42 {
43 	class Content;
44 }
45 namespace odma
46 {
47 	typedef ::cppu::WeakImplHelper5<	::com::sun::star::io::XInputStream,
48 										::com::sun::star::io::XStream,
49 										::com::sun::star::io::XTruncate,
50 										::com::sun::star::io::XSeekable,
51 										::com::sun::star::io::XOutputStream> OOdmaStreamBase;
52 
53 	class ContentProvider;
54 	class ContentProperties;
55 	class OOdmaStream : public OOdmaStreamBase
56 	{
57 		::osl::Mutex	m_aMutex;
58 		::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream>	m_xOutput;
59 		::com::sun::star::uno::Reference< ::com::sun::star::io::XTruncate>		m_xTruncate;
60 		::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream>	m_xInput;
61 		::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable>		m_xInputSeek;
62 
63 		::rtl::Reference<ContentProperties>	m_aProp;
64 		::ucbhelper::Content*		        m_pContent;
65 		ContentProvider*				    m_pProvider;
66 		sal_Bool						    m_bInputStreamCalled;
67 		sal_Bool						    m_bOutputStreamCalled;
68 		sal_Bool						    m_bModified;
69 
70 		void ensureInputStream()  throw( ::com::sun::star::io::IOException );
71 		void ensureOutputStream()  throw( ::com::sun::star::io::IOException );
72 		void SAL_CALL closeStream() throw(	::com::sun::star::io::NotConnectedException,
73 											::com::sun::star::io::IOException,
74 											::com::sun::star::uno::RuntimeException );
75 	public:
76 		OOdmaStream(::ucbhelper::Content* _pContent,
77 					ContentProvider* _pProvider,
78 					const ::rtl::Reference<ContentProperties>& _rProp);
79 		virtual ~OOdmaStream();
80 		// com::sun::star::io::XInputStream
81 		virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead )
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 sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead )
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 void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
90 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException,
91 				  ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
92 
93 		virtual sal_Int32 SAL_CALL available(  )
94 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
95 
96 		virtual void SAL_CALL closeInput(  )
97 			throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
98 
99 		// com::sun::star::io::XStream
100 		virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getInputStream(  ) throw( com::sun::star::uno::RuntimeException );
101 		virtual com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > SAL_CALL getOutputStream(  ) throw( com::sun::star::uno::RuntimeException );
102 
103 		// com::sun::star::io::XOutputStream
104 		void SAL_CALL writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& aData )
105 					throw( com::sun::star::io::NotConnectedException,
106 						   com::sun::star::io::BufferSizeExceededException,
107 						   com::sun::star::io::IOException,
108 						   com::sun::star::uno::RuntimeException);
109 
110 		void SAL_CALL flush()
111 					throw( com::sun::star::io::NotConnectedException,
112 						   com::sun::star::io::BufferSizeExceededException,
113 						   com::sun::star::io::IOException,
114 						   com::sun::star::uno::RuntimeException);
115         void SAL_CALL closeOutput()
116 					throw( com::sun::star::io::NotConnectedException,
117 						   com::sun::star::io::IOException,
118 						   com::sun::star::uno::RuntimeException );
119 		// XTruncate
120 		virtual void SAL_CALL truncate( void )
121 			throw( com::sun::star::io::IOException,
122 				   com::sun::star::uno::RuntimeException );
123 		// XSeekable
124 		void SAL_CALL seek(sal_Int64 location )
125 			throw( com::sun::star::lang::IllegalArgumentException,
126 				   com::sun::star::io::IOException,
127 				   com::sun::star::uno::RuntimeException );
128 
129 		sal_Int64 SAL_CALL getPosition()
130 			throw( com::sun::star::io::IOException,
131 				   com::sun::star::uno::RuntimeException );
132 
133 		sal_Int64 SAL_CALL getLength()
134 			throw( com::sun::star::io::IOException,
135 				   com::sun::star::uno::RuntimeException );
136 	};
137 }
138 #endif // ODMA_INPUTSTREAM_HXX
139