Search in sources :

Example 11 with Device

use of org.cybergarage.upnp.Device in project felix by apache.

the class BuildDevice method buildDevice.

private static void buildDevice(String id, Device parent, ServiceReference sr) {
    Node dev = new Node(Device.ELEM_NAME);
    DeviceData dd = new DeviceData();
    dd.setDescriptionURI(id + "/gen-desc.xml");
    dev.setUserData(dd);
    Device devUPnP = new Device(dev);
    devUPnP.setDeviceType(extractDeviceType(sr));
    devUPnP.setFriendlyName((String) sr.getProperty(UPnPDevice.FRIENDLY_NAME));
    devUPnP.setManufacture((String) sr.getProperty(UPnPDevice.MANUFACTURER));
    devUPnP.setManufactureURL((String) sr.getProperty(UPnPDevice.MANUFACTURER_URL));
    devUPnP.setModelDescription((String) sr.getProperty(UPnPDevice.MODEL_DESCRIPTION));
    devUPnP.setModelName((String) sr.getProperty(UPnPDevice.MODEL_NAME));
    devUPnP.setModelNumber((String) sr.getProperty(UPnPDevice.MODEL_NUMBER));
    devUPnP.setModelURL((String) sr.getProperty(UPnPDevice.MODEL_URL));
    devUPnP.setSerialNumber((String) sr.getProperty(UPnPDevice.SERIAL_NUMBER));
    devUPnP.setUDN((String) sr.getProperty(UPnPDevice.UDN));
    devUPnP.setUPC((String) sr.getProperty(UPnPDevice.UPC));
    devUPnP.setLocation(id + "/gen-desc.xml");
    addServices(id, devUPnP, sr);
    addDevices(id, devUPnP, sr);
    // twa: essential!!!!!!!
    parent.addDevice(devUPnP);
    devUPnP.setPresentationURL((String) sr.getProperty(UPnPDevice.PRESENTATION_URL));
}
Also used : UPnPDevice(org.osgi.service.upnp.UPnPDevice) Device(org.cybergarage.upnp.Device) Node(org.cybergarage.xml.Node) DeviceData(org.cybergarage.upnp.xml.DeviceData)

Example 12 with Device

use of org.cybergarage.upnp.Device in project felix by apache.

the class BuildDevice method buildRootDeviceNode.

private static Device buildRootDeviceNode(Node root, ServiceReference sr) {
    Node dev = new Node(Device.ELEM_NAME);
    root.addNode(dev);
    DeviceData dd = new DeviceData();
    dd.setDescriptionURI("/gen-desc.xml");
    dev.setUserData(dd);
    Device devUPnP = new Device(root, dev);
    devUPnP.setDeviceType(extractDeviceType(sr));
    devUPnP.setFriendlyName((String) sr.getProperty(UPnPDevice.FRIENDLY_NAME));
    devUPnP.setManufacture((String) sr.getProperty(UPnPDevice.MANUFACTURER));
    devUPnP.setManufactureURL((String) sr.getProperty(UPnPDevice.MANUFACTURER_URL));
    devUPnP.setModelDescription((String) sr.getProperty(UPnPDevice.MODEL_DESCRIPTION));
    devUPnP.setModelName((String) sr.getProperty(UPnPDevice.MODEL_NAME));
    devUPnP.setModelNumber((String) sr.getProperty(UPnPDevice.MODEL_NUMBER));
    devUPnP.setModelURL((String) sr.getProperty(UPnPDevice.MODEL_URL));
    devUPnP.setSerialNumber((String) sr.getProperty(UPnPDevice.SERIAL_NUMBER));
    devUPnP.setUDN((String) sr.getProperty(UPnPDevice.UDN));
    devUPnP.setUPC((String) sr.getProperty(UPnPDevice.UPC));
    devUPnP.setLocation("/gen-desc.xml");
    addServices("", devUPnP, sr);
    addDevices("", devUPnP, sr);
    devUPnP.setPresentationURL((String) sr.getProperty(UPnPDevice.PRESENTATION_URL));
    return devUPnP;
}
Also used : UPnPDevice(org.osgi.service.upnp.UPnPDevice) Device(org.cybergarage.upnp.Device) Node(org.cybergarage.xml.Node) DeviceData(org.cybergarage.upnp.xml.DeviceData)

