use of org.cybergarage.upnp.DeviceList 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.DeviceList 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.DeviceList in project felix by apache.
the class MyCtrlPoint method findDeviceCtrl.
public Device findDeviceCtrl(ControlPoint ctrl, String udn) {
/*
* this return the device looking in all the struct
*/
DeviceList devList = getDeviceList();
Device dev = null;
int i = 0;
while (i < devList.size() && (dev == null)) {
if (devList.getDevice(i).getUDN().equals(udn)) {
dev = devList.getDevice(i);
return dev;
}
dev = findDevice(udn, devList.getDevice(i));
i++;
}
return dev;
}
use of org.cybergarage.upnp.DeviceList in project i2p.i2p by i2p.
the class UPnP method main.
/**
* Dumps out device info in semi-HTML format
*/
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.setProperty(PROP_ADVANCED, "true");
I2PAppContext ctx = new I2PAppContext(props);
UPnP cp = new UPnP(ctx);
org.cybergarage.upnp.UPnP.setEnable(org.cybergarage.upnp.UPnP.USE_ONLY_IPV4_ADDR);
Debug.initialize(ctx);
cp.setHTTPPort(49152 + ctx.random().nextInt(5000));
cp.setSSDPPort(54152 + ctx.random().nextInt(5000));
long start = System.currentTimeMillis();
cp.start();
long s2 = System.currentTimeMillis();
System.err.println("Start took " + (s2 - start) + "ms");
System.err.println("Searching for UPnP devices");
start = System.currentTimeMillis();
cp.search();
s2 = System.currentTimeMillis();
System.err.println("Search kickoff took " + (s2 - start) + "ms");
System.err.println("Waiting 10 seconds for responses");
Thread.sleep(10000);
DeviceList list = cp.getDeviceList();
if (list.isEmpty()) {
System.err.println("No UPnP devices found");
System.exit(1);
}
System.err.println("Found " + list.size() + " devices.");
System.err.println("Redirect the following output to an html file and view in a browser.");
StringBuilder sb = new StringBuilder();
Iterator<Device> it = list.iterator();
int i = 0;
while (it.hasNext()) {
Device device = it.next();
cp.listSubDev(device.toString(), device, sb);
System.out.println("<h3>Device " + (++i) + ": " + DataHelper.escapeHTML(device.getFriendlyName()) + "</h3>");
System.out.println("<p>UDN: " + DataHelper.escapeHTML(device.getUDN()));
System.out.println("<br>IP: " + getIP(device));
System.out.println(sb.toString());
sb.setLength(0);
}
System.exit(0);
}
use of org.cybergarage.upnp.DeviceList 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;
}
}
Aggregations