libctdb: first cut, supports getrecmaster only
[sahlberg/ctdb.git] / libctdb / libctdb_private.h
1 #ifndef _LIBCTDB_PRIVATE_H
2 #define _LIBCTDB_PRIVATE_H
3 #include <dlinklist.h>
4 #include <stdbool.h>
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include <ctdb.h>
8
9 struct message_handler_info;
10 struct ctdb_reply_call;
11
12 struct ctdb_request {
13         struct ctdb_request *next, *prev;
14         struct io_elem *io;
15         union {
16                 struct ctdb_req_header *hdr;
17                 struct ctdb_req_call *call;
18                 struct ctdb_req_control *control;
19                 struct ctdb_req_message *message;
20         } hdr;
21         bool cancelled;
22         union {
23                 ctdb_getrecmaster_cb getrecmaster;
24                 ctdb_getpnn_cb getpnn;
25                 void (*register_srvid)(int, struct message_handler_info *);
26                 void (*attachdb)(int, uint32_t id, struct ctdb_db *);
27                 void (*getdbpath)(int, const char *, void *);
28                 void (*nullfunc)(int, struct ctdb_reply_call *, void *);
29                 void (*immediate)(struct ctdb_request *, void *);
30         } callback;
31         void *priv_data;
32 };
33
34 struct ctdb_connection {
35         /* Socket to ctdbd. */
36         int fd;
37         /* Currently our failure mode is simple; return -1 from ctdb_service */
38         bool broken;
39         /* Linked list of pending outgoings. */
40         struct ctdb_request *outq;
41         /* Finished outgoings (awaiting response) */
42         struct ctdb_request *doneq;
43         /* Successful sync requests, waiting for next service. */
44         struct ctdb_request *immediateq;
45         /* Current incoming. */
46         struct io_elem *in;
47         /* Guess at a good reqid to try next. */
48         uint32_t next_id;
49         /* List of messages */
50         struct message_handler_info *message_handlers;
51         /* PNN of this ctdb: valid by the time we do our first db connection. */
52         uint32_t pnn;
53 };
54
55 /* ctdb.c */
56 struct ctdb_request *new_ctdb_request(size_t len);
57 struct ctdb_request *new_ctdb_control_request(struct ctdb_connection *ctdb,
58                                               uint32_t opcode,
59                                               uint32_t destnode,
60                                               const void *extra_data,
61                                               size_t extra);
62 uint32_t new_reqid(struct ctdb_connection *ctdb);
63 #endif /* _LIBCTDB_PRIVATE_H */