summaryrefslogtreecommitdiffstats
path: root/src/grpc/qgrpcstream.cpp
blob: 5a93428d0ceec47e89ab273fdd8a02b7bbb91c03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// 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 <QtGrpc/qgrpcoperationcontext.h>
#include <QtGrpc/qgrpcstream.h>

QT_BEGIN_NAMESPACE

/*!
    \class QGrpcServerStream
    \inmodule QtGrpc
    \since 6.7
    \brief The QGrpcServerStream class provides access in handling server-streaming RPCs.

    The QGrpcServerStream class provides the interface for handling
    server-streaming remote procedure calls (RPCs), which is one of the four
    \gRPC \l{Service Methods}{service methods}.

    For a high-level overview, refer to the \l {Server Streaming} {Qt GRPC
    Client Guide}.

    \include qtgrpc-shared.qdocinc rpc-lifetime-note
*/

/*!
    \fn void QGrpcServerStream::messageReceived()

//! [message-received-desc]
    This signal is emitted when the streaming RPC has received a new message
    from the server. The read() methods can then be used to deserialize the
    received message.
//! [message-received-desc]
*/

/*!
    \internal

    Constructs a new QGrpcServerStream from QGrpcClientBase.

    This is indirectly called by the generated client interface.

    \sa QGrpcClientBase::serverStream QAbstractGrpcChannel::serverStream
*/
QGrpcServerStream::QGrpcServerStream(const QLatin1StringView service,
                                     const QLatin1StringView method,
                                     const QGrpcCallOptions &options,
                                     const std::weak_ptr<QAbstractGrpcChannel> &channel,
                                     PrivateConstructor /* unused */)
    : QGrpcOperation({ service, method, QtGrpc::RpcType::ServerStreaming }, options, channel)
{
    QObject::connect(&QGrpcOperation::context(), &QGrpcOperationContext::messageReceived, this,
                     &QGrpcServerStream::messageReceived);
}

/*!
    Destroys the QGrpcServerStream.
*/
QGrpcServerStream::~QGrpcServerStream() = default;

bool QGrpcServerStream::event(QEvent *event)
{
    return QGrpcOperation::event(event);
}

/*!
    \class QGrpcClientStream
    \inmodule QtGrpc
    \since 6.7
    \brief The QGrpcClientStream class provides access in handling client-streaming RPCs.

    The QGrpcClientStream class provides the interface for handling
    client-streaming remote procedure calls (RPCs), which is one of the four
    \gRPC \l{Service Methods}{service methods}.

    For a high-level overview, refer to the \l {Client Streaming} {Qt GRPC
    Client Guide}.

    \include qtgrpc-shared.qdocinc rpc-lifetime-note
*/

/*!
    \internal

    Constructs a new QGrpcClientStream from QGrpcClientBase.

    This is indirectly called by the generated client interface.

    \sa QGrpcClientBase::clientStream QAbstractGrpcChannel::clientStream
*/
QGrpcClientStream::QGrpcClientStream(const QLatin1StringView service,
                                     const QLatin1StringView method,
                                     const QGrpcCallOptions &options,
                                     const std::weak_ptr<QAbstractGrpcChannel> &channel,
                                     PrivateConstructor /* unused */)
    : QGrpcOperation({ service, method, QtGrpc::RpcType::ClientStreaming }, options, channel)
{
}

/*!
    Destroys the QGrpcClientStream.
*/
QGrpcClientStream::~QGrpcClientStream() = default;

/*!
//! [write-message-desc]
    Serializes \a message and sends it to the server.
//! [write-message-desc]
*/
void QGrpcClientStream::writeMessage(const QProtobufMessage &message)
{
    QGrpcOperation::writeMessage(message);
}

/*!
    \since 6.8
//! [writes-done-desc]
    Ends the stream from the client side (half-closing). The server is still allowed to send
    responses after this call.
//! [writes-done-desc]
*/
void QGrpcClientStream::writesDone()
{
    QGrpcOperation::writesDone();
}

bool QGrpcClientStream::event(QEvent *event)
{
    return QGrpcOperation::event(event);
}

/*!
    \class QGrpcBidiStream
    \inmodule QtGrpc
    \since 6.7
    \brief The QGrpcBidiStream class provides access in handling
    bidirectional-streaming RPCs.

    The QGrpcBidiStream class provides the interface for handling
    bidirectional-streaming remote procedure calls (RPCs), which is one of the
    four \gRPC \l{Service Methods}{service methods}.

    For a high-level overview, refer to the \l {Bidirectional Streaming} {Qt
    GRPC Client Guide}.

    \include qtgrpc-shared.qdocinc rpc-lifetime-note
*/

/*!
    \fn void QGrpcBidiStream::messageReceived()

    \include qgrpcstream.cpp message-received-desc
*/

/*!
    \internal

    Constructs a new QGrpcBidiStream from QGrpcClientBase.

    This is indirectly called by the generated client interface.

    \sa QGrpcClientBase::bidiStream QAbstractGrpcChannel::bidiStream
*/
QGrpcBidiStream::QGrpcBidiStream(const QLatin1StringView service, const QLatin1StringView method,
                                 const QGrpcCallOptions &options,
                                 const std::weak_ptr<QAbstractGrpcChannel> &channel,
                                 PrivateConstructor /* unused */)
    : QGrpcOperation({ service, method, QtGrpc::RpcType::BidiStreaming }, options, channel)
{
    QObject::connect(&QGrpcOperation::context(), &QGrpcOperationContext::messageReceived,
                     this, &QGrpcBidiStream::messageReceived);
}

/*!
    Destroys the QGrpcBidiStream.
*/
QGrpcBidiStream::~QGrpcBidiStream() = default;

/*!
    \include qgrpcstream.cpp write-message-desc
*/
void QGrpcBidiStream::writeMessage(const QProtobufMessage &message)
{
    QGrpcOperation::writeMessage(message);
}

/*!
    \since 6.8
    \include qgrpcstream.cpp writes-done-desc
*/
void QGrpcBidiStream::writesDone()
{
    QGrpcOperation::writesDone();
}

bool QGrpcBidiStream::event(QEvent *event)
{
    return QGrpcOperation::event(event);
}

QT_END_NAMESPACE

#include "moc_qgrpcstream.cpp"