eal: add application usage hook

Signed-off-by: Intel
This commit is contained in:
Intel 2013-06-03 00:00:00 +00:00 committed by Thomas Monjalon
parent d6772940c0
commit bfdbde0c20
3 changed files with 73 additions and 0 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}
/*