Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / unotools / source / ucbhelper / ucblockbytes.hxx
blobdf1e237e94159c64dc006ffaa655214b46a2c2e6
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_UNOTOOLS_UCBLOCKBYTES_HXX
20 #define INCLUDED_UNOTOOLS_UCBLOCKBYTES_HXX
22 #include <com/sun/star/uno/Reference.hxx>
24 #include <osl/conditn.hxx>
25 #include <osl/mutex.hxx>
26 #include <tools/stream.hxx>
27 #include <vcl/errcode.hxx>
29 namespace com
31 namespace sun
33 namespace star
35 namespace task
37 class XInteractionHandler;
39 namespace io
41 class XStream;
42 class XInputStream;
43 class XOutputStream;
44 class XSeekable;
46 namespace ucb
48 class XContent;
50 namespace beans
52 struct PropertyValue;
58 namespace utl
60 class UcbLockBytes;
61 typedef tools::SvRef<UcbLockBytes> UcbLockBytesRef;
63 class UcbLockBytes : public virtual SvLockBytes
65 osl::Condition m_aInitialized;
66 osl::Condition m_aTerminated;
67 osl::Mutex m_aMutex;
69 css::uno::Reference < css::io::XInputStream > m_xInputStream;
70 css::uno::Reference < css::io::XOutputStream > m_xOutputStream;
71 css::uno::Reference < css::io::XSeekable > m_xSeekable;
73 ErrCode m_nError;
75 bool m_bTerminated;
76 bool m_bDontClose;
77 bool m_bStreamValid;
79 UcbLockBytes();
80 protected:
81 virtual ~UcbLockBytes() override;
83 public:
84 // properties: Referer, PostMimeType
85 static UcbLockBytesRef CreateLockBytes( const css::uno::Reference < css::ucb::XContent >& xContent,
86 const css::uno::Sequence < css::beans::PropertyValue >& rProps,
87 StreamMode eMode,
88 const css::uno::Reference < css::task::XInteractionHandler >& xInter );
90 static UcbLockBytesRef CreateInputLockBytes( const css::uno::Reference < css::io::XInputStream >& xContent );
91 static UcbLockBytesRef CreateLockBytes( const css::uno::Reference < css::io::XStream >& xContent );
93 // SvLockBytes
94 virtual ErrCode ReadAt(sal_uInt64 nPos, void *pBuffer, std::size_t nCount, std::size_t *pRead) const override;
95 virtual ErrCode WriteAt(sal_uInt64, const void*, std::size_t, std::size_t *pWritten) override;
96 virtual ErrCode Flush() const override;
97 virtual ErrCode SetSize(sal_uInt64) override;
98 virtual ErrCode Stat ( SvLockBytesStat *pStat ) const override;
100 void SetError( ErrCode nError )
101 { m_nError = nError; }
103 ErrCode const & GetError() const
104 { return m_nError; }
106 // calling this method delegates the responsibility to call closeinput to the caller!
107 css::uno::Reference < css::io::XInputStream > getInputStream();
109 bool setInputStream_Impl( const css::uno::Reference < css::io::XInputStream > &rxInputStream,
110 bool bSetXSeekable = true );
111 void setStream_Impl( const css::uno::Reference < css::io::XStream > &rxStream );
112 void terminate_Impl();
114 css::uno::Reference < css::io::XInputStream > getInputStream_Impl() const
116 osl::MutexGuard aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex );
117 return m_xInputStream;
120 css::uno::Reference < css::io::XOutputStream > getOutputStream_Impl() const
122 osl::MutexGuard aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex );
123 return m_xOutputStream;
126 css::uno::Reference < css::io::XSeekable > getSeekable_Impl() const
128 osl::MutexGuard aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex );
129 return m_xSeekable;
132 void setDontClose_Impl()
133 { m_bDontClose = true; }
135 void SetStreamValid_Impl();
140 #endif
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */