clean up lcdproc client and add menu support (to be enabled at compile time) -

based upon patch by Andrew Foss
This commit is contained in:
marschap
2006-02-18 19:50:50 +00:00
parent d77ada0bde
commit 6bc60a92fe
20 changed files with 224 additions and 510 deletions
+1 -12
View File
@@ -71,24 +71,13 @@ battery_status(int status)
// +--------------------+
//
int
#ifdef LCDPROC_MENUS
battery_screen (int rep, int display, int * flags_ptr)
#else
battery_screen (int rep, int display)
#endif
battery_screen (int rep, int display, int *flags_ptr)
{
int acstat = 0, battstat = 0, percent = 0;
int gauge_wid = lcd_wid - 2;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string (sock, "screen_add B\n");
sprintf (buffer, "screen_set B -name {APM stats: %s}\n", get_hostname());
+1 -5
View File
@@ -1,10 +1,6 @@
#ifndef BATT_H
#define BATT_H
#ifdef LCDPROC_MENUS
int battery_screen (int rep, int display, int * flags_ptr);
#else
int battery_screen (int rep, int display);
#endif
int battery_screen (int rep, int display, int *flags_ptr);
#endif
+11 -66
View File
@@ -96,11 +96,7 @@ static char *shortmonths[] = {
//+--------------------+
//
int
#ifdef LCDPROC_MENUS
time_screen (int rep, int display, int * flags_ptr)
#else
time_screen (int rep, int display)
#endif
time_screen (int rep, int display, int *flags_ptr)
{
char now[20];
char day[16], month[16];
@@ -111,16 +107,9 @@ time_screen (int rep, int display)
time_t thetime;
struct tm *rtime;
double uptime, idle;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string (sock, "screen_add T\n");
sprintf (buffer, "screen_set T -name {Time Screen: %s}\n", get_hostname());
@@ -222,11 +211,7 @@ time_screen (int rep, int display)
//+--------------------+
//
int
#ifdef LCDPROC_MENUS
clock_screen (int rep, int display, int * flags_ptr)
#else
clock_screen (int rep, int display)
#endif
clock_screen (int rep, int display, int *flags_ptr)
{
char now[20];
char day[16], month[16];
@@ -235,16 +220,9 @@ clock_screen (int rep, int display)
static char colon[] = {':', ' '};
time_t thetime;
struct tm *rtime;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string (sock, "screen_add O\n");
sprintf (buffer, "screen_set O -name {Old Clock Screen: %s}\n", get_hostname());
@@ -326,27 +304,16 @@ clock_screen (int rep, int display)
//+--------------------+
//
int
#ifdef LCDPROC_MENUS
uptime_screen (int rep, int display, int * flags_ptr)
#else
uptime_screen (int rep, int display)
#endif
uptime_screen (int rep, int display, int *flags_ptr)
{
int xoffs;
int days, hour, min, sec;
double uptime, idle;
static int heartbeat = 0;
static char colon[] = {':', ' '};
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string (sock, "screen_add U\n");
sprintf (buffer, "screen_set U -name {Uptime Screen: %s}\n", get_hostname());
@@ -413,11 +380,7 @@ uptime_screen (int rep, int display)
// +--------------------+
//
int
#ifdef LCDPROC_MENUS
big_clock_screen (int rep, int display, int * flags_ptr)
#else
big_clock_screen (int rep, int display)
#endif
big_clock_screen (int rep, int display, int *flags_ptr)
{
time_t thetime;
struct tm *rtime;
@@ -432,16 +395,9 @@ big_clock_screen (int rep, int display)
// toggle colon display
heartbeat ^= 1;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string (sock, "screen_add K\n");
sock_send_string (sock, "screen_set K -name {Big Clock Screen} -heartbeat off\n");
@@ -490,7 +446,7 @@ big_clock_screen (int rep, int display)
//////////////////////////////////////////////////////////////////////
// Essential Clock Screen displays the current time with hours & minutes only
// Mini Clock Screen displays the current time with hours & minutes only
//
//+--------------------+ +--------------------+
//| | | 11:32 |
@@ -500,38 +456,27 @@ big_clock_screen (int rep, int display)
//+--------------------+
//
int
#ifdef LCDPROC_MENUS
essential_clock_screen (int rep, int display, int * flags_ptr)
#else
essential_clock_screen (int rep, int display)
#endif
mini_clock_screen (int rep, int display, int *flags_ptr)
{
struct tm *rtime;
struct timeval ttime;
static char colon[] = {':', ' '};
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string (sock, "screen_add E\n");
sock_send_string (sock, "screen_set E -name {Essential Clock Screen} -heartbeat off\n");
sock_send_string (sock, "widget_add E one string\n");
sock_send_string (sock, "screen_add N\n");
sock_send_string (sock, "screen_set N -name {Essential Clock Screen} -heartbeat off\n");
sock_send_string (sock, "widget_add N one string\n");
}
gettimeofday(&ttime, NULL);
rtime = localtime (&ttime.tv_sec);
sprintf(tmp, "%02d%c%02d", rtime->tm_hour, colon[(ttime.tv_usec / 500000) & 1], rtime->tm_min);
sprintf(buffer, "widget_set E one %d %d {%s}\n",
sprintf(buffer, "widget_set N one %d %d {%s}\n",
((lcd_wid - 5) / 2) + 1, (lcd_hgt / 2), tmp);
sock_send_string (sock, buffer);
return 0;
} // End essential_clock_screen()
} // End mini_clock_screen()
+5 -13
View File
@@ -1,18 +1,10 @@
#ifndef CHRONO_H
#define CHRONO_H
#ifdef LCDPROC_MENUS
int clock_screen (int rep, int display, int * flags_ptr);
int uptime_screen (int rep, int display, int * flags_ptr);
int time_screen (int rep, int display, int * flags_ptr);
int big_clock_screen (int rep, int display, int * flags_ptr);
int essential_clock_screen (int rep, int display, int * flags_ptr);
#else
int clock_screen (int rep, int display);
int uptime_screen (int rep, int display);
int time_screen (int rep, int display);
int big_clock_screen (int rep, int display);
int essential_clock_screen (int rep, int display);
#endif
int clock_screen (int rep, int display, int *flags_ptr);
int uptime_screen (int rep, int display, int *flags_ptr);
int time_screen (int rep, int display, int *flags_ptr);
int big_clock_screen (int rep, int display, int *flags_ptr);
int mini_clock_screen (int rep, int display, int *flags_ptr);
#endif
+2 -23
View File
@@ -29,11 +29,7 @@
// +--------------------+
//
int
#ifdef LCDPROC_MENUS
cpu_screen(int rep, int display, int * flags_ptr)
#else
cpu_screen(int rep, int display)
#endif
cpu_screen(int rep, int display, int *flags_ptr)
{
#undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 4
@@ -44,16 +40,9 @@ cpu_screen(int rep, int display)
int i, j, n;
double value;
load_type load;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string(sock, "screen_add C\n");
sprintf(buffer, "screen_set C -name {CPU Use: %s}\n", get_hostname());
@@ -218,11 +207,7 @@ cpu_screen(int rep, int display)
// +--------------------+
//
int
#ifdef LCDPROC_MENUS
cpu_graph_screen(int rep, int display, int * flags_ptr)
#else
cpu_graph_screen(int rep, int display)
#endif
cpu_graph_screen(int rep, int display, int *flags_ptr)
{
#undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 2
@@ -233,16 +218,10 @@ cpu_graph_screen(int rep, int display)
int i, n = 0;
double value ;
load_type load;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
sock_send_string(sock, "screen_add G\n");
+2 -7
View File
@@ -1,12 +1,7 @@
#ifndef CPU_H
#define CPU_H
#ifdef LCDPROC_MENUS
int cpu_screen (int rep, int display, int * flags_ptr);
int cpu_graph_screen (int rep, int display, int * flags_ptr);
#else
int cpu_screen (int rep, int display);
int cpu_graph_screen (int rep, int display);
#endif
int cpu_screen (int rep, int display, int *flags_ptr);
int cpu_graph_screen (int rep, int display, int *flags_ptr);
#endif
+1 -12
View File
@@ -65,11 +65,7 @@ static char *numnames[MAX_CPUS] = { "one", "two", "three", "four", "five", "six"
// CPU screen shows info about percentage of the CPU being used
//
int
#ifdef LCDPROC_MENUS
cpu_smp_screen (int rep, int display, int * flags_ptr)
#else
cpu_smp_screen (int rep, int display)
#endif
cpu_smp_screen (int rep, int display, int *flags_ptr)
{
#undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 4
@@ -80,16 +76,9 @@ cpu_smp_screen (int rep, int display)
int numprocs;
char buf[256];
char *graphsize;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
machine_get_smpload (load, &numprocs);
+1 -5
View File
@@ -1,10 +1,6 @@
#ifndef CPU_SMP_H
#define CPU_SMP_H
#ifdef LCDPROC_MENUS
int cpu_smp_screen (int rep, int display, int * flags_ptr);
#else
int cpu_smp_screen (int rep, int display);
#endif
int cpu_smp_screen (int rep, int display, int *flags_ptr);
#endif
+1 -11
View File
@@ -32,11 +32,7 @@
//
// TODO: Disk screen! Requires virtual pages in the server, though...
int
#ifdef LCDPROC_MENUS
disk_screen (int rep, int display, int * flags_ptr)
#else
disk_screen (int rep, int display)
#endif
disk_screen (int rep, int display, int *flags_ptr)
{
static mounts_type mnt[256];
static int count = 0;
@@ -54,16 +50,10 @@ disk_screen (int rep, int display)
#define huge long long int
huge size;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
dev_wid = (lcd_wid >= 20) ? (lcd_wid - 8) / 2 : (lcd_wid / 2) - 1;
gauge_wid = (lcd_wid >= 20) ? (lcd_wid - dev_wid - 10) : (lcd_wid - dev_wid - 3);
+1 -5
View File
@@ -1,10 +1,6 @@
#ifndef DISK_H
#define DISK_H
#ifdef LCDPROC_MENUS
int disk_screen (int rep, int display, int * flags_ptr);
#else
int disk_screen (int rep, int display);
#endif
int disk_screen (int rep, int display, int *flags_ptr);
#endif
+1 -11
View File
@@ -26,27 +26,17 @@
// +--------------------+
//
int
#ifdef LCDPROC_MENUS
xload_screen (int rep, int display, int * flags_ptr)
#else
xload_screen (int rep, int display)
#endif
xload_screen (int rep, int display, int *flags_ptr)
{
static int gauge_hgt = 0;
static double loads[LCD_MAX_WIDTH];
int loadtop, i;
double loadmax = 0, factor;
int status = 0;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
memset (loads, '\0', sizeof (double) * LCD_MAX_WIDTH);
+1 -5
View File
@@ -8,10 +8,6 @@
#define LOAD_MIN 0.5
#endif
#ifdef LCDPROC_MENUS
int xload_screen (int rep, int display, int * flags_ptr);
#else
int xload_screen (int rep, int display);
#endif
int xload_screen (int rep, int display, int *flags_ptr);
#endif
+94 -185
View File
@@ -41,7 +41,7 @@ static struct utsname unamebuf;
See below... (default_sequence[])
*/
static void HelpScreen();
static void HelpScreen(int exit_state);
static void exit_program(int val);
static void main_loop();
@@ -51,48 +51,27 @@ static int islow = -1;
#define TIME_UNIT 125000
/* list of modes to run */
#ifdef LCDPROC_MENUS
mode sequence[] =
{
// flags default ACTIVE will run by default
// longname which on off inv timer flags
// longname which on off inv timer flags
{ "CPU", 'C', 1, 2, 0, 0xffff, ACTIVE,}, // [C]PU
{ "Memory", 'M', 4, 16, 0, 0xffff, ACTIVE,}, // [M]emory
{ "Load", 'X', 64, 128, 1, 0xffff, ACTIVE,}, // [X]-load (load histogram)
{ "Load", 'L', 64, 128, 1, 0xffff, ACTIVE,}, // [L]oad (load histogram)
{ "TimeDate", 'T', 4, 64, 0, 0xffff, ACTIVE,}, // [T]ime/Date
{ "About", 'A', 999, 9999, 0, 0xffff, ACTIVE,}, // [A]bout (credits)
#else
mode *sequence = NULL;
mode default_sequence[] =
{
// longname which on off inv timer visible/flags
{ "CPU", 'C', 1, 2, 0, 0xffff, 0,}, // [C]PU
{ "Memory", 'M', 4, 16, 0, 0xffff, 0,}, // [M]emory
{ "Load", 'X', 64, 128, 1, 0xffff, 0,}, // [X]-load (load histogram)
{ "TimeDate", 'T', 4, 64, 0, 0xffff, 0,}, // [T]ime/Date
{ "About", 'A', 999, 9999, 0, 0xffff, 0,}, // [A]bout (credits)
{ NULL, 1, 0, 0, 0, 0, 0,}, // Modes after this line will not be run by default...
// ... all non-default modes must be in here!
// ... they will not show up otherwise.
#endif
{ "SMP-CPU", 'P', 1, 2, 0, 0xffff, 0,}, // CPU_SM[P]
{ "OldTime", 'O', 4, 64, 0, 0xffff, 0,}, // [O]ld Timescreen
{ "BigClock", 'K', 4, 64, 0, 0xffff, 0,}, // big cloc[K]
{ "Uptime", 'U', 4, 128, 0, 0xffff, 0,}, // Old [U]ptime Screen
{ "Battery", 'B', 32, 256, 1, 0xffff, 0,}, // [B]attery Status
{ "CPUGraph", 'G', 1, 2, 0, 0xffff, 0,}, // CPU histogram [G]raph
{ "ProcSize", 'S', 16, 256, 1, 0xffff, 0,}, // [S]ize of biggest programs
{ "ProcSize", 'S', 16, 256, 1, 0xffff, 0,}, // [S]ize of biggest processes
{ "Disk", 'D', 256, 256, 1, 0xffff, 0,}, // [D]isk stats
{ "MiniClock", 'E', 4, 64, 0, 0xffff, 0,}, // [E]ssential clock
{ "MiniClock", 'N', 4, 64, 0, 0xffff, 0,}, // Mi[n]i clock
{ NULL, 0, 0, 0, 0, 0,}, // No more.. all done.
};
#ifdef LCDPROC_MENUS
int seqlen = sizeof(sequence) / sizeof(mode);
#else
int seqlen = sizeof(default_sequence) / sizeof(mode);
#endif //LCDPROC_MENUS
// TODO: Config file; not just command line
@@ -112,18 +91,18 @@ const char *get_sysrelease()
return(unamebuf.release);
}
#ifdef LCDPROC_MENUS //set_mode function
int set_mode(int shortname, char * longname, int state)
int set_mode(int shortname, char *longname, int state)
{
int k;
/* ignore already selected modes */
for (k = 0; (k < seqlen) && (sequence[k].which != 0); k++) {
for (k = 0; sequence[k].which != 0; k++) {
if (((sequence[k].longname != NULL) &&
(0 == strcasecmp(longname, sequence[k].longname))) ||
(shortname == sequence[k].which)) {
(toupper(shortname) == sequence[k].which)) {
if (!state) {
sequence[k].flags &= (~ACTIVE & ~INITIALIZED); /* both the active and inititialized bits */
/* clean both the active and inititialized bits since we delete the screen */
sequence[k].flags &= (~ACTIVE & ~INITIALIZED);
sprintf (buffer, "screen_del %c\n", shortname );
sock_send_string (sock, buffer);
} else
@@ -138,11 +117,10 @@ void clear_modes()
{
int k;
/* ignore already selected modes */
for (k = 0; (k < seqlen) && (sequence[k].which != 0); k++) {
for (k = 0; sequence[k].which != 0; k++) {
sequence[k].flags &= (~ACTIVE);
}
}
#endif //LCDPROC_MENUS
int
main(int argc, char **argv)
@@ -159,23 +137,6 @@ main(int argc, char **argv)
return(EXIT_FAILURE);
}
#ifdef LCDPROC_MENUS
// sequence = default_sequence;
#else
/* allocate sequence */
sequence = (mode *) malloc(seqlen * sizeof(mode));
if (sequence == NULL) {
perror("sequence malloc");
return(EXIT_FAILURE);
}
/* copy default_sequence[] to sequence */
for (i = 0; i < seqlen; i++) {
//sequence[i] = default_sequence[i];
memcpy(&sequence[i], &default_sequence[i], sizeof(mode));
}
#endif //LCDPROC_MENUS
/* setup error handlers */
signal(SIGINT, exit_program); // Ctrl-C
signal(SIGTERM, exit_program); // "regular" kill
@@ -186,7 +147,7 @@ main(int argc, char **argv)
opterr = 0;
/* get options */
while ((c = getopt( argc, argv, "s:p:e:d")) > 0) {
while ((c = getopt( argc, argv, "s:p:e:dhv")) > 0) {
switch (c) {
// s is for server
case 's':
@@ -209,59 +170,29 @@ main(int argc, char **argv)
case 'd':
daemonize = TRUE;
break;
case 'h':
HelpScreen(EXIT_SUCCESS);
break;
case 'v':
fprintf(stderr, "LCDproc %s\n", version);
exit(EXIT_SUCCESS);
break;
// otherwise... Get help!
case '?': // unknown option or missing argument
default:
HelpScreen();
HelpScreen(EXIT_FAILURE);
break;
}
}
#ifdef LCDPROC_MENUS
/* parse arguments */
if (argc > 1 ) //user specified some modes, so clear all defaults
if (argc > optind) //user specified some modes, so clear all defaults
clear_modes();
for (i = (optind > 0) ? optind : 1; i < argc; i++) {
for (i = max(optind, 1); i < argc; i++) {
int shortname = (strlen(argv[i]) == 1) ? toupper(argv[i][0]) : '\0';
int found = set_mode(shortname, argv[i], 1);
#else
/* parse arguments */
for (i = (optind > 0) ? optind : 1, j = 0; i < argc; i++) {
int shortname = (strlen(argv[i]) == 1) ? toupper(argv[i][0]) : '\0';
int k, found = FALSE;
/* skip this round if we used all allocated slots */
if (j >= seqlen)
continue;
/* ignore already selected modes */
for (k = 0; (k < j) && (sequence[k].which != 0); k++) {
if (((sequence[k].longname != NULL) &&
(0 == strcasecmp(argv[i], sequence[k].longname))) ||
(shortname == sequence[k].which)) {
found = TRUE;
}
}
if (found) {
fprintf(stderr, "Warning: ignoring duplicate mode\n");
continue;
}
// try to find the mode from the mode list
for (k = 0; k < seqlen; k++) {
if (((default_sequence[k].longname != NULL) &&
(0 == strcasecmp(argv[i], default_sequence[k].longname))) ||
(shortname == default_sequence[k].which)) {
//sequence[j] = default_sequence[k];
memcpy(&sequence[j], &default_sequence[k], sizeof(mode));
j++;
//sequence[j] = default_sequence[seqlen-1];
memcpy(&sequence[j], &default_sequence[seqlen-1], sizeof(mode));
found = TRUE;
break;
}
}
#endif
if (!found) {
fprintf(stderr, "Invalid Mode: %c, ignoring\n", argv[i][0]);
return(EXIT_FAILURE);
@@ -310,22 +241,38 @@ main(int argc, char **argv)
}
void
HelpScreen ()
HelpScreen (int exit_state)
{
printf("LCDproc, %s\n", version);
printf("Usage: lcdproc [-s server] [-p port] [-e islow] [-d] [modelist]\n");
printf("\tOptions in []'s are optional.\n");
printf("\tmodelist is \"mode [mode mode ...]\"\n");
printf ("\tMode letters:\t[C]pu [G]raph [T]ime [M]emory [X]load [D]isk [B]attery\n"
"\t\t\tproc_[S]izes [O]ld_time big_cloc[K] [E]ssential_clock\n"
"\t\t\t[U]ptime CPU_SM[P] [A]bout\n");
printf("\n");
printf("\tislow is to slow down initial announcement of modes (in 1/100 sec)\n");
printf("\tUse \"man lcdproc\" for more info.\n");
printf("Example:\n");
printf("\tlcdproc -s my.lcdproc.server.com C M X -p 13666\n");
printf("\n");
exit(EXIT_FAILURE);
fprintf(stderr,
"Usage: lcdproc [<options>] [<modes> ...]\n"
" where <options> are\n"
" -s <host> connect to LCDd daemon on <host>\n"
" -p <port> connect to LCDd daemon using <port>\n"
" -d daemonize\n"
" -e <delay> slow down initial announcement of modes (in 1/100s)\n"
" -h show this help screen\n"
" -v display program version\n"
" and <modes> are\n"
" C CPU detailed CPU usage\n"
" P SMP-CPU CPU usage overview (one line per CPU)\n"
" G CPUGraph CPU usage histogram\n"
" L Load load histogram\n"
" M Memory memory & swap usage\n"
" S ProcSize biggest processes size\n"
" D Disk disk usage\n"
" B Battery battery status\n"
" T TimeDate time & date information\n"
" O OldTime old time screen\n"
" U Uptime old uptime screen\n"
" K BigClock big clock\n"
" N MiniClock minimal clock\n"
" A About credits page\n"
"\n"
"Example:\n"
" lcdproc -s my.lcdproc.server.com p 13666 C M X\n"
);
exit(exit_state);
}
///////////////////////////////////////////////////////////////////
@@ -338,13 +285,10 @@ exit_program(int val)
Quit = 1;
sock_close(sock);
mode_close();
#ifndef LCDPROC_MENUS
free(sequence);
#endif
exit(val);
}
#ifdef LCDPROC_MENUS //menus_init
#ifdef LCDPROC_MENUS
int
menus_init ()
{
@@ -352,12 +296,14 @@ menus_init ()
for (k = 0; sequence[k].which ; k++) {
if (sequence[k].longname) {
sprintf (buffer, "menu_add_item {} %c checkbox {%s} -value %s\n", sequence[k].which, sequence[k].longname, sequence[k].flags & ACTIVE ? "on" : "off");
sprintf (buffer, "menu_add_item {} %c checkbox {%s} -value %s\n",
sequence[k].which, sequence[k].longname,
(sequence[k].flags & ACTIVE) ? "on" : "off");
sock_send_string (sock, buffer);
}
}
#ifdef TESTMENUS
#ifdef LCDPROC_CLIENT_TESTMENUS
// # to be entered on escape from test_menu (but overwritten
// # for test_{checkbox,ring}
sock_send_string (sock, "menu_add_item {} ask menu {Leave menus?} -is_hidden true\n");
@@ -386,11 +332,13 @@ menus_init ()
sock_send_string (sock, "menu_set_item {test} test_alpha -next {test_ip} -prev {test_numeric}\n");
sock_send_string (sock, "menu_set_item {test} test_ip -next {test_menu} -prev {test_alpha}\n");
sock_send_string (sock, "menu_set_item {test} test_menu_action -next {_close_}\n");
#endif //TESTMENUS
#endif //LCDPROC_CLIENT_TESTMENUS
return 0;
}
#endif //LCDPROC_MENUS
///////////////////////////////////////////////////////////////////
// Main program loop...
//
@@ -406,22 +354,19 @@ main_loop()
// Main loop
// Run whatever screen we want, then wait. Woo-hoo!
while (!Quit)
{
while (!Quit) {
// Check for server input...
len = sock_recv(sock, buf, 8000);
// Handle server input...
while (len > 0)
{
while (len > 0) {
// Now split the string into tokens...
//for (i=0; i<argc; i++) argv[i]=NULL; // Get rid of old tokens
argc = 0;
newtoken = 1;
for (i = 0; i < len; i++)
{
switch (buf[i])
{
for (i = 0; i < len; i++) {
switch (buf[i]) {
case ' ':
newtoken = 1;
buf[i] = 0;
@@ -434,61 +379,40 @@ main_loop()
case '\0':
case '\n':
buf[i] = 0;
if (argc > 0)
{
if (argc > 0) {
//printf("%s %s\n", argv[0], argv[1]);
if (0 == strcmp(argv[0], "listen"))
{
for (j = 0; sequence[j].which; j++)
{
if (sequence[j].which == argv[1][0])
{
#ifdef LCDPROC_MENUS
if (0 == strcmp(argv[0], "listen")) {
for (j = 0; sequence[j].which; j++) {
if (sequence[j].which == argv[1][0]) {
sequence[j].flags |= VISIBLE;
#else
sequence[j].visible = 1;
#endif
//debug("Listen %s\n", argv[1]);
}
}
}
else if (0 == strcmp(argv[0], "ignore"))
{
for (j = 0; sequence[j].which; j++)
{
if (sequence[j].which == argv[1][0])
{
#ifdef LCDPROC_MENUS
else if (0 == strcmp(argv[0], "ignore")) {
for (j = 0; sequence[j].which; j++) {
if (sequence[j].which == argv[1][0]) {
sequence[j].flags &= ~VISIBLE;
#else
sequence[j].visible = 0;
#endif
//debug("Ignore %s\n", argv[1]);
}
}
}
else if (0 == strcmp(argv[0], "key"))
{
else if (0 == strcmp(argv[0], "key")) {
debug("Key %s\n", argv[1]);
}
#ifdef LCDPROC_MENUS
else if (0 == strcmp(argv[0], "menuevent"))
{
if (argc == 4 && (0 == strcmp(argv[1], "update")))
{
else if (0 == strcmp(argv[0], "menuevent")) {
if (argc == 4 && (0 == strcmp(argv[1], "update"))) {
set_mode(argv[2][0],"", strcmp(argv[3],"off"));
}
}
#else
else if (0 == strcmp(argv[0], "menu"))
{
else if (0 == strcmp(argv[0], "menu")) {
}
#endif
else if (0 == strcmp(argv[0], "connect"))
{
else if (0 == strcmp(argv[0], "connect")) {
int a;
for (a = 1; a < argc; a++)
{
for (a = 1; a < argc; a++) {
if (0 == strcmp(argv[a], "wid"))
lcd_wid = atoi(argv[++a]);
else if (0 == strcmp(argv[a], "hgt"))
@@ -499,25 +423,18 @@ main_loop()
lcd_cellhgt = atoi(argv[++a]);
}
connected = 1;
{
char buffer[8192];
snprintf(buffer, sizeof(buffer), "client_set -name {LCDproc %s}\n", get_hostname());
sock_send_string(sock, buffer);
}
sock_printf(sock, "client_set -name {LCDproc %s}\n", get_hostname());
#ifdef LCDPROC_MENUS
menus_init();
#endif
}
else if (0 == strcmp(argv[0], "bye"))
{
else if (0 == strcmp(argv[0], "bye")) {
//printf("Exiting LCDproc\n");
exit_program(EXIT_SUCCESS);
}
else if (0 == strcmp(argv[0], "success"))
{
else if (0 == strcmp(argv[0], "success")) {
}
else
{
else {
//int j;
//for (j = 0; j < argc; j++)
// printf("%s ", argv[j]);
@@ -538,30 +455,22 @@ main_loop()
// Gather stats...
// Update screens...
if (connected)
{
for (i = 0; sequence[i].which > 0; i++)
{
if (connected) {
for (i = 0; sequence[i].which > 0; i++) {
sequence[i].timer++;
#ifdef LCDPROC_MENUS
if ((sequence[i].flags & ACTIVE) == 0 )
if (!(sequence[i].flags & ACTIVE))
continue;
if (sequence[i].flags & VISIBLE)
#else
if (sequence[i].visible)
#endif
{
if (sequence[i].timer >= sequence[i].on_time)
{
if (sequence[i].flags & VISIBLE) {
if (sequence[i].timer >= sequence[i].on_time) {
sequence[i].timer = 0;
// Now, update the screen...
update_screen(&sequence[i], 1);
}
}
else
{
if (sequence[i].timer >= sequence[i].off_time)
{
else {
if (sequence[i].timer >= sequence[i].off_time) {
sequence[i].timer = 0;
// Now, update the screen...
update_screen(&sequence[i], sequence[i].show_invisible);
+11 -14
View File
@@ -32,22 +32,19 @@ extern int lcd_cellhgt;
typedef struct mode
{
char *longname; // Which screen is it?
char which; // Which screen is it?
int on_time; // How often to update while visible?
int off_time; // How often to get stats while not visible?
int show_invisible; // Send stats while not visible?
int timer; // Time since last update
#ifdef LCDPROC_MENUS //struct mode flags
int flags; //bit 1 visible, bit 2 selected for display, bit 3 first
#else
int visible; // Can we be seen right now?
#endif //LCDPROC_MENUS
char *longname; // Which screen is it?
char which; // Which screen is it?
int on_time; // How often to update while visible?
int off_time; // How often to get stats while not visible?
int show_invisible; // Send stats while not visible?
int timer; // Time since last update
int flags; // bit 1 visible, bit 2 selected for display, bit 3 first
} mode;
//mode flags
#define VISIBLE 0x00000001 //currently visible
#define ACTIVE 0x00000002 //selected for display
#define INITIALIZED 0x00000004 //replaces the first variable to indicate whether the update screens are initialized
#define VISIBLE 0x00000001 //currently visible
#define ACTIVE 0x00000002 //selected for display
#define INITIALIZED 0x00000004 //replaces the first variable to indicate whether the update screens are initialized
#define BLINK_ON 0x10
#define BLINK_OFF 0x11
+2 -24
View File
@@ -29,26 +29,15 @@
// +--------------------+
//
int
#ifdef LCDPROC_MENUS
mem_screen (int rep, int display, int * flags_ptr)
#else
mem_screen (int rep, int display)
#endif
mem_screen (int rep, int display, int *flags_ptr)
{
static int which_title = 0;
static int gauge_wid = 0;
static int gauge_offs = 0;
meminfo_type mem[2];
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string(sock, "screen_add M\n");
sprintf(buffer, "screen_set M -name {Memory & Swap: %s}\n", get_hostname());
@@ -248,24 +237,13 @@ sort_procs (void *a, void *b)
// +--------------------+
//
int
#ifdef LCDPROC_MENUS
mem_top_screen (int rep, int display, int * flags_ptr)
#else
mem_top_screen (int rep, int display)
#endif
mem_top_screen (int rep, int display, int *flags_ptr)
{
LinkedList *procs;
int i;
#ifdef LCDPROC_MENUS
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
#else
static int first = TRUE;
if (first) {
first = FALSE;
#endif
sock_send_string(sock, "screen_add S\n");
sprintf(buffer, "screen_set S -name {Top Memory Use: %s}\n", get_hostname());
+2 -7
View File
@@ -1,12 +1,7 @@
#ifndef MEM_H
#define MEM_H
#ifdef LCDPROC_MENUS
int mem_screen (int rep, int display, int * flags_ptr);
int mem_top_screen (int rep, int display, int * flags_ptr);
#else
int mem_screen (int rep, int display);
int mem_top_screen (int rep, int display);
#endif
int mem_screen (int rep, int display, int *flags_ptr);
int mem_top_screen (int rep, int display, int *flags_ptr);
#endif
+12 -82
View File
@@ -36,14 +36,12 @@ char *buffer = NULL;
int
mode_init()
{
if ((buffer = malloc(1024)) == NULL)
{
if ((buffer = malloc(1024)) == NULL) {
perror("malloc buffer");
return(0);
}
if ((tmp = malloc(1024)) == NULL)
{
if ((tmp = malloc(1024)) == NULL) {
perror("malloc tmp");
return(0);
}
@@ -58,14 +56,12 @@ mode_close()
{
machine_close();
if (tmp != NULL)
{
if (tmp != NULL) {
free(tmp);
tmp = NULL;
}
if (buffer != NULL)
{
if (buffer != NULL) {
free(buffer);
buffer = NULL;
}
@@ -81,7 +77,6 @@ update_screen(mode *m, int display)
{
switch(m->which)
{
#ifdef LCDPROC_MENUS
case 'g':
case 'G':
status = cpu_graph_screen(m->timer, display, &(m->flags));
@@ -118,8 +113,8 @@ update_screen(mode *m, int display)
case 'D':
status = disk_screen(m->timer, display, &(m->flags));
break;
case 'x':
case 'X':
case 'l':
case 'L':
status = xload_screen(m->timer, display, &(m->flags));
break;
case 'b':
@@ -134,68 +129,10 @@ update_screen(mode *m, int display)
case 'P':
status = cpu_smp_screen(m->timer, display, &(m->flags));
break;
case 'e':
case 'E':
status = essential_clock_screen(m->timer, display, &(m->flags));
case 'n':
case 'N':
status = mini_clock_screen(m->timer, display, &(m->flags));
break;
#else
case 'g':
case 'G':
status = cpu_graph_screen(m->timer, display);
break;
case 'c':
case 'C':
status = cpu_screen(m->timer, display);
break;
case 'o':
case 'O':
status = clock_screen(m->timer, display);
break;
case 'k':
case 'K':
status = big_clock_screen(m->timer, display);
break;
case 'm':
case 'M':
status = mem_screen(m->timer, display);
break;
case 's':
case 'S':
status = mem_top_screen(m->timer, display);
break;
case 'u':
case 'U':
status = uptime_screen(m->timer, display);
break;
case 't':
case 'T':
status = time_screen(m->timer, display);
break;
case 'd':
case 'D':
status = disk_screen(m->timer, display);
break;
case 'x':
case 'X':
status = xload_screen(m->timer, display);
break;
case 'b':
case 'B':
status = battery_screen(m->timer, display);
break;
case 'a':
case 'A':
status = credit_screen(m->timer, display);
break;
case 'p':
case 'P':
status = cpu_smp_screen(m->timer, display);
break;
case 'e':
case 'E':
status = essential_clock_screen(m->timer, display);
break;
#endif
default:
break;
}
@@ -223,17 +160,10 @@ update_screen(mode *m, int display)
// Credit Screen shows who wrote this...
//
int
#ifdef LCDPROC_MENUS
credit_screen(int rep, int display, int * flags_ptr)
#else
credit_screen(int rep, int display)
#endif
credit_screen(int rep, int display, int *flags_ptr)
{
static int first = 1;
if (first)
{
first = 0;
if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED;
sock_send_string(sock, "screen_add A\n");
sock_send_string(sock, "screen_set A -name {Credits for LCDproc}\n");
+1 -5
View File
@@ -11,10 +11,6 @@ int mode_init ();
void mode_close ();
int update_screen (mode * m, int display);
#ifdef LCDPROC_MENUS
int credit_screen (int rep, int display, int * flags_ptr);
#else
int credit_screen (int rep, int display);
#endif
int credit_screen (int rep, int display, int *flags_ptr);
#endif
+7
View File
@@ -539,6 +539,13 @@ AC_ARG_ENABLE(permissive_menu_goto,
fi,
)
AC_ARG_ENABLE(lcdproc-menus,
[ --enable-lcdproc-menus enable menu support in lcdproc client],
if [[[ "$enableval" = "yes" ]]]; then
AC_DEFINE(LCDPROC_MENUS,[1],[Define to 1 to enable menu support in lcdproc client])
fi,
)
# check for doxygen
BB_ENABLE_DOXYGEN
+67 -18
View File
@@ -1,53 +1,102 @@
.TH lcdproc 1 "1-aug-01" "LCDproc"
.SH NAME
lcdproc - displays system status on LCDproc server (LCDd(8))
.SH SYNOPSIS
.B lcdproc
[\-s \fIserver\fP] [\-p \fIport\fP] [\-d] [\fImode\fP [\fImode\fP ...]]
[\-s \fIserver\fP] [\-p \fIport\fP] [\-e \fIdelay\fP] [\-d] [\-h] [\-v] [\fImode\fP [\fImode\fP ...]]
.SH DESCRIPTION
lcdproc connects to the LCDproc server to display status information about the system.
.PP
Currently, only Linux, xBSD and Solaris are supported with not all features being available on all platforms.
.SH OPTIONS
.I lcdproc
understands these options:
.TP 8
.B \-s \fIserver\fP
Set the hostname which LCDproc is running on, assumed to be localhost unless otherwise set
Set the hostname which LCDproc is running on, assumed to be localhost unless otherwise set.
.TP 8
.B \-p \fIport\fP
Set the port which LCDproc is accepting connections on, assumed to be 13666 unless otherwise set
Set the port which LCDproc is accepting connections on, assumed to be 13666 unless otherwise set.
.TP 8
.B \-d
Daemonize right after startup
Daemonize right after startup.
.TP 8
.B \-e \fIdelay\fP
xxx
.TP 8
.B \-h
Show help screen.
.TP 8
.B \-v
Print the version of the program and exit.
.TP 8
.B \fImode\fP
Where mode is one of the following letters:
.RS
[C]pu [G]raph [T]ime [M]emory [X]load [D]isk [B]attery proc_[S]izes [O]ld_time big_cloc[K] [E]ssential_clock [U]ptime CPU_SM[P] [A]bout
.RE
is one of the following:
.TP 16
.B C CPU
show detailed CPU usage
.TP 16
.B P SMP-CPU
CPU usage overview (one line per CPU)
.TP 16
.B G CPUGraph
CPU histogram
.TP 16
.B L Load
Load histogram
.TP 16
.B M Memory
memory & swap usage
.TP 16
.B S ProcSize
show memory usage of 5 biggest processes
.TP 16
.B D Disk
disk usage
.TP 16
.B B Battery
battery status
.TP 16
.B T TimeDate
time & date information
.TP 16
.B O OldTime
old time screen
.TP 16
.B U Uptime
old uptime screen
.TP 16
.B K BigClock
big clock
.TP 16
.B N MiniClock
essential clock
.TP 16
.B A About
credits page
.PP
.SH EXAMPLES
lcdproc C M D X
lcdproc C M D L
.TP 8
connects to the LCDproc server and specifies the following modes:
connects to the LCDproc server running on the default port 13666 on the local machine and specifies the following modes:
.RS
- CPU Usage
- detailed CPU Usage
.PP
- Memory usage
- Memory & swap usage
.PP
- Uptime
- Disk usage
.PP
- Date and Time
.PP
- X-Load average over time
- Load histogram
.RE
.PP
.Sh SEE ALSO
.SH SEE ALSO
.Xr LCDd 8
.SH AUTHOR
LCDproc was originally written by William Ferrell (wwf@splatwerks.org) and Scott Scriven (scriven@cs.colostate.edu).
@@ -56,7 +105,7 @@ Since that time various people have contributed to LCDproc.
The newest version of LCDproc should be available from here:
http://lcdproc.omnipotent.net/
http://www.lcdproc.org/
.SH LEGAL STUFF
LCDproc is released as "WorksForMe-Ware". In other words, it is free, kinda neat, and we don't guarantee that it will do anything in particular on any machine except the ones it was developed on.