From: Jani Nikula Date: Sun, 3 Nov 2013 12:24:45 +0000 (+0200) Subject: lib: add closure parameter to compact status update callback X-Git-Tag: 0.17_rc1~77 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=180dba66e47a5257b2cdf2f1ceb59cc8fa5a69d4;p=notmuch.git lib: add closure parameter to compact status update callback This provides much more flexibility for the caller. --- diff --git a/lib/database.cc b/lib/database.cc index eadf8a76..5a017034 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -821,9 +821,11 @@ static int rmtree (const char *path) class NotmuchCompactor : public Xapian::Compactor { notmuch_compact_status_cb_t status_cb; + void *status_closure; public: - NotmuchCompactor(notmuch_compact_status_cb_t cb) : status_cb(cb) { } + NotmuchCompactor(notmuch_compact_status_cb_t cb, void *closure) : + status_cb(cb), status_closure(closure) { } virtual void set_status (const std::string &table, const std::string &status) @@ -842,7 +844,7 @@ public: return; } - status_cb(msg); + status_cb(msg, status_closure); talloc_free(msg); } }; @@ -861,7 +863,8 @@ public: notmuch_status_t notmuch_database_compact (const char* path, const char* backup_path, - notmuch_compact_status_cb_t status_cb) + notmuch_compact_status_cb_t status_cb, + void *closure) { void *local; char *notmuch_path, *xapian_path, *compact_xapian_path; @@ -913,7 +916,7 @@ notmuch_database_compact (const char* path, } try { - NotmuchCompactor compactor(status_cb); + NotmuchCompactor compactor(status_cb, closure); compactor.set_renumber(false); compactor.add_source(xapian_path); @@ -953,7 +956,8 @@ DONE: notmuch_status_t notmuch_database_compact (unused (const char* path), unused (const char* backup_path), - unused (notmuch_compact_status_cb_t status_cb)) + unused (notmuch_compact_status_cb_t status_cb), + unused (void *closure)) { fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n"); return NOTMUCH_STATUS_UNSUPPORTED_OPERATION; diff --git a/lib/notmuch.h b/lib/notmuch.h index 9dab555f..cd301a4f 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -219,7 +219,7 @@ notmuch_database_close (notmuch_database_t *database); /* A callback invoked by notmuch_database_compact to notify the user * of the progress of the compaction process. */ -typedef void (*notmuch_compact_status_cb_t)(const char*); +typedef void (*notmuch_compact_status_cb_t)(const char *message, void *closure); /* Compact a notmuch database, backing up the original database to the * given path. @@ -231,7 +231,8 @@ typedef void (*notmuch_compact_status_cb_t)(const char*); notmuch_status_t notmuch_database_compact (const char* path, const char* backup_path, - notmuch_compact_status_cb_t status_cb); + notmuch_compact_status_cb_t status_cb, + void *closure); /* Destroy the notmuch database, closing it if necessary and freeing * all associated resources. diff --git a/notmuch-compact.c b/notmuch-compact.c index bfda40e3..ee7afcf6 100644 --- a/notmuch-compact.c +++ b/notmuch-compact.c @@ -20,10 +20,8 @@ #include "notmuch-client.h" -void status_update_cb (const char *msg); - -void -status_update_cb (const char *msg) +static void +status_update_cb (const char *msg, unused (void *closure)) { printf("%s\n", msg); } @@ -38,7 +36,7 @@ notmuch_compact_command (notmuch_config_t *config, notmuch_status_t ret; printf ("Compacting database...\n"); - ret = notmuch_database_compact (path, backup_path, status_update_cb); + ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL); if (ret) { fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string(ret)); } else {