From 6338febf8fac5b6f5b0b48e4dfc72e31c524af38 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sat, 15 Sep 2012 09:52:29 +0000 Subject: [PATCH] Changed prototype of new API call Xorriso_start_msg_watcher() --- xorriso/base_obj.c | 2 ++ xorriso/parse_exec.c | 6 +++--- xorriso/text_io.c | 34 ++++++++++++++++++++++++---------- xorriso/xorriso.h | 26 +++++++++++++++++--------- xorriso/xorriso_private.h | 6 ++++-- xorriso/xorriso_timestamp.h | 2 +- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/xorriso/base_obj.c b/xorriso/base_obj.c index 38bc4e0d..a737c992 100644 --- a/xorriso/base_obj.c +++ b/xorriso/base_obj.c @@ -324,7 +324,9 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag) m->msg_watcher_lock_ini= 0; m->msg_watcher_state= 0; m->msgw_result_handler= NULL; + m->msgw_result_handle= NULL; m->msgw_info_handler= NULL; + m->msgw_info_handle= NULL; m->msgw_stack_handle= -1; m->msglist_stackfill= 0; m->status_history_max= Xorriso_status_history_maX; diff --git a/xorriso/parse_exec.c b/xorriso/parse_exec.c index 88005661..49e3a6c6 100644 --- a/xorriso/parse_exec.c +++ b/xorriso/parse_exec.c @@ -1761,7 +1761,7 @@ next_command:; ret, line_count); } } else if(strcmp(arg1, "start") == 0) { - ret= Xorriso_start_msg_watcher(xorriso, NULL, NULL, 0); + ret= Xorriso_start_msg_watcher(xorriso, NULL, NULL, NULL, NULL, 0); fprintf(stderr, "xorriso -test: Xorriso_start_msg_watcher() = %d\n", ret); } else if(strcmp(arg1, "stop") == 0) { ret= Xorriso_stop_msg_watcher(xorriso, 0); @@ -1864,7 +1864,7 @@ if(0){ if(xorriso->add_plainly>1) goto add_plain_argument; unknown_option:; - sprintf(xorriso->info_text, "Not a known option: '%s'\n", + sprintf(xorriso->info_text, "Not a known command: '%s'\n", original_cmd); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); {ret= 0; goto eval_any_problems;} @@ -2223,7 +2223,7 @@ protect_stdout:; i+= arg_count; } else if((flag & 2) && ((was_dashed && xorriso->add_plainly <= 1) || xorriso->add_plainly <= 0)) { - sprintf(xorriso->info_text, "Not a known option: '%s'\n", + sprintf(xorriso->info_text, "Not a known command: '%s'\n", original_cmd); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); error_seen= 1; diff --git a/xorriso/text_io.c b/xorriso/text_io.c index 16a4e626..c4343199 100644 --- a/xorriso/text_io.c +++ b/xorriso/text_io.c @@ -938,7 +938,7 @@ ex:; } -int Xorriso_result_handler_stdout(struct XorrisO *xorriso, char *text) +int Xorriso_result_handler_stdout(void *handle, char *text) { printf("%s", text); fflush(stdout); @@ -946,8 +946,11 @@ int Xorriso_result_handler_stdout(struct XorrisO *xorriso, char *text) } -int Xorriso_info_handler_stderr(struct XorrisO *xorriso, char *text) +int Xorriso_info_handler_stderr(void *handle, char *text) { + struct XorrisO *xorriso; + + xorriso= (struct XorrisO *) handle; if(xorriso->stderr_fp != NULL) { fprintf(xorriso->stderr_fp, "%s", text); fflush(xorriso->stderr_fp); @@ -966,23 +969,30 @@ int Xorriso_process_msg_lists(struct XorrisO *xorriso, { struct Xorriso_lsT *lpt; int ret; - int (*handler)(struct XorrisO *xorriso, char *text); + int (*handler)(void *handle, char *text); + void *handle; handler= xorriso->msgw_result_handler; - if(handler == NULL) + handle= xorriso->msgw_result_handle; + if(handler == NULL) { handler= Xorriso_result_handler_stdout; + handle= xorriso; + } for(lpt= result_list; lpt != NULL; lpt= lpt->next) { (*line_count)++; - ret= (*handler)(xorriso, Xorriso_lst_get_text(lpt, 0)); + ret= (*handler)(handle, Xorriso_lst_get_text(lpt, 0)); if(ret < 0) return(-1); } handler= xorriso->msgw_info_handler; - if(handler == NULL) + handle= xorriso->msgw_info_handle; + if(handler == NULL) { handler= Xorriso_info_handler_stderr; + handle= xorriso; + } for(lpt= info_list; lpt != NULL; lpt= lpt->next) { (*line_count)++; - ret= (*handler)(xorriso, Xorriso_lst_get_text(lpt, 0)); + ret= (*handler)(handle, Xorriso_lst_get_text(lpt, 0)); if(ret < 0) return(-1); } @@ -993,7 +1003,7 @@ int Xorriso_process_msg_lists(struct XorrisO *xorriso, static void *Xorriso_msg_watcher(void *state_pt) { struct XorrisO *xorriso; - int ret, u_wait= 10000, line_count, sleep_thresh= 20; + int ret, u_wait= 25000, line_count, sleep_thresh= 20; struct Xorriso_lsT *result_list= NULL, *info_list= NULL; static int debug_sev= 0; @@ -1042,8 +1052,10 @@ static void *Xorriso_msg_watcher(void *state_pt) int Xorriso_start_msg_watcher(struct XorrisO *xorriso, - int (*result_handler)(struct XorrisO *xorriso, char *text), - int (*info_handler)(struct XorrisO *xorriso, char *text), + int (*result_handler)(void *handle, char *text), + void *result_handle, + int (*info_handler)(void *handle, char *text), + void *info_handle, int flag) { int ret, u_wait= 1000, locked= 0, pushed= 0, uret, line_count= 0; @@ -1076,7 +1088,9 @@ int Xorriso_start_msg_watcher(struct XorrisO *xorriso, /* Register watcher */ xorriso->msgw_result_handler= result_handler; + xorriso->msgw_result_handle= result_handle; xorriso->msgw_info_handler= info_handler; + xorriso->msgw_info_handle= info_handle; xorriso->msg_watcher_state= 1; /* Start thread */ diff --git a/xorriso/xorriso.h b/xorriso/xorriso.h index 698ab2ba..9b436a63 100644 --- a/xorriso/xorriso.h +++ b/xorriso/xorriso.h @@ -564,6 +564,10 @@ int Xorriso_process_errfile(struct XorrisO *xorriso, later time be retrieved by the application. These redirection caches can be stacked to allow stacked applications. xorriso itself uses them for internal purposes. + + The call Xorriso_start_msg_watcher() starts a concurrent thread which + uses outlists to collect messages and to hand them over by calling + application provided functions. */ /* A list item able of forming double chained lists */ @@ -604,7 +608,7 @@ int Xorriso_push_outlists(struct XorrisO *xorriso, int *stack_handle, xorriso API call is being executed on the same struct XorrisO. In such a situation, it should not be used with high frequency in order not to hamper the ongoing xorriso operation by blocking its message - output facility. Ten times per second should be enough. + output facility. A hundred times per second should be enough. @since 1.2.6 @param xorriso The environment handle @@ -655,22 +659,26 @@ int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle, @param result_handler Pointer to the function which shall be called with each result message. A NULL pointer causes output to be directed to stdout. - The function should use the pointer xorriso with - outmost caution, because nearly all API calls are not - thread-safe and may not be used. Best is to use it - only to distinguish the callers if more than one - struct XorrisO is in use by the application. + @param result_handle The first argument of (*result_handler)(). It shall + point to a memory object that knows all necessary + external parameters for running (*result_handler)(). + Submit NULL if result_handler is NULL. @param info_handler Pointer to the function which shall be called with each info message. A NULL pointer causes output to be directed to stderr resp. to -as mkisofs -log-file. - The same caution is needed as with result_handler. + @param info_handle The first argument of (*info_handler)(). It shall + point to a memory object that knows all necessary + external parameters for running (*info_handler)(). + Submit NULL if info_handler is NULL. @param flag unused yet, submit 0 @return 1 on success, <=0 if failure (e.g. there is already a watcher active) */ int Xorriso_start_msg_watcher(struct XorrisO *xorriso, - int (*result_handler)(struct XorrisO *xorriso, char *text), - int (*info_handler)(struct XorrisO *xorriso, char *text), + int (*result_handler)(void *handle, char *text), + void *result_handle, + int (*info_handler)(void *handle, char *text), + void *info_handle, int flag); diff --git a/xorriso/xorriso_private.h b/xorriso/xorriso_private.h index e02ef7c3..45a4fefa 100644 --- a/xorriso/xorriso_private.h +++ b/xorriso/xorriso_private.h @@ -582,8 +582,10 @@ struct XorrisO { /* the global context of xorriso */ 2= started 3= request to end */ - int (*msgw_result_handler)(struct XorrisO *xorriso, char *text); - int (*msgw_info_handler)(struct XorrisO *xorriso, char *text); + int (*msgw_result_handler)(void *handle, char *text); + void *msgw_result_handle; + int (*msgw_info_handler)(void *handle, char *text); + void *msgw_info_handle; int msgw_stack_handle; int status_history_max; /* for -status long_history */ diff --git a/xorriso/xorriso_timestamp.h b/xorriso/xorriso_timestamp.h index 804617ef..7dc65092 100644 --- a/xorriso/xorriso_timestamp.h +++ b/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2012.09.14.175104" +#define Xorriso_timestamP "2012.09.15.095146"