Example 13 with Device

use of org.cybergarage.upnp.Device in project felix by apache.

the class ExporterUPnPEventListener method notifyUPnPEvent.

/**
 * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String, java.lang.String, java.util.Dictionary)
 */
public void notifyUPnPEvent(String deviceId, String serviceId, Dictionary events) {
    Device dAux = null;
    if (d.getUDN().equals(deviceId)) {
        dAux = d;
    } else {
        dAux = d.getDevice(deviceId);
    }
    Service s = dAux.getService(serviceId);
    // fix 2/9/2004 francesco
    Enumeration e = events.keys();
    while (e.hasMoreElements()) {
        StateVariable sv;
        String dataType;
        String name;
        Object key = e.nextElement();
        if (key instanceof String) {
            name = (String) key;
            sv = s.getStateVariable(name);
            dataType = sv.getDataType();
        } else {
            Activator.logger.ERROR(deviceId + " notified the change in the StateVariable of " + serviceId + " but the key Java type contained in the Dictiories was " + key.getClass().getName() + " instead of " + String.class.getName() + " as specified by Javadoc");
            continue;
        }
        try {
            sv.setValue(Converter.toString(events.get(key), dataType));
        } catch (Exception ignored) {
            Activator.logger.ERROR("UPnP Base Driver Exporter: error converting datatype while sending event, exception message follows:" + ignored.getMessage());
        }
    }
}
Also used : Enumeration(java.util.Enumeration) StateVariable(org.cybergarage.upnp.StateVariable) Device(org.cybergarage.upnp.Device) Service(org.cybergarage.upnp.Service)

Example 14 with Device

use of org.cybergarage.upnp.Device 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)

Example 15 with Device

use of org.cybergarage.upnp.Device in project felix by apache.

the class ThreadExporter method unexportDevice.

/**
 * @param property
 */
private synchronized void unexportDevice(ServiceReference dev) {
    String udn = (String) dev.getProperty(UPnPDevice.PARENT_UDN);
    if (udn == null) {
        ExportedDeviceInfo edi = (ExportedDeviceInfo) exportedDevices.get(dev.getProperty(UPnPDevice.UDN));
        Device d = edi.getDevice();
        if (d != null) {
            Activator.logger.INFO("[Exporter] removing device:" + d.getFriendlyName());
            d.stop();
            exportedDevices.remove(d.getUDN());
        }
        ServiceRegistration srListener = edi.getServiceRegistration();
        if (srListener != null)
            srListener.unregister();
    } else {
        ServiceReference[] servs = null;
        try {
            servs = Activator.bc.getServiceReferences(UPnPDevice.class.getName(), "(" + UPnPDevice.UDN + "=" + udn + ")");
        } catch (InvalidSyntaxException ignored) {
        }
        if (servs == null)
            return;
        this.unexportDevice(servs[0]);
    }
}
Also used : UPnPDevice(org.osgi.service.upnp.UPnPDevice) Device(org.cybergarage.upnp.Device) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceRegistration(org.osgi.framework.ServiceRegistration) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

Device (org.cybergarage.upnp.Device)21 UPnPDevice (org.osgi.service.upnp.UPnPDevice)15 ControlPoint (org.cybergarage.upnp.ControlPoint)10 DeviceList (org.cybergarage.upnp.DeviceList)9 Service (org.cybergarage.upnp.Service)6 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 ServiceRegistration (org.osgi.framework.ServiceRegistration)5 ServiceReference (org.osgi.framework.ServiceReference)4 Node (org.cybergarage.xml.Node)3 UPnPService (org.osgi.service.upnp.UPnPService)3 Enumeration (java.util.Enumeration)2 Properties (java.util.Properties)2 Vector (java.util.Vector)2 UPnPDeviceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPDeviceImpl)2 ServiceList (org.cybergarage.upnp.ServiceList)2 DeviceData (org.cybergarage.upnp.xml.DeviceData)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1