Assemblies

Assembly

An Assembly is KOS’s way of abstracting a collection of hardware into an atomic unit, which can be installed and uninstalled. In KOS, each physical hardware component has a corresponding software counterpart, called a Board. These logical representations are gathered and stored within the Assembly, which can then be installed and uninstalled via the AssemblyService. The benefits of abstracting hardware this way are two-fold. For one, it reduces race conditions, and secondly, it provides a pluggable system for adding new elements to an assembly.

It is typical that a device will only have a single Assembly. But for cases where a device supports expansion hardware multiple Assemblies can exist. That being said, even in instances where there is only one Assembly. The CoreAssembly differs from other assemblies in one way. Unlike other Assemblies it cannot be uninstalled. This is because the CoreAssembly abstracts the collection of boards intrinsic to the device’s basic functionality.

Similar to applications, assemblies implement the Loadable interface, and in so doing allow the developer to benefit from the presence of its lifecycle events. These lifecycle events are called by the AssemblyService, which is responsible for installing and uninstalling assemblies.

Assemblies also implement HandleAware, meaning that every Assembly has its own unique handlepath; see here for more info on handlepaths. This means that assemblies can also be fetched via the HandleService.

Using the AssemblyService

In order to install and uninstall assemblies you will need access to the AssemblyService, which can be obtained by autowiring it from the context. Once you have the service, you can simply call install and uninstall like so…

It is worth noting that the system app has a helper method for this

()
which handles the autowiring and installation part for you. ## Listening for an `Assembly` There are times when you may need to listen for the installation of an `Assembly`. KOS comes with the tooling to do this. To listen to an Assembly, just implement the `AssemblyListener`, before adding the listener to the context. This will autowire it into the `AssemblyService`. The `AssemblyService` calls to the various lifecycle methods of the `AssemblyListener` when installing and uninstalling assemblies. A list of all these methods can be found [here](https://api.kosdev.com/v0.0.0-SNAPSHOT/api-core/com/kosdev/kos/core/service/assembly/AssemblyListener.html).