Search in sources :

Example 1 with AllowedValueList

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

the class BuildDevice method addServices.

/**
 * Method used to create a new Service in CyberLink world without creating the XML
 *
 * @param id ServiceId
 * @param devUPnP the CyberLink device that where the new Service will be created
 * @param sr ServiceReference to OSGi Device that used as source of the information
 *              for the creation of the device
 */
private static void addServices(String id, Device devUPnP, ServiceReference sr) {
    UPnPDevice devOSGi = (UPnPDevice) Activator.bc.getService(sr);
    if (devOSGi == null) {
        // added by twa to prevent a null pointer exception
        Activator.logger.WARNING("UPnP Device that cotains serviceId=" + id + " is deregistered from the framework while is exported");
        return;
    }
    UPnPService[] services = devOSGi.getServices();
    if (services == null || services.length == 0)
        return;
    for (int i = 0; i < services.length; i++) {
        Service ser = new Service();
        devUPnP.addService(ser);
        ser.setServiceType(services[i].getType());
        ser.setServiceID(services[i].getId());
        ser.setSCPDURL(id + "/service/" + i + "/gen-desc.xml");
        ser.setDescriptionURL(id + "/service/" + i + "/gen-desc.xml");
        ser.setControlURL(id + "/service/" + i + "/ctrl");
        ser.setEventSubURL(id + "/service/" + i + "/event");
        UPnPAction[] actions = services[i].getActions();
        for (int j = 0; j < actions.length; j++) {
            boolean valid = true;
            Action act = new Action(ser.getServiceNode());
            act.setName(actions[j].getName());
            ArgumentList al = new ArgumentList();
            String[] names = actions[j].getInputArgumentNames();
            if (names != null) {
                for (int k = 0; k < names.length; k++) {
                    UPnPStateVariable variable = actions[j].getStateVariable(names[k]);
                    if (variable == null) {
                        /*
                             * //TODO Create a stict and relaxed behavior of the base driver which 
                             * export as much it can or export only 100% complaint UPnPDevice service 
                             */
                        Activator.logger.WARNING("UPnP Device that cotains serviceId=" + id + " contains the action " + actions[j].getName() + " with the Input argument " + names[k] + " not related to any UPnPStateVariable. Thus this action won't be exported");
                        valid = false;
                        break;
                    }
                    Argument a = new Argument();
                    a.setDirection(Argument.IN);
                    a.setName(names[k]);
                    a.setRelatedStateVariableName(variable.getName());
                    al.add(a);
                }
            }
            names = actions[j].getOutputArgumentNames();
            if (names != null && valid) {
                for (int k = 0; k < names.length; k++) {
                    UPnPStateVariable variable = actions[j].getStateVariable(names[k]);
                    if (variable == null) {
                        /*
                             * //TODO Create a stict and relaxed behavior of the base driver which 
                             * export as much it can or export only 100% complaint UPnPDevice service 
                             */
                        Activator.logger.WARNING("UPnP Device that cotains serviceId=" + id + " contains the action " + actions[j].getName() + " with the Output argument " + names[k] + " not related to any UPnPStateVariable. Thus this action won't be exported");
                    }
                    Argument a = new Argument();
                    a.setDirection(Argument.OUT);
                    a.setName(names[k]);
                    a.setRelatedStateVariableName(variable.getName());
                    al.add(a);
                }
            }
            if (valid) {
                act.setArgumentList(al);
                ser.addAction(act);
            }
        }
        UPnPStateVariable[] vars = services[i].getStateVariables();
        for (int j = 0; j < vars.length; j++) {
            StateVariable var = new StateVariable();
            var.setDataType(vars[j].getUPnPDataType());
            var.setName(vars[j].getName());
            var.setSendEvents(vars[j].sendsEvents());
            String[] values = vars[j].getAllowedValues();
            if (values != null) {
                AllowedValueList avl = new AllowedValueList(values);
                var.setAllowedValueList(avl);
            } else if (vars[j].getMaximum() != null) {
                AllowedValueRange avr = new AllowedValueRange(vars[j].getMaximum(), vars[j].getMinimum(), vars[j].getStep());
                var.setAllowedValueRange(avr);
            }
            if (vars[j].getDefaultValue() != null)
                try {
                    var.setDefaultValue(Converter.toString(vars[j].getDefaultValue(), vars[j].getUPnPDataType()));
                } catch (Exception ignored) {
                }
            ser.addStateVariable(var);
        }
        Activator.bc.ungetService(sr);
    }
}
Also used : UPnPAction(org.osgi.service.upnp.UPnPAction) Action(org.cybergarage.upnp.Action) AllowedValueList(org.cybergarage.upnp.AllowedValueList) AllowedValueRange(org.cybergarage.upnp.AllowedValueRange) Argument(org.cybergarage.upnp.Argument) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable) StateVariable(org.cybergarage.upnp.StateVariable) UPnPService(org.osgi.service.upnp.UPnPService) Service(org.cybergarage.upnp.Service) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable) ArgumentList(org.cybergarage.upnp.ArgumentList) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UPnPDevice(org.osgi.service.upnp.UPnPDevice) UPnPService(org.osgi.service.upnp.UPnPService) UPnPAction(org.osgi.service.upnp.UPnPAction)

Example 2 with AllowedValueList

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

the class UPnPStateVariableImpl method initValueConstraint.

/**
 * <b>NOTE:</b>  This type of control caches the value recieved by the Device so if XML changes it doesn't affect the OSGi service
 *
 * @since 0.3
 */
private void initValueConstraint() {
    if (hasRangeValues != null || hasMaxMinStep != null)
        return;
    hasRangeValues = Boolean.FALSE;
    hasMaxMinStep = Boolean.FALSE;
    final AllowedValueRange allowedValueRange = variable.getAllowedValueRange();
    final AllowedValueList allowedValueList = variable.getAllowedValueList();
    if (allowedValueRange != null && allowedValueList != null) {
        Activator.logger.WARNING("Imported device with StateVariable " + variable.getName() + " contains either AllowedValueRange and AllowedValueList UPnP doesn't allow it because it. Neither of the restriction will be applied");
    } else if (allowedValueRange != null) {
        initMaxMinStep(allowedValueRange);
    } else if (allowedValueList != null) {
        initAllowedValues(allowedValueList);
    }
}
Also used : AllowedValueRange(org.cybergarage.upnp.AllowedValueRange) AllowedValueList(org.cybergarage.upnp.AllowedValueList)

Aggregations

AllowedValueList (org.cybergarage.upnp.AllowedValueList)2 AllowedValueRange (org.cybergarage.upnp.AllowedValueRange)2 Action (org.cybergarage.upnp.Action)1 Argument (org.cybergarage.upnp.Argument)1 ArgumentList (org.cybergarage.upnp.ArgumentList)1 Service (org.cybergarage.upnp.Service)1 StateVariable (org.cybergarage.upnp.StateVariable)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 UPnPAction (org.osgi.service.upnp.UPnPAction)1 UPnPDevice (org.osgi.service.upnp.UPnPDevice)1 UPnPService (org.osgi.service.upnp.UPnPService)1 UPnPStateVariable (org.osgi.service.upnp.UPnPStateVariable)1