From 227620704107a19c03824ae146249fff4a939839 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Tue, 24 Sep 2013 11:03:11 +0800 Subject: discover: Add struct load_url_result and load_task Currently, load_url and load_url_async return a filename parameter and a tempfile flag (indicating whether the file needs to be cleaned after use). Instead, encapsulate this data in a struct load_url_result, which the caller (and async callbacks) can read the status, filename and clean parameters. For internal use in load_url and helpers, we add a struct load_task to hold a pointer to the load_url_result and async data. Signed-off-by: Jeremy Kerr --- discover/paths.h | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'discover/paths.h') diff --git a/discover/paths.h b/discover/paths.h index 2f52e82..e905094 100644 --- a/discover/paths.h +++ b/discover/paths.h @@ -16,12 +16,30 @@ char *join_paths(void *alloc_ctx, const char *a, const char *b); */ const char *mount_base(void); -typedef void (*load_url_callback)(void *data, int status); + +struct load_url_result { + enum { + LOAD_OK, /* load complete. other members should only be + accessed if status == LOAD_OK */ + + LOAD_ERROR, /* only signalled to async loaders + * (sync will see a NULL result) */ + + LOAD_ASYNC, /* async load still in progress */ + } status; + const char *local; + bool cleanup_local; +}; + +/* callback type for asynchronous loads. The callback implementation is + * responsible for freeing result. + */ +typedef void (*load_url_complete)(struct load_url_result *result, void *data); /* Load a (potentially remote) file, and return a guaranteed-local name */ -char *load_url_async(void *ctx, struct pb_url *url, unsigned int *tempfile, - load_url_callback url_cb); +struct load_url_result *load_url_async(void *ctx, struct pb_url *url, + load_url_complete complete, void *data); -char *load_url(void *ctx, struct pb_url *url, unsigned int *tempfile); +struct load_url_result *load_url(void *ctx, struct pb_url *url); #endif /* PATHS_H */ -- cgit v1.2.1