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