File: history.h

package info (click to toggle)
gps 1.1.0.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,212 kB
  • ctags: 987
  • sloc: cpp: 11,600; sh: 381; makefile: 319; ansic: 227; perl: 17
file content (133 lines) | stat: -rw-r--r-- 3,867 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* $Id: history.h,v 1.7 2000/09/29 10:15:36 bergo Exp $ */

#ifndef GPS_HISTORY_H
#define GPS_HISTORY_H

#include "transient.h"
#include <gtk/gtk.h>
#include <pthread.h>

#include "polling.h"

#define HISTORY_LENGTH 1024

typedef enum { CPU_USAGE, MEM_USAGE, SWAP_USAGE } HistoryData;

typedef enum { GREEN, RED, BLUE, YELLOW } BarColor;

/** history data. provides three 1024-value circular buffer
    histories for cpu, memory and swap. All values range from
    0 (no usage) to 1 (total load). 64 additional buffers
    provide SMP CPU load.  */
class History {
 public:

  int NCPU;

  /// trivial constructor
  History(int ncpu);
  /// trivial destructor
  ~History();

  /// returns history value on position pos, history q.
  float getValue(int pos,HistoryData q);

  /// sets history value for all three fields: cpu, memory and swap.
  void setValue(float vc,float vm,float vs);

  /// sets cpu load value
  void setCpuLoad(int cpu,float load);

  /// gets cpu load
  float getCpuLoad(int pos,int cpu);
  

  /** advances history position. The real advance is only done after
      all host histories (each one running on a separate thread)
      call advance. The number of advance() calls needed to do the
      advance is determined by the global variable history_watch_count,
      which contains the number of threads */
  void advance();

  /// gets global cursor position. (global to all active histories)
  static int getCursor();

  /// resets everything. (pending advance calls, history data).
  static void reset();

  /// the thread id of the thread this History set is being updated by.
  pthread_t tid;

  /// the source of information.
  SystemInfoProvider *sip;

  /** a mutex to prevent the threads from doing stupid things with
      getValue(), setValue() and (especially) advance(). */
  static pthread_mutex_t ohshit;

 private:
  static int cursor,adv;
  float *dcpu,*dmem,*dswp;
  float *smpcpu[64];
};

void *thread_history_poller(void *p);

void pop_history(GtkWidget *widget, gpointer data);

void close_history(GtkWidget *w, gpointer data);
void destroy_history(GtkWidget *w,gpointer data);

void view_selection_callback(GtkWidget *widget,gint row,gint column,
			     GdkEventButton *event,gpointer data);

/* private? */

void mk_cput(GtkWidget *t);

gboolean g1_expose_event(GtkWidget *widget,GdkEventExpose *ee,
			    gpointer data);
gboolean g1_configure_event(GtkWidget *widget,GdkEventConfigure *ce,
			    gpointer data);
gboolean h1_expose_event(GtkWidget *widget,GdkEventExpose *ee,
			    gpointer data);
gboolean h1_configure_event(GtkWidget *widget,GdkEventConfigure *ce,
			    gpointer data);
gboolean g2_expose_event(GtkWidget *widget,GdkEventExpose *ee,
			    gpointer data);
gboolean g2_configure_event(GtkWidget *widget,GdkEventConfigure *ce,
			    gpointer data);
gboolean h2_expose_event(GtkWidget *widget,GdkEventExpose *ee,
			    gpointer data);
gboolean h2_configure_event(GtkWidget *widget,GdkEventConfigure *ce,
			    gpointer data);

gint refresh_history(gpointer data);

/* all-together painters */

gboolean g1_party_configure_event(GtkWidget *widget,GdkEventConfigure *ce,
			    gpointer data);
gboolean h1_party_configure_event(GtkWidget *widget,GdkEventConfigure *ce,
			    gpointer data);
gboolean g2_party_configure_event(GtkWidget *widget,GdkEventConfigure *ce,
			    gpointer data);
gboolean h2_party_configure_event(GtkWidget *widget,GdkEventConfigure *ce,
			    gpointer data);

/* common things */

void gauge_grid(GdkPixmap *drw,GdkGC *gc,int x,int y);

void draw_bar(GdkPixmap *drawable,GdkGC *gc,int x,int y,int w,
	      int h,BarColor bc);

void draw_jelly_bar(GdkPixmap *drawable,GdkGC *gc,int x,int y,int w,
		    int h,BarColor bc);
void draw_usual_bar(GdkPixmap *drawable,GdkGC *gc,int x,int y,int w,
		    int h,BarColor bc);

int darken(int c);
int lighten(int c);

#endif