+/*
+ tell the daemon what messaging srvid we will use, and register the message
+ handler function in the client
+*/
+ctdb_handle *
+ctdb_set_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
+ ctdb_set_message_handler_cb callback,
+ ctdb_message_fn_t handler,
+ void *private_data)
+
+{
+ struct ctdb_client_control_state *state;
+ struct ctdb_control_cb_data *cb_data;
+
+ if (ctdb_register_message_handler(ctdb, ctdb, srvid, handler, private_data) != 0) {
+ return NULL;
+ }
+
+ state = ctdb_control_send(ctdb, CTDB_CURRENT_NODE, srvid,
+ CTDB_CONTROL_REGISTER_SRVID, 0, tdb_null,
+ ctdb, NULL, NULL);
+
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to send REGISTER_SRVID control\n"));
+ return NULL;
+ }
+
+ if (callback != NULL) {
+ cb_data = talloc(state, struct ctdb_control_cb_data);
+ cb_data->callback = callback;
+ cb_data->private_data = private_data;
+
+ state->async.fn = ctdb_getrecmaster_recv_cb;
+ state->async.private_data = cb_data;
+ }
+
+ return (ctdb_handle *)state;
+}
+
+int ctdb_set_message_handler_recv(struct ctdb_context *ctdb, ctdb_handle *handle)
+{
+ struct ctdb_client_control_state *state = talloc_get_type(handle, struct ctdb_client_control_state);
+ int ret;
+ int32_t res;
+
+ ret = ctdb_control_recv(ctdb, state, state, NULL, &res, NULL);
+ if (ret != 0 || res != 0) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_set_message_handler_recv failed\n"));
+ return -1;
+ }
+
+ return state->status;
+}
+
+int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, ctdb_message_fn_t handler, void *private_data)
+{
+ struct ctdb_client_control_state *state;
+
+ state = ctdb_set_message_handler_send(ctdb, srvid, NULL, handler, private_data);
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_set_message_handler_send() failed.\n"));
+ return -1;
+ }
+
+ return ctdb_set_message_handler_recv(ctdb, state);
+}