diff --git a/core/include/ten_utils/log/log.h b/core/include/ten_utils/log/log.h index e69440fac..3218cee63 100644 --- a/core/include/ten_utils/log/log.h +++ b/core/include/ten_utils/log/log.h @@ -86,6 +86,9 @@ __LINE__, __VA_ARGS__); \ } while (0) +typedef struct ten_string_t ten_string_t; +typedef struct ten_log_t ten_log_t; + typedef enum TEN_LOG_LEVEL { TEN_LOG_LEVEL_INVALID, @@ -97,8 +100,12 @@ typedef enum TEN_LOG_LEVEL { TEN_LOG_LEVEL_FATAL, } TEN_LOG_LEVEL; -typedef struct ten_string_t ten_string_t; -typedef struct ten_log_t ten_log_t; +typedef enum TEN_LOG_OUTPUT_TYPE { + TEN_LOG_OUTPUT_TYPE_INVALID, + + TEN_LOG_OUTPUT_TYPE_FILE, + TEN_LOG_OUTPUT_TYPE_STDERR, +} TEN_LOG_OUTPUT_TYPE; typedef void (*ten_log_output_on_output_func_t)(ten_log_t *self, ten_string_t *msg); @@ -121,6 +128,8 @@ typedef struct ten_log_output_t { ten_log_output_on_close_func_t on_close; ten_log_output_on_reload_func_t on_reload; ten_log_output_on_deinit_func_t on_deinit; + + TEN_LOG_OUTPUT_TYPE type; void *user_data; } ten_log_output_t; diff --git a/core/include_internal/ten_utils/log/log.h b/core/include_internal/ten_utils/log/log.h index d646eac9f..3a8358474 100644 --- a/core/include_internal/ten_utils/log/log.h +++ b/core/include_internal/ten_utils/log/log.h @@ -62,6 +62,8 @@ TEN_UTILS_API void ten_log_global_set_output_to_stderr(void); TEN_UTILS_API void ten_log_global_set_output_to_file(const char *log_path); +TEN_UTILS_API const char *ten_log_global_get_output_file_path(void); + TEN_UTILS_API void ten_log_global_set_encrypt_cb( ten_log_encrypt_on_encrypt_func_t cb, void *cb_data); diff --git a/core/include_internal/ten_utils/log/output.h b/core/include_internal/ten_utils/log/output.h index cd394b7e6..c0b01581b 100644 --- a/core/include_internal/ten_utils/log/output.h +++ b/core/include_internal/ten_utils/log/output.h @@ -50,3 +50,5 @@ TEN_UTILS_PRIVATE_API void ten_log_output_to_stderr(ten_log_t *self, TEN_UTILS_PRIVATE_API void ten_log_set_output_to_file(ten_log_t *self, const char *log_path); + +TEN_UTILS_PRIVATE_API const char *ten_log_get_output_file_path(ten_log_t *self); diff --git a/core/src/ten_manager/Cargo.lock b/core/src/ten_manager/Cargo.lock index 984253956..af73bb557 100644 --- a/core/src/ten_manager/Cargo.lock +++ b/core/src/ten_manager/Cargo.lock @@ -452,26 +452,6 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bindgen" -version = "0.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" -dependencies = [ - "bitflags 2.9.0", - "cexpr", - "clang-sys", - "itertools", - "log", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash 1.1.0", - "shlex", - "syn", -] - [[package]] name = "bit-set" version = "0.8.0" @@ -589,15 +569,6 @@ dependencies = [ "shlex", ] -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfb" version = "0.7.3" @@ -640,17 +611,6 @@ dependencies = [ "inout", ] -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "4.5.37" @@ -1030,12 +990,6 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c7a8fb8a9fbf66c1f703fe16184d10ca0ee9d23be5b4436400408ba54a95005" -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - [[package]] name = "email_address" version = "0.2.9" @@ -1338,12 +1292,6 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" -[[package]] -name = "glob" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" - [[package]] name = "globset" version = "0.4.16" @@ -1776,15 +1724,6 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.15" @@ -1905,16 +1844,6 @@ version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" -[[package]] -name = "libloading" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" -dependencies = [ - "cfg-if", - "windows-targets 0.52.6", -] - [[package]] name = "libm" version = "0.2.13" @@ -2027,12 +1956,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.8.8" @@ -2101,16 +2024,6 @@ dependencies = [ "libc", ] -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "normpath" version = "1.3.0" @@ -2387,16 +2300,6 @@ dependencies = [ "zerocopy 0.8.24", ] -[[package]] -name = "prettyplease" -version = "0.2.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "664ec5419c51e34154eec046ebcba56312d5a2fc3b09a06da188e1ad21afadf6" -dependencies = [ - "proc-macro2", - "syn", -] - [[package]] name = "proc-macro2" version = "1.0.95" @@ -2438,7 +2341,7 @@ dependencies = [ "pin-project-lite", "quinn-proto", "quinn-udp", - "rustc-hash 2.1.1", + "rustc-hash", "rustls", "socket2", "thiserror 2.0.12", @@ -2457,7 +2360,7 @@ dependencies = [ "getrandom 0.3.2", "rand 0.9.1", "ring", - "rustc-hash 2.1.1", + "rustc-hash", "rustls", "rustls-pki-types", "slab", @@ -2755,12 +2658,6 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc-hash" version = "2.1.1" @@ -3219,7 +3116,6 @@ dependencies = [ "actix-web", "aes", "anyhow", - "bindgen", "ctr", "futures", "json5", diff --git a/core/src/ten_manager/src/cmd/cmd_fetch.rs b/core/src/ten_manager/src/cmd/cmd_fetch.rs index 41ae788e7..d58a256de 100644 --- a/core/src/ten_manager/src/cmd/cmd_fetch.rs +++ b/core/src/ten_manager/src/cmd/cmd_fetch.rs @@ -142,6 +142,7 @@ pub async fn execute_cmd( Some(command_data.pkg_type), Some(command_data.pkg_name.clone()), Some(command_data.version_req.clone()), + None, // No tag filtering. None, None, // Retrieve all packages. &out, diff --git a/core/src/ten_manager/src/create/mod.rs b/core/src/ten_manager/src/create/mod.rs index 8da5088c9..ed332e28f 100644 --- a/core/src/ten_manager/src/create/mod.rs +++ b/core/src/ten_manager/src/create/mod.rs @@ -67,6 +67,7 @@ pub async fn create_pkg_in_path( Some(*pkg_type), Some(template_pkg_name.clone()), Some(template_pkg_version.clone()), + None, // No tag filtering. None, None, // Retrieve all packages. out, diff --git a/core/src/ten_manager/src/dep_and_candidate/mod.rs b/core/src/ten_manager/src/dep_and_candidate/mod.rs index b4df5e30e..dbb8c0b13 100644 --- a/core/src/ten_manager/src/dep_and_candidate/mod.rs +++ b/core/src/ten_manager/src/dep_and_candidate/mod.rs @@ -201,6 +201,7 @@ async fn process_non_local_dependency_to_get_candidate( // design, this is the best we can do for now. The answer won't be // wrong, but the efficiency might be somewhat lower. Some(version_req.clone()), + None, // No tag filtering. None, None, // Retrieve all packages. out, diff --git a/core/src/ten_manager/src/designer/registry/packages.rs b/core/src/ten_manager/src/designer/registry/packages.rs index 9af8ed4f1..7fa36b98b 100644 --- a/core/src/ten_manager/src/designer/registry/packages.rs +++ b/core/src/ten_manager/src/designer/registry/packages.rs @@ -37,6 +37,10 @@ pub struct GetPackagesRequestPayload { #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] pub page: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default)] + pub tags: Option>, } #[derive(Serialize, Debug)] @@ -71,6 +75,7 @@ pub async fn get_packages_endpoint( request_query.pkg_type, request_query.name.clone(), version_req, + request_query.tags.clone(), request_query.page_size, request_query.page, &state.out, diff --git a/core/src/ten_manager/src/registry/local.rs b/core/src/ten_manager/src/registry/local.rs index 779c1cb42..b8434b6c7 100644 --- a/core/src/ten_manager/src/registry/local.rs +++ b/core/src/ten_manager/src/registry/local.rs @@ -260,6 +260,7 @@ fn find_file_with_criteria( pkg_type: Option, name: Option<&String>, version_req: Option<&VersionReq>, + tags: Option<&Vec>, ) -> Result> { let mut results = Vec::::new(); @@ -271,7 +272,7 @@ fn find_file_with_criteria( let search_path = base_url.join(pkg_type.to_string()); if search_path.exists() { let mut path_results = - search_versions(&search_path, name_str, version_req)?; + search_versions(&search_path, name_str, version_req, tags)?; results.append(&mut path_results); } } @@ -287,6 +288,7 @@ fn find_file_with_criteria( &search_path, &name_str, version_req, + tags, )?; results.append(&mut name_results); } @@ -300,8 +302,12 @@ fn find_file_with_criteria( let type_dir = entry.path(); let name_dir = type_dir.join(name); if name_dir.exists() { - let mut type_results = - search_versions(&type_dir, name, version_req)?; + let mut type_results = search_versions( + &type_dir, + name, + version_req, + tags, + )?; results.append(&mut type_results); } } @@ -323,6 +329,7 @@ fn find_file_with_criteria( .to_string_lossy() .as_ref(), version_req, + tags, )?; results.append(&mut name_results); } @@ -340,6 +347,7 @@ fn search_versions( base_dir: &Path, name: &str, version_req: Option<&VersionReq>, + tags: Option<&Vec>, ) -> Result> { let mut results = Vec::::new(); let target_path = base_dir.join(name); @@ -402,6 +410,30 @@ fn search_versions( let manifest = Manifest::from_str(&manifest_content)?; + // Check if the manifest meets the tags + // requirements. + if let Some(tag_filters) = tags { + if !tag_filters.is_empty() { + // If manifest has no tags, skip this + // package. + if manifest.tags.is_none() { + continue; + } + + // If manifest has tags, check if it + // contains all the required tags. + let manifest_tags = + manifest.tags.as_ref().unwrap(); + let all_tags_contained = tag_filters + .iter() + .all(|tag| manifest_tags.contains(tag)); + + if !all_tags_contained { + continue; + } + } + } + // Generate the download URL from the file path. let download_url = url::Url::from_file_path(path) .map_err(|_| { @@ -438,6 +470,7 @@ pub async fn get_package_list( pkg_type: Option, name: Option, version_req: Option, + tags: Option>, page_size: Option, page: Option, _out: &Arc>, @@ -465,6 +498,7 @@ pub async fn get_package_list( pkg_type, name_ref, version_req_ref, + tags.as_ref(), )?; // If page is specified, paginate the results. diff --git a/core/src/ten_manager/src/registry/mod.rs b/core/src/ten_manager/src/registry/mod.rs index fe6e446cb..027e9032f 100644 --- a/core/src/ten_manager/src/registry/mod.rs +++ b/core/src/ten_manager/src/registry/mod.rs @@ -120,6 +120,8 @@ pub async fn get_package( /// extension). /// * `name` - Optional name of the package to search for. /// * `version_req` - Optional version requirement to filter packages. +/// * `tags` - Optional tags to filter packages by. If specified, only packages +/// with all the specified tags will be returned. /// * `page_size` - Optional number of items per page. Default is 100 if not /// specified. /// * `page` - Optional page number to retrieve. If not specified, all items are @@ -136,11 +138,13 @@ pub async fn get_package( /// * If the URL scheme is not supported (only "file" and "https" are /// supported). /// * If there's an error retrieving the package list from the registry. +#[allow(clippy::too_many_arguments)] pub async fn get_package_list( tman_config: Arc>, pkg_type: Option, name: Option, version_req: Option, + tags: Option>, page_size: Option, page: Option, out: &Arc>, @@ -168,6 +172,7 @@ pub async fn get_package_list( pkg_type, name, version_req, + tags, page_size, page, out, @@ -181,6 +186,7 @@ pub async fn get_package_list( pkg_type, name, version_req, + tags, page_size, page, out, diff --git a/core/src/ten_manager/src/registry/remote.rs b/core/src/ten_manager/src/registry/remote.rs index 05c1bc838..21d262a75 100644 --- a/core/src/ten_manager/src/registry/remote.rs +++ b/core/src/ten_manager/src/registry/remote.rs @@ -622,6 +622,7 @@ struct RegistryPackagesData { /// extension). /// * `name` - Optional name of the package to search for. /// * `version_req` - Optional version requirement to filter packages. +/// * `tags` - Optional tags to filter packages. /// * `page_size` - Optional page size for pagination. /// * `page` - Optional page number for pagination. /// * `out` - Output interface for logging. @@ -642,6 +643,7 @@ pub async fn get_package_list( pkg_type: Option, name: Option, version_req: Option, + tags: Option>, page_size: Option, page: Option, out: &Arc>, @@ -663,6 +665,7 @@ pub async fn get_package_list( let out = out.clone(); let version_req = version_req.clone(); let name = name.clone(); + let tags = tags.clone(); let tman_config = tman_config.clone(); Box::pin(async move { @@ -698,6 +701,13 @@ pub async fn get_package_list( query.append_pair("version", &vr.to_string()); } + // Add tags parameter if provided. + if let Some(t) = &tags { + if !t.is_empty() { + query.append_pair("tags", &t.join(",")); + } + } + // Pagination parameters. query .append_pair( @@ -709,7 +719,7 @@ pub async fn get_package_list( if is_verbose(tman_config.clone()).await { let query_info = format!( - "{}{}{}", + "{}{}{}{}", pkg_type.as_ref().map_or( "".to_string(), |pt| format!("type={} ", pt) @@ -720,8 +730,15 @@ pub async fn get_package_list( )), version_req.as_ref().map_or( "".to_string(), - |vr| format!("version={}", vr) - ) + |vr| format!("version={} ", vr) + ), + tags.as_ref().map_or("".to_string(), |t| { + if t.is_empty() { + "".to_string() + } else { + format!("tags={}", t.join(",")) + } + }) ); out.normal_line(&format!( diff --git a/core/src/ten_runtime/app/service_hub/api/api.c b/core/src/ten_runtime/app/service_hub/api/api.c index 2391fff0e..706343f96 100644 --- a/core/src/ten_runtime/app/service_hub/api/api.c +++ b/core/src/ten_runtime/app/service_hub/api/api.c @@ -9,10 +9,13 @@ #include -#include "core/include_internal/ten_runtime/common/version.h" +#include "include_internal/ten_runtime/common/version.h" +#include "include_internal/ten_utils/log/log.h" const char *ten_get_runtime_version(void) { return TEN_RUNTIME_VERSION; } -const char *ten_get_global_log_path(void) { return NULL; } +const char *ten_get_global_log_path(void) { + return ten_log_global_get_output_file_path(); +} #endif diff --git a/core/src/ten_rust/Cargo.toml b/core/src/ten_rust/Cargo.toml index 78a080a30..b736846e5 100644 --- a/core/src/ten_rust/Cargo.toml +++ b/core/src/ten_rust/Cargo.toml @@ -42,8 +42,9 @@ tempfile = { version = "3.10" } uuid = { version = "1.16.0", features = ["serde", "v4"] } [build-dependencies] -bindgen = { version = "0.70" } +bindgen = { version = "0.70", optional = true } [features] default = ["service-hub"] service-hub = [] +deprecated = ["bindgen"] diff --git a/core/src/ten_rust/src/build.rs b/core/src/ten_rust/src/build.rs index 9c7093718..ad06e4a17 100644 --- a/core/src/ten_rust/src/build.rs +++ b/core/src/ten_rust/src/build.rs @@ -6,11 +6,11 @@ // use std::{env, path::PathBuf}; -#[allow(dead_code)] -mod archive { +#[cfg(feature = "deprecated")] +mod deprecated { use std::{env, fs, path::Path, process::id, thread, time::Duration}; - fn auto_gen_schema_bindings_from_c() { + pub fn auto_gen_schema_bindings_from_c() { let mut base_dir = env::current_dir() .unwrap_or("Failed to get path of //ten_rust/src".into()); base_dir.pop(); @@ -138,7 +138,7 @@ mod archive { } } - fn auto_gen_service_hub_bindings_from_c() { + pub fn auto_gen_service_hub_bindings_from_c() { let mut base_dir = env::current_dir() .unwrap_or("Failed to get path of //ten_rust/src".into()); base_dir.pop(); @@ -290,8 +290,11 @@ fn auto_detect_utils_library_path() -> PathBuf { } fn main() { - // auto_gen_schema_bindings_from_c(); - // auto_gen_service_hub_bindings_from_c(); + #[cfg(feature = "deprecated")] + { + deprecated::auto_gen_schema_bindings_from_c(); + deprecated::auto_gen_service_hub_bindings_from_c(); + } // If the auto-detected utils library path is incorrect, we can specify it // using the environment variable. diff --git a/core/src/ten_rust/src/schema/bindings.rs b/core/src/ten_rust/src/schema/bindings.rs index 7120a012c..56a4f79df 100644 --- a/core/src/ten_rust/src/schema/bindings.rs +++ b/core/src/ten_rust/src/schema/bindings.rs @@ -1,31 +1,226 @@ -// -// Copyright © 2025 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to the "LICENSE" file in the root directory for more information. -// +#![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(dead_code)] +#![allow(improper_ctypes)] +#![allow(improper_ctypes_definitions)] +#![allow(clippy::upper_case_acronyms)] +/* automatically generated by rust-bindgen 0.70.1 */ + +pub const _STDINT_H: u32 = 1; +pub const _FEATURES_H: u32 = 1; +pub const _DEFAULT_SOURCE: u32 = 1; +pub const __GLIBC_USE_ISOC2X: u32 = 0; +pub const __USE_ISOC11: u32 = 1; +pub const __USE_ISOC99: u32 = 1; +pub const __USE_ISOC95: u32 = 1; +pub const __USE_POSIX_IMPLICITLY: u32 = 1; +pub const _POSIX_SOURCE: u32 = 1; +pub const _POSIX_C_SOURCE: u32 = 200809; +pub const __USE_POSIX: u32 = 1; +pub const __USE_POSIX2: u32 = 1; +pub const __USE_POSIX199309: u32 = 1; +pub const __USE_POSIX199506: u32 = 1; +pub const __USE_XOPEN2K: u32 = 1; +pub const __USE_XOPEN2K8: u32 = 1; +pub const _ATFILE_SOURCE: u32 = 1; +pub const __WORDSIZE: u32 = 64; +pub const __WORDSIZE_TIME64_COMPAT32: u32 = 1; +pub const __SYSCALL_WORDSIZE: u32 = 64; +pub const __TIMESIZE: u32 = 64; +pub const __USE_MISC: u32 = 1; +pub const __USE_ATFILE: u32 = 1; +pub const __USE_FORTIFY_LEVEL: u32 = 0; +pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0; +pub const __GLIBC_USE_DEPRECATED_SCANF: u32 = 0; +pub const __GLIBC_USE_C2X_STRTOL: u32 = 0; +pub const _STDC_PREDEF_H: u32 = 1; +pub const __STDC_IEC_559__: u32 = 1; +pub const __STDC_IEC_60559_BFP__: u32 = 201404; +pub const __STDC_IEC_559_COMPLEX__: u32 = 1; +pub const __STDC_IEC_60559_COMPLEX__: u32 = 201404; +pub const __STDC_ISO_10646__: u32 = 201706; +pub const __GNU_LIBRARY__: u32 = 6; +pub const __GLIBC__: u32 = 2; +pub const __GLIBC_MINOR__: u32 = 39; +pub const _SYS_CDEFS_H: u32 = 1; +pub const __glibc_c99_flexarr_available: u32 = 1; +pub const __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI: u32 = 0; +pub const __HAVE_GENERIC_SELECTION: u32 = 1; +pub const __GLIBC_USE_LIB_EXT2: u32 = 0; +pub const __GLIBC_USE_IEC_60559_BFP_EXT: u32 = 0; +pub const __GLIBC_USE_IEC_60559_BFP_EXT_C2X: u32 = 0; +pub const __GLIBC_USE_IEC_60559_EXT: u32 = 0; +pub const __GLIBC_USE_IEC_60559_FUNCS_EXT: u32 = 0; +pub const __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X: u32 = 0; +pub const __GLIBC_USE_IEC_60559_TYPES_EXT: u32 = 0; +pub const _BITS_TYPES_H: u32 = 1; +pub const _BITS_TYPESIZES_H: u32 = 1; +pub const __OFF_T_MATCHES_OFF64_T: u32 = 1; +pub const __INO_T_MATCHES_INO64_T: u32 = 1; +pub const __RLIM_T_MATCHES_RLIM64_T: u32 = 1; +pub const __STATFS_MATCHES_STATFS64: u32 = 1; +pub const __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64: u32 = 1; +pub const __FD_SETSIZE: u32 = 1024; +pub const _BITS_TIME64_H: u32 = 1; +pub const _BITS_WCHAR_H: u32 = 1; +pub const _BITS_STDINT_INTN_H: u32 = 1; +pub const _BITS_STDINT_UINTN_H: u32 = 1; +pub const _BITS_STDINT_LEAST_H: u32 = 1; +pub const INT8_MIN: i32 = -128; +pub const INT16_MIN: i32 = -32768; +pub const INT32_MIN: i32 = -2147483648; +pub const INT8_MAX: u32 = 127; +pub const INT16_MAX: u32 = 32767; +pub const INT32_MAX: u32 = 2147483647; +pub const UINT8_MAX: u32 = 255; +pub const UINT16_MAX: u32 = 65535; +pub const UINT32_MAX: u32 = 4294967295; +pub const INT_LEAST8_MIN: i32 = -128; +pub const INT_LEAST16_MIN: i32 = -32768; +pub const INT_LEAST32_MIN: i32 = -2147483648; +pub const INT_LEAST8_MAX: u32 = 127; +pub const INT_LEAST16_MAX: u32 = 32767; +pub const INT_LEAST32_MAX: u32 = 2147483647; +pub const UINT_LEAST8_MAX: u32 = 255; +pub const UINT_LEAST16_MAX: u32 = 65535; +pub const UINT_LEAST32_MAX: u32 = 4294967295; +pub const INT_FAST8_MIN: i32 = -128; +pub const INT_FAST16_MIN: i64 = -9223372036854775808; +pub const INT_FAST32_MIN: i64 = -9223372036854775808; +pub const INT_FAST8_MAX: u32 = 127; +pub const INT_FAST16_MAX: u64 = 9223372036854775807; +pub const INT_FAST32_MAX: u64 = 9223372036854775807; +pub const UINT_FAST8_MAX: u32 = 255; +pub const UINT_FAST16_MAX: i32 = -1; +pub const UINT_FAST32_MAX: i32 = -1; +pub const INTPTR_MIN: i64 = -9223372036854775808; +pub const INTPTR_MAX: u64 = 9223372036854775807; +pub const UINTPTR_MAX: i32 = -1; +pub const PTRDIFF_MIN: i64 = -9223372036854775808; +pub const PTRDIFF_MAX: u64 = 9223372036854775807; +pub const SIG_ATOMIC_MIN: i32 = -2147483648; +pub const SIG_ATOMIC_MAX: u32 = 2147483647; +pub const SIZE_MAX: i32 = -1; +pub const WINT_MIN: u32 = 0; +pub const WINT_MAX: u32 = 4294967295; +pub const __bool_true_false_are_defined: u32 = 1; +pub const true_: u32 = 1; +pub const false_: u32 = 0; +pub type __u_char = ::std::os::raw::c_uchar; +pub type __u_short = ::std::os::raw::c_ushort; +pub type __u_int = ::std::os::raw::c_uint; +pub type __u_long = ::std::os::raw::c_ulong; +pub type __int8_t = ::std::os::raw::c_schar; +pub type __uint8_t = ::std::os::raw::c_uchar; +pub type __int16_t = ::std::os::raw::c_short; +pub type __uint16_t = ::std::os::raw::c_ushort; +pub type __int32_t = ::std::os::raw::c_int; +pub type __uint32_t = ::std::os::raw::c_uint; +pub type __int64_t = ::std::os::raw::c_long; +pub type __uint64_t = ::std::os::raw::c_ulong; +pub type __int_least8_t = __int8_t; +pub type __uint_least8_t = __uint8_t; +pub type __int_least16_t = __int16_t; +pub type __uint_least16_t = __uint16_t; +pub type __int_least32_t = __int32_t; +pub type __uint_least32_t = __uint32_t; +pub type __int_least64_t = __int64_t; +pub type __uint_least64_t = __uint64_t; +pub type __quad_t = ::std::os::raw::c_long; +pub type __u_quad_t = ::std::os::raw::c_ulong; +pub type __intmax_t = ::std::os::raw::c_long; +pub type __uintmax_t = ::std::os::raw::c_ulong; +pub type __dev_t = ::std::os::raw::c_ulong; +pub type __uid_t = ::std::os::raw::c_uint; +pub type __gid_t = ::std::os::raw::c_uint; +pub type __ino_t = ::std::os::raw::c_ulong; +pub type __ino64_t = ::std::os::raw::c_ulong; +pub type __mode_t = ::std::os::raw::c_uint; +pub type __nlink_t = ::std::os::raw::c_ulong; +pub type __off_t = ::std::os::raw::c_long; +pub type __off64_t = ::std::os::raw::c_long; +pub type __pid_t = ::std::os::raw::c_int; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __fsid_t { + pub __val: [::std::os::raw::c_int; 2usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of __fsid_t"][::std::mem::size_of::<__fsid_t>() - 8usize]; + ["Alignment of __fsid_t"][::std::mem::align_of::<__fsid_t>() - 4usize]; + ["Offset of field: __fsid_t::__val"][::std::mem::offset_of!(__fsid_t, __val) - 0usize]; +}; +pub type __clock_t = ::std::os::raw::c_long; +pub type __rlim_t = ::std::os::raw::c_ulong; +pub type __rlim64_t = ::std::os::raw::c_ulong; +pub type __id_t = ::std::os::raw::c_uint; +pub type __time_t = ::std::os::raw::c_long; +pub type __useconds_t = ::std::os::raw::c_uint; +pub type __suseconds_t = ::std::os::raw::c_long; +pub type __suseconds64_t = ::std::os::raw::c_long; +pub type __daddr_t = ::std::os::raw::c_int; +pub type __key_t = ::std::os::raw::c_int; +pub type __clockid_t = ::std::os::raw::c_int; +pub type __timer_t = *mut ::std::os::raw::c_void; +pub type __blksize_t = ::std::os::raw::c_long; +pub type __blkcnt_t = ::std::os::raw::c_long; +pub type __blkcnt64_t = ::std::os::raw::c_long; +pub type __fsblkcnt_t = ::std::os::raw::c_ulong; +pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; +pub type __fsword_t = ::std::os::raw::c_long; +pub type __ssize_t = ::std::os::raw::c_long; +pub type __syscall_slong_t = ::std::os::raw::c_long; +pub type __syscall_ulong_t = ::std::os::raw::c_ulong; +pub type __loff_t = __off64_t; +pub type __caddr_t = *mut ::std::os::raw::c_char; +pub type __intptr_t = ::std::os::raw::c_long; +pub type __socklen_t = ::std::os::raw::c_uint; +pub type __sig_atomic_t = ::std::os::raw::c_int; +pub type int_least8_t = __int_least8_t; +pub type int_least16_t = __int_least16_t; +pub type int_least32_t = __int_least32_t; +pub type int_least64_t = __int_least64_t; +pub type uint_least8_t = __uint_least8_t; +pub type uint_least16_t = __uint_least16_t; +pub type uint_least32_t = __uint_least32_t; +pub type uint_least64_t = __uint_least64_t; +pub type int_fast8_t = ::std::os::raw::c_schar; +pub type int_fast16_t = ::std::os::raw::c_long; +pub type int_fast32_t = ::std::os::raw::c_long; +pub type int_fast64_t = ::std::os::raw::c_long; +pub type uint_fast8_t = ::std::os::raw::c_uchar; +pub type uint_fast16_t = ::std::os::raw::c_ulong; +pub type uint_fast32_t = ::std::os::raw::c_ulong; +pub type uint_fast64_t = ::std::os::raw::c_ulong; +pub type intmax_t = __intmax_t; +pub type uintmax_t = __uintmax_t; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ten_schema_t { _unused: [u8; 0], } - extern "C" { pub fn ten_schema_create_from_json_str_proxy( json_str: *const ::std::os::raw::c_char, err_msg: *mut *const ::std::os::raw::c_char, ) -> *mut ten_schema_t; - +} +extern "C" { pub fn ten_schema_destroy_proxy(self_: *const ten_schema_t); - +} +extern "C" { pub fn ten_schema_adjust_and_validate_json_str_proxy( self_: *const ten_schema_t, json_str: *const ::std::os::raw::c_char, err_msg: *mut *const ::std::os::raw::c_char, ) -> bool; - +} +extern "C" { pub fn ten_schema_is_compatible_proxy( self_: *const ten_schema_t, target: *const ten_schema_t, diff --git a/core/src/ten_rust/src/service_hub/api/mod.rs b/core/src/ten_rust/src/service_hub/api/mod.rs index 4a145f9a7..1acc82dc6 100644 --- a/core/src/ten_rust/src/service_hub/api/mod.rs +++ b/core/src/ten_rust/src/service_hub/api/mod.rs @@ -8,13 +8,11 @@ use std::ffi::CStr; use actix_web::{web, HttpResponse}; -use super::bindings::ten_app_t; - // In normal builds, use the implementation from bindings. #[cfg(not(test))] use super::bindings::*; -pub fn configure_api_route(cfg: &mut web::ServiceConfig, app: *mut ten_app_t) { +pub fn configure_api_route(cfg: &mut web::ServiceConfig) { cfg.service( web::scope("/api/v1") .service(web::resource("/version").route(web::get().to(|| async { @@ -28,20 +26,15 @@ pub fn configure_api_route(cfg: &mut web::ServiceConfig, app: *mut ten_app_t) { }))) }))) .service(web::resource("/log-path").route(web::get().to( - move || { - let app_ptr = app; - async move { - let log_path = unsafe { - let c_str = CStr::from_ptr( - ten_get_global_log_path(app_ptr), - ); - c_str.to_string_lossy().into_owned() - }; - - HttpResponse::Ok().json(web::Json(serde_json::json!({ - "log_path": log_path - }))) - } + move || async move { + let log_path = unsafe { + let c_str = CStr::from_ptr(ten_get_global_log_path()); + c_str.to_string_lossy().into_owned() + }; + + HttpResponse::Ok().json(web::Json(serde_json::json!({ + "log_path": log_path + }))) }, ))), ); @@ -55,17 +48,13 @@ use mock::*; mod mock { use std::os::raw::c_char; - use crate::service_hub::bindings::ten_app_t; - #[no_mangle] pub extern "C" fn ten_get_runtime_version() -> *const c_char { "1.0.0".as_ptr() as *const c_char } #[no_mangle] - pub extern "C" fn ten_get_global_log_path( - _app: *mut ten_app_t, - ) -> *const c_char { + pub extern "C" fn ten_get_global_log_path() -> *const c_char { "/tmp/ten_runtime.log".as_ptr() as *const c_char } } diff --git a/core/src/ten_rust/src/service_hub/bindings.rs b/core/src/ten_rust/src/service_hub/bindings.rs index 6c9d7b205..e62fb19c8 100644 --- a/core/src/ten_rust/src/service_hub/bindings.rs +++ b/core/src/ten_rust/src/service_hub/bindings.rs @@ -1,23 +1,16 @@ -// -// Copyright © 2025 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to the "LICENSE" file in the root directory for more information. -// +#![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(dead_code)] +#![allow(improper_ctypes)] +#![allow(improper_ctypes_definitions)] +#![allow(clippy::upper_case_acronyms)] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ten_app_t { - _unused: [u8; 0], -} +/* automatically generated by rust-bindgen 0.70.1 */ extern "C" { - #[allow(dead_code)] pub fn ten_get_runtime_version() -> *const ::std::os::raw::c_char; - - #[allow(dead_code)] - pub fn ten_get_global_log_path( - app: *mut ten_app_t, - ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn ten_get_global_log_path() -> *const ::std::os::raw::c_char; } diff --git a/core/src/ten_rust/src/service_hub/mod.rs b/core/src/ten_rust/src/service_hub/mod.rs index b930bf55c..9ff7ed670 100644 --- a/core/src/ten_rust/src/service_hub/mod.rs +++ b/core/src/ten_rust/src/service_hub/mod.rs @@ -19,9 +19,6 @@ use futures::future::select; use futures::FutureExt; use prometheus::Registry; -// Import ten_app_t from the bindings -use self::bindings::ten_app_t; - use crate::constants::{ SERVICE_HUB_SERVER_BIND_MAX_RETRIES, SERVICE_HUB_SERVER_BIND_RETRY_INTERVAL_SECS, @@ -48,7 +45,6 @@ fn configure_routes( registry: Registry, is_telemetry_endpoint: bool, is_api_endpoint: bool, - app: *mut ten_app_t, ) { if is_telemetry_endpoint { // Configure telemetry endpoint. @@ -57,7 +53,7 @@ fn configure_routes( if is_api_endpoint { // Configure API endpoints. - api::configure_api_route(cfg, app); + api::configure_api_route(cfg); } } @@ -100,7 +96,6 @@ fn create_server_app( registry: Registry, telemetry_endpoint: &Option, api_endpoint: &Option, - app: *mut ten_app_t, ) -> App< impl actix_web::dev::ServiceFactory< actix_web::dev::ServiceRequest, @@ -150,13 +145,7 @@ fn create_server_app( } })) .configure(|cfg| { - configure_routes( - cfg, - registry.clone(), - true, - false, - app, - ) + configure_routes(cfg, registry.clone(), true, false) }), ) // Add API routes with guard. @@ -182,13 +171,7 @@ fn create_server_app( } })) .configure(|cfg| { - configure_routes( - cfg, - registry.clone(), - false, - true, - app, - ) + configure_routes(cfg, registry.clone(), false, true) }), ) } else { @@ -198,7 +181,7 @@ fn create_server_app( let is_api = api_endpoint.is_some(); app_builder.configure(|cfg| { - configure_routes(cfg, registry.clone(), is_telemetry, is_api, app) + configure_routes(cfg, registry.clone(), is_telemetry, is_api) }) } } @@ -213,7 +196,6 @@ fn create_server_and_bind_to_addresses( registry: Registry, telemetry_endpoint: &Option, api_endpoint: &Option, - app: *mut ten_app_t, ) -> (Option, Vec) { let mut bind_errors = Vec::new(); @@ -222,20 +204,13 @@ fn create_server_and_bind_to_addresses( let telemetry_endpoint_clone = telemetry_endpoint.clone(); let api_endpoint_clone = api_endpoint.clone(); - // Convert the pointer to usize which is Send. - let app_addr = app as usize; - // Create a new server with a factory that uses the create_server_app // function let server = HttpServer::new(move || { - // Convert back to pointer inside the closure. - let app_ptr = app_addr as *mut ten_app_t; - create_server_app( registry_clone.clone(), &telemetry_endpoint_clone, &api_endpoint_clone, - app_ptr, ) }) .shutdown_timeout(0) @@ -312,7 +287,6 @@ fn create_service_hub_server_with_retry( telemetry_endpoint: &Option, api_endpoint: &Option, registry: Registry, - app: *mut ten_app_t, ) -> Option { // If both endpoints are None, return None early. if telemetry_endpoint.is_none() && api_endpoint.is_none() { @@ -330,7 +304,6 @@ fn create_service_hub_server_with_retry( registry.clone(), telemetry_endpoint, api_endpoint, - app, ); // If we've successfully bound to the specified addresses, return the @@ -469,7 +442,6 @@ pub unsafe extern "C" fn ten_service_hub_create( telemetry_port: u32, api_host: *const c_char, api_port: u32, - app: *mut ten_app_t, ) -> *mut ServiceHub { // Check if both hosts are NULL, if so, return null. if telemetry_host.is_null() && api_host.is_null() { @@ -521,7 +493,6 @@ pub unsafe extern "C" fn ten_service_hub_create( &telemetry_endpoint, &api_endpoint, registry_clone, - app, ) { Some(server) => server, None => { @@ -553,7 +524,6 @@ pub unsafe extern "C" fn ten_service_hub_create( &telemetry_endpoint, &api_endpoint, registry_clone, - app, ) { Some(server) => server, None => { @@ -589,7 +559,6 @@ pub unsafe extern "C" fn ten_service_hub_create( &telemetry_endpoint, &None, registry_clone, - app, ) { Some(server) => server, None => { @@ -620,7 +589,6 @@ pub unsafe extern "C" fn ten_service_hub_create( &None, &api_endpoint, registry_clone, - app, ) { Some(server) => server, None => { diff --git a/core/src/ten_utils/log/global.c b/core/src/ten_utils/log/global.c index 07c9ff9e0..190763ee4 100644 --- a/core/src/ten_utils/log/global.c +++ b/core/src/ten_utils/log/global.c @@ -30,6 +30,10 @@ void ten_log_global_set_output_to_file(const char *log_path) { ten_log_set_output_to_file(&ten_global_log, log_path); } +const char *ten_log_global_get_output_file_path(void) { + return ten_log_get_output_file_path(&ten_global_log); +} + void ten_log_global_set_encrypt_cb(ten_log_encrypt_on_encrypt_func_t cb, void *cb_data) { ten_log_set_encrypt_cb(&ten_global_log, cb, cb_data); diff --git a/core/src/ten_utils/log/output.c b/core/src/ten_utils/log/output.c index fa298fdf5..64101d806 100644 --- a/core/src/ten_utils/log/output.c +++ b/core/src/ten_utils/log/output.c @@ -102,7 +102,7 @@ static bool create_directories(const char *path) { return true; } -static void ten_log_output_set(ten_log_t *self, +static void ten_log_output_set(ten_log_t *self, TEN_LOG_OUTPUT_TYPE type, const ten_log_output_on_output_func_t output_cb, const ten_log_output_on_close_func_t close_cb, const ten_log_output_on_reload_func_t reload_cb, @@ -120,17 +120,23 @@ static void ten_log_output_set(ten_log_t *self, self->output.on_deinit(self); } - self->output.user_data = user_data; self->output.on_output = output_cb; self->output.on_close = close_cb; self->output.on_reload = reload_cb; self->output.on_deinit = deinit_cb; + + self->output.type = type; + self->output.user_data = user_data; } static void ten_log_close_file(ten_log_t *self) { TEN_ASSERT(self, "Invalid argument."); TEN_ASSERT(ten_log_check_integrity(self), "Invalid argument."); + if (self->output.type != TEN_LOG_OUTPUT_TYPE_FILE) { + return; + } + ten_log_output_to_file_ctx_t *ctx = (ten_log_output_to_file_ctx_t *)self->output.user_data; TEN_ASSERT(ctx, "Invalid argument."); @@ -221,17 +227,23 @@ void ten_log_output_to_file_ctx_destroy(ten_log_output_to_file_ctx_t *ctx) { void ten_log_output_init(ten_log_output_t *self) { TEN_ASSERT(self, "Invalid argument."); - self->user_data = NULL; self->on_output = NULL; self->on_close = NULL; self->on_reload = NULL; self->on_deinit = NULL; + + self->user_data = NULL; + self->type = TEN_LOG_OUTPUT_TYPE_INVALID; } void ten_log_output_to_file(ten_log_t *self, ten_string_t *msg) { TEN_ASSERT(self, "Invalid argument."); TEN_ASSERT(msg, "Invalid argument."); + if (self->output.type != TEN_LOG_OUTPUT_TYPE_FILE) { + return; + } + ten_log_output_to_file_ctx_t *ctx = (ten_log_output_to_file_ctx_t *)self->output.user_data; TEN_ASSERT(ctx, "Invalid argument."); @@ -284,6 +296,10 @@ static void ten_log_output_to_file_deinit(ten_log_t *self) { TEN_ASSERT(self->output.on_output == ten_log_output_to_file, "Invalid argument."); + if (self->output.type != TEN_LOG_OUTPUT_TYPE_FILE) { + return; + } + ten_log_output_to_file_ctx_t *ctx = (ten_log_output_to_file_ctx_t *)self->output.user_data; TEN_ASSERT(ctx, "Invalid argument."); @@ -295,6 +311,10 @@ static void ten_log_output_to_file_reload(ten_log_t *self) { TEN_ASSERT(self, "Invalid argument."); TEN_ASSERT(ten_log_check_integrity(self), "Invalid argument."); + if (self->output.type != TEN_LOG_OUTPUT_TYPE_FILE) { + return; + } + ten_log_output_to_file_ctx_t *ctx = (ten_log_output_to_file_ctx_t *)self->output.user_data; TEN_ASSERT(ctx, "Invalid argument."); @@ -316,13 +336,32 @@ void ten_log_set_output_to_file(ten_log_t *self, const char *log_path) { ten_log_output_to_file_ctx_create(fd, log_path); TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_log_output_set(self, ten_log_output_to_file, ten_log_close_file, - ten_log_output_to_file_reload, + ten_log_output_set(self, TEN_LOG_OUTPUT_TYPE_FILE, ten_log_output_to_file, + ten_log_close_file, ten_log_output_to_file_reload, ten_log_output_to_file_deinit, ctx); ten_log_set_formatter(self, ten_log_default_formatter, NULL); } +const char *ten_log_get_output_file_path(ten_log_t *self) { + TEN_ASSERT(self, "Invalid argument."); + TEN_ASSERT(ten_log_check_integrity(self), "Invalid argument."); + + if (self->output.type != TEN_LOG_OUTPUT_TYPE_FILE) { + return NULL; + } + + ten_log_output_to_file_ctx_t *ctx = + (ten_log_output_to_file_ctx_t *)self->output.user_data; + TEN_ASSERT(ctx, "Invalid argument."); + + ten_mutex_lock(ctx->mutex); + const char *path = ten_string_get_raw_str(&ctx->log_path); + ten_mutex_unlock(ctx->mutex); + + return path; +} + void ten_log_output_to_stderr(ten_log_t *self, ten_string_t *msg) { TEN_ASSERT(self, "Invalid argument."); TEN_ASSERT(msg, "Invalid argument."); @@ -349,7 +388,8 @@ void ten_log_output_to_stderr(ten_log_t *self, ten_string_t *msg) { } void ten_log_set_output_to_stderr(ten_log_t *self) { - ten_log_output_set(self, ten_log_output_to_stderr, NULL, NULL, NULL, NULL); + ten_log_output_set(self, TEN_LOG_OUTPUT_TYPE_STDERR, ten_log_output_to_stderr, + NULL, NULL, NULL, NULL); ten_log_formatter_on_format_func_t formatter_func = NULL;