Previous Topic

Next Topic

Book Contents

Book Index

Device Item

The Device Admin guide details on how to create a Device with a set of functionalities. Below you will found information from the Device Item abstraction perspective.

The Device Item (com.prosyst.mbs.services.fim.FunctionalItem) represents the functionality of the Device. It has set of properties and operations that bring the real physical access to the Device functionalities. Every Device Item is a Functional Item and it is registered as an OSGi service. Each Device may have zero or more Device Items attached to it. The Device Access defines the common items interfaces.
The Device Access provides a mapping mechanism which is applied to the Device Items. This means that Device Access enables you to construct your own Device Item which can be mapped to the Device Item that is provided by the protocol adapter. You can learn more about it and how you can do it on Overview page.

Retrieving a Device Item

The Device Access provides two ways by which you can retrieve a Device Item. The following description gives you more information and examples about the ways. First you should have available device with some functionalities.

Retrieving a Device Item Using Service Registry

Each Device Item is registered as a service in an OSGi registry. In this way for retrieving a Device Item you should call the BundleContext.getServiceReferences(Class<?>, String) method, where:

The following example shows how to retrieve the Device Item with name "test:device:item:name". For this reason you should have created Device with any Device Item.

Collection<ServiceReference<FunctionalItem>> items = bc.getServiceReferences(StepperMotor.class, '(' + FunctionalItem.NAME + "=test:device:item:name))");

When the Device Item is in the OSGi registry this ensures that the Device Item is available and you can access it. If the protocol adapter is unregistered, the Device Items that was provided from it, should be unregistered from the OSGi registry also. In this situation the Device is in status of offline.

Retrieving a Device Item Using the so-Called Local Device Methods

You can use this methods of the Device to retrieve a Device Item. You should be careful with using these methods because when you get the Device Item, it may not be available for use. It is recommended to get the Device Item from the service registry (see above).

Registration properties

The following table describes the Device Item registration properties:

Property

Description

FunctionalItem.UID

The UID of the Device Item

FunctionalItem.NAME

The name of the Device Item

FunctionalItem.TAGS

The tags of the Device Item

FunctionalItem.OBJECT_CLASS

The value of this property is List<String>> with the following ordered elements:

  • the implemented main Functional Item element
  • the inherited interfaces
  • the FunctionalItem interface

FunctionalItem.getAttributes()

The attributes of the Device Item - DeviceItemConstant.DEVICE_UID, DeviceItemConstnat.MAPPING, etc. You can learn more about the Device attributes on the following section.

DeviceItem attributes

Attribute

Description

DeviceItemConstant.DEVICE_UID

This constant is used to specify the Device UID. Every Device Item has this attribute. This constant is used as a DeviceItem registration property. The type of value is String

DeviceItemConstants.MAPPING

This constant is used to provide mapping source information. More information about the mapping, you will found on Mapping page.
This constant is used as a DeviceItem registration property. The value type of this attribute is instance of Map with the following keys:

  • DeviceItemConstants.MAPPING.UID – UID of the applied mapping.
  • DeviceItemConstants.SOURCE_UID – the source device item UID.
  • DeviceItemConstants.SOURCE_CLASS – the class name of the source device item of the applied mapping.

Custom attributes

It is possible to provide a custom user attributes or adapter attributes. All Device Item attributes are used as a registration properties.

Functional properties and operations

Each Device Item is a FunctionalItem that represents the functionalities of the Device. Each Device Item implements some functional interface. Each functional interface has set of functional properties and operations. More about how to define your Functional Item and whats are the restriction when you write a Functional Item, you can found on Functional Item Developer Guide - Defining Functional Items page.

The Device Item may define functional properties. You can get information about defined Device Item properties by using the FunctionalItem.getItemMetadata() method. It returns com.prosyst.mbs.services.fim.metadata.ItemMetadata that holds Map<String, PropertyMetadata>. You can learn more about the metadata on Functional Item Developer Guide - Metadata and Annotations page. These Device Items that have readable properties are registered in the OSGi registry after initialization of internal cache.

Operations

The Device Item may define operations to be executed over a Device Item. You can get information about defined Device Item operations by using the FunctionalItem.getItemMetadata() method. It returns com.prosyst.mbs.services.fim.metadata.ItemMetadata that holds Map<String, OperationMetadata>. For more details about the metadata refer to Functional Item Developer Guide - Metadata and Annotations page.