Class DeviceService
java.lang.Object
com.kosdev.kos.core.service.device.DeviceService
- Direct Known Subclasses:
DeviceServer
Track device changes and send notifications.
- Since:
- 1
- Version:
- 1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDevice<?>Return the device type of the entire device.Return the device serial number.Get the serial number provider.voidCalled from the device when it changes.voidSet the device.voidsetSerialNumber(String serialNum) Set the device serial number.voidsetSerialNumberProvider(SerialNumberProvider provider) Set the serial number provider.
-
Constructor Details
-
DeviceService
public DeviceService()
-
-
Method Details
-
setDevice
Set the device. This is called internally to set the device to an instance ofAssemblyDevice, but can be called from the system app to use a differentDeviceimplementation.- Since:
- 1
-
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
Get the serial number provider. The serial number should be set / fetched viaDeviceServicewhich 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 usewhenReady(). This allows application code to know when the provider is ready for use. This can be used to avoid callinggetSerialNumber()when the provider isn't ready as it will simply throw an exception.- Since:
- 1
-
setSerialNumberProvider
Set the serial number provider. This is how the device determines the serial number. The provider implementsReadyand 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
ClientSerialNumberProviderby 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
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
Set the device serial number. This will be stored using the associatedSerialNumberProvider. 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
-