extra stuff

This commit is contained in:
Gvidas Juknevičius 2024-06-23 14:16:27 +03:00
parent 5b3b89ec4c
commit 6dd22fe0c3
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
4 changed files with 70 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
/target /target
/plugins /plugins
/.cache /.cache
/config/*
!/config/main.template.toml
compile_commands.json compile_commands.json

12
Cargo.lock generated
View File

@ -592,6 +592,18 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "volume"
version = "0.1.0"
dependencies = [
"anyhow",
"dim_sdk",
"lazy_static",
"regex",
"serde",
"toml",
]
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.92" version = "0.2.92"

View File

@ -5,6 +5,7 @@ members = [
"dim_plugins/clock", "dim_plugins/clock",
"dim_plugins/counter", "dim_plugins/counter",
"dim_plugins/battery", "dim_plugins/battery",
"dim_plugins/volume",
] ]
[package] [package]

55
\ Normal file
View File

@ -0,0 +1,55 @@
// Lord have mercy on me
#[macro_export]
macro_rules! plugin_info {
($typ:ty, $name:literal, $version:literal, $license:literal) => {
lazy_static::lazy_static!(
static ref PLUGIN_INFO: $crate::PluginInfo = $crate::PluginInfo::new($name, $version, $license);
);
static mut PLUG: *mut $typ = std::ptr::null_mut() as *mut $typ;
#[no_mangle]
unsafe extern "C" fn plug_get_info() -> *const std::ffi::c_void {
PLUGIN_INFO.get_raw_ptr()
}
#[no_mangle]
unsafe extern "C" fn plug_init(ctx: *const $crate::ContextRaw) {
PLUG = std::alloc::alloc(std::alloc::Layout::new::<$typ>()) as *mut $typ;
*PLUG = <$typ>::new();
let ctx = $crate::Context::new(ctx);
(&mut *PLUG).init(ctx);
}
#[no_mangle]
unsafe extern "C" fn plug_pre_reload() -> *mut $typ {
//TODO: Untested
(&mut *PLUG).pre_reload();
return PLUG;
}
#[no_mangle]
unsafe extern "C" fn plug_post_reload(state: *mut $typ) {
//TODO: Untested
PLUG = state;
(&mut *PLUG).post_reload();
}
#[no_mangle]
unsafe extern "C" fn plug_poll(buf: *mut i8, len: std::ffi::c_uint) {
let mut buf = $crate::CBuffer::from_raw_parts_mut(buf, len as usize);
if let Err(_e) = (&mut *PLUG).poll(&mut buf) {
// TODO: Handle error maybe?
}
}
#[no_mangle]
unsafe extern "C" fn plug_free() {
std::alloc::dealloc(PLUG as *mut u8, std::alloc::Layout::new::<$typ>());
(&mut *PLUG).free();
}
};
}