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 _XTEMPFILE_HXX_ 24 #define _XTEMPFILE_HXX_ 25 26 #include <com/sun/star/io/XInputStream.hpp> 27 #include <com/sun/star/io/XOutputStream.hpp> 28 #include <com/sun/star/io/XSeekable.hpp> 29 #include <com/sun/star/io/XStream.hpp> 30 #include <com/sun/star/io/XTempFile.hpp> 31 #include <com/sun/star/io/XTruncate.hpp> 32 #include <com/sun/star/lang/XSingleComponentFactory.hpp> 33 #include <com/sun/star/lang/XServiceInfo.hpp> 34 #include <cppuhelper/implbase5.hxx> 35 #ifndef _CPPUHELPER_PROPERTYSETMIXIN_HXX_ 36 #include <cppuhelper/propertysetmixin.hxx> 37 #endif 38 #include <osl/mutex.hxx> 39 40 class SvStream; 41 namespace utl { class TempFile; } 42 43 typedef ::cppu::WeakImplHelper5< ::com::sun::star::io::XTempFile 44 , ::com::sun::star::io::XInputStream 45 , ::com::sun::star::io::XOutputStream 46 , ::com::sun::star::io::XTruncate 47 , ::com::sun::star::lang::XServiceInfo 48 > 49 OTempFileBase; 50 51 class OTempFileService : 52 public OTempFileBase, 53 public ::cppu::PropertySetMixin< ::com::sun::star::io::XTempFile > 54 { 55 protected: 56 ::utl::TempFile* mpTempFile; 57 ::osl::Mutex maMutex; 58 SvStream* mpStream; 59 sal_Bool mbRemoveFile; 60 sal_Bool mbInClosed; 61 sal_Bool mbOutClosed; 62 63 sal_Int64 mnCachedPos; 64 sal_Bool mbHasCachedPos; 65 66 void checkError () const; 67 void checkConnected (); 68 69 public: 70 OTempFileService (::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context); 71 72 //Methods 73 // XInterface 74 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ); 75 virtual void SAL_CALL acquire( ) 76 throw (); 77 virtual void SAL_CALL release( ) 78 throw (); 79 // XTypeProvider 80 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ); 81 virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL getImplementationId( ); 82 83 // XTempFile 84 virtual ::sal_Bool SAL_CALL getRemoveFile(); 85 virtual void SAL_CALL setRemoveFile( ::sal_Bool _removefile ); 86 virtual ::rtl::OUString SAL_CALL getUri(); 87 virtual ::rtl::OUString SAL_CALL getResourceName(); 88 89 // XInputStream 90 virtual ::sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ); 91 virtual ::sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ); 92 virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ); 93 virtual ::sal_Int32 SAL_CALL available( ); 94 virtual void SAL_CALL closeInput( ); 95 // XOutputStream 96 virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ); 97 virtual void SAL_CALL flush( ); 98 virtual void SAL_CALL closeOutput( ); 99 // XSeekable 100 virtual void SAL_CALL seek( sal_Int64 location ); 101 virtual sal_Int64 SAL_CALL getPosition( ); 102 virtual sal_Int64 SAL_CALL getLength( ); 103 // XStream 104 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ); 105 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ); 106 // XTruncate 107 virtual void SAL_CALL truncate(); 108 // XServiceInfo 109 virtual ::rtl::OUString SAL_CALL getImplementationName(); 110 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 111 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(); 112 113 //::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > SAL_CALL XTempFile_createInstance( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context); 114 static ::rtl::OUString getImplementationName_Static (); 115 static ::com::sun::star::uno::Sequence < ::rtl::OUString > getSupportedServiceNames_Static(); 116 117 private: 118 OTempFileService( OTempFileService & ); 119 virtual ~OTempFileService (); 120 121 }; 122 #endif 123