1*f319bb99SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f319bb99SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f319bb99SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f319bb99SAndrew Rist * distributed with this work for additional information 6*f319bb99SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f319bb99SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f319bb99SAndrew Rist * "License"); you may not use this file except in compliance 9*f319bb99SAndrew Rist * with the License. You may obtain a copy of the License at 10*f319bb99SAndrew Rist * 11*f319bb99SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f319bb99SAndrew Rist * 13*f319bb99SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f319bb99SAndrew Rist * software distributed under the License is distributed on an 15*f319bb99SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f319bb99SAndrew Rist * KIND, either express or implied. See the License for the 17*f319bb99SAndrew Rist * specific language governing permissions and limitations 18*f319bb99SAndrew Rist * under the License. 19*f319bb99SAndrew Rist * 20*f319bb99SAndrew Rist *************************************************************/ 21*f319bb99SAndrew Rist 22*f319bb99SAndrew Rist 23cdf0e10cSrcweir #ifndef _SPSTREAM_HXX 24cdf0e10cSrcweir #define _SPSTREAM_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 27cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 28cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 29cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 30cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 31cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp> 32cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp> 33cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 34cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp> 35cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 36cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 37cdf0e10cSrcweir #include <com/sun/star/io/XAsyncOutputMonitor.hpp> 38cdf0e10cSrcweir #include <osl/mutex.hxx> 39cdf0e10cSrcweir #include <cppuhelper/implbase6.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir //================================================================== 42cdf0e10cSrcweir // SwitchablePersistenceStream 43cdf0e10cSrcweir // 44cdf0e10cSrcweir // Allows to switch the stream persistence on the fly. The target 45cdf0e10cSrcweir // stream ( if not filled by the implementation ) MUST have the same 46cdf0e10cSrcweir // size as the original one! 47cdf0e10cSrcweir //================================================================== 48cdf0e10cSrcweir 49cdf0e10cSrcweir struct SPStreamData_Impl; 50cdf0e10cSrcweir class SwitchablePersistenceStream 51cdf0e10cSrcweir : public ::cppu::WeakImplHelper6 < 52cdf0e10cSrcweir ::com::sun::star::io::XStream, 53cdf0e10cSrcweir ::com::sun::star::io::XInputStream, 54cdf0e10cSrcweir ::com::sun::star::io::XOutputStream, 55cdf0e10cSrcweir ::com::sun::star::io::XTruncate, 56cdf0e10cSrcweir ::com::sun::star::io::XSeekable, 57cdf0e10cSrcweir ::com::sun::star::io::XAsyncOutputMonitor > 58cdf0e10cSrcweir { 59cdf0e10cSrcweir ::osl::Mutex m_aMutex; 60cdf0e10cSrcweir 61cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; 62cdf0e10cSrcweir 63cdf0e10cSrcweir SPStreamData_Impl* m_pStreamData; 64cdf0e10cSrcweir 65cdf0e10cSrcweir void CloseAll_Impl(); 66cdf0e10cSrcweir 67cdf0e10cSrcweir public: 68cdf0e10cSrcweir 69cdf0e10cSrcweir SwitchablePersistenceStream( 70cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, 71cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir SwitchablePersistenceStream( 74cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, 75cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir ~SwitchablePersistenceStream(); 78cdf0e10cSrcweir 79cdf0e10cSrcweir void SwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir void SwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInputStream ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir void CopyAndSwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir // com::sun::star::io::XStream 86cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); 87cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); 88cdf0e10cSrcweir 89cdf0e10cSrcweir // com::sun::star::io::XInputStream 90cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 91cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 92cdf0e10cSrcweir virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 93cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL available( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 94cdf0e10cSrcweir virtual void SAL_CALL closeInput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 95cdf0e10cSrcweir 96cdf0e10cSrcweir // com::sun::star::io::XOutputStream 97cdf0e10cSrcweir virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 98cdf0e10cSrcweir virtual void SAL_CALL flush( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 99cdf0e10cSrcweir virtual void SAL_CALL closeOutput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 100cdf0e10cSrcweir 101cdf0e10cSrcweir // com::sun::star::io::XTruncate 102cdf0e10cSrcweir virtual void SAL_CALL truncate( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 103cdf0e10cSrcweir 104cdf0e10cSrcweir // com::sun::star::io::XSeekable 105cdf0e10cSrcweir virtual void SAL_CALL seek( ::sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 106cdf0e10cSrcweir virtual ::sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 107cdf0e10cSrcweir virtual ::sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 108cdf0e10cSrcweir 109cdf0e10cSrcweir // ::com::sun::star::io::XAsyncOutputMonitor 110cdf0e10cSrcweir virtual void SAL_CALL waitForCompletion( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 111cdf0e10cSrcweir 112cdf0e10cSrcweir }; 113cdf0e10cSrcweir 114cdf0e10cSrcweir #endif //_SPSTREAM_HXX 115cdf0e10cSrcweir 116cdf0e10cSrcweir 117