From: Intel Date: Mon, 3 Jun 2013 00:00:00 +0000 (+0000) Subject: eal: add application usage hook X-Git-Tag: spdx-start~11260 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=bfdbde0c20ed23eff74dc8e6346892295d49acf8;p=dpdk.git eal: add application usage hook Signed-off-by: Intel --- diff --git a/app/test/test_debug.c b/app/test/test_debug.c index 4c878c8006..b98239b5d4 100644 --- a/app/test/test_debug.c +++ b/app/test/test_debug.c @@ -138,6 +138,26 @@ test_exit(void) #endif +static void +dummy_app_usage(const char *progname) +{ + RTE_SET_USED(progname); +} + +static int +test_usage(void) +{ + if (rte_set_application_usage_hook(dummy_app_usage) != NULL) { + printf("Non-NULL value returned for initial usage hook\n"); + return -1; + } + if (rte_set_application_usage_hook(NULL) != dummy_app_usage) { + printf("Incorrect value returned for application usage hook\n"); + return -1; + } + return 0; +} + int test_debug(void) { @@ -147,5 +167,7 @@ test_debug(void) return -1; if (test_exit() < 0) return -1; + if (test_usage() < 0) + return -1; return 0; } diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h index 2445f6b4fd..1df8d108ca 100644 --- a/lib/librte_eal/common/include/rte_eal.h +++ b/lib/librte_eal/common/include/rte_eal.h @@ -146,6 +146,37 @@ enum rte_proc_type_t rte_eal_process_type(void); * - On failure, a negative error value. */ int rte_eal_init(int argc, char **argv); +/** + * Usage function typedef used by the application usage function. + * + * Use this function typedef to define and call rte_set_applcation_usage_hook() + * routine. + */ +typedef void (*rte_usage_hook_t)(const char * prgname); + +/** + * Add application usage routine callout from the eal_usage() routine. + * + * This function allows the application to include its usage message + * in the EAL system usage message. The routine rte_set_application_usage_hook() + * needs to be called before the rte_eal_init() routine in the application. + * + * This routine is optional for the application and will behave as if the set + * routine was never called as the default behavior. + * + * @param func + * The func argument is a function pointer to the application usage routine. + * Called function is defined using rte_usage_hook_t typedef, which is of + * the form void rte_usage_func(const char * prgname). + * + * Calling this routine with a NULL value will reset the usage hook routine and + * return the current value, which could be NULL. + * @return + * - Returns the current value of the rte_application_usage pointer to allow + * the caller to daisy chain the usage routines if needing more then one. + */ +rte_usage_hook_t +rte_set_application_usage_hook( rte_usage_hook_t usage_func ); /** * macro to get the lock of tailq in mem_config diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index bedf5bed8f..afa0cce929 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -103,6 +103,8 @@ (in) = end + 1; \ } +/* Allow the application to print its usage message too if set */ +static rte_usage_hook_t rte_application_usage_hook = NULL; /* early configuration structure, when memory config is not mmapped */ static struct rte_mem_config early_mem_config; @@ -329,6 +331,24 @@ eal_usage(const char *prgname) " --"OPT_NO_HPET" : disable hpet\n" " --"OPT_NO_SHCONF": no shared config (mmap'd files)\n\n", prgname); + /* Allow the application to print its usage message too if hook is set */ + if ( rte_application_usage_hook ) { + printf("===== Application Usage =====\n\n"); + rte_application_usage_hook(prgname); + } +} + +/* Set a per-application usage message */ +rte_usage_hook_t +rte_set_application_usage_hook( rte_usage_hook_t usage_func ) +{ + rte_usage_hook_t old_func; + + /* Will be NULL on the first call to denote the last usage routine. */ + old_func = rte_application_usage_hook; + rte_application_usage_hook = usage_func; + + return old_func; } /*