ACTION-119: on how to define the availability of properties

Background:

Among the system properties that can have more than one instance (e.g. 
network, or storage devices), it is sometimes useful to indicate whether 
one is active or not: for instance, the webapp writer may want to know 
which network connection (among WiFi, GSM, GPRS, as available) is 
active, or which microphone is currently recording audio.

There are 2 ways of modelling this.

1. with a flag

interface Network {
   attribute int currentDownloadBandwith; //etc.
   attribute boolean active;
}

Yielding the following code:

get("Network",function(networks) {
                 for (var i=0; i<length; i++)
                   if (networks[i].active) alert("network: 
"+networks[i].info+" is active");});  


OR

2. with an array and a pointer to one of its items

interface Network {
   attribute NetworkConnection current;
   attribute NetworkConnection available[];
}

interface NetworkConnection {
   attribute int currentDownloadBandwidth; //etc.
}

yielding

get("Network",function(networks) {
                 alert("network: "+networks.current.info+" is active");});


* Pros and Cons

Option 1 is
+ easier to define (only needs 1 interface)
+ allows more than one device to be active (not sure if that's useful)
- makes it harder for the webapp writer to access the active device
+ lets you watch the active-ness of a specific device

What do people think?

Max.

Received on Tuesday, 23 March 2010 17:26:17 UTC