From 33113fe0d73ea3299843b483f108ef5bcfcc944f Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 10 Apr 2006 20:40:38 +0000 Subject: - Overhaul meters implementation; - add AllCPUsMeter; - because of that, the new .htoprc is incompatible with previous released versions. --- SwapMeter.c | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) (limited to 'SwapMeter.c') diff --git a/SwapMeter.c b/SwapMeter.c index 46897152..7b295e96 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -19,45 +19,36 @@ in the source distribution for its full text. #include "debug.h" #include -/*{ - -typedef struct SwapMeter_ SwapMeter; - -struct SwapMeter_ { - Meter super; - ProcessList* pl; +/* private property */ +static int SwapMeter_attributes[] = { SWAP }; + +/* private */ +MeterType SwapMeter = { + .setValues = SwapMeter_setValues, + .display = SwapMeter_display, + .mode = BAR_METERMODE, + .items = 1, + .total = 100.0, + .attributes = SwapMeter_attributes, + .name = "Swap", + .uiName = "Swap", + .caption = "Swp" }; -}*/ - -SwapMeter* SwapMeter_new(ProcessList* pl) { - SwapMeter* this = malloc(sizeof(SwapMeter)); - Meter_init((Meter*)this, String_copy("Swap"), String_copy("Swp"), 1); - ((Meter*)this)->attributes[0] = SWAP; - ((Meter*)this)->setValues = SwapMeter_setValues; - ((Object*)this)->display = SwapMeter_display; - this->pl = pl; - Meter_setMode((Meter*)this, BAR); - return this; -} - -void SwapMeter_setValues(Meter* cast) { - SwapMeter* this = (SwapMeter*)cast; - - double totalSwap = (double)this->pl->totalSwap; +void SwapMeter_setValues(Meter* this, char* buffer, int len) { long int usedSwap = this->pl->usedSwap; - cast->total = totalSwap; - cast->values[0] = usedSwap; - snprintf(cast->displayBuffer.c, 14, "%ld/%ldMB", usedSwap / 1024, this->pl->totalSwap / 1024); + this->total = this->pl->totalSwap; + this->values[0] = usedSwap; + snprintf(buffer, len, "%ld/%ldMB", (long int) usedSwap / 1024, (long int) this->total / 1024); } void SwapMeter_display(Object* cast, RichString* out) { char buffer[50]; - Meter* meter = (Meter*)cast; - long int swap = (long int) meter->values[0]; + Meter* this = (Meter*)cast; + long int swap = (long int) this->values[0]; RichString_prune(out); RichString_append(out, CRT_colors[METER_TEXT], ":"); - sprintf(buffer, "%ldM ", (long int) meter->total / 1024); + sprintf(buffer, "%ldM ", (long int) this->total / 1024); RichString_append(out, CRT_colors[METER_VALUE], buffer); sprintf(buffer, "%ldk", swap); RichString_append(out, CRT_colors[METER_TEXT], "used:"); -- cgit v1.2.3