template <typename Interface, typename ImplPtr = Interface*>

class Binding

Defined at line 62 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

Binds the implementation of |Interface| to a channel.

The |Binding| listens for incoming messages on the channel, decodes them, and

calls the appropriate method on the bound implementation. If the message

expects a reply, the |Binding| creates callbacks that encode and send

reply messages when called.

When the |Binding| object is destroyed, the binding between the channel

and the interface is torn down and the channel is closed, leaving the

|Binding| in an unbound state.

The implementation pointer type of the binding is also parameterized,

allowing the use of smart pointer types such as |std::unique_ptr| to

reference the implementation.

Example:

#include "foo.fidl.h"

class FooImpl : public Foo {

public:

explicit FooImpl(InterfaceRequest

<Foo

> request)

: binding_(this, std::move(request)) {}

// Foo implementation here.

private:

Binding

<Foo

> binding_;

};

After the |Binding| has been bound to an implementation, the implementation

will receive methods calls from the remote endpoint of the channel on the

async_dispatcher_t to which the |InterfaceRequest| was bound. By default this

is the thread on which the binding occurred.

See also:

* |InterfacePtr|, which is the client analog of a |Binding|.

* |EventSender|, which can send messages from multiple threads safely.

Public Methods

void Binding<Interface, ImplPtr> (ImplPtr impl)

Constructs an incomplete binding that will use the implementation |impl|.

The binding may be completed with a subsequent call to the |Bind| method.

Does not take ownership of |impl|, which must outlive the binding.

Defined at line 85 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

void Binding<Interface, ImplPtr> (ImplPtr impl, zx::channel channel, async_dispatcher_t * dispatcher)

Constructs a completed binding of |channel| to implementation |impl|.

Does not take ownership of |impl|, which must outlive the binding.

If the |Binding| cannot be bound to the given |channel| (e.g., because

the |channel| lacks |ZX_RIGHT_WAIT|), the |Binding| will be constructed

in an unbound state.

Uses the given async_dispatcher_t (e.g., a message loop) in order to read

messages from the channel and to monitor the channel for

|ZX_CHANNEL_PEER_CLOSED|. If |dispatcher| is null, the current thread must

have a default async_dispatcher_t.

Defined at line 102 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

void Binding<Interface, ImplPtr> (ImplPtr impl, InterfaceRequest<Interface> request, async_dispatcher_t * dispatcher)

Constructs a completed binding of |impl| to the channel in |request|.

Does not take ownership of |impl|, which must outlive the binding.

If the |Binding| cannot be bound to the given |channel| (e.g., because

the |channel| lacks |ZX_RIGHT_WAIT|), the |Binding| will be constructed

in an unbound state.

Uses the given async_dispatcher_t (e.g., a message loop) in order to read

messages from the channel and to monitor the channel for

|ZX_CHANNEL_PEER_CLOSED|. If |dispatcher| is null, the current thread must

have a default async_dispatcher_t.

Defined at line 119 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

void Binding<Interface, ImplPtr> (const Binding<Interface, ImplPtr> & )

Defined at line 125 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

Binding<Interface, ImplPtr> & operator= (const Binding<Interface, ImplPtr> & )

Defined at line 126 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

void Binding<Interface, ImplPtr> (Binding<Interface, ImplPtr> && )

The implementation of this class provides external references to class members via pointers.

As a result, instances cannot be move-constructed or move-assigned.

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

Binding<Interface, ImplPtr> & operator= (Binding<Interface, ImplPtr> && )

Defined at line 131 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

InterfaceHandle<Interface> NewBinding (async_dispatcher_t * dispatcher)

Completes a binding by creating a new channel, binding one endpoint to

the previously specified implementation and returning the other endpoint.

If |NewBinding| fails to create the underlying channel, the returned

|InterfaceHandle| will return false from |is_valid()|.

Uses the given async_dispatcher_t (e.g., a message loop) in order to read

messages from the channel and to monitor the channel for

|ZX_CHANNEL_PEER_CLOSED|. If |dispatcher| is null, the current thread must

have a default async_dispatcher_t.

Defined at line 143 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

zx_status_t Bind (zx::channel channel, async_dispatcher_t * dispatcher)

Binds the previously specified implementation to the given |channel|.

If the |Binding| was previously bound to another channel, that channel is

closed.

Uses the given async_dispatcher_t (e.g., a message loop) in order to read

messages from the channel and to monitor the channel for

|ZX_CHANNEL_PEER_CLOSED|. If |dispatcher| is null, the current thread must

have a default async_dispatcher_t.

Returns an error if the binding was not able to be created (e.g., because

the |channel| lacks |ZX_RIGHT_WAIT|).

Defined at line 161 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

zx_status_t Bind (InterfaceRequest<Interface> request, async_dispatcher_t * dispatcher)

Binds the previously specified implementation to the given

|InterfaceRequest|.

If the |Binding| was previously bound to another channel, that channel is

closed.

Uses the given async_dispatcher_t (e.g., a message loop) in order to read

messages from the channel and to monitor the channel for

|ZX_CHANNEL_PEER_CLOSED|. If |dispatcher| is null, the current thread must

have a default async_dispatcher_t.

Returns an error if the binding was not able to be created (e.g., because

the |channel| lacks |ZX_RIGHT_WAIT|).

Defined at line 178 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

InterfaceRequest<Interface> Unbind ()

Unbinds the underlying channel from this binding and returns it so it can

be used in another context, such as on another thread or with a different

implementation.

After this function returns, the |Binding| is ready to be bound to another

channel.

Defined at line 188 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

zx_status_t Close (zx_status_t epitaph_value)

Sends an Epitaph over the bound channel corresponding to the error passed

as a parameter, closes the channel, and unbinds it. An Epitaph is the last

message sent over a channel before a close operation; for the purposes of

this function, it can be thought of as a return code. See the FIDL

language spec for more information about Epitaphs.

The return value can be any of the return values of zx_channel_write.

Defined at line 199 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

zx_status_t WaitForMessage ()

Blocks the calling thread until either a message arrives on the previously

bound channel or an error occurs.

Returns an error if waiting for the message, reading the message, or

processing the message fails. If the error results in the channel being

closed, the error handler will be called synchronously before this

method returns.

This method can be called only if this |Binding| is currently bound to a

channel.

Defined at line 211 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

bool has_error_handler ()

Whether an error handler has been set.

See |set_error_handler()|.

Defined at line 218 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

void set_error_handler (fit::function<void (zx_status_t)> error_handler)

Sets an error handler that will be called if an error causes the underlying

channel to be closed.

If the error is being reported because an error occurred on the local side

of the channel, the zx_status_t of that error will be passed as the

parameter to the handler.

For example, the error handler will be called if the remote side of the

channel sends an invalid message. When the error handler is called, the

|Binding| will no longer be bound to the channel.

Defined at line 230 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

const ImplPtr & impl ()

The implementation used by this |Binding| to process incoming messages.

Defined at line 235 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

typename Interface::EventSender_ & events ()

The interface for sending events back to the client.

Defined at line 238 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

bool is_bound ()

Whether this |Binding| is currently listening to a channel.

Defined at line 241 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

const zx::channel & channel ()

The underlying channel.

Defined at line 244 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

async_dispatcher_t * dispatcher ()

The |async_dispatcher_t| to which this binding is bound, if any.

Defined at line 247 of file ../../sdk/lib/fidl/hlcpp/include/lib/fidl/cpp/binding.h

Records