| 70 | DECLARE_HDB_DATABASE(votequorum_handle_t_db, votequorum_inst_free); |
| 71 | |
| 72 | cs_error_t votequorum_initialize ( |
| 73 | votequorum_handle_t *handle, |
| 74 | votequorum_callbacks_t *callbacks) |
| 75 | { |
| 76 | cs_error_t error; |
| 77 | struct votequorum_inst *votequorum_inst; |
| 78 | |
| 79 | error = hdb_error_to_cs(hdb_handle_create (&votequorum_handle_t_db, sizeof (struct votequorum_inst), handle)); |
| 80 | if (error != CS_OK) { |
| 81 | goto error_no_destroy; |
| 82 | } |
| 83 | |
| 84 | error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, *handle, (void *)&votequorum_inst)); |
| 85 | if (error != CS_OK) { |
| 86 | goto error_destroy; |
| 87 | } |
| 88 | |
| 89 | votequorum_inst->finalize = 0; |
| 90 | votequorum_inst->c = qb_ipcc_connect ("votequorum", IPC_REQUEST_SIZE); |
| 91 | if (votequorum_inst->c == NULL) { |
| 92 | error = qb_to_cs_error(-errno); |
| 93 | goto error_put_destroy; |
| 94 | } |
| 95 | |
| 96 | if (callbacks) |
| 97 | memcpy(&votequorum_inst->callbacks, callbacks, sizeof (*callbacks)); |
| 98 | else |
| 99 | memset(&votequorum_inst->callbacks, 0, sizeof (*callbacks)); |
| 100 | |
| 101 | hdb_handle_put (&votequorum_handle_t_db, *handle); |
| 102 | |
| 103 | return (CS_OK); |
| 104 | |
| 105 | error_put_destroy: |
| 106 | hdb_handle_put (&votequorum_handle_t_db, *handle); |
| 107 | error_destroy: |
| 108 | hdb_handle_destroy (&votequorum_handle_t_db, *handle); |
| 109 | error_no_destroy: |
| 110 | return (error); |
| 111 | } |
| 112 | |
| 113 | static void votequorum_inst_free (void *inst) |
| 114 | { |