From: Todd Brandt Date: Thu, 23 Aug 2012 08:58:46 +0000 (-0700) Subject: added better comments to api.js and moved server test code into subdir X-Git-Tag: submit/release/20120910.223349~70^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1047da5c298b9537ec38129d1bb47c9842a8dcf1;p=profile%2Fivi%2Fautomotive-message-broker.git added better comments to api.js and moved server test code into subdir --- diff --git a/plugins/websocketsink/test/api.js b/plugins/websocketsink/test/api.js index 30bff95..b1f0d5b 100644 --- a/plugins/websocketsink/test/api.js +++ b/plugins/websocketsink/test/api.js @@ -7,25 +7,86 @@ * */ -/* ------------------------ vehicle interface ----------------------------- */ +/***************************************************************************** +* Class name: Vehicle +* Description: +* A javascript implementation of the IVI vehicle API that communicates +* to the automotive message broker through a websocket +* Optional constructor arguments: +* sCB: success callback, called when socket is connected, argument is +* success message string +* eCB: error callback, called on socket close or error, argument is error +* message string +* url: the URL to use for the websocket, in the form "ws://host:port/script" +* protocol: the protocol to use for the websocket, default is "http-only" +* +* [Public Member functions] +* Function name: getSupportedEventTypes(type, writeable, successCB, errorCB) +* Description: +* Retrieves a list of vehicle events for the requested type +* Required arguments: +* type: target event or group to query (use empty string for all events) +* writeable: if true, return only writeable events, otherwise get all +* successCB: success callback, gets called with a string list of names +* for all the events and event groups that are children of the +* target. e.g. "vehicle_info" returns all events/groups with the +* vehicle_info prefix. If the target is an event group, it's +* omitted from the returned list +* errorCB: error callback, called with error message string +* +* Function name: get(type, successCB, errorCB) +* Description: +* Retrieves a list of event/value pairs for a target event or event group +* Required arguments: +* type: target event group to query (use empty string for all events) +* successCB: success callback, gets called with the event/value pair list +* for all event children of the target. The list is the in the +* form of data[n].name/data[n].value +* errorCB: error callback, called with error message string +* +* Function name: set(type, value, successCB, errorCB) +* Description: +* Sets a single event's value (triggers error if it's read-only) +* Required arguments: +* type: target event to set (an event group will trigger an error) +* successCB: success callback, gets called with the event/value pair +* that was successfully set in the form data.name/data.value +* errorCB: error callback, called with error message string +* +******************************************************************************/ -function Vehicle(socketUrl, sCB, eCB, calltimeout) +function Vehicle(sCB, eCB, url, protocol) { + /* store a copy of Vehicle this for reference in callbacks */ var self = this; + this.iSuccessCB = sCB; this.iErrorCB = eCB; - this.retries = 5; - this.connected = false; this.transactionid = 0; - this.methodCalls = []; - this.methodIdx = 0; - this.timeouttime = (calltimeout == undefined)?5000:calltimeout; + /* variables for call management, supports up to 100 simultaneously */ + this.methodIdx = 0; + this.methodCalls = []; for(var i = 0; i < 100; i++) { this.methodCalls[i] = null; } + /* number of connection retries to attempt if the socket closes */ + this.retries = 5; + this.connected = false; + + /* timeout for method calls in milliseconds */ + this.timeouttime = 5000; + + /* default values for WebSocket */ + this.socketUrl = "ws://localhost:23000/vehicle"; + this.socketProtocol = "http-only"; + + /* override the websocket address if parameters are given */ + if(url != undefined) this.socketUrl = url; + if(protocol != undefined) this.socketProtocol = protocol; + this.VehicleMethodCall = function(id, name, successCB, errorCB) { var me = this; @@ -57,11 +118,17 @@ function Vehicle(socketUrl, sCB, eCB, calltimeout) function init() { if ("WebSocket" in window) { - self.socket = new WebSocket(socketUrl,"http-only"); + if(self.socketProtocol.length > 0) + { + self.socket = new WebSocket(self.socketUrl, self.socketProtocol); + } + else + { + self.socket = new WebSocket(self.socketUrl); + } self.socket.onopen = function() { self.connected = true; - this.send("client"); self.iSuccessCB((self.retries < 5)?"(RECONNECTED)":""); self.retries = 5; }; diff --git a/plugins/websocketsink/test/servertest/client.html b/plugins/websocketsink/test/servertest/client.html new file mode 100644 index 0000000..9ef2ee3 --- /dev/null +++ b/plugins/websocketsink/test/servertest/client.html @@ -0,0 +1,17 @@ + + + + IVI API Tester + + + + + +
+
+
+
+ + + + diff --git a/plugins/websocketsink/test/server.html b/plugins/websocketsink/test/servertest/server.html similarity index 89% rename from plugins/websocketsink/test/server.html rename to plugins/websocketsink/test/servertest/server.html index 0e5d50c..43dc72a 100644 --- a/plugins/websocketsink/test/server.html +++ b/plugins/websocketsink/test/servertest/server.html @@ -12,7 +12,7 @@ word-wrap: break-word; } - + diff --git a/plugins/websocketsink/test/server.js b/plugins/websocketsink/test/servertest/server.js similarity index 97% rename from plugins/websocketsink/test/server.js rename to plugins/websocketsink/test/servertest/server.js index 54b5ee4..180c23f 100644 --- a/plugins/websocketsink/test/server.js +++ b/plugins/websocketsink/test/servertest/server.js @@ -59,7 +59,6 @@ function VehicleServer(socketUrl) self.socket.onopen = function() { PRINT.pass("Server READY"); - this.send("server"); }; self.socket.onclose = function() { @@ -173,5 +172,5 @@ VehicleServer.prototype.receive = function(msg) window.addEventListener('load', function () { "use strict"; PRINT.init("result"); - var server = new VehicleServer("ws://localhost:23000/vehicle"); + var server = new VehicleServer("ws://localhost:23023/vehicle?server"); }); diff --git a/plugins/websocketsink/test/test.js b/plugins/websocketsink/test/test.js index db4f8e2..ebeb4be 100644 --- a/plugins/websocketsink/test/test.js +++ b/plugins/websocketsink/test/test.js @@ -150,8 +150,7 @@ function error(msg) PRINT.fail(msg); } -function init() { +function init(url, protocol) { PRINT.init("result"); - window.vehicle = new Vehicle("ws://localhost:23000/vehicle", - start, error); + window.vehicle = new Vehicle(start, error, url, protocol); }