Search in sources :

Example 1 with ServiceStateTable

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

the class MyCtrlPoint method searchForListener.

public void searchForListener(Device device) {
    Activator.logger.DEBUG("[Importer] searching for UPnPEventListener");
    ServiceReference[] listeners = null;
    try {
        listeners = context.getServiceReferences(UPnPEventListener.class.getName(), null);
    } catch (InvalidSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (listeners != null) {
        String deviceID = device.getUDN();
        String serviceID;
        String deviceType = device.getDeviceType();
        String serviceType;
        Hashtable hash = new Hashtable();
        hash.put(UPnPDevice.ID, deviceID);
        hash.put(UPnPDevice.TYPE, deviceType);
        ServiceList services = device.getServiceList();
        Vector eventedSers = new Vector();
        for (int i = 0; i < services.size(); i++) {
            Service service = (Service) services.elementAt(i);
            ServiceStateTable vars = service.getServiceStateTable();
            for (int j = 0; j < vars.size(); j++) {
                StateVariable var = (StateVariable) vars.elementAt(j);
                if (var.isSendEvents()) {
                    eventedSers.add(service);
                    break;
                }
            }
        }
        for (int i = 0; i < listeners.length; i++) {
            UPnPEventListener listener = (UPnPEventListener) context.getService(listeners[i]);
            Filter filter = (Filter) listeners[i].getProperty(UPnPEventListener.UPNP_FILTER);
            if (filter == null) {
                for (int j = 0; j < eventedSers.size(); j++) {
                    Service ser = (Service) eventedSers.elementAt(j);
                    subQueue.enqueue(new FirstMessage(ser, listener));
                }
            } else {
                for (int j = 0; j < eventedSers.size(); j++) {
                    Service ser = (Service) eventedSers.elementAt(j);
                    serviceID = ser.getServiceID();
                    serviceType = ser.getServiceType();
                    hash.put(UPnPService.ID, serviceID);
                    hash.put(UPnPService.TYPE, serviceType);
                    boolean bool = filter.match(hash);
                    if (bool) {
                        subQueue.enqueue(new FirstMessage(ser, listener));
                    }
                }
            }
        }
    }
}
Also used : UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable) StateVariable(org.cybergarage.upnp.StateVariable) Hashtable(java.util.Hashtable) ServiceList(org.cybergarage.upnp.ServiceList) UPnPService(org.osgi.service.upnp.UPnPService) Service(org.cybergarage.upnp.Service) FirstMessage(org.apache.felix.upnp.basedriver.importer.core.event.message.FirstMessage) ServiceStateTable(org.cybergarage.upnp.ServiceStateTable) ControlPoint(org.cybergarage.upnp.ControlPoint) ServiceReference(org.osgi.framework.ServiceReference) Filter(org.osgi.framework.Filter) UPnPEventListener(org.osgi.service.upnp.UPnPEventListener) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Vector(java.util.Vector)

Example 2 with ServiceStateTable

use of org.cybergarage.upnp.ServiceStateTable in project i2p.i2p by i2p.

the class UPnP method listStateTable.

/**
 * debug only
 */
private static void listStateTable(Service serv, StringBuilder sb) {
    ServiceStateTable table;
    try {
        table = serv.getServiceStateTable();
    } catch (RuntimeException e) {
        // getSCPDNode() returns null,
        // NPE at org.cybergarage.upnp.Service.getServiceStateTable(Service.java:526)
        sb.append(" : no state");
        return;
    }
    sb.append("<ul><small>");
    for (int i = 0; i < table.size(); i++) {
        StateVariable current = table.getStateVariable(i);
        sb.append("<li>").append(DataHelper.escapeHTML(current.getName())).append(" : \"").append(DataHelper.escapeHTML(current.getValue())).append("\"</li>");
    }
    sb.append("</small></ul>");
}
Also used : StateVariable(org.cybergarage.upnp.StateVariable) ServiceStateTable(org.cybergarage.upnp.ServiceStateTable) ControlPoint(org.cybergarage.upnp.ControlPoint)

Aggregations

ControlPoint (org.cybergarage.upnp.ControlPoint)2 ServiceStateTable (org.cybergarage.upnp.ServiceStateTable)2 StateVariable (org.cybergarage.upnp.StateVariable)2 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 FirstMessage (org.apache.felix.upnp.basedriver.importer.core.event.message.FirstMessage)1 Service (org.cybergarage.upnp.Service)1 ServiceList (org.cybergarage.upnp.ServiceList)1 Filter (org.osgi.framework.Filter)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1 UPnPEventListener (org.osgi.service.upnp.UPnPEventListener)1 UPnPService (org.osgi.service.upnp.UPnPService)1 UPnPStateVariable (org.osgi.service.upnp.UPnPStateVariable)1