create an async version of ctdb_attachdb_send() for libctdb
[sahlberg/ctdb.git] / libctdb / ctdb_client.c
index c7ce13889d74f969b1011e367f2dc2fdf7482022..864877ce5af73677da4549a69f22a28991a7a687 100644 (file)
@@ -216,7 +216,7 @@ int ctdb_control_recv(struct ctdb_context *ctdb,
    called when a control completes or timesout to invoke the callback
    function the user provided
 */
-static void invoke_control_callback(struct event_context *ev, struct timed_event *te, 
+void ctdb_invoke_control_callback(struct event_context *ev, struct timed_event *te, 
        struct timeval t, void *private_data)
 {
        struct ctdb_client_control_state *state;
@@ -278,7 +278,7 @@ static void ctdb_client_reply_control(struct ctdb_context *ctdb,
           and call the callback.
        */
        if (state->async.fn) {
-               event_add_timed(ctdb->ev, state, timeval_zero(), invoke_control_callback, state);
+               event_add_timed(ctdb->ev, state, timeval_zero(), ctdb_invoke_control_callback, state);
        }
 }
 
@@ -436,32 +436,11 @@ static int ctdb_client_queue_pkt(struct ctdb_context *ctdb, struct ctdb_req_head
 }
 
 
-/* time out handler for ctdb_control */
-static void control_timeout_func(struct event_context *ev, struct timed_event *te, 
-       struct timeval t, void *private_data)
-{
-       struct ctdb_client_control_state *state = talloc_get_type(private_data, struct ctdb_client_control_state);
-
-       DEBUG(DEBUG_ERR,(__location__ " control timed out. reqid:%u opcode:%u "
-                        "dstnode:%u\n", state->reqid, state->c->opcode,
-                        state->c->hdr.destnode));
-
-       state->state = CTDB_CONTROL_TIMEOUT;
-
-       /* if we had a callback registered for this control, pull the response
-          and call the callback.
-       */
-       if (state->async.fn) {
-               event_add_timed(state->ctdb->ev, state, timeval_zero(), invoke_control_callback, state);
-       }
-}
-
 /* async version of send control request */
 struct ctdb_client_control_state *ctdb_control_send(struct ctdb_context *ctdb, 
                uint32_t destnode, uint64_t srvid, 
                uint32_t opcode, uint32_t flags, TDB_DATA data, 
                TALLOC_CTX *mem_ctx,
-               struct timeval *timeout,
                char **errormsg)
 {
        struct ctdb_client_control_state *state;
@@ -504,11 +483,6 @@ struct ctdb_client_control_state *ctdb_control_send(struct ctdb_context *ctdb,
                memcpy(&c->data[0], data.dptr, data.dsize);
        }
 
-       /* timeout */
-       if (timeout && !timeval_is_zero(timeout)) {
-               event_add_timed(ctdb->ev, state, *timeout, control_timeout_func, state);
-       }
-
        ret = ctdb_client_queue_pkt(ctdb, &(c->hdr));
        if (ret != 0) {
                talloc_free(state);
@@ -680,4 +654,40 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn,
 
 
 
+/*
+  setup a call for a database
+ */
+int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id)
+{
+       struct ctdb_registered_call *call;
+
+#if 0
+       TDB_DATA data;
+       int32_t status;
+       struct ctdb_control_set_call c;
+       int ret;
+
+       /* this is no longer valid with the separate daemon architecture */
+       c.db_id = ctdb_db->db_id;
+       c.fn    = fn;
+       c.id    = id;
 
+       data.dptr = (uint8_t *)&c;
+       data.dsize = sizeof(c);
+
+       ret = ctdb_control(ctdb_db->ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_SET_CALL, 0,
+                          data, NULL, NULL, &status, NULL, NULL);
+       if (ret != 0 || status != 0) {
+               DEBUG(DEBUG_ERR,("ctdb_set_call failed for call %u\n", id));
+               return -1;
+       }
+#endif
+
+       /* also register locally */
+       call = talloc(ctdb_db, struct ctdb_registered_call);
+       call->fn = fn;
+       call->id = id;
+
+       DLIST_ADD(ctdb_db->calls, call);        
+       return 0;
+}