template <typename FidlProtocol>

class SyncClient

Defined at line 69 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

|fidl::SyncClient| owns a client endpoint and exposes synchronous FIDL calls

taking both natural and wire types. Prefer using this owning class over

|fidl::Call| 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|.

fidl::SyncClient client(std::move(client_end));

// Call the |Foo| method synchronously, obtaining the results from the

// return value.

fidl::Result result = client->Foo(args);

|fidl::SyncClient| is suitable for code without access to an async

dispatcher.

|fidl::SyncClient| includes a superset of the functionality of

|fidl::WireSyncClient|, which only exposes synchronous FIDL calls with wire

types. Prefer |fidl::SyncClient| over |fidl::WireSyncClient| unless your

application needs to statically enforce that only the more performant wire

types are used.

## Thread safety

|SyncClient| 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 |SyncClient| variable.

- Moving the |SyncClient| to a different location.

- Destroying the |SyncClient|.

- There can be at most one `HandleOneEvent` call going on at the same time.

Public Methods

void SyncClient<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 82 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

void SyncClient<FidlProtocol> (::fidl::ClientEnd<FidlProtocol> client_end)

Creates an initialized client. FIDL calls will be made on |client_end|.

Similar to |fidl::Client|, 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 |fidl::Call(client_end)| helper. We may extend

|fidl::SyncClient

<P

>| with richer features hinging on having a valid

endpoint in the future.

Defined at line 92 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

void ~SyncClient<FidlProtocol> ()

Defined at line 94 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

void SyncClient<FidlProtocol> (SyncClient<FidlProtocol> && )

Defined at line 95 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

SyncClient<FidlProtocol> & operator= (SyncClient<FidlProtocol> && )

Defined at line 96 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

bool is_valid ()

Whether the client is initialized.

Defined at line 99 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

bool operator bool ()

Defined at line 100 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

const ::fidl::ClientEnd<FidlProtocol> & client_end ()

Borrows the underlying client endpoint. The client must have been

initialized.

Defined at line 104 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

void Bind (::fidl::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

|SyncClient| to a different endpoint, simply replace the

|SyncClient| variable with a new instance.

Defined at line 112 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

::fidl::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 118 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

internal::SyncEndpointManagedVeneer<internal::NaturalSyncClientImpl<FidlProtocol>> operator-> ()

Returns the interface for making FIDL calls with natural objects.

Defined at line 121 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

const Base & wire ()

Returns the interface for making outgoing FIDL calls using wire objects.

The client must be initialized first.

Defined at line 130 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h

::fidl::Status HandleOneEvent (fidl::SyncEventHandler<FidlProtocol> & event_handler)

Handle all possible events defined in this protocol.

Blocks to consume exactly one message from the channel, then call the corresponding virtual

method defined in |event_handler|. If the message was unknown or malformed, returns an

error without calling any virtual method.

Defined at line 137 of file ../../sdk/lib/fidl/cpp/include/lib/fidl/cpp/channel.h