class ServiceDirectory
Defined at line 25 of file ../../sdk/lib/sys/cpp/service_directory.h
A directory of services provided by another component.
These services are typically received by the component through its namespace,
specifically through the "/svc" entry.
Instances of this class are thread-safe.
Public Methods
void ServiceDirectory (zx::channel directory)
Create an directory of services backed by given |directory|.
Requests for services are routed to entries in this directory.
The directory is expected to implement the |fuchsia.io.Directory| protocol.
Defined at line 24 of file ../../sdk/lib/sys/cpp/service_directory.cc
void ServiceDirectory (fidl::InterfaceHandle<fuchsia::io::Directory> directory)
Defined at line 27 of file ../../sdk/lib/sys/cpp/service_directory.cc
void ~ServiceDirectory ()
Defined at line 30 of file ../../sdk/lib/sys/cpp/service_directory.cc
std::shared_ptr<ServiceDirectory> CreateFromNamespace ()
Create an directory of services from this component's namespace.
Uses the "/svc" entry in the namespace as the backing directory for the
returned directory of services.
Rather than creating a new |ServiceDirectory| consider passing |svc()| from
your |ComponentContext| around as that makes your code unit testable and
consumes one less kernel handle.
Defined at line 32 of file ../../sdk/lib/sys/cpp/service_directory.cc
std::shared_ptr<ServiceDirectory> CreateWithRequest (zx::channel * out_request)
Create a directory of services and return a request for an implementation
of the underlying directory in |out_request|.
Useful when creating components.
Defined at line 36 of file ../../sdk/lib/sys/cpp/service_directory.cc
void ServiceDirectory (const ServiceDirectory & )
ServiceDirectory objects cannot be copied.
Defined at line 38 of file ../../sdk/lib/sys/cpp/service_directory.h
ServiceDirectory & operator= (const ServiceDirectory & )
Defined at line 39 of file ../../sdk/lib/sys/cpp/service_directory.h
void ServiceDirectory (ServiceDirectory && other)
ServiceDirectory objects can be moved.
Defined at line 42 of file ../../sdk/lib/sys/cpp/service_directory.h
ServiceDirectory & operator= (ServiceDirectory && other)
Defined at line 43 of file ../../sdk/lib/sys/cpp/service_directory.h
std::shared_ptr<ServiceDirectory> CreateWithRequest (fidl::InterfaceRequest<fuchsia::io::Directory> * out_request)
Defined at line 45 of file ../../sdk/lib/sys/cpp/service_directory.cc
zx_status_t Connect (const std::string & interface_name, zx::channel request)
Connect to an interface in the directory.
The interface name and the channel must be supplied explicitly.
Returns whether the request was successfully sent to the remote directory
backing this service bundle.
# Errors
ZX_ERR_UNAVAILABLE: The directory backing this service bundle is invalid.
ZX_ERR_ACCESS_DENIED: This service bundle has insufficient rights to
connect to services.
# Example
```
zx::channel controller, request;
zx_status_t status = zx::channel::create(0,
&controller
,
&request
);
if (status != ZX_OK) {
[...]
}
directory.Connect("fuchsia.foo.Controller", std::move(request));
```
Defined at line 53 of file ../../sdk/lib/sys/cpp/service_directory.cc
fidl::InterfaceHandle<fuchsia::io::Directory> CloneChannel ()
Clone underlying directory channel.
This overload for |CloneHandle| discards the status of the underlying
operation. Callers that wish to receive that status should use
other overload that returns a |zx_status_t|.
Defined at line 64 of file ../../sdk/lib/sys/cpp/service_directory.cc
zx_status_t CloneChannel (fidl::InterfaceRequest<fuchsia::io::Directory> )
Clone underlying directory channel.
Returns whether the request was successfully sent to the remote directory
backing this service bundle.
# Errors
ZX_ERR_UNAVAILABLE: The directory backing this service bundle is invalid.
Other transport and application-level errors associated with
|fuchsia.io.Node/Clone|.
# Example
```
fuchsia::io::DirectoryPtr dir;
directory.CloneHandle(dir.NewRequest());
```
Defined at line 70 of file ../../sdk/lib/sys/cpp/service_directory.cc
template <typename Interface>
fidl::InterfacePtr<Interface> Connect (const std::string & interface_name)
Connect to an interface in the directory.
The discovery name of the interface is inferred from the C++ type of the
interface. Callers can supply an interface name explicitly to override
the default name.
This overload for |Connect| discards the status of the underlying
connection operation. Callers that wish to receive that status should use
one of the other overloads that returns a |zx_status_t|.
# Example
```
auto controller = directory.Connect
<fuchsia
::foo::Controller>();
```
Defined at line 82 of file ../../sdk/lib/sys/cpp/service_directory.h
template <typename Interface>
zx_status_t Connect (fidl::InterfaceRequest<Interface> request, const std::string & interface_name)
Connect to an interface in the directory.
The discovery name of the interface is inferred from the C++ type of the
interface request. Callers can supply an interface name explicitly to
override the default name.
Returns whether the request was successfully sent to the remote directory
backing this service bundle.
# Errors
ZX_ERR_UNAVAILABLE: The directory backing this service bundle is invalid.
ZX_ERR_ACCESS_DENIED: This service bundle has insufficient rights to
connect to services.
# Example
```
fuchsia::foo::ControllerPtr controller;
directory.Connect(controller.NewRequest());
```
Defined at line 112 of file ../../sdk/lib/sys/cpp/service_directory.h