Initialize a connection to the cpg 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)
| 331 | /// else and use the passed back [Handle]. |
| 332 | /// Remember to free the handle using [finalize] when finished. |
| 333 | pub fn initialize(model_data: &ModelData, context: u64) -> Result<Handle> { |
| 334 | let mut handle: ffi::cpg_handle_t = 0; |
| 335 | let mut m = match model_data { |
| 336 | ModelData::ModelV1(_v1) => { |
| 337 | ffi::cpg_model_v1_data_t { |
| 338 | model: ffi::CPG_MODEL_V1, |
| 339 | cpg_deliver_fn: Some(rust_deliver_fn), |
| 340 | cpg_confchg_fn: Some(rust_confchg_fn), |
| 341 | cpg_totem_confchg_fn: Some(rust_totem_confchg_fn), |
| 342 | flags: 0, // No supported flags (yet) |
| 343 | } |
| 344 | } |
| 345 | _ => return Err(CsError::CsErrInvalidParam), |
| 346 | }; |
| 347 | |
| 348 | unsafe { |
| 349 | let c_context: *mut c_void = &mut &context as *mut _ as *mut c_void; |
| 350 | let c_model: *mut ffi::cpg_model_data_t = &mut m as *mut _ as *mut ffi::cpg_model_data_t; |
| 351 | let res = ffi::cpg_model_initialize(&mut handle, m.model, c_model, c_context); |
| 352 | |
| 353 | if res == ffi::CS_OK { |
| 354 | let rhandle = Handle { |
| 355 | cpg_handle: handle, |
| 356 | model_data: *model_data, |
| 357 | clone: false, |
| 358 | }; |
| 359 | HANDLE_HASH.lock().unwrap().insert(handle, rhandle.clone()); |
| 360 | Ok(rhandle) |
| 361 | } else { |
| 362 | Err(CsError::from_c(res)) |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | /// Finish with a connection to corosync |
| 368 | pub fn finalize(handle: &Handle) -> Result<()> { |