mirror of https://github.com/qt/qtgrpc.git
QGrpcOperation: add private slots for handling context signals
More structured way of handling the code that complements the interceptors patch. Pick-to: 6.10 6.9 6.8 Change-Id: I6660e9a95ff8faef8e50966d912fdf9f1a7967c9 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
parent
94e8326137
commit
4f1b19c584
|
|
@ -67,23 +67,14 @@ QGrpcOperation::QGrpcOperation(std::shared_ptr<QGrpcOperationContext> operationC
|
||||||
: QObject(*new QGrpcOperationPrivate(std::move(operationContext)), parent)
|
: QObject(*new QGrpcOperationPrivate(std::move(operationContext)), parent)
|
||||||
{
|
{
|
||||||
Q_D(QGrpcOperation);
|
Q_D(QGrpcOperation);
|
||||||
[[maybe_unused]] bool valid = QObject::connect(d->operationContext.get(),
|
[[maybe_unused]] bool valid = false;
|
||||||
&QGrpcOperationContext::messageReceived, this,
|
valid = connect(d->operationContext.get(), &QGrpcOperationContext::messageReceived, this,
|
||||||
[this](const QByteArray &data) {
|
&QGrpcOperation::onMessageReceived);
|
||||||
Q_D(QGrpcOperation);
|
|
||||||
d->data = data;
|
|
||||||
});
|
|
||||||
Q_ASSERT_X(valid, "QGrpcOperation::QGrpcOperation",
|
Q_ASSERT_X(valid, "QGrpcOperation::QGrpcOperation",
|
||||||
"Unable to make connection to the 'messageReceived' signal");
|
"Unable to make connection to the 'messageReceived' signal");
|
||||||
|
|
||||||
valid = QObject::connect(d->operationContext.get(), &QGrpcOperationContext::finished, this,
|
valid = connect(d->operationContext.get(), &QGrpcOperationContext::finished, this,
|
||||||
[this](const QGrpcStatus &status) {
|
&QGrpcOperation::onFinished);
|
||||||
if (!isFinished()) {
|
|
||||||
Q_D(QGrpcOperation);
|
|
||||||
d->isFinished.storeRelaxed(true);
|
|
||||||
emit this->finished(status);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Q_ASSERT_X(valid, "QGrpcOperation::QGrpcOperation",
|
Q_ASSERT_X(valid, "QGrpcOperation::QGrpcOperation",
|
||||||
"Unable to make connection to the 'finished' signal");
|
"Unable to make connection to the 'finished' signal");
|
||||||
}
|
}
|
||||||
|
|
@ -252,6 +243,21 @@ const QGrpcOperationContext &QGrpcOperation::context() const & noexcept
|
||||||
return *d->operationContext;
|
return *d->operationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QGrpcOperation::onMessageReceived(const QByteArray &data)
|
||||||
|
{
|
||||||
|
Q_D(QGrpcOperation);
|
||||||
|
d->data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QGrpcOperation::onFinished(const QGrpcStatus &status)
|
||||||
|
{
|
||||||
|
Q_D(QGrpcOperation);
|
||||||
|
if (isFinished())
|
||||||
|
return;
|
||||||
|
d->isFinished.storeRelaxed(true);
|
||||||
|
emit finished(status);
|
||||||
|
}
|
||||||
|
|
||||||
bool QGrpcOperation::event(QEvent *event)
|
bool QGrpcOperation::event(QEvent *event)
|
||||||
{
|
{
|
||||||
return QObject::event(event);
|
return QObject::event(event);
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,10 @@ protected:
|
||||||
}
|
}
|
||||||
void context() const && = delete;
|
void context() const && = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onMessageReceived(const QByteArray &data);
|
||||||
|
void onFinished(const QGrpcStatus &status);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY_MOVE(QGrpcOperation)
|
Q_DISABLE_COPY_MOVE(QGrpcOperation)
|
||||||
Q_DECLARE_PRIVATE(QGrpcOperation)
|
Q_DECLARE_PRIVATE(QGrpcOperation)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue