xref: /aoo42x/main/ucb/source/ucp/gvfs/gvfs_stream.hxx (revision cdf0e10c)
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 #ifndef _GVFSSTREAM_HXX_
28 #define _GVFSSTREAM_HXX_
29 
30 #include <sal/types.h>
31 #include <rtl/ustring.hxx>
32 #include <cppuhelper/weak.hxx>
33 #include <com/sun/star/io/XStream.hpp>
34 #include <com/sun/star/io/XInputStream.hpp>
35 #include <com/sun/star/io/XOutputStream.hpp>
36 #include <com/sun/star/io/XTruncate.hpp>
37 #include <com/sun/star/io/XSeekable.hpp>
38 
39 #include <libgnomevfs/gnome-vfs-handle.h>
40 
41 namespace gvfs
42 {
43 
44 class Stream : public ::com::sun::star::io::XStream,
45 	       public ::com::sun::star::io::XInputStream,
46 	       public ::com::sun::star::io::XOutputStream,
47 	       public ::com::sun::star::io::XTruncate,
48 	       public ::com::sun::star::io::XSeekable,
49 	       public ::cppu::OWeakObject
50 {
51 private:
52 	GnomeVFSHandle  *m_handle;
53 	GnomeVFSFileInfo m_info;
54 	osl::Mutex       m_aMutex;
55 	sal_Bool         m_eof;
56 	sal_Bool         m_bInputStreamCalled;
57 	sal_Bool         m_bOutputStreamCalled;
58 
59 	void throwOnError( GnomeVFSResult result )
60 		throw( ::com::sun::star::io::NotConnectedException,
61 		       ::com::sun::star::io::BufferSizeExceededException,
62 		       ::com::sun::star::io::IOException,
63 		       ::com::sun::star::uno::RuntimeException );
64 
65 	void closeStream( void )
66 		throw( ::com::sun::star::io::NotConnectedException,
67 		       ::com::sun::star::io::IOException,
68 		       ::com::sun::star::uno::RuntimeException );
69 
70 public:
71 	Stream ( GnomeVFSHandle         *handle,
72 		 const GnomeVFSFileInfo *aInfo );
73 	virtual ~Stream();
74 
75 	// XInterface
76 	virtual com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type & type )
77 		throw( ::com::sun::star::uno::RuntimeException );
78 	virtual void SAL_CALL acquire( void )
79 		throw ()
80 			{ OWeakObject::acquire(); }
81 	virtual void SAL_CALL release( void )
82 		throw()
83 			{ OWeakObject::release(); }
84 
85 	// XStream
86 	virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getInputStream(  )
87 		throw( com::sun::star::uno::RuntimeException );
88 
89 	virtual com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > SAL_CALL getOutputStream(  )
90 		throw( com::sun::star::uno::RuntimeException );
91 
92 	// XInputStream
93 	virtual sal_Int32 SAL_CALL readBytes(
94 	  		::com::sun::star::uno::Sequence< sal_Int8 > & aData,
95 			sal_Int32 nBytesToRead )
96 				throw( ::com::sun::star::io::NotConnectedException,
97 			   		   ::com::sun::star::io::BufferSizeExceededException,
98 			   		   ::com::sun::star::io::IOException,
99 			   		   ::com::sun::star::uno::RuntimeException );
100 
101 	virtual sal_Int32 SAL_CALL readSomeBytes(
102     		::com::sun::star::uno::Sequence< sal_Int8 > & aData,
103 			sal_Int32 nMaxBytesToRead )
104         		throw( ::com::sun::star::io::NotConnectedException,
105                		   ::com::sun::star::io::BufferSizeExceededException,
106                		   ::com::sun::star::io::IOException,
107                		   ::com::sun::star::uno::RuntimeException );
108 
109 	virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
110         		throw( ::com::sun::star::io::NotConnectedException,
111                		   ::com::sun::star::io::BufferSizeExceededException,
112                		   ::com::sun::star::io::IOException,
113                		   ::com::sun::star::uno::RuntimeException );
114 
115 	virtual sal_Int32 SAL_CALL available( void )
116         		throw( ::com::sun::star::io::NotConnectedException,
117                		   ::com::sun::star::io::IOException,
118                		   ::com::sun::star::uno::RuntimeException );
119 
120 	virtual void SAL_CALL closeInput( void )
121         		throw( ::com::sun::star::io::NotConnectedException,
122                		   ::com::sun::star::io::IOException,
123                		   ::com::sun::star::uno::RuntimeException );
124 
125 	// XSeekable
126 	virtual void SAL_CALL seek(	sal_Int64 location )
127 		throw( ::com::sun::star::lang::IllegalArgumentException,
128 			   ::com::sun::star::io::IOException,
129 			   ::com::sun::star::uno::RuntimeException );
130 
131 	virtual sal_Int64 SAL_CALL getPosition()
132 		throw( ::com::sun::star::io::IOException,
133 			   ::com::sun::star::uno::RuntimeException );
134 
135 	virtual sal_Int64 SAL_CALL getLength()
136 		throw( ::com::sun::star::io::IOException,
137 			   ::com::sun::star::uno::RuntimeException );
138 
139         // XOutputStream
140 	virtual void SAL_CALL writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& aData )
141 		throw( com::sun::star::io::NotConnectedException,
142 		       com::sun::star::io::BufferSizeExceededException,
143 		       com::sun::star::io::IOException,
144 		       com::sun::star::uno::RuntimeException);
145 
146 	virtual void SAL_CALL flush( void )
147 		throw( com::sun::star::io::NotConnectedException,
148 		       com::sun::star::io::BufferSizeExceededException,
149 		       com::sun::star::io::IOException,
150 		       com::sun::star::uno::RuntimeException);
151 
152 
153         virtual void SAL_CALL closeOutput( void )
154 		throw( com::sun::star::io::NotConnectedException,
155 		       com::sun::star::io::IOException,
156 		       com::sun::star::uno::RuntimeException );
157 
158 	// XTruncate
159 	virtual void SAL_CALL truncate( void )
160 		throw( com::sun::star::io::IOException,
161 		       com::sun::star::uno::RuntimeException );
162 };
163 
164 } // namespace gvfs
165 #endif // _GVFSSTREAM_HXX_
166