Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / package / source / xstor / switchpersistencestream.hxx
blobf52d9bd4415ea8debe0d1308137f95f949849138
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/implbase.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::WeakImplHelper <
46 css::io::XStream,
47 css::io::XInputStream,
48 css::io::XOutputStream,
49 css::io::XTruncate,
50 css::io::XSeekable,
51 css::io::XAsyncOutputMonitor >
53 ::osl::Mutex m_aMutex;
55 const css::uno::Reference< css::uno::XComponentContext > m_xContext;
57 std::unique_ptr<SPStreamData_Impl> m_pStreamData;
59 void CloseAll_Impl();
61 public:
63 SwitchablePersistenceStream(
64 const css::uno::Reference< css::uno::XComponentContext >& xContext,
65 const css::uno::Reference< css::io::XStream >& xStream );
67 SwitchablePersistenceStream(
68 const css::uno::Reference< css::uno::XComponentContext >& xContext,
69 const css::uno::Reference< css::io::XInputStream >& xInStream );
71 virtual ~SwitchablePersistenceStream() override;
73 void SwitchPersistenceTo( const css::uno::Reference< css::io::XStream >& xStream );
75 void SwitchPersistenceTo( const css::uno::Reference< css::io::XInputStream >& xInputStream );
77 void CopyAndSwitchPersistenceTo( const css::uno::Reference< css::io::XStream >& xStream );
79 // css::io::XStream
80 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override;
81 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream( ) override;
83 // css::io::XInputStream
84 virtual ::sal_Int32 SAL_CALL readBytes( css::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) override;
85 virtual ::sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) override;
86 virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) override;
87 virtual ::sal_Int32 SAL_CALL available( ) override;
88 virtual void SAL_CALL closeInput( ) override;
90 // css::io::XOutputStream
91 virtual void SAL_CALL writeBytes( const css::uno::Sequence< ::sal_Int8 >& aData ) override;
92 virtual void SAL_CALL flush( ) override;
93 virtual void SAL_CALL closeOutput( ) override;
95 // css::io::XTruncate
96 virtual void SAL_CALL truncate( ) override;
98 // css::io::XSeekable
99 virtual void SAL_CALL seek( ::sal_Int64 location ) override;
100 virtual ::sal_Int64 SAL_CALL getPosition( ) override;
101 virtual ::sal_Int64 SAL_CALL getLength( ) override;
103 // css::io::XAsyncOutputMonitor
104 virtual void SAL_CALL waitForCompletion( ) override;
108 #endif // INCLUDED_PACKAGE_SOURCE_XSTOR_SWITCHPERSISTENCESTREAM_HXX
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */