summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2013-06-24 23:04:44 +0200
committerTobias Klauser <tklauser@distanz.ch>2013-06-24 23:14:22 +0200
commitbedc03e69281508ffdb374085225b5ea516c4b13 (patch)
tree3a1dda0f787c95ab3ad307140341c01658e15f54
parent0d50f6b5e8f682fcb34bfac8c21c83f1a246b4dc (diff)
ifpps, flowtop: Move ncurses init and end to common module
ncurses (de-)initialization is duplicated across flowtop and ifpps, so move it to an own module and use it from both tools. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--flowtop.c24
-rw-r--r--flowtop/Makefile1
-rw-r--r--ifpps.c23
-rw-r--r--ifpps/Makefile1
-rw-r--r--screen.c24
-rw-r--r--screen.h9
6 files changed, 40 insertions, 42 deletions
diff --git a/flowtop.c b/flowtop.c
index 87bcbc2..fa0cd21 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -37,6 +37,7 @@
#include "locking.h"
#include "dissector_eth.h"
#include "pkt_buff.h"
+#include "screen.h"
struct flow_entry {
uint32_t flow_id, use, status;
@@ -740,20 +741,6 @@ static uint16_t presenter_get_port(uint16_t src, uint16_t dst, int tcp)
}
}
-static WINDOW *presenter_screen_init(void)
-{
- WINDOW *screen = initscr();
-
- noecho();
- cbreak();
- keypad(stdscr, TRUE);
- nodelay(screen, TRUE);
- refresh();
- wrefresh(screen);
-
- return screen;
-}
-
static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n,
unsigned int *line)
{
@@ -987,18 +974,13 @@ static void presenter_screen_update(WINDOW *screen, struct flow_list *fl,
refresh();
}
-static inline void presenter_screen_end(void)
-{
- endwin();
-}
-
static void presenter(void)
{
int skip_lines = 0;
WINDOW *screen;
dissector_init_ethernet(0);
- screen = presenter_screen_init();
+ screen = screen_init(false);
rcu_register_thread();
while (!sigint) {
@@ -1030,7 +1012,7 @@ static void presenter(void)
}
rcu_unregister_thread();
- presenter_screen_end();
+ screen_end();
dissector_cleanup_ethernet();
}
diff --git a/flowtop/Makefile b/flowtop/Makefile
index 7e7797a..c8998a6 100644
--- a/flowtop/Makefile
+++ b/flowtop/Makefile
@@ -20,4 +20,5 @@ flowtop-objs = xmalloc.o \
proto_none.o \
tprintf.o \
geoip.o \
+ screen.o \
flowtop.o
diff --git a/ifpps.c b/ifpps.c
index e5988e6..0ae77cb 100644
--- a/ifpps.c
+++ b/ifpps.c
@@ -28,6 +28,7 @@
#include "promisc.h"
#include "cpus.h"
#include "built_in.h"
+#include "screen.h"
struct wifi_stat {
uint32_t bitrate;
@@ -635,21 +636,6 @@ static void stats_top(const struct ifstat *rel, const struct ifstat *abs,
}
}
-static void screen_init(WINDOW **screen)
-{
- (*screen) = initscr();
-
- raw();
- noecho();
- cbreak();
- nodelay((*screen), TRUE);
-
- keypad(stdscr, TRUE);
-
- refresh();
- wrefresh((*screen));
-}
-
static void screen_header(WINDOW *screen, const char *ifname, int *voff,
uint64_t ms_interval, unsigned int top_cpus)
{
@@ -931,17 +917,12 @@ static void screen_update(WINDOW *screen, const char *ifname, const struct ifsta
refresh();
}
-static void screen_end(void)
-{
- endwin();
-}
-
static int screen_main(const char *ifname, uint64_t ms_interval,
unsigned int top_cpus)
{
int first = 1, key;
- screen_init(&stats_screen);
+ stats_screen = screen_init(true);
while (!sigint) {
key = getch();
diff --git a/ifpps/Makefile b/ifpps/Makefile
index 6f2666f..6c8ac43 100644
--- a/ifpps/Makefile
+++ b/ifpps/Makefile
@@ -8,4 +8,5 @@ ifpps-objs = xmalloc.o \
sock.o \
dev.o \
sig.o \
+ screen.o \
ifpps.o
diff --git a/screen.c b/screen.c
new file mode 100644
index 0000000..34b27f3
--- /dev/null
+++ b/screen.c
@@ -0,0 +1,24 @@
+#include <curses.h>
+
+#include "screen.h"
+
+WINDOW *screen_init(bool israw)
+{
+ WINDOW *screen = initscr();
+
+ if (israw)
+ raw();
+ noecho();
+ cbreak();
+ nodelay(screen, TRUE);
+ keypad(stdscr, TRUE);
+ refresh();
+ wrefresh(screen);
+
+ return screen;
+}
+
+void screen_end(void)
+{
+ endwin();
+}
diff --git a/screen.h b/screen.h
new file mode 100644
index 0000000..7a647be
--- /dev/null
+++ b/screen.h
@@ -0,0 +1,9 @@
+#ifndef SCREEN_H
+#define SCREEN_H
+
+#include <curses.h>
+
+extern WINDOW *screen_init(bool israw);
+extern void screen_end(void);
+
+#endif /* SCREEN_H */