libctdb: add synchronous message handling and unregister, with tests.
[sahlberg/ctdb.git] / libctdb / sync.c
index 2e6ba9926fe5dae1b804a1e7c49a113082a7c483..2ec96d8737b444badace1b3b7d3d94c0a75dccca 100644 (file)
@@ -23,6 +23,9 @@
 #include <stdlib.h>
 #include "libctdb_private.h"
 
+/* Remove type-safety macros. */
+#undef ctdb_set_message_handler
+
 /* On failure, frees req and returns NULL. */
 static struct ctdb_request *synchronous(struct ctdb_connection *ctdb,
                                        struct ctdb_request *req,
@@ -116,6 +119,24 @@ bool ctdb_getpnn(struct ctdb_connection *ctdb,
        return ret;
 }
 
+bool ctdb_set_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
+                             ctdb_message_fn_t handler, void *cbdata)
+{
+       struct ctdb_request *req;
+       bool done = false;
+       bool ret = false;
+
+       req = synchronous(ctdb,
+                         ctdb_set_message_handler_send(ctdb, srvid, handler,
+                                                       cbdata, set, &done),
+                         &done);
+       if (req != NULL) {
+               ret = ctdb_set_message_handler_recv(ctdb, req);
+               ctdb_request_free(ctdb, req);
+       }
+       return ret;
+}
+
 struct rrl_info {
        bool done;
        struct ctdb_lock *lock;