use super::*;
use crate::common::log::tee_file::TeeFileConfiguration;
use std::ptr::null;
#[no_mangle]
pub extern "C" fn dqcs_pcfg_new(
typ: dqcs_plugin_type_t,
name: *const c_char,
spec: *const c_char,
) -> dqcs_handle_t {
api_return(0, || {
let typ: Result<PluginType> = typ.into();
let spec = receive_optional_str(spec)?.filter(|x| !x.is_empty());
if let Some(spec) = spec {
Ok(insert(PluginProcessConfiguration::new(
receive_optional_str(name)?.unwrap_or(""),
PluginProcessSpecification::from_sugar(spec, typ?)?,
)))
} else {
inv_arg("plugin specification must not be empty")
}
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_new_raw(
typ: dqcs_plugin_type_t,
name: *const c_char,
executable: *const c_char,
script: *const c_char,
) -> dqcs_handle_t {
api_return(0, || {
let typ: Result<PluginType> = typ.into();
let executable = receive_optional_str(executable)?.filter(|x| !x.is_empty());
let script = receive_optional_str(script)?.filter(|x| !x.is_empty());
if let Some(executable) = executable {
Ok(insert(PluginProcessConfiguration::new(
receive_optional_str(name)?.unwrap_or(""),
PluginProcessSpecification::new(executable, script, typ?),
)))
} else {
inv_arg("plugin executable must not be empty")
}
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_type(pcfg: dqcs_handle_t) -> dqcs_plugin_type_t {
api_return(dqcs_plugin_type_t::DQCS_PTYPE_INVALID, || {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.specification.typ.into())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_name(pcfg: dqcs_handle_t) -> *mut c_char {
api_return_string(|| {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.name.to_string())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_executable(pcfg: dqcs_handle_t) -> *mut c_char {
api_return_string(|| {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.specification.executable.to_string_lossy().to_string())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_script(pcfg: dqcs_handle_t) -> *mut c_char {
api_return_string(|| {
resolve!(pcfg as &PluginProcessConfiguration);
if let Some(script) = pcfg.specification.script.as_ref() {
Ok(script.to_string_lossy().to_string())
} else {
Ok("".to_string())
}
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_init_cmd(pcfg: dqcs_handle_t, cmd: dqcs_handle_t) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
take!(cmd as ArbCmd);
pcfg.functional.init.push(cmd);
Ok(())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_env_set(
pcfg: dqcs_handle_t,
key: *const c_char,
value: *const c_char,
) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
if value.is_null() {
pcfg.functional.env.push(EnvMod::remove(receive_str(key)?));
} else {
pcfg.functional
.env
.push(EnvMod::set(receive_str(key)?, receive_str(value)?));
}
Ok(())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_env_unset(pcfg: dqcs_handle_t, key: *const c_char) -> dqcs_return_t {
dqcs_pcfg_env_set(pcfg, key, null())
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_work_set(pcfg: dqcs_handle_t, work: *const c_char) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
let work: std::path::PathBuf = receive_str(work)?.into();
if !work.is_dir() {
inv_arg("not a directory")
} else {
pcfg.functional.work = work;
Ok(())
}
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_work_get(pcfg: dqcs_handle_t) -> *mut c_char {
api_return_string(|| {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.functional.work.to_string_lossy().to_string())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_verbosity_set(
pcfg: dqcs_handle_t,
level: dqcs_loglevel_t,
) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
pcfg.nonfunctional.verbosity = level.into_loglevel_filter()?;
Ok(())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_verbosity_get(pcfg: dqcs_handle_t) -> dqcs_loglevel_t {
api_return(dqcs_loglevel_t::DQCS_LOG_INVALID, || {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.nonfunctional.verbosity.into())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_tee(
pcfg: dqcs_handle_t,
verbosity: dqcs_loglevel_t,
filename: *const c_char,
) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
pcfg.nonfunctional.tee_files.push(TeeFileConfiguration::new(
verbosity.into_loglevel_filter()?,
receive_str(filename)?,
));
Ok(())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_stdout_mode_set(
pcfg: dqcs_handle_t,
level: dqcs_loglevel_t,
) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
pcfg.nonfunctional.stdout_mode = level.into_capture_mode()?;
Ok(())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_stdout_mode_get(pcfg: dqcs_handle_t) -> dqcs_loglevel_t {
api_return(dqcs_loglevel_t::DQCS_LOG_INVALID, || {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.nonfunctional.stdout_mode.clone().into())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_stderr_mode_set(
pcfg: dqcs_handle_t,
level: dqcs_loglevel_t,
) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
pcfg.nonfunctional.stderr_mode = level.into_capture_mode()?;
Ok(())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_stderr_mode_get(pcfg: dqcs_handle_t) -> dqcs_loglevel_t {
api_return(dqcs_loglevel_t::DQCS_LOG_INVALID, || {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.nonfunctional.stderr_mode.clone().into())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_accept_timeout_set(pcfg: dqcs_handle_t, timeout: f64) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
pcfg.nonfunctional.accept_timeout = Timeout::try_from_double(timeout)?;
Ok(())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_accept_timeout_get(pcfg: dqcs_handle_t) -> f64 {
api_return(-1.0, || {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.nonfunctional.accept_timeout.to_double())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_shutdown_timeout_set(
pcfg: dqcs_handle_t,
timeout: f64,
) -> dqcs_return_t {
api_return_none(|| {
resolve!(pcfg as &mut PluginProcessConfiguration);
pcfg.nonfunctional.shutdown_timeout = Timeout::try_from_double(timeout)?;
Ok(())
})
}
#[no_mangle]
pub extern "C" fn dqcs_pcfg_shutdown_timeout_get(pcfg: dqcs_handle_t) -> f64 {
api_return(-1.0, || {
resolve!(pcfg as &PluginProcessConfiguration);
Ok(pcfg.nonfunctional.shutdown_timeout.to_double())
})
}