//  
//  Copyright (c) 1994 by Mike Romberg (  romberg@md.fsl.noaa.gov )
//  Debugged and Featurized by Michael Hemy
//
//  This file may be distributed under terms of the GPL
//

#include "swapmeter.h"
#include <stdio.h>


SwapMeter::SwapMeter( XOSView *parent, int x, int y, int width, int height )
: FieldMeter( parent, x, y, width, height, 2, "SWAP", "USED FREE" ){

  char buf[256];  
  meminfo_ = new ifstream( MEMFILENAME );
  meminfo_->getline( buf, 256 );
  meminfo_->getline( buf, 256 );  
  fpos_ = meminfo_->tellg();
}

SwapMeter::~SwapMeter( void ){
  delete meminfo_;
}

void SwapMeter::checkevent( void ){
  getswapinfo();
  drawfields();
}

void SwapMeter::getswapinfo( void ){
  static char buf[32];
  
  meminfo_->seekg( fpos_ );

  *meminfo_ >>buf >>total_ >>fields_[0] >>fields_[1];
  if ( total_ == 0 ){
    total_ = 1;
    fields_[0] = 0;
    fields_[1] = 1;
  }
  extra_val_ = 100*fields_[0]/total_;
  sprintf(extra_str_,"%3d%%", int(extra_val_));
}
