Previous Topic

Next Topic

Book Contents

Book Index

Device Items Events

Functional Item events related to Device Items

For receiving the events related to the Device Items, there should have any available Devices in the system, that have defined functionality (Device Items). You can learn more about how to create a Device with DeviceItem from the Creating a Device guide.

Subscribing to Events When Device Item Properties are Changed

The FunctionalItemEventConstnats.TOPIC_PROPERTY_CHANGED is thrown when:

The properties of this event are:

Subscribing to Events When FunctionalItem.NAME Property Changed

The following example demonstrate how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when Device Item with UID test:device:item:UID changes its property FunctionalItem.NAME. For example to receive this event, you have to call FunctionalItem.setName(String) on this Device Item.

public void registerListener() {

  Hashtable<String, String> properties = new Hashtable<String, String>();

  properties.put(EventConstants.EVENT_TOPIC, FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED);

  properties.put(EventConstants.EVENT_FILTER, "(&(" + FunctionalItem.UID + "=test:device:item:UID)(" + FunctionalItemEventConstants.PROPERTY_NAME + '=' + FunctionalItem.NAME + "))");

  serviceRegistration = bc.registerService(EventHandler.class, this, properties);

}

Subscribing to Events When FunctionalItem.TAGS Property Changed

The following example demonstrate how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when Device Item with UID test:device:item:UID change its property FunctionalItem.TAGS. For example to receive this event, you have to call FunctionalItem.setTags(Set<String>) on this Device Item.

public void registerListener() {

  Hashtable<String, String> properties = new Hashtable<String, String>();

  properties.put(EventConstants.EVENT_TOPIC, FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED);

  properties.put(EventConstants.EVENT_FILTER, "(&(" + FunctionalItem.UID + "=test:device:item:UID)(" + FunctionalItemEventConstants.PROPERTY_NAME + '=' + FunctionalItem.TAGS + "))");

  serviceRegistration = bc.registerService(EventHandler.class, this, properties);

}

Subscribing to Events When eventable Property Changed

The following example demonstrate how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when Device Items with object class StepperMotor change the property StepperMotor.PROPERTY_DIRECTION. For example to receive this event, you have to call StepperMotor.setDirection(String) on this Device Item.

public void registerListener() {

  Hashtable<String, String> properties = new Hashtable<String, String>();

  properties.put(EventConstants.EVENT_TOPIC, FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED);

  properties.put(EventConstants.EVENT_FILTER, "(&(" + FunctionalItem.OBJECT_CLASS + '=' + StepperMotor.class.getName() + ")("

                                                    + FunctionalItemEventConstants.PROPERTY_NAME + '=' + StepperMotor.PROPERTY_DIRECTION + "))");

  serviceRegistration = bc.registerService(EventHandler.class, this, properties);

}

FunctionalItemEventConstants.TOPIC_OPERATION_EXECUTED

FunctionalItem event with topic FunctionalItemEventConstants.TOPIC_OPERATION_EXECUTED is not created for all operations in Device Access, exept for the operations in Device Admin: