#ifndef _CPUMON_FETCHER_H_
#define _CPUMON_FETCHER_H_

#include <vdr/plugin.h>
#include <vdr/thread.h>
#include <vdr/status.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include "parms.h"

#define VAL_COUNT 150
#define USER   0
#define NICE   1
#define SYSTEM 2
#define IDLE   3

static const char DName[] = "/proc/stat";

// ---------------------------------------------------------------------

struct tMeasured
{
  unsigned int val[4],
               // 0:user,   /* jiffies in user mode */
               // 1:nice,   /* jiffies in user mode with low priority (nice) */
	       // 2:system, /* jiffies in system mode */
	       // 3:idle,   /* jiffies in idle task */
	               /* jiffie = 1/100 second */
	       sum;    /* sum of all four values */
  struct timeval t_val;
  bool used;
};

// ---------------------------------------------------------------------
/* cCPUUsageFetcher - responsible for reading the
 * /proc/stat file and to extract the most important
 * values from it.
 */
 
class cCpuMonFetcher: public cThread
{
private:
  FILE *Datei;
  unsigned int v_index,
               m_index;
  char name[7];
  tMeasured measurements[VAL_COUNT + 1];
  struct timezone t_zone;
  cCondWait timer;
  cParameters *parms;
  unsigned int round(float x);
public:
  virtual void Action();
  
  // own members:
  tMeasured values[VAL_COUNT];
  cCpuMonFetcher(cParameters *pparms);
  ~cCpuMonFetcher();
  unsigned int get_index();
  int fetch_values();
  void Stop();
};

#endif
