1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_PACKAGE_SOURCE_XSTOR_SWITCHPERSISTENCESTREAM_HXX
20 #define INCLUDED_PACKAGE_SOURCE_XSTOR_SWITCHPERSISTENCESTREAM_HXX
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/io/XInputStream.hpp>
25 #include <com/sun/star/io/XOutputStream.hpp>
26 #include <com/sun/star/io/XSeekable.hpp>
27 #include <com/sun/star/io/XTruncate.hpp>
28 #include <com/sun/star/io/XStream.hpp>
29 #include <com/sun/star/embed/XTransactedObject.hpp>
30 #include <com/sun/star/beans/XPropertySetInfo.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
33 #include <com/sun/star/io/XAsyncOutputMonitor.hpp>
34 #include <osl/mutex.hxx>
35 #include <cppuhelper/implbase6.hxx>
37 // SwitchablePersistenceStream
39 // Allows to switch the stream persistence on the fly. The target
40 // stream ( if not filled by the implementation ) MUST have the same
41 // size as the original one!
43 struct SPStreamData_Impl
;
44 class SwitchablePersistenceStream
45 : public ::cppu::WeakImplHelper6
<
46 ::com::sun::star::io::XStream
,
47 ::com::sun::star::io::XInputStream
,
48 ::com::sun::star::io::XOutputStream
,
49 ::com::sun::star::io::XTruncate
,
50 ::com::sun::star::io::XSeekable
,
51 ::com::sun::star::io::XAsyncOutputMonitor
>
53 ::osl::Mutex m_aMutex
;
55 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
57 SPStreamData_Impl
* m_pStreamData
;
63 SwitchablePersistenceStream(
64 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xContext
,
65 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xStream
);
67 SwitchablePersistenceStream(
68 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xContext
,
69 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xInStream
);
71 virtual ~SwitchablePersistenceStream();
73 void SwitchPersistenceTo( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xStream
);
75 void SwitchPersistenceTo( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xInputStream
);
77 void CopyAndSwitchPersistenceTo( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xStream
);
79 // com::sun::star::io::XStream
80 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getInputStream( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
81 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
> SAL_CALL
getOutputStream( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
83 // com::sun::star::io::XInputStream
84 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
, std::exception
) SAL_OVERRIDE
;
85 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
, std::exception
) SAL_OVERRIDE
;
86 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
, std::exception
) SAL_OVERRIDE
;
87 virtual ::sal_Int32 SAL_CALL
available( ) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
88 virtual void SAL_CALL
closeInput( ) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
90 // com::sun::star::io::XOutputStream
91 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
, std::exception
) SAL_OVERRIDE
;
92 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
, std::exception
) SAL_OVERRIDE
;
93 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
, std::exception
) SAL_OVERRIDE
;
95 // com::sun::star::io::XTruncate
96 virtual void SAL_CALL
truncate( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
98 // com::sun::star::io::XSeekable
99 virtual void SAL_CALL
seek( ::sal_Int64 location
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
100 virtual ::sal_Int64 SAL_CALL
getPosition( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
101 virtual ::sal_Int64 SAL_CALL
getLength( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
103 // ::com::sun::star::io::XAsyncOutputMonitor
104 virtual void SAL_CALL
waitForCompletion( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
108 #endif // INCLUDED_PACKAGE_SOURCE_XSTOR_SWITCHPERSISTENCESTREAM_HXX
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */