Changed prototype of new API call Xorriso_start_msg_watcher()

This commit is contained in:
Thomas Schmitt 2012-09-15 09:52:29 +00:00
parent eaa501c9ec
commit 6338febf8f
6 changed files with 51 additions and 25 deletions

View File

@ -324,7 +324,9 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->msg_watcher_lock_ini= 0; m->msg_watcher_lock_ini= 0;
m->msg_watcher_state= 0; m->msg_watcher_state= 0;
m->msgw_result_handler= NULL; m->msgw_result_handler= NULL;
m->msgw_result_handle= NULL;
m->msgw_info_handler= NULL; m->msgw_info_handler= NULL;
m->msgw_info_handle= NULL;
m->msgw_stack_handle= -1; m->msgw_stack_handle= -1;
m->msglist_stackfill= 0; m->msglist_stackfill= 0;
m->status_history_max= Xorriso_status_history_maX; m->status_history_max= Xorriso_status_history_maX;

View File

@ -1761,7 +1761,7 @@ next_command:;
ret, line_count); ret, line_count);
} }
} else if(strcmp(arg1, "start") == 0) { } 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); fprintf(stderr, "xorriso -test: Xorriso_start_msg_watcher() = %d\n", ret);
} else if(strcmp(arg1, "stop") == 0) { } else if(strcmp(arg1, "stop") == 0) {
ret= Xorriso_stop_msg_watcher(xorriso, 0); ret= Xorriso_stop_msg_watcher(xorriso, 0);
@ -1864,7 +1864,7 @@ if(0){
if(xorriso->add_plainly>1) if(xorriso->add_plainly>1)
goto add_plain_argument; goto add_plain_argument;
unknown_option:; unknown_option:;
sprintf(xorriso->info_text, "Not a known option: '%s'\n", sprintf(xorriso->info_text, "Not a known command: '%s'\n",
original_cmd); original_cmd);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
{ret= 0; goto eval_any_problems;} {ret= 0; goto eval_any_problems;}
@ -2223,7 +2223,7 @@ protect_stdout:;
i+= arg_count; i+= arg_count;
} else if((flag & 2) && ((was_dashed && xorriso->add_plainly <= 1) || } else if((flag & 2) && ((was_dashed && xorriso->add_plainly <= 1) ||
xorriso->add_plainly <= 0)) { 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); original_cmd);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
error_seen= 1; error_seen= 1;

View File

@ -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); printf("%s", text);
fflush(stdout); 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) { if(xorriso->stderr_fp != NULL) {
fprintf(xorriso->stderr_fp, "%s", text); fprintf(xorriso->stderr_fp, "%s", text);
fflush(xorriso->stderr_fp); fflush(xorriso->stderr_fp);
@ -966,23 +969,30 @@ int Xorriso_process_msg_lists(struct XorrisO *xorriso,
{ {
struct Xorriso_lsT *lpt; struct Xorriso_lsT *lpt;
int ret; int ret;
int (*handler)(struct XorrisO *xorriso, char *text); int (*handler)(void *handle, char *text);
void *handle;
handler= xorriso->msgw_result_handler; handler= xorriso->msgw_result_handler;
if(handler == NULL) handle= xorriso->msgw_result_handle;
if(handler == NULL) {
handler= Xorriso_result_handler_stdout; handler= Xorriso_result_handler_stdout;
handle= xorriso;
}
for(lpt= result_list; lpt != NULL; lpt= lpt->next) { for(lpt= result_list; lpt != NULL; lpt= lpt->next) {
(*line_count)++; (*line_count)++;
ret= (*handler)(xorriso, Xorriso_lst_get_text(lpt, 0)); ret= (*handler)(handle, Xorriso_lst_get_text(lpt, 0));
if(ret < 0) if(ret < 0)
return(-1); return(-1);
} }
handler= xorriso->msgw_info_handler; handler= xorriso->msgw_info_handler;
if(handler == NULL) handle= xorriso->msgw_info_handle;
if(handler == NULL) {
handler= Xorriso_info_handler_stderr; handler= Xorriso_info_handler_stderr;
handle= xorriso;
}
for(lpt= info_list; lpt != NULL; lpt= lpt->next) { for(lpt= info_list; lpt != NULL; lpt= lpt->next) {
(*line_count)++; (*line_count)++;
ret= (*handler)(xorriso, Xorriso_lst_get_text(lpt, 0)); ret= (*handler)(handle, Xorriso_lst_get_text(lpt, 0));
if(ret < 0) if(ret < 0)
return(-1); return(-1);
} }
@ -993,7 +1003,7 @@ int Xorriso_process_msg_lists(struct XorrisO *xorriso,
static void *Xorriso_msg_watcher(void *state_pt) static void *Xorriso_msg_watcher(void *state_pt)
{ {
struct XorrisO *xorriso; 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; struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
static int debug_sev= 0; 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 Xorriso_start_msg_watcher(struct XorrisO *xorriso,
int (*result_handler)(struct XorrisO *xorriso, char *text), int (*result_handler)(void *handle, char *text),
int (*info_handler)(struct XorrisO *xorriso, char *text), void *result_handle,
int (*info_handler)(void *handle, char *text),
void *info_handle,
int flag) int flag)
{ {
int ret, u_wait= 1000, locked= 0, pushed= 0, uret, line_count= 0; 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 */ /* Register watcher */
xorriso->msgw_result_handler= result_handler; xorriso->msgw_result_handler= result_handler;
xorriso->msgw_result_handle= result_handle;
xorriso->msgw_info_handler= info_handler; xorriso->msgw_info_handler= info_handler;
xorriso->msgw_info_handle= info_handle;
xorriso->msg_watcher_state= 1; xorriso->msg_watcher_state= 1;
/* Start thread */ /* Start thread */

View File

@ -564,6 +564,10 @@ int Xorriso_process_errfile(struct XorrisO *xorriso,
later time be retrieved by the application. later time be retrieved by the application.
These redirection caches can be stacked to allow stacked applications. These redirection caches can be stacked to allow stacked applications.
xorriso itself uses them for internal purposes. 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 */ /* 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. 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 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 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 @since 1.2.6
@param xorriso The environment handle @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 @param result_handler Pointer to the function which shall be called with
each result message. A NULL pointer causes output each result message. A NULL pointer causes output
to be directed to stdout. to be directed to stdout.
The function should use the pointer xorriso with @param result_handle The first argument of (*result_handler)(). It shall
outmost caution, because nearly all API calls are not point to a memory object that knows all necessary
thread-safe and may not be used. Best is to use it external parameters for running (*result_handler)().
only to distinguish the callers if more than one Submit NULL if result_handler is NULL.
struct XorrisO is in use by the application.
@param info_handler Pointer to the function which shall be called with @param info_handler Pointer to the function which shall be called with
each info message. A NULL pointer causes output to each info message. A NULL pointer causes output to
be directed to stderr resp. to -as mkisofs -log-file. 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 @param flag unused yet, submit 0
@return 1 on success, <=0 if failure (e.g. there is already @return 1 on success, <=0 if failure (e.g. there is already
a watcher active) a watcher active)
*/ */
int Xorriso_start_msg_watcher(struct XorrisO *xorriso, int Xorriso_start_msg_watcher(struct XorrisO *xorriso,
int (*result_handler)(struct XorrisO *xorriso, char *text), int (*result_handler)(void *handle, char *text),
int (*info_handler)(struct XorrisO *xorriso, char *text), void *result_handle,
int (*info_handler)(void *handle, char *text),
void *info_handle,
int flag); int flag);

View File

@ -582,8 +582,10 @@ struct XorrisO { /* the global context of xorriso */
2= started 2= started
3= request to end 3= request to end
*/ */
int (*msgw_result_handler)(struct XorrisO *xorriso, char *text); int (*msgw_result_handler)(void *handle, char *text);
int (*msgw_info_handler)(struct XorrisO *xorriso, char *text); void *msgw_result_handle;
int (*msgw_info_handler)(void *handle, char *text);
void *msgw_info_handle;
int msgw_stack_handle; int msgw_stack_handle;
int status_history_max; /* for -status long_history */ int status_history_max; /* for -status long_history */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2012.09.14.175104" #define Xorriso_timestamP "2012.09.15.095146"