mirror of https://github.com/xzeldon/htop.git
Mark Object pointer to _display function const
This commit is contained in:
parent
e5fdb80c7d
commit
79ad39c718
|
@ -44,8 +44,8 @@ static void MaskItem_delete(Object* cast) {
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MaskItem_display(Object* cast, RichString* out) {
|
static void MaskItem_display(const Object* cast, RichString* out) {
|
||||||
MaskItem* this = (MaskItem*)cast;
|
const MaskItem* this = (const MaskItem*)cast;
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
RichString_append(out, CRT_colors[CHECK_BOX], "[");
|
RichString_append(out, CRT_colors[CHECK_BOX], "[");
|
||||||
if (this->value == 2)
|
if (this->value == 2)
|
||||||
|
|
|
@ -66,9 +66,9 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CPUMeter_display(Object* cast, RichString* out) {
|
static void CPUMeter_display(const Object* cast, RichString* out) {
|
||||||
char buffer[50];
|
char buffer[50];
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
RichString_prune(out);
|
RichString_prune(out);
|
||||||
if (this->param > this->pl->cpuCount) {
|
if (this->param > this->pl->cpuCount) {
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "absent");
|
RichString_append(out, CRT_colors[METER_TEXT], "absent");
|
||||||
|
|
|
@ -21,8 +21,8 @@ static void CheckItem_delete(Object* cast) {
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CheckItem_display(Object* cast, RichString* out) {
|
static void CheckItem_display(const Object* cast, RichString* out) {
|
||||||
CheckItem* this = (CheckItem*)cast;
|
const CheckItem* this = (const CheckItem*)cast;
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
||||||
if (CheckItem_get(this))
|
if (CheckItem_get(this))
|
||||||
|
@ -61,7 +61,7 @@ void CheckItem_set(CheckItem* this, bool value) {
|
||||||
this->value = value;
|
this->value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckItem_get(CheckItem* this) {
|
bool CheckItem_get(const CheckItem* this) {
|
||||||
if (this->ref)
|
if (this->ref)
|
||||||
return *(this->ref);
|
return *(this->ref);
|
||||||
else
|
else
|
||||||
|
|
|
@ -24,6 +24,6 @@ CheckItem* CheckItem_newByVal(char* text, bool value);
|
||||||
|
|
||||||
void CheckItem_set(CheckItem* this, bool value);
|
void CheckItem_set(CheckItem* this, bool value);
|
||||||
|
|
||||||
bool CheckItem_get(CheckItem* this);
|
bool CheckItem_get(const CheckItem* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -59,7 +59,7 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||||
snprintf(buffer, len, "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff);
|
snprintf(buffer, len, "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DIskIOMeter_display(ATTR_UNUSED Object* cast, RichString* out) {
|
static void DIskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
|
|
||||||
int color = cached_utilisation_diff > 40.0 ? DISKIO_UTIL_HIGH : METER_VALUE;
|
int color = cached_utilisation_diff > 40.0 ? DISKIO_UTIL_HIGH : METER_VALUE;
|
||||||
|
|
|
@ -22,8 +22,8 @@ static void ListItem_delete(Object* cast) {
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ListItem_display(Object* cast, RichString* out) {
|
static void ListItem_display(const Object* cast, RichString* out) {
|
||||||
ListItem* const this = (ListItem*)cast;
|
const ListItem* const this = (const ListItem*)cast;
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
/*
|
/*
|
||||||
int len = strlen(this->value)+1;
|
int len = strlen(this->value)+1;
|
||||||
|
|
|
@ -26,8 +26,8 @@ static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
|
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadAverageMeter_display(Object* cast, RichString* out) {
|
static void LoadAverageMeter_display(const Object* cast, RichString* out) {
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
|
||||||
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
||||||
|
@ -46,8 +46,8 @@ static void LoadMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
xSnprintf(buffer, size, "%.2f", this->values[0]);
|
xSnprintf(buffer, size, "%.2f", this->values[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadMeter_display(Object* cast, RichString* out) {
|
static void LoadMeter_display(const Object* cast, RichString* out) {
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
|
||||||
RichString_write(out, CRT_colors[LOAD], buffer);
|
RichString_write(out, CRT_colors[LOAD], buffer);
|
||||||
|
|
|
@ -36,9 +36,9 @@ static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MemoryMeter_display(Object* cast, RichString* out) {
|
static void MemoryMeter_display(const Object* cast, RichString* out) {
|
||||||
char buffer[50];
|
char buffer[50];
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
RichString_write(out, CRT_colors[METER_TEXT], ":");
|
RichString_write(out, CRT_colors[METER_TEXT], ":");
|
||||||
Meter_humanUnit(buffer, this->total, 50);
|
Meter_humanUnit(buffer, this->total, 50);
|
||||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||||
|
|
5
Meter.c
5
Meter.c
|
@ -92,7 +92,7 @@ void Meter_setCaption(Meter* this, const char* caption) {
|
||||||
this->caption = xStrdup(caption);
|
this->caption = xStrdup(caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Meter_displayBuffer(Meter* this, char* buffer, RichString* out) {
|
static inline void Meter_displayBuffer(const Meter* this, const char* buffer, RichString* out) {
|
||||||
if (Object_displayFn(this)) {
|
if (Object_displayFn(this)) {
|
||||||
Object_display(this, out);
|
Object_display(this, out);
|
||||||
} else {
|
} else {
|
||||||
|
@ -428,8 +428,7 @@ static void BlankMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BlankMeter_display(Object* cast, RichString* out) {
|
static void BlankMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
|
||||||
(void) cast;
|
|
||||||
RichString_prune(out);
|
RichString_prune(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
Object.h
8
Object.h
|
@ -14,16 +14,16 @@ in the source distribution for its full text.
|
||||||
|
|
||||||
typedef struct Object_ Object;
|
typedef struct Object_ Object;
|
||||||
|
|
||||||
typedef void(*Object_Display)(Object*, RichString*);
|
typedef void(*Object_Display)(const Object*, RichString*);
|
||||||
typedef long(*Object_Compare)(const void*, const void*);
|
typedef long(*Object_Compare)(const void*, const void*);
|
||||||
typedef void(*Object_Delete)(Object*);
|
typedef void(*Object_Delete)(Object*);
|
||||||
|
|
||||||
#define Object_getClass(obj_) ((Object*)(obj_))->klass
|
#define Object_getClass(obj_) ((const Object*)(obj_))->klass
|
||||||
#define Object_setClass(obj_, class_) Object_getClass(obj_) = (const ObjectClass*) class_
|
#define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) class_)
|
||||||
|
|
||||||
#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
|
#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
|
||||||
#define Object_displayFn(obj_) Object_getClass(obj_)->display
|
#define Object_displayFn(obj_) Object_getClass(obj_)->display
|
||||||
#define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_)
|
#define Object_display(obj_, str_) Object_getClass(obj_)->display((const Object*)(obj_), str_)
|
||||||
#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
|
#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
|
||||||
|
|
||||||
#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))
|
#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))
|
||||||
|
|
12
Process.c
12
Process.c
|
@ -181,9 +181,9 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Process_writeCommand(Process* this, int attr, int baseattr, RichString* str) {
|
static inline void Process_writeCommand(const Process* this, int attr, int baseattr, RichString* str) {
|
||||||
int start = RichString_size(str), finish = 0;
|
int start = RichString_size(str), finish = 0;
|
||||||
char* comm = this->comm;
|
const char* comm = this->comm;
|
||||||
|
|
||||||
if (this->settings->highlightBaseName || !this->settings->showProgramPath) {
|
if (this->settings->highlightBaseName || !this->settings->showProgramPath) {
|
||||||
int i, basename = 0;
|
int i, basename = 0;
|
||||||
|
@ -240,7 +240,7 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
void Process_writeField(const Process* this, RichString* str, ProcessField field) {
|
||||||
char buffer[256]; buffer[255] = '\0';
|
char buffer[256]; buffer[255] = '\0';
|
||||||
int attr = CRT_colors[DEFAULT_COLOR];
|
int attr = CRT_colors[DEFAULT_COLOR];
|
||||||
int baseattr = CRT_colors[PROCESS_BASENAME];
|
int baseattr = CRT_colors[PROCESS_BASENAME];
|
||||||
|
@ -366,9 +366,9 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||||
RichString_append(str, attr, buffer);
|
RichString_append(str, attr, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_display(Object* cast, RichString* out) {
|
void Process_display(const Object* cast, RichString* out) {
|
||||||
Process* this = (Process*) cast;
|
const Process* this = (const Process*) cast;
|
||||||
ProcessField* fields = this->settings->fields;
|
const ProcessField* fields = this->settings->fields;
|
||||||
RichString_prune(out);
|
RichString_prune(out);
|
||||||
for (int i = 0; fields[i]; i++)
|
for (int i = 0; fields[i]; i++)
|
||||||
As_Process(this)->writeField(this, out, fields[i]);
|
As_Process(this)->writeField(this, out, fields[i]);
|
||||||
|
|
|
@ -113,7 +113,7 @@ typedef struct ProcessFieldData_ {
|
||||||
} ProcessFieldData;
|
} ProcessFieldData;
|
||||||
|
|
||||||
// Implemented in platform-specific code:
|
// Implemented in platform-specific code:
|
||||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
void Process_writeField(const Process* this, RichString* str, ProcessField field);
|
||||||
long Process_compare(const void* v1, const void* v2);
|
long Process_compare(const void* v1, const void* v2);
|
||||||
void Process_delete(Object* cast);
|
void Process_delete(Object* cast);
|
||||||
bool Process_isThread(const Process* this);
|
bool Process_isThread(const Process* this);
|
||||||
|
@ -122,7 +122,7 @@ extern ProcessPidColumn Process_pidColumns[];
|
||||||
extern char Process_pidFormat[20];
|
extern char Process_pidFormat[20];
|
||||||
|
|
||||||
typedef Process*(*Process_New)(struct Settings_*);
|
typedef Process*(*Process_New)(struct Settings_*);
|
||||||
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
|
typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField);
|
||||||
|
|
||||||
typedef struct ProcessClass_ {
|
typedef struct ProcessClass_ {
|
||||||
const ObjectClass super;
|
const ObjectClass super;
|
||||||
|
@ -158,7 +158,7 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths);
|
||||||
|
|
||||||
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
||||||
|
|
||||||
void Process_display(Object* cast, RichString* out);
|
void Process_display(const Object* cast, RichString* out);
|
||||||
|
|
||||||
void Process_done(Process* this);
|
void Process_done(Process* this);
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,9 @@ static void SwapMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SwapMeter_display(Object* cast, RichString* out) {
|
static void SwapMeter_display(const Object* cast, RichString* out) {
|
||||||
char buffer[50];
|
char buffer[50];
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
RichString_write(out, CRT_colors[METER_TEXT], ":");
|
RichString_write(out, CRT_colors[METER_TEXT], ":");
|
||||||
Meter_humanUnit(buffer, this->total, 50);
|
Meter_humanUnit(buffer, this->total, 50);
|
||||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||||
|
|
|
@ -33,9 +33,9 @@ static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||||
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
|
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TasksMeter_display(Object* cast, RichString* out) {
|
static void TasksMeter_display(const Object* cast, RichString* out) {
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
Settings* settings = this->pl->settings;
|
const Settings* settings = this->pl->settings;
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
|
|
||||||
int processes = (int) this->values[2];
|
int processes = (int) this->values[2];
|
||||||
|
|
|
@ -41,8 +41,8 @@ static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len)
|
||||||
xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]);
|
xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PressureStallMeter_display(Object* cast, RichString* out) {
|
static void PressureStallMeter_display(const Object* cast, RichString* out) {
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]);
|
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]);
|
||||||
RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer);
|
RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer);
|
||||||
|
|
|
@ -55,9 +55,9 @@ static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZfsArcMeter_display(Object* cast, RichString* out) {
|
static void ZfsArcMeter_display(const Object* cast, RichString* out) {
|
||||||
char buffer[50];
|
char buffer[50];
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
|
|
||||||
if (this->values[5] > 0) {
|
if (this->values[5] > 0) {
|
||||||
Meter_humanUnit(buffer, this->total, 50);
|
Meter_humanUnit(buffer, this->total, 50);
|
||||||
|
|
|
@ -38,7 +38,7 @@ void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZfsCompressedArcMeter_printRatioString(Meter* this, char* buffer, int size) {
|
static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, int size) {
|
||||||
xSnprintf(buffer, size, "%.2f:1", this->total/this->values[0]);
|
xSnprintf(buffer, size, "%.2f:1", this->total/this->values[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,9 +48,9 @@ static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int si
|
||||||
ZfsCompressedArcMeter_printRatioString(this, buffer, size);
|
ZfsCompressedArcMeter_printRatioString(this, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZfsCompressedArcMeter_display(Object* cast, RichString* out) {
|
static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) {
|
||||||
char buffer[50];
|
char buffer[50];
|
||||||
Meter* this = (Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
|
|
||||||
if (this->values[0] > 0) {
|
if (this->values[0] > 0) {
|
||||||
Meter_humanUnit(buffer, this->total, 50);
|
Meter_humanUnit(buffer, this->total, 50);
|
||||||
|
|
Loading…
Reference in New Issue