Previous Topic

Next Topic

Book Contents

Book Index

Device Events

Functional Item Events Related to Device

Subscribing to Events When the Device Properties are Changed

For receiving this event, there should be some available Devices in the system. You can learn more about how to create a Device here Subscribing for event is possible when the Device is available.

FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED is thrown when:

The properties of this event are:

Subscribing to events when Device.NAME property is changed

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

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, "(&(" + Device.UID + '=' + "test:device:UID)(" + FunctionalItemEventConstants.PROPERTY_NAME + '=' + Device.NAME + "))");

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

}

Subscribing to Events when Device.TAGS is Changed

The following example demonstrates how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when Device with UID test:device:UID changes the Device.TAGS property. For example to receive this event, you call Device.setTags(Set<String>).

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, "(&(" + Device.UID + '=' + "test:device:UID)(" + FunctionalItemEventConstants.PROPERTY_NAME + '=' + Device.TAGS + "))");

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

}

Subscribing to Events When Device.STATUS Property is Changed

The following example demonstrates how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when Device with UID test:device:UID changes the Device.STATUS property. The created Device should change its status, if the DeviceAdmin.remove(String) method is invoked.

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, "(&(" + Device.UID + '=' + "test:device:UID)(" + FunctionalItemEventConstants.PROPERTY_NAME + '=' + Device.STATUS + "))");

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

}

Subscribing to events when Device.ERROR property is changed

The following example demonstrate how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when Device with UID test:device:UID changes the Device.ERROR property. For example this event should received when the protocol adapter which register this Device is unregistered.

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, "(&(" + Device.UID + '=' + "test:device:UID)(" + FunctionalItemEventConstants.PROPERTY_NAME + '=' + Device.ERROR + "))");

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

}

Generally the events related with Device.STATUS and Device.ERROR are consistent. In the most cases when the device change its status, its change and the its error. In this situation the generated events are two.

FunctionalItemEventConstants.TOPIC_OPERATION_EXECUTED

FunctionalItem event with topic FunctionalItemEventConstants.TOPIC_OPERATION_EXECUTED is not created for all operation in Device Access, expect the operations in Device Admin - DeviceAdmin.OPERATION_CREATE, DeviceAdmin.OPERATION_CREATE_DEVICE, DeviceAdmin.OPERATION_REMOVE and DeviceAdmin.OPERATION_REMOVE_DEVICE.