Search in sources :

Example 6 with UPnPService

use of org.osgi.service.upnp.UPnPService in project felix by apache.

the class GeneralActionListener method actionControlReceived.

/**
 * @see org.cybergarage.upnp.control.ActionListener#actionControlReceived(org.cybergarage.upnp.Action)
 */
public synchronized boolean actionControlReceived(Action upnpAct) {
    if (!open)
        return false;
    UPnPService osgiServ = null;
    try {
        osgiServ = ((UPnPDevice) Activator.bc.getService(dev)).getService(id);
    } catch (Exception ignored) {
    }
    if (osgiServ == null)
        return exiting(false);
    UPnPAction osgiAct = osgiServ.getAction(upnpAct.getName());
    Properties inArgs = null;
    ArgumentList alIn = upnpAct.getInputArgumentList();
    ArgumentList alOut = upnpAct.getOutputArgumentList();
    String[] inArg = osgiAct.getInputArgumentNames();
    boolean invalidAction = false;
    if (inArg != null) {
        inArgs = new Properties();
        Argument arg;
        for (int j = 0; j < inArg.length; j++) {
            arg = alIn.getArgument(inArg[j]);
            try {
                inArgs.put(inArg[j], Converter.parseString(arg.getValue(), arg.getRelatedStateVariable().getDataType()));
            } catch (Exception e) {
                invalidAction = true;
                break;
            }
        }
    }
    Dictionary outArgs = null;
    try {
        outArgs = osgiAct.invoke(inArgs);
    } catch (UPnPException e) {
        // TODO Activator.logger.log()
        upnpAct.setStatus(e.getUPnPError_Code(), e.getMessage());
        invalidAction = true;
    } catch (Exception e) {
        // TODO Activator.logger.log()
        upnpAct.setStatus(UPnPStatus.ACTION_FAILED);
        invalidAction = true;
    }
    if (invalidAction)
        return exiting(false);
    String[] outArg = osgiAct.getOutputArgumentNames();
    if (outArg != null) {
        Argument arg;
        for (int j = 0; j < outArg.length; j++) {
            arg = alOut.getArgument(outArg[j]);
            try {
                arg.setValue(Converter.toString(outArgs.get(outArg[j]), arg.getRelatedStateVariable().getDataType()));
            } catch (Exception e) {
                e.printStackTrace();
                return exiting(false);
            }
        }
    }
    return exiting(true);
}
Also used : Dictionary(java.util.Dictionary) Argument(org.cybergarage.upnp.Argument) UPnPService(org.osgi.service.upnp.UPnPService) Properties(java.util.Properties) ArgumentList(org.cybergarage.upnp.ArgumentList) UPnPException(org.osgi.service.upnp.UPnPException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UPnPException(org.osgi.service.upnp.UPnPException) UPnPAction(org.osgi.service.upnp.UPnPAction)

Example 7 with UPnPService

use of org.osgi.service.upnp.UPnPService 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 8 with UPnPService

use of org.osgi.service.upnp.UPnPService in project felix by apache.

the class TreePopup method doNodeAction.

private void doNodeAction(UPnPDeviceTreeNode node) {
    if (node == null) {
        clearPropertiesViewer();
        return;
    }
    if (node.category.equals(UPnPDeviceTreeNode.ACTION))
        Mediator.getPropertiesViewer().showActionPanel(true);
    else
        Mediator.getPropertiesViewer().showActionPanel(false);
    if (node.category.equals(UPnPDeviceTreeNode.SERVICE))
        Mediator.getPropertiesViewer().showSubscriptionPanel(true);
    else
        Mediator.getPropertiesViewer().showSubscriptionPanel(false);
    if (node.category.equals(UPnPDeviceTreeNode.DEVICE) || node.category.equals(UPnPDeviceTreeNode.ROOT_DEVICE)) {
        DeviceNode device = (DeviceNode) node.getUserObject();
        UPnPDevice upnpDevice = device.getDevice(Activator.context);
        makeProperties(upnpDevice);
    } else if (node.category.equals(UPnPDeviceTreeNode.SERVICE)) {
        UPnPService service = (UPnPService) node.getUserObject();
        makeProperties(service);
    } else if (node.category.equals(UPnPDeviceTreeNode.ACTION)) {
        UPnPAction action = (UPnPAction) node.getUserObject();
        makeProperties(action);
        Mediator.getPropertiesViewer().setAction(action);
    } else if (node.category.equals(UPnPDeviceTreeNode.STATE) || node.category.equals(UPnPDeviceTreeNode.EVENTED_STATE) || node.category.equals(UPnPDeviceTreeNode.SUBSCRIBED_STATE)) {
        UPnPStateVariable state = (UPnPStateVariable) node.getUserObject();
        makeProperties(state);
    }
}
Also used : DeviceNode(org.apache.felix.upnp.tester.discovery.DeviceNode) UPnPDevice(org.osgi.service.upnp.UPnPDevice) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable) UPnPService(org.osgi.service.upnp.UPnPService) UPnPAction(org.osgi.service.upnp.UPnPAction)

Aggregations

UPnPService (org.osgi.service.upnp.UPnPService)8 UPnPDevice (org.osgi.service.upnp.UPnPDevice)5 UPnPAction (org.osgi.service.upnp.UPnPAction)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 UPnPStateVariable (org.osgi.service.upnp.UPnPStateVariable)3 Dictionary (java.util.Dictionary)2 Enumeration (java.util.Enumeration)2 UPnPServiceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl)2 Argument (org.cybergarage.upnp.Argument)2 ArgumentList (org.cybergarage.upnp.ArgumentList)2 ControlPoint (org.cybergarage.upnp.ControlPoint)2 Service (org.cybergarage.upnp.Service)2 ServiceReference (org.osgi.framework.ServiceReference)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Properties (java.util.Properties)1 Vector (java.util.Vector)1