//
// BEGIN FLOCK GPL
//
// Copyright Flock Inc. 2005-2009
// http://flock.com
//
// This file may be used under the terms of the
// GNU General Public License Version 2 or later (the "GPL"),
// http://www.gnu.org/licenses/gpl.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// END FLOCK GPL
//


var flockSystemInfo = {
  _Logger: null,
  _SystemInfo: null,
  
  init: function() {
    this._Logger = Components.classes["@flock.com/logger;1"].createInstance(Components.interfaces.flockILogger);
    if (!this._Logger) {
      dump("****** NO LOGGER! ******\n");
      return;
    }
    this._Logger.init("flockSystemInfoTest");
    
    this._Logger.debug("Getting flockISystemInfo service.");
    this._SystemInfo = Components.classes["@flock.com/sysinfo;1"].getService(Components.interfaces.flockISystemInfo);
    
    if (this._SystemInfo) {
      this._Logger.debug("Successfully got flockISystemInfo service.");
    } else {
      this._Logger.debug("Failed to get flockISystemInfo service.");
      return;
    }    
    this._Logger.debug("Setting first timeout for getData in 1 second.");
    setTimeout("flockSystemInfo.getData()", 1000);
  },
  
  getData: function() {
    if (!this._SystemInfo) {
      this._Logger.debug("Lost flockISystemInfo service?");
      return;
    }
    
    this._Logger.debug("Getting description controls.");
    var cpuInfo = document.getElementById("cpuInfo");
    var memInfo = document.getElementById("memInfo");
    var buildInfo = document.getElementById("buildInfo");
    var startTime = document.getElementById("startTime");
    
    this._Logger.debug("Getting values from system and displaying.");
    cpuInfo.setAttribute("value", this._SystemInfo.getCPU());
    memInfo.setAttribute("value", this._SystemInfo.getMem());
    buildInfo.setAttribute("value", this._SystemInfo.getBuildInfo());
    startTime.setAttribute("value", this._SystemInfo.getStartTime());
    
    this._Logger.debug("Setting new timeout for getData in 1 second.");
    setTimeout("flockSystemInfo.getData()", 1000);
  }

};
