From fe1b8b88e1d8ced2769bffbd2dccc0a747cef489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20D=C3=A9saulniers?= Date: Fri, 17 Jun 2016 16:37:39 -0400 Subject: [PATCH] pht: provide simpler lookup callback From a user point of view, the structure Prefix doesn't make sense really. It's better to provide a simpler callback function signature for the user then. --- include/opendht/indexation/pht.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/opendht/indexation/pht.h b/include/opendht/indexation/pht.h index 479952a2..92328703 100644 --- a/include/opendht/indexation/pht.h +++ b/include/opendht/indexation/pht.h @@ -148,6 +148,15 @@ public: raw_cb((std::vector>*) &values, (Prefix*) &p, user_data); }; } + using LookupCallbackSimple = std::function>& values)>; + typedef void (*LookupCallbackSimpleRaw)(std::vector>* values, void *user_data); + static LookupCallbackSimple + bindLookupCbSimple(LookupCallbackSimpleRaw raw_cb, void* user_data) { + if (not raw_cb) return {}; + return [=](std::vector>& values) { + raw_cb((std::vector>*) &values, user_data); + }; + } Pht(std::string name, KeySpec k_spec, std::shared_ptr dht) : name_(INDEX_PREFIX + name), canary_(name_ + ".canary"), keySpec_(k_spec), dht_(dht) @@ -160,7 +169,11 @@ public: /** * Lookup a key for a value. */ - void lookup(Key k, LookupCallback cb = {}, DoneCallbackSimple doneCb = {}, bool exact_match = true); + void lookup(Key k, LookupCallback cb = {}, DoneCallbackSimple done_cb = {}, bool exact_match = true); + void lookup(Key k, LookupCallbackSimple cb = {}, DoneCallbackSimple done_cb = {}, bool exact_match = true) + { + lookup(k, [=](std::vector>& values, Prefix) { cb(values); }, done_cb, exact_match); + } /** * Adds an entry into the index. */