Services

A service provides a set of FIDL protocols over a channel. Logically-related protocols can be aggregated into a service and routed as a single unit.

library fuchsia.examples;

const uint64 MAX_STRING_LENGTH = 32;

[Discoverable]
protocol Echo {
    EchoString(string:MAX_STRING_LENGTH value) -> (string:MAX_STRING_LENGTH response);
    SendString(string:MAX_STRING_LENGTH value);
    -> OnString(string:MAX_STRING_LENGTH response);
};

service EchoService {
    Echo regular_echo;
    Echo reversed_echo;
};

Note: For more details on FIDL protocol syntax, see the FIDL language reference.

The service identifies each protocol by a unique name. Components access these protocols using this name from within their namespace.

For example, the fuchsia.examples.EchoService instance above provides the following namespace paths to access the protocols it contains:

  • /svc/fuchsia.examples.EchoService/default/regular_echo
  • /svc/fuchsia.examples.EchoService/default/reversed_echo

The default marker in the above paths identifies the service instance.

Instances

Multiple named instances of a service can be hosted by a single component. These are presented in the namespace of the consuming component as subdirectories of the service.

For example, a component hosting different implementations of fuchsia.sys.Launcher might expose a privileged and sandboxed instance. These instances would be accessed by a client using the paths /svc/fuchsia.sys.Launcher/privileged and /svc/fuchsia.sys.Launcher/sandboxed respectively.

Default instance

By convention, if a service only ever has a single instance, or if clients of a service typically don't care which instance they connect to, the provider of the service should expose an instance named default.

For example, if clients typically don't care about which fuchsia.sys.Launcher implementation they use, the providing component could expose a default instance that the client accesses using the path /svc/fuchsia.sys.Launcher/default.

Default instances are a useful convention that allow the caller to avoid enumerating instances.

Routing

Services are routed to components through service capabilities.