htop/Meter.h

119 lines
3.1 KiB
C
Raw Normal View History

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
Released under the GNU GPLv2, see the COPYING file
2006-03-04 18:16:49 +00:00
in the source distribution for its full text.
*/
#include "config.h" // IWYU pragma: keep
#include <stdbool.h>
2020-11-18 13:26:30 +00:00
#include <stdint.h>
#include <sys/time.h>
2006-03-04 18:16:49 +00:00
2020-09-18 17:23:04 +00:00
#include "ListItem.h"
#include "Object.h"
#include "ProcessList.h"
2020-09-18 17:23:04 +00:00
#define METER_BUFFER_LEN 256
struct Meter_;
2006-03-04 18:16:49 +00:00
typedef struct Meter_ Meter;
typedef void(*Meter_Init)(Meter*);
typedef void(*Meter_Done)(Meter*);
typedef void(*Meter_UpdateMode)(Meter*, int);
typedef void(*Meter_UpdateValues)(Meter*, char*, int);
2006-03-04 18:16:49 +00:00
typedef void(*Meter_Draw)(Meter*, int, int, int);
typedef struct MeterClass_ {
const ObjectClass super;
const Meter_Init init;
const Meter_Done done;
const Meter_UpdateMode updateMode;
const Meter_Draw draw;
const Meter_UpdateValues updateValues;
const int defaultMode;
const double total;
const int* const attributes;
const char* const name;
const char* const uiName;
const char* const caption;
const char* const description;
const uint8_t maxItems;
} MeterClass;
#define As_Meter(this_) ((const 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
#define Meter_updateValues(this_, buf_, sz_) \
As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_)
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
#define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName
2020-10-02 14:27:57 +00:00
typedef struct GraphData_ {
struct timeval time;
double values[METER_BUFFER_LEN];
} GraphData;
struct Meter_ {
Object super;
Meter_Draw draw;
2019-10-31 16:39:12 +00:00
char* caption;
int mode;
int param;
2020-10-02 14:27:57 +00:00
GraphData* drawData;
int h;
const ProcessList* pl;
uint8_t curItems;
2006-03-04 18:16:49 +00:00
double* values;
double total;
void* meterData;
2006-03-04 18:16:49 +00:00
};
typedef struct MeterMode_ {
Meter_Draw draw;
const char* uiName;
int h;
} MeterMode;
typedef enum {
CUSTOM_METERMODE = 0,
BAR_METERMODE,
TEXT_METERMODE,
GRAPH_METERMODE,
LED_METERMODE,
LAST_METERMODE
} MeterModeId;
2006-03-04 18:16:49 +00:00
2020-10-05 11:19:50 +00:00
extern const MeterClass Meter_class;
2006-03-04 18:16:49 +00:00
Meter* Meter_new(const ProcessList* pl, int param, const MeterClass* type);
2006-03-04 18:16:49 +00:00
int Meter_humanUnit(char* buffer, unsigned long int value, int size);
void Meter_delete(Object* cast);
2006-03-04 18:16:49 +00:00
void Meter_setCaption(Meter* this, const char* caption);
2006-03-04 18:16:49 +00:00
void Meter_setMode(Meter* this, int modeIndex);
2006-03-04 18:16:49 +00:00
ListItem* Meter_toListItem(Meter* this, bool moving);
2006-03-04 18:16:49 +00:00
2020-10-05 11:19:50 +00:00
extern const MeterMode* const Meter_modes[];
2020-10-05 11:19:50 +00:00
extern const MeterClass BlankMeter_class;
2014-02-27 19:35:22 +00:00
2006-03-04 18:16:49 +00:00
#endif