From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A39B8429E3E for ; Sun, 3 Nov 2013 04:25:30 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gAUrwLYers1X for ; Sun, 3 Nov 2013 04:25:24 -0800 (PST) Received: from mail-ee0-f50.google.com (mail-ee0-f50.google.com [74.125.83.50]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 399E8431FDE for ; Sun, 3 Nov 2013 04:25:08 -0800 (PST) Received: by mail-ee0-f50.google.com with SMTP id l10so581664eei.37 for ; Sun, 03 Nov 2013 04:25:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=DWEBbUuiEDmuadlgd42BYlBJOj0kYq9uRut/OMxFDXU=; b=UZW6cCtVzWaOSxChr+7+NEsrtQbc3t9DKzh0HAUtkx3XpvnKS/h3wTyJmgPSZ8AHtK cX/8niCO5V8FJhP1gAGqhh2MWLxEBkRt9h5I+qNT9Rkq6G1iNY7G3R4orkixQVFCv1H3 G+ThAkZfXAPVRW4dRQZ7LSuSmClq7TT04n0saVdIaM0CbgV2vCxGGuwet9KXwghSjg7l y5eMkt+Gxrlpz9mSNHfJSLm4dTNY54VSyhhBkOwf4BhhFd3lxYAKiSohlN58CEupigXu kTgIhQH+G68O936JICRnX3+nHbOs4s7ZQOYGbct4UTqBgAlfm6xy+EyaoviMSgDdV+un qFig== X-Gm-Message-State: ALoCoQmVQBcBe9EnXS5MMzZUqpRurdG/L4vT9Z3KheTbGqSAvH8XmyhYp4DO6VrSdlXNaD5GQZxm X-Received: by 10.14.224.132 with SMTP id x4mr12725741eep.5.1383481506926; Sun, 03 Nov 2013 04:25:06 -0800 (PST) Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. [88.195.111.91]) by mx.google.com with ESMTPSA id k7sm32794500eeg.13.2013.11.03.04.25.05 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 03 Nov 2013 04:25:06 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v2 05/11] lib: add closure parameter to compact status update callback Date: Sun, 3 Nov 2013 14:24:45 +0200 Message-Id: <277337f8810959b702ddc657e88577c125cbd15e.1383481295.git.jani@nikula.org> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: References: In-Reply-To: References: X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Nov 2013 12:25:31 -0000 This provides much more flexibility for the caller. --- lib/database.cc | 14 +++++++++----- lib/notmuch.h | 5 +++-- notmuch-compact.c | 8 +++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index eadf8a7..5a01703 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 9dab555..cd301a4 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 bfda40e..ee7afcf 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 { -- 1.8.4.rc3