use std::ffi::c_void;
use std::os::raw::c_ulong;
type THD = c_void;
#[derive(Eq, PartialEq, Copy, Clone)]
#[cfg_attr(test, derive(Debug))]
#[non_exhaustive]
#[repr(i32)]
pub enum PluginType {
Udf = 0,
Storage = 1,
}
#[derive(Eq, PartialEq, Copy, Clone)]
#[cfg_attr(test, derive(Debug))]
#[repr(i32)]
pub enum License {
Proprietary = 0,
Gpl = 1,
Bsd = 2,
}
#[derive(Copy, Clone)]
#[cfg_attr(test, derive(Debug))]
#[repr(C)]
pub struct StorageEngineInfo {
pub interface_version: i32,
}
#[derive(Eq, PartialEq, Copy, Clone)]
#[cfg_attr(test, derive(Debug))]
#[allow(missing_docs)]
#[repr(C)]
pub enum ShowCompOption {
Yes,
No,
Disabled,
}
#[derive(Eq, PartialEq, Copy, Clone)]
#[cfg_attr(test, derive(Debug))]
#[allow(missing_docs)]
#[repr(C)]
pub enum LegacyDbType {
Unknown = 0,
DiabIsam = 1,
Hash,
MIsam,
PIsam,
RmsIsam,
Heam,
Isam,
MrgIsam,
MyIsam,
MrgMyIsam,
BerkeleyDb,
InnoDb,
Gemini,
NDbCluster,
ExampleDb,
ArchiveDb,
CsvDb,
FederatedDb,
BlackholeDb,
PartitionDb,
Binlog,
Solid,
Pbxt,
TableFunction,
MemCache,
Falcon,
Maria,
PerformanceSchema,
TempTable,
FirstDynamic = 42,
Default = 127, }
pub type CloseConnectionFunc = extern "C" fn(hton: *mut Handlerton, thd: *mut THD) -> i32;
pub type KillConnectionFunc = extern "C" fn(hton: *mut Handlerton, thd: *mut THD);
pub type PreDdShutdownFunc = extern "C" fn(hton: *mut Handlerton);
#[derive(Copy, Clone)]
#[cfg_attr(test, derive(Debug))]
#[allow(missing_docs)]
#[repr(C)]
pub struct Handlerton {
pub state: ShowCompOption,
pub db_type: LegacyDbType,
pub slot: u32,
pub savepoint_offset: u32,
pub close_connection: *const CloseConnectionFunc,
pub kill_connection: *const KillConnectionFunc,
pub pre_dd_shutdown: *const PreDdShutdownFunc,
}
pub type InitFunc = extern "C" fn(*mut c_void) -> i32;
pub type CheckUninstallFunc = extern "C" fn(*mut c_void) -> i32;
pub type DeinitFunc = extern "C" fn(*mut c_void) -> i32;
#[cfg_attr(test, derive(Debug))]
#[repr(C)]
pub struct Plugin {
pub plugin_type: PluginType,
pub info: *const c_void,
pub name: *const u8,
pub author: *const u8,
pub descr: *const u8,
pub license: License,
pub init: *const InitFunc,
pub check_uninstall: *const CheckUninstallFunc,
pub deinit: *const DeinitFunc,
pub version: u32,
pub status_vars: *const c_void,
pub system_vars: *const c_void,
pub reserved: *const c_void,
pub flags: c_ulong,
}
unsafe impl Sync for Plugin {}
impl Plugin {
pub const fn zero() -> Self {
Self {
plugin_type: PluginType::Udf,
info: std::ptr::null_mut(),
name: std::ptr::null(),
author: std::ptr::null(),
descr: std::ptr::null(),
license: License::Proprietary,
init: std::ptr::null(),
check_uninstall: std::ptr::null(),
deinit: std::ptr::null(),
version: 0,
status_vars: std::ptr::null(),
system_vars: std::ptr::null(),
reserved: std::ptr::null(),
flags: 0,
}
}
}
#[cfg(test)]
mod tests {
use std::ffi::c_void;
use crate::constants::MYSQL_HANDLERTON_INTERFACE_VERSION;
use crate::types::{License, Plugin, PluginType, StorageEngineInfo};
#[test]
fn create_plugin_struct() {
let info = StorageEngineInfo {
interface_version: MYSQL_HANDLERTON_INTERFACE_VERSION,
};
let plugin = Plugin {
plugin_type: PluginType::Storage,
info: &info as *const _ as *const c_void,
name: b"example\0" as *const u8,
author: b"Felix Bytow\0" as *const u8,
descr: b"Example storage engine in Rust\0" as *const u8,
license: License::Bsd,
..Plugin::zero()
};
let _plugins: [Plugin; 2] = [
plugin,
Plugin::zero(),
];
}
}