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);
}
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;
}
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);
}
}
Aggregations