Search in sources :

Example 6 with UPnPDevice

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

the class ControlServlet method getDevice.

private final UPnPDevice getDevice(String udn) {
    final UPnPDevice device;
    synchronized (cacheLock) {
        fillCache();
        device = (UPnPDevice) devices.get(udn);
    }
    if (null == device) {
        throw new IllegalArgumentException("Device '" + udn + "' not found!");
    }
    return device;
}
Also used : UPnPDevice(org.osgi.service.upnp.UPnPDevice)

Example 7 with UPnPDevice

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

the class ControlServlet method requireService.

private final UPnPService requireService(HttpServletRequest request) throws ServletException {
    // $NON-NLS-1$
    final String deviceUdn = require("udn", request);
    // $NON-NLS-1$
    final String serviceUrn = require("urn", request);
    final UPnPDevice device = getDevice(deviceUdn);
    return getService(device, serviceUrn);
}
Also used : UPnPDevice(org.osgi.service.upnp.UPnPDevice)

Example 8 with UPnPDevice

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

the class MyCtrlPoint method deviceSearchResponseReceived.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.cybergarage.upnp.device.SearchResponseListener#deviceSearchResponseReceived(org.cybergarage.upnp.ssdp.SSDPPacket)
	 */
public void deviceSearchResponseReceived(SSDPPacket ssdpPacket) {
    Activator.logger.DEBUG("[Importer] deviceSearchResponseReceived");
    Activator.logger.PACKET(ssdpPacket.toString());
    String usn = ssdpPacket.getUSN();
    ParseUSN parseUSN = new ParseUSN(usn);
    String udn = parseUSN.getUDN();
    ServiceReference[] refs = null;
    String filter = "(&" + UPNP_DEVICE_FLTR + EXPORT_FLTR + ")";
    try {
        refs = context.getServiceReferences(UPnPDevice.class.getName(), filter);
    } catch (InvalidSyntaxException e) {
        e.printStackTrace();
    }
    if (refs != null) {
        for (int i = 0; i < refs.length; i++) {
            UPnPDevice dev = (UPnPDevice) context.getService(refs[i]);
            Dictionary dic = dev.getDescriptions(null);
            if (((String) dic.get(UPnPDevice.UDN)).equals(udn)) {
                return;
            }
        }
    }
    if (devices.containsKey(udn)) {
        Activator.logger.DEBUG("[Importer] Device already discovered");
        /*
			 * Exist the registered device either in OSGi and 
			 * hashtable of local device
			 */
        if (parseUSN.isService()) {
            doServiceUpdating(udn, parseUSN.getServiceType());
        }
    } else {
        doDeviceRegistration(udn);
    }
}
Also used : Dictionary(java.util.Dictionary) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UPnPDevice(org.osgi.service.upnp.UPnPDevice) ParseUSN(org.apache.felix.upnp.basedriver.importer.util.ParseUSN) ControlPoint(org.cybergarage.upnp.ControlPoint) ServiceReference(org.osgi.framework.ServiceReference)

Example 9 with UPnPDevice

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

the class MyCtrlPoint method registerUPnPDevice.

public void registerUPnPDevice(Device dev, UPnPDeviceImpl upnpDev, Dictionary prop) {
    /*
		 * registering the new Device as OSGi UPnPDevice and then add 
		 * ServiceRegistration and UPnPDevice reference to the hashtable
		 * that contains local devices
		 */
    if (prop == null && upnpDev == null) {
        UPnPDeviceImpl newDevice = new UPnPDeviceImpl(dev, context);
        ServiceRegistration registration = context.registerService(UPnPDevice.class.getName(), newDevice, newDevice.getDescriptions(null));
        OSGiDeviceInfo deviceInfo = new OSGiDeviceInfo(newDevice, registration);
        String udn = (String) ((newDevice.getDescriptions(null)).get(UPnPDevice.UDN));
        devices.put(udn, deviceInfo);
    } else {
        ServiceRegistration registration = context.registerService(UPnPDevice.class.getName(), upnpDev, prop);
        OSGiDeviceInfo deviceInfo = new OSGiDeviceInfo(upnpDev, registration);
        devices.put(upnpDev.getDescriptions(null).get(UPnPDevice.UDN), deviceInfo);
    }
}
Also used : UPnPDevice(org.osgi.service.upnp.UPnPDevice) UPnPDeviceImpl(org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPDeviceImpl) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 10 with UPnPDevice

use of org.osgi.service.upnp.UPnPDevice 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)

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