Class DeviceService

java.lang.Object
com.kosdev.kos.core.service.device.DeviceService
Direct Known Subclasses:
DeviceServer

public class DeviceService extends Object
Track device changes and send notifications.
Since:
1
Version:
1
  • Constructor Details

    • DeviceService

      public DeviceService()
  • Method Details

    • setDevice

      public void setDevice(Device<?> device)
      Set the device. This is called internally to set the device to an instance of AssemblyDevice , but can be called from the system app to use a different Device implementation.
      Since:
      1
    • getDeviceType

      public String getDeviceType()
      Return the device type of the entire device. If the device is multi-node, every node in the device will return the same device type. Only the primary node can set the device type.
      Since:
      1
    • getSerialNumberProvider

      public SerialNumberProvider getSerialNumberProvider()
      Get the serial number provider. The serial number should be set / fetched via DeviceService which verifies that the provider is installed and ready. However, in cases where a provider may take some time to be ready, such as when using critical data, it can be convenient to fetch the provider directly and use whenReady() . This allows application code to know when the provider is ready for use. This can be used to avoid calling getSerialNumber() when the provider isn't ready as it will simply throw an exception.
      Since:
      1
    • setSerialNumberProvider

      public void setSerialNumberProvider(SerialNumberProvider provider)
      Set the serial number provider. This is how the device determines the serial number. The provider implements Ready and the serial number will not be available until the provider becomes ready. Depending on the provider, this may take some time or may, under some conditions, never become ready. In this case the device effectively has no serial number.

      If this is called more than once, only the last provider will be used.

      The serial number provider on secondary nodes is set to ClientSerialNumberProvider by default. This provider synchronizes the serial number from the primary node so that the entire multi-node device sees the same serial number.

      Since:
      1
    • getSerialNumber

      public String getSerialNumber() throws Exception
      Return the device serial number. If no serial number provider has been set, this will throw an exception. If the serial number has not been determined, this may throw an exception depending on the implementation of the provider.
      Throws:
      Exception
      Since:
      1
    • setSerialNumber

      public void setSerialNumber(String serialNum) throws Exception
      Set the device serial number. This will be stored using the associated SerialNumberProvider . It is up to the provider to persist the serial number in some way to survive reboots and board swaps.

      If a provider is not installed, this will throw an exception.

      This can only be called on the primary node. By default, secondary nodes synchronize the serial number from the primary node.

      Throws:
      Exception
      Since:
      1
    • notifyListeners

      public void notifyListeners()
      Called from the device when it changes.
      Since:
      1
    • getDevice

      public Device<?> getDevice()