From 763d6d590165fd39e27b6a0cd123c56484b6c18f Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 12 Aug 2009 17:21:58 +0200 Subject: [PATCH] wme_test: Make it work with ncurses TUI There are still some problems with FRSH code --- wme_test/Makefile.omk | 2 +- wme_test/wclient.c | 81 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/wme_test/Makefile.omk b/wme_test/Makefile.omk index a25b7f9..43ac0a5 100644 --- a/wme_test/Makefile.omk +++ b/wme_test/Makefile.omk @@ -1,6 +1,6 @@ bin_PROGRAMS = fwptester fwptesterserver -CFLAGS += -Wall -D_REENTRANT -g -O2 -DWITH_FWP +CFLAGS += -D_REENTRANT -g -DWITH_FWP lib_LOADLIBES = pthread rt frsh ulut ncurses fwptester_SOURCES = wclient.c common.c diff --git a/wme_test/wclient.c b/wme_test/wclient.c index 9a034d0..6ff81b6 100644 --- a/wme_test/wclient.c +++ b/wme_test/wclient.c @@ -26,6 +26,13 @@ #include #include #include +#include +#include + +static UL_LOG_CUST(ulogd); +static ul_log_domain_t ulogd = {UL_LOGL_MSG, "wclient"}; +UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(init_ulogd_wclient, ulogd); + #endif #define MAX_STREAMS 10 @@ -858,11 +865,10 @@ char* parse_bandwidths(char *params) void wait_for_all_threads_to_finish_fwp(void) { int i; - /* Wait for all threads to finish */ - /* FIXME: */ -/* for (i=0; i < 2*nr_streams; i++) { */ -/* sem_wait(&sem_thread_finished); */ -/* } */ + /* wait for all threads to finish */ + for (i=0; i < 2*nr_streams; i++) { + sem_wait(&sem_thread_finished); + } } #else void wait_for_all_threads_to_finish_native(void) @@ -876,13 +882,70 @@ void wait_for_all_threads_to_finish_native(void) #endif #ifdef WITH_FWP + +WINDOW *logwin; + +struct log_params { + ul_log_domain_t *domain; + int level; + const char *format; + va_list ap; +}; + + +int locked_log(WINDOW *logwin, void *arg) +{ + struct log_params *p = arg; + if(!(p->level&UL_LOGL_CONT)) { + p->level&=UL_LOGL_MASK; + if(p->level) + wprintw(logwin,"<%d>", p->level); + if(p->domain && p->domain->name) + wprintw(logwin,"%s: ",p->domain->name); + } + vwprintw(logwin, p->format, p->ap); + wnoutrefresh(logwin); + return 0; +} + +void +wclient_log_fnc(ul_log_domain_t *domain, int level, + const char *format, va_list ap) +{ + struct log_params p = { + .domain = domain, + .level = level, + .format = format, + }; + va_copy(p.ap, ap); + va_end(ap); + + use_window(logwin, locked_log, (void*)&p); +} + + void init_gui() { initscr(); cbreak(); noecho(); + + logwin = newwin(0, 0, LINES/2, 0); + if (logwin) { + scrollok(logwin, TRUE); + ul_log_redir(wclient_log_fnc, 0); + } +} + +void end_gui() +{ + endwin(); + if (logwin) { + ul_log_redir(NULL, 0); + } } + #define addfield(title, format, ...) \ move(y, x); \ x+=strlen(title)+1; \ @@ -911,10 +974,12 @@ void print_status(int seconds) addfield("Worst-case delay", "%s", usec_to_text(s1, s->wc_delay)); addfield("Received responses", "%lld", s->received); } - refresh(); + wnoutrefresh(stdscr); + doupdate(); } #else void init_gui() {} +void end_gui() {} void print_status(int seconds) { int ac; @@ -1092,7 +1157,7 @@ int main(int argc, char *argv[]) if (some_contract_not_accepted) { stopper(); } else { - //init_gui(); + init_gui(); seconds = 1; frames=0; @@ -1114,7 +1179,7 @@ int main(int argc, char *argv[]) } #ifdef WITH_FWP - //endwin(); + end_gui(); for (i=0; i < nr_streams; i++) { if (streams[i].vres) frsh_contract_cancel(streams[i].vres); -- 2.39.2