зеркало из https://github.com/mozilla/gecko-dev.git
Bug 746069: Part 1: Integration with netd daemon using IPC. r=philikon
This commit is contained in:
Родитель
5835dd507f
Коммит
77008a5934
|
@ -279,6 +279,33 @@ NetworkManager.prototype = {
|
|||
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
|
||||
|
||||
controlMessage: function controlMessage(params, callback) {
|
||||
|
|
|
@ -102,6 +102,20 @@ function usbTetheringSuccess(params) {
|
|||
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.
|
||||
*
|
||||
|
@ -353,6 +367,18 @@ function stopSoftAP(params, 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".
|
||||
function setAccessPoint(params, callback) {
|
||||
let command = "softap set " + params.ifname +
|
||||
|
@ -535,6 +561,24 @@ function setUSBTethering(params) {
|
|||
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;
|
||||
if (DEBUG) {
|
||||
debug = function (s) {
|
||||
|
|
|
@ -99,10 +99,20 @@ interface nsIWifiTetheringCallback : nsISupports
|
|||
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.
|
||||
*/
|
||||
[scriptable, uuid(a02de6b0-fb25-11e1-a21f-0800200c9a66)]
|
||||
[scriptable, uuid(4bee9633-47ed-47ae-b92b-3e0679087561)]
|
||||
interface nsINetworkManager : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -188,4 +198,19 @@ interface nsINetworkManager : nsISupports
|
|||
void setWifiTethering(in boolean enabled,
|
||||
in nsINetworkInterface networkInterface,
|
||||
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);
|
||||
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче