2006-03-04 18:16:49 +00:00
|
|
|
#ifndef HEADER_Meter
|
|
|
|
#define HEADER_Meter
|
|
|
|
/*
|
2006-06-06 20:28:42 +00:00
|
|
|
htop - Meter.h
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2006-03-04 18:16:49 +00:00
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
#define METER_BUFFER_LEN 256
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2015-01-23 05:08:21 +00:00
|
|
|
#define GRAPH_DELAY (DEFAULT_DELAY/2)
|
|
|
|
|
2016-01-21 02:11:54 +00:00
|
|
|
#define GRAPH_HEIGHT 4 /* Unit: rows (lines) */
|
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "ListItem.h"
|
2015-01-22 01:27:31 +00:00
|
|
|
|
|
|
|
#include <sys/time.h>
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
typedef struct Meter_ Meter;
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
typedef void(*Meter_Init)(Meter*);
|
|
|
|
typedef void(*Meter_Done)(Meter*);
|
|
|
|
typedef void(*Meter_UpdateMode)(Meter*, int);
|
2016-05-04 05:39:26 +00:00
|
|
|
typedef void(*Meter_UpdateValues)(Meter*, char*, int);
|
2006-03-04 18:16:49 +00:00
|
|
|
typedef void(*Meter_Draw)(Meter*, int, int, int);
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
typedef struct MeterClass_ {
|
|
|
|
ObjectClass super;
|
|
|
|
const Meter_Init init;
|
|
|
|
const Meter_Done done;
|
|
|
|
const Meter_UpdateMode updateMode;
|
|
|
|
const Meter_Draw draw;
|
2016-05-04 05:39:26 +00:00
|
|
|
const Meter_UpdateValues updateValues;
|
2012-12-05 15:12:20 +00:00
|
|
|
const int defaultMode;
|
|
|
|
const double total;
|
|
|
|
const int* attributes;
|
2010-02-25 01:43:18 +00:00
|
|
|
const char* name;
|
|
|
|
const char* uiName;
|
|
|
|
const char* caption;
|
2015-02-03 21:31:44 +00:00
|
|
|
const char* description;
|
2014-01-16 03:40:47 +00:00
|
|
|
const char maxItems;
|
|
|
|
char curItems;
|
2012-12-05 15:12:20 +00:00
|
|
|
} MeterClass;
|
|
|
|
|
|
|
|
#define As_Meter(this_) ((MeterClass*)((this_)->super.klass))
|
|
|
|
#define Meter_initFn(this_) As_Meter(this_)->init
|
|
|
|
#define Meter_init(this_) As_Meter(this_)->init((Meter*)(this_))
|
|
|
|
#define Meter_done(this_) As_Meter(this_)->done((Meter*)(this_))
|
|
|
|
#define Meter_updateModeFn(this_) As_Meter(this_)->updateMode
|
|
|
|
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
|
|
|
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
|
|
|
#define Meter_doneFn(this_) As_Meter(this_)->done
|
2016-05-04 05:39:26 +00:00
|
|
|
#define Meter_updateValues(this_, buf_, sz_) \
|
|
|
|
As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_)
|
2012-12-05 15:12:20 +00:00
|
|
|
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
|
2014-01-16 03:40:47 +00:00
|
|
|
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
|
|
|
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
2012-12-05 15:12:20 +00:00
|
|
|
#define Meter_attributes(this_) As_Meter(this_)->attributes
|
|
|
|
#define Meter_name(this_) As_Meter(this_)->name
|
|
|
|
#define Meter_uiName(this_) As_Meter(this_)->uiName
|
2006-04-10 20:40:38 +00:00
|
|
|
|
|
|
|
struct Meter_ {
|
|
|
|
Object super;
|
2012-12-05 15:12:20 +00:00
|
|
|
Meter_Draw draw;
|
2019-10-31 16:39:12 +00:00
|
|
|
|
2006-04-10 20:40:38 +00:00
|
|
|
char* caption;
|
|
|
|
int mode;
|
|
|
|
int param;
|
2011-03-22 20:37:08 +00:00
|
|
|
void* drawData;
|
2006-04-10 20:40:38 +00:00
|
|
|
int h;
|
2015-01-22 01:27:31 +00:00
|
|
|
struct ProcessList_* pl;
|
2006-03-04 18:16:49 +00:00
|
|
|
double* values;
|
|
|
|
double total;
|
|
|
|
};
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
typedef struct MeterMode_ {
|
|
|
|
Meter_Draw draw;
|
|
|
|
const char* uiName;
|
|
|
|
int h;
|
|
|
|
} MeterMode;
|
2011-03-22 20:37:08 +00:00
|
|
|
|
2006-04-10 20:40:38 +00:00
|
|
|
typedef enum {
|
|
|
|
CUSTOM_METERMODE = 0,
|
|
|
|
BAR_METERMODE,
|
|
|
|
TEXT_METERMODE,
|
|
|
|
GRAPH_METERMODE,
|
|
|
|
LED_METERMODE,
|
|
|
|
LAST_METERMODE
|
|
|
|
} MeterModeId;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
typedef struct GraphData_ {
|
|
|
|
struct timeval time;
|
|
|
|
double values[METER_BUFFER_LEN];
|
|
|
|
} GraphData;
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-04-10 20:40:38 +00:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
|
|
|
#endif
|
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a,b) ((a)>(b)?(a):(b))
|
|
|
|
#endif
|
Introduce CLAMP macro. Unify all MIN(MAX(a,b),c) uses.
With the CLAMP macro replacing the combination of MIN and MAX, we will
have at least two advantages:
1. It's more obvious semantically.
2. There are no more mixes of confusing uses like MIN(MAX(a,b),c) and
MAX(MIN(a,b),c) and MIN(a,MAX(b,c)) appearing everywhere. We unify
the 'clamping' with a single macro.
Note that the behavior of this CLAMP macro is different from
the combination `MAX(low,MIN(x,high))`.
* This CLAMP macro expands to two comparisons instead of three from
MAX and MIN combination. In theory, this makes the code slightly
smaller, in case that (low) or (high) or both are computed at
runtime, so that compilers cannot optimize them. (The third
comparison will matter if (low)>(high); see below.)
* CLAMP has a side effect, that if (low)>(high) it will produce weird
results. Unlike MIN & MAX which will force either (low) or (high) to
win. No assertion of ((low)<=(high)) is done in this macro, for now.
This CLAMP macro is implemented like described in glib
<http://developer.gnome.org/glib/stable/glib-Standard-Macros.html>
and does not handle weird uses like CLAMP(a++, low++, high--) .
2016-01-15 12:26:01 +00:00
|
|
|
#ifndef CLAMP
|
|
|
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
|
|
|
#endif
|
2006-04-10 20:40:38 +00:00
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
extern MeterClass Meter_class;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
int Meter_humanUnit(char* buffer, unsigned long int value, int size);
|
2015-06-12 07:50:55 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Meter_delete(Object* cast);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Meter_setCaption(Meter* this, const char* caption);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
void Meter_setMode(Meter* this, int modeIndex);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-09-02 07:38:44 +00:00
|
|
|
ListItem* Meter_toListItem(Meter* this, bool moving);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-04-10 20:40:38 +00:00
|
|
|
/* ---------- TextMeterMode ---------- */
|
|
|
|
|
|
|
|
/* ---------- BarMeterMode ---------- */
|
|
|
|
|
|
|
|
/* ---------- GraphMeterMode ---------- */
|
|
|
|
|
2015-07-17 12:33:34 +00:00
|
|
|
#ifdef HAVE_LIBNCURSESW
|
|
|
|
|
2015-07-16 11:05:48 +00:00
|
|
|
#define PIXPERROW_UTF8 4
|
2015-07-17 12:33:34 +00:00
|
|
|
#endif
|
|
|
|
|
2015-07-16 11:05:48 +00:00
|
|
|
#define PIXPERROW_ASCII 2
|
|
|
|
|
2006-04-10 20:40:38 +00:00
|
|
|
/* ---------- LEDMeterMode ---------- */
|
|
|
|
|
2015-07-17 12:33:34 +00:00
|
|
|
#ifdef HAVE_LIBNCURSESW
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
extern MeterMode* Meter_modes[];
|
|
|
|
|
2014-02-27 19:35:22 +00:00
|
|
|
/* Blank meter */
|
|
|
|
|
|
|
|
extern int BlankMeter_attributes[];
|
|
|
|
|
|
|
|
extern MeterClass BlankMeter_class;
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
#endif
|