class Transaction

Defined at line 77 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/transaction.h

An abstract transaction, encapsulating the logic of sending reply messages.

The transaction type is polymorphic, to cater to a variety of transports and usage patterns.

Concrete implementations of this class are provided, so most clients do not have to worry about

implementing |fidl::Transaction|, and higher-level APIs such as |fidl::BindServer| cover most use

cases.

Should greater flexibility over managing in-flight transactions and server lifecycle be desired,

clients usually manually dispatch the FIDL messages. This is accomplished in the C bindings by

creating a transaction type that is memory layout-compatible with |fidl_txn_t|, and passing that

when calling the |foo_bar_try_dispatch| functions generated by the C bindings. Similarly here,

clients can manually invoke the [Try]Dispatch functions generated by the C++ bindings, passing in

their own transaction type by inheriting from this class and implementing the pure virtual

interfaces, e.g.

// Imaginary use-case: suppose drivers send messages in their own ways

class DriverRpcTransaction : public Transaction {

public:

// Implementation left-out

DriverRpcTransaction(/* ...some args... */);

~DriverRpcTransaction();

DriverRpcTransaction(DriverRpcTransaction

&

&

other) noexcept

: Transaction(std::move(other));

DriverRpcTransaction

&

operator=(DriverRpcTransaction

&

&

other) noexcept;

protected:

zx_status_t Reply(fidl::internal::Message* message) final {

/* Send to another driver etc. */

}

void Close(zx_status_t epitaph) final { /* Send epitaph and close down transport. */ }

std::unique_ptr

<Transaction

> TakeOwnership() final {

return std::make_unique

<DriverRpcTransaction

>(std::move(*this));

}

private:

// Driver-specific state...

};

and then dispatch to the server e.g.

fidl::WireServer

<fuchsia

::device::driver>* server_impl = /* construct/obtain server */;

fidl_incoming_msg_t msg = /* read FIDL message */;

DriverRpcTransaction txn(/* ...some args... */);

fuchsia::device::driver::Dispatch(server_impl,

&msg

,

&txn

);

/* Inspect |txn| */

The LLCPP runtime provides strong invariants around each method in the interface. It is possible

to implement a variety of dispatching behaviors by relying on them.

Public Methods

std::unique_ptr<Transaction> TakeOwnership ()

Move the contents of this transaction to heap, for an asynchronous reply.

Called exactly once when a sync completer is converted to an async completer.

Implementation may pause message dispatching here, in which case there will be

at most one in-flight transaction.

|Reply| and |Close| are never called on a transaction that has been moved from.

zx_status_t Reply (fidl::OutgoingMessage * message, fidl::WriteOptions write_options)

Called at most once for a two-way FIDL method, to reply to a two-way call.

Never called in case of a one-way call.

Implementation must fill in the correct transaction ID.

|Reply| usually consumes the handles (in which case |ReleaseHandles()| has been called).

If not, the destructor of |FidlMessage| will close them.

void Close (zx_status_t epitaph)

Should send an epitaph and then close the underlying transport e.g. channel.

void Transaction ()

Defined at line 79 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/transaction.h

void InternalError (UnbindInfo error, ErrorOrigin origin)

Implementations which support a user-specified unbound hook should propagate `error` to that

hook. Otherwise, by default, InternalError() just closes the connection to the client.

Defined at line 101 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/transaction.h

void EnableNextDispatch ()

Resumes the asynchronous wait on the underlying channel. This allows at least one more

dispatcher thread to enter the message handler for this binding in parallel.

Defined at line 105 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/transaction.h

bool DidOrGoingToUnbind ()

Returns true if the transaction references some internal binding, and that

binding either no longer accessible, or scheduled to be destroyed at the

next iteration of the event loop. This is used to determine whether a reply

is still required. The default implementation returns false for bindings

which do not support user-initiated unbinding.

Defined at line 114 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/transaction.h

void ~Transaction ()

A transaction will only be destroyed after one of three actions happens to it:

the Completer containing it is destroyed, the transaction is closed, or ownership is taken from

the transaction.

An async transaction is destroyed immediately after the request has been closed or the

Completer containing it is destroyed.

A synchronous transaction lives on the stack, and may provide status/errors to the binding

dispatch loop.

If the implementation paused message dispatching above, it may resume dispatching here.

Defined at line 124 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/transaction.h