use std::ffi::{c_char, c_int, c_void};
#[repr(C)]
pub struct WhiskerEngine {
_private: [u8; 0],
}
#[repr(C)]
pub struct WhiskerElement {
_private: [u8; 0],
}
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum WhiskerElementTag {
Page = 1,
View = 2,
Text = 3,
RawText = 4,
ScrollView = 5,
}
pub type WhiskerTasmCallback = extern "C" fn(user_data: *mut c_void);
pub type WhiskerEventCallback = extern "C" fn(user_data: *mut c_void);
pub type LynxListComponentAtIndexFn = extern "C" fn(
index: u32,
operation_id: i64,
reuse_notification: c_int,
user_data: *mut c_void,
) -> i32;
pub type LynxListEnqueueComponentFn = extern "C" fn(sign: i32, user_data: *mut c_void);
pub type LynxUserDataFreeFn = extern "C" fn(user_data: *mut c_void);
pub const LYNX_LIST_INVALID_INDEX: i32 = -1;
pub type WhiskerEventValueCallback =
extern "C" fn(user_data: *mut c_void, payload: *const WhiskerValueRaw);
pub type WhiskerEventDispatcher = extern "C" fn(
target_sign: i32,
event_name: *const c_char,
body: *const WhiskerValueRaw,
) -> bool;
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WhiskerValueType {
Null = 0,
Bool = 1,
Int = 2,
Float = 3,
String = 4,
Bytes = 5,
Array = 6,
Map = 7,
Error = 8,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct WhiskerStringRef {
pub ptr: *const c_char,
pub len: usize,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct WhiskerBytesRef {
pub ptr: *const u8,
pub len: usize,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct WhiskerValueArray {
pub items: *mut WhiskerValueRaw,
pub count: usize,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct WhiskerValueMap {
pub entries: *mut WhiskerKeyValueRaw,
pub count: usize,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union WhiskerValueUnion {
pub b: bool,
pub i: i64,
pub f: f64,
pub s: WhiskerStringRef,
pub bytes: WhiskerBytesRef,
pub array: WhiskerValueArray,
pub map: WhiskerValueMap,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct WhiskerValueRaw {
pub type_: u8,
pub _pad: [u8; 7],
pub v: WhiskerValueUnion,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct WhiskerKeyValueRaw {
pub key: WhiskerStringRef,
pub value: WhiskerValueRaw,
}
pub type WhiskerModuleCallback =
extern "C" fn(user_data: *mut c_void, result: *const WhiskerValueRaw);
pub type WhiskerModuleEventCallback =
extern "C" fn(user_data: *mut c_void, payload: *const WhiskerValueRaw);
pub type WhiskerModuleObserverHook =
extern "C" fn(module_name: *const c_char, event_name: *const c_char);
pub type WhiskerModuleDispatchFn = extern "C" fn(
method_name: *const c_char,
args: *const WhiskerValueRaw,
arg_count: usize,
) -> WhiskerValueRaw;
extern "C" {
pub fn whisker_bridge_engine_attach(lynx_view_ptr: *mut c_void) -> *mut WhiskerEngine;
pub fn whisker_bridge_engine_release(engine: *mut WhiskerEngine);
pub fn whisker_bridge_dispatch(
engine: *mut WhiskerEngine,
callback: WhiskerTasmCallback,
user_data: *mut c_void,
) -> bool;
pub fn whisker_bridge_create_element(
engine: *mut WhiskerEngine,
tag: WhiskerElementTag,
) -> *mut WhiskerElement;
pub fn whisker_bridge_create_element_by_name(
engine: *mut WhiskerEngine,
tag_name: *const c_char,
) -> *mut WhiskerElement;
pub fn whisker_bridge_release_element(element: *mut WhiskerElement);
pub fn whisker_bridge_set_attribute(
element: *mut WhiskerElement,
key: *const c_char,
value: *const c_char,
);
pub fn whisker_bridge_set_attribute_int(
element: *mut WhiskerElement,
key: *const c_char,
value: i64,
);
pub fn whisker_bridge_set_attribute_bool(
element: *mut WhiskerElement,
key: *const c_char,
value: bool,
);
pub fn whisker_bridge_set_attribute_double(
element: *mut WhiskerElement,
key: *const c_char,
value: f64,
);
pub fn whisker_bridge_set_inline_styles(element: *mut WhiskerElement, css: *const c_char);
pub fn whisker_bridge_list_set_item_count(element: *mut WhiskerElement, count: i32);
pub fn whisker_bridge_list_set_native_item_provider(
element: *mut WhiskerElement,
component_at_index: LynxListComponentAtIndexFn,
enqueue_component: LynxListEnqueueComponentFn,
user_data: *mut c_void,
user_data_free: LynxUserDataFreeFn,
);
pub fn whisker_bridge_debug_log_i32(tag: *const c_char, value: i32);
pub fn whisker_bridge_append_child(parent: *mut WhiskerElement, child: *mut WhiskerElement);
pub fn whisker_bridge_remove_child(parent: *mut WhiskerElement, child: *mut WhiskerElement);
pub fn whisker_bridge_set_event_listener(
element: *mut WhiskerElement,
event_name: *const c_char,
callback: WhiskerEventCallback,
user_data: *mut c_void,
);
pub fn whisker_bridge_set_event_listener_with_value(
element: *mut WhiskerElement,
event_name: *const c_char,
callback: WhiskerEventValueCallback,
user_data: *mut c_void,
);
pub fn whisker_bridge_register_event_dispatcher(dispatcher: WhiskerEventDispatcher);
pub fn whisker_bridge_element_sign(element: *mut WhiskerElement) -> i32;
pub fn whisker_bridge_set_native_event_handler(
element: *mut WhiskerElement,
event_name: *const c_char,
);
pub fn whisker_bridge_set_root(engine: *mut WhiskerEngine, page: *mut WhiskerElement);
pub fn whisker_bridge_flush(engine: *mut WhiskerEngine);
pub fn whisker_bridge_invoke_module(
module_name: *const c_char,
method_name: *const c_char,
args: *const WhiskerValueRaw,
arg_count: usize,
) -> WhiskerValueRaw;
pub fn whisker_bridge_invoke_module_async(
module_name: *const c_char,
method_name: *const c_char,
args: *const WhiskerValueRaw,
arg_count: usize,
callback: WhiskerModuleCallback,
user_data: *mut c_void,
) -> bool;
pub fn whisker_bridge_value_release(value: *mut WhiskerValueRaw);
pub fn whisker_bridge_register_module_dispatch(
module_name: *const c_char,
dispatch: WhiskerModuleDispatchFn,
);
pub fn whisker_bridge_module_add_event_listener(
module_name: *const c_char,
event_name: *const c_char,
callback: WhiskerModuleEventCallback,
user_data: *mut c_void,
) -> i32;
pub fn whisker_bridge_module_remove_event_listener(listener_id: i32);
pub fn whisker_bridge_module_send_event(
module_name: *const c_char,
event_name: *const c_char,
payload: *const WhiskerValueRaw,
);
pub fn whisker_bridge_module_register_observer_hooks(
module_name: *const c_char,
started: WhiskerModuleObserverHook,
stopped: WhiskerModuleObserverHook,
);
pub fn whisker_bridge_log_info(tag: *const c_char, msg: *const c_char);
pub fn whisker_bridge_invoke_element_method(
element: *mut WhiskerElement,
method_name: *const c_char,
args: *const WhiskerValueRaw,
arg_count: usize,
) -> WhiskerValueRaw;
pub fn whisker_bridge_invoke_element_method_with_params(
element: *mut WhiskerElement,
method_name: *const c_char,
params: *const WhiskerValueRaw,
) -> WhiskerValueRaw;
pub fn whisker_bridge_element_animate(
element: *mut WhiskerElement,
operation: i32,
animation_name: *const c_char,
keyframes: *const WhiskerValueRaw,
options: *const WhiskerValueRaw,
) -> WhiskerValueRaw;
pub fn whisker_bridge_invoke_element_method_async(
element: *mut WhiskerElement,
method_name: *const c_char,
args: *const WhiskerValueRaw,
arg_count: usize,
callback: WhiskerModuleCallback,
user_data: *mut c_void,
) -> bool;
pub fn whisker_bridge_invoke_element_method_async_with_params(
element: *mut WhiskerElement,
method_name: *const c_char,
params: *const WhiskerValueRaw,
callback: WhiskerModuleCallback,
user_data: *mut c_void,
) -> bool;
}