/src/libreoffice/unotools/source/ucbhelper/ucblockbytes.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | #pragma once |
20 | | |
21 | | #include <com/sun/star/uno/Reference.hxx> |
22 | | |
23 | | #include <osl/conditn.hxx> |
24 | | #include <tools/stream.hxx> |
25 | | #include <comphelper/errcode.hxx> |
26 | | #include <mutex> |
27 | | |
28 | | namespace com |
29 | | { |
30 | | namespace sun |
31 | | { |
32 | | namespace star |
33 | | { |
34 | | namespace task |
35 | | { |
36 | | class XInteractionHandler; |
37 | | } |
38 | | namespace io |
39 | | { |
40 | | class XStream; |
41 | | class XInputStream; |
42 | | class XOutputStream; |
43 | | class XSeekable; |
44 | | } |
45 | | namespace ucb |
46 | | { |
47 | | class XContent; |
48 | | } |
49 | | namespace beans |
50 | | { |
51 | | struct PropertyValue; |
52 | | } |
53 | | } |
54 | | } |
55 | | } |
56 | | |
57 | | namespace utl |
58 | | { |
59 | | class UcbLockBytes; |
60 | | typedef tools::SvRef<UcbLockBytes> UcbLockBytesRef; |
61 | | |
62 | | class UcbLockBytes : public SvLockBytes |
63 | | { |
64 | | osl::Condition m_aInitialized; |
65 | | osl::Condition m_aTerminated; |
66 | | std::mutex m_aMutex; |
67 | | |
68 | | css::uno::Reference < css::io::XInputStream > m_xInputStream; |
69 | | css::uno::Reference < css::io::XOutputStream > m_xOutputStream; |
70 | | css::uno::Reference < css::io::XSeekable > m_xSeekable; |
71 | | |
72 | | ErrCode m_nError; |
73 | | |
74 | | bool m_bTerminated; |
75 | | bool m_bDontClose; |
76 | | bool m_bStreamValid; |
77 | | |
78 | | UcbLockBytes(); |
79 | | protected: |
80 | | virtual ~UcbLockBytes() override; |
81 | | |
82 | | public: |
83 | | // properties: Referer, PostMimeType |
84 | | static UcbLockBytesRef CreateLockBytes( const css::uno::Reference < css::ucb::XContent >& xContent, |
85 | | const css::uno::Sequence < css::beans::PropertyValue >& rProps, |
86 | | StreamMode eMode, |
87 | | const css::uno::Reference < css::task::XInteractionHandler >& xInter ); |
88 | | |
89 | | static UcbLockBytesRef CreateInputLockBytes( const css::uno::Reference < css::io::XInputStream >& xContent ); |
90 | | static UcbLockBytesRef CreateLockBytes( const css::uno::Reference < css::io::XStream >& xContent ); |
91 | | |
92 | | // SvLockBytes |
93 | | virtual ErrCode ReadAt(sal_uInt64 nPos, void *pBuffer, std::size_t nCount, std::size_t *pRead) const override; |
94 | | virtual ErrCode WriteAt(sal_uInt64, const void*, std::size_t, std::size_t *pWritten) override; |
95 | | virtual ErrCode Flush() const override; |
96 | | virtual ErrCode SetSize(sal_uInt64) override; |
97 | | virtual ErrCode Stat ( SvLockBytesStat *pStat ) const override; |
98 | | |
99 | | void SetError( ErrCode nError ) |
100 | 0 | { m_nError = nError; } |
101 | | |
102 | | ErrCode const & GetError() const |
103 | 581k | { return m_nError; } |
104 | | |
105 | | // calling this method delegates the responsibility to call closeinput to the caller! |
106 | | css::uno::Reference < css::io::XInputStream > getInputStream(); |
107 | | |
108 | | bool setInputStream( const css::uno::Reference < css::io::XInputStream > &rxInputStream ); |
109 | | void setStream( const css::uno::Reference < css::io::XStream > &rxStream ); |
110 | | void terminate(); |
111 | | |
112 | | css::uno::Reference < css::io::XInputStream > getInputStream() const |
113 | 46.1M | { |
114 | 46.1M | std::unique_lock aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); |
115 | 46.1M | return m_xInputStream; |
116 | 46.1M | } |
117 | | |
118 | | css::uno::Reference < css::io::XOutputStream > getOutputStream() const |
119 | 1.62M | { |
120 | 1.62M | std::unique_lock aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); |
121 | 1.62M | return m_xOutputStream; |
122 | 1.62M | } |
123 | | |
124 | | css::uno::Reference < css::io::XSeekable > getSeekable() const |
125 | 47.2M | { |
126 | 47.2M | std::unique_lock aGuard( const_cast< UcbLockBytes* >(this)->m_aMutex ); |
127 | 47.2M | return m_xSeekable; |
128 | 47.2M | } |
129 | | |
130 | | void setDontClose() |
131 | 380k | { m_bDontClose = true; } |
132 | | |
133 | | void SetStreamValid(); |
134 | | |
135 | | private: |
136 | | bool setInputStreamImpl( std::unique_lock<std::mutex>& rGuard, |
137 | | const css::uno::Reference < css::io::XInputStream > &rxInputStream, |
138 | | bool bSetXSeekable = true ); |
139 | | }; |
140 | | |
141 | | } |
142 | | |
143 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |