}
-void pnn_cb(int32_t status, int32_t pnn, void *private_data)
+void pnn_cb(int32_t status, struct ctdb_context *ctdb, ctdb_handle *handle, void *private_data)
{
+ uint32_t pnn;
+ int ret;
+
+ if (status != 0) {
+ printf("Error reading PNN\n");
+ return;
+ }
+
+ ret = ctdb_getpnn_recv(ctdb, handle, &pnn);
+ if (ret != 0) {
+ printf("Failed to read getpnn reply\n");
+ return;
+ }
+
printf("status:%d pnn:%d\n", status, pnn);
}
int main(int argc, char *argv[])
{
- struct ctdb_context *ctdb_context;
+ struct ctdb_context *ctdb;
struct ctdb_db_context *ctdb_db_context;
ctdb_handle *handle;
struct pollfd pfd;
key.dptr = "Test Record";
key.dsize = strlen(key.dptr);
- ctdb_context = ctdb_connect("/tmp/ctdb.socket");
+ ctdb = ctdb_connect("/tmp/ctdb.socket");
- handle = ctdb_set_message_handler_send(ctdb_context, 55, NULL, msg_h, NULL);
+ handle = ctdb_set_message_handler_send(ctdb, 55, NULL, msg_h, NULL);
if (handle == NULL) {
printf("Failed to register message port\n");
exit(10);
}
- ret = ctdb_set_message_handler_recv(ctdb_context, handle);
+ ret = ctdb_set_message_handler_recv(ctdb, handle);
if (ret != 0) {
printf("Failed to receive set_message_handler reply\n");
exit(10);
msg.dptr="HelloWorld";
msg.dsize = strlen(msg.dptr);
- ret = ctdb_send_message(ctdb_context, 0, 55, msg);
+ ret = ctdb_send_message(ctdb, 0, 55, msg);
if (ret != 0) {
printf("Failed to send message. Aborting\n");
exit(10);
}
- handle = ctdb_attachdb_send(ctdb_context, "test_test.tdb", 0, 0, NULL, NULL);
+ handle = ctdb_attachdb_send(ctdb, "test_test.tdb", 0, 0, NULL, NULL);
if (handle == NULL) {
printf("Failed to send attachdb control\n");
exit(10);
}
- ret = ctdb_attachdb_recv(ctdb_context, handle, &ctdb_db_context);
+ ret = ctdb_attachdb_recv(ctdb, handle, &ctdb_db_context);
if (ret != 0 ) {
printf("Failed to attach to database\n");
exit(10);
}
- handle = ctdb_getpnn_send(ctdb_context, CTDB_CURRENT_NODE, pnn_cb, NULL);
+
+
+ handle = ctdb_getpnn_send(ctdb, CTDB_CURRENT_NODE);
if (handle == NULL) {
printf("Failed to send get_pnn control\n");
exit(10);
}
+ ret = ctdb_set_callback(handle, pnn_cb, NULL);
+ if (ret != 0) {
+ printf("Failed to set callback for getpnn\n");
+ ctdb_free(handle);
+ exit(10);
+ }
+
+
+
- handle = ctdb_readrecordlock_send(ctdb_context, ctdb_db_context, key, rrl_cb, NULL);
+ handle = ctdb_readrecordlock_send(ctdb, ctdb_db_context, key, rrl_cb, NULL);
if (handle == NULL) {
printf("Failed to send READRECORDLOCK\n");
exit(10);
}
- pfd.fd = ctdb_get_fd(ctdb_context);
+ pfd.fd = ctdb_get_fd(ctdb);
for (;;) {
- pfd.events = ctdb_which_events(ctdb_context);
+ pfd.events = ctdb_which_events(ctdb);
if (poll(&pfd, 1, -1) < 0) {
printf("Poll failed");
exit(10);
}
- ctdb_service(ctdb_context);
+ ctdb_service(ctdb);
}
return 0;