use of org.cybergarage.upnp.Device in project felix by apache.
the class BuildDevice method buildDevice.
private static void buildDevice(String id, Device parent, ServiceReference sr) {
Node dev = new Node(Device.ELEM_NAME);
DeviceData dd = new DeviceData();
dd.setDescriptionURI(id + "/gen-desc.xml");
dev.setUserData(dd);
Device devUPnP = new Device(dev);
devUPnP.setDeviceType(extractDeviceType(sr));
devUPnP.setFriendlyName((String) sr.getProperty(UPnPDevice.FRIENDLY_NAME));
devUPnP.setManufacture((String) sr.getProperty(UPnPDevice.MANUFACTURER));
devUPnP.setManufactureURL((String) sr.getProperty(UPnPDevice.MANUFACTURER_URL));
devUPnP.setModelDescription((String) sr.getProperty(UPnPDevice.MODEL_DESCRIPTION));
devUPnP.setModelName((String) sr.getProperty(UPnPDevice.MODEL_NAME));
devUPnP.setModelNumber((String) sr.getProperty(UPnPDevice.MODEL_NUMBER));
devUPnP.setModelURL((String) sr.getProperty(UPnPDevice.MODEL_URL));
devUPnP.setSerialNumber((String) sr.getProperty(UPnPDevice.SERIAL_NUMBER));
devUPnP.setUDN((String) sr.getProperty(UPnPDevice.UDN));
devUPnP.setUPC((String) sr.getProperty(UPnPDevice.UPC));
devUPnP.setLocation(id + "/gen-desc.xml");
addServices(id, devUPnP, sr);
addDevices(id, devUPnP, sr);
// twa: essential!!!!!!!
parent.addDevice(devUPnP);
devUPnP.setPresentationURL((String) sr.getProperty(UPnPDevice.PRESENTATION_URL));
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class BuildDevice method buildRootDeviceNode.
private static Device buildRootDeviceNode(Node root, ServiceReference sr) {
Node dev = new Node(Device.ELEM_NAME);
root.addNode(dev);
DeviceData dd = new DeviceData();
dd.setDescriptionURI("/gen-desc.xml");
dev.setUserData(dd);
Device devUPnP = new Device(root, dev);
devUPnP.setDeviceType(extractDeviceType(sr));
devUPnP.setFriendlyName((String) sr.getProperty(UPnPDevice.FRIENDLY_NAME));
devUPnP.setManufacture((String) sr.getProperty(UPnPDevice.MANUFACTURER));
devUPnP.setManufactureURL((String) sr.getProperty(UPnPDevice.MANUFACTURER_URL));
devUPnP.setModelDescription((String) sr.getProperty(UPnPDevice.MODEL_DESCRIPTION));
devUPnP.setModelName((String) sr.getProperty(UPnPDevice.MODEL_NAME));
devUPnP.setModelNumber((String) sr.getProperty(UPnPDevice.MODEL_NUMBER));
devUPnP.setModelURL((String) sr.getProperty(UPnPDevice.MODEL_URL));
devUPnP.setSerialNumber((String) sr.getProperty(UPnPDevice.SERIAL_NUMBER));
devUPnP.setUDN((String) sr.getProperty(UPnPDevice.UDN));
devUPnP.setUPC((String) sr.getProperty(UPnPDevice.UPC));
devUPnP.setLocation("/gen-desc.xml");
addServices("", devUPnP, sr);
addDevices("", devUPnP, sr);
devUPnP.setPresentationURL((String) sr.getProperty(UPnPDevice.PRESENTATION_URL));
return devUPnP;
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class ExporterUPnPEventListener method notifyUPnPEvent.
/**
* @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String, java.lang.String, java.util.Dictionary)
*/
public void notifyUPnPEvent(String deviceId, String serviceId, Dictionary events) {
Device dAux = null;
if (d.getUDN().equals(deviceId)) {
dAux = d;
} else {
dAux = d.getDevice(deviceId);
}
Service s = dAux.getService(serviceId);
// fix 2/9/2004 francesco
Enumeration e = events.keys();
while (e.hasMoreElements()) {
StateVariable sv;
String dataType;
String name;
Object key = e.nextElement();
if (key instanceof String) {
name = (String) key;
sv = s.getStateVariable(name);
dataType = sv.getDataType();
} else {
Activator.logger.ERROR(deviceId + " notified the change in the StateVariable of " + serviceId + " but the key Java type contained in the Dictiories was " + key.getClass().getName() + " instead of " + String.class.getName() + " as specified by Javadoc");
continue;
}
try {
sv.setValue(Converter.toString(events.get(key), dataType));
} catch (Exception ignored) {
Activator.logger.ERROR("UPnP Base Driver Exporter: error converting datatype while sending event, exception message follows:" + ignored.getMessage());
}
}
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class ThreadExporter method bindInvokes.
/*
/**
* @param upnpDev
* @param refDev
*
private void makeIcons(
org.apache.felix.upnpbase.export.xml.Device upnpDev,
String path) {
Icon[] icons = upnpDev.getIcons();
if(icons!=null){
byte[] buf = new byte[512];
for (int i = 0; i < icons.length; i++) {
try {
String icoPath = path+icons[i].getUrl().replace('/',File.separatorChar);
InputStream is = icons[i].getInputStream();
Converter.makeParentPath(icoPath);
FileOutputStream fos = new FileOutputStream(icoPath);
int n=is.read(buf,0,buf.length);
while(n>0){
fos.write(buf,0,n);
n=is.read(buf,0,buf.length);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
org.apache.felix.upnpbase.export.xml.Device[] devs = upnpDev.getDevices();
if(devs==null)
return;
for (int i = 0; i < devs.length; i++) {
makeIcons(devs[i],path);
}
}*/
/**
* This method is used to connect all the Action that are shown to UPnP world
* by CyberLink UPnP Device to the real implementation that is conatined iniside
* the OSGi service.
* This method will connect even all the subdevice of te given OSGi device.
*
* @param d CyberLink Device that will be used associated to the OSGi Device
* @param rootDevice ServiceReference to the OSGi Device that will be used as
* implementation of the CyberLink Device
* @return true if and only if the binding off all the action of all the children
* device is done succesfully
*/
private boolean bindInvokes(Device d, ServiceReference rootDevice) {
bindInvoke(d, rootDevice);
ServiceReference[] childs = null;
try {
childs = Activator.bc.getServiceReferences(UPnPDevice.class.getName(), "(" + UPnPDevice.PARENT_UDN + "=" + rootDevice.getProperty(UPnPDevice.UDN) + ")");
} catch (InvalidSyntaxException e) {
e.printStackTrace();
}
String[] childsUDN = (String[]) rootDevice.getProperty(UPnPDevice.CHILDREN_UDN);
if ((childs == null) && (childsUDN == null)) {
return true;
} else if ((childs == null) || (childsUDN == null)) {
return false;
} else if (childs.length == childsUDN.length) {
DeviceList dl = d.getDeviceList();
for (int i = 0; i < childs.length; i++) {
Device dev = (Device) dl.elementAt(i);
if (!bindInvokes(dev, childs[i]))
return false;
}
return true;
} else {
return false;
}
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class ThreadExporter method unexportDevice.
/**
* @param property
*/
private synchronized void unexportDevice(ServiceReference dev) {
String udn = (String) dev.getProperty(UPnPDevice.PARENT_UDN);
if (udn == null) {
ExportedDeviceInfo edi = (ExportedDeviceInfo) exportedDevices.get(dev.getProperty(UPnPDevice.UDN));
Device d = edi.getDevice();
if (d != null) {
Activator.logger.INFO("[Exporter] removing device:" + d.getFriendlyName());
d.stop();
exportedDevices.remove(d.getUDN());
}
ServiceRegistration srListener = edi.getServiceRegistration();
if (srListener != null)
srListener.unregister();
} else {
ServiceReference[] servs = null;
try {
servs = Activator.bc.getServiceReferences(UPnPDevice.class.getName(), "(" + UPnPDevice.UDN + "=" + udn + ")");
} catch (InvalidSyntaxException ignored) {
}
if (servs == null)
return;
this.unexportDevice(servs[0]);
}
}
Aggregations