Connection Manager
From WebOS101
Contents |
Introduction
The Connection Manager getstatus method allows you to get the current status of the data connection and optionally subscribe to status change notifications.
Objects
The Connection Manager uses the following objects:
- btpan
- wan
- wifi
btpan
| Attribute | Type | Description |
|---|---|---|
| ipAddress | string | The Bluetooth PAN IP address. |
| panUser | string | Set to the name of the Bluetooth PAN client that is connected to the device. |
| state | string | Set to either "connected" or "disconnected". |
wan
| Attribute | Type | Description |
|---|---|---|
| ipAddress | string | The WAN IP address. |
| network | string | Set to "unknown", "unusable", "gprs", "edge", "umts", "hsdpa", "1x", or "evdo." Note : "unusable" is a special condition where the WAN interface is still connected, but data cannot be sent or received. |
| state | string | Set to either "connected" or "disconnected". |
wifi
| Attribute | Type | Description |
|---|---|---|
| bssid | string | The basic service set identifier (BSSID) of the connected virtual access point (AP). |
| ipAddress | string | The Wi-Fi IP address. |
| ssid | string | The service set identifier (SSID) of the connected AP. |
| state | string | Set to either "connected" or "disconnected". |
Methods
The Connection Manager supports only one method: getstatus
getstatus
Gets the connections status and optionally subscribes to connection notification.
Required parameters: None.
Parameters
| Parameter | Type | Description |
|---|---|---|
| subscribe | boolean | Optional. Set to true for subscriptions. Default is false. |
Return Handling
onSuccess
Returns an object containing the following attributes.
| Attribute | Type | Description |
|---|---|---|
| errorCode | integer | Set to the error value if an invalid return. |
| errorText | string | Set to the error text value if an invalid return. |
| isInternetConnectionAvailable | boolean | Set to true if the connection is available; false if not. |
| returnValue | boolean | true. If the subscribe parameter was set to true when this was called, this item is only received on the initial call. |
| wifi | object | Wi-Fi information. See above. |
| wan | object | wan information. See above. |
| btpan | object | btpan information. See above. |
onFailure
| Attribute | Type | Description |
|---|---|---|
| errorCode | string | Numeric string representing an error code: 1. For unknown. 2. For failing to subscribe successfully. |
| errorText | string | Text string representing an error for display if needed. |
| returnValue | boolean | false |
Example
This example uses the Connection Manager service to see if an internet connection and/or wifi service are available and takes action accordingly.
this.controller.serviceRequest('palm://com.palm.connectionmanager', {
method: 'getstatus',
parameters: {},
onSuccess: function(response){
Mojo.Log.info("Response %j", response);
if (response.isInternetConnectionAvailable) {
if (!MyAPP.prefs.syncWifiOnly ||
response.wifi.state === 'connected') {
// Show scrim, spinner and sync output div
this.controller.get('Scrim').show();
var syncOutput = this.controller.get('syncTaskOutput');
syncOutput.show();
this.spinnerModel.spinning = true;
this.controller.modelChanged(this.spinnerModel);
// Run my Sync Routines which calls the syncFinished
// method of my assistant when completed and also updates
// the syncOutput div during the sync process
sync.initSync(this.syncFinished.bind(this), syncOutput);
}
else {
Mojo.Log.info("Wifi connection not available!");
Mojo.Controller.errorDialog("Wifi connection not available!");
}
}
else {
Mojo.Log.info("Internet connection not available!");
Mojo.Controller.errorDialog("Internet connection not available!");
}
}.bind(this),
onFailure: function(response){
Mojo.Log.info("Connection Status Service Request FAILED!");
}.bind(this)
});
Example response:
{"returnValue": true, "isInternetConnectionAvailable": true, "wifi": {"state":
"connected", "ipAddress": "10.11.12.15", "ssid": "Emulator", "bssid": "Emulator"}, "wan": {"state": "disconnected"},
"btpan": {"state": "disconnected"}}
Enyo Example
This example sets up a subscription to status change events, and then sets a variable in this program to keep track of whether Internet is available.
components:
[
{ name: "ConnectionService", kind: "PalmService", service: "palm://com.palm.connectionmanager/", method: "getStatus", onSuccess: "connectionStatusChange", subscribe: true},
// the rest of the components for your app go here
],
create: function() {
this.inherited(arguments);
this.Online = true; // assume online
this.$.ConnectionService.call();
},
connectionStatusChange: function(inSender,status,inRequest) {
/* status:
errorCode
errorText
isInternetConnectionAvailable
returnValue (true if we are initially subscribing, otherwise nonexistent)
wifi [object]
wan [object]
btpan [object]
*/
this.Online = status.isInternetConnectionAvailable;
},