//  
//  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 "netmeter.h"

#define FIELDS      11
#define INFIELD      0
#define OUTFIELD     5


float NetMeter::incoming_[2];
float NetMeter::outgoing_[2];
Timer NetMeter::timer_( 1 );
int NetMeter::index_ = 0;
float NetMeter::lastinterval_;


NetMeter::NetMeter( void ){
  checkevent();
  checkevent();
}

NetMeter::~NetMeter( void ){
}

void NetMeter::checkevent( void ){
  static char buf[256];
  static float totals[FIELDS];
  float tmp;
  ifstream stats( NETFILENAME );

  stats.getline( buf, 256 );
  stats.getline( buf, 256 );

  for ( int i = 0 ; i < FIELDS ; i++ )
    totals[i] = 0;

  while ( !stats.eof() ){
    stats.getline( buf, 256, ':' );
    if ( !stats.eof() ){
      for ( i = 0 ; i < FIELDS ; i++ ){
	stats >>tmp;
	totals[i] += tmp;
      }
    }
  }

  timer_.stop();
  lastinterval_ = timer_.report();
  timer_.start();
  incoming_[index_] = totals[INFIELD];
  outgoing_[index_] = totals[OUTFIELD];
  index_ = (index_ + 1) % 2;
}
