Changeset 141 for trunk/sonorous/uk.co.matbooth.sonorous/src/uk/co/matbooth/sonorous/zones/Zone.java
- Timestamp:
- 31/12/09 02:27:54 (8 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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 }