template <typename Protocol>
class WireSharedClient
Defined at line 249 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
|fdf::WireSharedClient| is a client for sending and receiving FIDL wire messages
over the driver transport. It exposes similar looking interfaces as
|fidl::WireSharedClient|, but has driver-specific concepts such as arenas and
driver dispatchers.
|WireSharedClient| is suitable for systems with less defined threading
guarantees, by providing the building blocks to implement a two-phase
asynchronous shutdown pattern.
In addition, |WireSharedClient| supports cloning multiple instances sharing
the same underlying endpoint.
## Thread safety
FIDL method calls on this class are thread-safe. |AsyncTeardown| and |Clone|
are also thread-safe, and may be invoked in parallel with FIDL method calls.
However, those operations must be synchronized with operations that consume
or mutate the |WireSharedClient| itself:
- Assigning a new value to the |WireSharedClient| variable.
- Moving the |WireSharedClient| to a different location.
- Destroying the |WireSharedClient| variable.
See
https://fuchsia.dev/fuchsia-src/development/languages/fidl/guides/llcpp-threading
for thread safety notes on |fidl::WireSharedClient|, which also largely apply
to |fdf::WireSharedClient|.
Public Methods
void WireSharedClient<Protocol> (fdf::ClientEnd<Protocol> client_end, fdf_dispatcher_t * dispatcher, std::unique_ptr<fdf::WireAsyncEventHandler<Protocol>> event_handler)
Creates an initialized |WireSharedClient| which manages the binding of the
client end of a channel to a dispatcher.
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.
|event_handler| will be destroyed when teardown completes.
Defined at line 262 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void WireSharedClient<Protocol> (fdf::ClientEnd<Protocol> client_end, fdf_dispatcher_t * dispatcher, fdf::WireAsyncEventHandler<Protocol> * event_handler, fidl::AnyTeardownObserver teardown_observer)
Creates a |WireSharedClient| that supports custom behavior on teardown
completion via |teardown_observer|. Through helpers that return an
|AnyTeardownObserver|, users may link the completion of teardown to the
invocation of a callback or the lifecycle of related business objects. See
for example |fidl::ObserveTeardown| and |fidl::ShareUntilTeardown|.
This overload does not demand taking ownership of |event_handler| by
|std::unique_ptr|, hence is suitable when the |event_handler| needs to be
managed independently of the client lifetime.
See |WireSharedClient| above for other behavior aspects of the constructor.
Defined at line 278 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void WireSharedClient<Protocol> (fdf::ClientEnd<Protocol> client_end, fdf_dispatcher_t * dispatcher, fidl::AnyTeardownObserver teardown_observer)
Overload of |WireSharedClient| that omits the |event_handler|, to
workaround C++ limitations on default arguments.
See |WireSharedClient| above for other behavior aspects of the constructor.
Defined at line 289 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void WireSharedClient<Protocol> ()
Creates an uninitialized |WireSharedClient|.
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 301 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
bool is_valid ()
Returns if the |WireSharedClient| is initialized.
Defined at line 304 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
bool operator bool ()
Defined at line 305 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void ~WireSharedClient<Protocol> ()
If the current |WireSharedClient| is the last instance controlling the
current connection, the destructor of this |WireSharedClient| will trigger
teardown.
When the last |WireSharedClient| destructs:
- The channel will be closed.
- Pointers obtained via |get| will be invalidated.
- Teardown will be initiated. See the **Lifecycle** section from the
class documentation of |fidl::WireClient|.
See also: |AsyncTeardown|.
Defined at line 318 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void WireSharedClient<Protocol> (WireSharedClient<Protocol> && other)
|fidl::WireSharedClient|s can be safely moved without affecting any in-progress
operations. 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 324 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
WireSharedClient<Protocol> & operator= (WireSharedClient<Protocol> && other)
Defined at line 325 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, std::unique_ptr<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.
It is not allowed to call |Bind| on an initialized client. To rebind a
|WireSharedClient| to a different endpoint, simply replace the
|WireSharedClient| variable with a new instance.
When other error occurs during binding, the |event_handler->on_fidl_error|
handler will be asynchronously invoked with the reason, if specified.
|event_handler| will be destroyed when teardown completes.
Defined at line 340 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, fidl::AnyTeardownObserver teardown_observer)
Overload of |Bind| that supports custom behavior on teardown completion via
|teardown_observer|. Through helpers that return an |AnyTeardownObserver|,
users may link the completion of teardown to the invocation of a callback
or the lifecycle of related business objects. See for example
|fidl::ObserveTeardown| and |fidl::ShareUntilTeardown|.
This overload does not demand taking ownership of |event_handler| by
|std::unique_ptr|, hence is suitable when the |event_handler| needs to be
managed independently of the client lifetime.
See |Bind| above for other behavior aspects of the function.
Defined at line 358 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, fidl::AnyTeardownObserver teardown_observer)
Overload of |Bind| that omits the |event_handler|, to
workaround C++ limitations on default arguments.
See |Bind| above for other behavior aspects of the constructor.
Defined at line 372 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
void AsyncTeardown ()
Initiates asynchronous teardown of the bindings. See the **Lifecycle**
section from |fidl::WireSharedClient|.
|Bind| must have been called before this.
While it is safe to invoke |AsyncTeardown| from any thread, it is unsafe to
wait for teardown to complete from a dispatcher thread, as that will likely
deadlock.
Defined at line 385 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
WireSharedClient<Protocol> Clone ()
Returns another |WireSharedClient| instance sharing the same channel.
Prefer to |Clone| only when necessary e.g. extending the lifetime of a
|SharedClient| to a different scope. Any clone will prevent the cleanup
of the channel while the binding is alive.
Defined at line 392 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
auto buffer (const fdf::Arena & arena)
Returns a veneer object which exposes the caller-allocating API, using
the provided |resource| to allocate buffers necessary for each call.
See documentation on |WireClient::buffer| for detailed behavior.
TODO(https://fxbug.dev/42172634): Consider taking |const fdf::Arena
&
| or similar.
Defined at line 399 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
auto sync ()
Returns a veneer object exposing synchronous calls. Example:
fidl::WireClient client(std::move(client_end), some_dispatcher);
fidl::WireResult result = client.sync().buffer(...)->FooMethod(args);
Defined at line 410 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/wire_client.h
Friends
template <typename Protocol>
class ClientChecker