use super::{
FfiScopeStack, FfiThreadScopeStackBinding, NemoFlowStatus, capture_thread_scope_stack,
clear_last_error, create_scope_stack, restore_thread_scope_stack, scope_stack_active,
set_last_error, set_thread_scope_stack,
};
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nemo_flow_scope_stack_create(
out: *mut *mut FfiScopeStack,
) -> NemoFlowStatus {
clear_last_error();
if out.is_null() {
set_last_error("out pointer is null");
return NemoFlowStatus::NullPointer;
}
let handle = create_scope_stack();
unsafe { *out = Box::into_raw(Box::new(FfiScopeStack(handle))) };
NemoFlowStatus::Ok
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nemo_flow_scope_stack_set_thread(
stack: *const FfiScopeStack,
) -> NemoFlowStatus {
clear_last_error();
if stack.is_null() {
set_last_error("stack pointer is null");
return NemoFlowStatus::NullPointer;
}
let handle = unsafe { &*stack }.0.clone();
set_thread_scope_stack(handle);
NemoFlowStatus::Ok
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nemo_flow_scope_stack_capture_thread(
out: *mut *mut FfiThreadScopeStackBinding,
) -> NemoFlowStatus {
clear_last_error();
if out.is_null() {
set_last_error("out pointer is null");
return NemoFlowStatus::NullPointer;
}
let binding = capture_thread_scope_stack();
unsafe { *out = Box::into_raw(Box::new(FfiThreadScopeStackBinding(binding))) };
NemoFlowStatus::Ok
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nemo_flow_scope_stack_restore_thread(
binding: *mut FfiThreadScopeStackBinding,
) -> NemoFlowStatus {
clear_last_error();
if binding.is_null() {
set_last_error("binding pointer is null");
return NemoFlowStatus::NullPointer;
}
let binding = unsafe { Box::from_raw(binding) };
restore_thread_scope_stack(binding.0);
NemoFlowStatus::Ok
}
#[unsafe(no_mangle)]
pub extern "C" fn nemo_flow_scope_stack_active() -> bool {
scope_stack_active()
}