Component-based software

<<../../_common/intro/_components_intro.md>>

<<../../_common/intro/_components_manager.md>>

<<../../_common/intro/_components_capabilities.md>>

<<../../_common/intro/_components_organization.md>>

Exercise: Components

In this exercise, you'll explore the component instance tree and look in detail at capability routing in action using some core system components.

<<../_common/_start_femu.md>>

Explore system components

Open another terminal window and use the component list command to dump the system's component tree:

ffx component list

You should see output similar to the (truncated) list below:

/
/bootstrap
/bootstrap/archivist
/bootstrap/base_resolver
/bootstrap/console
/bootstrap/console-launcher
/bootstrap/decompressor
/bootstrap/device_name_provider
/bootstrap/driver_manager
/bootstrap/fshost
/bootstrap/miscsvc
/bootstrap/netsvc
/bootstrap/power_manager
/bootstrap/ptysvc
/bootstrap/pwrbtn-monitor
/bootstrap/shutdown_shim
/bootstrap/svchost
/bootstrap/sysinfo
/bootstrap/virtual_console
/core
/core/activity
/core/appmgr
...
/core/debug_serial
/core/detect
/core/font_provider
/core/log-stats
/core/remote-control
/core/remote-diagnostics-bridge
/core/sampler
/core/system-update-committer
/core/temperature-logger
/core/test_manager
/core/full-resolver
/startup

This list represents the component instance tree, with organizational components like bootstrap, core, and startup forming sub-trees underneath the root.

The component show command provides more details about each component.

Use this command to see the details of fshost — the Fuchsia filesystem manager:

ffx component show fshost.cm

The command outputs the following report:

               Moniker: /bootstrap/fshost
                   URL: fuchsia-boot:///#meta/fshost.cm
                  Type: CML static component
       Component State: Resolved
 Incoming Capabilities: ...
  Exposed Capabilities: ...
         Configuration: ...
       Execution State: Running
          Start reason: '/bootstrap/base_resolver' requested capability 'pkgfs-packages-delayed'
           Running for: 759834353 ticks
                Job ID: 2933
            Process ID: 2995
 Outgoing Capabilities: ...

Notice a few of the details reported here:

  1. A unique identifier for the component instance (called a moniker).
  2. The package URL where this component was loaded from.
  3. The execution state of the component.
  4. The current job/process ID where the instance is running.
  5. A set of requested and exposed capabilities for the component.

Trace a capability route

In the previous output, there are three capability groups listed:

  • Incoming Capabilities: Capabilities that the component declares with use. These are provided to the component through its namespace.
  • Outgoing Capabilities: Capabilities the component has published to its outgoing directory.
  • Exposed Capabilities: Capabilities the component declares with expose. These are the component's exposed services.

One of the capabilities exposed by fshost to its parent realm is fuchsia.fshost.Admin. This enables other components to access directories in the registered filesystems on the device.

Use the component select command determine how many components use this capability (i.e., have it listed under Incoming Capabilities):

ffx component select moniker '*/*:in:fuchsia.fshost.Admin'

The command lists all the matching components:

bootstrap/driver_manager
|
--in
   |
   --fuchsia.fshost.Admin

Looks like this protocol is consumed by the driver_manager component. The common ancestor between these components is bootstrap, which handles the routing of this capability to the necessary children.