Move UptimeMeter into platform-dependent area.

Set up environment to move other meters.
This commit is contained in:
Hisham Muhammad 2014-11-27 19:18:14 -02:00
parent b192af006f
commit 357e7a3243
10 changed files with 75 additions and 41 deletions

View File

@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "CPUMeter.h" #include "CPUMeter.h"
#include "Header.h" #include "Header.h"
#include "ListItem.h" #include "ListItem.h"
#include "Platform.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
@ -56,7 +57,7 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
case 'l': case 'l':
case 'L': case 'L':
{ {
AvailableMetersPanel_addHeader(header, this->leftPanel, Meter_types[type], param, LEFT_HEADER); AvailableMetersPanel_addHeader(header, this->leftPanel, Platform_meterTypes[type], param, LEFT_HEADER);
result = HANDLED; result = HANDLED;
break; break;
} }
@ -64,7 +65,7 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
case 'r': case 'r':
case 'R': case 'R':
{ {
AvailableMetersPanel_addHeader(header, this->rightPanel, Meter_types[type], param, RIGHT_HEADER); AvailableMetersPanel_addHeader(header, this->rightPanel, Platform_meterTypes[type], param, RIGHT_HEADER);
result = HANDLED; result = HANDLED;
break; break;
} }
@ -97,8 +98,8 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMe
this->scr = scr; this->scr = scr;
Panel_setHeader(super, "Available meters"); Panel_setHeader(super, "Available meters");
for (int i = 1; Meter_types[i]; i++) { for (int i = 1; Platform_meterTypes[i]; i++) {
MeterClass* type = Meter_types[i]; MeterClass* type = Platform_meterTypes[i];
if (type != &CPUMeter_class) { if (type != &CPUMeter_class) {
Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16)); Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16));
} }

View File

@ -9,6 +9,7 @@ in the source distribution for its full text.
#include "CRT.h" #include "CRT.h"
#include "String.h" #include "String.h"
#include "Platform.h"
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
@ -66,7 +67,7 @@ void Header_createMeter(Header* this, char* name, HeaderSide side) {
if (!ok) param = 0; if (!ok) param = 0;
*paren = '\0'; *paren = '\0';
} }
for (MeterClass** type = Meter_types; *type; type++) { for (MeterClass** type = Platform_meterTypes; *type; type++) {
if (String_eq(name, (*type)->name)) { if (String_eq(name, (*type)->name)) {
Vector_add(meters, Meter_new(this->pl, param, *type)); Vector_add(meters, Meter_new(this->pl, param, *type));
break; break;

View File

@ -21,7 +21,7 @@ DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \ SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \
UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \
HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c
myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \
@ -30,15 +30,17 @@ CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \ ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
TraceScreen.h UptimeMeter.h UsersTable.h Vector.h Process.h AffinityPanel.h \ TraceScreen.h UsersTable.h Vector.h Process.h AffinityPanel.h \
HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h
if HTOP_LINUX if HTOP_LINUX
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c \
linux/UptimeMeter.c
myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \ myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h \
linux/UptimeMeter.h
endif endif
if HTOP_UNSUPPORTED if HTOP_UNSUPPORTED

30
Meter.c
View File

@ -7,15 +7,6 @@ in the source distribution for its full text.
#include "Meter.h" #include "Meter.h"
#include "CPUMeter.h"
#include "MemoryMeter.h"
#include "SwapMeter.h"
#include "TasksMeter.h"
#include "LoadAverageMeter.h"
#include "UptimeMeter.h"
#include "BatteryMeter.h"
#include "ClockMeter.h"
#include "HostnameMeter.h"
#include "RichString.h" #include "RichString.h"
#include "Object.h" #include "Object.h"
#include "CRT.h" #include "CRT.h"
@ -126,27 +117,6 @@ MeterClass Meter_class = {
} }
}; };
MeterClass* Meter_types[] = {
&CPUMeter_class,
&ClockMeter_class,
&LoadAverageMeter_class,
&LoadMeter_class,
&MemoryMeter_class,
&SwapMeter_class,
&TasksMeter_class,
&UptimeMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&LeftCPUsMeter_class,
&RightCPUsMeter_class,
&LeftCPUs2Meter_class,
&RightCPUs2Meter_class,
&BlankMeter_class,
NULL
};
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type) { Meter* Meter_new(ProcessList* pl, int param, MeterClass* type) {
Meter* this = calloc(1, sizeof(Meter)); Meter* this = calloc(1, sizeof(Meter));
Object_setClass(this, type); Object_setClass(this, type);

View File

@ -99,8 +99,6 @@ typedef struct GraphData_ {
extern MeterClass Meter_class; extern MeterClass Meter_class;
extern MeterClass* Meter_types[];
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type); Meter* Meter_new(ProcessList* pl, int param, MeterClass* type);
void Meter_delete(Object* cast); void Meter_delete(Object* cast);

View File

@ -9,6 +9,16 @@ in the source distribution for its full text.
#include "IOPriority.h" #include "IOPriority.h"
#include "IOPriorityPanel.h" #include "IOPriorityPanel.h"
#include "LinuxProcess.h" #include "LinuxProcess.h"
#include "Meter.h"
#include "CPUMeter.h"
#include "MemoryMeter.h"
#include "SwapMeter.h"
#include "TasksMeter.h"
#include "LoadAverageMeter.h"
#include "UptimeMeter.h"
#include "BatteryMeter.h"
#include "ClockMeter.h"
#include "HostnameMeter.h"
/*{ /*{
#include "Action.h" #include "Action.h"
@ -35,3 +45,25 @@ static Htop_Reaction Platform_actionSetIOPriority(Panel* panel, ProcessList* pl,
void Platform_setBindings(Htop_Action* keys) { void Platform_setBindings(Htop_Action* keys) {
keys['i'] = Platform_actionSetIOPriority; keys['i'] = Platform_actionSetIOPriority;
} }
MeterClass* Platform_meterTypes[] = {
&CPUMeter_class,
&ClockMeter_class,
&LoadAverageMeter_class,
&LoadMeter_class,
&MemoryMeter_class,
&SwapMeter_class,
&TasksMeter_class,
&UptimeMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&LeftCPUsMeter_class,
&RightCPUsMeter_class,
&LeftCPUs2Meter_class,
&RightCPUs2Meter_class,
&BlankMeter_class,
NULL
};

View File

@ -6,6 +6,14 @@ in the source distribution for its full text.
*/ */
#include "Platform.h" #include "Platform.h"
#include "CPUMeter.h"
#include "MemoryMeter.h"
#include "SwapMeter.h"
#include "TasksMeter.h"
#include "LoadAverageMeter.h"
#include "BatteryMeter.h"
#include "ClockMeter.h"
#include "HostnameMeter.h"
/*{ /*{
#include "Action.h" #include "Action.h"
@ -15,3 +23,23 @@ void Platform_setBindings(Htop_Action* keys) {
(void) keys; (void) keys;
} }
MeterClass* Platform_meterTypes[] = {
&CPUMeter_class,
&ClockMeter_class,
&LoadAverageMeter_class,
&LoadMeter_class,
&MemoryMeter_class,
&SwapMeter_class,
&TasksMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&LeftCPUsMeter_class,
&RightCPUsMeter_class,
&LeftCPUs2Meter_class,
&RightCPUs2Meter_class,
&BlankMeter_class,
NULL
};

View File

@ -13,5 +13,7 @@ in the source distribution for its full text.
void Platform_setBindings(Htop_Action* keys); void Platform_setBindings(Htop_Action* keys);
extern MeterClass* Platform_meterTypes[];
#endif #endif