summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-04 17:55:08 +0200
committercgzones <cgzones@googlemail.com>2020-10-07 13:01:53 +0200
commit08d85e61435e43ade490ecef16437f93c0d88bed (patch)
treefd7357e4a53f7786b5001ef128ffa8e473570f00
parent164051354f11c0426e09e4fa09feeca7de92e619 (diff)
Mark Object classes and Object class fields const
-rw-r--r--CPUMeter.c2
-rw-r--r--InfoScreen.h4
-rw-r--r--Meter.c8
-rw-r--r--Meter.h20
-rw-r--r--Object.c2
-rw-r--r--Object.h10
-rw-r--r--Panel.c4
-rw-r--r--Panel.h6
-rw-r--r--Process.h2
-rw-r--r--ProcessList.c2
-rw-r--r--ProcessList.h2
-rw-r--r--Vector.c2
-rw-r--r--Vector.h4
-rw-r--r--darwin/Platform.c2
-rw-r--r--dragonflybsd/Platform.c4
-rw-r--r--freebsd/Platform.c4
-rw-r--r--linux/Platform.c4
-rw-r--r--openbsd/Platform.c4
-rw-r--r--solaris/Platform.c4
-rw-r--r--zfs/ZfsArcMeter.c2
20 files changed, 45 insertions, 47 deletions
diff --git a/CPUMeter.c b/CPUMeter.c
index 51c16c68..72988472 100644
--- a/CPUMeter.c
+++ b/CPUMeter.c
@@ -146,7 +146,7 @@ static void CPUMeterCommonInit(Meter *this, int ncol) {
AllCPUsMeter_getRange(this, &start, &count);
for (int i = 0; i < count; i++) {
if (!meters[i])
- meters[i] = Meter_new(this->pl, start+i+1, (MeterClass*) Class(CPUMeter));
+ meters[i] = Meter_new(this->pl, start+i+1, (const MeterClass*) Class(CPUMeter));
Meter_init(meters[i]);
}
if (this->mode == 0)
diff --git a/InfoScreen.h b/InfoScreen.h
index 196c56e1..e5c58461 100644
--- a/InfoScreen.h
+++ b/InfoScreen.h
@@ -14,14 +14,14 @@ typedef void(*InfoScreen_OnErr)(InfoScreen*);
typedef bool(*InfoScreen_OnKey)(InfoScreen*, int);
typedef struct InfoScreenClass_ {
- ObjectClass super;
+ const ObjectClass super;
const InfoScreen_Scan scan;
const InfoScreen_Draw draw;
const InfoScreen_OnErr onErr;
const InfoScreen_OnKey onKey;
} InfoScreenClass;
-#define As_InfoScreen(this_) ((InfoScreenClass*)(((InfoScreen*)(this_))->super.klass))
+#define As_InfoScreen(this_) ((const InfoScreenClass*)(((InfoScreen*)(this_))->super.klass))
#define InfoScreen_scan(this_) As_InfoScreen(this_)->scan((InfoScreen*)(this_))
#define InfoScreen_draw(this_) As_InfoScreen(this_)->draw((InfoScreen*)(this_))
#define InfoScreen_onErr(this_) As_InfoScreen(this_)->onErr((InfoScreen*)(this_))
diff --git a/Meter.c b/Meter.c
index c0b2af9e..cd6d089f 100644
--- a/Meter.c
+++ b/Meter.c
@@ -27,13 +27,13 @@ MeterClass Meter_class = {
}
};
-Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) {
+Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type) {
Meter* this = xCalloc(1, sizeof(Meter));
Object_setClass(this, type);
this->h = 1;
this->param = param;
this->pl = pl;
- type->curItems = type->maxItems;
+ this->curItems = type->maxItems;
this->values = xCalloc(type->maxItems, sizeof(double));
this->total = type->total;
this->caption = xStrdup(type->caption);
@@ -191,7 +191,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
// First draw in the bar[] buffer...
int offset = 0;
- int items = Meter_getItems(this);
+ int items = this->curItems;
for (int i = 0; i < items; i++) {
double value = this->values[i];
value = CLAMP(value, 0.0, this->total);
@@ -292,7 +292,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
Meter_updateValues(this, buffer, nValues - 1);
double value = 0.0;
- int items = Meter_getItems(this);
+ int items = this->curItems;
for (int i = 0; i < items; i++)
value += this->values[i];
value /= this->total;
diff --git a/Meter.h b/Meter.h
index 07e66e0e..34f388f4 100644
--- a/Meter.h
+++ b/Meter.h
@@ -22,7 +22,7 @@ typedef void(*Meter_UpdateValues)(Meter*, char*, int);
typedef void(*Meter_Draw)(Meter*, int, int, int);
typedef struct MeterClass_ {
- ObjectClass super;
+ const ObjectClass super;
const Meter_Init init;
const Meter_Done done;
const Meter_UpdateMode updateMode;
@@ -30,16 +30,15 @@ typedef struct MeterClass_ {
const Meter_UpdateValues updateValues;
const int defaultMode;
const double total;
- const int* attributes;
- const char* name;
- const char* uiName;
- const char* caption;
- const char* description;
+ const int* const attributes;
+ const char* const name;
+ const char* const uiName;
+ const char* const caption;
+ const char* const description;
const char maxItems;
- char curItems;
} MeterClass;
-#define As_Meter(this_) ((MeterClass*)((this_)->super.klass))
+#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_))
@@ -50,8 +49,6 @@ typedef struct MeterClass_ {
#define Meter_updateValues(this_, buf_, sz_) \
As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_)
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
-#define Meter_getItems(this_) As_Meter(this_)->curItems
-#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
#define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName
@@ -66,6 +63,7 @@ struct Meter_ {
void* drawData;
int h;
struct ProcessList_* pl;
+ char curItems;
double* values;
double total;
};
@@ -92,7 +90,7 @@ typedef struct GraphData_ {
extern MeterClass Meter_class;
-Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type);
+Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type);
int Meter_humanUnit(char* buffer, unsigned long int value, int size);
diff --git a/Object.c b/Object.c
index 6f16009a..97e913e6 100644
--- a/Object.c
+++ b/Object.c
@@ -8,7 +8,7 @@ in the source distribution for its full text.
#include "Object.h"
-ObjectClass Object_class = {
+const ObjectClass Object_class = {
.extends = NULL
};
diff --git a/Object.h b/Object.h
index 6fafd4e1..0d0e0036 100644
--- a/Object.h
+++ b/Object.h
@@ -19,26 +19,26 @@ typedef long(*Object_Compare)(const void*, const void*);
typedef void(*Object_Delete)(Object*);
#define Object_getClass(obj_) ((Object*)(obj_))->klass
-#define Object_setClass(obj_, class_) Object_getClass(obj_) = (ObjectClass*) class_
+#define Object_setClass(obj_, class_) Object_getClass(obj_) = (const ObjectClass*) class_
#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
#define Object_displayFn(obj_) Object_getClass(obj_)->display
#define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_)
#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
-#define Class(class_) ((ObjectClass*)(&(class_ ## _class)))
+#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))
#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_));
typedef struct ObjectClass_ {
- const void* extends;
+ const void* const extends;
const Object_Display display;
const Object_Delete delete;
const Object_Compare compare;
} ObjectClass;
struct Object_ {
- ObjectClass* klass;
+ const ObjectClass* klass;
};
typedef union {
@@ -46,7 +46,7 @@ typedef union {
void* v;
} Arg;
-extern ObjectClass Object_class;
+extern const ObjectClass Object_class;
#ifndef NDEBUG
diff --git a/Panel.c b/Panel.c
index b97fbc9c..5922d4c7 100644
--- a/Panel.c
+++ b/Panel.c
@@ -27,7 +27,7 @@ PanelClass Panel_class = {
.eventHandler = Panel_selectByTyping,
};
-Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar) {
+Panel* Panel_new(int x, int y, int w, int h, bool owner, const ObjectClass* type, FunctionBar* fuBar) {
Panel* this;
this = xMalloc(sizeof(Panel));
Object_setClass(this, Class(Panel));
@@ -41,7 +41,7 @@ void Panel_delete(Object* cast) {
free(this);
}
-void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar) {
+void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type, bool owner, FunctionBar* fuBar) {
this->x = x;
this->y = y;
this->w = w;
diff --git a/Panel.h b/Panel.h
index 239de0a5..7c4a6f2f 100644
--- a/Panel.h
+++ b/Panel.h
@@ -35,7 +35,7 @@ typedef struct PanelClass_ {
const Panel_EventHandler eventHandler;
} PanelClass;
-#define As_Panel(this_) ((PanelClass*)((this_)->super.klass))
+#define As_Panel(this_) ((const PanelClass*)((this_)->super.klass))
#define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler
#define Panel_eventHandler(this_, ev_) As_Panel(this_)->eventHandler((Panel*)(this_), ev_)
@@ -62,11 +62,11 @@ struct Panel_ {
extern PanelClass Panel_class;
-Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar);
+Panel* Panel_new(int x, int y, int w, int h, bool owner, const ObjectClass* type, FunctionBar* fuBar);
void Panel_delete(Object* cast);
-void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar);
+void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type, bool owner, FunctionBar* fuBar);
void Panel_done(Panel* this);
diff --git a/Process.h b/Process.h
index dd9c052c..2ff7f5e0 100644
--- a/Process.h
+++ b/Process.h
@@ -129,7 +129,7 @@ typedef struct ProcessClass_ {
const Process_WriteField writeField;
} ProcessClass;
-#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
+#define As_Process(this_) ((const ProcessClass*)((this_)->super.klass))
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
diff --git a/ProcessList.c b/ProcessList.c
index 6ec7ce85..e509b897 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -15,7 +15,7 @@ in the source distribution for its full text.
#include <string.h>
-ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
+ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
this->processes = Vector_new(klass, true, DEFAULT_SIZE);
this->processTable = Hashtable_new(140, false);
this->usersTable = usersTable;
diff --git a/ProcessList.h b/ProcessList.h
index c9d1f28f..164ff7b0 100644
--- a/ProcessList.h
+++ b/ProcessList.h
@@ -69,7 +69,7 @@ void ProcessList_delete(ProcessList* pl);
void ProcessList_goThroughEntries(ProcessList* pl);
-ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId);
+ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId);
void ProcessList_done(ProcessList* this);
diff --git a/Vector.c b/Vector.c
index 3d4e6466..a12d6bb5 100644
--- a/Vector.c
+++ b/Vector.c
@@ -13,7 +13,7 @@ in the source distribution for its full text.
#include <stdbool.h>
-Vector* Vector_new(ObjectClass* type, bool owner, int size) {
+Vector* Vector_new(const ObjectClass* type, bool owner, int size) {
Vector* this;
if (size == DEFAULT_SIZE)
diff --git a/Vector.h b/Vector.h
index e2de5e82..d0d42c6c 100644
--- a/Vector.h
+++ b/Vector.h
@@ -17,14 +17,14 @@ in the source distribution for its full text.
typedef struct Vector_ {
Object **array;
- ObjectClass* type;
+ const ObjectClass* type;
int arraySize;
int growthRate;
int items;
bool owner;
} Vector;
-Vector* Vector_new(ObjectClass* type, bool owner, int size);
+Vector* Vector_new(const ObjectClass* type, bool owner, int size);
void Vector_delete(Vector* this);
diff --git a/darwin/Platform.c b/darwin/Platform.c
index b7451e83..fabf5520 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -216,7 +216,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
mtr->values[CPU_METER_KERNEL]
= ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total;
- Meter_setItems(mtr, 3);
+ mtr->curItems = 3;
/* Convert to percent and return */
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c
index 8fd929e6..33282405 100644
--- a/dragonflybsd/Platform.c
+++ b/dragonflybsd/Platform.c
@@ -167,11 +167,11 @@ double Platform_setCPUValues(Meter* this, int cpu) {
if (this->pl->settings->detailedCPUTime) {
v[CPU_METER_KERNEL] = cpuData->systemPercent;
v[CPU_METER_IRQ] = cpuData->irqPercent;
- Meter_setItems(this, 4);
+ this->curItems = 4;
percent = v[0]+v[1]+v[2]+v[3];
} else {
v[2] = cpuData->systemAllPercent;
- Meter_setItems(this, 3);
+ this->curItems = 3;
percent = v[0]+v[1]+v[2];
}
diff --git a/freebsd/Platform.c b/freebsd/Platform.c
index 59256858..3e4b9b74 100644
--- a/freebsd/Platform.c
+++ b/freebsd/Platform.c
@@ -170,11 +170,11 @@ double Platform_setCPUValues(Meter* this, int cpu) {
if (this->pl->settings->detailedCPUTime) {
v[CPU_METER_KERNEL] = cpuData->systemPercent;
v[CPU_METER_IRQ] = cpuData->irqPercent;
- Meter_setItems(this, 4);
+ this->curItems = 4;
percent = v[0]+v[1]+v[2]+v[3];
} else {
v[2] = cpuData->systemAllPercent;
- Meter_setItems(this, 3);
+ this->curItems = 3;
percent = v[0]+v[1]+v[2];
}
diff --git a/linux/Platform.c b/linux/Platform.c
index b0053bc0..6ec0d076 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -191,7 +191,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
v[CPU_METER_STEAL] = cpuData->stealPeriod / total * 100.0;
v[CPU_METER_GUEST] = cpuData->guestPeriod / total * 100.0;
v[CPU_METER_IOWAIT] = cpuData->ioWaitPeriod / total * 100.0;
- Meter_setItems(this, 8);
+ this->curItems = 8;
if (this->pl->settings->accountGuestInCPUMeter) {
percent = v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6];
} else {
@@ -200,7 +200,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
} else {
v[2] = cpuData->systemAllPeriod / total * 100.0;
v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
- Meter_setItems(this, 4);
+ this->curItems = 4;
percent = v[0]+v[1]+v[2]+v[3];
}
percent = CLAMP(percent, 0.0, 100.0);
diff --git a/openbsd/Platform.c b/openbsd/Platform.c
index 6649064f..0368d722 100644
--- a/openbsd/Platform.c
+++ b/openbsd/Platform.c
@@ -173,13 +173,13 @@ double Platform_setCPUValues(Meter* this, int cpu) {
v[CPU_METER_GUEST] = 0.0;
v[CPU_METER_IOWAIT] = 0.0;
v[CPU_METER_FREQUENCY] = NAN;
- Meter_setItems(this, 8);
+ this->curItems = 8;
totalPercent = v[0]+v[1]+v[2]+v[3];
} else {
v[2] = cpuData->sysAllPeriod / total * 100.0;
v[3] = 0.0; // No steal nor guest on OpenBSD
totalPercent = v[0]+v[1]+v[2];
- Meter_setItems(this, 4);
+ this->curItems = 4;
}
totalPercent = CLAMP(totalPercent, 0.0, 100.0);
diff --git a/solaris/Platform.c b/solaris/Platform.c
index 4a5daee6..5f737342 100644
--- a/solaris/Platform.c
+++ b/solaris/Platform.c
@@ -185,11 +185,11 @@ double Platform_setCPUValues(Meter* this, int cpu) {
if (this->pl->settings->detailedCPUTime) {
v[CPU_METER_KERNEL] = cpuData->systemPercent;
v[CPU_METER_IRQ] = cpuData->irqPercent;
- Meter_setItems(this, 4);
+ this->curItems = 4;
percent = v[0]+v[1]+v[2]+v[3];
} else {
v[2] = cpuData->systemAllPercent;
- Meter_setItems(this, 3);
+ this->curItems = 3;
percent = v[0]+v[1]+v[2];
}
diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c
index 94bffdc7..d52605c6 100644
--- a/zfs/ZfsArcMeter.c
+++ b/zfs/ZfsArcMeter.c
@@ -38,7 +38,7 @@ void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats) {
// "Hide" the last value so it can
// only be accessed by index and is not
// displayed by the Bar or Graph style
- Meter_setItems(this, 5);
+ this->curItems = 5;
this->values[5] = stats->size;
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy