Initialize a connection to the cfg library. You must call this before doing anything else and use the passed back [Handle]. Remember to free the handle using [finalize] when finished.
(callbacks: &Callbacks)
| 127 | /// else and use the passed back [Handle]. |
| 128 | /// Remember to free the handle using [finalize] when finished. |
| 129 | pub fn initialize(callbacks: &Callbacks) -> Result<Handle> { |
| 130 | let mut handle: ffi::corosync_cfg_handle_t = 0; |
| 131 | |
| 132 | let c_callbacks = ffi::corosync_cfg_callbacks_t { |
| 133 | corosync_cfg_shutdown_callback: Some(rust_shutdown_notification_fn), |
| 134 | }; |
| 135 | |
| 136 | unsafe { |
| 137 | let res = ffi::corosync_cfg_initialize(&mut handle, &c_callbacks); |
| 138 | if res == ffi::CS_OK { |
| 139 | let rhandle = Handle { |
| 140 | cfg_handle: handle, |
| 141 | callbacks: *callbacks, |
| 142 | clone: false, |
| 143 | }; |
| 144 | HANDLE_HASH.lock().unwrap().insert(handle, rhandle.clone()); |
| 145 | Ok(rhandle) |
| 146 | } else { |
| 147 | Err(CsError::from_c(res)) |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /// Finish with a connection to corosync, after calling this the [Handle] is invalid |
| 153 | pub fn finalize(handle: &Handle) -> Result<()> { |
nothing calls this directly
no test coverage detected