/* Main sysmon client source file. */ #include #include #include #include #include "action.h" #include "global.h" #include "window.h" /*************************************************************************/ /* Minimum time between trying to execute a specific action, in msec */ #define ACTION_DELAY 50 /* Should we quit? */ static int quit = 0; /*************************************************************************/ /*************************************************************************/ /* See if any windows need to be refreshed, and if so, do it. */ static void check_refresh(void) { Window *win; int refreshed = 0; for (win = winlist; win; win = win->next) { if (win->refresh > 0 && tv_diff_milli(NULL, &win->lastdraw) >= win->refresh) { gettimeofday(&win->lastdraw, NULL); win_refresh(win); refreshed = 1; } } if (refreshed) screen_refresh(); } /*************************************************************************/ /* See what actions need to be executed now. */ static void check_actions(void) { Action *act; for (act = actlist; act; act = act->next) { if (tv_diff_milli(NULL, &act->lasttouch) >= ACTION_DELAY && act->check > 0 && tv_diff_milli(NULL, &act->lastexec) >= act->check) { act_execute(act); } } } /*************************************************************************/ /* See if there's any input to do something with. */ static void check_input(void) { static char escape_buf[16]; /* For saving escape sequences */ static int escape_len = 0; int c; while ((c = getch()) != ERR) { if (escape_len > 0) { if (escape_len < sizeof(escape_buf)-1) escape_buf[escape_len++] = c; /* XXX check for escape codes */ continue; } if (c == 'q') { quit = 1; } else if (c == 'R') { reboot_menu(0); } else if (c == '\022') { reboot_menu(1); } } } /*************************************************************************/ /*************************************************************************/ static void init(int argc, char **argv) { const char *config = DEF_CONFIG; Window *win; /* Set up the screen. This gets us the screen size, which we need for * processing the config file. */ screen_setup(); /* Read the config file. If we get failure, bail. */ if (!read_config(config)) exit(1); /* Display all windows. */ for (win = winlist; win; win = win->next) { win_open(win); win_refresh(win); } /* Draw stuff to the screen. */ screen_redraw(); } /*************************************************************************/ int main(int argc, char **argv) { init(argc, argv); while (!quit) { check_refresh(); check_actions(); check_input(); usleep(5000); } return 0; } /*************************************************************************/