Search in sources :

Example 6 with DeviceList

use of org.cybergarage.upnp.DeviceList 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;
}
Also used : UPnPDevice(org.osgi.service.upnp.UPnPDevice) Device(org.cybergarage.upnp.Device) DeviceList(org.cybergarage.upnp.DeviceList) ControlPoint(org.cybergarage.upnp.ControlPoint)

Example 7 with DeviceList

use of org.cybergarage.upnp.DeviceList 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);
}
Also used : UPnPIcon(org.osgi.service.upnp.UPnPIcon) UPnPDevice(org.osgi.service.upnp.UPnPDevice) Device(org.cybergarage.upnp.Device) ServiceList(org.cybergarage.upnp.ServiceList) UPnPIconImpl(org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPIconImpl) UPnPService(org.osgi.service.upnp.UPnPService) Service(org.cybergarage.upnp.Service) DeviceList(org.cybergarage.upnp.DeviceList) IconList(org.cybergarage.upnp.IconList) UPnPServiceImpl(org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 8 with DeviceList

use of org.cybergarage.upnp.DeviceList 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");
}
Also used : Device(org.cybergarage.upnp.Device) DeviceList(org.cybergarage.upnp.DeviceList) ControlPoint(org.cybergarage.upnp.ControlPoint)

Example 9 with DeviceList

use of org.cybergarage.upnp.DeviceList in project i2p.i2p by i2p.

the class UPnP method discoverService.

/**
 * Traverses the structure of the router device looking for the port mapping service.
 */
private void discoverService() {
    synchronized (lock) {
        for (Device current : _router.getDeviceList()) {
            String type = current.getDeviceType();
            if (!(WAN_DEVICE.equals(type) || WAN_DEVICE_2.equals(type)))
                continue;
            DeviceList l = current.getDeviceList();
            for (int i = 0; i < current.getDeviceList().size(); i++) {
                Device current2 = l.getDevice(i);
                type = current2.getDeviceType();
                if (!(WANCON_DEVICE.equals(type) || WANCON_DEVICE_2.equals(type)))
                    continue;
                _service = current2.getService(WAN_IP_CONNECTION_2);
                if (_service == null) {
                    _service = current2.getService(WAN_IP_CONNECTION);
                    if (_service == null) {
                        _service = current2.getService(WAN_PPP_CONNECTION);
                        if (_service == null) {
                            if (_log.shouldWarn())
                                _log.warn(_router.getFriendlyName() + " doesn't have any recognized connection type; we won't be able to use it!");
                        }
                    }
                }
                if (_log.shouldWarn()) {
                    Service svc2 = current2.getService(WAN_IPV6_CONNECTION);
                    if (svc2 != null)
                        _log.warn(_router.getFriendlyName() + " supports WANIPv6Connection, but we don't");
                }
                _serviceLacksAPM = false;
                return;
            }
        }
    }
}
Also used : Device(org.cybergarage.upnp.Device) Service(org.cybergarage.upnp.Service) DeviceList(org.cybergarage.upnp.DeviceList) ControlPoint(org.cybergarage.upnp.ControlPoint)

Aggregations

Device (org.cybergarage.upnp.Device)9 DeviceList (org.cybergarage.upnp.DeviceList)9 ControlPoint (org.cybergarage.upnp.ControlPoint)6 UPnPDevice (org.osgi.service.upnp.UPnPDevice)6 Properties (java.util.Properties)2 Service (org.cybergarage.upnp.Service)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 I2PAppContext (net.i2p.I2PAppContext)1 UPnPIconImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPIconImpl)1 UPnPServiceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl)1 IconList (org.cybergarage.upnp.IconList)1 ServiceList (org.cybergarage.upnp.ServiceList)1 Filter (org.osgi.framework.Filter)1 ServiceReference (org.osgi.framework.ServiceReference)1 UPnPEventListener (org.osgi.service.upnp.UPnPEventListener)1 UPnPIcon (org.osgi.service.upnp.UPnPIcon)1 UPnPService (org.osgi.service.upnp.UPnPService)1