Search in sources :

Example 11 with Service

use of org.cybergarage.upnp.Service 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 12 with Service

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

the class MyCtrlPoint method serviceFromSid.

/*
	   * (non-Javadoc)
	   * 
	   * @see org.cybergarage.upnp.event.EventListener#eventNotifyReceived(java.lang.String,
	   *      long, java.lang.String, java.lang.String)
	   */
/*
	 * public void eventNotifyReceived(String uuid, long seq, String varName,
	 * String value) { // TODO Auto-generated method stub StateChanged msg = new
	 * StateChanged(uuid, varName, value,seq);,serviceFromSid(uuid)
	 * notifierQueue.enqueue(msg); }
	 */
public Service serviceFromSid(String sid) {
    Enumeration e = devices.elements();
    Service cyberService = null;
    while (e.hasMoreElements()) {
        OSGiDeviceInfo deviceinfo = (OSGiDeviceInfo) e.nextElement();
        UPnPDevice device = deviceinfo.getOSGiDevice();
        UPnPService[] services = (UPnPService[]) device.getServices();
        UPnPServiceImpl[] servicesImpl = new UPnPServiceImpl[services.length];
        for (int i = 0; i < servicesImpl.length; i++) {
            servicesImpl[i] = (UPnPServiceImpl) services[i];
        }
        for (int i = 0; i < servicesImpl.length; i++) {
            cyberService = servicesImpl[i].getCyberService();
            boolean bool = cyberService.isSubscribed();
            if (bool) {
                if (cyberService.getSID().equals(sid)) {
                    return cyberService;
                }
            }
        }
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) UPnPServiceImpl(org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl) UPnPService(org.osgi.service.upnp.UPnPService) Service(org.cybergarage.upnp.Service) UPnPDevice(org.osgi.service.upnp.UPnPDevice) UPnPService(org.osgi.service.upnp.UPnPService) ControlPoint(org.cybergarage.upnp.ControlPoint)

Example 13 with Service

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

the class Monitor method unsubscribeListenerForSid.

/**
 * Unregister the listener as UPnPListener for the UPnPService with
 * the spicfied SID
 *
 * @param sid
 * @param listener
 * @param ctrl
 */
private void unsubscribeListenerForSid(String sid, UPnPEventListener listener, MyCtrlPoint ctrl) {
    Vector listeners = sidListSid.getListenersFromSid(sid);
    listeners.remove(listener);
    if (listeners.size() == 0) {
        Service service = ctrl.serviceFromSid(sid);
        if (service != null) {
            boolean ok = ctrl.unsubscribe(service);
            if (!ok) {
                // TODO Log?
                service.clearSID();
            }
        }
        sidListSid.setAlreadyFirst(sid, false);
        sidStateVars.remove(sid);
    }
    Vector sids = sidListSid.getSidsFromListener(listener);
    sids.remove(sid);
    if (sids.size() == 0) {
        sidListSid.removeListenerKey(listener);
    }
}
Also used : Service(org.cybergarage.upnp.Service) Vector(java.util.Vector)

Example 14 with Service

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

the class Monitor method delListener.

/**
 * Delete the reference to the listener from the stuctures sid2Listeners and listener2Sids.
 * Also if no more listner are listening for a UPnP Service that UPnP Service is unscribed.
 *
 * @param listener The listener to delete
 * @param ctrl Needed for reference
 */
public synchronized void delListener(UPnPEventListener listener, MyCtrlPoint ctrl) /*##renew, SidRenewer sidRenewer*/
{
    // francesco-renew
    // State variable clean up -- todo?
    Vector sids = sidListSid.getSidsFromListener(listener);
    if (sids != null) {
        Iterator i = sids.iterator();
        while (i.hasNext()) {
            String sid = (String) i.next();
            Vector listeners = sidListSid.getListenersFromSid(sid);
            listeners.remove(listener);
            if (listeners.size() == 0) {
                Service service = ctrl.serviceFromSid(sid);
                // ##renew  renewer.stop();
                if (service != null) {
                    boolean ok = ctrl.unsubscribe(service);
                    if (!ok) {
                        // TODO Log?s
                        service.clearSID();
                    }
                }
                sidListSid.setAlreadyFirst(sid, false);
                sidStateVars.remove(sid);
                i.remove();
            }
        }
        sidListSid.removeListenerKey(listener);
    }
}
Also used : Iterator(java.util.Iterator) Service(org.cybergarage.upnp.Service) Vector(java.util.Vector)

Example 15 with Service

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

Aggregations

Service (org.cybergarage.upnp.Service)19 ControlPoint (org.cybergarage.upnp.ControlPoint)7 Action (org.cybergarage.upnp.Action)6 Device (org.cybergarage.upnp.Device)6 UPnPService (org.osgi.service.upnp.UPnPService)6 Vector (java.util.Vector)5 UPnPDevice (org.osgi.service.upnp.UPnPDevice)5 Argument (org.cybergarage.upnp.Argument)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 FirstMessage (org.apache.felix.upnp.basedriver.importer.core.event.message.FirstMessage)3 ServiceList (org.cybergarage.upnp.ServiceList)3 StateVariable (org.cybergarage.upnp.StateVariable)3 Enumeration (java.util.Enumeration)2 Hashtable (java.util.Hashtable)2 Iterator (java.util.Iterator)2 UPnPServiceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl)2 DeviceList (org.cybergarage.upnp.DeviceList)2 ServiceReference (org.osgi.framework.ServiceReference)2 UPnPEventListener (org.osgi.service.upnp.UPnPEventListener)2 UPnPStateVariable (org.osgi.service.upnp.UPnPStateVariable)2