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)
return;
}
- status_cb(msg);
+ status_cb(msg, status_closure);
talloc_free(msg);
}
};
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;
}
try {
- NotmuchCompactor compactor(status_cb);
+ NotmuchCompactor compactor(status_cb, closure);
compactor.set_renumber(false);
compactor.add_source(xapian_path);
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;
/* 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.
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.
#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);
}
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 {