use of org.osgi.service.upnp.UPnPDevice 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);
}
}
use of org.osgi.service.upnp.UPnPDevice in project felix by apache.
the class ControlServlet method deviceTreeToJSON.
private final Map<String, Object> deviceTreeToJSON(ServiceReference ref) {
final UPnPDevice device = (UPnPDevice) tracker.getService(ref);
if (null == device) {
// the device is dynamically removed
return null;
}
final Object parentUdn = ref.getProperty(UPnPDevice.UDN);
if (parentUdn == null) {
plugin.log(LogService.LOG_ERROR, "Invalid device, no UDN property specified for " + device);
return null;
}
final Map<String, Object> json = Serializer.deviceToJSON(ref, device);
// add child devices
final Object[] refs = tracker.getServiceReferences();
if (refs != null) {
List<Object> children = new ArrayList<Object>();
// $NON-NLS-1$
json.put("children", children);
for (int i = 0; i < refs.length; i++) {
ref = (ServiceReference) refs[i];
final Object parent = ref.getProperty(UPnPDevice.PARENT_UDN);
final Object currentUDN = ref.getProperty(UPnPDevice.UDN);
if (parent == null) {
// no parent
continue;
} else if (currentUDN != null && currentUDN.equals(parent)) {
// self ?
continue;
} else if (parentUdn.equals(parent)) {
Map<String, Object> deviceJSON = deviceTreeToJSON(ref);
if (null != deviceJSON) {
children.add(deviceJSON);
}
}
}
}
return json;
}
use of org.osgi.service.upnp.UPnPDevice in project felix by apache.
the class ControlServlet method fillCache.
private final void fillCache() {
final ServiceReference[] refs = tracker.getServiceReferences();
for (int i = 0; i < refs.length; i++) {
final ServiceReference ref = refs[i];
final Object udn = ref.getProperty(UPnPDevice.UDN);
if (icons.containsKey(udn)) {
continue;
}
final UPnPDevice device = (UPnPDevice) bc.getService(ref);
UPnPIcon icon = null;
try {
// Fix for FELIX-4012
UPnPIcon[] _icons = device == null ? null : device.getIcons(null);
icon = _icons != null && _icons.length > 0 ? _icons[0] : null;
} catch (IllegalStateException e) {
// since OSGi r4.3 ignore it
}
icons.put(udn, icon);
devices.put(udn, device);
}
}
Aggregations