template <typename ServiceMember>

class ServiceMemberWatcher

Defined at line 55 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h

Watch for service instances and connect to a member protocol of each instance.

ServiceMemberWatcher and SyncServiceMemberWatcher are templated on a ServiceMember, which

specifies both the service that it is a part of, and a member protocol of that service.

For a fidl protocol and service defined as:

library fidl.examples.echo;

protocol DriverEcho {...}

service DriverEchoService {

echo_device client_end:DriverEcho;

};

The ServiceMember would be: fidl_examples_echo::Service::EchoDevice

Note that the last part of the ServiceMember corresponds to the name of the

client_end in the service, not the protocol type.

Services can be waited on asynchronously with ServiceMemberWatcher and synchronously with

SyncServiceMemberWatcher. If you have a service with multiple protocols, and need to access

more than one protocol of a service for each instance, you can use component::ServiceWatcher

Define a callback function:

void OnInstanceFound(ClientEnd

<fidl

_examples_echo::DriverEcho> client_end) {...}

Optionally define an idle function, which will be called when all existing instances have been

enumerated:

void AllExistingEnumerated() {...}

Create the ServiceMemberWatcher:

ServiceMemberWatcher

<fidl

_examples_echo::Service::EchoDevice> watcher;

watcher->Begin(get_default_dispatcher(),

&OnInstanceFound

,

&AllExistingEnumerated

);

The ServiceMemberWatcher will stop upon destruction, or when |Cancel| is called.

Public Methods

zx::result<> Cancel ()

Cancels watching for service instances.

Defined at line 67 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h

void ServiceMemberWatcher<ServiceMember> (fidl::UnownedClientEnd<fuchsia_io::Directory> svc_root)

For tests, the service root can be set manually

Defined at line 73 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h

void ServiceMemberWatcher<ServiceMember> ()

Defined at line 75 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h

zx::result<> Begin (async_dispatcher_t * dispatcher, ClientCallback callback, IdleCallback idle_callback)

Begins asynchronously waiting for service instances using the given dispatcher.

Waits for services in the incoming service directory: /svc/ServiceMember::ServiceName

Asynchronously invokes |client_callback| for all existing service instances

within the specified aggregate service type, as any subsequently added

devices until service member watcher is destroyed. Ignores any service

named ".".

The |idle_callback| is invoked once immediately after all pre-existing

service instances have been reported via |client_callback| shortly after creation.

After |idle_callback| returns, any newly-arriving devices are reported via

|client_callback|.

|idle_callback| will be deleted after it is called, so captured context

is guaranteed to not be retained.

Defined at line 92 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h