use of org.cybergarage.upnp.Device in project felix by apache.
the class DriverControllerImpl method getSCPDURL.
public String getSCPDURL(String udn, String serviceId) {
if (myCtrl == null) {
logger.WARNING("UPnP Importer is disabled. getSCPDURL() is not available");
return null;
}
if (udn == null || udn.equals(""))
throw new IllegalArgumentException("Invalid udn paramenter");
if (serviceId == null || serviceId.equals(""))
throw new IllegalArgumentException("Invalid serviceId paramenter");
Device device = myCtrl.getDevice(udn);
if (device == null) {
logger.WARNING("getSCPDURL():: No device data available for UDN: " + udn);
return null;
}
Service service = device.getService(serviceId);
if (service == null) {
logger.WARNING("getSCPDURL():: No service data available for serviceId:" + serviceId + " of UDN " + udn);
return null;
}
String scpd = service.getSCPDURL().trim();
return resolveRelativeLink(device, scpd);
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class ThreadExporter method cleanUp.
/**
*/
public synchronized void cleanUp() {
Activator.logger.INFO("Cleaning...");
Enumeration keys;
Activator.logger.INFO("Removing temporary listener....");
keys = exportedDevices.keys();
while (keys.hasMoreElements()) {
ServiceRegistration sr = ((ExportedDeviceInfo) exportedDevices.get(keys.nextElement())).getServiceRegistration();
sr.unregister();
}
Activator.logger.INFO("Done");
Activator.logger.INFO("Removing device....");
keys = exportedDevices.keys();
while (keys.hasMoreElements()) {
Device dev = ((ExportedDeviceInfo) exportedDevices.get(keys.nextElement())).getDevice();
dev.stop();
}
Activator.logger.INFO("Done");
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class ThreadExporter method bindSubscribe.
/**
* This method add an UPnPEventListener Service to the OSGi Framework so that
* the Base Driver can notify all the event listener registered on the CyberLink
* UPnP device from the UPnP World.
*
* @param d Device of CyberLink that will be notified by the changing of the StateVariable
* that happen on the OSGi World
* @return ServiceRegistration of the new registered service.
*/
private ServiceRegistration bindSubscribe(Device d) {
ExporterUPnPEventListener eventer = new ExporterUPnPEventListener(d);
Properties p = new Properties();
StringBuffer sb = new StringBuffer("(|");
Vector v = new Vector();
v.add(d);
Device current;
while (v.size() != 0) {
current = (Device) v.elementAt(0);
v.remove(0);
DeviceList dl = current.getDeviceList();
for (int i = 0; i < dl.size(); i++) {
v.add(dl.elementAt(i));
}
sb.append("(").append(UPnPDevice.ID).append("=").append(current.getUDN()).append(")");
}
sb.append(")");
Filter f = null;
try {
f = Activator.bc.createFilter(sb.toString());
} catch (InvalidSyntaxException e) {
e.printStackTrace();
return null;
}
if (f != null)
p.put(UPnPEventListener.UPNP_FILTER, f);
return Activator.bc.registerService(UPnPEventListener.class.getName(), eventer, p);
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class MyCtrlPoint method removeExpiredDevices.
/*
* (non-Javadoc)
*
* @see org.cybergarage.upnp.ControlPoint#removeExpiredDevices()
*
*/
public void removeExpiredDevices() {
DeviceList devList = getDeviceList();
int devCnt = devList.size();
for (int n = 0; n < devCnt; n++) {
Device dev = devList.getDevice(n);
if (dev.isExpired() == true) {
Activator.logger.DEBUG("[Importer] Expired device:" + dev.getFriendlyName());
removeDevice(dev);
removeOSGiExpireDevice(dev);
}
}
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class MyCtrlPoint method doServiceUpdating.
public void doServiceUpdating(String udn, String serviceType) {
Activator.logger.DEBUG("[Importer] check for service updating");
OSGiDeviceInfo deviceinfo = (OSGiDeviceInfo) devices.get(udn);
UPnPDeviceImpl device = deviceinfo.getOSGiDevice();
boolean isSerPresent = device.existServiceType(serviceType);
if (!isSerPresent) {
/*
* The serivice doesn't exist so it's new.
* Find the udn of owner device and re-register the owner
*/
ServiceRegistration registar = ((OSGiDeviceInfo) devices.remove(udn)).getRegistration();
String[] oldServicesID = (String[]) device.getDescriptions(null).get(UPnPServiceImpl.ID);
String[] oldServicesType = (String[]) device.getDescriptions(null).get(UPnPServiceImpl.TYPE);
// to handle multiple instance of a serivice of the same type
Device cyberDevice = findDeviceCtrl(this, udn);
ServiceList serviceList = cyberDevice.getServiceList();
ArrayList newServicesID = new ArrayList();
for (int i = 0; i < serviceList.size(); i++) {
if (serviceList.getService(i).getServiceType().equals(serviceType)) {
newServicesID.add(serviceList.getService(i).getServiceID());
}
}
// adding the new servicesID
String[] currentServicesID = new String[(oldServicesID.length + newServicesID.size())];
int endOld = 1;
for (int i = 0; i < oldServicesID.length; i++) {
currentServicesID[i] = oldServicesID[i];
endOld++;
}
int j = 0;
for (; endOld < currentServicesID.length; endOld++) {
currentServicesID[endOld] = (String) newServicesID.get(j);
j++;
}
// adding the new ServiceType
String[] currentServicesType = new String[oldServicesType.length + 1];
for (int i = 0; i < oldServicesType.length; i++) {
currentServicesType[i] = oldServicesType[i];
}
currentServicesType[currentServicesType.length - 1] = serviceType;
// unregistring the OSGi Device
// and setting new properties
unregisterUPnPDevice(registar);
device.setProperty(UPnPService.ID, currentServicesID);
device.setProperty(UPnPServiceImpl.TYPE, currentServicesType);
// registering the service with the updated properties
// TODO Check if null to the first paramaters is correct or it requires the reference to the cyberdomo upnp device
registerUPnPDevice(null, device, device.getDescriptions(null));
searchForListener(cyberDevice);
}
}
Aggregations