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)
|
||||
{
|
||||
Q_D(QGrpcOperation);
|
||||
[[maybe_unused]] bool valid = QObject::connect(d->operationContext.get(),
|
||||
&QGrpcOperationContext::messageReceived, this,
|
||||
[this](const QByteArray &data) {
|
||||
Q_D(QGrpcOperation);
|
||||
d->data = data;
|
||||
});
|
||||
[[maybe_unused]] bool valid = false;
|
||||
valid = connect(d->operationContext.get(), &QGrpcOperationContext::messageReceived, this,
|
||||
&QGrpcOperation::onMessageReceived);
|
||||
Q_ASSERT_X(valid, "QGrpcOperation::QGrpcOperation",
|
||||
"Unable to make connection to the 'messageReceived' signal");
|
||||
|
||||
valid = QObject::connect(d->operationContext.get(), &QGrpcOperationContext::finished, this,
|
||||
[this](const QGrpcStatus &status) {
|
||||
if (!isFinished()) {
|
||||
Q_D(QGrpcOperation);
|
||||
d->isFinished.storeRelaxed(true);
|
||||
emit this->finished(status);
|
||||
}
|
||||
});
|
||||
valid = connect(d->operationContext.get(), &QGrpcOperationContext::finished, this,
|
||||
&QGrpcOperation::onFinished);
|
||||
Q_ASSERT_X(valid, "QGrpcOperation::QGrpcOperation",
|
||||
"Unable to make connection to the 'finished' signal");
|
||||
}
|
||||
|
|
@ -252,6 +243,21 @@ const QGrpcOperationContext &QGrpcOperation::context() const & noexcept
|
|||
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)
|
||||
{
|
||||
return QObject::event(event);
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ protected:
|
|||
}
|
||||
void context() const && = delete;
|
||||
|
||||
private:
|
||||
void onMessageReceived(const QByteArray &data);
|
||||
void onFinished(const QGrpcStatus &status);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY_MOVE(QGrpcOperation)
|
||||
Q_DECLARE_PRIVATE(QGrpcOperation)
|
||||
|
|
|
|||
Loading…
Reference in New Issue