W3C home > Mailing lists > Public > public-device-apis@w3.org > June 2013

[discovery] request to simply the NSD API

From: Jean-Claude Dufourd <jean-claude.dufourd@telecom-paristech.fr>
Date: Mon, 17 Jun 2013 18:52:24 +0200
Message-ID: <51BF3EC8.5060506@telecom-paristech.fr>
To: public-device-apis@w3.org
Dear all

The current NSD API is used in this sequence:
- NSD.getNetworkServices( "type", callback, errorcb)
- then in callback, you immediately set the onserviceavailable callback 
and you return, because usually, the first NetworkServices object you 
get is empty
- then onserviceavailable is called, and in there you call 
NSD.getNetworkServices( "type", callback, errorcb) again
- then in callback, you immediately set the onserviceavailable callback 
and you do the actual work.

You need to define:
- a function calling NSD.getNetworkServices( "type", successcallback, 
errorcb)
- a onserviceavailable callback that calls NSD.getNetworkServices( 
"type", successcallback, errorcb)
- the successcallback.

It is possible to define a wrapper around this to deal with the 
onserviceavailable process transparently for the author, on top of the 
existing API.
Thus, I avoid the need for the definition of onserviceavailable.

The actual code does the same as above, but the process that the webapp 
author sees is:
- discover( "type", callback, errorcb)
- then in callback, you immediately do the actual work.

Why not simplify the API and get rid of the need for onserviceavaible ?
Why make the API more complex than it needs to be ?
Why expose a more intricate process that brings no advantage ?

Best regards
JC

Note: here is a possible implementation of the wrapper avoiding the need 
for onserviceavailable:

function discover(serviceType, callBack, errcb) {

     var thisFunction = function (services) {

         services.onserviceavailable = function () {

             NSD.getNetworkServices(serviceType, thisFunction, errcb);

         };

         if (services.length > 0) {

             callBack.call(this, services);

         }

     };

     NSD.getNetworkServices(serviceType, thisFunction, errcb);

}


-- 
TÚlÚcom ParisTech <http://www.telecom-paristech.fr> 	*Jean-Claude DUFOURD*
Directeur d'Útudes
TÚl. : 01 45 81 77 33 	37-39 rue Dareau
75014 Paris

Site web <http://www.telecom-paristech.fr>Twitter 
<https://twitter.com/TelecomPTech>Facebook 
<https://www.facebook.com/TelecomParisTech>Google+ 
<https://plus.google.com/111525064771175271294>Blog 
<http://blogrecherche.wp.mines-telecom.fr>
Received on Monday, 17 June 2013 16:52:54 UTC

This archive was generated by hypermail 2.3.1 : Monday, 23 October 2017 14:53:59 UTC