template <typename FidlProtocol>
class WireSyncClient
Defined at line 129 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
|fdf::WireSyncClient| owns a client endpoint and exposes synchronous FIDL
calls. Prefer using this owning class over |fdf::WireCall| unless one has to
interface with very low-level functionality (such as making a call over a raw
zx_handle_t).
Generated FIDL APIs are accessed by 'dereferencing' the client value:
// Creates a sync client that speaks over |client_end|.
fdf::WireSyncClient client(std::move(client_end));
// Call the |Foo| method synchronously, obtaining the results from the
// return value.
fdf::Arena arena('EXAM');
fidl::WireResult result = client.buffer(arena)->Foo(args);
|fdf::WireSyncClient| is suitable for code without access to an fdf
dispatcher.
## Thread safety
|WireSyncClient| is generally thread-safe with a few caveats:
- Client objects can be safely sent between threads.
- One may invoke many FIDL methods in parallel on the same client. However,
FIDL method calls must be synchronized with operations that consume or
mutate the client object itself:
- Calling `Bind` or `TakeClientEnd`.
- Assigning a new value to the |WireSyncClient| variable.
- Moving the |WireSyncClient| to a different location.
- Destroying the |WireSyncClient|.
Public Methods
void WireSyncClient<FidlProtocol> ()
Creates an uninitialized client that is not bound to a client endpoint.
Prefer using the constructor overload that initializes the client
atomically during construction. Use this default constructor only when the
client must be constructed first before an endpoint could be obtained (for
example, if the client is an instance variable).
The client may be initialized later via |Bind|.
Defined at line 139 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
void WireSyncClient<FidlProtocol> (fdf::ClientEnd<FidlProtocol> client_end)
Creates an initialized client. FIDL calls will be made on |client_end|.
Similar to |fdf::WireClient|, the client endpoint must be valid.
To just make a FIDL call uniformly on a client endpoint that may or may not
be valid, use the |fdf::WireCall(client_end)| helper. We may extend
|fdf::WireSyncClient
<P
>| with richer features hinging on having a valid
endpoint in the future.
Defined at line 149 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
void ~WireSyncClient<FidlProtocol> ()
Defined at line 154 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
void WireSyncClient<FidlProtocol> (WireSyncClient<FidlProtocol> && )
Defined at line 155 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
WireSyncClient<FidlProtocol> & operator= (WireSyncClient<FidlProtocol> && )
Defined at line 156 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
bool is_valid ()
Whether the client is initialized.
Defined at line 159 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
bool operator bool ()
Defined at line 160 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
const fdf::ClientEnd<FidlProtocol> & client_end ()
Borrows the underlying client endpoint. The client must have been
initialized.
Defined at line 164 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
void Bind (fdf::ClientEnd<FidlProtocol> client_end)
Initializes the client with a |client_end|. FIDL calls will be made on this
endpoint.
It is not allowed to call |Bind| on an initialized client. To rebind a
|WireSyncClient| to a different endpoint, simply replace the
|WireSyncClient| variable with a new instance.
Defined at line 175 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h
fdf::ClientEnd<FidlProtocol> TakeClientEnd ()
Extracts the underlying endpoint from the client. After this operation, the
client goes back to an uninitialized state.
It is not safe to invoke this method while there are ongoing FIDL calls.
Defined at line 185 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.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.
Defined at line 194 of file ../../sdk/lib/fidl_driver/include/lib/fidl_driver/cpp/sync_call.h