Search in sources :

Example 1 with DeviceList

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);
}
Also used : Filter(org.osgi.framework.Filter) UPnPDevice(org.osgi.service.upnp.UPnPDevice) Device(org.cybergarage.upnp.Device) UPnPEventListener(org.osgi.service.upnp.UPnPEventListener) DeviceList(org.cybergarage.upnp.DeviceList) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Properties(java.util.Properties) Vector(java.util.Vector)

Example 2 with DeviceList

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

Example 3 with DeviceList

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

Example 4 with DeviceList

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);
}
Also used : I2PAppContext(net.i2p.I2PAppContext) Device(org.cybergarage.upnp.Device) DeviceList(org.cybergarage.upnp.DeviceList) Properties(java.util.Properties) ControlPoint(org.cybergarage.upnp.ControlPoint)

Example 5 with DeviceList

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

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