Search in sources :

Example 1 with Device

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

the class DriverControllerImpl method getSCPDURL.

public String getSCPDURL(String udn, String serviceId) {
    if (myCtrl == null) {
        logger.WARNING("UPnP Importer is disabled. getSCPDURL() is not available");
        return null;
    }
    if (udn == null || udn.equals(""))
        throw new IllegalArgumentException("Invalid udn paramenter");
    if (serviceId == null || serviceId.equals(""))
        throw new IllegalArgumentException("Invalid serviceId paramenter");
    Device device = myCtrl.getDevice(udn);
    if (device == null) {
        logger.WARNING("getSCPDURL():: No device data available for UDN: " + udn);
        return null;
    }
    Service service = device.getService(serviceId);
    if (service == null) {
        logger.WARNING("getSCPDURL():: No service data available for serviceId:" + serviceId + " of UDN " + udn);
        return null;
    }
    String scpd = service.getSCPDURL().trim();
    return resolveRelativeLink(device, scpd);
}
Also used : Device(org.cybergarage.upnp.Device) Service(org.cybergarage.upnp.Service)

Example 2 with Device

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

the class ThreadExporter method cleanUp.

/**
 */
public synchronized void cleanUp() {
    Activator.logger.INFO("Cleaning...");
    Enumeration keys;
    Activator.logger.INFO("Removing temporary listener....");
    keys = exportedDevices.keys();
    while (keys.hasMoreElements()) {
        ServiceRegistration sr = ((ExportedDeviceInfo) exportedDevices.get(keys.nextElement())).getServiceRegistration();
        sr.unregister();
    }
    Activator.logger.INFO("Done");
    Activator.logger.INFO("Removing device....");
    keys = exportedDevices.keys();
    while (keys.hasMoreElements()) {
        Device dev = ((ExportedDeviceInfo) exportedDevices.get(keys.nextElement())).getDevice();
        dev.stop();
    }
    Activator.logger.INFO("Done");
}
Also used : Enumeration(java.util.Enumeration) UPnPDevice(org.osgi.service.upnp.UPnPDevice) Device(org.cybergarage.upnp.Device) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 3 with Device

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

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

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

the class MyCtrlPoint method doServiceUpdating.

public void doServiceUpdating(String udn, String serviceType) {
    Activator.logger.DEBUG("[Importer] check for service updating");
    OSGiDeviceInfo deviceinfo = (OSGiDeviceInfo) devices.get(udn);
    UPnPDeviceImpl device = deviceinfo.getOSGiDevice();
    boolean isSerPresent = device.existServiceType(serviceType);
    if (!isSerPresent) {
        /*
             * The serivice doesn't exist so it's new.
             * Find the udn of owner device and re-register the owner
             */
        ServiceRegistration registar = ((OSGiDeviceInfo) devices.remove(udn)).getRegistration();
        String[] oldServicesID = (String[]) device.getDescriptions(null).get(UPnPServiceImpl.ID);
        String[] oldServicesType = (String[]) device.getDescriptions(null).get(UPnPServiceImpl.TYPE);
        // to handle multiple instance of a serivice of the same type
        Device cyberDevice = findDeviceCtrl(this, udn);
        ServiceList serviceList = cyberDevice.getServiceList();
        ArrayList newServicesID = new ArrayList();
        for (int i = 0; i < serviceList.size(); i++) {
            if (serviceList.getService(i).getServiceType().equals(serviceType)) {
                newServicesID.add(serviceList.getService(i).getServiceID());
            }
        }
        // adding the new servicesID
        String[] currentServicesID = new String[(oldServicesID.length + newServicesID.size())];
        int endOld = 1;
        for (int i = 0; i < oldServicesID.length; i++) {
            currentServicesID[i] = oldServicesID[i];
            endOld++;
        }
        int j = 0;
        for (; endOld < currentServicesID.length; endOld++) {
            currentServicesID[endOld] = (String) newServicesID.get(j);
            j++;
        }
        // adding the new ServiceType
        String[] currentServicesType = new String[oldServicesType.length + 1];
        for (int i = 0; i < oldServicesType.length; i++) {
            currentServicesType[i] = oldServicesType[i];
        }
        currentServicesType[currentServicesType.length - 1] = serviceType;
        // unregistring the OSGi Device
        // and setting new properties
        unregisterUPnPDevice(registar);
        device.setProperty(UPnPService.ID, currentServicesID);
        device.setProperty(UPnPServiceImpl.TYPE, currentServicesType);
        // registering the service with the updated properties
        // TODO Check if null to the first paramaters is correct or it requires the reference to the cyberdomo upnp device
        registerUPnPDevice(null, device, device.getDescriptions(null));
        searchForListener(cyberDevice);
    }
}
Also used : UPnPDevice(org.osgi.service.upnp.UPnPDevice) Device(org.cybergarage.upnp.Device) ServiceList(org.cybergarage.upnp.ServiceList) ArrayList(java.util.ArrayList) UPnPDeviceImpl(org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPDeviceImpl) ControlPoint(org.cybergarage.upnp.ControlPoint) ServiceRegistration(org.osgi.framework.ServiceRegistration)

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