//  
//  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 "memmeter.h"
#include <stdio.h>


MemMeter::MemMeter( XOSView *parent, int x, int y, int width, int height )
: FieldMeter( parent, x, y, width, height, 4, "MEM", "USED SHAR BUFF FREE" ){

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

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

void MemMeter::checkevent( void ){
  getmeminfo();
  drawfields();
}

void MemMeter::getmeminfo( void ){
  static char buf[32];
  float used;
  
  meminfo_->seekg( fpos_ );

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

  fields_[0] = used - fields_[1] - fields_[2];
  if ( fields_[0] < 0 )
    fields_[0] = 0;
}
