* properties
* *device* BYEBYE then I'll re-register the UPnPDevice that contain the device with the updated
* properties and also unregister the UPnPDevice that has left
*/
String usn = ssdpPacket.getUSN();
ParseUSN parseUSN = new ParseUSN(usn);
String udn = parseUSN.getUDN();
ServiceReference[] refs = null;
String filter = "(&" + UPNP_DEVICE_FLTR + EXPORT_FLTR+ ")";
try {
refs = context.getServiceReferences(UPnPDevice.class.getName(), filter);
} catch (InvalidSyntaxException e) {
e.printStackTrace();
}
if (refs != null) {
for (int i = 0; i < refs.length; i++) {
UPnPDevice dev = (UPnPDevice) context.getService(refs[i]);
Dictionary dic = dev.getDescriptions(null);
if (((String) dic.get(UPnPDevice.UDN)).equals(udn)) {
return;
}
}
}
if (ssdpPacket.isAlive()) {
Activator.logger.DEBUG("[Importer] ssdpPacket.isAlive");
if (devices.containsKey(udn)) {
Activator.logger.DEBUG("[Importer] Device already discovered");
if (parseUSN.isService()) {
doServiceUpdating(udn,parseUSN.getServiceType());
}
} else {
doDeviceRegistration(udn);
}
} else if (ssdpPacket.isByeBye()) {
Activator.logger.DEBUG("[Importer] ssdpPacket.isByeBye");
synchronized (devices) {
if (devices.containsKey(udn)) {
if (parseUSN.isDevice()) {
Activator.logger.DEBUG("[Importer] parseUSN.isDevice ...unregistering all the children devices ");
//unregistering all the children devices
UPnPDeviceImpl dev = ((OSGiDeviceInfo) devices.get(udn)).getOSGiDevice();
removeOSGiandUPnPDeviceHierarchy(dev);
} else if (parseUSN.isService()) {
Activator.logger.DEBUG("[Importer] parseUSN.isService ...registering modified device again ");
/*
* I have to unregister the UPnPDevice and register it again
* with the updated properties
*/
UPnPDeviceImpl device =
((OSGiDeviceInfo) devices.get(udn)).getOSGiDevice();
ServiceRegistration registar =
((OSGiDeviceInfo) devices.get(udn)).getRegistration();
String[] oldServicesID =
(String[]) (device.getDescriptions(null).get(UPnPService.ID));
String[] oldServiceType =
(String[]) (device.getDescriptions(null).get(UPnPService.TYPE));
Device cyberDevice = findDeviceCtrl(this, udn);
Vector vec = new Vector();
for (int i = 0; i < oldServiceType.length; i++) {
Service ser = cyberDevice.getService(oldServicesID[i]);
if (!(ser.getServiceType().equals(parseUSN.getServiceType())))
{
vec.add(oldServicesID[i]);
}
}
//new serviceID
String[] actualServicesID = new String[vec.size()];
actualServicesID = (String[]) vec.toArray(new String[]{});
//new serviceType
String[] actualServiceType = new String[oldServiceType.length - 1];
vec.clear();
for (int i = 0; i < oldServiceType.length; i++) {
if (!(oldServiceType[i].equals(parseUSN.getServiceType())))
{
vec.add(oldServiceType[i]);
}
}
actualServiceType = (String[]) vec.toArray(new String[]{});