diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2006-04-10 20:40:38 +0000 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2006-04-10 20:40:38 +0000 |
commit | 33113fe0d73ea3299843b483f108ef5bcfcc944f (patch) | |
tree | 4c6b50b3bc6fbe9e1a44dd3b9c56e63571c83d73 /SwapMeter.c | |
parent | 34bcf8050e56fc799efb1013cb92ba1b44bd6df1 (diff) |
- Overhaul meters implementation;
- add AllCPUsMeter;
- because of that, the new .htoprc is incompatible with previous released versions.
Diffstat (limited to 'SwapMeter.c')
-rw-r--r-- | SwapMeter.c | 51 |
1 files changed, 21 insertions, 30 deletions
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 <assert.h> -/*{ - -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:"); |