Previous Topic

Next Topic

Book Contents

Book Index

Device Admin Events

Functional Item Events Related to Device Admin

Subscribing to Events When DeviceAdmin.OPERATION_CREATE or DeviceAdmin.OPERATION_CREATE_DEVICE is Executed

When the operations DeviceAdmin.OPERATION_CREATE and DeviceAdmin.OPERATION_CREATE_DEVICE are executed the Device Access throws a FunctionalItem event with topic FunctionalItemEventConstants.TOPIC_OPERATION_EXECUTED. This guide details on creating a Device. For both operations the event properties are:

The following example shows how to retrieve this event and filter it by:

Subscribing to Events When DeviceAdmin.OPERATION_RECREATE_DEVICE Operation is Executed

DeviceAdmin supports operation for re-create the device. For this operation no operation method is defined. There is only the constant DeviceAdmin.OPERATION_RECREATE_DEVICE. This constant is used only for FunctionalItem event operation name.

The situation when the Device Access will throw this event will be: when a device is available in the network and the device is join again in the network. The result is that the Device Access will throw event for re-created the device.

The event topic is FunctionalItemEventConstant.TOPIC_OPERATION_EXECUTED and the properties of the event are:

Subscribing to Events When DeviceAdmin.OPERATION_REMOVE or DeviceAdmin.OPERATION_REMOVE_DEVICE Operation is Executed

When the operations DeviceAdmin.OPERATION_REMOVE and DeviceAdmin.OPERATION_REMOVE_DEVICE are executed the Device Access throws FunctionalItem event with topic FunctionalItemEventConstant.TOPIC_OPERATION_EXECUTED. This guide describes the removing of a Device. For both operations the properties of the event are:

The following example shows how to retrieve this event and filtered by the Protocol Adapter name which is "DA Demo" and operation name which is value of the constant DeviceAdmin.OPERATION_REMOVE.

public void registerListener() {

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

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

  properties.put(EventConstants.EVENT_FILTER, "(&(&(" + Device.ADAPTER_NAME + '=' + ADAPTER_DEMO + ")("

                                                      + FunctionalItem.OBJECT_CLASS + '=' + DeviceAdmin.class.getName() + ")("

                                                      + FunctionalItemEventConstants.OPERATION_NAME + '=' + DeviceAdmin.OPERATION_REMOVE + ")))");

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

}

Subscribing to Events When Device Admin Properties are Changed

The FunctionalItemEventConstnats.TOPIC_PROPERTY_CHANGED is thrown when:

The properties of this event are:

Subscribing to Events When DeviceAdmin.NAME is Changed

The following example demonstrate how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when Device Admin change its property DeviceAdmin.NAME. For example to receive this event, you have to call DeviceAdmin.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, "(&(" + FunctionalItem.UID + '=' + DeviceAdmin.DEVICE_ADMIN_UID + ")("

                                                    + FunctionalItemEventConstants.PROPERTY_NAME + '=' + DeviceAdmin.NAME + "))");

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

}

Subscribing to Events When DeviceAdmin.TAGS is Changed

The following example demonstrate how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when Device Admin change its property DeviceAdmin.TAGS. For example to receive this event, you have to call DeviceAdmin.setTags(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, "(&(" + FunctionalItem.UID + '=' + DeviceAdmin.DEVICE_ADMIN_UID + ")("

                                                    + FunctionalItemEventConstants.PROPERTY_NAME + '=' + DeviceAdmin.TAGS + "))");

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

}

Subscribing to Events When DeviceAdmin.PROPERTY_ADAPTER_INFOS is Changed

The following example demonstrate how to subscribe for FunctionalItemEventConstants.TOPIC_PROPERTY_CHANGED, when information about the supported protocol adapters is changed.

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 + '=' + DeviceAdmin.DEVICE_ADMIN_UID + ")("

                                                    + FunctionalItemEventConstants.PROPERTY_NAME + '=' + DeviceAdmin.PROPERTY_ADAPTER_INFOS + "))");

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

}