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 #ifndef _GVFSSTREAM_HXX_ 24 #define _GVFSSTREAM_HXX_ 25 26 #include <sal/types.h> 27 #include <rtl/ustring.hxx> 28 #include <cppuhelper/weak.hxx> 29 #include <com/sun/star/io/XStream.hpp> 30 #include <com/sun/star/io/XInputStream.hpp> 31 #include <com/sun/star/io/XOutputStream.hpp> 32 #include <com/sun/star/io/XTruncate.hpp> 33 #include <com/sun/star/io/XSeekable.hpp> 34 35 #include <libgnomevfs/gnome-vfs-handle.h> 36 37 namespace gvfs 38 { 39 40 class Stream : public ::com::sun::star::io::XStream, 41 public ::com::sun::star::io::XInputStream, 42 public ::com::sun::star::io::XOutputStream, 43 public ::com::sun::star::io::XTruncate, 44 public ::com::sun::star::io::XSeekable, 45 public ::cppu::OWeakObject 46 { 47 private: 48 GnomeVFSHandle *m_handle; 49 GnomeVFSFileInfo m_info; 50 osl::Mutex m_aMutex; 51 sal_Bool m_eof; 52 sal_Bool m_bInputStreamCalled; 53 sal_Bool m_bOutputStreamCalled; 54 55 void throwOnError( GnomeVFSResult result ); 56 57 void closeStream( void ); 58 59 public: 60 Stream ( GnomeVFSHandle *handle, 61 const GnomeVFSFileInfo *aInfo ); 62 virtual ~Stream(); 63 64 // XInterface 65 virtual com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type & type ); 66 virtual void SAL_CALL acquire( void ) 67 throw () 68 { OWeakObject::acquire(); } 69 virtual void SAL_CALL release( void ) 70 throw() 71 { OWeakObject::release(); } 72 73 // XStream 74 virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getInputStream( ); 75 76 virtual com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ); 77 78 // XInputStream 79 virtual sal_Int32 SAL_CALL readBytes( 80 ::com::sun::star::uno::Sequence< sal_Int8 > & aData, 81 sal_Int32 nBytesToRead ); 82 83 virtual sal_Int32 SAL_CALL readSomeBytes( 84 ::com::sun::star::uno::Sequence< sal_Int8 > & aData, 85 sal_Int32 nMaxBytesToRead ); 86 87 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ); 88 89 virtual sal_Int32 SAL_CALL available( void ); 90 91 virtual void SAL_CALL closeInput( void ); 92 93 // XSeekable 94 virtual void SAL_CALL seek( sal_Int64 location ); 95 96 virtual sal_Int64 SAL_CALL getPosition(); 97 98 virtual sal_Int64 SAL_CALL getLength(); 99 100 // XOutputStream 101 virtual void SAL_CALL writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& aData ); 102 103 virtual void SAL_CALL flush( void ); 104 105 106 virtual void SAL_CALL closeOutput( void ); 107 108 // XTruncate 109 virtual void SAL_CALL truncate( void ); 110 }; 111 112 } // namespace gvfs 113 #endif // _GVFSSTREAM_HXX_ 114