Commit Graph

8 Commits

Author SHA1 Message Date
Dennis Oberst 19fca04537 Prefer the usage of SingleShotConnection
Currently we're doing something manually, which, since Qt6 is a
dedicated feature. Use that instead for less error-prone disconnections
for our single-shot signals.

Lets not re-invent the wheel for something that has been (potentially
faster rather then slower) invented for this exact usecase.

We will promote the usage of Qt::SingleShotConnection, so as good
teachers we should be using it as well.

Pick-to: 6.8
Change-Id: I3b2b9f176f06d91b4d0946a38c53a4c2614c8a01
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
2024-09-20 15:48:06 +02:00
Marc Mutz 99e8dcc33e Make makeServerStreamConnections() SCARY
Extract Method Private::makeServerStreamConnectionsImpl(),
encapsulating all the template-independent code, passing the
template-dependent code, which was already factored nicely into
QtGrpcQuickFunctional::handleReceivedMessage(), as a function pointer.

Not only does this speed up compilation, it also reduces executable
code duplication, resulting in smaller binaries.

Change-Id: I2208622fd31951afa14faca57c722d84fd93cd5d
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
2024-09-13 08:21:20 +02:00
Marc Mutz b56b4c9fe1 Make connectSingleReceiveOperationFinished() SCARY
Extract Method Private::connectSingleReceiveOperationFinishedImpl(),
encapsulating all the template-independent code, passing the
template-dependent code, which was already factored nicely into
QtGrpcQuickFunctional::handleReceivedMessage(), as a function pointer.

Not only does this speed up compilation, it also reduces executable
code duplication, resulting in smaller binaries.

Change-Id: I376d17d3cf525d907d1b837a4342a085851b8899
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
2024-09-13 08:21:13 +02:00
Alexey Edelev a1b5a6dd8f Migrate to std::unique_ptr return value for all RPCs
The use of shared pointers has potential risk of storing the
QGrpcOperation children forever and leaking in user code. The problem
is clearly in the lambda connections that we encourage to use in the
docs and examples:

  auto stream = testStream(...);
  QObject::connect(stream.get(), &QGrpcOperation::finished,
                   ctx, [ctx, stream]{...});

The above code will hold the 'stream' forever, unless user will make
the explicit disconnect in the lambda.

By using std::unique_ptr we partially solve this, or at least convince
user to solve this. When user creates lambda he knows the 'stream'
lifetime and most probably should consider that after the move, lambda
is owning the QGrpcOperation, so the need of disconnect is more clear
in this case:

  auto stream = testStream(...);
  auto *streamPtr = stream.get();
  QObject::connect(streamPtr, &QGrpcOperation::finished,
                   ctx, [ctx, stream = std::move(stream)]{...});

The code becomes a bit more complicated, but it points explicitly to
the potential risk. Also it disallows to make this trick to multiple
lambdas at the same time.

Of course using the lambda context to control the QGrpcOperation
lifetime in this case is not necessary. But even if users will decide
to manage the QGrpcOperation lifetime differently, the use of
std::unique_ptr will clearly point to the ownership.

[ChangeLog][Grpc] All generated RPC methods now return std::unique_ptr
instead of std::shared_ptr. This change explicitly defines that caller
takes the ownership of the returned pointers.

Pick-to: 6.8
Change-Id: I271b91454f0c1b12b77127a7e025fa493367e279
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
2024-08-30 12:08:46 +02:00
Alexey Edelev e7ef620d7f Remove QGrpcOperation::deserializationError(String) methods
API looks wrong, we expose the QGrpcOperation internals which doesn't
looks right.

[ChangeLog][Grpc] QGrpcOperation::deserializationError and
QGrpcOperation::deserializationErrorString methods are removed.

Pick-to: 6.8
Task-number: QTBUG-123625
Change-Id: I681bc5941238e30d8636b16fa28045da17c9f51c
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
2024-08-28 14:47:48 +02:00
Alexey Edelev 2d88bfdf3b Improve QML gRPC functional handlers
Move the common parts of 'make' functions to a separate functions(DRY).
Move functionality that doesn't depend on the template arguments to
out-of-line functions(SCARY).

Pick-to: 6.8
Task-number: QTBUG-125859
Change-Id: Ibb519463de81f3909732638428eb18c55fe9ae63
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-08-19 13:15:35 +02:00
Alexey Edelev 8e1988169b Add the null checks to QtGrpcQuickFunctional handlers
Assert if any of raw pointers are null.

Pick-to: 6.8
Change-Id: Ie4d7315770de932c19264abe947f3285be3fe4ba
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
2024-08-19 13:15:28 +02:00
Alexey Edelev f0d9c251e5 Move the QGrpcOperation::finished signal connection to the non-inline function
The functionality doesn't depend on the template arguments so we may
move it out of template function body.

Pick-to: 6.8
Task-number: QTBUG-120943
Change-Id: I80f402d43bfc88d109d3c9170ed01eebb4e207d8
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
2024-08-19 13:14:49 +02:00