Changeset 141 for trunk/sonorous
- Timestamp:
- 31/12/09 02:27:54 (7 months ago)
- Location:
- trunk/sonorous/uk.co.matbooth.sonorous/src/uk/co/matbooth/sonorous
- Files:
-
- 4 modified
-
upnp/SubscriptionManager.java (modified) (3 diffs)
-
zones/Zone.java (modified) (5 diffs)
-
zones/ZoneLabelProvider.java (modified) (1 diff)
-
zones/ZoneManager.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sonorous/uk.co.matbooth.sonorous/src/uk/co/matbooth/sonorous/upnp/SubscriptionManager.java
r140 r141 8 8 package uk.co.matbooth.sonorous.upnp; 9 9 10 import java.util.ArrayList; 11 import java.util.Dictionary; 12 import java.util.Enumeration; 10 13 import java.util.HashMap; 14 import java.util.List; 11 15 import java.util.Properties; 12 16 13 17 import org.eclipse.core.runtime.ILog; 14 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.MultiStatus; 15 20 import org.eclipse.core.runtime.Status; 16 21 import org.osgi.framework.BundleContext; … … 73 78 + serviceId + " on " + deviceId)); 74 79 } else { 75 log.log(new Status(IStatus.WARNING, Activator.ID, "No subscription to "76 + serviceId + " on " + deviceId));80 log.log(new Status(IStatus.WARNING, Activator.ID, 81 "No subscription exists to " + serviceId + " on " + deviceId)); 77 82 } 78 83 } 79 84 80 private class Subscription { 85 /** 86 * TODO 87 */ 88 private class Subscription implements UPnPEventListener { 81 89 82 90 private final ServiceRegistration reg; 91 private final UPnPEventListener listener; 83 92 84 public Subscription(BundleContext context, String filter, 85 UPnPEventListener listener)throws Exception {93 public Subscription(BundleContext context, String filter, UPnPEventListener l) 94 throws Exception { 86 95 Properties p = new Properties(); 87 96 p.put(UPnPEventListener.UPNP_FILTER, context.createFilter(filter)); 88 reg = context.registerService(UPnPEventListener.class.getName(), listener, p); 97 listener = l; 98 reg = context.registerService(UPnPEventListener.class.getName(), this, p); 89 99 } 90 100 … … 92 102 reg.unregister(); 93 103 } 104 105 public void notifyUPnPEvent(String deviceId, String serviceId, Dictionary events) { 106 // Log the event before sending it up to the real listener 107 List<IStatus> details = new ArrayList<IStatus>(); 108 for (Enumeration<String> keys = events.keys(); keys.hasMoreElements();) { 109 String key = keys.nextElement(); 110 details.add(new Status(IStatus.INFO, Activator.ID, key + ": " 111 + events.get(key))); 112 } 113 MultiStatus status = new MultiStatus(Activator.ID, IStatus.INFO, details 114 .toArray(new IStatus[details.size()]), "Event received from " 115 + serviceId + " on " + deviceId, null); 116 log.log(status); 117 listener.notifyUPnPEvent(deviceId, serviceId, events); 118 } 94 119 } 95 120 } -
trunk/sonorous/uk.co.matbooth.sonorous/src/uk/co/matbooth/sonorous/zones/Zone.java
r140 r141 8 8 package uk.co.matbooth.sonorous.zones; 9 9 10 import java.beans.PropertyChangeListener; 11 import java.beans.PropertyChangeSupport; 10 12 import java.util.ArrayList; 11 13 import java.util.Dictionary; … … 22 24 */ 23 25 public class Zone implements UPnPEventListener { 26 private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); 27 28 /** 29 * The device tree this zone is based on. 30 */ 24 31 private final DeviceNode rootNode; 25 32 26 33 /** 27 * List of all the services we want to subscribe to. 34 * List of all the services provided by the device tree that we want to 35 * subscribe to. 28 36 */ 29 37 private static final String SERVICES[] = { "urn:upnp-org:serviceId:DeviceProperties", 30 "urn:upnp-org:serviceId:ZoneGroupTopology", }; 38 // "urn:upnp-org:serviceId:ZoneGroupTopology", // TODO 39 }; 31 40 32 41 /** … … 36 45 private final List<String[]> subscriptions = new ArrayList<String[]>(); 37 46 47 private String zoneName = ""; 48 38 49 public Zone(DeviceNode device) { 39 50 rootNode = device; … … 42 53 public String getRootUDN() { 43 54 return rootNode.getUDN(); 55 } 56 57 public String getZoneName() { 58 return zoneName; 44 59 } 45 60 … … 62 77 } 63 78 79 /** 80 * Implement UPnPEventListener. Update the zone's properties and fire off 81 * property change events. 82 */ 64 83 public void notifyUPnPEvent(String deviceId, String serviceId, Dictionary events) { 65 Enumeration en = events.keys(); 66 System.out.println(); 67 System.out.println("Event!"); 68 System.out.println("UDN: " + deviceId); 69 System.out.println("ServiceID: " + serviceId); 70 for (; en.hasMoreElements();) { 71 String ssvName = (String) en.nextElement(); 72 Object value = events.get(ssvName); 73 System.out.println("Variable: " + ssvName + " = " + value); 84 if (serviceId.equals("urn:upnp-org:serviceId:DeviceProperties")) { 85 for (Enumeration<String> keys = events.keys(); keys.hasMoreElements();) { 86 String key = keys.nextElement(); 87 if (key.equals("ZoneName")) 88 pcs.firePropertyChange(key, zoneName, zoneName = (String) events 89 .get(key)); 90 } 91 // return; 92 } 93 if (serviceId.equals("urn:upnp-org:serviceId:ZoneGroupTopology")) { 94 for (Enumeration<String> keys = events.keys(); keys.hasMoreElements();) { 95 96 } 97 // return; 74 98 } 75 99 } 100 101 /** 102 * Adds a listener to receive property change events from this zone. 103 * 104 * @param listener 105 * a PropertyChangeListener implementation 106 */ 107 public void addPropertyChangeListener(PropertyChangeListener listener) { 108 pcs.addPropertyChangeListener(listener); 109 } 110 111 /** 112 * Removes the specified listener so that it no longer receives property 113 * change events from this zone. 114 * 115 * @param listener 116 * a PropertyChangeListener implementation 117 */ 118 public void removePropertyChangeListener(PropertyChangeListener listener) { 119 pcs.removePropertyChangeListener(listener); 120 } 121 76 122 } -
trunk/sonorous/uk.co.matbooth.sonorous/src/uk/co/matbooth/sonorous/zones/ZoneLabelProvider.java
r140 r141 22 22 switch (columnIndex) { 23 23 case 0: 24 return zone.get RootUDN();24 return zone.getZoneName(); 25 25 default: 26 26 return "?"; -
trunk/sonorous/uk.co.matbooth.sonorous/src/uk/co/matbooth/sonorous/zones/ZoneManager.java
r140 r141 8 8 package uk.co.matbooth.sonorous.zones; 9 9 10 import java.beans.PropertyChangeEvent; 11 import java.beans.PropertyChangeListener; 10 12 import java.util.ArrayList; 11 13 import java.util.HashSet; … … 21 23 * and notifies interested parties of changes to that model. 22 24 */ 23 public class ZoneManager implements DeviceListener {25 public class ZoneManager implements DeviceListener, PropertyChangeListener { 24 26 private static ZoneManager provider; 25 27 … … 60 62 Zone z = new Zone(event.getDevice()); 61 63 if (zones.add(z)) { 64 z.addPropertyChangeListener(this); 62 65 z.startSubscriptions(); 63 66 fireZoneChanged(); … … 76 79 if (z.getRootUDN().equals(event.getDevice().getUDN())) { 77 80 z.stopSubscriptions(); 81 z.removePropertyChangeListener(this); 78 82 i.remove(); 79 83 fireZoneChanged(); … … 81 85 } 82 86 } 87 } 88 89 /** 90 * Implement PropertyChangeListener. Fire an event when a zone changes. 91 */ 92 public void propertyChange(PropertyChangeEvent evt) { 93 fireZoneChanged(); 83 94 } 84 95