From ddcd5e7d24ad57257117402529eacddd8feed2cf Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Tue, 2 Aug 2016 10:10:34 +0200 Subject: [PATCH] Derive initial interface selection based on policy So far, any output module with a selection capability defaulted to the first interface in the list as first pick. This uses the policy configuration instead and thus allows to select which interface to display first: Examples: bmon -p 'em1,*' bmon -p 'eth*,lo,*' The first rule that finds a matching interface is used and will trigger initial selection. Note that this is *ONLY* evaluated after the first read of the statistics so if a more preferred interface appears later, the selection will not be changed. Signed-off-by: Thomas Graf --- NEWS | 3 +++ src/element.c | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 38771d3..f25b836 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +HEAD + * Pick default selected interface based on policy + v3.9 - Jul 19, 2016 * Color support * Add ability to reset statistics from curses UI diff --git a/src/element.c b/src/element.c index d71a337..ebddc2e 100644 --- a/src/element.c +++ b/src/element.c @@ -358,6 +358,26 @@ int element_set_usage_attr(struct element *e, const char *usage) return 0; } +void element_pick_from_policy(struct element_group *g) +{ + if (!list_empty(&allowed)) { + struct policy *p; + + list_for_each_entry(p, &allowed, p_list) { + struct element *e; + + list_for_each_entry(e, &g->g_elements, e_list) { + if (match_mask(p, e->e_name)) { + g->g_current = e; + return; + } + } + } + } + + element_select_first(); +} + struct element *element_current(void) { struct element_group *g; @@ -365,8 +385,12 @@ struct element *element_current(void) if (!(g = group_current())) return NULL; + /* + * If no element is picked yet, pick a default interface according to + * the selection policy. + */ if (!g->g_current) - element_select_first(); + element_pick_from_policy(g); return g->g_current; }