htop/UptimeMeter.c

61 lines
1.5 KiB
C
Raw Permalink Normal View History

2006-03-04 18:16:49 +00:00
/*
2011-12-26 21:35:57 +00:00
htop - UptimeMeter.c
2011-05-26 16:35:07 +00:00
(C) 2004-2011 Hisham H. Muhammad
2006-03-04 18:16:49 +00:00
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "UptimeMeter.h"
2014-11-27 21:41:14 +00:00
#include "Platform.h"
2006-03-04 18:16:49 +00:00
#include "CRT.h"
2011-12-26 21:35:57 +00:00
/*{
#include "Meter.h"
}*/
int UptimeMeter_attributes[] = {
UPTIME
};
static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) {
2014-11-27 21:41:14 +00:00
int totalseconds = Platform_getUptime();
if (totalseconds == -1) {
xSnprintf(buffer, len, "(unknown)");
2014-11-27 21:41:14 +00:00
return;
2011-09-08 02:54:02 +00:00
}
int seconds = totalseconds % 60;
2009-03-11 13:26:39 +00:00
int minutes = (totalseconds/60) % 60;
int hours = (totalseconds/3600) % 24;
int days = (totalseconds/86400);
this->values[0] = days;
if (days > this->total) {
this->total = days;
2006-03-04 18:16:49 +00:00
}
char daysbuf[32];
if (days > 100) {
xSnprintf(daysbuf, sizeof(daysbuf), "%d days(!), ", days);
} else if (days > 1) {
xSnprintf(daysbuf, sizeof(daysbuf), "%d days, ", days);
} else if (days == 1) {
xSnprintf(daysbuf, sizeof(daysbuf), "1 day, ");
} else {
daysbuf[0] = '\0';
2006-03-04 18:16:49 +00:00
}
xSnprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
2006-03-04 18:16:49 +00:00
}
MeterClass UptimeMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete
},
.updateValues = UptimeMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 100.0,
.attributes = UptimeMeter_attributes,
.name = "Uptime",
.uiName = "Uptime",
.caption = "Uptime: "
};