Show
Ignore:
Timestamp:
31/12/09 02:27:54 (8 months ago)
Author:
mbooth
Message:

Sonorous now responds to its first UPnP event -- changing the zone name on another controller is reflected in Sonorous! Hurray!

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/sonorous/uk.co.matbooth.sonorous/src/uk/co/matbooth/sonorous/zones/Zone.java

    r140 r141  
    88package uk.co.matbooth.sonorous.zones; 
    99 
     10import java.beans.PropertyChangeListener; 
     11import java.beans.PropertyChangeSupport; 
    1012import java.util.ArrayList; 
    1113import java.util.Dictionary; 
     
    2224 */ 
    2325public class Zone implements UPnPEventListener { 
     26    private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); 
     27 
     28    /** 
     29     * The device tree this zone is based on. 
     30     */ 
    2431    private final DeviceNode rootNode; 
    2532 
    2633    /** 
    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. 
    2836     */ 
    2937    private static final String SERVICES[] = { "urn:upnp-org:serviceId:DeviceProperties", 
    30             "urn:upnp-org:serviceId:ZoneGroupTopology", }; 
     38//          "urn:upnp-org:serviceId:ZoneGroupTopology", // TODO 
     39    }; 
    3140 
    3241    /** 
     
    3645    private final List<String[]> subscriptions = new ArrayList<String[]>(); 
    3746 
     47    private String zoneName = ""; 
     48 
    3849    public Zone(DeviceNode device) { 
    3950        rootNode = device; 
     
    4253    public String getRootUDN() { 
    4354        return rootNode.getUDN(); 
     55    } 
     56 
     57    public String getZoneName() { 
     58        return zoneName; 
    4459    } 
    4560 
     
    6277    } 
    6378 
     79    /** 
     80     * Implement UPnPEventListener. Update the zone's properties and fire off 
     81     * property change events. 
     82     */ 
    6483    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; 
    7498        } 
    7599    } 
     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 
    76122}