Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qiooperation.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qiooperation_p.h"
6
#
include
"qiooperation_p_p.h"
7
8
#
include
<
QtCore
/
private
/
qobject_p
.
h
>
9
#
include
<
QtCore
/
private
/
qrandomaccessasyncfile_p_p
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
QIOOperationPrivate
::
QIOOperationPrivate
(
QtPrivate
::QIOOperationDataStorage *storage)
14
: dataStorage(storage)
15
{
16
Q_ASSERT(storage);
17
}
18
19
QIOOperationPrivate::~QIOOperationPrivate()
20
{
21
}
22
23
void
QIOOperationPrivate
::
appendBytesProcessed
(qint64 num)
24
{
25
processed += num;
26
}
27
28
void
QIOOperationPrivate
::
operationComplete
(QIOOperation::Error err)
29
{
30
Q_Q(QIOOperation);
31
32
error = err;
33
state
=
State
::
Finished
;
34
if
(err != QIOOperation::Error::None)
35
Q_EMIT q->errorOccurred(err);
36
Q_EMIT q->finished();
37
}
38
39
void
QIOOperationPrivate
::
setError
(QIOOperation::Error err)
40
{
41
Q_Q(QIOOperation);
42
error = err;
43
if
(err != QIOOperation::Error::None) {
44
state
=
State
::
Finished
;
45
Q_EMIT q->errorOccurred(err);
46
Q_EMIT q->finished();
47
}
48
}
49
50
QIOOperation::~QIOOperation()
51
{
52
ensureCompleteOrCanceled();
53
}
54
55
QIOOperation::Type QIOOperation::type()
const
56
{
57
Q_D(
const
QIOOperation);
58
return
d->type;
59
}
60
61
QIOOperation::Error QIOOperation::error()
const
62
{
63
Q_D(
const
QIOOperation);
64
return
d->error;
65
}
66
67
bool
QIOOperation::isFinished()
const
68
{
69
Q_D(
const
QIOOperation);
70
return
d->state == QIOOperationPrivate::State::Finished;
71
}
72
73
QIOOperation::QIOOperation(QIOOperationPrivate &dd, QObject *parent)
74
: QObject(dd, parent)
75
{
76
if
(
auto
file = qobject_cast<QRandomAccessAsyncFile*>(parent))
77
d_func()->file = file;
78
}
79
80
void
QIOOperation::ensureCompleteOrCanceled()
81
{
82
// Block until the operation is either complete or canceled.
83
// Otherwise the write/read might use removed data
84
Q_D(QIOOperation);
85
if
(d->state != QIOOperationPrivate::State::Finished) {
86
if
(d->file) {
87
auto
*filePriv = QRandomAccessAsyncFilePrivate::get(d->file);
88
filePriv->cancelAndWait(
this
);
89
}
90
}
91
}
92
93
QIOReadWriteOperationBase::~QIOReadWriteOperationBase()
94
=
default
;
95
96
qint64 QIOReadWriteOperationBase::offset()
const
97
{
98
Q_D(
const
QIOOperation);
99
return
d->offset;
100
}
101
102
qint64 QIOReadWriteOperationBase::numBytesProcessed()
const
103
{
104
if
(!isFinished())
105
return
-1;
106
Q_D(
const
QIOOperation);
107
return
d->processed;
108
}
109
110
QIOReadWriteOperationBase::QIOReadWriteOperationBase(QIOOperationPrivate &dd, QObject *parent)
111
: QIOOperation(dd, parent)
112
{
113
}
114
115
QIOReadOperation::~QIOReadOperation() =
default
;
116
117
QByteArray QIOReadOperation::data()
const
118
{
119
if
(!isFinished())
120
return
{};
121
Q_D(
const
QIOOperation);
122
return
d->dataStorage->getValue<QByteArray>();
123
}
124
125
QIOReadOperation::QIOReadOperation(QIOOperationPrivate &dd, QObject *parent)
126
: QIOReadWriteOperationBase(dd, parent)
127
{
128
Q_ASSERT(dd.type == QIOOperation::Type::Read);
129
Q_ASSERT(dd.dataStorage->containsByteArray());
130
}
131
132
QIOWriteOperation::~QIOWriteOperation() =
default
;
133
134
QByteArray QIOWriteOperation::data()
const
135
{
136
if
(!isFinished())
137
return
{};
138
Q_D(
const
QIOOperation);
139
return
d->dataStorage->getValue<QByteArray>();
140
}
141
142
QIOWriteOperation::QIOWriteOperation(QIOOperationPrivate &dd, QObject *parent)
143
: QIOReadWriteOperationBase(dd, parent)
144
{
145
Q_ASSERT(dd.type == QIOOperation::Type::Write);
146
Q_ASSERT(dd.dataStorage->containsByteArray());
147
}
148
149
QIOVectoredReadOperation::~QIOVectoredReadOperation() =
default
;
150
151
QSpan<
const
QSpan<std::byte>> QIOVectoredReadOperation::data()
const
152
{
153
if
(!isFinished())
154
return
{};
155
Q_D(
const
QIOOperation);
156
return
d->dataStorage->getValue<QSpan<
const
QSpan<std::byte>>>();
157
}
158
159
QIOVectoredReadOperation::QIOVectoredReadOperation(QIOOperationPrivate &dd, QObject *parent)
160
: QIOReadWriteOperationBase(dd, parent)
161
{
162
Q_ASSERT(dd.type == QIOOperation::Type::Read);
163
Q_ASSERT(dd.dataStorage->containsReadSpans());
164
}
165
166
QIOVectoredWriteOperation::~QIOVectoredWriteOperation() =
default
;
167
168
QSpan<
const
QSpan<
const
std::byte>> QIOVectoredWriteOperation::data()
const
169
{
170
if
(!isFinished())
171
return
{};
172
Q_D(
const
QIOOperation);
173
return
d->dataStorage->getValue<QSpan<
const
QSpan<
const
std::byte>>>();
174
}
175
176
QIOVectoredWriteOperation::QIOVectoredWriteOperation(QIOOperationPrivate &dd, QObject *parent)
177
: QIOReadWriteOperationBase(dd, parent)
178
{
179
Q_ASSERT(dd.type == QIOOperation::Type::Write);
180
Q_ASSERT(dd.dataStorage->containsWriteSpans());
181
}
182
183
QT_END_NAMESPACE
QIOOperationPrivate
Definition
qiooperation_p_p.h:151
QIOOperationPrivate::State
State
Definition
qiooperation_p_p.h:156
QIOOperationPrivate::State::Finished
@ Finished
Definition
qiooperation_p_p.h:158
QIOOperationPrivate::setError
void setError(QIOOperation::Error err)
Definition
qiooperation.cpp:39
QIOOperationPrivate::state
State state
Definition
qiooperation_p_p.h:179
QIOOperationPrivate::operationComplete
void operationComplete(QIOOperation::Error err)
Definition
qiooperation.cpp:28
QIOOperationPrivate::appendBytesProcessed
void appendBytesProcessed(qint64 num)
Definition
qiooperation.cpp:23
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtPrivate
Definition
qalloc.h:29
qtbase
src
corelib
io
qiooperation.cpp
Generated on
for Qt by
1.18.0