]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
wme_test: Make it work with ncurses TUI
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 12 Aug 2009 15:21:58 +0000 (17:21 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 12 Aug 2009 15:21:58 +0000 (17:21 +0200)
There are still some problems with FRSH code

wme_test/Makefile.omk
wme_test/wclient.c

index a25b7f92a7b0161c43b3918708846ad7ccc604f9..43ac0a54f8412a38a94ab53ea24f4110dff7621e 100644 (file)
@@ -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
index 9a034d033d31b1a0bb98dace0e6d7d0398f33499..6ff81b6beb03abdad87d1bee8601d1a41bfd17bd 100644 (file)
 #include <frsh.h>
 #include <ncurses.h>
 #include <fwp_res.h>
+#include <ul_log.h>
+#include <ul_logreg.h>
+
+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);