template <typename ServiceMember>
class ServiceMemberWatcher
Defined at line 56 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 71 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 78 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h
void ServiceMemberWatcher<ServiceMember> ()
Defined at line 80 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h
zx::result<> Begin (async_dispatcher_t *dispatcher,ClientCallbackcallback,IdleCallbackidle_callback)
Begins asynchronously waiting for service instances using the given dispatcher.
Waits for services in the incoming service directory: /svc/ServiceMember::ServiceName
Asynchronously invokes the callback for all existing service instances
within the specified aggregate service type, as well as any subsequently added
instances 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 the callback shortly after creation.
After |idle_callback| returns, any newly-arriving instances are reported via
the callback.
|idle_callback| will be deleted after it is called, so captured context
is guaranteed to not be retained.
Defined at line 97 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h
zx::result<> Begin (async_dispatcher_t *dispatcher,ClientCallbackWithInstancecallback,IdleCallbackidle_callback)
Begins asynchronously waiting for service instances using the given dispatcher.
Similar to the other Begin overload, but the callback |callback| is invoked
with both the client end and the instance name.
Defined at line 111 of file ../../sdk/lib/component/incoming/cpp/service_member_watcher.h