diff --git a/.vscode/launch.json b/.vscode/launch.json index 924f13441..99a7adcaa 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -129,7 +129,7 @@ "request": "launch", "program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test", "args": [ - "--gtest_filter=ExtensionTest.BasicMultiAppCloseThroughEngine" + "--gtest_filter=CmdConversionTest.CmdConversionPathArray1" ], "cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/", "env": { diff --git a/build/common/rust/rust.gni b/build/common/rust/rust.gni index bcf12d30c..ba7ed03c6 100644 --- a/build/common/rust/rust.gni +++ b/build/common/rust/rust.gni @@ -156,7 +156,12 @@ template("rust_test") { assert(defined(invoker.project_path), "project_path is not defined") _target_name = target_name + target_path = target_gen_dir + if (defined(invoker.target_path)) { + target_path = invoker.target_path + } + tg_timestamp_proxy_file = "${target_path}/${target_name}_rust_tests" action("${_target_name}") { diff --git a/core/include/ten_runtime/addon/extension_group/extension_group.h b/core/include/ten_runtime/addon/extension_group/extension_group.h index 06224b6ec..d82d0e997 100644 --- a/core/include/ten_runtime/addon/extension_group/extension_group.h +++ b/core/include/ten_runtime/addon/extension_group/extension_group.h @@ -18,4 +18,4 @@ TEN_RUNTIME_API ten_addon_host_t *ten_addon_register_extension_group( const char *name, ten_addon_t *addon); TEN_RUNTIME_API void ten_addon_unregister_extension_group(const char *name, - ten_addon_t *addon); + ten_addon_t *addon); diff --git a/core/include/ten_runtime/ten_env_proxy/ten_env_proxy.h b/core/include/ten_runtime/ten_env_proxy/ten_env_proxy.h index 8d487e695..c8fb73d36 100644 --- a/core/include/ten_runtime/ten_env_proxy/ten_env_proxy.h +++ b/core/include/ten_runtime/ten_env_proxy/ten_env_proxy.h @@ -20,19 +20,19 @@ typedef struct ten_env_t ten_env_t; typedef void (*ten_notify_func_t)(ten_env_t *ten_env, void *user_data); TEN_RUNTIME_API ten_env_proxy_t *ten_env_proxy_create(ten_env_t *ten_env, - size_t initial_thread_cnt, - ten_error_t *err); + size_t initial_thread_cnt, + ten_error_t *err); TEN_RUNTIME_API bool ten_env_proxy_release(ten_env_proxy_t *self, - ten_error_t *err); + ten_error_t *err); TEN_RUNTIME_API bool ten_env_proxy_notify(ten_env_proxy_t *self, - ten_notify_func_t notify_func, - void *user_data, bool sync, - ten_error_t *err); + ten_notify_func_t notify_func, + void *user_data, bool sync, + ten_error_t *err); TEN_RUNTIME_API bool ten_env_proxy_acquire_lock_mode(ten_env_proxy_t *self, - ten_error_t *err); + ten_error_t *err); TEN_RUNTIME_API bool ten_env_proxy_release_lock_mode(ten_env_proxy_t *self, - ten_error_t *err); + ten_error_t *err); diff --git a/core/include_internal/ten_runtime/app/app.h b/core/include_internal/ten_runtime/app/app.h index c7cc443ab..e01410197 100644 --- a/core/include_internal/ten_runtime/app/app.h +++ b/core/include_internal/ten_runtime/app/app.h @@ -101,6 +101,8 @@ typedef struct ten_app_t { ten_schema_store_t schema_store; ten_string_t base_dir; + + void *user_data; } ten_app_t; TEN_RUNTIME_PRIVATE_API void ten_app_add_orphan_connection( diff --git a/core/include_internal/ten_runtime/app/msg_interface/common.h b/core/include_internal/ten_runtime/app/msg_interface/common.h index b4f6eb514..7d66d0552 100644 --- a/core/include_internal/ten_runtime/app/msg_interface/common.h +++ b/core/include_internal/ten_runtime/app/msg_interface/common.h @@ -18,10 +18,14 @@ typedef struct ten_engine_t ten_engine_t; TEN_RUNTIME_PRIVATE_API void ten_app_push_to_in_msgs_queue( ten_app_t *self, ten_shared_ptr_t *msg); -TEN_RUNTIME_PRIVATE_API bool ten_app_on_msg(ten_app_t *self, - ten_connection_t *connection, - ten_shared_ptr_t *msg, - ten_error_t *err); +TEN_RUNTIME_PRIVATE_API bool ten_app_handle_out_msg(ten_app_t *self, + ten_shared_ptr_t *msg, + ten_error_t *err); + +TEN_RUNTIME_PRIVATE_API bool ten_app_handle_in_msg(ten_app_t *self, + ten_connection_t *connection, + ten_shared_ptr_t *msg, + ten_error_t *err); TEN_RUNTIME_PRIVATE_API ten_connection_t *ten_app_find_src_connection_for_msg( ten_app_t *self, ten_shared_ptr_t *msg); diff --git a/core/include_internal/ten_runtime/app/msg_interface/start_graph.h b/core/include_internal/ten_runtime/app/msg_interface/start_graph.h index a8585ac56..e12bcf344 100644 --- a/core/include_internal/ten_runtime/app/msg_interface/start_graph.h +++ b/core/include_internal/ten_runtime/app/msg_interface/start_graph.h @@ -14,6 +14,6 @@ typedef struct ten_app_t ten_app_t; typedef struct ten_connection_t ten_connection_t; -TEN_RUNTIME_PRIVATE_API bool ten_app_on_cmd_start_graph( +TEN_RUNTIME_PRIVATE_API bool ten_app_handle_start_graph_cmd( ten_app_t *self, ten_connection_t *connection, ten_shared_ptr_t *cmd, ten_error_t *err); diff --git a/core/include_internal/ten_runtime/test/extension_test.h b/core/include_internal/ten_runtime/test/extension_test.h index cd913cc82..3466d1175 100644 --- a/core/include_internal/ten_runtime/test/extension_test.h +++ b/core/include_internal/ten_runtime/test/extension_test.h @@ -7,6 +7,7 @@ #include "ten_runtime/ten_config.h" #include "include_internal/ten_runtime/extension/extension.h" +#include "ten_runtime/ten_env_proxy/ten_env_proxy.h" typedef struct ten_extension_test_t { ten_extension_thread_t *test_extension_thread; @@ -23,3 +24,14 @@ TEN_RUNTIME_API void ten_extension_test_start(ten_extension_test_t *self); TEN_RUNTIME_API void ten_extension_test_wait(ten_extension_test_t *self); TEN_RUNTIME_API void ten_extension_test_destroy(ten_extension_test_t *self); + +typedef struct ten_extension_test_new_t { + ten_thread_t *test_app_thread; + ten_env_proxy_t *test_app_ten_env_proxy; + ten_event_t *test_app_ten_env_proxy_create_completed; +} ten_extension_test_new_t; + +TEN_RUNTIME_API ten_extension_test_new_t *ten_extension_test_create_new(void); + +TEN_RUNTIME_API void ten_extension_test_destroy_new( + ten_extension_test_new_t *self); diff --git a/core/include_internal/ten_runtime/test/test_extension_group.h b/core/include_internal/ten_runtime/test/test_extension_group.h new file mode 100644 index 000000000..942c8a264 --- /dev/null +++ b/core/include_internal/ten_runtime/test/test_extension_group.h @@ -0,0 +1,22 @@ +// +// Copyright © 2024 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. +// +#include "ten_runtime/ten_config.h" + +#include "ten_utils/macro/mark.h" + +typedef struct ten_addon_t ten_addon_t; +typedef struct ten_env_t ten_env_t; + +TEN_RUNTIME_PRIVATE_API void ten_test_extension_group_addon_on_init( + TEN_UNUSED ten_addon_t *addon, ten_env_t *ten_env); + +TEN_RUNTIME_PRIVATE_API void ten_test_extension_group_addon_create_instance( + ten_addon_t *addon, ten_env_t *ten_env, const char *name, void *context); + +TEN_RUNTIME_PRIVATE_API void ten_test_extension_group_addon_destroy_instance( + TEN_UNUSED ten_addon_t *addon, ten_env_t *ten_env, void *_extension_group, + void *context); diff --git a/core/src/ten_manager/BUILD.gn b/core/src/ten_manager/BUILD.gn index f06ef4ef7..9073e4d92 100644 --- a/core/src/ten_manager/BUILD.gn +++ b/core/src/ten_manager/BUILD.gn @@ -25,6 +25,14 @@ if (ten_enable_package_manager) { utils_static_lib_path = rebase_path("${root_gen_dir}/core/src/ten_utils") env += [ "TEN_UTILS_LIBRARY_PATH=${utils_static_lib_path}" ] + # If the output directory of `cargo build` (tman) and + # `cargo build --tests` (tman_test) is the same, and if `cargo build` is + # executed first followed by `cargo build --tests`, the resulting + # executable will be the normal executable, not the test case executable. + # Therefore, it's necessary to separate the `target-dir` for these two + # `cargo build` commands to avoid interfering with each other. + target_path = "${root_gen_dir}/core/src/tman_test" + test_output_dir = "${root_out_dir}/tests/standalone/ten_manager" deps = [ diff --git a/core/src/ten_manager/Cargo.toml b/core/src/ten_manager/Cargo.toml index 6f277ad1f..54ef3887d 100644 --- a/core/src/ten_manager/Cargo.toml +++ b/core/src/ten_manager/Cargo.toml @@ -2,7 +2,6 @@ name = "ten_manager" version = "0.1.0" edition = "2021" -build = "src/build.rs" [[bin]] name = "tman" diff --git a/core/src/ten_manager/src/build.rs b/core/src/ten_manager/src/build.rs deleted file mode 100644 index eff5d1b45..000000000 --- a/core/src/ten_manager/src/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright © 2024 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. -// -use std::fs; -use std::process::Command; - -fn main() { - let output = Command::new("git") - .args(["describe", "--tags", "--abbrev=0"]) - .output() - .expect("Failed to execute git command"); - - let version = - String::from_utf8(output.stdout).expect("Invalid UTF-8 sequence"); - let version_trimmed = version.trim(); - - let version_without_v = - version_trimmed.strip_prefix('v').unwrap_or(version_trimmed); - - fs::write( - "src/version.rs", - format!("pub const VERSION: &str = \"{}\";", version_without_v), - ) - .expect("Unable to write version to file"); -} diff --git a/core/src/ten_runtime/app/app.c b/core/src/ten_runtime/app/app.c index 61ce446b6..db7e1b069 100644 --- a/core/src/ten_runtime/app/app.c +++ b/core/src/ten_runtime/app/app.c @@ -136,6 +136,8 @@ ten_app_t *ten_app_create(ten_app_on_configure_func_t on_configure, self->manifest_info = NULL; self->property_info = NULL; + self->user_data = NULL; + return self; } diff --git a/core/src/ten_runtime/app/close.c b/core/src/ten_runtime/app/close.c index 9b6dba1f6..ca0517b4a 100644 --- a/core/src/ten_runtime/app/close.c +++ b/core/src/ten_runtime/app/close.c @@ -26,6 +26,41 @@ #include "ten_utils/macro/mark.h" #include "ten_utils/sanitizer/thread_check.h" +static bool ten_app_has_no_work(ten_app_t *self) { + TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); + + if (ten_list_is_empty(&self->engines) && + ten_list_is_empty(&self->orphan_connections)) { + return true; + } + + return false; +} + +static bool ten_app_could_be_close(ten_app_t *self) { + TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); + + if (ten_app_has_no_work(self) && ten_app_is_endpoint_closed(self) && + ten_protocol_context_store_is_closed(self->protocol_context_store)) { + return true; + } + + return false; +} + +static void ten_app_proceed_to_close(ten_app_t *self) { + TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); + + if (!ten_app_could_be_close(self)) { + TEN_LOGD("[%s] Could not close alive app.", + ten_string_get_raw_str(ten_app_get_uri(self))); + return; + } + TEN_LOGD("[%s] Close app.", ten_string_get_raw_str(ten_app_get_uri(self))); + + ten_app_on_deinit(self); +} + static void ten_app_close_sync(ten_app_t *self) { TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); @@ -84,17 +119,6 @@ bool ten_app_close(ten_app_t *self, TEN_UNUSED ten_error_t *err) { return true; } -static bool ten_app_has_no_work(ten_app_t *self) { - TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); - - if (ten_list_is_empty(&self->engines) && - ten_list_is_empty(&self->orphan_connections)) { - return true; - } - - return false; -} - bool ten_app_is_closing(ten_app_t *self) { // TEN_NOLINTNEXTLINE(thread-check) // thread-check: this function is used to be called in threads other than the @@ -111,30 +135,6 @@ bool ten_app_is_closing(ten_app_t *self) { return is_closing; } -static bool ten_app_could_be_close(ten_app_t *self) { - TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); - - if (ten_app_has_no_work(self) && ten_app_is_endpoint_closed(self) && - ten_protocol_context_store_is_closed(self->protocol_context_store)) { - return true; - } - - return false; -} - -static void ten_app_proceed_to_close(ten_app_t *self) { - TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); - - if (!ten_app_could_be_close(self)) { - TEN_LOGD("[%s] Could not close alive app.", - ten_string_get_raw_str(ten_app_get_uri(self))); - return; - } - TEN_LOGD("[%s] Close app.", ten_string_get_raw_str(ten_app_get_uri(self))); - - ten_app_on_deinit(self); -} - void ten_app_check_termination_when_engine_closed(ten_app_t *self, ten_engine_t *engine) { TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); diff --git a/core/src/ten_runtime/app/msg_interface/common.c b/core/src/ten_runtime/app/msg_interface/common.c index 01eebe090..1171d3835 100644 --- a/core/src/ten_runtime/app/msg_interface/common.c +++ b/core/src/ten_runtime/app/msg_interface/common.c @@ -22,7 +22,6 @@ #include "include_internal/ten_runtime/msg/cmd_base/cmd_base.h" #include "include_internal/ten_runtime/msg/msg.h" #include "include_internal/ten_runtime/protocol/protocol.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/app/app.h" #include "ten_runtime/msg/cmd_result/cmd_result.h" #include "ten_runtime/msg/msg.h" @@ -32,6 +31,7 @@ #include "ten_utils/lib/error.h" #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/lib/string.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" #include "ten_utils/value/value.h" @@ -60,10 +60,10 @@ void ten_app_do_connection_migration_or_push_to_engine_queue( } } -static bool ten_app_on_msg_default_handler(ten_app_t *self, - ten_connection_t *connection, - ten_shared_ptr_t *msg, - ten_error_t *err) { +static bool ten_app_handle_msg_default_handler(ten_app_t *self, + ten_connection_t *connection, + ten_shared_ptr_t *msg, + ten_error_t *err) { TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); TEN_ASSERT( msg && ten_msg_check_integrity(msg) && ten_msg_get_dest_cnt(msg) == 1, @@ -184,7 +184,10 @@ static bool ten_app_on_msg_default_handler(ten_app_t *self, // The 'msg' might be sent from extension A in engine 1 to extension B in // engine 2, there is no 'connection' in this case, the cmd result should // be sent back to engine A1. - result = ten_app_on_msg(self, NULL, resp, err); + // + // So, this cmd result needs to be passed back to the app for further + // processing. + result = ten_app_handle_in_msg(self, NULL, resp, err); } ten_shared_ptr_destroy(resp); @@ -193,9 +196,9 @@ static bool ten_app_on_msg_default_handler(ten_app_t *self, return result; } -static bool ten_app_on_cmd_close_app(ten_app_t *self, - ten_connection_t *connection, - ten_error_t *err) { +static bool ten_app_handle_close_app_cmd(ten_app_t *self, + ten_connection_t *connection, + ten_error_t *err) { TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); if (connection) { @@ -213,8 +216,9 @@ static bool ten_app_on_cmd_close_app(ten_app_t *self, return true; } -static bool ten_app_on_cmd_stop_graph(ten_app_t *self, ten_shared_ptr_t *cmd, - ten_error_t *err) { +static bool ten_app_handle_stop_graph_cmd(ten_app_t *self, + ten_shared_ptr_t *cmd, + TEN_UNUSED ten_error_t *err) { TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); TEN_ASSERT(cmd && ten_cmd_base_check_integrity(cmd), "Should not happen."); TEN_ASSERT(ten_msg_get_type(cmd) == TEN_MSG_TYPE_CMD_STOP_GRAPH, @@ -267,8 +271,36 @@ static bool ten_app_on_cmd_stop_graph(ten_app_t *self, ten_shared_ptr_t *cmd, return true; } -bool ten_app_on_msg(ten_app_t *self, ten_connection_t *connection, - ten_shared_ptr_t *msg, ten_error_t *err) { +bool ten_app_handle_out_msg(ten_app_t *self, ten_shared_ptr_t *msg, + ten_error_t *err) { + // The source of the out message is the current app. + ten_msg_set_src_to_app(msg, self); + + ten_loc_t *dest_loc = ten_msg_get_first_dest_loc(msg); + TEN_ASSERT(dest_loc && ten_loc_check_integrity(dest_loc) && + ten_msg_get_dest_cnt(msg) == 1, + "Should not happen."); + TEN_ASSERT(!ten_string_is_empty(&dest_loc->app_uri), + "App URI should not be empty."); + + if (!ten_string_is_equal(&dest_loc->app_uri, ten_app_get_uri(self))) { + TEN_ASSERT(0, "Handle this condition."); + } else { + if (ten_string_is_empty(&dest_loc->graph_name)) { + // It means asking the app to do something. + + ten_app_push_to_in_msgs_queue(self, msg); + ten_shared_ptr_destroy(msg); + } else { + TEN_ASSERT(0, "Handle this condition."); + } + } + + return true; +} + +bool ten_app_handle_in_msg(ten_app_t *self, ten_connection_t *connection, + ten_shared_ptr_t *msg, ten_error_t *err) { TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen."); TEN_ASSERT(msg && ten_msg_check_integrity(msg), "Should not happen."); @@ -290,16 +322,16 @@ bool ten_app_on_msg(ten_app_t *self, ten_connection_t *connection, switch (ten_msg_get_type(msg)) { case TEN_MSG_TYPE_CMD_START_GRAPH: - return ten_app_on_cmd_start_graph(self, connection, msg, err); + return ten_app_handle_start_graph_cmd(self, connection, msg, err); case TEN_MSG_TYPE_CMD_CLOSE_APP: - return ten_app_on_cmd_close_app(self, connection, err); + return ten_app_handle_close_app_cmd(self, connection, err); case TEN_MSG_TYPE_CMD_STOP_GRAPH: - return ten_app_on_cmd_stop_graph(self, msg, err); + return ten_app_handle_stop_graph_cmd(self, msg, err); default: - return ten_app_on_msg_default_handler(self, connection, msg, err); + return ten_app_handle_msg_default_handler(self, connection, msg, err); } } @@ -373,7 +405,7 @@ static void ten_app_handle_in_msgs_sync(ten_app_t *self) { // And the following function -- 'ten_app_on_msg()' will do connection // migration if needed. So the cmd's 'origin_connection' _must_ _not_ be // passed to the 'ten_app_on_msg()' function here. - ten_app_on_msg(self, NULL, msg, &err); + ten_app_handle_in_msg(self, NULL, msg, &err); } ten_list_clear(&in_msgs_); diff --git a/core/src/ten_runtime/app/msg_interface/start_graph.c b/core/src/ten_runtime/app/msg_interface/start_graph.c index 2367e8e7b..fc150a159 100644 --- a/core/src/ten_runtime/app/msg_interface/start_graph.c +++ b/core/src/ten_runtime/app/msg_interface/start_graph.c @@ -23,9 +23,9 @@ #include "include_internal/ten_runtime/msg/cmd_base/cmd/start_graph/cmd.h" #include "include_internal/ten_runtime/msg/msg.h" #include "include_internal/ten_runtime/protocol/protocol.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/app/app.h" #include "ten_utils/lib/smart_ptr.h" +#include "ten_utils/macro/check.h" static bool ten_app_fill_start_graph_cmd_extensions_info_from_predefined_graph( ten_app_t *self, ten_shared_ptr_t *cmd, ten_error_t *err) { @@ -53,8 +53,9 @@ static bool ten_app_fill_start_graph_cmd_extensions_info_from_predefined_graph( return true; } -bool ten_app_on_cmd_start_graph(ten_app_t *self, ten_connection_t *connection, - ten_shared_ptr_t *cmd, ten_error_t *err) { +bool ten_app_handle_start_graph_cmd(ten_app_t *self, + ten_connection_t *connection, + ten_shared_ptr_t *cmd, ten_error_t *err) { TEN_ASSERT(self && ten_app_check_integrity(self, true), "Invalid argument."); TEN_ASSERT(cmd && ten_cmd_base_check_integrity(cmd), "Invalid argument."); TEN_ASSERT(ten_msg_get_type(cmd) == TEN_MSG_TYPE_CMD_START_GRAPH, diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_addon_create_extension.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_addon_create_extension.c index a8576db00..6c421caab 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_addon_create_extension.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_addon_create_extension.c @@ -13,7 +13,6 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/extension/extension.h" #include "include_internal/ten_runtime/extension_group/extension_group.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/addon/extension/extension.h" #include "ten_runtime/binding/common.h" #include "ten_runtime/binding/go/interface/ten/common.h" @@ -22,6 +21,7 @@ #include "ten_runtime/ten_env/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct addon_create_extension_done_call_info_t { @@ -103,8 +103,8 @@ static void proxy_addon_create_extension_done(ten_env_t *ten_env, ten_go_callback_info_destroy(callback_info); } -static void ten_env_notify_addon_create_extension(ten_env_t *ten_env, - void *user_data) { +static void ten_env_proxy_notify_addon_create_extension(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT( ten_env && @@ -151,7 +151,7 @@ bool ten_go_ten_env_addon_create_extension(uintptr_t bridge_addr, addon_name, instance_name, callback_info); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_addon_create_extension, + ten_env_proxy_notify_addon_create_extension, addon_extension_create_info, false, &err)) { TEN_LOGD("TEN/GO failed to addon_extension_create."); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_addon_destroy_extension.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_addon_destroy_extension.c index c2ed4d700..b2b9a10a2 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_addon_destroy_extension.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_addon_destroy_extension.c @@ -11,7 +11,6 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/extension/extension.h" #include "include_internal/ten_runtime/extension_group/extension_group.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/addon/extension/extension.h" #include "ten_runtime/binding/go/interface/ten/common.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" @@ -19,6 +18,7 @@ #include "ten_runtime/ten_env/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct ten_env_notify_addon_destroy_extension_info_t { @@ -77,8 +77,8 @@ static void proxy_addon_destroy_extension_done(ten_env_t *ten_env, ten_env_notify_addon_destroy_extension_info_destroy(info); } -static void ten_env_notify_addon_destroy_extension(ten_env_t *ten_env, - void *user_data) { +static void ten_env_proxy_notify_addon_destroy_extension(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT( ten_env && @@ -124,7 +124,7 @@ void ten_go_ten_env_addon_destroy_extension(uintptr_t bridge_addr, ten_go_extension_c_extension(extension_bridge), callback_info); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_addon_destroy_extension, + ten_env_proxy_notify_addon_destroy_extension, addon_extension_destroy_info, false, &err)) { TEN_LOGD("TEN/GO failed to addon_extension_destroy."); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_get_property.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_get_property.c index cb8b0009e..f0856d575 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_get_property.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_get_property.c @@ -12,7 +12,6 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/binding/go/value/value.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/common.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/binding/go/interface/ten/value.h" @@ -22,6 +21,7 @@ #include "ten_utils/lib/error.h" #include "ten_utils/lib/event.h" #include "ten_utils/lib/string.h" +#include "ten_utils/macro/check.h" #include "ten_utils/value/value.h" #include "ten_utils/value/value_get.h" @@ -55,7 +55,8 @@ static void ten_env_notify_get_property_info_destroy( TEN_FREE(info); } -static void ten_env_notify_get_property(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -116,8 +117,9 @@ static ten_value_t *ten_go_ten_env_get_property_and_check_if_exists( ten_env_notify_get_property_info_t *info = ten_env_notify_get_property_info_create(path, path_len); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_get_property, - info, false, &err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_get_property, info, false, + &err)) { ten_go_status_from_error(status, &err); goto done; } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_get_property_async.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_get_property_async.c index e03e4a44f..35116fa26 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_get_property_async.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_get_property_async.c @@ -9,11 +9,11 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/binding/go/value/value.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/binding/go/interface/ten/value.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct ten_env_notify_get_property_info_t { @@ -68,7 +68,8 @@ static void proxy_get_property_callback(ten_env_t *ten_env, ten_value_t *res, ten_env_notify_get_property_info_destroy(get_property_info); } -static void ten_notify_get_property_async(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_get_property_async(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -106,8 +107,8 @@ bool ten_go_ten_env_get_property_async(uintptr_t bridge_addr, const char *path, path, ten_go_callback_info_create(callback_id)); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_notify_get_property_async, get_property_info, - false, &err)) { + ten_env_proxy_notify_get_property_async, + get_property_info, false, &err)) { TEN_LOGD("TEN/GO failed to get_property."); ten_env_notify_get_property_info_destroy(get_property_info); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_init_property.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_init_property.c index 90b5a2a54..f253e3bf1 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_init_property.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_init_property.c @@ -47,8 +47,8 @@ static void ten_env_notify_init_property_info_destroy( TEN_FREE(self); } -static void ten_env_notify_init_property_from_json(ten_env_t *ten_env, - void *user_data) { +static void ten_env_proxy_notify_init_property_from_json(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -86,8 +86,8 @@ ten_go_status_t ten_go_ten_env_init_property_from_json_bytes( TEN_ASSERT(info, "Should not happen."); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_init_property_from_json, info, false, - &info->err)) { + ten_env_proxy_notify_init_property_from_json, info, + false, &info->err)) { goto done; } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_is_cmd_connected.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_is_cmd_connected.c index cc9e57850..f9e94f9dd 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_is_cmd_connected.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_is_cmd_connected.c @@ -40,7 +40,8 @@ static void ten_env_notify_is_cmd_connected_info_destroy( TEN_FREE(info); } -static void ten_notify_is_cmd_connected(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_is_cmd_connected(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -73,8 +74,9 @@ bool ten_go_ten_env_is_cmd_connected(uintptr_t bridge_addr, const char *name) { ten_env_notify_is_cmd_connected_info_t *info = ten_env_notify_is_cmd_connected_info_create(name); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_notify_is_cmd_connected, - info, false, &err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_is_cmd_connected, info, false, + &err)) { TEN_LOGD("TEN/GO failed to is_cmd_connected."); result = false; goto done; diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_log.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_log.c index 6637568f3..e7b238e29 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_log.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_log.c @@ -59,7 +59,7 @@ static void ten_env_notify_log_info_destroy(ten_env_notify_log_info_t *info) { TEN_FREE(info); } -static void ten_env_notify_log(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_log(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -120,8 +120,8 @@ void ten_go_ten_env_log(uintptr_t bridge_addr, int level, const void *func_name, info->file_name, info->file_name_len, info->line_no, "%.*s", info->msg_len, info->msg); } else { - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_log, info, - false, &err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_proxy_notify_log, + info, false, &err)) { goto done; } ten_event_wait(info->completed, -1); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_configure_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_configure_done.c index 8ea47b71b..6cc4762da 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_configure_done.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_configure_done.c @@ -14,8 +14,8 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_configure_done(ten_env_t *ten_env, - TEN_UNUSED void *user_data) { +static void ten_env_proxy_notify_on_configure_done(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -48,8 +48,8 @@ void ten_go_ten_env_on_configure_done(uintptr_t bridge_addr) { rc = ten_env_on_configure_done(self->c_ten_env, &err); } else { rc = ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_on_configure_done, NULL, false, - &err); + ten_env_proxy_notify_on_configure_done, NULL, + false, &err); } TEN_ASSERT(rc, "Should not happen."); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_create_extension_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_create_extension_done.c index 8e3309f62..0a6f768fa 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_create_extension_done.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_create_extension_done.c @@ -11,10 +11,10 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/ten_env/ten_env.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" +#include "ten_utils/macro/check.h" typedef struct ten_env_notify_on_create_extensions_done_info_t { ten_list_t result; @@ -43,8 +43,8 @@ static void ten_env_notify_on_create_extensions_done_info_destroy( TEN_FREE(info); } -static void ten_notify_on_create_extensions_done(ten_env_t *ten_env, - void *user_data) { +static void ten_notify_proxy_on_create_extensions_done(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT( ten_env && @@ -97,7 +97,7 @@ void ten_go_ten_env_on_create_extensions_done( ten_env_notify_on_create_extensions_done_info_create(&result); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_notify_on_create_extensions_done, + ten_notify_proxy_on_create_extensions_done, on_create_extensions_done_info, false, &err)) { TEN_LOGD("TEN/GO failed to on_create_extensions_done."); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_deinit_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_deinit_done.c index 4c64b106a..a312b2ab4 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_deinit_done.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_deinit_done.c @@ -8,12 +8,13 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/rwlock.h" +#include "ten_utils/macro/check.h" -static void ten_env_notify_on_deinit_done(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_on_deinit_done(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -72,7 +73,8 @@ void ten_go_ten_env_on_deinit_done(uintptr_t bridge_addr) { rc = ten_env_on_deinit_done(self->c_ten_env, &err); } else { rc = ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_on_deinit_done, self, false, &err); + ten_env_proxy_notify_on_deinit_done, self, false, + &err); } TEN_ASSERT(rc, "Should not happen."); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_delete_extension_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_delete_extension_done.c index 8e35645b8..32fb16e7d 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_delete_extension_done.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_delete_extension_done.c @@ -8,12 +8,12 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_destroy_extensions_done( +static void ten_env_proxy_notify_on_destroy_extensions_done( ten_env_t *ten_env, TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && @@ -42,8 +42,8 @@ void ten_go_ten_env_on_destroy_extensions_done(uintptr_t bridge_addr) { ten_error_init(&err); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_on_destroy_extensions_done, NULL, - false, &err)) { + ten_env_proxy_notify_on_destroy_extensions_done, + NULL, false, &err)) { TEN_LOGD("TEN/GO failed to on_destroy_extensions_done."); } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_init_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_init_done.c index 0c8640dbc..dda9b08f2 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_init_done.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_init_done.c @@ -9,13 +9,13 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/ten_env/ten_env.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_init_done(ten_env_t *ten_env, - TEN_UNUSED void *user_data) { +static void ten_env_proxy_notify_on_init_done(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -48,7 +48,8 @@ void ten_go_ten_env_on_init_done(uintptr_t bridge_addr) { rc = ten_env_on_init_done(self->c_ten_env, &err); } else { rc = ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_on_init_done, NULL, false, &err); + ten_env_proxy_notify_on_init_done, NULL, false, + &err); } TEN_ASSERT(rc, "Should not happen."); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_start_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_start_done.c index 66e56daaa..d9344928c 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_start_done.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_start_done.c @@ -9,13 +9,13 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/ten_env/ten_env.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_start_done(ten_env_t *ten_env, - TEN_UNUSED void *user_data) { +static void ten_env_proxy_notify_on_start_done(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -42,8 +42,9 @@ void ten_go_ten_env_on_start_done(uintptr_t bridge_addr) { ten_error_t err; ten_error_init(&err); - TEN_UNUSED bool rc = ten_env_proxy_notify( - self->c_ten_env_proxy, ten_env_notify_on_start_done, NULL, false, &err); + TEN_UNUSED bool rc = ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_on_start_done, + NULL, false, &err); TEN_ASSERT(rc, "Should not happen."); ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_stop_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_stop_done.c index cec9eb843..c15b9a1bf 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_stop_done.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_stop_done.c @@ -8,13 +8,13 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_stop_done(ten_env_t *ten_env, - TEN_UNUSED void *user_data) { +static void ten_env_proxy_notify_on_stop_done(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -41,8 +41,9 @@ void ten_go_ten_env_on_stop_done(uintptr_t bridge_addr) { ten_error_t err; ten_error_init(&err); - TEN_UNUSED bool rc = ten_env_proxy_notify( - self->c_ten_env_proxy, ten_env_notify_on_stop_done, NULL, false, &err); + TEN_UNUSED bool rc = ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_on_stop_done, + NULL, false, &err); TEN_ASSERT(rc, "Should not happen."); ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_return_result.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_return_result.c index c89ec908e..1adead094 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_return_result.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_return_result.c @@ -13,7 +13,6 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/ten_env/ten_env.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/common.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" @@ -24,6 +23,7 @@ #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/error.h" +#include "ten_utils/macro/check.h" #include "ten_utils/value/value.h" typedef struct ten_env_notify_return_result_info_t { @@ -63,7 +63,8 @@ static void ten_env_notify_return_result_info_destroy( TEN_FREE(info); } -static void ten_notify_return_result(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -114,7 +115,8 @@ ten_go_status_t ten_go_ten_env_return_result(uintptr_t bridge_addr, ten_env_notify_return_result_info_create( ten_go_msg_move_c_msg(cmd_result), ten_go_msg_move_c_msg(cmd)); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_notify_return_result, + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_return_result, return_result_info, false, &err)) { ten_env_notify_return_result_info_destroy(return_result_info); ten_go_status_from_error(&api_status, &err); @@ -149,7 +151,8 @@ ten_go_status_t ten_go_ten_env_return_result_directly( ten_env_notify_return_result_info_create( ten_go_msg_move_c_msg(cmd_result), NULL); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_notify_return_result, + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_return_result, return_result_info, false, &err)) { ten_env_notify_return_result_info_destroy(return_result_info); ten_go_status_from_error(&api_status, &err); @@ -186,7 +189,8 @@ bool ten_go_ten_return_status_value(ten_go_ten_env_t *self, ten_go_msg_t *cmd, ten_env_notify_return_result_info_t *return_result_info = ten_env_notify_return_result_info_create(cmd_result, ten_go_msg_move_c_msg(cmd)); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_notify_return_result, + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_return_result, return_result_info, false, &err)) { result = false; ten_env_notify_return_result_info_destroy(return_result_info); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_audio_frame.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_audio_frame.c index d8dfd67a8..5f2c7e299 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_audio_frame.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_audio_frame.c @@ -9,12 +9,12 @@ #include "include_internal/ten_runtime/binding/go/msg/msg.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/common.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct ten_env_notify_send_audio_frame_info_t { @@ -46,8 +46,8 @@ static void ten_env_notify_send_audio_frame_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_audio_frame(ten_env_t *ten_env, - void *user_audio_frame) { +static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, + void *user_audio_frame) { TEN_ASSERT(user_audio_frame, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -86,8 +86,8 @@ bool ten_go_ten_env_send_audio_frame(uintptr_t bridge_addr, ten_go_msg_move_c_msg(audio_frame)); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_send_audio_frame, notify_info, false, - &err)) { + ten_env_proxy_notify_send_audio_frame, notify_info, + false, &err)) { ten_env_notify_send_audio_frame_info_destroy(notify_info); result = false; } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_cmd.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_cmd.c index 1c66cbec0..9a6cdcef8 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_cmd.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_cmd.c @@ -10,13 +10,13 @@ #include "include_internal/ten_runtime/binding/go/msg/msg.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/common.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/error.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct ten_env_notify_send_cmd_info_t { @@ -52,7 +52,7 @@ static void ten_env_notify_send_cmd_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_cmd(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -103,8 +103,9 @@ ten_go_status_t ten_go_ten_env_send_cmd(uintptr_t bridge_addr, ten_go_msg_move_c_msg(cmd), handler_id <= 0 ? TEN_GO_NO_RESPONSE_HANDLER : handler_id); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_send_cmd, - notify_info, false, &err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_send_cmd, notify_info, false, + &err)) { ten_env_notify_send_cmd_info_destroy(notify_info); ten_go_status_from_error(&status, &err); } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_data.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_data.c index 6caa15393..0f3738357 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_data.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_data.c @@ -11,7 +11,6 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/ten_env/ten_env.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/common.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" @@ -19,6 +18,7 @@ #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/error.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct ten_env_notify_send_data_info_t { @@ -50,7 +50,8 @@ static void ten_env_notify_send_data_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_data(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -88,8 +89,9 @@ ten_go_status_t ten_go_ten_env_send_data(uintptr_t bridge_addr, ten_env_notify_send_data_info_t *notify_info = ten_env_notify_send_data_info_create(ten_go_msg_move_c_msg(data)); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_send_data, - notify_info, false, &err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_send_data, notify_info, false, + &err)) { ten_env_notify_send_data_info_destroy(notify_info); ten_go_status_from_error(&status, &err); } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_json.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_json.c index 96dc69fa0..4c82d0b89 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_json.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_json.c @@ -10,7 +10,6 @@ #include "include_internal/ten_runtime/binding/go/internal/json.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/common.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/common/errno.h" @@ -18,6 +17,7 @@ #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/error.h" #include "ten_utils/lib/json.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct ten_env_notify_send_json_info_t { @@ -53,7 +53,8 @@ static void ten_env_notify_send_json_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_json(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_send_json(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -105,8 +106,9 @@ ten_go_status_t ten_go_ten_env_send_json(uintptr_t bridge_addr, ten_error_t err; ten_error_init(&err); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_send_json, - notify_info, false, &err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_send_json, notify_info, false, + &err)) { ten_env_notify_send_json_info_destroy(notify_info); ten_go_status_from_error(&status, &err); } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_video_frame.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_video_frame.c index 0995b34be..765ff2844 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_video_frame.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_send_video_frame.c @@ -11,13 +11,13 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/ten_env/ten_env.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/common.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/error.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct ten_env_notify_send_video_frame_info_t { @@ -49,8 +49,8 @@ static void ten_env_notify_send_video_frame_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_video_frame(ten_env_t *ten_env, - void *user_video_frame) { +static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, + void *user_video_frame) { TEN_ASSERT(user_video_frame, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -92,8 +92,8 @@ ten_go_status_t ten_go_ten_env_send_video_frame( ten_go_msg_move_c_msg(video_frame)); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_notify_send_video_frame, notify_info, false, - &err)) { + ten_env_proxy_notify_send_video_frame, notify_info, + false, &err)) { ten_env_notify_send_video_frame_info_destroy(notify_info); ten_go_status_from_error(&status, &err); } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_set_property.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_set_property.c index a64a54dca..e6e18e199 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_set_property.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_set_property.c @@ -60,7 +60,8 @@ static void ten_env_notify_set_property_info_destroy( TEN_FREE(self); } -static void ten_env_notify_set_property(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -90,8 +91,9 @@ static void ten_go_ten_env_set_property(ten_go_ten_env_t *self, ten_env_notify_set_property_info_t *info = ten_env_notify_set_property_info_create(path, path_len, value); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_set_property, - info, false, &info->err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_set_property, info, false, + &info->err)) { goto done; } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_set_property_async.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_set_property_async.c index 5946f9383..06e97f737 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_set_property_async.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_set_property_async.c @@ -9,11 +9,11 @@ #include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" #include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" #include "include_internal/ten_runtime/binding/go/value/value.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/ten_env.h" #include "ten_runtime/binding/go/interface/ten/value.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" typedef struct ten_env_notify_set_property_info_t { @@ -69,7 +69,8 @@ static void proxy_set_property_callback(ten_env_t *ten_env, bool res, ten_env_notify_set_property_info_destroy(set_property_info, false); } -static void ten_env_notify_set_property(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -109,7 +110,8 @@ bool ten_go_ten_env_set_property_async(uintptr_t bridge_addr, const char *name, name, ten_go_value_c_value(value), ten_go_callback_info_create(callback_id)); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_set_property, + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_set_property, set_property_info, false, &err)) { TEN_LOGD("TEN/GO failed to set_property: %s", name); ten_env_notify_set_property_info_destroy(set_property_info, true); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property.c index af5e24a2e..b8c64ec6d 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property.c @@ -8,10 +8,10 @@ #include "include_internal/ten_runtime/binding/python/common/error.h" #include "include_internal/ten_runtime/binding/python/ten_env/ten_env.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/error.h" #include "ten_utils/lib/json.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/memory.h" #include "ten_utils/value/value.h" #include "ten_utils/value/value_get.h" @@ -46,7 +46,8 @@ static void ten_env_notify_get_property_info_destroy( TEN_FREE(info); } -static void ten_env_notify_get_property(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -82,8 +83,9 @@ static ten_value_t *ten_py_ten_property_get_and_check_if_exists( ten_env_notify_get_property_info_t *info = ten_env_notify_get_property_info_create(path); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_get_property, - info, false, &err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_get_property, info, false, + &err)) { goto done; } diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_init_property.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_init_property.c index efce126e7..98a9f95c7 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_init_property.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_init_property.c @@ -39,8 +39,8 @@ static void ten_env_notify_init_property_info_destroy( TEN_FREE(self); } -static void ten_env_notify_init_property_from_json(ten_env_t *ten_env, - void *user_data) { +static void ten_env_proxy_notify_init_property_from_json(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -84,8 +84,8 @@ PyObject *ten_py_ten_env_init_property_from_json(PyObject *self, ten_env_notify_init_property_info_create(json_str, strlen(json_str)); if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, - ten_env_notify_init_property_from_json, info, false, - NULL)) { + ten_env_proxy_notify_init_property_from_json, info, + false, NULL)) { goto done; } diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_log.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_log.c index 04bba53c8..4a7a7a059 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_log.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_log.c @@ -47,7 +47,7 @@ static void ten_env_notify_log_info_destroy(ten_env_notify_log_info_t *info) { TEN_FREE(info); } -static void ten_env_notify_log(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_log(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -99,8 +99,8 @@ PyObject *ten_py_ten_env_log(PyObject *self, PyObject *args) { info->func_name, info->file_name, info->line_no, info->msg); } else { - if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, ten_env_notify_log, info, - false, &err)) { + if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, ten_env_proxy_notify_log, + info, false, &err)) { goto done; } diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_configure_done.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_configure_done.c index a18317e9e..e64e1e3cc 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_configure_done.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_configure_done.c @@ -15,8 +15,8 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_configure_done(ten_env_t *ten_env, - TEN_UNUSED void *user_data) { +static void ten_env_proxy_notify_on_configure_done(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -47,8 +47,8 @@ PyObject *ten_py_ten_env_on_configure_done(PyObject *self, PyObject *args) { rc = ten_env_on_configure_done(py_ten->c_ten_env, &err); } else { rc = ten_env_proxy_notify(py_ten->c_ten_env_proxy, - ten_env_notify_on_configure_done, NULL, false, - &err); + ten_env_proxy_notify_on_configure_done, NULL, + false, &err); } if (!rc) { diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_deinit_done.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_deinit_done.c index 5f3878ee4..1b726c6ad 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_deinit_done.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_deinit_done.c @@ -14,7 +14,8 @@ #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_deinit_done(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_on_deinit_done(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -74,8 +75,8 @@ PyObject *ten_py_ten_env_on_deinit_done(PyObject *self, rc = ten_env_on_deinit_done(py_ten->c_ten_env, &err); } else { rc = ten_env_proxy_notify(py_ten->c_ten_env_proxy, - ten_env_notify_on_deinit_done, py_ten, false, - &err); + ten_env_proxy_notify_on_deinit_done, py_ten, + false, &err); } ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_init_done.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_init_done.c index 12c87c324..ba66bb16a 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_init_done.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_init_done.c @@ -10,13 +10,13 @@ #include "include_internal/ten_runtime/binding/python/ten_env/ten_env.h" #include "include_internal/ten_runtime/metadata/metadata_info.h" #include "include_internal/ten_runtime/ten_env/ten_env.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/ten_env/internal/on_xxx_done.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_init_done(ten_env_t *ten_env, - TEN_UNUSED void *user_data) { +static void ten_env_proxy_notify_on_init_done(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -47,7 +47,8 @@ PyObject *ten_py_ten_env_on_init_done(PyObject *self, PyObject *args) { rc = ten_env_on_init_done(py_ten->c_ten_env, &err); } else { rc = ten_env_proxy_notify(py_ten->c_ten_env_proxy, - ten_env_notify_on_init_done, NULL, false, &err); + ten_env_proxy_notify_on_init_done, NULL, false, + &err); } if (!rc) { diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_start_done.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_start_done.c index 8a476b1f0..733c053d9 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_start_done.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_start_done.c @@ -12,8 +12,8 @@ #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_start_done(ten_env_t *ten_env, - TEN_UNUSED void *user_data) { +static void ten_env_proxy_notify_on_start_done(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -39,8 +39,9 @@ PyObject *ten_py_ten_env_on_start_done(PyObject *self, ten_error_t err; ten_error_init(&err); - TEN_UNUSED bool rc = ten_env_proxy_notify( - py_ten->c_ten_env_proxy, ten_env_notify_on_start_done, NULL, false, &err); + TEN_UNUSED bool rc = ten_env_proxy_notify(py_ten->c_ten_env_proxy, + ten_env_proxy_notify_on_start_done, + NULL, false, &err); TEN_ASSERT(rc, "Should not happen."); ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_stop_done.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_stop_done.c index 8d9a8b758..a0a376d6e 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_stop_done.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_on_stop_done.c @@ -12,8 +12,8 @@ #include "ten_runtime/ten_env/internal/on_xxx_done.h" #include "ten_utils/macro/mark.h" -static void ten_env_notify_on_stop_done(ten_env_t *ten_env, - TEN_UNUSED void *user_data) { +static void ten_env_proxy_notify_on_stop_done(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { TEN_ASSERT( ten_env && ten_env_check_integrity( @@ -39,8 +39,9 @@ PyObject *ten_py_ten_env_on_stop_done(PyObject *self, ten_error_t err; ten_error_init(&err); - TEN_UNUSED bool rc = ten_env_proxy_notify( - py_ten->c_ten_env_proxy, ten_env_notify_on_stop_done, NULL, false, &err); + TEN_UNUSED bool rc = ten_env_proxy_notify(py_ten->c_ten_env_proxy, + ten_env_proxy_notify_on_stop_done, + NULL, false, &err); ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_return_result.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_return_result.c index 74a2ea6d1..74b449ad9 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_return_result.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_return_result.c @@ -50,7 +50,8 @@ static void ten_env_notify_return_result_info_destroy( TEN_FREE(info); } -static void ten_notify_return_result(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -108,9 +109,9 @@ PyObject *ten_py_ten_env_return_result(PyObject *self, PyObject *args) { ten_env_notify_return_result_info_t *notify_info = ten_env_notify_return_result_info_create(c_result_cmd, c_target_cmd); - bool rc = - ten_env_proxy_notify(py_ten->c_ten_env_proxy, ten_notify_return_result, - notify_info, false, &err); + bool rc = ten_env_proxy_notify(py_ten->c_ten_env_proxy, + ten_env_proxy_notify_return_result, + notify_info, false, &err); if (!rc) { ten_env_notify_return_result_info_destroy(notify_info); success = false; @@ -170,8 +171,9 @@ PyObject *ten_py_ten_env_return_result_directly(PyObject *self, ten_env_notify_return_result_info_t *notify_info = ten_env_notify_return_result_info_create(c_result_cmd, NULL); - if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, ten_notify_return_result, - notify_info, false, &err)) { + if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, + ten_env_proxy_notify_return_result, notify_info, + false, &err)) { ten_env_notify_return_result_info_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception( diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_audio_frame.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_audio_frame.c index 252116bf0..7aa4c8aac 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_audio_frame.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_audio_frame.c @@ -40,8 +40,8 @@ static void ten_env_notify_send_audio_frame_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_audio_frame(ten_env_t *ten_env, - void *user_data) { +static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -78,8 +78,8 @@ PyObject *ten_py_ten_env_send_audio_frame(PyObject *self, PyObject *args) { ten_env_notify_send_audio_frame_info_create(cloned_frame); if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, - ten_env_notify_send_audio_frame, notify_info, false, - &err)) { + ten_env_proxy_notify_send_audio_frame, notify_info, + false, &err)) { ten_env_notify_send_audio_frame_info_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to send audio frame."); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_cmd.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_cmd.c index f0581d040..f69abc286 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_cmd.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_cmd.c @@ -11,10 +11,10 @@ #include "include_internal/ten_runtime/binding/python/msg/msg.h" #include "include_internal/ten_runtime/binding/python/ten_env/ten_env.h" #include "include_internal/ten_runtime/msg/cmd_base/cmd_base.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/extension/extension.h" #include "ten_runtime/msg/cmd_result/cmd_result.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" #include "ten_utils/macro/memory.h" @@ -95,7 +95,7 @@ static void ten_env_notify_send_cmd_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_cmd(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -152,8 +152,9 @@ PyObject *ten_py_ten_env_send_cmd(PyObject *self, PyObject *args) { ten_env_notify_send_cmd_info_t *notify_info = ten_env_notify_send_cmd_info_create(cloned_cmd, cb_func); - if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, ten_env_notify_send_cmd, - notify_info, false, &err)) { + if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, + ten_env_proxy_notify_send_cmd, notify_info, false, + &err)) { ten_env_notify_send_cmd_info_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to send cmd."); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_data.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_data.c index a384cb7d5..da0f2b75c 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_data.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_data.c @@ -39,7 +39,8 @@ static void ten_env_notify_send_data_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_data(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -73,8 +74,9 @@ PyObject *ten_py_ten_env_send_data(PyObject *self, PyObject *args) { ten_env_notify_send_data_info_t *notify_info = ten_env_notify_send_data_info_create(cloned_data); - if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, ten_env_notify_send_data, - notify_info, false, &err)) { + if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, + ten_env_proxy_notify_send_data, notify_info, false, + &err)) { ten_env_notify_send_data_info_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to send data."); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_json.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_json.c index f23d2fa30..fffcd5a08 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_json.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_json.c @@ -92,7 +92,8 @@ static void ten_env_notify_send_json_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_json(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_send_json(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -151,8 +152,9 @@ PyObject *ten_py_ten_env_send_json(PyObject *self, PyObject *args) { ten_env_notify_send_json_info_create(json, cb_func); ten_json_destroy(json); - if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, ten_env_notify_send_json, - notify_info, false, &err)) { + if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, + ten_env_proxy_notify_send_json, notify_info, false, + &err)) { ten_py_raise_py_runtime_error_exception(ten_error_errmsg(&err)); ten_env_notify_send_json_info_destroy(notify_info); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_video_frame.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_video_frame.c index e24397baf..2e5c3f712 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_video_frame.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_video_frame.c @@ -38,8 +38,8 @@ static void ten_env_notify_send_video_frame_info_destroy( TEN_FREE(info); } -static void ten_env_notify_send_video_frame(ten_env_t *ten_env, - void *user_data) { +static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -76,8 +76,8 @@ PyObject *ten_py_ten_env_send_video_frame(PyObject *self, PyObject *args) { ten_env_notify_send_video_frame_info_create(cloned_frame); if (!ten_env_proxy_notify(py_ten->c_ten_env_proxy, - ten_env_notify_send_video_frame, notify_info, false, - &err)) { + ten_env_proxy_notify_send_video_frame, notify_info, + false, &err)) { ten_env_notify_send_video_frame_info_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to send video frame."); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_set_property.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_set_property.c index d0aacb71b..a5f49255e 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_set_property.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_set_property.c @@ -47,7 +47,8 @@ static void ten_env_notify_set_property_info_destroy( TEN_FREE(self); } -static void ten_env_notify_set_property(ten_env_t *ten_env, void *user_data) { +static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -78,8 +79,9 @@ static void ten_py_ten_env_set_property(ten_py_ten_env_t *self, ten_env_notify_set_property_info_t *info = ten_env_notify_set_property_info_create(path, value); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_notify_set_property, - info, false, &err)) { + if (!ten_env_proxy_notify(self->c_ten_env_proxy, + ten_env_proxy_notify_set_property, info, false, + &err)) { goto done; } diff --git a/core/src/ten_runtime/connection/connection.c b/core/src/ten_runtime/connection/connection.c index 65948fbad..7114ba1d2 100644 --- a/core/src/ten_runtime/connection/connection.c +++ b/core/src/ten_runtime/connection/connection.c @@ -244,7 +244,7 @@ static bool ten_connection_on_input(ten_connection_t *self, return ten_remote_on_input(self->attached_target.remote, msg, err); case TEN_CONNECTION_ATTACH_TO_APP: // Enable the 'app' to handle this message. - return ten_app_on_msg(self->attached_target.app, self, msg, err); + return ten_app_handle_in_msg(self->attached_target.app, self, msg, err); default: TEN_ASSERT(0, "Should not happen."); return false; diff --git a/core/src/ten_runtime/ten_env/internal/send.c b/core/src/ten_runtime/ten_env/internal/send.c index 3cd9ff715..25a7377ab 100644 --- a/core/src/ten_runtime/ten_env/internal/send.c +++ b/core/src/ten_runtime/ten_env/internal/send.c @@ -8,6 +8,7 @@ #include +#include "include_internal/ten_runtime/app/msg_interface/common.h" #include "include_internal/ten_runtime/common/loc.h" #include "include_internal/ten_runtime/extension/extension.h" #include "include_internal/ten_runtime/extension_context/extension_context.h" @@ -85,26 +86,43 @@ static bool ten_send_msg_internal( // @} } - ten_extension_t *extension = ten_env_get_attached_extension(self); - TEN_ASSERT(extension, "Invalid argument."); + switch (ten_env_get_attach_to(self)) { + case TEN_ENV_ATTACH_TO_EXTENSION: { + ten_extension_t *extension = ten_env_get_attached_extension(self); + TEN_ASSERT(extension, "Should not happen."); + + if (extension->state < TEN_EXTENSION_STATE_INITTED) { + TEN_LOGE("Cannot send messages before on_init_done."); + ten_error_set(err, TEN_ERRNO_GENERIC, + "Cannot send messages before on_init_done."); + result = false; + goto done; + } + + if (extension->state >= TEN_EXTENSION_STATE_CLOSING) { + TEN_LOGE("Cannot send messages after on_stop_done."); + ten_error_set(err, TEN_ERRNO_GENERIC, + "Cannot send messages after on_stop_done."); + result = false; + goto done; + } + + result = ten_extension_handle_out_msg(extension, msg, err); + break; + } - if (extension->state < TEN_EXTENSION_STATE_INITTED) { - TEN_LOGE("Cannot send messages before on_init_done."); - ten_error_set(err, TEN_ERRNO_GENERIC, - "Cannot send messages before on_init_done."); - result = false; - goto done; - } + case TEN_ENV_ATTACH_TO_APP: { + ten_app_t *app = ten_env_get_attached_app(self); + TEN_ASSERT(app, "Should not happen."); - if (extension->state >= TEN_EXTENSION_STATE_CLOSING) { - TEN_LOGE("Cannot send messages after on_stop_done."); - ten_error_set(err, TEN_ERRNO_GENERIC, - "Cannot send messages after on_stop_done."); - result = false; - goto done; - } + result = ten_app_handle_out_msg(app, msg, err); + break; + } - result = ten_extension_handle_out_msg(extension, msg, err); + default: + TEN_ASSERT(0, "Handle more conditions: %d", ten_env_get_attach_to(self)); + break; + } done: if (err_new_created) { diff --git a/core/src/ten_runtime/ten_env_proxy/internal/notify.c b/core/src/ten_runtime/ten_env_proxy/internal/notify.c index 4caf3b8ec..59d30372a 100644 --- a/core/src/ten_runtime/ten_env_proxy/internal/notify.c +++ b/core/src/ten_runtime/ten_env_proxy/internal/notify.c @@ -11,13 +11,13 @@ #include "include_internal/ten_runtime/ten_env/ten_env.h" #include "include_internal/ten_runtime/ten_env/ten_env_proxy.h" #include "include_internal/ten_runtime/ten_env_proxy/ten_env_proxy.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/extension/extension.h" #include "ten_runtime/extension_group/extension_group.h" #include "ten_runtime/ten_env/ten_env.h" #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/io/runloop.h" #include "ten_utils/lib/thread.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/memory.h" static ten_notify_data_t *ten_notify_data_create(ten_notify_func_t notify_func, @@ -181,7 +181,7 @@ bool ten_env_proxy_notify(ten_env_proxy_t *self, ten_notify_func_t notify_func, if (ten_extension_thread_call_by_me(extension_thread)) { notify_func(self->ten_env, user_data); } else { - TEN_ASSERT(sync == true, "Unsupported operation."); + TEN_ASSERT(sync == false, "Unsupported operation."); ten_runloop_post_task_tail( ten_extension_group_get_attached_runloop(extension_group), @@ -201,7 +201,7 @@ bool ten_env_proxy_notify(ten_env_proxy_t *self, ten_notify_func_t notify_func, if (ten_app_thread_call_by_me(app)) { notify_func(self->ten_env, user_data); } else { - TEN_ASSERT(sync == true, "Unsupported operation."); + TEN_ASSERT(sync == false, "Unsupported operation."); ten_runloop_post_task_tail( ten_app_get_attached_runloop(app), ten_notify_to_app_task, app, diff --git a/core/src/ten_runtime/ten_env_proxy/ten_env_proxy.c b/core/src/ten_runtime/ten_env_proxy/ten_env_proxy.c index e1ac4388c..63399d0a8 100644 --- a/core/src/ten_runtime/ten_env_proxy/ten_env_proxy.c +++ b/core/src/ten_runtime/ten_env_proxy/ten_env_proxy.c @@ -12,7 +12,6 @@ #include "include_internal/ten_runtime/extension_thread/extension_thread.h" #include "include_internal/ten_runtime/ten_env/ten_env.h" #include "include_internal/ten_runtime/ten_env_proxy/ten_env_proxy.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/common/errno.h" #include "ten_runtime/extension/extension.h" #include "ten_runtime/extension_group/extension_group.h" @@ -21,6 +20,7 @@ #include "ten_utils/io/runloop.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/mutex.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" // There's no need to check for thread-safety, as ten_env_proxy is inherently @@ -53,6 +53,8 @@ ten_env_proxy_t *ten_env_proxy_create(ten_env_t *ten_env, return NULL; } + // Checking 1: The platform currently only supports creating a `ten_env_proxy` + // from the `ten_env` of an extension, an extension_group, and an app. switch (ten_env->attach_to) { case TEN_ENV_ATTACH_TO_EXTENSION: case TEN_ENV_ATTACH_TO_EXTENSION_GROUP: @@ -69,6 +71,8 @@ ten_env_proxy_t *ten_env_proxy_create(ten_env_t *ten_env, } } + // Checking 2: The creation of `ten_env_proxy` must occur within the belonging + // thread of the corresponding `ten_env`. switch (ten_env->attach_to) { case TEN_ENV_ATTACH_TO_EXTENSION: { ten_extension_t *extension = ten_env->attached_target.extension; @@ -143,6 +147,9 @@ ten_env_proxy_t *ten_env_proxy_create(ten_env_t *ten_env, self->thread_cnt = initial_thread_cnt; self->ten_env = ten_env; + // The created `ten_env_proxy` needs to be recorded, and the corresponding + // `ten_env` cannot be destroyed as long as any `ten_env_proxy` has not yet + // been destroyed. ten_env_add_ten_proxy(ten_env, self); return self; diff --git a/core/src/ten_runtime/test/extension_test.c b/core/src/ten_runtime/test/extension_test.c index 63533d1a5..950c8c6d2 100644 --- a/core/src/ten_runtime/test/extension_test.c +++ b/core/src/ten_runtime/test/extension_test.c @@ -8,13 +8,28 @@ #include +#include "include_internal/ten_runtime/app/app.h" +#include "include_internal/ten_runtime/common/constant_str.h" #include "include_internal/ten_runtime/extension_group/extension_group.h" #include "include_internal/ten_runtime/extension_thread/extension_thread.h" #include "include_internal/ten_runtime/extension_thread/on_xxx.h" +#include "include_internal/ten_runtime/ten_env/ten_env.h" +#include "include_internal/ten_runtime/test/test_extension_group.h" +#include "ten_runtime/addon/extension_group/extension_group.h" +#include "ten_runtime/app/app.h" #include "ten_runtime/extension/extension.h" +#include "ten_runtime/msg/cmd/close_app/cmd.h" +#include "ten_runtime/msg/msg.h" +#include "ten_runtime/ten_env/internal/metadata.h" +#include "ten_runtime/ten_env/internal/on_xxx_done.h" +#include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/container/list.h" #include "ten_utils/container/list_ptr.h" +#include "ten_utils/lib/event.h" +#include "ten_utils/lib/smart_ptr.h" #include "ten_utils/lib/thread.h" +#include "ten_utils/macro/check.h" +#include "ten_utils/macro/mark.h" #include "ten_utils/macro/memory.h" static void *ten_extension_thread_main(void *self_) { @@ -35,6 +50,151 @@ static void *ten_extension_thread_main(void *self_) { return ten_extension_thread_main_actual(self->test_extension_thread); } +static void test_ten_app_on_configure(ten_app_t *app, ten_env_t *ten_env) { +#if 0 + const char *property_json = + "{\ + \"_ten\": {\ + \"predefined_graphs\": [{\ + \"name\": \"0\",\ + \"auto_start\": false,\ + \"nodes\": [{\ + \"type\": \"extension_group\",\ + \"name\": \"test_extension_group\",\ + \"addon\": \"test_extension_group\"\ + },{\ + \"type\": \"extension\",\ + \"name\": \"...\",\ + \"addon\": \"...\",\ + \"extension_group\": \"test_extension_group\"\ + }]\ + }]\ + }\ + }"; + bool rc = ten_env_init_property_from_json(ten_env, property_json, NULL); + TEN_ASSERT(rc, "Should not happen."); +#endif + + bool rc = ten_env_on_configure_done(ten_env, NULL); + TEN_ASSERT(rc, "Should not happen."); +} + +static void test_ten_app_on_init(ten_app_t *app, ten_env_t *ten_env) { + ten_extension_test_new_t *test_info = app->user_data; + TEN_ASSERT(test_info, "Should not happen."); + + test_info->test_app_ten_env_proxy = ten_env_proxy_create(ten_env, 1, NULL); + TEN_ASSERT(test_info->test_app_ten_env_proxy, "Should not happen."); + + ten_event_set(test_info->test_app_ten_env_proxy_create_completed); + + ten_env_on_init_done(ten_env, NULL); +} + +static void test_ten_app_on_deinit(ten_app_t *app, ten_env_t *ten_env) { + ten_extension_test_new_t *test_info = app->user_data; + TEN_ASSERT(test_info, "Should not happen."); + + bool rc = ten_env_proxy_release(test_info->test_app_ten_env_proxy, NULL); + TEN_ASSERT(rc, "Should not happen."); + + test_info->test_app_ten_env_proxy = NULL; + + ten_env_on_deinit_done(ten_env, NULL); +} + +void *test_app_thread_main(void *args) { + ten_error_t err; + ten_error_init(&err); + + ten_extension_test_new_t *test_info = args; + + ten_app_t *test_app = + ten_app_create(test_ten_app_on_configure, test_ten_app_on_init, + test_ten_app_on_deinit, &err); + TEN_ASSERT(test_app, "Failed to create app."); + + test_app->user_data = test_info; + + bool rc = ten_app_run(test_app, false, &err); + TEN_ASSERT(rc, "Should not happen."); + + ten_app_destroy(test_app); + + return NULL; +} + +static ten_addon_t test_extension_group_addon = { + NULL, + TEN_ADDON_SIGNATURE, + ten_test_extension_group_addon_on_init, + NULL, + NULL, + NULL, + ten_test_extension_group_addon_create_instance, + ten_test_extension_group_addon_destroy_instance, + NULL, + NULL, +}; + +ten_extension_test_new_t *ten_extension_test_create_new(void) { + // Register the test_extension_group addon. + ten_addon_register_extension_group("test_extension_group", + &test_extension_group_addon); + + ten_extension_test_new_t *self = TEN_MALLOC(sizeof(ten_extension_test_new_t)); + TEN_ASSERT(self, "Failed to allocate memory."); + + self->test_app_ten_env_proxy = NULL; + self->test_app_ten_env_proxy_create_completed = ten_event_create(0, 1); + + self->test_app_thread = + ten_thread_create("test app thread", test_app_thread_main, self); + + ten_event_wait(self->test_app_ten_env_proxy_create_completed, -1); + + return self; +} + +static void ten_env_proxy_notify_close_app(ten_env_t *ten_env, + TEN_UNUSED void *user_data) { + TEN_ASSERT( + ten_env && + ten_env_check_integrity( + ten_env, + ten_env->attach_to != TEN_ENV_ATTACH_TO_ADDON ? true : false), + "Should not happen."); + + ten_shared_ptr_t *close_app_cmd = ten_cmd_close_app_create(); + TEN_ASSERT(close_app_cmd, "Should not happen."); + + // Set the destination so that the recipient is the app itself. + bool rc = ten_msg_clear_and_set_dest(close_app_cmd, TEN_STR_LOCALHOST, NULL, + NULL, NULL, NULL, NULL); + TEN_ASSERT(rc, "Should not happen."); + + rc = ten_env_send_cmd(ten_env, close_app_cmd, NULL, NULL, NULL); + TEN_ASSERT(rc, "Should not happen."); +} + +void ten_extension_test_destroy_new(ten_extension_test_new_t *self) { + TEN_ASSERT(self, "Invalid argument."); + TEN_ASSERT(self->test_app_ten_env_proxy, "Invalid argument."); + + ten_env_proxy_notify(self->test_app_ten_env_proxy, + ten_env_proxy_notify_close_app, NULL, false, NULL); + + ten_thread_join(self->test_app_thread, -1); + + TEN_ASSERT(self->test_app_ten_env_proxy == NULL, "Should not happen."); + ten_event_destroy(self->test_app_ten_env_proxy_create_completed); + + TEN_FREE(self); + + ten_addon_unregister_extension_group("test_extension_group", + &test_extension_group_addon); +} + ten_extension_test_t *ten_extension_test_create( ten_extension_t *test_extension, ten_extension_t *target_extension) { ten_extension_test_t *self = TEN_MALLOC(sizeof(ten_extension_test_t)); diff --git a/core/src/ten_runtime/test/test_extension_group.c b/core/src/ten_runtime/test/test_extension_group.c new file mode 100644 index 000000000..5a8182639 --- /dev/null +++ b/core/src/ten_runtime/test/test_extension_group.c @@ -0,0 +1,202 @@ +// +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0. +// See the LICENSE file for more information. +// +#include +#include + +#include "include_internal/ten_runtime/addon/addon.h" +#include "include_internal/ten_runtime/extension/extension_addon_and_instance_name_pair.h" +#include "include_internal/ten_runtime/extension_group/extension_group.h" +#include "include_internal/ten_runtime/ten_env/metadata.h" +#include "include_internal/ten_runtime/ten_env/ten_env.h" +#include "ten_runtime/addon/extension_group/extension_group.h" +#include "ten_runtime/extension_group/extension_group.h" +#include "ten_runtime/ten.h" +#include "ten_runtime/ten_env/internal/log.h" +#include "ten_runtime/ten_env/ten_env.h" +#include "ten_utils/container/list_ptr.h" +#include "ten_utils/log/log.h" +#include "ten_utils/macro/check.h" +#include "ten_utils/macro/mark.h" + +static void on_addon_create_instance_done(ten_env_t *ten_env, + ten_extension_t *extension, + void *cb_data) { + TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), + "Invalid argument."); + TEN_ASSERT(extension && ten_extension_check_integrity(extension, true), + "Invalid argument."); + TEN_ASSERT( + ten_env_get_attach_to(ten_env) == TEN_ENV_ATTACH_TO_EXTENSION_GROUP, + "Invalid argument."); + + ten_extension_group_t *extension_group = ten_env_get_attached_target(ten_env); + TEN_ASSERT(extension_group && + ten_extension_group_check_integrity(extension_group, true), + "Invalid argument."); + + ten_list_t *result = (ten_list_t *)cb_data; + TEN_ASSERT(result, "Should not happen."); + + ten_list_push_ptr_back(result, extension, NULL); + + if (ten_list_size(result) == + ten_list_size( + ten_extension_group_get_extension_addon_and_instance_name_pairs( + extension_group))) { + // Notify the default extension group that all extensions have been created. + ten_env_on_create_extensions_done( + ten_extension_group_get_ten_env(extension_group), result, NULL); + + ten_list_destroy(result); + } +} + +static void on_addon_destroy_instance_done(ten_env_t *ten_env, + TEN_UNUSED void *cb_data) { + TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), + "Invalid argument."); + TEN_ASSERT( + ten_env_get_attach_to(ten_env) == TEN_ENV_ATTACH_TO_EXTENSION_GROUP, + "Invalid argument."); + + ten_extension_group_t *extension_group = ten_env_get_attached_target(ten_env); + TEN_ASSERT(extension_group && + ten_extension_group_check_integrity(extension_group, true), + "Invalid argument."); + + // We modify 'extensions_cnt_of_being_destroyed' on the extension thread, so + // it's thread safe. + if (ten_extension_group_decrement_extension_cnt_of_being_destroyed( + extension_group) == 0) { + ten_env_on_destroy_extensions_done(ten_env, NULL); + } +} + +static void ten_test_extension_group_on_init(ten_extension_group_t *self, + ten_env_t *ten_env) { + TEN_ASSERT(self, "Invalid argument."); + TEN_ASSERT(ten_env, "Invalid argument."); + + ten_env_on_init_done(ten_env, NULL); +} + +static void ten_test_extension_group_on_deinit(ten_extension_group_t *self, + ten_env_t *ten_env) { + TEN_ASSERT(self, "Invalid argument."); + TEN_ASSERT(ten_env, "Invalid argument."); + + ten_env_on_deinit_done(ten_env, NULL); +} + +static void ten_test_extension_group_on_create_extensions( + ten_extension_group_t *self, ten_env_t *ten_env) { + TEN_ASSERT(self, "Invalid argument."); + TEN_ASSERT(ten_env, "Invalid argument."); + + ten_list_t *result = ten_list_create(); + + if (ten_list_is_empty( + ten_extension_group_get_extension_addon_and_instance_name_pairs( + self))) { + ten_env_on_create_extensions_done(ten_env, result, NULL); + ten_list_destroy(result); + return; + } + + // Get the information of all the extensions which this extension group should + // create. + ten_list_foreach ( + ten_extension_group_get_extension_addon_and_instance_name_pairs(self), + iter) { + ten_extension_addon_and_instance_name_pair_t *extension_name_info = + ten_ptr_listnode_get(iter.node); + TEN_ASSERT(extension_name_info, "Invalid argument."); + + ten_string_t *extension_addon_name = &extension_name_info->addon_name; + ten_string_t *extension_instance_name = &extension_name_info->instance_name; + + bool res = ten_addon_create_extension_async( + ten_env, ten_string_get_raw_str(extension_addon_name), + ten_string_get_raw_str(extension_instance_name), + (ten_env_addon_on_create_instance_async_cb_t) + on_addon_create_instance_done, + result, NULL); + + if (!res) { + TEN_LOGE("Failed to find the addon for extension %s", + ten_string_get_raw_str(extension_addon_name)); +#if defined(_DEBUG) + TEN_ASSERT(0, "Should not happen."); +#endif + } + } +} + +static void ten_test_extension_group_on_destroy_extensions( + ten_extension_group_t *self, ten_env_t *ten_env, ten_list_t extensions) { + TEN_ASSERT(self, "Invalid argument."); + TEN_ASSERT(ten_env, "Invalid argument."); + + if (ten_list_size(&extensions) == 0) { + ten_env_on_destroy_extensions_done(ten_env, NULL); + return; + } + + ten_extension_group_set_extension_cnt_of_being_destroyed( + self, ten_list_size(&extensions)); + + ten_list_foreach (&extensions, iter) { + ten_extension_t *extension = ten_ptr_listnode_get(iter.node); + TEN_ASSERT(extension && ten_extension_check_integrity(extension, true), + "Invalid argument."); + + ten_addon_destroy_extension_async( + ten_env, extension, on_addon_destroy_instance_done, NULL, NULL); + } +} + +void ten_test_extension_group_addon_on_init(TEN_UNUSED ten_addon_t *addon, + ten_env_t *ten_env) { + bool result = ten_env_init_manifest_from_json(ten_env, + // clang-format off + "{\ + \"type\": \"extension_group\",\ + \"name\": \"test_extension_group\",\ + \"version\": \"1.0.0\"\ + }", + // clang-format on + NULL); + TEN_ASSERT(result, "Should not happen."); + + ten_env_on_init_done(ten_env, NULL); +} + +void ten_test_extension_group_addon_create_instance(ten_addon_t *addon, + ten_env_t *ten_env, + const char *name, + void *context) { + TEN_ASSERT(addon && name, "Invalid argument."); + + ten_extension_group_t *ext_group = ten_extension_group_create( + name, NULL, ten_test_extension_group_on_init, + ten_test_extension_group_on_deinit, + ten_test_extension_group_on_create_extensions, + ten_test_extension_group_on_destroy_extensions); + + ten_env_on_create_instance_done(ten_env, ext_group, context, NULL); +} + +void ten_test_extension_group_addon_destroy_instance( + TEN_UNUSED ten_addon_t *addon, ten_env_t *ten_env, void *_extension_group, + void *context) { + ten_extension_group_t *extension_group = + (ten_extension_group_t *)_extension_group; + TEN_ASSERT(extension_group, "Invalid argument."); + + ten_extension_group_destroy(extension_group); + + ten_env_on_destroy_instance_done(ten_env, context, NULL); +} diff --git a/core/src/ten_rust/BUILD.gn b/core/src/ten_rust/BUILD.gn index c5698d150..bbb49e3f4 100644 --- a/core/src/ten_rust/BUILD.gn +++ b/core/src/ten_rust/BUILD.gn @@ -16,12 +16,21 @@ if (enable_ten_rust) { if (is_linux || is_win || (is_mac && target_cpu == "x64")) { rust_test("ten_rust_test") { project_path = "//core/src/ten_rust" - test_output_dir = "${root_out_dir}/tests/standalone/ten_rust" integration_test_output_name = "integration_test" utils_static_lib_path = rebase_path("${root_gen_dir}/core/src/ten_utils") env = [ "TEN_UTILS_LIBRARY_PATH=${utils_static_lib_path}" ] + # If the output directory of `cargo build` (tman) and + # `cargo build --tests` (tman_test) is the same, and if `cargo build` is + # executed first followed by `cargo build --tests`, the resulting + # executable will be the normal executable, not the test case executable. + # Therefore, it's necessary to separate the `target-dir` for these two + # `cargo build` commands to avoid interfering with each other. + target_path = "${root_gen_dir}/core/src/ten_rust_test" + + test_output_dir = "${root_out_dir}/tests/standalone/ten_rust" + deps = [ ":ten_rust_build_deps", ":ten_rust_test_data", diff --git a/core/src/ten_rust/src/build.rs b/core/src/ten_rust/src/build.rs index 025a78cb7..56a31832a 100644 --- a/core/src/ten_rust/src/build.rs +++ b/core/src/ten_rust/src/build.rs @@ -4,7 +4,13 @@ // Licensed under the Apache License, Version 2.0, with certain conditions. // Refer to the "LICENSE" file in the root directory for more information. // -use std::{env, fs, path::PathBuf}; +use std::{ + env, fs, + path::{Path, PathBuf}, + process::id, + thread, + time::Duration, +}; fn auto_gen_schema_bindings_from_c() { let mut base_dir = env::current_dir() @@ -32,13 +38,40 @@ fn auto_gen_schema_bindings_from_c() { .generate() .expect("Unable to generate bindings"); - let generated_bindings = "src/schema/bindings.rs"; + // Generate a unique temporary file based on the current process ID. + // + // When `ten_rust` is built, it writes to the + // `core/src/ten_rust/src/schema/bindings.rs` file, and multiple GN build + // paths can trigger the `cargo build` of `ten_rust`. For example, one is + // the `ten_rust_static_lib` GN target, another is the `ten_rust_test` GN + // target, and another case could be when building `tman`, where the + // `Cargo.toml` of `tman` includes a dependency on `ten_rust`, thus + // triggering the build of `ten_rust`. Therefore, if these targets trigger + // the `cargo build` at the same time, it may result in corrupted content in + // `core/src/ten_rust/src/schema/bindings.rs`. To prevent this, an + // atomic operation is needed to ensure that the content of + // `core/src/ten_rust/src/schema/bindings.rs` is not corrupted due to + // multiple parallel generation actions overwriting each other's file + // content. On Windows, Linux, and macOS, file system `rename` operations + // within the same mount point are atomic. Therefore, taking advantage of + // this feature, the content of `bindings.rs` is first generated into a + // temporary file, which is then atomically renamed to the final + // `bindings.rs`, thereby avoiding content corruption caused by parallel + // `cargo build` processes. + // + // TODO(Wei): Another possible solution is to differentiate the + // `core/src/ten_rust/src/schema/bindings.rs` files under these GN build + // paths, with each build path using its own `schema/bindings.rs`. + let schema_dir = Path::new("src/schema/"); + let generated_bindings = schema_dir.join("bindings.rs"); + let temp_bindings = schema_dir.join(format!("bindings_{}.rs.tmp", id())); + binding_gen - .write_to_file(generated_bindings) + .write_to_file(&temp_bindings) .expect("Unable to write bindings into file."); // Add some rules to the bindings file to disable clippy lints. - let bindings_content = fs::read_to_string(generated_bindings) + let bindings_content = fs::read_to_string(&temp_bindings) .expect("Unable to read generated bindings"); let disabled_clippy_lints = [ "#![allow(non_upper_case_globals)]", @@ -47,8 +80,35 @@ fn auto_gen_schema_bindings_from_c() { ]; let new_bindings_content = disabled_clippy_lints.join("\n") + "\n\n" + &bindings_content; - fs::write(generated_bindings, new_bindings_content) + fs::write(&temp_bindings, new_bindings_content) .expect("Unable to add clippy lint rules to the generated bindings."); + + let max_retries = 5; + // 500 milliseconds delay between retries. + let retry_delay = Duration::from_millis(500); + + for attempt in 1..=max_retries { + // Atomically move the temporary file to the target file. + match fs::rename(&temp_bindings, &generated_bindings) { + Ok(_) => { + println!("File renamed successfully."); + break; + } + Err(e) if attempt < max_retries => { + println!( + "Attempt {}/{} failed: {}. Retrying...", + attempt, max_retries, e + ); + thread::sleep(retry_delay); + } + Err(e) => { + panic!( + "Unable to move temporary bindings to final destination after {} attempts: {}", + max_retries, e + ); + } + } + } } // The current auto-detection only supports limited environment combinations; diff --git a/tests/ten_runtime/smoke/standalone_test/BUILD.gn b/tests/ten_runtime/smoke/standalone_test/BUILD.gn index ab81e6c8f..b1fb48323 100644 --- a/tests/ten_runtime/smoke/standalone_test/BUILD.gn +++ b/tests/ten_runtime/smoke/standalone_test/BUILD.gn @@ -10,6 +10,7 @@ import("//build/ten_runtime/ten.gni") glob("standalone_test") { file_list = [ # "basic.cc", + "new.cc", "send_cmd.cc", ] diff --git a/tests/ten_runtime/smoke/standalone_test/new.cc b/tests/ten_runtime/smoke/standalone_test/new.cc new file mode 100644 index 000000000..5ed25ac97 --- /dev/null +++ b/tests/ten_runtime/smoke/standalone_test/new.cc @@ -0,0 +1,41 @@ +// +// Copyright © 2024 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. +// +#include "gtest/gtest.h" +#include "include_internal/ten_runtime/binding/cpp/ten.h" +#include "include_internal/ten_runtime/test/extension_test.h" +#include "ten_utils/lang/cpp/lib/value.h" +#include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h" + +namespace { + +// This part is the extension codes written by the developer, maintained in its +// final release form, and will not change due to testing requirements. + +class test_extension_1 : public ten::extension_t { + public: + explicit test_extension_1(const std::string &name) : ten::extension_t(name) {} + + void on_cmd(ten::ten_env_t &ten_env, + std::unique_ptr cmd) override { + if (std::string(cmd->get_name()) == "hello_world") { + auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); + cmd_result->set_property("detail", "hello world, too"); + bool rc = ten_env.return_result(std::move(cmd_result), std::move(cmd)); + EXPECT_EQ(rc, true); + } + } +}; + +TEN_CPP_REGISTER_ADDON_AS_EXTENSION(standalone_test_new__test_extension_1, + test_extension_1); + +} // namespace + +TEST(StandaloneTest, New) { // NOLINT + ten_extension_test_new_t *test = ten_extension_test_create_new(); + ten_extension_test_destroy_new(test); +}