Search in sources :

Example 1 with UPnPIcon

use of org.osgi.service.upnp.UPnPIcon 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 2 with UPnPIcon

use of org.osgi.service.upnp.UPnPIcon in project felix by apache.

the class ControlServlet method fillCache.

private final void fillCache() {
    final ServiceReference[] refs = tracker.getServiceReferences();
    for (int i = 0; i < refs.length; i++) {
        final ServiceReference ref = refs[i];
        final Object udn = ref.getProperty(UPnPDevice.UDN);
        if (icons.containsKey(udn)) {
            continue;
        }
        final UPnPDevice device = (UPnPDevice) bc.getService(ref);
        UPnPIcon icon = null;
        try {
            // Fix for FELIX-4012
            UPnPIcon[] _icons = device == null ? null : device.getIcons(null);
            icon = _icons != null && _icons.length > 0 ? _icons[0] : null;
        } catch (IllegalStateException e) {
        // since OSGi r4.3 ignore it
        }
        icons.put(udn, icon);
        devices.put(udn, device);
    }
}
Also used : UPnPIcon(org.osgi.service.upnp.UPnPIcon) UPnPDevice(org.osgi.service.upnp.UPnPDevice) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with UPnPIcon

use of org.osgi.service.upnp.UPnPIcon in project felix by apache.

the class ControlServlet method doGet.

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
@Override
protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // $NON-NLS-1$
    String udn = request.getParameter("icon");
    if (udn != null) {
        UPnPIcon icon = getIcon(udn);
        if (icon == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } else {
            if (// $NON-NLS-1$
            request.getDateHeader("If-Modified-Since") > 0) {
                // if it is already in cache - don't bother to go further
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            } else {
                // enable caching
                // $NON-NLS-1$
                response.setDateHeader("Last-Modified", LAST_MODIFIED);
                InputStream in = icon.getInputStream();
                if (null == in) {
                    // this is buggy implementations
                    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
                    return;
                }
                String mime = icon.getMimeType();
                if (mime != null)
                    response.setContentType(mime);
                OutputStream out = response.getOutputStream();
                int size = icon.getSize();
                if (size > 0)
                    response.setContentLength(size);
                // can't use buffer, because it's might block if reading byte[]
                int read;
                while (-1 != (read = in.read())) out.write(read);
            }
        }
    }
}
Also used : UPnPIcon(org.osgi.service.upnp.UPnPIcon) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream)

Aggregations

UPnPIcon (org.osgi.service.upnp.UPnPIcon)3 UPnPDevice (org.osgi.service.upnp.UPnPDevice)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 UPnPIconImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPIconImpl)1 UPnPServiceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl)1 Device (org.cybergarage.upnp.Device)1 DeviceList (org.cybergarage.upnp.DeviceList)1 IconList (org.cybergarage.upnp.IconList)1 Service (org.cybergarage.upnp.Service)1 ServiceList (org.cybergarage.upnp.ServiceList)1 ServiceReference (org.osgi.framework.ServiceReference)1 UPnPService (org.osgi.service.upnp.UPnPService)1