W3C home > Mailing lists > Public > public-device-apis@w3.org > March 2010

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

From: Max Froumentin <maxfro@opera.com>
Date: Tue, 23 Mar 2010 18:25:42 +0100
Message-ID: <4BA8F996.9010903@opera.com>
To: "public-device-apis@w3.org" <public-device-apis@w3.org>


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


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.


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?

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:32:18 UTC