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
|
2020-10-05 07:51:32 +00:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2020-10-03 19:20:43 +00:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
#include <stdbool.h>
|
2021-04-29 15:12:43 +00:00
|
|
|
#include <stddef.h>
|
2020-11-18 13:26:30 +00:00
|
|
|
#include <stdint.h>
|
2015-01-22 01:27:31 +00:00
|
|
|
#include <sys/time.h>
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-09-18 17:23:04 +00:00
|
|
|
#include "ListItem.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "Object.h"
|
|
|
|
#include "ProcessList.h"
|
|
|
|
|
2020-09-18 17:23:04 +00:00
|
|
|
|
2020-10-06 11:13:16 +00:00
|
|
|
#define METER_TXTBUFFER_LEN 256
|
|
|
|
#define METER_GRAPHDATA_SIZE 256
|
2020-09-12 21:25:25 +00:00
|
|
|
|
2020-11-24 18:34:27 +00:00
|
|
|
#define METER_BUFFER_CHECK(buffer, size, written) \
|
|
|
|
do { \
|
|
|
|
if ((written) < 0 || (size_t)(written) >= (size)) { \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
(buffer) += (written); \
|
|
|
|
(size) -= (size_t)(written); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define METER_BUFFER_APPEND_CHR(buffer, size, c) \
|
|
|
|
do { \
|
|
|
|
if ((size) < 2) { \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
*(buffer)++ = c; \
|
|
|
|
*(buffer) = '\0'; \
|
|
|
|
(size)--; \
|
|
|
|
if ((size) == 0) { \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
struct Meter_;
|
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);
|
2020-10-06 11:13:16 +00:00
|
|
|
typedef void(*Meter_UpdateValues)(Meter*);
|
2006-03-04 18:16:49 +00:00
|
|
|
typedef void(*Meter_Draw)(Meter*, int, int, int);
|
2021-07-14 17:24:18 +00:00
|
|
|
typedef const char* (*Meter_GetCaption)(const Meter*);
|
2021-06-23 07:44:56 +00:00
|
|
|
typedef void(*Meter_GetUiName)(const Meter*, char*, size_t);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
typedef struct MeterClass_ {
|
2020-10-04 15:55:08 +00:00
|
|
|
const ObjectClass super;
|
2012-12-05 15:12:20 +00:00
|
|
|
const Meter_Init init;
|
|
|
|
const Meter_Done done;
|
|
|
|
const Meter_UpdateMode updateMode;
|
2016-05-04 05:39:26 +00:00
|
|
|
const Meter_UpdateValues updateValues;
|
2021-06-23 07:44:56 +00:00
|
|
|
const Meter_Draw draw;
|
2021-07-07 06:57:03 +00:00
|
|
|
const Meter_GetCaption getCaption;
|
2021-06-23 07:44:56 +00:00
|
|
|
const Meter_GetUiName getUiName;
|
2012-12-05 15:12:20 +00:00
|
|
|
const int defaultMode;
|
|
|
|
const double total;
|
2020-10-04 15:55:08 +00:00
|
|
|
const int* const attributes;
|
2020-11-29 14:26:57 +00:00
|
|
|
const char* const name; /* internal name of the meter, must not contain any space */
|
|
|
|
const char* const uiName; /* display name in header setup menu */
|
|
|
|
const char* const caption; /* prefix in the actual header */
|
|
|
|
const char* const description; /* optional meter description in header setup menu */
|
2020-10-29 22:17:12 +00:00
|
|
|
const uint8_t maxItems;
|
2012-12-05 15:12:20 +00:00
|
|
|
} MeterClass;
|
|
|
|
|
2020-10-04 15:55:08 +00:00
|
|
|
#define As_Meter(this_) ((const MeterClass*)((this_)->super.klass))
|
2012-12-05 15:12:20 +00:00
|
|
|
#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
|
2020-10-06 11:13:16 +00:00
|
|
|
#define Meter_updateValues(this_) As_Meter(this_)->updateValues((Meter*)(this_))
|
2021-06-23 07:44:56 +00:00
|
|
|
#define Meter_getUiNameFn(this_) As_Meter(this_)->getUiName
|
|
|
|
#define Meter_getUiName(this_,n_,l_) As_Meter(this_)->getUiName((const Meter*)(this_),n_,l_)
|
2021-07-07 06:57:03 +00:00
|
|
|
#define Meter_getCaptionFn(this_) As_Meter(this_)->getCaption
|
|
|
|
#define Meter_getCaption(this_) (Meter_getCaptionFn(this_) ? As_Meter(this_)->getCaption((const Meter*)(this_)) : (this_)->caption)
|
2012-12-05 15:12:20 +00:00
|
|
|
#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
|
2006-04-10 20:40:38 +00:00
|
|
|
|
2020-10-02 14:27:57 +00:00
|
|
|
typedef struct GraphData_ {
|
|
|
|
struct timeval time;
|
2020-10-06 11:13:16 +00:00
|
|
|
double values[METER_GRAPHDATA_SIZE];
|
2020-10-02 14:27:57 +00:00
|
|
|
} GraphData;
|
|
|
|
|
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;
|
2021-02-17 16:38:35 +00:00
|
|
|
unsigned int param;
|
2020-10-02 14:27:57 +00:00
|
|
|
GraphData* drawData;
|
2006-04-10 20:40:38 +00:00
|
|
|
int h;
|
2021-08-14 09:32:38 +00:00
|
|
|
int columnWidthCount; /**< only used internally by the Header */
|
2020-10-21 19:25:50 +00:00
|
|
|
const ProcessList* pl;
|
2020-10-29 22:17:12 +00:00
|
|
|
uint8_t curItems;
|
2020-12-23 19:56:19 +00:00
|
|
|
const int* curAttributes;
|
2020-10-06 11:13:16 +00:00
|
|
|
char txtBuffer[METER_TXTBUFFER_LEN];
|
2006-03-04 18:16:49 +00:00
|
|
|
double* values;
|
|
|
|
double total;
|
2020-09-23 09:58:11 +00:00
|
|
|
void* meterData;
|
2006-03-04 18:16:49 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
extern const MeterClass Meter_class;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2021-02-17 16:38:35 +00:00
|
|
|
Meter* Meter_new(const ProcessList* pl, unsigned int param, const MeterClass* type);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-11-24 17:31:03 +00:00
|
|
|
int Meter_humanUnit(char* buffer, unsigned long int value, size_t 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
|
|
|
|
2021-01-05 22:42:55 +00:00
|
|
|
ListItem* Meter_toListItem(const 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[];
|
2008-03-09 08:58:38 +00:00
|
|
|
|
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
|