Commit 33113fe0 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

- Overhaul meters implementation;

- add AllCPUsMeter;
- because of that, the new .htoprc is incompatible with previous released versions.
parent 34bcf805
...@@ -14,33 +14,26 @@ in the source distribution for its full text. ...@@ -14,33 +14,26 @@ in the source distribution for its full text.
#include "debug.h" #include "debug.h"
/*{ /* private property */
int TasksMeter_attributes[] = { TASKS_RUNNING };
typedef struct TasksMeter_ TasksMeter;
/* private */
struct TasksMeter_ { MeterType TasksMeter = {
Meter super; .setValues = TasksMeter_setValues,
ProcessList* pl; .display = TasksMeter_display,
.mode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = TasksMeter_attributes,
.name = "Tasks",
.uiName = "Task counter",
.caption = "Tasks: "
}; };
}*/ void TasksMeter_setValues(Meter* this, char* buffer, int len) {
this->total = this->pl->totalTasks;
TasksMeter* TasksMeter_new(ProcessList* pl) { this->values[0] = this->pl->runningTasks;
TasksMeter* this = malloc(sizeof(TasksMeter)); snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
Meter_init((Meter*)this, String_copy("Tasks"), String_copy("Tasks: "), 1);
((Meter*)this)->attributes[0] = TASKS_RUNNING;
((Object*)this)->display = TasksMeter_display;
((Meter*)this)->setValues = TasksMeter_setValues;
this->pl = pl;
Meter_setMode((Meter*)this, TEXT);
return this;
}
void TasksMeter_setValues(Meter* cast) {
TasksMeter* this = (TasksMeter*)cast;
cast->total = this->pl->totalTasks;
cast->values[0] = this->pl->runningTasks;
snprintf(cast->displayBuffer.c, 20, "%d/%d", (int) cast->values[0], (int) cast->total);
} }
void TasksMeter_display(Object* cast, RichString* out) { void TasksMeter_display(Object* cast, RichString* out) {
......
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically generated. */
#ifndef HEADER_TasksMeter #ifndef HEADER_TasksMeter
#define HEADER_TasksMeter #define HEADER_TasksMeter
...@@ -18,17 +18,8 @@ in the source distribution for its full text. ...@@ -18,17 +18,8 @@ in the source distribution for its full text.
#include "debug.h" #include "debug.h"
typedef struct TasksMeter_ TasksMeter;
struct TasksMeter_ { void TasksMeter_setValues(Meter* this, char* buffer, int len);
Meter super;
ProcessList* pl;
};
TasksMeter* TasksMeter_new(ProcessList* pl);
void TasksMeter_setValues(Meter* cast);
void TasksMeter_display(Object* cast, RichString* out); void TasksMeter_display(Object* cast, RichString* out);
......
...@@ -14,64 +14,45 @@ in the source distribution for its full text. ...@@ -14,64 +14,45 @@ in the source distribution for its full text.
#include "debug.h" #include "debug.h"
/*{ /* private property */
static int UptimeMeter_attributes[] = { UPTIME };
typedef struct UptimeMeter_ UptimeMeter;
/* private */
struct UptimeMeter_ { MeterType UptimeMeter = {
Meter super; .setValues = UptimeMeter_setValues,
ProcessList* pl; .display = NULL,
int seconds; .mode = TEXT_METERMODE,
int minutes; .items = 1,
int hours; .total = 100.0,
int days; .attributes = UptimeMeter_attributes,
.name = "Uptime",
.uiName = "Uptime",
.caption = "Uptime: "
}; };
}*/ void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
UptimeMeter* UptimeMeter_new() {
UptimeMeter* this = malloc(sizeof(UptimeMeter));
Meter_init((Meter*)this, String_copy("Uptime"), String_copy("Uptime: "), 1);
((Meter*)this)->attributes[0] = UPTIME;
((Object*)this)->display = UptimeMeter_display;
((Meter*)this)->setValues = UptimeMeter_setValues;
Meter_setMode((Meter*)this, TEXT);
((Meter*)this)->total = 100.0;
return this;
}
void UptimeMeter_setValues(Meter* cast) {
UptimeMeter* this = (UptimeMeter*)cast;
double uptime; double uptime;
FILE* fd = fopen(PROCDIR "/uptime", "r"); FILE* fd = fopen(PROCDIR "/uptime", "r");
fscanf(fd, "%lf", &uptime); fscanf(fd, "%lf", &uptime);
fclose(fd); fclose(fd);
int totalseconds = (int) ceil(uptime); int totalseconds = (int) ceil(uptime);
this->seconds = totalseconds % 60; int seconds = totalseconds % 60;
this->minutes = (totalseconds-this->seconds) % 3600 / 60; int minutes = (totalseconds-seconds) % 3600 / 60;
this->hours = (totalseconds-this->seconds-(this->minutes*60)) % 86400 / 3600; int hours = (totalseconds-seconds-(minutes*60)) % 86400 / 3600;
this->days = (totalseconds-this->seconds-(this->minutes*60)-(this->hours*3600)) / 86400; int days = (totalseconds-seconds-(minutes*60)-(hours*3600)) / 86400;
cast->values[0] = this->days; this->values[0] = days;
if (this->days > cast->total) { if (days > this->total) {
cast->total = this->days; this->total = days;
} }
snprintf(cast->displayBuffer.c, 14, "%d", this->days); char daysbuf[10];
} if (days > 100) {
sprintf(daysbuf, "%d days(!), ", days);
void UptimeMeter_display(Object* cast, RichString* out) { } else if (days > 1) {
UptimeMeter* this = (UptimeMeter*)cast; sprintf(daysbuf, "%d days, ", days);
char buffer[20]; } else if (days == 1) {
RichString_prune(out); sprintf(daysbuf, "1 day, ");
if (this->days > 100) { } else {
sprintf(buffer, "%d days, ", this->days); daysbuf[0] = '\0';
RichString_write(out, CRT_colors[LARGE_NUMBER], buffer);
} else if (this->days > 1) {
sprintf(buffer, "%d days, ", this->days);
RichString_write(out, CRT_colors[UPTIME], buffer);
} else if (this->days == 1) {
sprintf(buffer, "%d day, ", this->days);
RichString_write(out, CRT_colors[UPTIME], buffer);
} }
sprintf(buffer, "%02d:%02d:%02d ", this->hours, this->minutes, this->seconds); snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
RichString_append(out, CRT_colors[UPTIME], buffer);
} }
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically generated. */
#ifndef HEADER_UptimeMeter #ifndef HEADER_UptimeMeter
#define HEADER_UptimeMeter #define HEADER_UptimeMeter
...@@ -18,22 +18,7 @@ in the source distribution for its full text. ...@@ -18,22 +18,7 @@ in the source distribution for its full text.
#include "debug.h" #include "debug.h"
typedef struct UptimeMeter_ UptimeMeter;
struct UptimeMeter_ { void UptimeMeter_setValues(Meter* cast, char* buffer, int len);
Meter super;
ProcessList* pl;
int seconds;
int minutes;
int hours;
int days;
};
UptimeMeter* UptimeMeter_new();
void UptimeMeter_setValues(Meter* cast);
void UptimeMeter_display(Object* cast, RichString* out);
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment