use std::collections::BTreeMap;
use std::ffi::CStr;
use std::os::raw::c_char;
use semq_sys as sys;
use crate::config::Operator;
pub(crate) const SDK_VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BuildInfo {
pub sdk_version: String,
pub core_version: String,
pub backend: BTreeMap<Operator, String>,
pub build_id: String,
}
pub fn build_info() -> BuildInfo {
let backend = [Operator::Orbit, Operator::Phase, Operator::Quant]
.into_iter()
.map(|op| {
let name = static_str(unsafe { sys::semq_backend_name(op.as_raw()) });
(op, name.to_owned())
})
.collect();
BuildInfo {
sdk_version: SDK_VERSION.to_owned(),
core_version: core_version().to_owned(),
backend,
build_id: build_id().to_owned(),
}
}
pub(crate) fn core_version() -> &'static str {
static_str(unsafe { sys::semq_core_version() })
}
pub(crate) fn build_id() -> &'static str {
static_str(unsafe { sys::semq_build_id() })
}
pub(crate) fn status_name(status: u32) -> &'static str {
static_str(unsafe { sys::semq_status_name(status) })
}
fn static_str(ptr: *const c_char) -> &'static str {
if ptr.is_null() {
return "";
}
unsafe { CStr::from_ptr(ptr) }.to_str().unwrap_or("")
}