use of org.cybergarage.upnp.Device in project felix by apache.
the class ThreadExporter method run.
public void run() {
File osgiRoot = Activator.bc.getDataFile("");
if (osgiRoot == null) {
Activator.logger.ERROR("Unable to use filesystem");
while (true) {
try {
Activator.bc.getBundle().stop();
break;
} catch (BundleException e) {
e.printStackTrace();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
return;
}
ServiceReference rootDevice = null;
while (!shouldEnd()) {
DeviceNode dn = queueRootDevice.getRootDevice();
if (dn == null)
continue;
rootDevice = dn.getReference();
if (!getListening())
setListen();
Activator.logger.INFO("[Exporter] Exporting device " + rootDevice.getProperty(UPnPDevice.FRIENDLY_NAME));
synchronized (this) {
Device d = BuildDevice.createCyberLinkDevice(dn.getReference());
if (d != null) {
if (!bindInvokes(d, rootDevice)) {
Activator.logger.DEBUG("Unable to find all the sub device or to set action listener");
continue;
}
ServiceRegistration listenReg = bindSubscribe(d);
if (listenReg == null) {
Activator.logger.DEBUG("Unable to set action listener event listener");
continue;
}
// makeIcons(r.getRootDevice(),xml.getAbsolutePath());
d.start();
exportedDevices.put(rootDevice.getProperty(UPnPDevice.UDN), new ExportedDeviceInfo(d, listenReg, dn));
}
}
}
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class MyCtrlPoint method findDevice.
public Device findDevice(String udn, Device dev) {
/*
* look for the device if it exist, starting from the root on
* cyberlink struct
*/
DeviceList devList = dev.getDeviceList();
Device aux = null;
for (int i = 0; i < devList.size(); i++) {
if (devList.getDevice(i).getUDN().equals(udn)) {
return devList.getDevice(i);
} else {
if ((aux = findDevice(udn, devList.getDevice(i))) != null)
return aux;
}
}
return null;
}
use of org.cybergarage.upnp.Device in project felix by apache.
the class DeviceSetup method deviceSetup.
public static void deviceSetup(Dictionary properties, Device dev, Vector icons, Hashtable services) {
// TODO if I don't have any device, the size of devlist is 0
DeviceList devList = dev.getDeviceList();
/* childrenUDN property */
if (devList.size() > 0) {
String[] childrenUDN = new String[devList.size()];
for (int i = 0; i < devList.size(); i++) {
childrenUDN[i] = devList.getDevice(i).getUDN();
}
properties.put(UPnPDevice.CHILDREN_UDN, childrenUDN);
}
/* DEVICE CATEGORY */
properties.put(org.osgi.service.device.Constants.DEVICE_CATEGORY, new String[] { UPnPDevice.DEVICE_CATEGORY });
/*UPNP_IMPORT*/
properties.put(Constants.UPNP_IMPORT, "http://felix.apache.org");
/* FRIENDLY_NAME */
// check the implementation fo getFriendlyName made by CyberLink
properties.put(UPnPDevice.FRIENDLY_NAME, dev.getFriendlyName());
/* MANUFACTURER */
properties.put(UPnPDevice.MANUFACTURER, dev.getManufacture());
/* MANUFACTURER_URL */
properties.put(UPnPDevice.MANUFACTURER_URL, dev.getManufactureURL());
/* MODEL_DESCRIPTION */
properties.put(UPnPDevice.MODEL_DESCRIPTION, dev.getModelDescription());
/* MODEL_NAME */
properties.put(UPnPDevice.MODEL_NAME, dev.getModelName());
/* MODEL_NUMBER */
properties.put(UPnPDevice.MODEL_NUMBER, dev.getModelNumber());
/* MODEL_URL */
properties.put(UPnPDevice.MODEL_URL, dev.getModelURL());
/* PARENT_UDN */
if (!dev.isRootDevice()) {
Device parent = dev.getParentDevice();
/*Device root = dev.getRootDevice();
if (root == null) {
System.out.println("il device " + dev.getFriendlyName()
+ "non ha root !!!");
}*/
properties.put(UPnPDevice.PARENT_UDN, parent.getUDN());
}
/* PRESENTATION_URL */
properties.put(UPnPDevice.PRESENTATION_URL, dev.getPresentationURL());
/* SERIAL_NUMBER */
properties.put(UPnPDevice.SERIAL_NUMBER, dev.getSerialNumber());
/* TYPE */
properties.put(UPnPDevice.TYPE, dev.getDeviceType());
/* UDN */
properties.put(UPnPDevice.UDN, dev.getUDN());
/* UPC */
properties.put(UPnPDevice.UPC, dev.getUPC());
IconList iconsList = dev.getIconList();
if (iconsList.size() != 0) {
for (int i = 0; i < iconsList.size(); i++) {
UPnPIcon icon = new UPnPIconImpl(iconsList.getIcon(i), dev);
icons.add(icon);
}
}
/*
* service of this device
*/
ServiceList serviceList = dev.getServiceList();
/*
* if dev contain no service I'll get an empty SserviceList object
*/
String[] servicesIDProperty = new String[serviceList.size()];
String[] servicesTypeProperty;
HashSet serTypeSet = new HashSet();
for (int i = 0; i < serviceList.size(); i++) {
Service service = serviceList.getService(i);
UPnPServiceImpl serviceImpl = new UPnPServiceImpl(service);
services.put(service.getServiceID(), serviceImpl);
servicesIDProperty[i] = serviceImpl.getId();
serTypeSet.add(serviceImpl.getType());
}
servicesTypeProperty = new String[serTypeSet.size()];
Iterator iter = serTypeSet.iterator();
int i = 0;
while (iter.hasNext()) {
servicesTypeProperty[i] = (String) iter.next();
i++;
}
properties.put(UPnPService.ID, servicesIDProperty);
properties.put(UPnPService.TYPE, servicesTypeProperty);
}
use of org.cybergarage.upnp.Device in project i2p.i2p by i2p.
the class UPnP method listSubDev.
private void listSubDev(String prefix, Device dev, StringBuilder sb) {
if (prefix == null)
sb.append("<p>").append(_t("Found Device")).append(": ");
else
sb.append("<li>").append(_t("Subdevice")).append(": ");
sb.append(DataHelper.escapeHTML(dev.getFriendlyName()));
if (prefix == null) {
String ip = getIP(dev);
if (ip != null)
sb.append("<br>IP: ").append(ip);
String udn = dev.getUDN();
if (udn != null)
sb.append("<br>UDN: ").append(DataHelper.escapeHTML(udn));
}
sb.append("</p>");
listSubServices(dev, sb);
DeviceList dl = dev.getDeviceList();
if (dl.isEmpty())
return;
sb.append("<ul>\n");
for (int j = 0; j < dl.size(); j++) {
Device subDev = dl.getDevice(j);
if (subDev == null)
continue;
listSubDev(dev.getFriendlyName(), subDev, sb);
}
sb.append("</ul>\n");
}
use of org.cybergarage.upnp.Device in project i2p.i2p by i2p.
the class UPnP method renderStatusHTML.
/**
* warning - slow
*/
public String renderStatusHTML() {
final StringBuilder sb = new StringBuilder();
sb.append("<h3 id=\"upnp\">").append(_t("UPnP Status")).append("</h3><div id=\"upnpscan\">");
synchronized (_otherUDNs) {
if (!_otherUDNs.isEmpty()) {
sb.append(_t("Disabled UPnP Devices"));
sb.append("<ul>");
for (Map.Entry<String, String> e : _otherUDNs.entrySet()) {
String udn = e.getKey();
String name = e.getValue();
sb.append("<li>").append(DataHelper.escapeHTML(name));
sb.append("<br>UDN: ").append(DataHelper.escapeHTML(udn)).append("</li>");
}
sb.append("</ul>");
}
}
if (isDisabled) {
sb.append("<p>");
sb.append(_t("UPnP has been disabled; Do you have more than one UPnP Internet Gateway Device on your LAN ?"));
return sb.toString();
} else if (!isNATPresent()) {
sb.append("<p>");
sb.append(_t("UPnP has not found any UPnP-aware, compatible device on your LAN."));
return sb.toString();
}
Device router;
synchronized (lock) {
router = _router;
}
if (router != null)
listSubDev(null, router, sb);
String addr = getNATAddress();
sb.append("<p>");
if (addr != null)
sb.append(_t("The current external IP address reported by UPnP is {0}", DataHelper.escapeHTML(addr)));
else
sb.append(_t("The current external IP address is not available."));
int downstreamMaxBitRate = getDownstreamMaxBitRate();
int upstreamMaxBitRate = getUpstreamMaxBitRate();
if (downstreamMaxBitRate > 0)
sb.append("<br>").append(_t("UPnP reports the maximum downstream bit rate is {0}bits/sec", DataHelper.formatSize2Decimal(downstreamMaxBitRate)));
if (upstreamMaxBitRate > 0)
sb.append("<br>").append(_t("UPnP reports the maximum upstream bit rate is {0}bits/sec", DataHelper.formatSize2Decimal(upstreamMaxBitRate)));
synchronized (lock) {
for (ForwardPort port : portsToForward) {
sb.append("<br>");
if (portsForwarded.contains(port))
// {0} is TCP or UDP
// {1,number,#####} prevents 12345 from being output as 12,345 in the English locale.
// If you want the digit separator in your locale, translate as {1}.
sb.append(_t("{0} port {1,number,#####} was successfully forwarded by UPnP.", protoToString(port.protocol), port.portNumber));
else
sb.append(_t("{0} port {1,number,#####} was not forwarded by UPnP.", protoToString(port.protocol), port.portNumber));
}
}
sb.append("</p></div>");
return sb.toString();
}
Aggregations