Initialize a connection to the quorum library. You must call this before doing anything else and use the passed back [Handle]. Remember to free the handle using [finalize] when finished.
(model_data: &ModelData, context: u64)
| 172 | /// else and use the passed back [Handle]. |
| 173 | /// Remember to free the handle using [finalize] when finished. |
| 174 | pub fn initialize(model_data: &ModelData, context: u64) -> Result<(Handle, QuorumType)> { |
| 175 | let mut handle: ffi::quorum_handle_t = 0; |
| 176 | let mut quorum_type: u32 = 0; |
| 177 | |
| 178 | let mut m = match model_data { |
| 179 | ModelData::ModelV1(_v1) => ffi::quorum_model_v1_data_t { |
| 180 | model: ffi::QUORUM_MODEL_V1, |
| 181 | quorum_notify_fn: Some(rust_quorum_notification_fn), |
| 182 | nodelist_notify_fn: Some(rust_nodelist_notification_fn), |
| 183 | }, |
| 184 | // Only V1 supported. No point in doing legacy stuff in a new binding |
| 185 | _ => return Err(CsError::CsErrInvalidParam), |
| 186 | }; |
| 187 | |
| 188 | handle = unsafe { |
| 189 | let c_context: *mut c_void = &mut &context as *mut _ as *mut c_void; |
| 190 | let c_model: *mut ffi::quorum_model_data_t = |
| 191 | &mut m as *mut _ as *mut ffi::quorum_model_data_t; |
| 192 | let res = ffi::quorum_model_initialize( |
| 193 | &mut handle, |
| 194 | m.model, |
| 195 | c_model, |
| 196 | &mut quorum_type, |
| 197 | c_context, |
| 198 | ); |
| 199 | |
| 200 | if res == ffi::CS_OK { |
| 201 | handle |
| 202 | } else { |
| 203 | return Err(CsError::from_c(res)); |
| 204 | } |
| 205 | }; |
| 206 | |
| 207 | let quorum_type = match quorum_type { |
| 208 | 0 => QuorumType::Free, |
| 209 | 1 => QuorumType::Set, |
| 210 | _ => QuorumType::Set, |
| 211 | }; |
| 212 | let rhandle = Handle { |
| 213 | quorum_handle: handle, |
| 214 | model_data: *model_data, |
| 215 | clone: false, |
| 216 | }; |
| 217 | HANDLE_HASH.lock().unwrap().insert(handle, rhandle.clone()); |
| 218 | Ok((rhandle, quorum_type)) |
| 219 | } |
| 220 | |
| 221 | /// Finish with a connection to corosync |
| 222 | pub fn finalize(handle: &Handle) -> Result<()> { |
nothing calls this directly
no test coverage detected