summaryrefslogtreecommitdiffstats
path: root/UptimeMeter.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2006-04-10 20:40:38 +0000
committerHisham Muhammad <hisham@gobolinux.org>2006-04-10 20:40:38 +0000
commit33113fe0d73ea3299843b483f108ef5bcfcc944f (patch)
tree4c6b50b3bc6fbe9e1a44dd3b9c56e63571c83d73 /UptimeMeter.c
parent34bcf8050e56fc799efb1013cb92ba1b44bd6df1 (diff)
- Overhaul meters implementation;
- add AllCPUsMeter; - because of that, the new .htoprc is incompatible with previous released versions.
Diffstat (limited to 'UptimeMeter.c')
-rw-r--r--UptimeMeter.c83
1 files changed, 32 insertions, 51 deletions
diff --git a/UptimeMeter.c b/UptimeMeter.c
index 05da4e73..4b212450 100644
--- a/UptimeMeter.c
+++ b/UptimeMeter.c
@@ -14,64 +14,45 @@ in the source distribution for its full text.
#include "debug.h"
-/*{
-
-typedef struct UptimeMeter_ UptimeMeter;
-
-struct UptimeMeter_ {
- Meter super;
- ProcessList* pl;
- int seconds;
- int minutes;
- int hours;
- int days;
+/* private property */
+static int UptimeMeter_attributes[] = { UPTIME };
+
+/* private */
+MeterType UptimeMeter = {
+ .setValues = UptimeMeter_setValues,
+ .display = NULL,
+ .mode = TEXT_METERMODE,
+ .items = 1,
+ .total = 100.0,
+ .attributes = UptimeMeter_attributes,
+ .name = "Uptime",
+ .uiName = "Uptime",
+ .caption = "Uptime: "
};
-}*/
-
-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;
+void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
double uptime;
FILE* fd = fopen(PROCDIR "/uptime", "r");
fscanf(fd, "%lf", &uptime);
fclose(fd);
int totalseconds = (int) ceil(uptime);
- this->seconds = totalseconds % 60;
- this->minutes = (totalseconds-this->seconds) % 3600 / 60;
- this->hours = (totalseconds-this->seconds-(this->minutes*60)) % 86400 / 3600;
- this->days = (totalseconds-this->seconds-(this->minutes*60)-(this->hours*3600)) / 86400;
- cast->values[0] = this->days;
- if (this->days > cast->total) {
- cast->total = this->days;
+ int seconds = totalseconds % 60;
+ int minutes = (totalseconds-seconds) % 3600 / 60;
+ int hours = (totalseconds-seconds-(minutes*60)) % 86400 / 3600;
+ int days = (totalseconds-seconds-(minutes*60)-(hours*3600)) / 86400;
+ this->values[0] = days;
+ if (days > this->total) {
+ this->total = days;
}
- snprintf(cast->displayBuffer.c, 14, "%d", this->days);
-}
-
-void UptimeMeter_display(Object* cast, RichString* out) {
- UptimeMeter* this = (UptimeMeter*)cast;
- char buffer[20];
- RichString_prune(out);
- if (this->days > 100) {
- sprintf(buffer, "%d days, ", this->days);
- 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);
+ char daysbuf[10];
+ if (days > 100) {
+ sprintf(daysbuf, "%d days(!), ", days);
+ } else if (days > 1) {
+ sprintf(daysbuf, "%d days, ", days);
+ } else if (days == 1) {
+ sprintf(daysbuf, "1 day, ");
+ } else {
+ daysbuf[0] = '\0';
}
- sprintf(buffer, "%02d:%02d:%02d ", this->hours, this->minutes, this->seconds);
- RichString_append(out, CRT_colors[UPTIME], buffer);
+ snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
}

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