Bug 746069: Part 1: Integration with netd daemon using IPC. r=philikon

This commit is contained in:
Albert Crespell 2012-10-04 18:39:59 +02:00
Родитель 5835dd507f
Коммит 77008a5934
3 изменённых файлов: 97 добавлений и 1 удалений

Просмотреть файл

@ -279,6 +279,33 @@ NetworkManager.prototype = {
this.setAndConfigureActive(); this.setAndConfigureActive();
}, },
getNetworkInterfaceStats: function getNetworkInterfaceStats(connectionType, callback) {
let iface = this.getNetworkInterface(connectionType);
if (!iface) {
debug("There is no interface registered for network type " + connectionType);
return false;
}
debug("getNetworkInterfaceStats for " + iface.name);
let params = {
cmd: "getNetworkInterfaceStats",
ifname: iface.name,
connType: connectionType
};
params.report = true;
params.isAsync = true;
this.controlMessage(params, function(result) {
let success = result.resultCode >= NETD_COMMAND_OKAY && result.resultCode < NETD_COMMAND_ERROR;
callback.networkStatsAvailable(success, result.connType, result.rxBytes, result.txBytes, result.date);
});
return true;
},
// Helpers // Helpers
controlMessage: function controlMessage(params, callback) { controlMessage: function controlMessage(params, callback) {

Просмотреть файл

@ -102,6 +102,20 @@ function usbTetheringSuccess(params) {
return true; return true;
} }
function networkInterfaceStatsFail(params) {
// Notify the main thread.
postMessage(params);
return true;
}
function networkInterfaceStatsSuccess(params) {
// Notify the main thread.
params.txBytes = parseFloat(params.resultReason);
postMessage(params);
return true;
}
/** /**
* Get network interface properties from the system property table. * Get network interface properties from the system property table.
* *
@ -353,6 +367,18 @@ function stopSoftAP(params, callback) {
return doCommand(command, callback); return doCommand(command, callback);
} }
function getRxBytes(params, callback) {
let command = "interface readrxcounter " + params.ifname;
return doCommand(command, callback);
}
function getTxBytes(params, callback) {
params.rxBytes = parseFloat(params.resultReason);
let command = "interface readtxcounter " + params.ifname;
return doCommand(command, callback);
}
// The command format is "softap set wlan0 wl0.1 hotspot456 open null 6 0 8". // The command format is "softap set wlan0 wl0.1 hotspot456 open null 6 0 8".
function setAccessPoint(params, callback) { function setAccessPoint(params, callback) {
let command = "softap set " + params.ifname + let command = "softap set " + params.ifname +
@ -535,6 +561,24 @@ function setUSBTethering(params) {
return true; return true;
} }
let gNetworkInterfaceStatsChain = [getRxBytes,
getTxBytes,
networkInterfaceStatsSuccess];
/**
* handling main thread's get network interface stats request
*/
function getNetworkInterfaceStats(params) {
debug("getNetworkInterfaceStats: " + params.ifname);
params.rxBytes = -1;
params.txBytes = -1;
params.date = new Date();
chain(params, gNetworkInterfaceStatsChain, networkInterfaceStatsFail);
return true;
}
let debug; let debug;
if (DEBUG) { if (DEBUG) {
debug = function (s) { debug = function (s) {

Просмотреть файл

@ -99,10 +99,20 @@ interface nsIWifiTetheringCallback : nsISupports
void wifiTetheringEnabledChange(in jsval error); void wifiTetheringEnabledChange(in jsval error);
}; };
[scriptable, function, uuid(9a887e18-b879-4bb1-8663-238bc4234ba0)]
interface nsINetworkStatsCallback : nsISupports
{
void networkStatsAvailable(in boolean success,
in short connType,
in unsigned long rxBytes,
in unsigned long txBytes,
in jsval date);
};
/** /**
* Manage network interfaces. * Manage network interfaces.
*/ */
[scriptable, uuid(a02de6b0-fb25-11e1-a21f-0800200c9a66)] [scriptable, uuid(4bee9633-47ed-47ae-b92b-3e0679087561)]
interface nsINetworkManager : nsISupports interface nsINetworkManager : nsISupports
{ {
/** /**
@ -188,4 +198,19 @@ interface nsINetworkManager : nsISupports
void setWifiTethering(in boolean enabled, void setWifiTethering(in boolean enabled,
in nsINetworkInterface networkInterface, in nsINetworkInterface networkInterface,
in nsIWifiTetheringCallback callback); in nsIWifiTetheringCallback callback);
/**
* Retrieve network interface stats.
*
* @param networkType
* Select the Network interface to request estats.
*
* @param callback
* Callback to notify result and provide stats, connectionType
* and the date when stats are retrieved
*
* @return false if there is no interface registered for the networkType param.
*/
boolean getNetworkInterfaceStats(in short networkType, in nsINetworkStatsCallback callback);
}; };