Search in sources :

Example 11 with UPnPDevice

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

Example 12 with UPnPDevice

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;
}
Also used : ArrayList(java.util.ArrayList) UPnPDevice(org.osgi.service.upnp.UPnPDevice)

Example 13 with UPnPDevice

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);
    }
}
Also used : UPnPIcon(org.osgi.service.upnp.UPnPIcon) UPnPDevice(org.osgi.service.upnp.UPnPDevice) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

UPnPDevice (org.osgi.service.upnp.UPnPDevice)13 UPnPService (org.osgi.service.upnp.UPnPService)6 ServiceReference (org.osgi.framework.ServiceReference)5 ControlPoint (org.cybergarage.upnp.ControlPoint)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 Dictionary (java.util.Dictionary)3 Service (org.cybergarage.upnp.Service)3 UPnPStateVariable (org.osgi.service.upnp.UPnPStateVariable)3 Vector (java.util.Vector)2 UPnPDeviceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPDeviceImpl)2 UPnPServiceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl)2 ParseUSN (org.apache.felix.upnp.basedriver.importer.util.ParseUSN)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 UPnPAction (org.osgi.service.upnp.UPnPAction)2 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 FirstMessage (org.apache.felix.upnp.basedriver.importer.core.event.message.FirstMessage)1 ListenerModified (org.apache.felix.upnp.basedriver.importer.core.event.message.ListenerModified)1