use std::ffi::c_char;
use std::os::raw::c_void;
pub const NODE_APP_ENTRY_SYMBOL: &[u8] = b"_node_app_entry\0";
#[repr(C)]
#[derive(Debug)]
pub struct FfiResult {
pub success: bool,
pub error_code: i32,
pub data: *mut u8,
pub data_len: usize,
}
impl FfiResult {
pub fn ok() -> Self {
Self {
success: true,
error_code: 0,
data: std::ptr::null_mut(),
data_len: 0,
}
}
pub fn error(code: i32) -> Self {
Self {
success: false,
error_code: code,
data: std::ptr::null_mut(),
data_len: 0,
}
}
}
#[repr(C)]
pub struct NodeAppMetadata {
pub api_version: u32,
pub name: *const c_char,
pub version: *const c_char,
pub author: *const c_char,
pub description: *const c_char,
pub capabilities: u32,
}
#[repr(C)]
pub struct NodeAppVTable {
pub metadata: NodeAppMetadata,
pub init: unsafe extern "C" fn(ctx: *const c_void) -> FfiResult,
pub shutdown: unsafe extern "C" fn() -> FfiResult,
pub handle_request:
unsafe extern "C" fn(request_json: *const u8, request_len: usize) -> FfiResult,
pub handle_event: unsafe extern "C" fn(event_json: *const u8, event_len: usize) -> FfiResult,
pub handle_capability:
unsafe extern "C" fn(request_json: *const u8, request_len: usize) -> FfiResult,
pub free: unsafe extern "C" fn(ptr: *mut u8, len: usize),
}
unsafe impl Send for NodeAppMetadata {}
unsafe impl Sync for NodeAppMetadata {}
unsafe impl Send for NodeAppVTable {}
unsafe impl Sync for NodeAppVTable {}
pub type NodeAppEntryFn = unsafe extern "C" fn(ctx: *const c_void) -> *const NodeAppVTable;