diff --git a/src/bindings/plugin_abi.rs b/src/bindings/plugin_abi.rs index 29db19d..17cce7d 100644 --- a/src/bindings/plugin_abi.rs +++ b/src/bindings/plugin_abi.rs @@ -28,6 +28,7 @@ pub enum LogLevel { #[repr(i32)] #[derive(Debug, Copy, Clone)] +#[non_exhaustive] pub enum PluginString { Name, // the name of the plugin LogName, // the name used for logging @@ -36,8 +37,10 @@ pub enum PluginString { #[repr(u32)] #[derive(Debug, Copy, Clone)] +#[non_exhaustive] pub enum PluginField { Context, + Color, } bitflags! { @@ -47,3 +50,11 @@ bitflags! { const CLIENT = 0x2; } } + +#[repr(packed)] +#[derive(Debug, Copy, Clone)] +pub struct PluginColor { + pub red: u8, + pub green: u8, + pub blue: u8, +} diff --git a/src/high/northstar.rs b/src/high/northstar.rs index 31440de..a06f4cc 100644 --- a/src/high/northstar.rs +++ b/src/high/northstar.rs @@ -2,7 +2,7 @@ use std::ffi::CStr; -use crate::bindings::plugin_abi::PluginContext; +use crate::bindings::plugin_abi::{PluginColor, PluginContext}; /// information about the plugin that the plugins system requests #[derive(Debug)] @@ -11,6 +11,7 @@ pub struct PluginInfo { log_name: &'static CStr, dependency_name: &'static CStr, context: PluginContext, + color: PluginColor, } impl PluginInfo { @@ -38,28 +39,55 @@ impl PluginInfo { "consider actually having a dependency_name" ); assert!(log_name.to_bytes().len() == 9, "log name is used for logging and ideally should be 9 chars long and all upercase to look like every other log str"); + // assert!(dependency_name.to_bytes() ); // TODO a check valid constants Self { name, log_name, dependency_name, context, + color: PluginColor { + red: 244, + green: 106, + blue: 14, + }, } } - /// Returns a reference to the get name of the plugin. + /// Creates a new [`PluginInfo`] but with a color for logs. + /// + /// # Panics + /// refer to `new` + pub const fn new_with_color( + name: &'static CStr, + log_name: &'static CStr, + dependency_name: &'static CStr, + context: PluginContext, + color: PluginColor, + ) -> Self { + Self { + color, + ..Self::new(name, log_name, dependency_name, context) + } + } + + /// Returns a reference to the name of the plugin. pub const fn get_name(&self) -> &'static CStr { self.name } - /// Returns a reference to the get log name of the plugin. + /// Returns a reference to the log name of the plugin. pub const fn get_log_name(&self) -> &'static CStr { self.log_name } - /// Returns a reference to the get dependency name of the plugin. + /// Returns a reference to the dependency name of the plugin. pub const fn get_dependency_name(&self) -> &'static CStr { self.dependency_name } - /// Returns the get context of the plugin. + /// Returns the context of the plugin. pub const fn get_context(&self) -> PluginContext { self.context } + /// Returns the color of the plugin. + pub const fn get_color(&self) -> PluginColor { + self.color + } } diff --git a/src/interfaces/manager.rs b/src/interfaces/manager.rs index 184a5e8..04279ef 100644 --- a/src/interfaces/manager.rs +++ b/src/interfaces/manager.rs @@ -63,7 +63,7 @@ unsafe extern "C" fn create_interface( /// /// # Safety /// -/// marked as unsafe for now since I don't know if the current Interface api is invariant enough +/// marked as unsafe for now since I don't know if the current Interface api safe enough and wouldn't be exploited from safe rust /// /// interfaces must be sync and send have to deal with the Interface struct instead of there struct which all handled by the [`crate::as_interface`] macro pub unsafe fn register_interface( diff --git a/src/macros/entry.rs b/src/macros/entry.rs index 8b11358..9ea864e 100644 --- a/src/macros/entry.rs +++ b/src/macros/entry.rs @@ -61,10 +61,7 @@ macro_rules! entry { Self } - const fn GetString( - &self, - prop: plugin_abi::PluginString, - ) -> *const std::ffi::c_char { + fn GetString(&self, prop: plugin_abi::PluginString) -> *const std::ffi::c_char { match prop { plugin_abi::PluginString::Name => { $plugin::PLUGIN_INFO.get_name().as_ptr() as *const i8 @@ -75,14 +72,35 @@ macro_rules! entry { plugin_abi::PluginString::DependencyName => { $plugin::PLUGIN_INFO.get_dependency_name().as_ptr() as *const i8 } + #[allow(unreachable_patterns)] + // for some reason this warning appears even tho the pattern is non exhaustive + _ => { + log::warn!("invalid plugin string requested!"); + c"err".as_ptr() + } } } - const fn GetField(&self, prop: plugin_abi::PluginField) -> i64 { + fn GetField(&self, prop: plugin_abi::PluginField) -> i64 { match prop { plugin_abi::PluginField::Context => { $plugin::PLUGIN_INFO.get_context().bits() as i64 } + plugin_abi::PluginField::Color => { + let mut packed = 0; + let color = $plugin::PLUGIN_INFO.get_color(); + + packed += color.red as i64; + packed += (color.green as i64) << 8; + packed += (color.blue as i64) << 16; + + packed + } + #[allow(unreachable_patterns)] + _ => { + log::warn!("invalid plugin field requested!"); + 0 + } } } }