template <typename Protocol>
class WireClient
Defined at line 85 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
|fdf::WireClient| is a client for sending and receiving FIDL wire messages
over the driver transport. It exposes similar looking interfaces as
|fidl::WireClient|, but has driver-specific concepts such as arenas and
driver dispatchers.
See |fidl::WireClient| for lifecycle notes, which also apply to
|fdf::WireClient|.
## Thread safety
|WireClient| provides an easier to use API in exchange of a more restrictive
threading model:
- The provided |fdf_dispatcher_t| must be a [synchronized dispatcher][synchronized-dispatcher].
- The client must be bound on a task running on that dispatcher.
- The client must be destroyed on a task running on that dispatcher.
- FIDL method calls must be made from tasks running on that dispatcher.
- Responses are always delivered from dispatcher tasks, as are events.
The above rules are checked in debug builds at run-time. In short, the client
is local to its associated dispatcher.
Note that FIDL method calls must be synchronized with operations that consume
or mutate the |WireClient| itself:
- Assigning a new value to the |WireClient| variable.
- Moving the |WireClient| to a different location.
- Destroying the |WireClient|.
See
https://fuchsia.dev/fuchsia-src/development/languages/fidl/tutorials/cpp/topics/threading
for thread safety notes on |fidl::WireClient|, which also largely apply to
|fdf::WireClient|.
[synchronized-dispatcher]:
https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/thread-safe-async#synchronized-dispatcher
Public Methods
void WireClient<Protocol> (fdf::ClientEnd<Protocol> client_end, fdf_dispatcher_t * dispatcher, fdf::WireAsyncEventHandler<Protocol> * event_handler)
Create an initialized client which manages the binding of the client end of
a channel to a dispatcher, as if that client had been default-constructed
then later bound to that endpoint via |Bind|.
It is a logic error to use a dispatcher that is shutting down or already
shut down. Doing so will result in a panic.
If any other error occurs during initialization, the
|event_handler->on_fidl_error| handler will be invoked asynchronously with
the reason, if specified.
Defined at line 97 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void WireClient<Protocol> ()
Create an uninitialized client. The client may then be bound to an endpoint
later via |Bind|.
Prefer using the constructor overload that binds the client to a channel
atomically during construction. Use this default constructor only when the
client must be constructed first before a channel could be obtained (for
example, if the client is an instance variable).
Defined at line 109 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
bool is_valid ()
Returns if the |WireClient| is initialized.
Defined at line 112 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
bool operator bool ()
Defined at line 113 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void ~WireClient<Protocol> ()
The destructor of |WireClient| will initiate binding teardown.
When the client destructs:
- The channel will be closed.
- Pointers obtained via |get| will be invalidated.
- Binding teardown will happen, implying:
* In-progress calls will be forgotten. Async callbacks will be dropped.
Defined at line 122 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void WireClient<Protocol> (WireClient<Protocol> && other)
|WireClient|s can be safely moved without affecting any in-flight FIDL
method calls. Note that calling methods on a client should be serialized
with respect to operations that consume the client, such as moving it or
destroying it.
Defined at line 128 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
WireClient<Protocol> & operator= (WireClient<Protocol> && other)
Defined at line 129 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void Bind (fdf::ClientEnd<Protocol> client_end, fdf_dispatcher_t * dispatcher, fdf::WireAsyncEventHandler<Protocol> * event_handler)
Initializes the client by binding the |client_end| endpoint to the
dispatcher.
It is a logic error to invoke |Bind| on a dispatcher that is shutting down
or already shut down. Doing so will result in a panic.
When other errors occur during binding, the |event_handler->on_fidl_error|
handler will be asynchronously invoked with the reason, if specified.
It is not allowed to call |Bind| on an initialized client. To rebind a
|WireClient| to a different endpoint, simply replace the |WireClient|
variable with a new instance.
Defined at line 143 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
auto buffer (const fdf::Arena & arena)
Returns an interface for making FIDL calls, using the provided |arena| to
allocate buffers necessary for each call. Requests will live on the arena.
Responses on the other hand live on the arena passed along with the
response, which may or may not be the same arena as the request.
## Lifecycle
The returned object borrows from this object, hence must not outlive
the client object. The return object borrows the arena, hence must not
outlive the arena.
The returned object may be briefly persisted for use over multiple calls:
fdf::Arena my_arena = /* create the arena */;
fdf::WireClient client(std::move(client_end), some_dispatcher);
auto buffered = client.buffer(my_arena);
buffered->FooMethod(args).ThenExactlyOnce(foo_response_context);
buffered->BarMethod(args).ThenExactlyOnce(bar_response_context);
...
In this situation, those calls will all use the initially provided arena
to allocate their message buffers.
Defined at line 174 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
auto sync ()
Returns a veneer object exposing synchronous calls. Example:
fdf::WireClient client(std::move(client_end), some_dispatcher);
fdf::WireResult result = client.sync().buffer(...)->FooMethod(args);
Defined at line 185 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
fit::result<fidl::Error, fdf::ClientEnd<Protocol>> UnbindMaybeGetEndpoint ()
Attempts to disassociate the client object from its endpoint and stop
monitoring it for messages. After this call, subsequent operations will
fail with an unbound error.
If there are pending two-way async calls, the endpoint is closed and this
method will fail with |fidl::Reason::kPendingTwoWayCallPreventsUnbind|. The
caller needs to arrange things such that unbinding happens after any
replies to two-way calls.
If the endpoint was already closed due to an earlier error, that error will
be returned here.
Otherwise, returns the client endpoint.
Defined at line 203 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h