mirror of https://github.com/qt/qtgrpc.git
Remove the redundant template argument from QtGrpcQuickFunctional::readReturnValue
'operation' doesn't need to be template, we may use the pointer to the base QGrpcOperation class to access the template read<> method. Pick-to: 6.8 Task-number: QTBUG-120943 Change-Id: I4aca0a374a2ea0229b98fc9602daace76b0fa31a Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
2b35d269ba
commit
11a3efc16d
|
|
@ -16,12 +16,12 @@ QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
namespace QtGrpcQuickFunctional {
|
namespace QtGrpcQuickFunctional {
|
||||||
|
|
||||||
template <typename Ret, typename Operation>
|
template <typename Ret>
|
||||||
void readReturnValue(QJSEngine *jsEngine, Operation *operation, const QJSValue &successCallback,
|
void readReturnValue(QJSEngine *jsEngine, QGrpcOperation *operation,
|
||||||
const QJSValue &errorCallback)
|
const QJSValue &successCallback, const QJSValue &errorCallback)
|
||||||
{
|
{
|
||||||
if (successCallback.isCallable()) {
|
if (successCallback.isCallable()) {
|
||||||
std::optional<Ret> result = operation->template read<Ret>();
|
std::optional<Ret> result = operation->read<Ret>();
|
||||||
if (result) {
|
if (result) {
|
||||||
successCallback.call(QJSValueList{ jsEngine->toScriptValue(*result) });
|
successCallback.call(QJSValueList{ jsEngine->toScriptValue(*result) });
|
||||||
} else if (errorCallback.isCallable()) {
|
} else if (errorCallback.isCallable()) {
|
||||||
|
|
@ -49,9 +49,7 @@ void makeCallConnections(QJSEngine *jsEngine, const std::shared_ptr<QGrpcCallRep
|
||||||
// We take 'reply' by copy so that its lifetime
|
// We take 'reply' by copy so that its lifetime
|
||||||
// is extended until this lambda is destroyed.
|
// is extended until this lambda is destroyed.
|
||||||
if (status.code() == QtGrpc::StatusCode::Ok) {
|
if (status.code() == QtGrpc::StatusCode::Ok) {
|
||||||
readReturnValue<Ret,
|
readReturnValue<Ret>(jsEngine, reply.get(),
|
||||||
QGrpcCallReply>(jsEngine,
|
|
||||||
reply.get(),
|
|
||||||
finishCallback,
|
finishCallback,
|
||||||
errorCallback);
|
errorCallback);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -87,8 +85,7 @@ void makeServerStreamConnections(QJSEngine *jsEngine,
|
||||||
});
|
});
|
||||||
QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, jsEngine,
|
QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, jsEngine,
|
||||||
[streamPtr = stream.get(), messageCallback, jsEngine, errorCallback]() {
|
[streamPtr = stream.get(), messageCallback, jsEngine, errorCallback]() {
|
||||||
readReturnValue<Ret, QGrpcServerStream>(jsEngine, streamPtr,
|
readReturnValue<Ret>(jsEngine, streamPtr, messageCallback, errorCallback);
|
||||||
messageCallback, errorCallback);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,9 +103,7 @@ Sender *makeClientStreamConnections(QJSEngine *jsEngine,
|
||||||
// We take 'stream' by copy so that its lifetime
|
// We take 'stream' by copy so that its lifetime
|
||||||
// is extended until this lambda is destroyed.
|
// is extended until this lambda is destroyed.
|
||||||
if (status.code() == QtGrpc::StatusCode::Ok) {
|
if (status.code() == QtGrpc::StatusCode::Ok) {
|
||||||
readReturnValue<Ret,
|
readReturnValue<Ret>(jsEngine, stream.get(),
|
||||||
QGrpcClientStream>(jsEngine,
|
|
||||||
stream.get(),
|
|
||||||
finishCallback,
|
finishCallback,
|
||||||
errorCallback);
|
errorCallback);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -147,8 +142,7 @@ Sender *makeBidirStreamConnections(QJSEngine *jsEngine,
|
||||||
});
|
});
|
||||||
QObject::connect(stream.get(), &QGrpcBidirStream::messageReceived, jsEngine,
|
QObject::connect(stream.get(), &QGrpcBidirStream::messageReceived, jsEngine,
|
||||||
[streamPtr = stream.get(), messageCallback, jsEngine, errorCallback] {
|
[streamPtr = stream.get(), messageCallback, jsEngine, errorCallback] {
|
||||||
readReturnValue<Ret, QGrpcBidirStream>(jsEngine, streamPtr,
|
readReturnValue<Ret>(jsEngine, streamPtr, messageCallback, errorCallback);
|
||||||
messageCallback, errorCallback);
|
|
||||||
});
|
});
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue