extern crate griddbnet_sys as ffi;
use crate::griddb::Store::*;
use crate::griddb::Util::*;
use std::ffi::CString;
use std::ptr;
use std::vec::Vec;
const RUST_CLIENT_VERSION: &str = "GridDB Rust Client Version 0.6";
pub type GSGridStore = ffi::GSGridStoreTag;
pub struct StoreFactory {
_ptr: *mut ffi::GSGridStoreFactory,
}
impl StoreFactory {
pub fn get_instance() -> StoreFactory {
let _factory;
unsafe {
_factory = ffi::gsGetDefaultFactory();
}
StoreFactory { _ptr: _factory }
}
pub fn get_store(&self, properties: Vec<(&str, &str)>) -> Result<Store, i32> {
let mut temp_vec: Vec<CString> = Vec::new();
let _properties = Util::tup_to_properties(properties, &mut temp_vec);
let mut _store: *mut ffi::GSGridStore = ptr::null_mut();
let ret;
let property_count = _properties.iter().len();
unsafe {
ret = ffi::gsGetGridStore(
self._ptr,
_properties.as_ptr(),
property_count as u64,
&mut _store,
);
}
drop(temp_vec);
if ret == ffi::GS_RESULT_OK as i32 {
Ok(Store::new(_store))
} else {
Err(ret)
}
}
pub fn get_version() -> String {
String::from(RUST_CLIENT_VERSION)
}
}
impl Drop for StoreFactory {
fn drop(&mut self) {
let all_related = ffi::GS_FALSE;
unsafe {
ffi::gsCloseFactory(&mut self._ptr, all_related as i8);
}
}
}