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:
FunctionalItemEventConstants.OPERATION_NAME – the value is the constant DeviceAdmin.OPERATION_CREATE.DeviceAdmin.UID – the value is the constant DeviceAdmin.DEVICE_ADMIN_UID.DeviceAdmin.OBJECT_CLASS – the value is the DeviceAdmin object class.DeviceAdmin.NAME – the name of the DeviceAdmin. This is optional.DeviceAdmin.TAGS – the tags of the DeviceAdmin.DeviceAdmin registration properties.DeviceEventConstants.PROPERTY_DEVICE_UID – the UID of the created Device.DeviceEventConstants.PROPERTY_DEVICE_NAME – the name of the created Device.DeviceEventConstants.PROPERTY_DEVICE_TAGS – the tags of the created Device.Device.UIDDevice.NAMEDevice.TAGSDevice.OBJECT_CLASSFunctionalItemFactory.FACTORY_UIDThe following example shows how to retrieve this event and filter it by:
DeviceAdmin.OPERATION_CREATE.
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_CREATE + ")))");
serviceRegistration = bc.registerService(EventHandler.class, this, properties);
}
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:
FunctionalItemEventConstants.OPERATION_NAME – the value is the constant DeviceAdmin.OPERATION_RECREATE_DEVICE.DeviceAdmin.UID – the value is the constant DeviceAdmin.DEVICE_ADMIN_UID.DeviceAdmin.OBJECT_CLASS – the value is the DeviceAdmin object class.DeviceAdmin.NAME – the name of the DeviceAdmin. This is optional.DeviceAdmin.TAGS – the tags of the DeviceAdmin.DeviceAdmin registration properties.DeviceEventConstants.PROPERTY_DEVICE_UID – the UID of the created Device.DeviceEventConstants.PROPERTY_DEVICE_NAME – the name of the created Device.DeviceEventConstants.PROPERTY_DEVICE_TAGS – the tags of the created Device.Device.UIDDevice.NAMEDevice.TAGSDevice.OBJECT_CLASSFunctionalItemFactory.FACTORY_UIDSubscribing 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:
FunctionalItemEventConstants.OPERATION_NAME – the value is one of the constants DeviceAdmin.OPERATION_REMOVE.DeviceAdmin.UID – the value is the constant DeviceAdmin.DEVICE_ADMIN_UID.DeviceAdmin.OBJECT_CLASS – the value is the DeviceAdmin object class.DeviceAdmin.NAME – the name of the DeviceAdmin. This is optional.DeviceAdmin.TAGS – the tags of the DeviceAdmin.DeviceAdmin registration properties.DeviceEventConstants.PROPERTY_DEVICE_UID – the UID of the removed Device.DeviceEventConstants.PROPERTY_DEVICE_NAME – the name of the removed Device.DeviceEventConstants.PROPERTY_DEVICE_TAGS – the tags of the removed Device.Device.UIDDevice.NAMEDevice.TAGSDevice.OBJECT_CLASSFunctionalItemFactory.FACTORY_UIDThe 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:
DeviceAdmin registration properties are changed (DeviceAdmin.NAME or DeviceAdmin.TAGS).DeviceAdmin.PROPERTY_ADAPTER_INFOS property is changed.The properties of this event are:
FunctionalItemEventConstants.PROPERTY_NAMEFunctionalItemEventConstants.PROPERTY_NEW_VALUEFunctionalItemEventConstants.PROPERTY_OLD_VALUEFunctionalItem.UIDFunctionalItem.NAMEFunctionalItem.TAGSFunctionalItem.OBJECT_CLASSEventConstants.TIMESTAMPFunctionalItem.getAttributes()
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);
}