2022-10-20 11:49:27 +00:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// Copyright (C) 2019 Alexey Edelev <semlanik@gmail.com>
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
|
|
|
|
|
|
|
|
|
#include <qtgrpcglobal_p.h>
|
|
|
|
|
|
2023-02-08 14:46:54 +00:00
|
|
|
#include <QtCore/qpointer.h>
|
|
|
|
|
#include <QtCore/private/qobject_p.h>
|
|
|
|
|
|
2022-12-16 08:55:22 +00:00
|
|
|
#include "qgrpcoperation.h"
|
2022-10-20 11:49:27 +00:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
|
|
/*!
|
2022-12-16 08:55:22 +00:00
|
|
|
\class QGrpcOperation
|
2023-03-10 09:49:15 +00:00
|
|
|
\inmodule QtGrpc
|
2022-12-16 08:55:22 +00:00
|
|
|
\brief The QGrpcOperation class implements common logic to
|
2022-10-20 11:49:27 +00:00
|
|
|
handle communication in Grpc channel.
|
2022-12-08 12:53:08 +00:00
|
|
|
*/
|
2022-10-20 11:49:27 +00:00
|
|
|
|
|
|
|
|
/*!
|
2022-12-09 12:03:04 +00:00
|
|
|
\fn template <typename T> T QGrpcOperation::read() const;
|
2022-10-20 11:49:27 +00:00
|
|
|
|
2022-12-08 12:53:08 +00:00
|
|
|
Reads message from raw byte array stored in QGrpcCallReply.
|
|
|
|
|
|
|
|
|
|
Returns a copy of the deserialized message or, on failure,
|
|
|
|
|
a default-constructed message.
|
|
|
|
|
*/
|
2022-10-20 11:49:27 +00:00
|
|
|
|
|
|
|
|
/*!
|
2023-01-27 19:49:36 +00:00
|
|
|
\fn void QGrpcOperation::finished()
|
2022-12-08 12:53:08 +00:00
|
|
|
|
|
|
|
|
This signal indicates the end of communication for this call.
|
|
|
|
|
|
|
|
|
|
If signal emitted by stream this means that stream is successfully
|
|
|
|
|
closed either by client or server.
|
|
|
|
|
*/
|
2022-10-20 11:49:27 +00:00
|
|
|
|
|
|
|
|
/*!
|
2023-01-27 19:49:36 +00:00
|
|
|
\fn void QGrpcOperation::errorOccurred(const QGrpcStatus &status)
|
2022-10-20 11:49:27 +00:00
|
|
|
|
2022-12-08 12:53:08 +00:00
|
|
|
This signal indicates the error occurred during serialization.
|
|
|
|
|
|
|
|
|
|
This signal is emitted when error with \a status occurs in channel
|
|
|
|
|
or during serialization.
|
|
|
|
|
*/
|
2022-10-20 11:49:27 +00:00
|
|
|
|
2023-02-08 14:46:54 +00:00
|
|
|
class QGrpcOperationPrivate : public QObjectPrivate
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_PUBLIC(QGrpcOperation)
|
|
|
|
|
public:
|
2023-04-21 10:01:26 +00:00
|
|
|
QGrpcOperationPrivate(std::shared_ptr<QAbstractProtobufSerializer> _serializer)
|
|
|
|
|
: serializer(std::move(_serializer))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 14:46:54 +00:00
|
|
|
QByteArray data;
|
2023-04-21 10:01:26 +00:00
|
|
|
std::shared_ptr<QAbstractProtobufSerializer> serializer;
|
2023-02-08 14:46:54 +00:00
|
|
|
};
|
|
|
|
|
|
2023-04-21 10:01:26 +00:00
|
|
|
QGrpcOperation::QGrpcOperation(std::shared_ptr<QAbstractProtobufSerializer> serializer)
|
|
|
|
|
: QObject(*new QGrpcOperationPrivate(std::move(serializer)))
|
2022-10-20 11:49:27 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-09 12:03:04 +00:00
|
|
|
QGrpcOperation::~QGrpcOperation() = default;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Interface for implementation of QAbstractGrpcChannel.
|
|
|
|
|
|
|
|
|
|
Should be used to write raw data from channel to reply \a data raw data
|
|
|
|
|
received from channel.
|
|
|
|
|
*/
|
|
|
|
|
void QGrpcOperation::setData(const QByteArray &data)
|
2022-10-20 11:49:27 +00:00
|
|
|
{
|
2023-02-08 14:46:54 +00:00
|
|
|
Q_D(QGrpcOperation);
|
|
|
|
|
d->data = data;
|
2022-10-20 11:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2022-12-08 12:53:08 +00:00
|
|
|
Interface for implementation of QAbstractGrpcChannel.
|
|
|
|
|
|
|
|
|
|
Should be used to write raw data from channel to reply \a data raw data
|
|
|
|
|
received from channel.
|
|
|
|
|
*/
|
2022-12-09 12:03:04 +00:00
|
|
|
void QGrpcOperation::setData(QByteArray &&data)
|
2022-10-20 11:49:27 +00:00
|
|
|
{
|
2023-02-08 14:46:54 +00:00
|
|
|
Q_D(QGrpcOperation);
|
|
|
|
|
d->data = std::move(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
Getter of the data received from the channel.
|
|
|
|
|
*/
|
|
|
|
|
QByteArray QGrpcOperation::data() const
|
|
|
|
|
{
|
|
|
|
|
return d_func()->data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
2023-04-21 10:01:26 +00:00
|
|
|
Getter of the serializer that QGrpcOperation was constructed with.
|
2023-02-08 14:46:54 +00:00
|
|
|
*/
|
2023-04-21 10:01:26 +00:00
|
|
|
std::shared_ptr<QAbstractProtobufSerializer> QGrpcOperation::serializer() const
|
2023-02-08 14:46:54 +00:00
|
|
|
{
|
2023-04-21 10:01:26 +00:00
|
|
|
return d_func()->serializer;
|
2022-10-20 11:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
2022-12-09 12:03:04 +00:00
|
|
|
|
|
|
|
|
#include "moc_qgrpcoperation.cpp"
|