Search in sources :

Example 1 with ServiceList

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

the class ThreadExporter method bindInvoke.

/**
 * This method do the real connection between OSGi UPnP Service action and
 * CyberLink UPnP Device action
 *
 * @param upnpDev the CyberLink UPnP Device object that will be connected
 * @param osgiDev the ServiceReference to OSGi UPnP Service that will be connected to
 * 		CyberLink UPnP as implementation of the Action
 * @return true if and only if the binding off all the action is done succesfully
 */
private boolean bindInvoke(Device upnpDev, ServiceReference osgiDev) {
    ServiceList sl = upnpDev.getServiceList();
    int l = sl.size();
    for (int i = 0; i < l; i++) {
        sl.getService(i).setActionListener(new GeneralActionListener(osgiDev, sl.getService(i).getServiceID()));
    }
    return true;
}
Also used : ServiceList(org.cybergarage.upnp.ServiceList)

Example 2 with ServiceList

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

Example 3 with ServiceList

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

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

the class UPnP method listSubServices.

// TODO: extend it! RTFM
private void listSubServices(Device dev, StringBuilder sb) {
    ServiceList sl = dev.getServiceList();
    if (sl.isEmpty())
        return;
    sb.append("<ul>\n");
    for (int i = 0; i < sl.size(); i++) {
        Service serv = sl.getService(i);
        if (serv == null)
            continue;
        sb.append("<li>").append(_t("Service")).append(": ");
        // NOTE: Group all toString() of common actions together
        // to avoid excess fetches, since toString() caches.
        String type = serv.getServiceType();
        if ("urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1".equals(type)) {
            sb.append(_t("WAN Common Interface Configuration"));
            sb.append("<ul><li>").append(_t("Status")).append(": ").append(toString("GetCommonLinkProperties", "NewPhysicalLinkStatus", serv));
            sb.append("<li>").append(_t("Type")).append(": ").append(toString("GetCommonLinkProperties", "NewWANAccessType", serv));
            sb.append("<li>").append(_t("Upstream")).append(": ").append(toLong("GetCommonLinkProperties", "NewLayer1UpstreamMaxBitRate", serv)).append("bps");
            sb.append("<li>").append(_t("Downstream")).append(": ").append(toLong("GetCommonLinkProperties", "NewLayer1DownstreamMaxBitRate", serv)).append("bps");
            if (_context.getBooleanProperty(PROP_ADVANCED)) {
                // don't bother translating
                sb.append("<li>").append("Sent: ").append(toLong("GetTotalBytesSent", "NewTotalBytesSent", serv)).append('B');
                sb.append("<li>").append("Received: ").append(toLong("GetTotalBytesReceived", "NewTotalBytesReceived", serv)).append('B');
                sb.append("<li>").append("Sent packets: ").append(toLong("GetTotalPacketsSent", "NewTotalPacketsSent", serv));
                sb.append("<li>").append("Received packets: ").append(toLong("GetTotalPacketsReceived", "NewTotalPacketsReceived", serv));
            }
        } else if (WAN_PPP_CONNECTION.equals(type)) {
            sb.append(_t("WAN PPP Connection"));
            sb.append("<ul><li>").append(_t("Status")).append(": ").append(toString("GetStatusInfo", "NewConnectionStatus", serv));
            sb.append("<li>").append(_t("Uptime")).append(": ").append(toTime("GetStatusInfo", "NewUptime", serv));
            sb.append("<li>").append(_t("Type")).append(": ").append(toString("GetConnectionTypeInfo", "NewConnectionType", serv));
            sb.append("<li>").append(_t("Upstream")).append(": ").append(toLong("GetLinkLayerMaxBitRates", "NewUpstreamMaxBitRate", serv)).append("bps");
            sb.append("<li>").append(_t("Downstream")).append(": ").append(toLong("GetLinkLayerMaxBitRates", "NewDownstreamMaxBitRate", serv)).append("bps");
            sb.append("<li>").append(_t("External IP")).append(": ").append(toString("GetExternalIPAddress", "NewExternalIPAddress", serv));
        } else if ("urn:schemas-upnp-org:service:Layer3Forwarding:1".equals(type)) {
            sb.append(_t("Layer 3 Forwarding"));
            sb.append("<ul><li>").append(_t("Default Connection Service")).append(": ").append(toString("GetDefaultConnectionService", "NewDefaultConnectionService", serv));
        } else if (WAN_IP_CONNECTION.equals(type) || WAN_IP_CONNECTION_2.equals(type)) {
            sb.append(_t("WAN IP Connection"));
            sb.append("<ul><li>").append(_t("Status")).append(": ").append(toString("GetStatusInfo", "NewConnectionStatus", serv));
            sb.append("<li>").append(_t("Uptime")).append(": ").append(toTime("GetStatusInfo", "NewUptime", serv));
            String error = toString("GetStatusInfo", "NewLastConnectionError", serv);
            if (error != null && error.length() > 0 && !error.equals("ERROR_NONE"))
                sb.append("<li>").append("Last Error").append(": ").append(error);
            sb.append("<li>").append(_t("Type")).append(": ").append(toString("GetConnectionTypeInfo", "NewConnectionType", serv));
            sb.append("<li>").append(_t("External IP")).append(": ").append(toString("GetExternalIPAddress", "NewExternalIPAddress", serv));
        } else if (WAN_IPV6_CONNECTION.equals(type)) {
            sb.append("WAN IPv6 Connection");
            sb.append("<ul><li>").append("Firewall Enabled").append(": ").append(toBoolean("GetFirewallStatus", "FirewallEnabled", serv));
            sb.append("<li>").append("Pinhole Allowed").append(": ").append(toBoolean("GetFirewallStatus", "InboundPinholeAllowed", serv));
        } else if ("urn:schemas-upnp-org:service:WANEthernetLinkConfig:1".equals(type)) {
            sb.append(_t("WAN Ethernet Link Configuration"));
            sb.append("<ul><li>").append(_t("Status")).append(": ").append(toString("GetEthernetLinkStatus", "NewEthernetLinkStatus", serv));
        } else {
            sb.append(DataHelper.escapeHTML(type)).append("<ul>");
        }
        if (_context.getBooleanProperty(PROP_ADVANCED)) {
            sb.append("<li>Actions");
            listActions(serv, sb);
            sb.append("</li><li>States");
            listStateTable(serv, sb);
            sb.append("</li>");
        }
        sb.append("</ul>\n");
    }
    sb.append("</ul>\n");
}
Also used : ServiceList(org.cybergarage.upnp.ServiceList) Service(org.cybergarage.upnp.Service) ControlPoint(org.cybergarage.upnp.ControlPoint)

Example 5 with ServiceList

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

ServiceList (org.cybergarage.upnp.ServiceList)5 ControlPoint (org.cybergarage.upnp.ControlPoint)3 Service (org.cybergarage.upnp.Service)3 Device (org.cybergarage.upnp.Device)2 UPnPDevice (org.osgi.service.upnp.UPnPDevice)2 UPnPService (org.osgi.service.upnp.UPnPService)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 FirstMessage (org.apache.felix.upnp.basedriver.importer.core.event.message.FirstMessage)1 UPnPDeviceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPDeviceImpl)1 UPnPIconImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPIconImpl)1 UPnPServiceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl)1 DeviceList (org.cybergarage.upnp.DeviceList)1 IconList (org.cybergarage.upnp.IconList)1 ServiceStateTable (org.cybergarage.upnp.ServiceStateTable)1 StateVariable (org.cybergarage.upnp.StateVariable)1 Filter (org.osgi.framework.Filter)1