2002-01-11 Lutz M�ller <urc8@rz.uni-karlsruhe.de>
* libgphoto2/gphoto2-context.[c,h]: Support for multiple progress
reports at once (especially sub-progress reports).
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@3799 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
2002-01-11 Lutz Müller <urc8@rz.uni-karlsruhe.de>
|
||||
|
||||
* libgphoto2/gphoto2-context.[c,h]: Support for multiple progress
|
||||
reports at once (especially sub-progress reports).
|
||||
|
||||
2002-01-10 Lutz Müller <urc8@rz.uni-karlsruhe.de>
|
||||
|
||||
* libgphoto2/gphoto2-filesys.[c,h]: Add a GPContext to all functions
|
||||
|
||||
@@ -1232,11 +1232,38 @@ ctx_error_func (GPContext *context, const char *format, va_list args,
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
static void
|
||||
ctx_progress_func (GPContext *context, float percentage, void *data)
|
||||
static float targets[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
static unsigned int
|
||||
ctx_progress_start_func (GPContext *context, float target,
|
||||
const char *format, va_list args, void *data)
|
||||
{
|
||||
fprintf (stderr, "Progress: %02.01f\r", percentage * 100.);
|
||||
unsigned int id;
|
||||
|
||||
for (id = 0; id < 7; id++)
|
||||
if (!targets[id])
|
||||
break;
|
||||
targets[id] = target;
|
||||
|
||||
vfprintf (stderr, format, args);
|
||||
fprintf (stderr, "\n");
|
||||
fflush (stderr);
|
||||
|
||||
return (id);
|
||||
}
|
||||
|
||||
static void
|
||||
ctx_progress_update_func (GPContext *context, unsigned int id,
|
||||
float current, void *data)
|
||||
{
|
||||
printf ("Percent completed: %02.01f\r", current / targets[id]);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void
|
||||
ctx_progress_stop_func (GPContext *context, unsigned int id, void *data)
|
||||
{
|
||||
targets[id] = 0;
|
||||
}
|
||||
|
||||
static GPContextFeedback
|
||||
@@ -1270,10 +1297,13 @@ init_globals (void)
|
||||
glob_recurse = 0;
|
||||
|
||||
glob_context = gp_context_new ();
|
||||
gp_context_set_cancel_func (glob_context, ctx_cancel_func, NULL);
|
||||
gp_context_set_progress_func (glob_context, ctx_progress_func, NULL);
|
||||
gp_context_set_error_func (glob_context, ctx_error_func, NULL);
|
||||
gp_context_set_status_func (glob_context, ctx_status_func, NULL);
|
||||
gp_context_set_cancel_func (glob_context, ctx_cancel_func, NULL);
|
||||
gp_context_set_progress_funcs (glob_context,
|
||||
ctx_progress_start_func,
|
||||
ctx_progress_update_func,
|
||||
ctx_progress_stop_func, NULL);
|
||||
gp_context_set_error_func (glob_context, ctx_error_func, NULL);
|
||||
gp_context_set_status_func (glob_context, ctx_status_func, NULL);
|
||||
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir,
|
||||
CameraLibraryAbilitiesFunc ab;
|
||||
CameraText text;
|
||||
int x, old_count, new_count;
|
||||
unsigned int i, n;
|
||||
unsigned int i, n, p;
|
||||
const char *filename;
|
||||
#ifdef HAVE_LTDL
|
||||
CameraList flist;
|
||||
@@ -246,8 +246,8 @@ gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir,
|
||||
GP_SYSTEM_CLOSEDIR (d);
|
||||
d = GP_SYSTEM_OPENDIR (dir);
|
||||
|
||||
gp_context_status (context, _("Loading camera drivers from '%s'..."),
|
||||
dir);
|
||||
p = gp_context_progress_start (context, n,
|
||||
_("Loading camera drivers from '%s'..."), dir);
|
||||
i = 0;
|
||||
do {
|
||||
|
||||
@@ -260,7 +260,7 @@ gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir,
|
||||
* possiblility to cancel.
|
||||
*/
|
||||
i++;
|
||||
gp_context_progress (context, (float) i / (float) n);
|
||||
gp_context_progress_update (context, p, i);
|
||||
if (gp_context_cancel (context) ==
|
||||
GP_CONTEXT_FEEDBACK_CANCEL)
|
||||
return (GP_ERROR_CANCEL);
|
||||
@@ -344,6 +344,7 @@ gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir,
|
||||
}
|
||||
}
|
||||
} while (de);
|
||||
gp_context_progress_stop (context, p);
|
||||
#endif
|
||||
|
||||
return (GP_OK);
|
||||
|
||||
@@ -28,8 +28,10 @@ struct _GPContext
|
||||
GPContextIdleFunc idle_func;
|
||||
void *idle_func_data;
|
||||
|
||||
GPContextProgressFunc progress_func;
|
||||
void *progress_func_data;
|
||||
GPContextProgressStartFunc progress_start_func;
|
||||
GPContextProgressUpdateFunc progress_update_func;
|
||||
GPContextProgressStopFunc progress_stop_func;
|
||||
void *progress_func_data;
|
||||
|
||||
GPContextErrorFunc error_func;
|
||||
void *error_func_data;
|
||||
@@ -127,15 +129,46 @@ gp_context_idle (GPContext *context)
|
||||
context->idle_func (context, context->idle_func_data);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
gp_context_progress_start (GPContext *context, float target,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
unsigned int id;
|
||||
|
||||
if (!context)
|
||||
return (0);
|
||||
|
||||
if (context->progress_start_func) {
|
||||
va_start (args, format);
|
||||
id = context->progress_start_func (context, target, format,
|
||||
args, context->progress_func_data);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
gp_context_progress (GPContext *context, float percentage)
|
||||
gp_context_progress_update (GPContext *context, unsigned int id, float current)
|
||||
{
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
if (context->progress_func)
|
||||
context->progress_func (context, percentage,
|
||||
context->progress_func_data);
|
||||
if (context->progress_update_func)
|
||||
context->progress_update_func (context, id, current,
|
||||
context->progress_func_data);
|
||||
}
|
||||
|
||||
void
|
||||
gp_context_progress_stop (GPContext *context, unsigned int id)
|
||||
{
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
if (context->progress_stop_func)
|
||||
context->progress_stop_func (context, id,
|
||||
context->progress_func_data);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -233,14 +266,19 @@ gp_context_set_idle_func (GPContext *context, GPContextIdleFunc func,
|
||||
}
|
||||
|
||||
void
|
||||
gp_context_set_progress_func (GPContext *context, GPContextProgressFunc func,
|
||||
void *data)
|
||||
gp_context_set_progress_funcs (GPContext *context,
|
||||
GPContextProgressStartFunc start_func,
|
||||
GPContextProgressUpdateFunc update_func,
|
||||
GPContextProgressStopFunc stop_func,
|
||||
void *data)
|
||||
{
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
context->progress_func = func;
|
||||
context->progress_func_data = data;
|
||||
context->progress_start_func = start_func;
|
||||
context->progress_update_func = update_func;
|
||||
context->progress_stop_func = stop_func;
|
||||
context->progress_func_data = data;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -38,8 +38,6 @@ enum _GPContextFeedback {
|
||||
|
||||
/* Functions */
|
||||
typedef void (* GPContextIdleFunc) (GPContext *context, void *data);
|
||||
typedef void (* GPContextProgressFunc) (GPContext *context, float percentage,
|
||||
void *data);
|
||||
typedef void (* GPContextErrorFunc) (GPContext *context, const char *format,
|
||||
va_list args, void *data);
|
||||
typedef void (* GPContextStatusFunc) (GPContext *context, const char *format,
|
||||
@@ -49,28 +47,46 @@ typedef GPContextFeedback (* GPContextQuestionFunc) (GPContext *context,
|
||||
va_list args, void *data);
|
||||
typedef GPContextFeedback (* GPContextCancelFunc) (GPContext *context,
|
||||
void *data);
|
||||
typedef unsigned int (* GPContextProgressStartFunc) (GPContext *context,
|
||||
float target,
|
||||
const char *format,
|
||||
va_list args, void *data);
|
||||
typedef void (* GPContextProgressUpdateFunc) (GPContext *context,
|
||||
unsigned int id,
|
||||
float current,
|
||||
void *data);
|
||||
typedef void (* GPContextProgressStopFunc) (GPContext *context,
|
||||
unsigned int id,
|
||||
void *data);
|
||||
|
||||
/* Setting those functions (frontends) */
|
||||
void gp_context_set_idle_func (GPContext *context,
|
||||
GPContextIdleFunc func, void *data);
|
||||
void gp_context_set_progress_func (GPContext *context,
|
||||
GPContextProgressFunc func, void *data);
|
||||
void gp_context_set_error_func (GPContext *context,
|
||||
GPContextErrorFunc func, void *data);
|
||||
void gp_context_set_status_func (GPContext *context,
|
||||
GPContextStatusFunc func, void *data);
|
||||
void gp_context_set_question_func (GPContext *context,
|
||||
GPContextQuestionFunc func, void *data);
|
||||
void gp_context_set_cancel_func (GPContext *context,
|
||||
GPContextCancelFunc func, void *data);
|
||||
void gp_context_set_idle_func (GPContext *context,
|
||||
GPContextIdleFunc func, void *data);
|
||||
void gp_context_set_progress_funcs (GPContext *context,
|
||||
GPContextProgressStartFunc start_func,
|
||||
GPContextProgressUpdateFunc update_func,
|
||||
GPContextProgressStopFunc stop_func,
|
||||
void *data);
|
||||
void gp_context_set_error_func (GPContext *context,
|
||||
GPContextErrorFunc func, void *data);
|
||||
void gp_context_set_status_func (GPContext *context,
|
||||
GPContextStatusFunc func, void *data);
|
||||
void gp_context_set_question_func (GPContext *context,
|
||||
GPContextQuestionFunc func, void *data);
|
||||
void gp_context_set_cancel_func (GPContext *context,
|
||||
GPContextCancelFunc func, void *data);
|
||||
|
||||
/* Calling those functions (backends) */
|
||||
void gp_context_idle (GPContext *context);
|
||||
void gp_context_progress (GPContext *context, float percentage);
|
||||
void gp_context_error (GPContext *context, const char *format, ...);
|
||||
void gp_context_status (GPContext *context, const char *format, ...);
|
||||
GPContextFeedback gp_context_question (GPContext *context, const char *format,
|
||||
...);
|
||||
GPContextFeedback gp_context_cancel (GPContext *context);
|
||||
unsigned int gp_context_progress_start (GPContext *context, float target,
|
||||
const char *format, ...);
|
||||
void gp_context_progress_update (GPContext *context, unsigned int id,
|
||||
float current);
|
||||
void gp_context_progress_stop (GPContext *context, unsigned int id);
|
||||
|
||||
#endif /* __GPHOTO2_CONTEXT_H__ */
|
||||
|
||||
Reference in New Issue
Block a user