Browse Source

update: rust log settings

dev
Dnomd343 2 years ago
parent
commit
cac9cec9d5
  1. 7
      include/utils/assets.h
  2. 32
      src/assets/src/ffi.rs
  3. 6
      src/assets/src/lib.rs
  4. 20
      src/cleardns.c

7
include/utils/assets.h

@ -12,11 +12,8 @@ void assets_load(assets *info);
void assets_extract();
// RUST DEMO START
void assets_log_init(uint8_t verbose);
void rust_test_single(const char *ptr);
void rust_test_multi(char *const *ptr);
// RUST DEMO END
uint8_t rust_assets_update(const char *file, char *const *sources, const char *assets_dir);
#endif

32
src/assets/src/ffi.rs

@ -1,3 +1,5 @@
use log::debug;
use std::env::set_var;
use std::os::raw::c_char;
use std::ffi::{CStr, CString};
@ -20,22 +22,26 @@ unsafe fn load_c_string_list(ptr: *const *const c_char) -> Vec<String> {
}
#[no_mangle]
pub unsafe extern "C" fn rust_test_single(ptr: *const c_char) {
println!("enter rust function");
let ret = load_c_string(ptr);
println!("ret: {:?}", ret);
println!("exit rust function");
pub unsafe extern "C" fn assets_log_init(verbose: u8) {
if verbose == 0 { // bool value `FALSE`
set_var("RUST_LOG", "info");
} else {
set_var("RUST_LOG", "trace");
}
env_logger::init();
}
#[no_mangle]
pub unsafe extern "C" fn rust_test_multi(ptr: *const *const c_char) {
println!("enter rust function");
pub unsafe extern "C" fn rust_assets_update(
file: *const c_char, sources: *const *const c_char, assets_dir: *const c_char) -> u8 {
let file = load_c_string(file); // import c-style string
let sources = load_c_string_list(sources);
let assets_dir = load_c_string(assets_dir);
let ret = load_c_string_list(ptr);
println!("ret: {:?}", ret);
debug!("file: {}", file);
debug!("source: {:?}", sources);
debug!("assets dir: {}", assets_dir);
println!("exit rust function");
0
}

6
src/assets/src/lib.rs

@ -1,9 +1,3 @@
// mod fetch;
//
// use std::env::set_var;
//
// use crate::fetch::Asset;
mod ffi;
// use std::ffi::{c_char, CStr};

20
src/cleardns.c

@ -130,22 +130,10 @@ int main(int argc, char *argv[]) {
char *tmp = string_list_dump(demo);
log_warn("dump -> %s", tmp);
log_info("string list -> %p -> %p", &demo, demo);
log_info("string list 1 -> %p -> %p -> `%s`", &demo[0], demo[0], demo[0]);
log_info("string list 2 -> %p -> %p -> `%s`", &demo[1], demo[1], demo[1]);
log_info("string list 3 -> %p -> %p -> `%s`", &demo[2], demo[2], demo[2]);
log_info("string list 4 -> %p -> %p -> `%s`", &demo[3], demo[3], demo[3]);
log_info("string list 5 -> %p -> %p -> `%s`", &demo[4], demo[4], demo[4]);
log_info("string list 6 -> %p -> %p -> `%s`", &demo[5], demo[5], demo[5]);
rust_test_multi(demo);
log_info("string list 1 -> %p -> %p -> `%s`", &demo[0], demo[0], demo[0]);
log_info("string list 2 -> %p -> %p -> `%s`", &demo[1], demo[1], demo[1]);
log_info("string list 3 -> %p -> %p -> `%s`", &demo[2], demo[2], demo[2]);
log_info("string list 4 -> %p -> %p -> `%s`", &demo[3], demo[3], demo[3]);
log_info("string list 5 -> %p -> %p -> `%s`", &demo[4], demo[4], demo[4]);
log_info("string list 6 -> %p -> %p -> `%s`", &demo[5], demo[5], demo[5]);
// assets_log_init(TRUE);
assets_log_init(FALSE);
rust_assets_update("test.txt", demo, ASSETS_DIR);
string_list_free(demo);

Loading…
Cancel
Save