feat: add all schema functions in cdylib project
This commit is contained in:
@@ -155,7 +155,7 @@ macro_rules! cffi_wrapper {
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
// Case without output parameter and no input parameters
|
// Case without output parameter and no input parameters
|
||||||
($inner_body:block) => {{
|
(|| $inner_body:block) => {{
|
||||||
fn inner() -> Result<()> $inner_body
|
fn inner() -> Result<()> $inner_body
|
||||||
|
|
||||||
match inner() {
|
match inner() {
|
||||||
@@ -179,14 +179,24 @@ macro_rules! cffi_wrapper {
|
|||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFStartup() -> bool {
|
pub extern "C" fn WFStartup() -> bool {
|
||||||
// TODO: Initialize all pool by fetching writer from them
|
// Initialize all pool by fetching writer from them
|
||||||
true
|
cffi_wrapper!(|| {
|
||||||
|
let _pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let _pool = pull_writer!(PROGRAM_POOL)?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFShutdown() -> bool {
|
pub extern "C" fn WFShutdown() -> bool {
|
||||||
// TODO: Free all pool stored objects
|
// Free all pool stored objects
|
||||||
true
|
cffi_wrapper!(|| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
pool.clear();
|
||||||
|
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
||||||
|
pool.clear();
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
@@ -228,17 +238,167 @@ pub extern "C" fn WFSchemaSetIdentifier(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaIntoProgram(
|
pub extern "C" fn WFSchemaSetPath(
|
||||||
in_schema: in_param_ty!(Token),
|
in_schema: in_param_ty!(Token),
|
||||||
out_program: out_param_ty!(Token),
|
in_value: in_param_ty!(CStyleString),
|
||||||
) -> bool {
|
) -> bool {
|
||||||
cffi_wrapper!(|in_schema: Token| -> (out_program: Token) {
|
cffi_wrapper!(|in_schema: Token, in_value: CStyleString| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
let schema = pool.pop(in_schema)?;
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
schema.set_path(cstr_ffi::parse_ffi_string(in_value)?);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
#[unsafe(no_mangle)]
|
||||||
let program = schema.into_program()?;
|
pub extern "C" fn WFSchemaSetClsid(
|
||||||
Ok(pool.allocate(program)?)
|
in_schema: in_param_ty!(Token),
|
||||||
|
in_value: in_param_ty!(CStyleString),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(|in_schema: Token, in_value: CStyleString| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
schema.set_clsid(cstr_ffi::parse_ffi_string(in_value)?);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFSchemaSetName(
|
||||||
|
in_schema: in_param_ty!(Token),
|
||||||
|
in_value: in_param_ty!(CStyleString),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(|in_schema: Token, in_value: CStyleString| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
|
||||||
|
let name = if in_value.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
||||||
|
};
|
||||||
|
schema.set_name(name);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFSchemaSetIcon(
|
||||||
|
in_schema: in_param_ty!(Token),
|
||||||
|
in_value: in_param_ty!(CStyleString),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(|in_schema: Token, in_value: CStyleString| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
|
||||||
|
let icon = if in_value.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
||||||
|
};
|
||||||
|
schema.set_icon(icon);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFSchemaSetBehavior(
|
||||||
|
in_schema: in_param_ty!(Token),
|
||||||
|
in_value: in_param_ty!(CStyleString),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(|in_schema: Token, in_value: CStyleString| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
|
||||||
|
let behavior = if in_value.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
||||||
|
};
|
||||||
|
schema.set_behavior(behavior);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFSchemaAddStr(
|
||||||
|
in_schema: in_param_ty!(Token),
|
||||||
|
in_name: in_param_ty!(CStyleString),
|
||||||
|
in_value: in_param_ty!(CStyleString),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(
|
||||||
|
|in_schema: Token, in_name: CStyleString, in_value: CStyleString| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
schema.add_str(
|
||||||
|
cstr_ffi::parse_ffi_string(in_name)?,
|
||||||
|
cstr_ffi::parse_ffi_string(in_value)?,
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFSchemaAddIcon(
|
||||||
|
in_schema: in_param_ty!(Token),
|
||||||
|
in_name: in_param_ty!(CStyleString),
|
||||||
|
in_value: in_param_ty!(CStyleString),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(
|
||||||
|
|in_schema: Token, in_name: CStyleString, in_value: CStyleString| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
schema.add_icon(
|
||||||
|
cstr_ffi::parse_ffi_string(in_name)?,
|
||||||
|
cstr_ffi::parse_ffi_string(in_value)?,
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFSchemaAddBehavior(
|
||||||
|
in_schema: in_param_ty!(Token),
|
||||||
|
in_name: in_param_ty!(CStyleString),
|
||||||
|
in_value: in_param_ty!(CStyleString),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(
|
||||||
|
|in_schema: Token, in_name: CStyleString, in_value: CStyleString| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
schema.add_behavior(
|
||||||
|
cstr_ffi::parse_ffi_string(in_name)?,
|
||||||
|
cstr_ffi::parse_ffi_string(in_value)?,
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFSchemaAddExt(
|
||||||
|
in_schema: in_param_ty!(Token),
|
||||||
|
in_ext: in_param_ty!(CStyleString),
|
||||||
|
in_ext_name: in_param_ty!(CStyleString),
|
||||||
|
in_ext_icon: in_param_ty!(CStyleString),
|
||||||
|
in_ext_behavior: in_param_ty!(CStyleString),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(|in_schema: Token,
|
||||||
|
in_ext: CStyleString,
|
||||||
|
in_ext_name: CStyleString,
|
||||||
|
in_ext_icon: CStyleString,
|
||||||
|
in_ext_behavior: CStyleString| {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.get_mut(in_schema)?;
|
||||||
|
schema.add_ext(
|
||||||
|
cstr_ffi::parse_ffi_string(in_ext)?,
|
||||||
|
cstr_ffi::parse_ffi_string(in_ext_name)?,
|
||||||
|
cstr_ffi::parse_ffi_string(in_ext_icon)?,
|
||||||
|
cstr_ffi::parse_ffi_string(in_ext_behavior)?,
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,6 +417,29 @@ pub extern "C" fn WFSchemaDestroy(in_schema: in_param_ty!(Token)) -> bool {
|
|||||||
static PROGRAM_POOL: LazyLock<RwLock<ObjectPool<Program>>> =
|
static PROGRAM_POOL: LazyLock<RwLock<ObjectPool<Program>>> =
|
||||||
LazyLock::new(|| RwLock::new(ObjectPool::new()));
|
LazyLock::new(|| RwLock::new(ObjectPool::new()));
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFProgramCreate(
|
||||||
|
in_schema: in_param_ty!(Token),
|
||||||
|
out_program: out_param_ty!(Token),
|
||||||
|
) -> bool {
|
||||||
|
cffi_wrapper!(|in_schema: Token| -> (out_program: Token) {
|
||||||
|
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
||||||
|
let schema = pool.pop(in_schema)?;
|
||||||
|
|
||||||
|
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
||||||
|
let program = Program::new(schema)?;
|
||||||
|
Ok(pool.allocate(program)?)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFProgramDestroy(in_program: in_param_ty!(Token)) -> bool {
|
||||||
|
cffi_wrapper!(|in_program: Token| {
|
||||||
|
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
||||||
|
Ok(pool.free(in_program)?)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ impl<T> ObjectPool<T> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clear(&mut self) -> () {
|
||||||
|
self.objs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn pop(&mut self, token: Token) -> Result<T, Error> {
|
pub fn pop(&mut self, token: Token) -> Result<T, Error> {
|
||||||
match self.objs.remove(Self::token_to_key(token)) {
|
match self.objs.remove(Self::token_to_key(token)) {
|
||||||
Some(obj) => Ok(obj),
|
Some(obj) => Ok(obj),
|
||||||
|
|||||||
Reference in New Issue
Block a user