B2G/gecko/dom/system/gonk/NetworkManager.js
/**
 * This component watches for network interfaces changing state and then
 * adjusts routes etc. accordingly.
 */
This component watches for network interfaces changing state and then
adjusts routes etc. accordingly.
This component watches for network interfaces changing state and then adjusts routes etc . accordingly .
function NetworkManager() {
  this.networkInterfaces = {};
  Services.obs.addObserver(this, TOPIC_INTERFACE_STATE_CHANGED, true);
  Services.obs.addObserver(this, TOPIC_INTERFACE_REGISTERED, true);
  Services.obs.addObserver(this, TOPIC_INTERFACE_UNREGISTERED, true);
  Services.obs.addObserver(this, TOPIC_XPCOM_SHUTDOWN, false);
  Services.obs.addObserver(this, TOPIC_MOZSETTINGS_CHANGED, false);
  debug("Starting worker.");
  this.worker = new ChromeWorker("resource://gre/modules/net_worker.js");
  this.worker.onmessage = this.handleWorkerMessage.bind(this);
  this.worker.onerror = function onerror(event) {
    debug("Received error from worker: " + event.filename +
          ":" + event.lineno + ": " + event.message + "\n");
    event.preventDefault();
  };
  this.controlCallbacks = Object.create(null);
  try {
    this._manageOfflineStatus =
      Services.prefs.getBoolPref(PREF_MANAGE_OFFLINE_STATUS);
  } catch(ex) {
  }
  Services.prefs.addObserver(PREF_MANAGE_OFFLINE_STATUS, this, false);
  this.possibleInterface = POSSIBLE_USB_INTERFACE_NAME.split(",");
  this._tetheringInterface = Object.create(null);
  this._tetheringInterface[TETHERING_TYPE_USB] = {externalInterface: DEFAULT_3G_INTERFACE_NAME,
                                                  internalInterface: DEFAULT_USB_INTERFACE_NAME};
  this._tetheringInterface[TETHERING_TYPE_WIFI] = {externalInterface: DEFAULT_3G_INTERFACE_NAME,
                                                   internalInterface: DEFAULT_WIFI_INTERFACE_NAME};
  this.initTetheringSettings();
  let settingsLock = gSettingsService.createLock();
  settingsLock.get(SETTINGS_USB_IP, this);
  settingsLock.get(SETTINGS_USB_PREFIX, this);
  settingsLock.get(SETTINGS_USB_DHCPSERVER_STARTIP, this);
  settingsLock.get(SETTINGS_USB_DHCPSERVER_ENDIP, this);
  settingsLock.get(SETTINGS_USB_DNS1, this);
  settingsLock.get(SETTINGS_USB_DNS2, this);
  settingsLock.get(SETTINGS_USB_ENABLED, this);
  this._usbTetheringSettingsToRead = [SETTINGS_USB_IP,
                                      SETTINGS_USB_PREFIX,
                                      SETTINGS_USB_DHCPSERVER_STARTIP,
                                      SETTINGS_USB_DHCPSERVER_ENDIP,
                                      SETTINGS_USB_DNS1,
                                      SETTINGS_USB_DNS2,
                                      SETTINGS_USB_ENABLED];
  this.wantConnectionEvent = null;
  this.setAndConfigureActive();
  defineLazyRegExp(this, "REGEXP_IPV4", "^\\d{1,3}(?:\\.\\d{1,3}){3}$");
  defineLazyRegExp(this, "REGEXP_IPV6", "^[\\da-fA-F]{4}(?::[\\da-fA-F]{4}){7}$");
}
function NetworkManager ( ) { this . networkInterfaces = { } ; Services . obs . addObserver ( this , TOPIC_INTERFACE_STATE_CHANGED , true ) ; Services . obs . addObserver ( this , TOPIC_INTERFACE_REGISTERED , true ) ; Services . obs . addObserver ( this , TOPIC_INTERFACE_UNREGISTERED , true ) ; Services . obs . addObserver ( this , TOPIC_XPCOM_SHUTDOWN , false ) ; Services . obs . addObserver ( this , TOPIC_MOZSETTINGS_CHANGED , false ) ; debug ( "Starting worker." ) ; this . worker = new ChromeWorker ( "resource://gre/modules/net_worker.js" ) ; this . worker . onmessage = this . handleWorkerMessage . bind ( this ) ; this . worker . onerror = function onerror ( event ) { debug ( "Received error from worker: " + event . filename + ":" + event . lineno + ": " + event . message + "\n" ) ; event . preventDefault ( ) ; } ; this . controlCallbacks = Object . create ( null ) ; try { this . _manageOfflineStatus = Services . prefs . getBoolPref ( PREF_MANAGE_OFFLINE_STATUS ) ; } catch ( ex ) { } Services . prefs . addObserver ( PREF_MANAGE_OFFLINE_STATUS , this , false ) ; this . possibleInterface = POSSIBLE_USB_INTERFACE_NAME . split ( "," ) ; this . _tetheringInterface = Object . create ( null ) ; this . _tetheringInterface [ TETHERING_TYPE_USB ] = { externalInterface : DEFAULT_3G_INTERFACE_NAME , internalInterface : DEFAULT_USB_INTERFACE_NAME } ; this . _tetheringInterface [ TETHERING_TYPE_WIFI ] = { externalInterface : DEFAULT_3G_INTERFACE_NAME , internalInterface : DEFAULT_WIFI_INTERFACE_NAME } ; this . initTetheringSettings ( ) ; let settingsLock = gSettingsService . createLock ( ) ; settingsLock . get ( SETTINGS_USB_IP , this ) ; settingsLock . get ( SETTINGS_USB_PREFIX , this ) ; settingsLock . get ( SETTINGS_USB_DHCPSERVER_STARTIP , this ) ; settingsLock . get ( SETTINGS_USB_DHCPSERVER_ENDIP , this ) ; settingsLock . get ( SETTINGS_USB_DNS1 , this ) ; settingsLock . get ( SETTINGS_USB_DNS2 , this ) ; settingsLock . get ( SETTINGS_USB_ENABLED , this ) ; this . _usbTetheringSettingsToRead = [ SETTINGS_USB_IP , SETTINGS_USB_PREFIX , SETTINGS_USB_DHCPSERVER_STARTIP , SETTINGS_USB_DHCPSERVER_ENDIP , SETTINGS_USB_DNS1 , SETTINGS_USB_DNS2 , SETTINGS_USB_ENABLED ] ; this . wantConnectionEvent = null ; this . setAndConfigureActive ( ) ; defineLazyRegExp ( this , "REGEXP_IPV4" , "^\\d{1,3}(?:\\.\\d{1,3}){3}$" ) ; defineLazyRegExp ( this , "REGEXP_IPV6" , "^[\\da-fA-F]{4}(?::[\\da-fA-F]{4}){7}$" ) ; }
This component watches for network interfaces changing state and then
 adjusts routes etc.
This component watches for network interfaces changing state and then adjusts routes etc .
// Prevent the event from bubbling any further. // Callbacks to invoke when a reply arrives from the net_worker. // Ignore. // Possible usb tethering interfaces for different gonk platform. // Default values for internal and external interfaces. // Read usb tethering data from settings DB. // Used in resolveHostname().