diff --git a/core/include_internal/ten_runtime/addon/addon.h b/core/include_internal/ten_runtime/addon/addon.h index 70c2af07e2..7cdf150c38 100644 --- a/core/include_internal/ten_runtime/addon/addon.h +++ b/core/include_internal/ten_runtime/addon/addon.h @@ -77,20 +77,20 @@ typedef struct ten_addon_host_t { void *user_data; } ten_addon_host_t; -typedef struct ten_addon_on_create_extension_instance_info_t { +typedef struct ten_addon_on_create_extension_instance_ctx_t { ten_string_t addon_name; ten_string_t instance_name; TEN_ADDON_TYPE addon_type; // Used to retrieve addon from the correct store. ten_env_addon_create_instance_done_cb_t cb; void *cb_data; -} ten_addon_on_create_extension_instance_info_t; +} ten_addon_on_create_extension_instance_ctx_t; -typedef struct ten_addon_on_destroy_instance_info_t { +typedef struct ten_addon_on_destroy_instance_ctx_t { ten_addon_host_t *addon_host; void *instance; ten_env_addon_destroy_instance_done_cb_t cb; void *cb_data; -} ten_addon_on_destroy_instance_info_t; +} ten_addon_on_destroy_instance_ctx_t; TEN_RUNTIME_PRIVATE_API bool ten_addon_host_check_integrity( ten_addon_host_t *self); @@ -110,23 +110,22 @@ TEN_RUNTIME_PRIVATE_API ten_addon_t *ten_addon_unregister( TEN_RUNTIME_PRIVATE_API const char *ten_addon_host_get_name( ten_addon_host_t *self); -TEN_RUNTIME_PRIVATE_API ten_addon_on_create_extension_instance_info_t * -ten_addon_on_create_extension_instance_info_create( +TEN_RUNTIME_PRIVATE_API ten_addon_on_create_extension_instance_ctx_t * +ten_addon_on_create_extension_instance_ctx_create( TEN_ADDON_TYPE addon_type, const char *addon_name, const char *instance_name, ten_env_addon_create_instance_done_cb_t cb, void *cb_data); -TEN_RUNTIME_PRIVATE_API void -ten_addon_on_create_extension_instance_info_destroy( - ten_addon_on_create_extension_instance_info_t *self); +TEN_RUNTIME_PRIVATE_API void ten_addon_on_create_extension_instance_ctx_destroy( + ten_addon_on_create_extension_instance_ctx_t *self); -TEN_RUNTIME_PRIVATE_API ten_addon_on_destroy_instance_info_t * -ten_addon_host_on_destroy_instance_info_create( +TEN_RUNTIME_PRIVATE_API ten_addon_on_destroy_instance_ctx_t * +ten_addon_host_on_destroy_instance_ctx_create( ten_addon_host_t *self, void *instance, ten_env_addon_destroy_instance_done_cb_t cb, void *cb_data); -TEN_RUNTIME_PRIVATE_API void ten_addon_on_destroy_instance_info_destroy( - ten_addon_on_destroy_instance_info_t *self); +TEN_RUNTIME_PRIVATE_API void ten_addon_on_destroy_instance_ctx_destroy( + ten_addon_on_destroy_instance_ctx_t *self); TEN_RUNTIME_PRIVATE_API ten_addon_store_t *ten_addon_get_store(void); diff --git a/core/include_internal/ten_runtime/addon/protocol/protocol.h b/core/include_internal/ten_runtime/addon/protocol/protocol.h index 85f8aa9dcf..ab7c078931 100644 --- a/core/include_internal/ten_runtime/addon/protocol/protocol.h +++ b/core/include_internal/ten_runtime/addon/protocol/protocol.h @@ -20,12 +20,12 @@ typedef struct ten_addon_store_t ten_addon_store_t; typedef void (*ten_env_addon_on_create_protocol_async_cb_t)( ten_env_t *ten_env, ten_protocol_t *protocol, void *cb_data); -typedef struct ten_addon_create_protocol_info_t { +typedef struct ten_addon_create_protocol_ctx_t { ten_string_t uri; TEN_PROTOCOL_ROLE role; ten_env_addon_on_create_protocol_async_cb_t cb; void *user_data; -} ten_addon_create_protocol_info_t; +} ten_addon_create_protocol_ctx_t; TEN_RUNTIME_PRIVATE_API bool ten_addon_create_protocol_with_uri( ten_env_t *ten_env, const char *uri, TEN_PROTOCOL_ROLE role, diff --git a/core/include_internal/ten_runtime/app/on_xxx.h b/core/include_internal/ten_runtime/app/on_xxx.h index d196e16884..86c020c48b 100644 --- a/core/include_internal/ten_runtime/app/on_xxx.h +++ b/core/include_internal/ten_runtime/app/on_xxx.h @@ -14,24 +14,24 @@ typedef struct ten_protocol_t ten_protocol_t; typedef struct ten_addon_loader_t ten_addon_loader_t; -typedef struct ten_app_thread_on_addon_create_protocol_done_info_t { +typedef struct ten_app_thread_on_addon_create_protocol_done_ctx_t { ten_protocol_t *protocol; ten_addon_context_t *addon_context; -} ten_app_thread_on_addon_create_protocol_done_info_t; +} ten_app_thread_on_addon_create_protocol_done_ctx_t; -typedef struct ten_app_thread_on_addon_create_addon_loader_done_info_t { +typedef struct ten_app_thread_on_addon_create_addon_loader_done_ctx_t { ten_addon_loader_t *addon_loader; ten_addon_context_t *addon_context; -} ten_app_thread_on_addon_create_addon_loader_done_info_t; +} ten_app_thread_on_addon_create_addon_loader_done_ctx_t; -TEN_RUNTIME_PRIVATE_API ten_app_thread_on_addon_create_protocol_done_info_t * -ten_app_thread_on_addon_create_protocol_done_info_create(void); +TEN_RUNTIME_PRIVATE_API ten_app_thread_on_addon_create_protocol_done_ctx_t * +ten_app_thread_on_addon_create_protocol_done_ctx_create(void); TEN_RUNTIME_PRIVATE_API void ten_app_thread_on_addon_create_protocol_done( void *self, void *arg); -TEN_RUNTIME_PRIVATE_API ten_app_thread_on_addon_create_addon_loader_done_info_t * -ten_app_thread_on_addon_create_addon_loader_done_info_create(void); +TEN_RUNTIME_PRIVATE_API ten_app_thread_on_addon_create_addon_loader_done_ctx_t * +ten_app_thread_on_addon_create_addon_loader_done_ctx_create(void); TEN_RUNTIME_PRIVATE_API void ten_app_thread_on_addon_create_addon_loader_done( void *self, void *arg); diff --git a/core/include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h b/core/include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h index 103dce5dd3..642e816c15 100644 --- a/core/include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h +++ b/core/include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h @@ -53,9 +53,9 @@ typedef struct ten_go_ten_env_t { ten_rwlock_t *lock; } ten_go_ten_env_t; -typedef struct ten_go_callback_info_t { +typedef struct ten_go_callback_ctx_t { ten_go_handle_t callback_id; -} ten_go_callback_info_t; +} ten_go_callback_ctx_t; extern void tenGoOnCmdResult(ten_go_handle_t ten_env_bridge, ten_go_handle_t cmd_result_bridge, @@ -66,11 +66,11 @@ extern void tenGoOnError(ten_go_handle_t ten_env_bridge, ten_go_handle_t error_handler, ten_go_error_t cgo_error); -TEN_RUNTIME_PRIVATE_API ten_go_callback_info_t *ten_go_callback_info_create( +TEN_RUNTIME_PRIVATE_API ten_go_callback_ctx_t *ten_go_callback_ctx_create( ten_go_handle_t handler_id); -TEN_RUNTIME_PRIVATE_API void ten_go_callback_info_destroy( - ten_go_callback_info_t *self); +TEN_RUNTIME_PRIVATE_API void ten_go_callback_ctx_destroy( + ten_go_callback_ctx_t *self); TEN_RUNTIME_PRIVATE_API void proxy_send_xxx_callback( ten_env_t *ten_env, ten_shared_ptr_t *cmd_result, void *callback_info, diff --git a/core/include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h b/core/include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h index b7e04582d1..e3be4eaddd 100644 --- a/core/include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h +++ b/core/include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h @@ -32,32 +32,31 @@ typedef struct ten_nodejs_ten_env_t { ten_env_proxy_t *c_ten_env_proxy; } ten_nodejs_ten_env_t; -typedef struct ten_nodejs_get_property_call_info_t { +typedef struct ten_nodejs_get_property_call_ctx_t { ten_nodejs_tsfn_t *cb_tsfn; ten_value_t *value; ten_error_t *error; -} ten_nodejs_get_property_call_info_t; +} ten_nodejs_get_property_call_ctx_t; -typedef struct ten_nodejs_set_property_call_info_t { +typedef struct ten_nodejs_set_property_call_ctx_t { ten_nodejs_tsfn_t *cb_tsfn; bool success; ten_error_t *error; -} ten_nodejs_set_property_call_info_t; +} ten_nodejs_set_property_call_ctx_t; -TEN_RUNTIME_PRIVATE_API ten_nodejs_get_property_call_info_t * -ten_nodejs_get_property_call_info_create(ten_nodejs_tsfn_t *cb_tsfn, - ten_value_t *value, - ten_error_t *error); +TEN_RUNTIME_PRIVATE_API ten_nodejs_get_property_call_ctx_t * +ten_nodejs_get_property_call_ctx_create(ten_nodejs_tsfn_t *cb_tsfn, + ten_value_t *value, ten_error_t *error); -TEN_RUNTIME_PRIVATE_API void ten_nodejs_get_property_call_info_destroy( - ten_nodejs_get_property_call_info_t *info); +TEN_RUNTIME_PRIVATE_API void ten_nodejs_get_property_call_ctx_destroy( + ten_nodejs_get_property_call_ctx_t *ctx); -TEN_RUNTIME_PRIVATE_API ten_nodejs_set_property_call_info_t * -ten_nodejs_set_property_call_info_create(ten_nodejs_tsfn_t *cb_tsfn, - bool success, ten_error_t *error); +TEN_RUNTIME_PRIVATE_API ten_nodejs_set_property_call_ctx_t * +ten_nodejs_set_property_call_ctx_create(ten_nodejs_tsfn_t *cb_tsfn, + bool success, ten_error_t *error); -TEN_RUNTIME_PRIVATE_API void ten_nodejs_set_property_call_info_destroy( - ten_nodejs_set_property_call_info_t *info); +TEN_RUNTIME_PRIVATE_API void ten_nodejs_set_property_call_ctx_destroy( + ten_nodejs_set_property_call_ctx_t *ctx); TEN_RUNTIME_API napi_value ten_nodejs_ten_env_module_init(napi_env env, napi_value exports); diff --git a/core/include_internal/ten_runtime/engine/internal/remote_interface.h b/core/include_internal/ten_runtime/engine/internal/remote_interface.h index 2017e32177..3f8b5b45c3 100644 --- a/core/include_internal/ten_runtime/engine/internal/remote_interface.h +++ b/core/include_internal/ten_runtime/engine/internal/remote_interface.h @@ -20,10 +20,10 @@ typedef void (*ten_engine_on_remote_created_cb_t)(ten_engine_t *engine, typedef void (*ten_engine_on_connected_to_graph_remote_cb_t)( ten_engine_t *engine, bool success, void *user_data); -typedef struct ten_engine_on_protocol_created_info_t { +typedef struct ten_engine_on_protocol_created_ctx_t { ten_engine_on_remote_created_cb_t cb; void *user_data; -} ten_engine_on_protocol_created_info_t; +} ten_engine_on_protocol_created_ctx_t; TEN_RUNTIME_PRIVATE_API void ten_engine_upgrade_weak_remote_to_normal_remote( ten_engine_t *self, ten_remote_t *remote); diff --git a/core/include_internal/ten_runtime/engine/on_xxx.h b/core/include_internal/ten_runtime/engine/on_xxx.h index 1c27f3b142..60bf2a48ad 100644 --- a/core/include_internal/ten_runtime/engine/on_xxx.h +++ b/core/include_internal/ten_runtime/engine/on_xxx.h @@ -15,10 +15,10 @@ typedef struct ten_engine_t ten_engine_t; typedef struct ten_extension_thread_t ten_extension_thread_t; typedef struct ten_protocol_t ten_protocol_t; -typedef struct ten_engine_thread_on_addon_create_protocol_done_info_t { +typedef struct ten_engine_thread_on_addon_create_protocol_done_ctx_t { ten_protocol_t *protocol; ten_addon_context_t *addon_context; -} ten_engine_thread_on_addon_create_protocol_done_info_t; +} ten_engine_thread_on_addon_create_protocol_done_ctx_t; TEN_RUNTIME_PRIVATE_API void ten_engine_find_extension_info_for_all_extensions_of_extension_thread( @@ -33,8 +33,8 @@ TEN_RUNTIME_PRIVATE_API void ten_engine_on_addon_create_extension_group_done( TEN_RUNTIME_PRIVATE_API void ten_engine_on_addon_destroy_extension_group_done( void *self_, void *arg); -TEN_RUNTIME_PRIVATE_API ten_engine_thread_on_addon_create_protocol_done_info_t * -ten_engine_thread_on_addon_create_protocol_done_info_create(void); +TEN_RUNTIME_PRIVATE_API ten_engine_thread_on_addon_create_protocol_done_ctx_t * +ten_engine_thread_on_addon_create_protocol_done_ctx_create(void); TEN_RUNTIME_PRIVATE_API void ten_engine_thread_on_addon_create_protocol_done( void *self, void *arg); diff --git a/core/include_internal/ten_runtime/extension_context/ten_env/on_xxx.h b/core/include_internal/ten_runtime/extension_context/ten_env/on_xxx.h index 94d39fe3ae..8b0a6c3682 100644 --- a/core/include_internal/ten_runtime/extension_context/ten_env/on_xxx.h +++ b/core/include_internal/ten_runtime/extension_context/ten_env/on_xxx.h @@ -13,16 +13,16 @@ typedef struct ten_env_t ten_env_t; typedef struct - ten_extension_context_on_addon_create_extension_group_done_info_t { + ten_extension_context_on_addon_create_extension_group_done_ctx_t { ten_extension_group_t *extension_group; ten_addon_context_t *addon_context; -} ten_extension_context_on_addon_create_extension_group_done_info_t; +} ten_extension_context_on_addon_create_extension_group_done_ctx_t; -ten_extension_context_on_addon_create_extension_group_done_info_t * -ten_extension_context_on_addon_create_extension_group_done_info_create(void); +ten_extension_context_on_addon_create_extension_group_done_ctx_t * +ten_extension_context_on_addon_create_extension_group_done_ctx_create(void); -void ten_extension_context_on_addon_create_extension_group_done_info_destroy( - ten_extension_context_on_addon_create_extension_group_done_info_t *self); +void ten_extension_context_on_addon_create_extension_group_done_ctx_destroy( + ten_extension_context_on_addon_create_extension_group_done_ctx_t *self); TEN_RUNTIME_PRIVATE_API void ten_extension_context_on_addon_create_extension_group_done( diff --git a/core/include_internal/ten_runtime/extension_thread/on_xxx.h b/core/include_internal/ten_runtime/extension_thread/on_xxx.h index 239ccf56f6..b602bc1c95 100644 --- a/core/include_internal/ten_runtime/extension_thread/on_xxx.h +++ b/core/include_internal/ten_runtime/extension_thread/on_xxx.h @@ -11,17 +11,17 @@ #include "include_internal/ten_runtime/addon/addon.h" #include "include_internal/ten_runtime/extension_thread/extension_thread.h" -typedef struct ten_extension_thread_on_addon_create_extension_done_info_t { +typedef struct ten_extension_thread_on_addon_create_extension_done_ctx_t { ten_extension_t *extension; ten_addon_context_t *addon_context; -} ten_extension_thread_on_addon_create_extension_done_info_t; +} ten_extension_thread_on_addon_create_extension_done_ctx_t; -TEN_RUNTIME_PRIVATE_API ten_extension_thread_on_addon_create_extension_done_info_t * -ten_extension_thread_on_addon_create_extension_done_info_create(void); +TEN_RUNTIME_PRIVATE_API ten_extension_thread_on_addon_create_extension_done_ctx_t * +ten_extension_thread_on_addon_create_extension_done_ctx_create(void); TEN_RUNTIME_PRIVATE_API void -ten_extension_thread_on_addon_create_extension_done_info_destroy( - ten_extension_thread_on_addon_create_extension_done_info_t *self); +ten_extension_thread_on_addon_create_extension_done_ctx_destroy( + ten_extension_thread_on_addon_create_extension_done_ctx_t *self); TEN_RUNTIME_API void ten_extension_inherit_thread_ownership( ten_extension_t *self, ten_extension_thread_t *extension_thread); diff --git a/core/src/ten_runtime/addon/addon.c b/core/src/ten_runtime/addon/addon.c index 97f7898f2a..a6e8e1408e 100644 --- a/core/src/ten_runtime/addon/addon.c +++ b/core/src/ten_runtime/addon/addon.c @@ -239,16 +239,16 @@ static void ten_addon_register_internal(ten_addon_store_t *addon_store, addon_host->addon->on_init); } -ten_addon_on_create_extension_instance_info_t * -ten_addon_on_create_extension_instance_info_create( +ten_addon_on_create_extension_instance_ctx_t * +ten_addon_on_create_extension_instance_ctx_create( TEN_ADDON_TYPE addon_type, const char *addon_name, const char *instance_name, ten_env_addon_create_instance_done_cb_t cb, void *cb_data) { TEN_ASSERT(addon_name && instance_name, "Should not happen."); - ten_addon_on_create_extension_instance_info_t *self = - (ten_addon_on_create_extension_instance_info_t *)TEN_MALLOC( - sizeof(ten_addon_on_create_extension_instance_info_t)); + ten_addon_on_create_extension_instance_ctx_t *self = + (ten_addon_on_create_extension_instance_ctx_t *)TEN_MALLOC( + sizeof(ten_addon_on_create_extension_instance_ctx_t)); TEN_ASSERT(self, "Failed to allocate memory."); ten_string_init_formatted(&self->addon_name, "%s", addon_name); @@ -260,8 +260,8 @@ ten_addon_on_create_extension_instance_info_create( return self; } -void ten_addon_on_create_extension_instance_info_destroy( - ten_addon_on_create_extension_instance_info_t *self) { +void ten_addon_on_create_extension_instance_ctx_destroy( + ten_addon_on_create_extension_instance_ctx_t *self) { TEN_ASSERT(self, "Should not happen."); ten_string_deinit(&self->addon_name); @@ -270,27 +270,27 @@ void ten_addon_on_create_extension_instance_info_destroy( TEN_FREE(self); } -ten_addon_on_destroy_instance_info_t * -ten_addon_host_on_destroy_instance_info_create( +ten_addon_on_destroy_instance_ctx_t * +ten_addon_host_on_destroy_instance_ctx_create( ten_addon_host_t *self, void *instance, ten_env_addon_destroy_instance_done_cb_t cb, void *cb_data) { TEN_ASSERT(self && instance, "Should not happen."); - ten_addon_on_destroy_instance_info_t *info = - (ten_addon_on_destroy_instance_info_t *)TEN_MALLOC( - sizeof(ten_addon_on_destroy_instance_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_addon_on_destroy_instance_ctx_t *ctx = + (ten_addon_on_destroy_instance_ctx_t *)TEN_MALLOC( + sizeof(ten_addon_on_destroy_instance_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->addon_host = self; - info->instance = instance; - info->cb = cb; - info->cb_data = cb_data; + ctx->addon_host = self; + ctx->instance = instance; + ctx->cb = cb; + ctx->cb_data = cb_data; - return info; + return ctx; } -void ten_addon_on_destroy_instance_info_destroy( - ten_addon_on_destroy_instance_info_t *self) { +void ten_addon_on_destroy_instance_ctx_destroy( + ten_addon_on_destroy_instance_ctx_t *self) { TEN_ASSERT(self && self->addon_host && self->instance, "Should not happen."); TEN_FREE(self); } diff --git a/core/src/ten_runtime/addon/extension/extension.c b/core/src/ten_runtime/addon/extension/extension.c index e194e1df2c..676dc3c133 100644 --- a/core/src/ten_runtime/addon/extension/extension.c +++ b/core/src/ten_runtime/addon/extension/extension.c @@ -62,14 +62,14 @@ bool ten_addon_create_extension(ten_env_t *ten_env, const char *addon_name, addon_name, instance_name, cb, cb_data); } else { - ten_addon_on_create_extension_instance_info_t *info = - ten_addon_on_create_extension_instance_info_create( + ten_addon_on_create_extension_instance_ctx_t *ctx = + ten_addon_on_create_extension_instance_ctx_create( TEN_ADDON_TYPE_EXTENSION, addon_name, instance_name, cb, cb_data); ten_runloop_post_task_tail( ten_extension_group_get_attached_runloop(extension_group), ten_extension_thread_create_extension_instance, - extension_group->extension_thread, info); + extension_group->extension_thread, ctx); return true; } } @@ -103,9 +103,9 @@ bool ten_addon_destroy_extension(ten_env_t *ten_env, ten_extension_t *extension, return ten_addon_host_destroy_instance_async(addon_host, ten_env, extension, cb, cb_data); } else { - ten_addon_on_destroy_instance_info_t *destroy_instance_info = - ten_addon_host_on_destroy_instance_info_create(addon_host, extension, - cb, cb_data); + ten_addon_on_destroy_instance_ctx_t *destroy_instance_info = + ten_addon_host_on_destroy_instance_ctx_create(addon_host, extension, cb, + cb_data); ten_runloop_post_task_tail( ten_extension_group_get_attached_runloop(extension_group), diff --git a/core/src/ten_runtime/addon/protocol/protocol.c b/core/src/ten_runtime/addon/protocol/protocol.c index eb403b55e1..c54b85cb43 100644 --- a/core/src/ten_runtime/addon/protocol/protocol.c +++ b/core/src/ten_runtime/addon/protocol/protocol.c @@ -107,36 +107,36 @@ ten_addon_host_t *ten_addon_protocol_find(const char *protocol) { return result; } -static ten_addon_create_protocol_info_t *ten_addon_create_protocol_info_create( +static ten_addon_create_protocol_ctx_t *ten_addon_create_protocol_ctx_create( const char *uri, TEN_PROTOCOL_ROLE role, ten_env_addon_on_create_protocol_async_cb_t cb, void *user_data) { TEN_ASSERT(role > TEN_PROTOCOL_ROLE_INVALID, "Should not happen."); - ten_addon_create_protocol_info_t *info = - (ten_addon_create_protocol_info_t *)TEN_MALLOC( - sizeof(ten_addon_create_protocol_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_addon_create_protocol_ctx_t *ctx = + (ten_addon_create_protocol_ctx_t *)TEN_MALLOC( + sizeof(ten_addon_create_protocol_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); if (!uri || strlen(uri) == 0) { - ten_string_init(&info->uri); + ten_string_init(&ctx->uri); } else { - ten_string_init_formatted(&info->uri, "%s", uri); + ten_string_init_formatted(&ctx->uri, "%s", uri); } - info->role = role; - info->cb = cb; - info->user_data = user_data; + ctx->role = role; + ctx->cb = cb; + ctx->user_data = user_data; - return info; + return ctx; } -static void ten_addon_create_protocol_info_destroy( - ten_addon_create_protocol_info_t *info) { - TEN_ASSERT(info, "Should not happen."); +static void ten_addon_create_protocol_ctx_destroy( + ten_addon_create_protocol_ctx_t *ctx) { + TEN_ASSERT(ctx, "Should not happen."); - ten_string_deinit(&info->uri); + ten_string_deinit(&ctx->uri); - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_on_addon_protocol_created(ten_env_t *ten_env, void *instance, @@ -144,27 +144,27 @@ static void proxy_on_addon_protocol_created(ten_env_t *ten_env, void *instance, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_addon_create_protocol_info_t *info = - (ten_addon_create_protocol_info_t *)cb_data; - TEN_ASSERT(info, "Should not happen."); + ten_addon_create_protocol_ctx_t *ctx = + (ten_addon_create_protocol_ctx_t *)cb_data; + TEN_ASSERT(ctx, "Should not happen."); ten_protocol_t *protocol = instance; if (protocol) { ten_protocol_determine_default_property_value(protocol); - if (!ten_string_is_empty(&info->uri)) { + if (!ten_string_is_empty(&ctx->uri)) { ten_string_set_formatted(&protocol->uri, "%s", - ten_string_get_raw_str(&info->uri)); + ten_string_get_raw_str(&ctx->uri)); } - protocol->role = info->role; + protocol->role = ctx->role; } - if (info->cb) { - info->cb(ten_env, protocol, info->user_data); + if (ctx->cb) { + ctx->cb(ten_env, protocol, ctx->user_data); } - ten_addon_create_protocol_info_destroy(info); + ten_addon_create_protocol_ctx_destroy(ctx); } bool ten_addon_create_protocol_with_uri( @@ -208,20 +208,20 @@ bool ten_addon_create_protocol_with_uri( ten_string_destroy(protocol_str); - ten_addon_create_protocol_info_t *info = - ten_addon_create_protocol_info_create(uri, role, cb, user_data); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_addon_create_protocol_ctx_t *ctx = + ten_addon_create_protocol_ctx_create(uri, role, cb, user_data); + TEN_ASSERT(ctx, "Failed to allocate memory."); bool rc = ten_addon_create_instance_async(ten_env, TEN_ADDON_TYPE_PROTOCOL, ten_string_get_raw_str(&addon_host->name), ten_string_get_raw_str(&addon_host->name), - proxy_on_addon_protocol_created, info); + proxy_on_addon_protocol_created, ctx); if (!rc) { TEN_ENV_LOG_ERROR_INTERNAL(ten_env, "Failed to create protocol for %s", uri); - ten_addon_create_protocol_info_destroy(info); + ten_addon_create_protocol_ctx_destroy(ctx); if (err) { ten_error_set(err, TEN_ERRNO_GENERIC, @@ -255,17 +255,17 @@ bool ten_addon_create_protocol(ten_env_t *ten_env, const char *addon_name, TEN_LOGD("Loading protocol addon: %s", addon_name); - ten_addon_create_protocol_info_t *info = - ten_addon_create_protocol_info_create(NULL, role, cb, user_data); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_addon_create_protocol_ctx_t *ctx = + ten_addon_create_protocol_ctx_create(NULL, role, cb, user_data); + TEN_ASSERT(ctx, "Failed to allocate memory."); bool rc = ten_addon_create_instance_async( ten_env, TEN_ADDON_TYPE_PROTOCOL, addon_name, instance_name, - proxy_on_addon_protocol_created, info); + proxy_on_addon_protocol_created, ctx); if (!rc) { TEN_LOGE("Failed to create protocol for %s", addon_name); - ten_addon_create_protocol_info_destroy(info); + ten_addon_create_protocol_ctx_destroy(ctx); if (err) { ten_error_set(err, TEN_ERRNO_GENERIC, diff --git a/core/src/ten_runtime/addon/ten_env/on_xxx.c b/core/src/ten_runtime/addon/ten_env/on_xxx.c index f979cd26aa..e13d343602 100644 --- a/core/src/ten_runtime/addon/ten_env/on_xxx.c +++ b/core/src/ten_runtime/addon/ten_env/on_xxx.c @@ -186,16 +186,16 @@ static void ten_extension_addon_on_create_instance_done(ten_env_t *self, ten_extension_thread_check_integrity(extension_thread, false), "Should not happen."); - ten_extension_thread_on_addon_create_extension_done_info_t *info = - ten_extension_thread_on_addon_create_extension_done_info_create(); + ten_extension_thread_on_addon_create_extension_done_ctx_t *ctx = + ten_extension_thread_on_addon_create_extension_done_ctx_create(); - info->extension = extension; - info->addon_context = addon_context; + ctx->extension = extension; + ctx->addon_context = addon_context; ten_runloop_post_task_tail( ten_extension_group_get_attached_runloop(extension_group), ten_extension_thread_on_addon_create_extension_done, extension_thread, - info); + ctx); break; } @@ -250,15 +250,15 @@ static void ten_extension_group_addon_on_create_instance_done(ten_env_t *self, // main thread), and all the function calls in this case are thread safe. ten_engine_check_integrity(engine, false); - ten_extension_context_on_addon_create_extension_group_done_info_t *info = - ten_extension_context_on_addon_create_extension_group_done_info_create(); + ten_extension_context_on_addon_create_extension_group_done_ctx_t *ctx = + ten_extension_context_on_addon_create_extension_group_done_ctx_create(); - info->extension_group = extension_group; - info->addon_context = addon_context; + ctx->extension_group = extension_group; + ctx->addon_context = addon_context; ten_runloop_post_task_tail( ten_engine_get_attached_runloop(engine), - ten_engine_on_addon_create_extension_group_done, engine, info); + ten_engine_on_addon_create_extension_group_done, engine, ctx); break; } @@ -314,15 +314,15 @@ static void ten_protocol_addon_on_create_instance_done(ten_env_t *self, TEN_ASSERT(engine && ten_engine_check_integrity(engine, true), "Should not happen."); - ten_engine_thread_on_addon_create_protocol_done_info_t *info = - ten_engine_thread_on_addon_create_protocol_done_info_create(); + ten_engine_thread_on_addon_create_protocol_done_ctx_t *ctx = + ten_engine_thread_on_addon_create_protocol_done_ctx_create(); - info->protocol = protocol; - info->addon_context = addon_context; + ctx->protocol = protocol; + ctx->addon_context = addon_context; ten_runloop_post_task_tail( ten_engine_get_attached_runloop(engine), - ten_engine_thread_on_addon_create_protocol_done, engine, info); + ten_engine_thread_on_addon_create_protocol_done, engine, ctx); break; } @@ -331,15 +331,15 @@ static void ten_protocol_addon_on_create_instance_done(ten_env_t *self, TEN_ASSERT(app && ten_app_check_integrity(app, true), "Should not happen."); - ten_app_thread_on_addon_create_protocol_done_info_t *info = - ten_app_thread_on_addon_create_protocol_done_info_create(); + ten_app_thread_on_addon_create_protocol_done_ctx_t *ctx = + ten_app_thread_on_addon_create_protocol_done_ctx_create(); - info->protocol = instance; - info->addon_context = addon_context; + ctx->protocol = instance; + ctx->addon_context = addon_context; ten_runloop_post_task_tail(ten_app_get_attached_runloop(app), ten_app_thread_on_addon_create_protocol_done, - app, info); + app, ctx); break; } @@ -388,15 +388,15 @@ static void ten_addon_loader_addon_on_create_instance_done(ten_env_t *self, TEN_ASSERT(app && ten_app_check_integrity(app, true), "Should not happen."); - ten_app_thread_on_addon_create_addon_loader_done_info_t *info = - ten_app_thread_on_addon_create_addon_loader_done_info_create(); + ten_app_thread_on_addon_create_addon_loader_done_ctx_t *ctx = + ten_app_thread_on_addon_create_addon_loader_done_ctx_create(); - info->addon_loader = instance; - info->addon_context = addon_context; + ctx->addon_loader = instance; + ctx->addon_context = addon_context; ten_runloop_post_task_tail( ten_app_get_attached_runloop(app), - ten_app_thread_on_addon_create_addon_loader_done, app, info); + ten_app_thread_on_addon_create_addon_loader_done, app, ctx); break; } diff --git a/core/src/ten_runtime/app/on_xxx.c b/core/src/ten_runtime/app/on_xxx.c index 4a5ef3e17d..ca8dfcb851 100644 --- a/core/src/ten_runtime/app/on_xxx.c +++ b/core/src/ten_runtime/app/on_xxx.c @@ -11,10 +11,10 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/memory.h" -ten_app_thread_on_addon_create_protocol_done_info_t * -ten_app_thread_on_addon_create_protocol_done_info_create(void) { - ten_app_thread_on_addon_create_protocol_done_info_t *self = - TEN_MALLOC(sizeof(ten_app_thread_on_addon_create_protocol_done_info_t)); +ten_app_thread_on_addon_create_protocol_done_ctx_t * +ten_app_thread_on_addon_create_protocol_done_ctx_create(void) { + ten_app_thread_on_addon_create_protocol_done_ctx_t *self = + TEN_MALLOC(sizeof(ten_app_thread_on_addon_create_protocol_done_ctx_t)); self->protocol = NULL; self->addon_context = NULL; @@ -22,8 +22,8 @@ ten_app_thread_on_addon_create_protocol_done_info_create(void) { return self; } -static void ten_app_thread_on_addon_create_protocol_done_info_destroy( - ten_app_thread_on_addon_create_protocol_done_info_t *self) { +static void ten_app_thread_on_addon_create_protocol_done_ctx_destroy( + ten_app_thread_on_addon_create_protocol_done_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); TEN_FREE(self); } @@ -32,12 +32,12 @@ void ten_app_thread_on_addon_create_protocol_done(void *self, void *arg) { ten_app_t *app = (ten_app_t *)self; TEN_ASSERT(app && ten_app_check_integrity(app, true), "Invalid argument."); - ten_app_thread_on_addon_create_protocol_done_info_t *info = - (ten_app_thread_on_addon_create_protocol_done_info_t *)arg; - TEN_ASSERT(info, "Invalid argument."); + ten_app_thread_on_addon_create_protocol_done_ctx_t *ctx = + (ten_app_thread_on_addon_create_protocol_done_ctx_t *)arg; + TEN_ASSERT(ctx, "Invalid argument."); - ten_protocol_t *protocol = info->protocol; - ten_addon_context_t *addon_context = info->addon_context; + ten_protocol_t *protocol = ctx->protocol; + ten_addon_context_t *addon_context = ctx->addon_context; TEN_ASSERT(addon_context, "Invalid argument."); @@ -47,13 +47,13 @@ void ten_app_thread_on_addon_create_protocol_done(void *self, void *arg) { } ten_addon_context_destroy(addon_context); - ten_app_thread_on_addon_create_protocol_done_info_destroy(info); + ten_app_thread_on_addon_create_protocol_done_ctx_destroy(ctx); } -ten_app_thread_on_addon_create_addon_loader_done_info_t * -ten_app_thread_on_addon_create_addon_loader_done_info_create(void) { - ten_app_thread_on_addon_create_addon_loader_done_info_t *self = TEN_MALLOC( - sizeof(ten_app_thread_on_addon_create_addon_loader_done_info_t)); +ten_app_thread_on_addon_create_addon_loader_done_ctx_t * +ten_app_thread_on_addon_create_addon_loader_done_ctx_create(void) { + ten_app_thread_on_addon_create_addon_loader_done_ctx_t *self = TEN_MALLOC( + sizeof(ten_app_thread_on_addon_create_addon_loader_done_ctx_t)); TEN_ASSERT(self, "Failed to allocate memory."); self->addon_loader = NULL; @@ -62,8 +62,8 @@ ten_app_thread_on_addon_create_addon_loader_done_info_create(void) { return self; } -static void ten_app_thread_on_addon_create_addon_loader_done_info_destroy( - ten_app_thread_on_addon_create_addon_loader_done_info_t *self) { +static void ten_app_thread_on_addon_create_addon_loader_done_ctx_destroy( + ten_app_thread_on_addon_create_addon_loader_done_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); TEN_FREE(self); } @@ -72,12 +72,12 @@ void ten_app_thread_on_addon_create_addon_loader_done(void *self, void *arg) { ten_app_t *app = (ten_app_t *)self; TEN_ASSERT(app && ten_app_check_integrity(app, true), "Invalid argument."); - ten_app_thread_on_addon_create_addon_loader_done_info_t *info = - (ten_app_thread_on_addon_create_addon_loader_done_info_t *)arg; - TEN_ASSERT(info, "Invalid argument."); + ten_app_thread_on_addon_create_addon_loader_done_ctx_t *ctx = + (ten_app_thread_on_addon_create_addon_loader_done_ctx_t *)arg; + TEN_ASSERT(ctx, "Invalid argument."); - ten_addon_loader_t *addon_loader = info->addon_loader; - ten_addon_context_t *addon_context = info->addon_context; + ten_addon_loader_t *addon_loader = ctx->addon_loader; + ten_addon_context_t *addon_context = ctx->addon_context; TEN_ASSERT(addon_context, "Invalid argument."); @@ -88,5 +88,5 @@ void ten_app_thread_on_addon_create_addon_loader_done(void *self, void *arg) { } ten_addon_context_destroy(addon_context); - ten_app_thread_on_addon_create_addon_loader_done_info_destroy(info); + ten_app_thread_on_addon_create_addon_loader_done_ctx_destroy(ctx); } 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 262201fc26..0fc7a60958 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 @@ -25,34 +25,34 @@ #include "ten_utils/value/value.h" #include "ten_utils/value/value_get.h" -typedef struct ten_env_notify_get_property_info_t { +typedef struct ten_env_notify_get_property_ctx_t { ten_string_t path; ten_value_t *c_value; ten_event_t *completed; -} ten_env_notify_get_property_info_t; +} ten_env_notify_get_property_ctx_t; -static ten_env_notify_get_property_info_t * -ten_env_notify_get_property_info_create(const void *path, int path_len) { - ten_env_notify_get_property_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_get_property_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_get_property_ctx_t * +ten_env_notify_get_property_ctx_create(const void *path, int path_len) { + ten_env_notify_get_property_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_get_property_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_formatted(&info->path, "%.*s", path_len, path); - info->c_value = NULL; - info->completed = ten_event_create(0, 1); + ten_string_init_formatted(&ctx->path, "%.*s", path_len, path); + ctx->c_value = NULL; + ctx->completed = ten_event_create(0, 1); - return info; + return ctx; } -static void ten_env_notify_get_property_info_destroy( - ten_env_notify_get_property_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_get_property_ctx_destroy( + ten_env_notify_get_property_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_string_deinit(&info->path); - info->c_value = NULL; - ten_event_destroy(info->completed); + ten_string_deinit(&ctx->path); + ctx->c_value = NULL; + ten_event_destroy(ctx->completed); - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, @@ -61,8 +61,8 @@ static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_get_property_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_get_property_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); @@ -90,14 +90,14 @@ static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, // on the same `ten_value_t*` might happen in parallel. ten_value_t *c_value = - ten_env_peek_property(ten_env, ten_string_get_raw_str(&info->path), &err); + ten_env_peek_property(ten_env, ten_string_get_raw_str(&ctx->path), &err); // Because this value will be passed out of the TEN world and back into the // GO world, and these two worlds are in different threads, copy semantics are // used to avoid thread safety issues. - info->c_value = c_value ? ten_value_clone(c_value) : NULL; + ctx->c_value = c_value ? ten_value_clone(c_value) : NULL; - ten_event_set(info->completed); + ten_event_set(ctx->completed); ten_error_deinit(&err); } @@ -114,11 +114,11 @@ static ten_value_t *ten_go_ten_env_get_property_and_check_if_exists( ten_error_t err; ten_error_init(&err); - ten_env_notify_get_property_info_t *info = - ten_env_notify_get_property_info_create(path, path_len); + ten_env_notify_get_property_ctx_t *ctx = + ten_env_notify_get_property_ctx_create(path, path_len); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_get_property, info, false, + ten_env_proxy_notify_get_property, ctx, false, &err)) { ten_go_error_from_error(status, &err); goto done; @@ -140,15 +140,15 @@ static ten_value_t *ten_go_ten_env_get_property_and_check_if_exists( // 2. The C function is always async, using a callback to notify the GO world. // There are a c-to-go call and a channel wait in GO. - ten_event_wait(info->completed, -1); - c_value = info->c_value; + ten_event_wait(ctx->completed, -1); + c_value = ctx->c_value; if (c_value == NULL) { ten_go_error_set_errno(status, TEN_ERRNO_GENERIC); } done: ten_error_deinit(&err); - ten_env_notify_get_property_info_destroy(info); + ten_env_notify_get_property_ctx_destroy(ctx); return c_value; } 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 42bfec1c6a..d951db2fc3 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 @@ -17,27 +17,27 @@ #include "ten_utils/lib/event.h" #include "ten_utils/lib/string.h" -typedef struct ten_notify_set_init_property_info_t { +typedef struct ten_notify_set_init_property_ctx_t { ten_string_t value; ten_error_t err; ten_event_t *completed; -} ten_env_notify_init_property_info_t; +} ten_env_notify_init_property_ctx_t; -static ten_env_notify_init_property_info_t * -ten_env_notify_init_property_info_create(const void *value, int value_len) { - ten_env_notify_init_property_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_init_property_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_init_property_ctx_t * +ten_env_notify_init_property_ctx_create(const void *value, int value_len) { + ten_env_notify_init_property_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_init_property_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_formatted(&info->value, "%.*s", value_len, value); - ten_error_init(&info->err); - info->completed = ten_event_create(0, 1); + ten_string_init_formatted(&ctx->value, "%.*s", value_len, value); + ten_error_init(&ctx->err); + ctx->completed = ten_event_create(0, 1); - return info; + return ctx; } -static void ten_env_notify_init_property_info_destroy( - ten_env_notify_init_property_info_t *self) { +static void ten_env_notify_init_property_ctx_destroy( + ten_env_notify_init_property_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); ten_string_deinit(&self->value); @@ -53,16 +53,16 @@ static void ten_env_proxy_notify_init_property_from_json(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_init_property_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_init_property_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); - ten_env_init_property_from_json(ten_env, ten_string_get_raw_str(&info->value), + ten_env_init_property_from_json(ten_env, ten_string_get_raw_str(&ctx->value), &err); - ten_event_set(info->completed); + ten_event_set(ctx->completed); ten_error_deinit(&err); } @@ -81,21 +81,21 @@ ten_go_error_t ten_go_ten_env_init_property_from_json_bytes( return cgo_error; }); - ten_env_notify_init_property_info_t *info = - ten_env_notify_init_property_info_create(json_str, json_str_len); - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_init_property_ctx_t *ctx = + ten_env_notify_init_property_ctx_create(json_str, json_str_len); + TEN_ASSERT(ctx, "Should not happen."); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_init_property_from_json, info, - false, &info->err)) { + ten_env_proxy_notify_init_property_from_json, ctx, + false, &ctx->err)) { goto done; } - ten_event_wait(info->completed, -1); + ten_event_wait(ctx->completed, -1); done: - ten_go_error_from_error(&cgo_error, &info->err); - ten_env_notify_init_property_info_destroy(info); + ten_go_error_from_error(&cgo_error, &ctx->err); + ten_env_notify_init_property_ctx_destroy(ctx); TEN_GO_TEN_ENV_IS_ALIVE_REGION_END(self); ten_is_close: diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_internal.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_internal.c index 64ceb2ffb0..5670914842 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_internal.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_internal.c @@ -17,18 +17,17 @@ #include "ten_utils/lib/alloc.h" #include "ten_utils/macro/check.h" -ten_go_callback_info_t *ten_go_callback_info_create( - ten_go_handle_t handler_id) { - ten_go_callback_info_t *info = - (ten_go_callback_info_t *)TEN_MALLOC(sizeof(ten_go_callback_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +ten_go_callback_ctx_t *ten_go_callback_ctx_create(ten_go_handle_t handler_id) { + ten_go_callback_ctx_t *ctx = + (ten_go_callback_ctx_t *)TEN_MALLOC(sizeof(ten_go_callback_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->callback_id = handler_id; + ctx->callback_id = handler_id; - return info; + return ctx; } -void ten_go_callback_info_destroy(ten_go_callback_info_t *self) { +void ten_go_callback_ctx_destroy(ten_go_callback_ctx_t *self) { TEN_ASSERT(self, "Should not happen."); TEN_FREE(self); @@ -44,7 +43,7 @@ void proxy_send_xxx_callback(ten_env_t *ten_env, ten_shared_ptr_t *cmd_result, ten_go_ten_env_t *ten_env_bridge = ten_go_ten_env_wrap(ten_env); ten_go_handle_t handler_id = - ((ten_go_callback_info_t *)callback_info)->callback_id; + ((ten_go_callback_ctx_t *)callback_info)->callback_id; // Same as Extension::OnCmd, the GO cmd result is only used for the GO // extension, so it can be created in GO world. We do not need to call GO @@ -63,5 +62,5 @@ void proxy_send_xxx_callback(ten_env_t *ten_env, ten_shared_ptr_t *cmd_result, tenGoOnCmdResult(ten_env_bridge->bridge.go_instance, cmd_result_bridge_addr, handler_id, cgo_error); - ten_go_callback_info_destroy(callback_info); + ten_go_callback_ctx_destroy(callback_info); } 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 8e4e175781..3945ea87a8 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 @@ -18,7 +18,7 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_log_info_t { +typedef struct ten_env_notify_log_ctx_t { int32_t level; const char *func_name; size_t func_name_len; @@ -28,35 +28,34 @@ typedef struct ten_env_notify_log_info_t { const char *msg; size_t msg_len; ten_event_t *completed; -} ten_env_notify_log_info_t; +} ten_env_notify_log_ctx_t; -static ten_env_notify_log_info_t *ten_env_notify_log_info_create( +static ten_env_notify_log_ctx_t *ten_env_notify_log_ctx_create( int32_t level, const char *func_name, size_t func_name_len, const char *file_name, size_t file_name_len, size_t line_no, const char *msg, size_t msg_len) { - ten_env_notify_log_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_log_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); - - info->level = level; - info->func_name = func_name; - info->func_name_len = func_name_len; - info->file_name = file_name; - info->file_name_len = file_name_len; - info->line_no = line_no; - info->msg = msg; - info->msg_len = msg_len; - info->completed = ten_event_create(0, 1); - - return info; + ten_env_notify_log_ctx_t *ctx = TEN_MALLOC(sizeof(ten_env_notify_log_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); + + ctx->level = level; + ctx->func_name = func_name; + ctx->func_name_len = func_name_len; + ctx->file_name = file_name; + ctx->file_name_len = file_name_len; + ctx->line_no = line_no; + ctx->msg = msg; + ctx->msg_len = msg_len; + ctx->completed = ten_event_create(0, 1); + + return ctx; } -static void ten_env_notify_log_info_destroy(ten_env_notify_log_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_log_ctx_destroy(ten_env_notify_log_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_event_destroy(info->completed); + ten_event_destroy(ctx->completed); - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_log(ten_env_t *ten_env, void *user_data) { @@ -64,15 +63,14 @@ static void ten_env_proxy_notify_log(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_log_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_log_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_env_log_with_size_formatted(ten_env, info->level, info->func_name, - info->func_name_len, info->file_name, - info->file_name_len, info->line_no, "%.*s", - info->msg_len, info->msg); + ten_env_log_with_size_formatted( + ten_env, ctx->level, ctx->func_name, ctx->func_name_len, ctx->file_name, + ctx->file_name_len, ctx->line_no, "%.*s", ctx->msg_len, ctx->msg); - ten_event_set(info->completed); + ten_event_set(ctx->completed); } void ten_go_ten_env_log(uintptr_t bridge_addr, int level, const void *func_name, @@ -101,7 +99,7 @@ void ten_go_ten_env_log(uintptr_t bridge_addr, int level, const void *func_name, msg_value = (const char *)msg; } - ten_env_notify_log_info_t *info = ten_env_notify_log_info_create( + ten_env_notify_log_ctx_t *ctx = ten_env_notify_log_ctx_create( level, func_name_value, func_name_len, file_name_value, file_name_len, line_no, msg_value, msg_len); @@ -116,18 +114,18 @@ void ten_go_ten_env_log(uintptr_t bridge_addr, int level, const void *func_name, // completely removed, and comprehensive thread safety checking can be // implemented. ten_env_log_with_size_formatted_without_check_thread( - self->c_ten_env, info->level, info->func_name, info->func_name_len, - info->file_name, info->file_name_len, info->line_no, "%.*s", - info->msg_len, info->msg); + self->c_ten_env, ctx->level, ctx->func_name, ctx->func_name_len, + ctx->file_name, ctx->file_name_len, ctx->line_no, "%.*s", ctx->msg_len, + ctx->msg); } else { if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_proxy_notify_log, - info, false, &err)) { + ctx, false, &err)) { goto done; } - ten_event_wait(info->completed, -1); + ten_event_wait(ctx->completed, -1); } done: ten_error_deinit(&err); - ten_env_notify_log_info_destroy(info); + ten_env_notify_log_ctx_destroy(ctx); } 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 ab6c08cd63..2a20a718b5 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 @@ -21,46 +21,46 @@ #include "ten_utils/lib/error.h" #include "ten_utils/macro/check.h" -typedef struct ten_env_notify_return_result_info_t { +typedef struct ten_env_notify_return_result_ctx_t { ten_shared_ptr_t *c_cmd; ten_shared_ptr_t *c_target_cmd; ten_go_handle_t handler_id; -} ten_env_notify_return_result_info_t; +} ten_env_notify_return_result_ctx_t; -static ten_env_notify_return_result_info_t * -ten_env_notify_return_result_info_create(ten_shared_ptr_t *c_cmd, - ten_shared_ptr_t *c_target_cmd, - ten_go_handle_t handler_id) { +static ten_env_notify_return_result_ctx_t * +ten_env_notify_return_result_ctx_create(ten_shared_ptr_t *c_cmd, + ten_shared_ptr_t *c_target_cmd, + ten_go_handle_t handler_id) { TEN_ASSERT(c_cmd, "Invalid argument."); - ten_env_notify_return_result_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_return_result_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_return_result_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_return_result_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_cmd = c_cmd; - info->c_target_cmd = c_target_cmd; - info->handler_id = handler_id; + ctx->c_cmd = c_cmd; + ctx->c_target_cmd = c_target_cmd; + ctx->handler_id = handler_id; - return info; + return ctx; } -static void ten_env_notify_return_result_info_destroy( - ten_env_notify_return_result_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_return_result_ctx_destroy( + ten_env_notify_return_result_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_cmd) { - ten_shared_ptr_destroy(info->c_cmd); - info->c_cmd = NULL; + if (ctx->c_cmd) { + ten_shared_ptr_destroy(ctx->c_cmd); + ctx->c_cmd = NULL; } - if (info->c_target_cmd) { - ten_shared_ptr_destroy(info->c_target_cmd); - info->c_target_cmd = NULL; + if (ctx->c_target_cmd) { + ten_shared_ptr_destroy(ctx->c_target_cmd); + ctx->c_target_cmd = NULL; } - info->handler_id = 0; + ctx->handler_id = 0; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_handle_return_error(ten_env_t *ten_env, void *user_data, @@ -68,7 +68,7 @@ static void proxy_handle_return_error(ten_env_t *ten_env, void *user_data, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_go_callback_info_t *callback_info = user_data; + ten_go_callback_ctx_t *callback_info = user_data; TEN_ASSERT(callback_info, "Should not happen."); ten_go_error_t cgo_error; @@ -86,7 +86,7 @@ static void proxy_handle_return_error(ten_env_t *ten_env, void *user_data, tenGoOnError(ten_env_bridge->bridge.go_instance, callback_info->callback_id, cgo_error); - ten_go_callback_info_destroy(callback_info); + ten_go_callback_ctx_destroy(callback_info); } static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, @@ -95,8 +95,8 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_return_result_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_return_result_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_go_error_t cgo_error; ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); @@ -105,26 +105,26 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, ten_error_init(&err); bool rc = false; - if (info->handler_id == TEN_GO_NO_RESPONSE_HANDLER) { - if (info->c_target_cmd) { - rc = ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, NULL, + if (ctx->handler_id == TEN_GO_NO_RESPONSE_HANDLER) { + if (ctx->c_target_cmd) { + rc = ten_env_return_result(ten_env, ctx->c_cmd, ctx->c_target_cmd, NULL, NULL, &err); TEN_ASSERT(rc, "Should not happen."); } else { - rc = ten_env_return_result_directly(ten_env, info->c_cmd, NULL, NULL, - &err); + rc = + ten_env_return_result_directly(ten_env, ctx->c_cmd, NULL, NULL, &err); TEN_ASSERT(rc, "Should not happen."); } } else { - ten_go_callback_info_t *callback_info = - ten_go_callback_info_create(info->handler_id); - if (info->c_target_cmd) { + ten_go_callback_ctx_t *callback_info = + ten_go_callback_ctx_create(ctx->handler_id); + if (ctx->c_target_cmd) { rc = - ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, + ten_env_return_result(ten_env, ctx->c_cmd, ctx->c_target_cmd, proxy_handle_return_error, callback_info, &err); } else { rc = ten_env_return_result_directly( - ten_env, info->c_cmd, proxy_handle_return_error, callback_info, &err); + ten_env, ctx->c_cmd, proxy_handle_return_error, callback_info, &err); } if (!rc) { @@ -133,16 +133,16 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, ten_go_ten_env_t *ten_env_bridge = ten_go_ten_env_wrap(ten_env); - tenGoOnError(ten_env_bridge->bridge.go_instance, info->handler_id, + tenGoOnError(ten_env_bridge->bridge.go_instance, ctx->handler_id, cgo_error); - ten_go_callback_info_destroy(callback_info); + ten_go_callback_ctx_destroy(callback_info); } } ten_error_deinit(&err); - ten_env_notify_return_result_info_destroy(info); + ten_env_notify_return_result_ctx_destroy(ctx); } ten_go_error_t ten_go_ten_env_return_result(uintptr_t bridge_addr, @@ -169,15 +169,15 @@ ten_go_error_t ten_go_ten_env_return_result(uintptr_t bridge_addr, ten_error_t err; ten_error_init(&err); - ten_env_notify_return_result_info_t *return_result_info = - ten_env_notify_return_result_info_create( + ten_env_notify_return_result_ctx_t *return_result_info = + ten_env_notify_return_result_ctx_create( ten_go_msg_move_c_msg(cmd_result), 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_proxy_notify_return_result, return_result_info, false, &err)) { - ten_env_notify_return_result_info_destroy(return_result_info); + ten_env_notify_return_result_ctx_destroy(return_result_info); ten_go_error_from_error(&cgo_error, &err); } @@ -207,15 +207,15 @@ ten_go_error_t ten_go_ten_env_return_result_directly( ten_error_t err; ten_error_init(&err); - ten_env_notify_return_result_info_t *return_result_info = - ten_env_notify_return_result_info_create( + ten_env_notify_return_result_ctx_t *return_result_info = + ten_env_notify_return_result_ctx_create( ten_go_msg_move_c_msg(cmd_result), NULL, handler_id <= 0 ? TEN_GO_NO_RESPONSE_HANDLER : handler_id); 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_env_notify_return_result_ctx_destroy(return_result_info); ten_go_error_from_error(&cgo_error, &err); } 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 9a586ee37c..7d5df13d5e 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 @@ -18,44 +18,44 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -typedef struct ten_env_notify_send_audio_frame_info_t { +typedef struct ten_env_notify_send_audio_frame_ctx_t { ten_shared_ptr_t *c_audio_frame; ten_go_handle_t callback_handle; -} ten_env_notify_send_audio_frame_info_t; +} ten_env_notify_send_audio_frame_ctx_t; -static ten_env_notify_send_audio_frame_info_t * -ten_env_notify_send_audio_frame_info_create(ten_shared_ptr_t *c_audio_frame, - ten_go_handle_t callback_handle) { +static ten_env_notify_send_audio_frame_ctx_t * +ten_env_notify_send_audio_frame_ctx_create(ten_shared_ptr_t *c_audio_frame, + ten_go_handle_t callback_handle) { TEN_ASSERT(c_audio_frame, "Invalid argument."); - ten_env_notify_send_audio_frame_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_audio_frame_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_audio_frame_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_audio_frame_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_audio_frame = c_audio_frame; - info->callback_handle = callback_handle; + ctx->c_audio_frame = c_audio_frame; + ctx->callback_handle = callback_handle; - return info; + return ctx; } -static void ten_env_notify_send_audio_frame_info_destroy( - ten_env_notify_send_audio_frame_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_audio_frame_ctx_destroy( + ten_env_notify_send_audio_frame_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_audio_frame) { - ten_shared_ptr_destroy(info->c_audio_frame); - info->c_audio_frame = NULL; + if (ctx->c_audio_frame) { + ten_shared_ptr_destroy(ctx->c_audio_frame); + ctx->c_audio_frame = NULL; } - info->callback_handle = 0; + ctx->callback_handle = 0; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_handle_audio_frame_error( ten_env_t *ten_env, TEN_UNUSED ten_shared_ptr_t *cmd_result, void *callback_info_, ten_error_t *err) { - ten_go_callback_info_t *callback_info = callback_info_; + ten_go_callback_ctx_t *callback_info = callback_info_; TEN_ASSERT(callback_info, "Should not happen."); ten_go_error_t cgo_error; @@ -73,7 +73,7 @@ static void proxy_handle_audio_frame_error( tenGoOnError(ten_env_bridge->bridge.go_instance, callback_info->callback_id, cgo_error); - ten_go_callback_info_destroy(callback_info); + ten_go_callback_ctx_destroy(callback_info); } static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, @@ -82,7 +82,7 @@ static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_audio_frame_info_t *notify_info = user_data; + ten_env_notify_send_audio_frame_ctx_t *notify_info = user_data; TEN_ASSERT(notify_info, "Should not happen."); ten_go_error_t cgo_error; @@ -97,8 +97,8 @@ static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, res = ten_env_send_audio_frame(ten_env, notify_info->c_audio_frame, NULL, NULL, &err); } else { - ten_go_callback_info_t *info = - ten_go_callback_info_create(notify_info->callback_handle); + ten_go_callback_ctx_t *ctx = + ten_go_callback_ctx_create(notify_info->callback_handle); res = ten_env_send_audio_frame(ten_env, notify_info->c_audio_frame, proxy_handle_audio_frame_error, notify_info, @@ -113,13 +113,13 @@ static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, tenGoOnError(ten_env_bridge->bridge.go_instance, notify_info->callback_handle, cgo_error); - ten_go_callback_info_destroy(info); + ten_go_callback_ctx_destroy(ctx); } } ten_error_deinit(&err); - ten_env_notify_send_audio_frame_info_destroy(notify_info); + ten_env_notify_send_audio_frame_ctx_destroy(notify_info); } ten_go_error_t ten_go_ten_env_send_audio_frame( @@ -142,15 +142,15 @@ ten_go_error_t ten_go_ten_env_send_audio_frame( ten_error_t err; ten_error_init(&err); - ten_env_notify_send_audio_frame_info_t *notify_info = - ten_env_notify_send_audio_frame_info_create( + ten_env_notify_send_audio_frame_ctx_t *notify_info = + ten_env_notify_send_audio_frame_ctx_create( ten_go_msg_move_c_msg(audio_frame), handler_id <= 0 ? TEN_GO_NO_RESPONSE_HANDLER : handler_id); if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_proxy_notify_send_audio_frame, notify_info, false, &err)) { - ten_env_notify_send_audio_frame_info_destroy(notify_info); + ten_env_notify_send_audio_frame_ctx_destroy(notify_info); ten_go_error_from_error(&cgo_error, &err); } 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 ce6ac51634..f49e14311c 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 @@ -19,39 +19,39 @@ #include "ten_utils/lib/error.h" #include "ten_utils/macro/check.h" -typedef struct ten_env_notify_send_cmd_info_t { +typedef struct ten_env_notify_send_cmd_ctx_t { ten_shared_ptr_t *c_cmd; ten_go_handle_t handler_id; bool is_ex; -} ten_env_notify_send_cmd_info_t; +} ten_env_notify_send_cmd_ctx_t; -static ten_env_notify_send_cmd_info_t *ten_env_notify_send_cmd_info_create( +static ten_env_notify_send_cmd_ctx_t *ten_env_notify_send_cmd_ctx_create( ten_shared_ptr_t *c_cmd, ten_go_handle_t handler_id, bool is_ex) { TEN_ASSERT(c_cmd, "Invalid argument."); - ten_env_notify_send_cmd_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_cmd_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_cmd_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_cmd_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_cmd = c_cmd; - info->handler_id = handler_id; - info->is_ex = is_ex; + ctx->c_cmd = c_cmd; + ctx->handler_id = handler_id; + ctx->is_ex = is_ex; - return info; + return ctx; } -static void ten_env_notify_send_cmd_info_destroy( - ten_env_notify_send_cmd_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_cmd_ctx_destroy( + ten_env_notify_send_cmd_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_cmd) { - ten_shared_ptr_destroy(info->c_cmd); - info->c_cmd = NULL; + if (ctx->c_cmd) { + ten_shared_ptr_destroy(ctx->c_cmd); + ctx->c_cmd = NULL; } - info->handler_id = 0; + ctx->handler_id = 0; - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { @@ -59,7 +59,7 @@ static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_cmd_info_t *notify_info = user_data; + ten_env_notify_send_cmd_ctx_t *notify_info = user_data; TEN_ASSERT(notify_info, "Should not happen."); ten_error_t err; @@ -76,13 +76,13 @@ static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { if (notify_info->handler_id == TEN_GO_NO_RESPONSE_HANDLER) { res = send_cmd_func(ten_env, notify_info->c_cmd, NULL, NULL, &err); } else { - ten_go_callback_info_t *info = - ten_go_callback_info_create(notify_info->handler_id); + ten_go_callback_ctx_t *ctx = + ten_go_callback_ctx_create(notify_info->handler_id); res = send_cmd_func(ten_env, notify_info->c_cmd, proxy_send_xxx_callback, - info, &err); + ctx, &err); if (!res) { - ten_go_callback_info_destroy(info); + ten_go_callback_ctx_destroy(ctx); } } @@ -101,7 +101,7 @@ static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { ten_error_deinit(&err); - ten_env_notify_send_cmd_info_destroy(notify_info); + ten_env_notify_send_cmd_ctx_destroy(notify_info); } ten_go_error_t ten_go_ten_env_send_cmd(uintptr_t bridge_addr, @@ -125,15 +125,15 @@ ten_go_error_t ten_go_ten_env_send_cmd(uintptr_t bridge_addr, ten_error_t err; ten_error_init(&err); - ten_env_notify_send_cmd_info_t *notify_info = - ten_env_notify_send_cmd_info_create( + ten_env_notify_send_cmd_ctx_t *notify_info = + ten_env_notify_send_cmd_ctx_create( ten_go_msg_move_c_msg(cmd), handler_id <= 0 ? TEN_GO_NO_RESPONSE_HANDLER : handler_id, is_ex); 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_env_notify_send_cmd_ctx_destroy(notify_info); ten_go_error_from_error(&cgo_error, &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 394f444cdd..64acbf9d56 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 @@ -22,43 +22,43 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -typedef struct ten_env_notify_send_data_info_t { +typedef struct ten_env_notify_send_data_ctx_t { ten_shared_ptr_t *c_data; ten_go_handle_t callback_handle; -} ten_env_notify_send_data_info_t; +} ten_env_notify_send_data_ctx_t; -static ten_env_notify_send_data_info_t *ten_env_notify_send_data_info_create( +static ten_env_notify_send_data_ctx_t *ten_env_notify_send_data_ctx_create( ten_shared_ptr_t *c_data, ten_go_handle_t callback_handle) { TEN_ASSERT(c_data, "Invalid argument."); - ten_env_notify_send_data_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_data_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_data_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_data_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_data = c_data; - info->callback_handle = callback_handle; + ctx->c_data = c_data; + ctx->callback_handle = callback_handle; - return info; + return ctx; } -static void ten_env_notify_send_data_info_destroy( - ten_env_notify_send_data_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_data_ctx_destroy( + ten_env_notify_send_data_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_data) { - ten_shared_ptr_destroy(info->c_data); - info->c_data = NULL; + if (ctx->c_data) { + ten_shared_ptr_destroy(ctx->c_data); + ctx->c_data = NULL; } - info->callback_handle = 0; + ctx->callback_handle = 0; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_handle_data_error(ten_env_t *ten_env, TEN_UNUSED ten_shared_ptr_t *cmd_result, void *callback_info_, ten_error_t *err) { - ten_go_callback_info_t *callback_info = callback_info_; + ten_go_callback_ctx_t *callback_info = callback_info_; TEN_ASSERT(callback_info, "Should not happen."); ten_go_error_t cgo_error; @@ -76,7 +76,7 @@ static void proxy_handle_data_error(ten_env_t *ten_env, tenGoOnError(ten_env_bridge->bridge.go_instance, callback_info->callback_id, cgo_error); - ten_go_callback_info_destroy(callback_info); + ten_go_callback_ctx_destroy(callback_info); } static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, @@ -85,7 +85,7 @@ static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_data_info_t *notify_info = user_data; + ten_env_notify_send_data_ctx_t *notify_info = user_data; TEN_ASSERT(notify_info, "Should not happen."); ten_go_error_t cgo_error; @@ -99,10 +99,10 @@ static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, if (notify_info->callback_handle == TEN_GO_NO_RESPONSE_HANDLER) { res = ten_env_send_data(ten_env, notify_info->c_data, NULL, NULL, &err); } else { - ten_go_callback_info_t *info = - ten_go_callback_info_create(notify_info->callback_handle); + ten_go_callback_ctx_t *ctx = + ten_go_callback_ctx_create(notify_info->callback_handle); res = ten_env_send_data(ten_env, notify_info->c_data, - proxy_handle_data_error, info, &err); + proxy_handle_data_error, ctx, &err); if (!res) { // Prepare error information to pass to Go. @@ -113,14 +113,14 @@ static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, tenGoOnError(ten_env_bridge->bridge.go_instance, notify_info->callback_handle, cgo_error); - ten_go_callback_info_destroy(info); + ten_go_callback_ctx_destroy(ctx); } } ten_error_deinit(&err); // The notify_info is no longer needed. - ten_env_notify_send_data_info_destroy(notify_info); + ten_env_notify_send_data_ctx_destroy(notify_info); } ten_go_error_t ten_go_ten_env_send_data(uintptr_t bridge_addr, @@ -143,8 +143,8 @@ ten_go_error_t ten_go_ten_env_send_data(uintptr_t bridge_addr, ten_error_t err; ten_error_init(&err); - ten_env_notify_send_data_info_t *notify_info = - ten_env_notify_send_data_info_create( + ten_env_notify_send_data_ctx_t *notify_info = + ten_env_notify_send_data_ctx_create( ten_go_msg_move_c_msg(data), handler_id <= 0 ? TEN_GO_NO_RESPONSE_HANDLER : handler_id); @@ -152,7 +152,7 @@ ten_go_error_t ten_go_ten_env_send_data(uintptr_t bridge_addr, ten_env_proxy_notify_send_data, notify_info, false, &err)) { // Failed to invoke ten_env_proxy_notify. - ten_env_notify_send_data_info_destroy(notify_info); + ten_env_notify_send_data_ctx_destroy(notify_info); ten_go_error_from_error(&cgo_error, &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 43d1fcb08b..753a270a30 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 @@ -20,44 +20,44 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -typedef struct ten_env_notify_send_video_frame_info_t { +typedef struct ten_env_notify_send_video_frame_ctx_t { ten_shared_ptr_t *c_video_frame; ten_go_handle_t callback_handle; -} ten_env_notify_send_video_frame_info_t; +} ten_env_notify_send_video_frame_ctx_t; -static ten_env_notify_send_video_frame_info_t * -ten_env_notify_send_video_frame_info_create(ten_shared_ptr_t *c_video_frame, - ten_go_handle_t callback_handle) { +static ten_env_notify_send_video_frame_ctx_t * +ten_env_notify_send_video_frame_ctx_create(ten_shared_ptr_t *c_video_frame, + ten_go_handle_t callback_handle) { TEN_ASSERT(c_video_frame, "Invalid argument."); - ten_env_notify_send_video_frame_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_video_frame_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_video_frame_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_video_frame_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_video_frame = c_video_frame; - info->callback_handle = callback_handle; + ctx->c_video_frame = c_video_frame; + ctx->callback_handle = callback_handle; - return info; + return ctx; } -static void ten_env_notify_send_video_frame_info_destroy( - ten_env_notify_send_video_frame_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_video_frame_ctx_destroy( + ten_env_notify_send_video_frame_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_video_frame) { - ten_shared_ptr_destroy(info->c_video_frame); - info->c_video_frame = NULL; + if (ctx->c_video_frame) { + ten_shared_ptr_destroy(ctx->c_video_frame); + ctx->c_video_frame = NULL; } - info->callback_handle = 0; + ctx->callback_handle = 0; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_handle_video_frame_error( ten_env_t *ten_env, TEN_UNUSED ten_shared_ptr_t *cmd_result, void *callback_info_, ten_error_t *err) { - ten_go_callback_info_t *callback_info = callback_info_; + ten_go_callback_ctx_t *callback_info = callback_info_; TEN_ASSERT(callback_info, "Should not happen."); ten_go_error_t cgo_error; @@ -75,7 +75,7 @@ static void proxy_handle_video_frame_error( tenGoOnError(ten_env_bridge->bridge.go_instance, callback_info->callback_id, cgo_error); - ten_go_callback_info_destroy(callback_info); + ten_go_callback_ctx_destroy(callback_info); } static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, @@ -84,7 +84,7 @@ static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_video_frame_info_t *notify_info = user_video_frame; + ten_env_notify_send_video_frame_ctx_t *notify_info = user_video_frame; TEN_ASSERT(notify_info, "Should not happen."); ten_go_error_t cgo_error; @@ -99,10 +99,10 @@ static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, res = ten_env_send_video_frame(ten_env, notify_info->c_video_frame, NULL, NULL, &err); } else { - ten_go_callback_info_t *info = - ten_go_callback_info_create(notify_info->callback_handle); + ten_go_callback_ctx_t *ctx = + ten_go_callback_ctx_create(notify_info->callback_handle); res = ten_env_send_video_frame(ten_env, notify_info->c_video_frame, - proxy_handle_video_frame_error, info, &err); + proxy_handle_video_frame_error, ctx, &err); if (!res) { // Prepare error information to pass to Go. @@ -113,13 +113,13 @@ static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, tenGoOnError(ten_env_bridge->bridge.go_instance, notify_info->callback_handle, cgo_error); - ten_go_callback_info_destroy(info); + ten_go_callback_ctx_destroy(ctx); } } ten_error_deinit(&err); - ten_env_notify_send_video_frame_info_destroy(notify_info); + ten_env_notify_send_video_frame_ctx_destroy(notify_info); } ten_go_error_t ten_go_ten_env_send_video_frame( @@ -142,15 +142,15 @@ ten_go_error_t ten_go_ten_env_send_video_frame( ten_error_t err; ten_error_init(&err); - ten_env_notify_send_video_frame_info_t *notify_info = - ten_env_notify_send_video_frame_info_create( + ten_env_notify_send_video_frame_ctx_t *notify_info = + ten_env_notify_send_video_frame_ctx_create( ten_go_msg_move_c_msg(video_frame), handler_id <= 0 ? TEN_GO_NO_RESPONSE_HANDLER : handler_id); if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_proxy_notify_send_video_frame, notify_info, false, &err)) { - ten_env_notify_send_video_frame_info_destroy(notify_info); + ten_env_notify_send_video_frame_ctx_destroy(notify_info); ten_go_error_from_error(&cgo_error, &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 08085a46a0..48e18afebe 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 @@ -23,38 +23,38 @@ #include "ten_utils/macro/check.h" #include "ten_utils/value/value.h" -typedef struct ten_env_notify_set_property_info_t { +typedef struct ten_env_notify_set_property_ctx_t { ten_string_t path; ten_value_t *c_value; uintptr_t callback_handle; -} ten_env_notify_set_property_info_t; +} ten_env_notify_set_property_ctx_t; -static ten_env_notify_set_property_info_t * -ten_env_notify_set_property_info_create(const void *path, int path_len, - ten_value_t *value, - uintptr_t callback_handle) { - ten_env_notify_set_property_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_set_property_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_set_property_ctx_t * +ten_env_notify_set_property_ctx_create(const void *path, int path_len, + ten_value_t *value, + uintptr_t callback_handle) { + ten_env_notify_set_property_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_set_property_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_formatted(&info->path, "%.*s", path_len, path); - info->c_value = value; - info->callback_handle = callback_handle; + ten_string_init_formatted(&ctx->path, "%.*s", path_len, path); + ctx->c_value = value; + ctx->callback_handle = callback_handle; - return info; + return ctx; } -static void ten_env_notify_set_property_info_destroy( - ten_env_notify_set_property_info_t *self) { - TEN_ASSERT(self, "Invalid argument."); +static void ten_env_notify_set_property_ctx_destroy( + ten_env_notify_set_property_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_string_deinit(&self->path); - if (self->c_value) { - ten_value_destroy(self->c_value); - self->c_value = NULL; + ten_string_deinit(&ctx->path); + if (ctx->c_value) { + ten_value_destroy(ctx->c_value); + ctx->c_value = NULL; } - TEN_FREE(self); + TEN_FREE(ctx); } static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, @@ -63,8 +63,8 @@ static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_set_property_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_set_property_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_go_error_t cgo_error; ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); @@ -72,23 +72,23 @@ static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, ten_error_t err; ten_error_init(&err); - bool res = ten_env_set_property(ten_env, ten_string_get_raw_str(&info->path), - info->c_value, &err); + bool res = ten_env_set_property(ten_env, ten_string_get_raw_str(&ctx->path), + ctx->c_value, &err); if (res) { // The ownership of the C value has been successfully transferred to the TEN // runtime. - info->c_value = NULL; + ctx->c_value = NULL; } else { // Prepare error information to pass to Go. ten_go_error_from_error(&cgo_error, &err); } // Call back into Go to signal that the async operation in C is complete. - tenGoCAsyncApiCallback(info->callback_handle, cgo_error); + tenGoCAsyncApiCallback(ctx->callback_handle, cgo_error); ten_error_deinit(&err); - ten_env_notify_set_property_info_destroy(info); + ten_env_notify_set_property_ctx_destroy(ctx); } static ten_go_error_t ten_go_ten_env_set_property(ten_go_ten_env_t *self, @@ -111,15 +111,15 @@ static ten_go_error_t ten_go_ten_env_set_property(ten_go_ten_env_t *self, ten_error_t err; ten_error_init(&err); - ten_env_notify_set_property_info_t *info = - ten_env_notify_set_property_info_create(path, path_len, value, - callback_handle); + ten_env_notify_set_property_ctx_t *ctx = + ten_env_notify_set_property_ctx_create(path, path_len, value, + callback_handle); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_set_property, info, false, + ten_env_proxy_notify_set_property, ctx, false, &err)) { // Failed to invoke ten_env_proxy_notify. - ten_env_notify_set_property_info_destroy(info); + ten_env_notify_set_property_ctx_destroy(ctx); ten_go_error_from_error(&cgo_error, &err); } diff --git a/core/src/ten_runtime/binding/nodejs/native/addon/addon.c b/core/src/ten_runtime/binding/nodejs/native/addon/addon.c index 42321de4b9..df9bcecdb7 100644 --- a/core/src/ten_runtime/binding/nodejs/native/addon/addon.c +++ b/core/src/ten_runtime/binding/nodejs/native/addon/addon.c @@ -26,37 +26,37 @@ typedef struct addon_on_xxx_callback_info_t { ten_env_t *ten_env; } addon_on_xxx_callback_info_t; -typedef struct addon_on_create_instance_callback_info_t { +typedef struct addon_on_create_instance_callback_ctx_t { ten_nodejs_addon_t *addon_bridge; ten_env_t *ten_env; ten_string_t instance_name; void *context; -} addon_on_create_instance_callback_info_t; - -static addon_on_create_instance_callback_info_t * -addon_on_create_instance_callback_info_create(ten_nodejs_addon_t *addon_bridge, - ten_env_t *ten_env, - const char *instance_name, - void *context) { - addon_on_create_instance_callback_info_t *info = - TEN_MALLOC(sizeof(addon_on_create_instance_callback_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); - - info->addon_bridge = addon_bridge; - info->ten_env = ten_env; - ten_string_init_from_c_str(&info->instance_name, instance_name, +} addon_on_create_instance_callback_ctx_t; + +static addon_on_create_instance_callback_ctx_t * +addon_on_create_instance_callback_ctx_create(ten_nodejs_addon_t *addon_bridge, + ten_env_t *ten_env, + const char *instance_name, + void *context) { + addon_on_create_instance_callback_ctx_t *ctx = + TEN_MALLOC(sizeof(addon_on_create_instance_callback_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); + + ctx->addon_bridge = addon_bridge; + ctx->ten_env = ten_env; + ten_string_init_from_c_str(&ctx->instance_name, instance_name, strlen(instance_name)); - info->context = context; + ctx->context = context; - return info; + return ctx; } -static void addon_on_create_instance_callback_info_destroy( - addon_on_create_instance_callback_info_t *info) { - TEN_ASSERT(info, "Should not happen."); +static void addon_on_create_instance_callback_ctx_destroy( + addon_on_create_instance_callback_ctx_t *ctx) { + TEN_ASSERT(ctx, "Should not happen."); - ten_string_deinit(&info->instance_name); - TEN_FREE(info); + ten_string_deinit(&ctx->instance_name); + TEN_FREE(ctx); } bool ten_nodejs_addon_check_integrity(ten_nodejs_addon_t *self, @@ -212,7 +212,7 @@ void ten_nodejs_invoke_addon_js_on_deinit(napi_env env, napi_value fn, void ten_nodejs_invoke_addon_js_on_create_instance(napi_env env, napi_value fn, void *context, void *data) { - addon_on_create_instance_callback_info_t *call_info = data; + addon_on_create_instance_callback_ctx_t *call_info = data; TEN_ASSERT(call_info, "Should not happen."); TEN_ASSERT(call_info->addon_bridge && ten_nodejs_addon_check_integrity( @@ -272,7 +272,7 @@ void ten_nodejs_invoke_addon_js_on_create_instance(napi_env env, napi_value fn, TEN_LOGE("Failed to call JS addon on_create_instance()."); done: - addon_on_create_instance_callback_info_destroy(call_info); + addon_on_create_instance_callback_ctx_destroy(call_info); } static void proxy_on_init(ten_addon_t *addon, ten_env_t *ten_env) { @@ -351,9 +351,9 @@ static void proxy_on_create_instance(ten_addon_t *addon, ten_env_t *ten_env, ten_nodejs_addon_check_integrity(addon_bridge, false), "Should not happen."); - addon_on_create_instance_callback_info_t *call_info = - addon_on_create_instance_callback_info_create(addon_bridge, ten_env, name, - context); + addon_on_create_instance_callback_ctx_t *call_info = + addon_on_create_instance_callback_ctx_create(addon_bridge, ten_env, name, + context); bool rc = ten_nodejs_tsfn_invoke(addon_bridge->js_on_create_instance, call_info); diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env.c index 53b58df272..50c88d537e 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env.c @@ -84,62 +84,62 @@ bool ten_nodejs_ten_env_check_integrity(ten_nodejs_ten_env_t *self, return true; } -ten_nodejs_get_property_call_info_t *ten_nodejs_get_property_call_info_create( +ten_nodejs_get_property_call_ctx_t *ten_nodejs_get_property_call_ctx_create( ten_nodejs_tsfn_t *cb_tsfn, ten_value_t *value, ten_error_t *error) { TEN_ASSERT(cb_tsfn, "Invalid argument."); - ten_nodejs_get_property_call_info_t *info = - (ten_nodejs_get_property_call_info_t *)TEN_MALLOC( - sizeof(ten_nodejs_get_property_call_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_nodejs_get_property_call_ctx_t *ctx = + (ten_nodejs_get_property_call_ctx_t *)TEN_MALLOC( + sizeof(ten_nodejs_get_property_call_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->cb_tsfn = cb_tsfn; - info->value = value; - info->error = error; + ctx->cb_tsfn = cb_tsfn; + ctx->value = value; + ctx->error = error; - return info; + return ctx; } -void ten_nodejs_get_property_call_info_destroy( - ten_nodejs_get_property_call_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +void ten_nodejs_get_property_call_ctx_destroy( + ten_nodejs_get_property_call_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->value) { - ten_value_destroy(info->value); + if (ctx->value) { + ten_value_destroy(ctx->value); } - if (info->error) { - ten_error_destroy(info->error); + if (ctx->error) { + ten_error_destroy(ctx->error); } - TEN_FREE(info); + TEN_FREE(ctx); } -ten_nodejs_set_property_call_info_t *ten_nodejs_set_property_call_info_create( +ten_nodejs_set_property_call_ctx_t *ten_nodejs_set_property_call_ctx_create( ten_nodejs_tsfn_t *cb_tsfn, bool success, ten_error_t *error) { TEN_ASSERT(cb_tsfn, "Invalid argument."); - ten_nodejs_set_property_call_info_t *info = - (ten_nodejs_set_property_call_info_t *)TEN_MALLOC( - sizeof(ten_nodejs_set_property_call_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_nodejs_set_property_call_ctx_t *ctx = + (ten_nodejs_set_property_call_ctx_t *)TEN_MALLOC( + sizeof(ten_nodejs_set_property_call_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->cb_tsfn = cb_tsfn; - info->success = success; - info->error = error; + ctx->cb_tsfn = cb_tsfn; + ctx->success = success; + ctx->error = error; - return info; + return ctx; } -void ten_nodejs_set_property_call_info_destroy( - ten_nodejs_set_property_call_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +void ten_nodejs_set_property_call_ctx_destroy( + ten_nodejs_set_property_call_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->error) { - ten_error_destroy(info->error); + if (ctx->error) { + ten_error_destroy(ctx->error); } - TEN_FREE(info); + TEN_FREE(ctx); } napi_value ten_nodejs_ten_env_create_new_js_object_and_wrap( diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property.c index c0cc7a8cc6..ec8854219e 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property.c @@ -8,31 +8,31 @@ #include "include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_get_property_info_t { +typedef struct ten_env_notify_get_property_ctx_t { ten_string_t path; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_get_property_info_t; +} ten_env_notify_get_property_ctx_t; -static ten_env_notify_get_property_info_t * -ten_env_notify_get_property_info_create(const void *path, - ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_get_property_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_get_property_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_get_property_ctx_t * +ten_env_notify_get_property_ctx_create(const void *path, + ten_nodejs_tsfn_t *js_cb) { + ten_env_notify_get_property_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_get_property_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_from_c_str(&info->path, path, strlen(path)); - info->js_cb = js_cb; + ten_string_init_from_c_str(&ctx->path, path, strlen(path)); + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_get_property_info_destroy( - ten_env_notify_get_property_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_get_property_ctx_destroy( + ten_env_notify_get_property_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_string_deinit(&info->path); + ten_string_deinit(&ctx->path); - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, @@ -41,10 +41,10 @@ static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_get_property_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_get_property_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); @@ -52,7 +52,7 @@ static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, ten_error_init(&err); ten_value_t *value = - ten_env_peek_property(ten_env, ten_string_get_raw_str(&info->path), &err); + ten_env_peek_property(ten_env, ten_string_get_raw_str(&ctx->path), &err); ten_value_t *cloned_value = NULL; ten_error_t *cloned_error = NULL; @@ -63,15 +63,15 @@ static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, ten_error_copy(cloned_error, &err); } - ten_nodejs_get_property_call_info_t *call_info = - ten_nodejs_get_property_call_info_create(js_cb, cloned_value, - cloned_error); + ten_nodejs_get_property_call_ctx_t *call_info = + ten_nodejs_get_property_call_ctx_create(js_cb, cloned_value, + cloned_error); TEN_ASSERT(call_info, "Should not happen."); bool rc = ten_nodejs_tsfn_invoke(js_cb, call_info); TEN_ASSERT(rc, "Should not happen."); - ten_env_notify_get_property_info_destroy(info); + ten_env_notify_get_property_ctx_destroy(ctx); ten_error_deinit(&err); } @@ -86,14 +86,14 @@ bool ten_nodejs_ten_env_get_property_value(ten_nodejs_ten_env_t *self, TEN_ASSERT(cb_tsfn && ten_nodejs_tsfn_check_integrity(cb_tsfn, true), "Invalid argument."); - ten_env_notify_get_property_info_t *info = - ten_env_notify_get_property_info_create(path, cb_tsfn); - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_get_property_ctx_t *ctx = + ten_env_notify_get_property_ctx_create(path, cb_tsfn); + TEN_ASSERT(ctx, "Should not happen."); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_get_property, info, false, + ten_env_proxy_notify_get_property, ctx, false, error)) { - ten_env_notify_get_property_info_destroy(info); + ten_env_notify_get_property_ctx_destroy(ctx); return false; } diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_number.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_number.c index a765cb6169..8fd9f98634 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_number.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_number.c @@ -12,9 +12,9 @@ static void tsfn_proxy_get_property_number_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_get_property_call_info_t *info = - (ten_nodejs_get_property_call_info_t *)data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_get_property_call_ctx_t *ctx = + (ten_nodejs_get_property_call_ctx_t *)data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_res = NULL; napi_value js_error = NULL; @@ -22,10 +22,10 @@ static void tsfn_proxy_get_property_number_callback(napi_env env, ten_error_t err; ten_error_init(&err); - ten_value_t *value = info->value; + ten_value_t *value = ctx->value; if (!value) { - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { ten_error_set(&err, TEN_ERRNO_GENERIC, "Failed to get property value"); @@ -55,9 +55,9 @@ static void tsfn_proxy_get_property_number_callback(napi_env env, status == napi_ok, "Failed to call JS callback of TenEnv::getPropertyNumber: %d", status); - ten_nodejs_tsfn_release(info->cb_tsfn); + ten_nodejs_tsfn_release(ctx->cb_tsfn); - ten_nodejs_get_property_call_info_destroy(info); + ten_nodejs_get_property_call_ctx_destroy(ctx); } napi_value ten_nodejs_ten_env_get_property_number(napi_env env, diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_string.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_string.c index 013f523adc..eae1e33d18 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_string.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_string.c @@ -9,9 +9,9 @@ static void tsfn_proxy_get_property_string_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_get_property_call_info_t *info = - (ten_nodejs_get_property_call_info_t *)data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_get_property_call_ctx_t *ctx = + (ten_nodejs_get_property_call_ctx_t *)data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_res = NULL; napi_value js_error = NULL; @@ -19,10 +19,10 @@ static void tsfn_proxy_get_property_string_callback(napi_env env, ten_error_t err; ten_error_init(&err); - ten_value_t *value = info->value; + ten_value_t *value = ctx->value; if (!value) { - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { ten_error_set(&err, TEN_ERRNO_GENERIC, "Failed to get property value"); @@ -52,9 +52,9 @@ static void tsfn_proxy_get_property_string_callback(napi_env env, status == napi_ok, "Failed to call JS callback of TenEnv::getPropertyString: %d", status); - ten_nodejs_tsfn_release(info->cb_tsfn); + ten_nodejs_tsfn_release(ctx->cb_tsfn); - ten_nodejs_get_property_call_info_destroy(info); + ten_nodejs_get_property_call_ctx_destroy(ctx); } napi_value ten_nodejs_ten_env_get_property_string(napi_env env, diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_to_json.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_to_json.c index cc7d6acc8f..7b6ccdbdd2 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_to_json.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_get_property_to_json.c @@ -14,9 +14,9 @@ static void tsfn_proxy_get_property_to_json_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_get_property_call_info_t *info = - (ten_nodejs_get_property_call_info_t *)data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_get_property_call_ctx_t *ctx = + (ten_nodejs_get_property_call_ctx_t *)data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_res = NULL; napi_value js_error = NULL; @@ -24,10 +24,10 @@ static void tsfn_proxy_get_property_to_json_callback(napi_env env, ten_error_t err; ten_error_init(&err); - ten_value_t *value = info->value; + ten_value_t *value = ctx->value; if (!value) { - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { ten_error_set(&err, TEN_ERRNO_GENERIC, "Failed to get property value"); @@ -74,9 +74,9 @@ static void tsfn_proxy_get_property_to_json_callback(napi_env env, status == napi_ok, "Failed to call JS callback of TenEnv::getPropertyToJson: %d", status); - ten_nodejs_tsfn_release(info->cb_tsfn); + ten_nodejs_tsfn_release(ctx->cb_tsfn); - ten_nodejs_get_property_call_info_destroy(info); + ten_nodejs_get_property_call_ctx_destroy(ctx); } napi_value ten_nodejs_ten_env_get_property_to_json(napi_env env, diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_init_property_from_json.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_init_property_from_json.c index 82f59f40c3..f4737e4f7c 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_init_property_from_json.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_init_property_from_json.c @@ -10,44 +10,44 @@ #include "ten_utils/lib/string.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_init_property_from_json_info_t { +typedef struct ten_env_notify_init_property_from_json_ctx_t { ten_string_t json_str; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_init_property_from_json_info_t; +} ten_env_notify_init_property_from_json_ctx_t; -typedef struct ten_nodejs_init_property_from_json_call_info_t { +typedef struct ten_nodejs_init_property_from_json_call_ctx_t { ten_nodejs_tsfn_t *js_cb; ten_error_t *error; -} ten_nodejs_init_property_from_json_call_info_t; +} ten_nodejs_init_property_from_json_call_ctx_t; -static ten_env_notify_init_property_from_json_info_t * -ten_env_notify_init_property_from_json_info_create(ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_init_property_from_json_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_init_property_from_json_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_init_property_from_json_ctx_t * +ten_env_notify_init_property_from_json_ctx_create(ten_nodejs_tsfn_t *js_cb) { + ten_env_notify_init_property_from_json_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_init_property_from_json_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init(&info->json_str); - info->js_cb = js_cb; + ten_string_init(&ctx->json_str); + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_init_property_from_json_info_destroy( - ten_env_notify_init_property_from_json_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_init_property_from_json_ctx_destroy( + ten_env_notify_init_property_from_json_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_string_deinit(&info->json_str); - info->js_cb = NULL; + ten_string_deinit(&ctx->json_str); + ctx->js_cb = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } static void tsfn_proxy_init_property_from_json_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_init_property_from_json_call_info_t *call_info = - (ten_nodejs_init_property_from_json_call_info_t *)data; + ten_nodejs_init_property_from_json_call_ctx_t *call_info = + (ten_nodejs_init_property_from_json_call_ctx_t *)data; TEN_ASSERT(call_info, "Should not happen."); napi_value js_error = NULL; @@ -80,10 +80,10 @@ static void ten_env_proxy_notify_init_property_from_json(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_init_property_from_json_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_init_property_from_json_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); @@ -91,7 +91,7 @@ static void ten_env_proxy_notify_init_property_from_json(ten_env_t *ten_env, ten_error_init(&err); bool rc = ten_env_init_property_from_json( - ten_env, ten_string_get_raw_str(&info->json_str), &err); + ten_env, ten_string_get_raw_str(&ctx->json_str), &err); ten_error_t *cloned_error = NULL; if (!rc) { @@ -99,8 +99,8 @@ static void ten_env_proxy_notify_init_property_from_json(ten_env_t *ten_env, ten_error_copy(cloned_error, &err); } - ten_nodejs_init_property_from_json_call_info_t *call_info = - TEN_MALLOC(sizeof(ten_nodejs_init_property_from_json_call_info_t)); + ten_nodejs_init_property_from_json_call_ctx_t *call_info = + TEN_MALLOC(sizeof(ten_nodejs_init_property_from_json_call_ctx_t)); TEN_ASSERT(call_info, "Failed to allocate memory."); call_info->js_cb = js_cb; @@ -111,7 +111,7 @@ static void ten_env_proxy_notify_init_property_from_json(ten_env_t *ten_env, ten_error_deinit(&err); - ten_env_notify_init_property_from_json_info_destroy(info); + ten_env_notify_init_property_from_json_ctx_destroy(ctx); } napi_value ten_nodejs_ten_env_init_property_from_json(napi_env env, @@ -141,8 +141,8 @@ napi_value ten_nodejs_ten_env_init_property_from_json(napi_env env, tsfn_proxy_init_property_from_json_callback); RETURN_UNDEFINED_IF_NAPI_FAIL(cb_tsfn, "Failed to create TSFN."); - ten_env_notify_init_property_from_json_info_t *notify_info = - ten_env_notify_init_property_from_json_info_create(cb_tsfn); + ten_env_notify_init_property_from_json_ctx_t *notify_info = + ten_env_notify_init_property_from_json_ctx_create(cb_tsfn); TEN_ASSERT(notify_info, "Failed to create notify info."); bool rc = ten_nodejs_get_str_from_js(env, args[1], ¬ify_info->json_str); @@ -165,7 +165,7 @@ napi_value ten_nodejs_ten_env_init_property_from_json(napi_env env, ten_string_deinit(&code_str); - ten_env_notify_init_property_from_json_info_destroy(notify_info); + ten_env_notify_init_property_from_json_ctx_destroy(notify_info); // The JS callback will not be called, so we need to clean up the tsfn. ten_nodejs_tsfn_release(cb_tsfn); diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_is_property_exist.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_is_property_exist.c index f3cf4169c8..18c582558f 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_is_property_exist.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_is_property_exist.c @@ -14,11 +14,11 @@ static void tsfn_proxy_is_property_exist_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_get_property_call_info_t *info = - (ten_nodejs_get_property_call_info_t *)data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_get_property_call_ctx_t *ctx = + (ten_nodejs_get_property_call_ctx_t *)data; + TEN_ASSERT(ctx, "Should not happen."); - ten_value_t *value = info->value; + ten_value_t *value = ctx->value; bool is_property_exist = value != NULL; napi_value js_res = NULL; @@ -31,9 +31,9 @@ static void tsfn_proxy_is_property_exist_callback(napi_env env, status == napi_ok, "Failed to call JS callback of TenEnv::isPropertyExist: %d", status); - ten_nodejs_tsfn_release(info->cb_tsfn); + ten_nodejs_tsfn_release(ctx->cb_tsfn); - ten_nodejs_get_property_call_info_destroy(info); + ten_nodejs_get_property_call_ctx_destroy(ctx); } napi_value ten_nodejs_ten_env_is_property_exist(napi_env env, diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_log_internal.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_log_internal.c index 62272ea1df..e7ec031758 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_log_internal.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_log_internal.c @@ -10,39 +10,38 @@ #include "ten_utils/lib/error.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_log_info_t { +typedef struct ten_env_notify_log_ctx_t { int32_t level; ten_string_t func_name; ten_string_t file_name; int32_t line_no; ten_string_t msg; ten_event_t *completed; -} ten_env_notify_log_info_t; +} ten_env_notify_log_ctx_t; -static ten_env_notify_log_info_t *ten_env_notify_log_info_create() { - ten_env_notify_log_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_log_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_log_ctx_t *ten_env_notify_log_ctx_create(void) { + ten_env_notify_log_ctx_t *ctx = TEN_MALLOC(sizeof(ten_env_notify_log_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->level = 0; - ten_string_init(&info->func_name); - ten_string_init(&info->file_name); - info->line_no = 0; - ten_string_init(&info->msg); - info->completed = ten_event_create(0, 1); + ctx->level = 0; + ten_string_init(&ctx->func_name); + ten_string_init(&ctx->file_name); + ctx->line_no = 0; + ten_string_init(&ctx->msg); + ctx->completed = ten_event_create(0, 1); - return info; + return ctx; } -static void ten_env_notify_log_info_destroy(ten_env_notify_log_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_log_ctx_destroy(ten_env_notify_log_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_string_deinit(&info->func_name); - ten_string_deinit(&info->file_name); - ten_string_deinit(&info->msg); - ten_event_destroy(info->completed); + ten_string_deinit(&ctx->func_name); + ten_string_deinit(&ctx->file_name); + ten_string_deinit(&ctx->msg); + ten_event_destroy(ctx->completed); - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_log(ten_env_t *ten_env, void *user_data) { @@ -50,14 +49,14 @@ static void ten_env_proxy_notify_log(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_log_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_log_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_env_log(ten_env, info->level, ten_string_get_raw_str(&info->func_name), - ten_string_get_raw_str(&info->file_name), info->line_no, - ten_string_get_raw_str(&info->msg)); + ten_env_log(ten_env, ctx->level, ten_string_get_raw_str(&ctx->func_name), + ten_string_get_raw_str(&ctx->file_name), ctx->line_no, + ten_string_get_raw_str(&ctx->msg)); - ten_event_set(info->completed); + ten_event_set(ctx->completed); } napi_value ten_nodejs_ten_env_log_internal(napi_env env, @@ -76,7 +75,7 @@ napi_value ten_nodejs_ten_env_log_internal(napi_env env, RETURN_UNDEFINED_IF_NAPI_FAIL(status == napi_ok && ten_env_bridge != NULL, "Failed to get ten_env bridge: %d", status); - ten_env_notify_log_info_t *notify_info = ten_env_notify_log_info_create(); + ten_env_notify_log_ctx_t *notify_info = ten_env_notify_log_ctx_create(); TEN_ASSERT(notify_info, "Failed to create log notify_info."); status = napi_get_value_int32(env, args[1], ¬ify_info->level); @@ -113,7 +112,7 @@ napi_value ten_nodejs_ten_env_log_internal(napi_env env, } ten_error_deinit(&err); - ten_env_notify_log_info_destroy(notify_info); + ten_env_notify_log_ctx_destroy(notify_info); return js_undefined(env); } diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_return_result.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_return_result.c index 4ad137db57..247f69a5a4 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_return_result.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_return_result.c @@ -13,86 +13,86 @@ #include "ten_utils/lib/string.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_return_result_info_t { +typedef struct ten_env_notify_return_result_ctx_t { ten_shared_ptr_t *c_cmd_result; ten_shared_ptr_t *c_target_cmd; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_return_result_info_t; +} ten_env_notify_return_result_ctx_t; -typedef struct ten_nodejs_return_result_callback_call_info_t { +typedef struct ten_nodejs_return_result_callback_call_ctx_t { ten_nodejs_tsfn_t *js_cb; ten_error_t *error; -} ten_nodejs_return_result_callback_call_info_t; +} ten_nodejs_return_result_callback_call_ctx_t; -static ten_env_notify_return_result_info_t * -ten_env_notify_return_result_info_create(ten_shared_ptr_t *c_cmd_result, - ten_shared_ptr_t *c_target_cmd, - ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_return_result_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_return_result_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_return_result_ctx_t * +ten_env_notify_return_result_ctx_create(ten_shared_ptr_t *c_cmd_result, + ten_shared_ptr_t *c_target_cmd, + ten_nodejs_tsfn_t *js_cb) { + ten_env_notify_return_result_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_return_result_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_cmd_result = c_cmd_result; - info->c_target_cmd = c_target_cmd; - info->js_cb = js_cb; + ctx->c_cmd_result = c_cmd_result; + ctx->c_target_cmd = c_target_cmd; + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_return_result_info_destroy( - ten_env_notify_return_result_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_return_result_ctx_destroy( + ten_env_notify_return_result_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_cmd_result) { - ten_shared_ptr_destroy(info->c_cmd_result); - info->c_cmd_result = NULL; + if (ctx->c_cmd_result) { + ten_shared_ptr_destroy(ctx->c_cmd_result); + ctx->c_cmd_result = NULL; } - if (info->c_target_cmd) { - ten_shared_ptr_destroy(info->c_target_cmd); - info->c_target_cmd = NULL; + if (ctx->c_target_cmd) { + ten_shared_ptr_destroy(ctx->c_target_cmd); + ctx->c_target_cmd = NULL; } - info->js_cb = NULL; + ctx->js_cb = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } -static ten_nodejs_return_result_callback_call_info_t * -ten_nodejs_return_result_callback_call_info_create(ten_nodejs_tsfn_t *js_cb, - ten_error_t *error) { - ten_nodejs_return_result_callback_call_info_t *info = - TEN_MALLOC(sizeof(ten_nodejs_return_result_callback_call_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_nodejs_return_result_callback_call_ctx_t * +ten_nodejs_return_result_callback_call_ctx_create(ten_nodejs_tsfn_t *js_cb, + ten_error_t *error) { + ten_nodejs_return_result_callback_call_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_nodejs_return_result_callback_call_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->js_cb = js_cb; - info->error = error; + ctx->js_cb = js_cb; + ctx->error = error; - return info; + return ctx; } -static void ten_nodejs_return_result_callback_call_info_destroy( - ten_nodejs_return_result_callback_call_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_nodejs_return_result_callback_call_ctx_destroy( + ten_nodejs_return_result_callback_call_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->error) { - ten_error_destroy(info->error); - info->error = NULL; + if (ctx->error) { + ten_error_destroy(ctx->error); + ctx->error = NULL; } - TEN_FREE(info); + TEN_FREE(ctx); } static void tsfn_proxy_return_result_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_return_result_callback_call_info_t *info = - (ten_nodejs_return_result_callback_call_info_t *)data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_return_result_callback_call_ctx_t *ctx = + (ten_nodejs_return_result_callback_call_ctx_t *)data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_error = NULL; - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { js_error = js_undefined(env); @@ -106,19 +106,19 @@ static void tsfn_proxy_return_result_callback(napi_env env, napi_value js_cb, "Failed to call JS callback of TenEnv::return_result: %d", status); - ten_nodejs_tsfn_release(info->js_cb); + ten_nodejs_tsfn_release(ctx->js_cb); - ten_nodejs_return_result_callback_call_info_destroy(info); + ten_nodejs_return_result_callback_call_ctx_destroy(ctx); } static void proxy_return_result_error_callback(ten_env_t *self, void *user_data, ten_error_t *err) { TEN_ASSERT(self && ten_env_check_integrity(self, true), "Should not happen."); - ten_env_notify_return_result_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_return_result_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); @@ -128,14 +128,14 @@ static void proxy_return_result_error_callback(ten_env_t *self, void *user_data, ten_error_copy(cloned_error, err); } - ten_nodejs_return_result_callback_call_info_t *call_info = - ten_nodejs_return_result_callback_call_info_create(js_cb, cloned_error); + ten_nodejs_return_result_callback_call_ctx_t *call_info = + ten_nodejs_return_result_callback_call_ctx_create(js_cb, cloned_error); TEN_ASSERT(call_info, "Should not happen."); bool rc = ten_nodejs_tsfn_invoke(js_cb, call_info); TEN_ASSERT(rc, "Should not happen."); - ten_env_notify_return_result_info_destroy(info); + ten_env_notify_return_result_ctx_destroy(ctx); } static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, @@ -144,17 +144,17 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_return_result_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_return_result_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); bool rc = - ten_env_return_result(ten_env, info->c_cmd_result, info->c_target_cmd, - proxy_return_result_error_callback, info, &err); + ten_env_return_result(ten_env, ctx->c_cmd_result, ctx->c_target_cmd, + proxy_return_result_error_callback, ctx, &err); if (!rc) { - proxy_return_result_error_callback(ten_env, info, &err); + proxy_return_result_error_callback(ten_env, ctx, &err); } ten_error_deinit(&err); @@ -199,8 +199,8 @@ napi_value ten_nodejs_ten_env_return_result(napi_env env, ten_error_t err; ten_error_init(&err); - ten_env_notify_return_result_info_t *notify_info = - ten_env_notify_return_result_info_create( + ten_env_notify_return_result_ctx_t *notify_info = + ten_env_notify_return_result_ctx_create( ten_shared_ptr_clone(cmd_result_bridge->msg.msg), ten_shared_ptr_clone(target_cmd_bridge->msg.msg), cb_tsfn); @@ -220,7 +220,7 @@ napi_value ten_nodejs_ten_env_return_result(napi_env env, // The JS callback will not be called, so release the TSFN here. ten_nodejs_tsfn_release(cb_tsfn); - ten_env_notify_return_result_info_destroy(notify_info); + ten_env_notify_return_result_ctx_destroy(notify_info); } ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_return_result_directly.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_return_result_directly.c index 6e7a7dbf36..1e4c268c42 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_return_result_directly.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_return_result_directly.c @@ -9,83 +9,83 @@ #include "ten_runtime/ten_env/internal/return.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_return_result_directly_info_t { +typedef struct ten_env_notify_return_result_directly_ctx_t { ten_shared_ptr_t *c_cmd_result; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_return_result_directly_info_t; +} ten_env_notify_return_result_directly_ctx_t; -typedef struct ten_nodejs_return_result_directly_callback_call_info_t { +typedef struct ten_nodejs_return_result_directly_callback_call_ctx_t { ten_nodejs_tsfn_t *js_cb; ten_error_t *error; -} ten_nodejs_return_result_directly_callback_call_info_t; +} ten_nodejs_return_result_directly_callback_call_ctx_t; -static ten_env_notify_return_result_directly_info_t * -ten_env_notify_return_result_directly_info_create( - ten_shared_ptr_t *c_cmd_result, ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_return_result_directly_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_return_result_directly_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_return_result_directly_ctx_t * +ten_env_notify_return_result_directly_ctx_create(ten_shared_ptr_t *c_cmd_result, + ten_nodejs_tsfn_t *js_cb) { + ten_env_notify_return_result_directly_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_return_result_directly_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_cmd_result = c_cmd_result; - info->js_cb = js_cb; + ctx->c_cmd_result = c_cmd_result; + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_return_result_directly_info_destroy( - ten_env_notify_return_result_directly_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_return_result_directly_ctx_destroy( + ten_env_notify_return_result_directly_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_cmd_result) { - ten_shared_ptr_destroy(info->c_cmd_result); - info->c_cmd_result = NULL; + if (ctx->c_cmd_result) { + ten_shared_ptr_destroy(ctx->c_cmd_result); + ctx->c_cmd_result = NULL; } - info->js_cb = NULL; + ctx->js_cb = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } -static ten_nodejs_return_result_directly_callback_call_info_t * -ten_nodejs_return_result_directly_callback_call_info_create( +static ten_nodejs_return_result_directly_callback_call_ctx_t * +ten_nodejs_return_result_directly_callback_call_ctx_create( ten_nodejs_tsfn_t *js_cb, ten_error_t *error) { - ten_nodejs_return_result_directly_callback_call_info_t *info = TEN_MALLOC( - sizeof(ten_nodejs_return_result_directly_callback_call_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_nodejs_return_result_directly_callback_call_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_nodejs_return_result_directly_callback_call_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->js_cb = js_cb; - info->error = error; + ctx->js_cb = js_cb; + ctx->error = error; - return info; + return ctx; } -static void ten_nodejs_return_result_directly_callback_call_info_destroy( - ten_nodejs_return_result_directly_callback_call_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_nodejs_return_result_directly_callback_call_ctx_destroy( + ten_nodejs_return_result_directly_callback_call_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->error) { - ten_error_destroy(info->error); - info->error = NULL; + if (ctx->error) { + ten_error_destroy(ctx->error); + ctx->error = NULL; } - TEN_FREE(info); + TEN_FREE(ctx); } static void tsfn_proxy_return_result_directly_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_return_result_directly_callback_call_info_t *info = data; - TEN_ASSERT(info, "Invalid argument."); + ten_nodejs_return_result_directly_callback_call_ctx_t *ctx = data; + TEN_ASSERT(ctx, "Invalid argument."); - ten_nodejs_tsfn_t *js_cb_tsfn = info->js_cb; + ten_nodejs_tsfn_t *js_cb_tsfn = ctx->js_cb; TEN_ASSERT(js_cb_tsfn && ten_nodejs_tsfn_check_integrity(js_cb_tsfn, false), "Should not happen."); napi_value js_error = NULL; - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { js_error = js_undefined(env); @@ -99,9 +99,9 @@ static void tsfn_proxy_return_result_directly_callback(napi_env env, "Failed to call JS callback of TenEnv::return_result: %d", status); - ten_nodejs_tsfn_release(info->js_cb); + ten_nodejs_tsfn_release(ctx->js_cb); - ten_nodejs_return_result_directly_callback_call_info_destroy(info); + ten_nodejs_return_result_directly_callback_call_ctx_destroy(ctx); } static void proxy_return_result_directly_error_callback(ten_env_t *self, @@ -109,10 +109,10 @@ static void proxy_return_result_directly_error_callback(ten_env_t *self, ten_error_t *error) { TEN_ASSERT(self && ten_env_check_integrity(self, true), "Should not happen."); - ten_env_notify_return_result_directly_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_return_result_directly_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); @@ -122,15 +122,15 @@ static void proxy_return_result_directly_error_callback(ten_env_t *self, ten_error_copy(cloned_error, error); } - ten_nodejs_return_result_directly_callback_call_info_t *call_info = - ten_nodejs_return_result_directly_callback_call_info_create(js_cb, - cloned_error); + ten_nodejs_return_result_directly_callback_call_ctx_t *call_info = + ten_nodejs_return_result_directly_callback_call_ctx_create(js_cb, + cloned_error); TEN_ASSERT(call_info, "Failed to create callback call info."); bool rc = ten_nodejs_tsfn_invoke(js_cb, call_info); TEN_ASSERT(rc, "Should not happen."); - ten_env_notify_return_result_directly_info_destroy(info); + ten_env_notify_return_result_directly_ctx_destroy(ctx); } static void ten_env_proxy_notify_return_result_directly(ten_env_t *ten_env, @@ -139,17 +139,17 @@ static void ten_env_proxy_notify_return_result_directly(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_return_result_directly_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_return_result_directly_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); bool rc = ten_env_return_result_directly( - ten_env, info->c_cmd_result, proxy_return_result_directly_error_callback, - info, &err); + ten_env, ctx->c_cmd_result, proxy_return_result_directly_error_callback, + ctx, &err); if (!rc) { - proxy_return_result_directly_error_callback(ten_env, info, &err); + proxy_return_result_directly_error_callback(ten_env, ctx, &err); } ten_error_deinit(&err); @@ -189,8 +189,8 @@ napi_value ten_nodejs_ten_env_return_result_directly(napi_env env, ten_error_t err; ten_error_init(&err); - ten_env_notify_return_result_directly_info_t *notify_info = - ten_env_notify_return_result_directly_info_create( + ten_env_notify_return_result_directly_ctx_t *notify_info = + ten_env_notify_return_result_directly_ctx_create( ten_shared_ptr_clone(cmd_result_bridge->msg.msg), cb_tsfn); bool rc = ten_env_proxy_notify(ten_env_bridge->c_ten_env_proxy, ten_env_proxy_notify_return_result_directly, @@ -208,7 +208,7 @@ napi_value ten_nodejs_ten_env_return_result_directly(napi_env env, // The JS callback will not be called, so release the TSFN here. ten_nodejs_tsfn_release(cb_tsfn); - ten_env_notify_return_result_directly_info_destroy(notify_info); + ten_env_notify_return_result_directly_ctx_destroy(notify_info); } ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_audio_frame.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_audio_frame.c index 3582ff3572..c4efa6e994 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_audio_frame.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_audio_frame.c @@ -8,78 +8,78 @@ #include "include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_send_audio_frame_info_t { +typedef struct ten_env_notify_send_audio_frame_ctx_t { ten_shared_ptr_t *c_audio_frame; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_send_audio_frame_info_t; +} ten_env_notify_send_audio_frame_ctx_t; -typedef struct ten_nodejs_send_audio_frame_callback_call_info_t { +typedef struct ten_nodejs_send_audio_frame_callback_call_ctx_t { ten_nodejs_tsfn_t *js_cb; ten_error_t *error; -} ten_nodejs_send_audio_frame_callback_call_info_t; +} ten_nodejs_send_audio_frame_callback_call_ctx_t; -static ten_env_notify_send_audio_frame_info_t * -ten_env_notify_send_audio_frame_info_create(ten_shared_ptr_t *c_audio_frame, - ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_send_audio_frame_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_audio_frame_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_send_audio_frame_ctx_t * +ten_env_notify_send_audio_frame_ctx_create(ten_shared_ptr_t *c_audio_frame, + ten_nodejs_tsfn_t *js_cb) { + ten_env_notify_send_audio_frame_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_audio_frame_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_audio_frame = c_audio_frame; - info->js_cb = js_cb; + ctx->c_audio_frame = c_audio_frame; + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_send_audio_frame_info_destroy( - ten_env_notify_send_audio_frame_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_audio_frame_ctx_destroy( + ten_env_notify_send_audio_frame_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_audio_frame) { - ten_shared_ptr_destroy(info->c_audio_frame); - info->c_audio_frame = NULL; + if (ctx->c_audio_frame) { + ten_shared_ptr_destroy(ctx->c_audio_frame); + ctx->c_audio_frame = NULL; } - info->js_cb = NULL; + ctx->js_cb = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } -static ten_nodejs_send_audio_frame_callback_call_info_t * -ten_nodejs_send_audio_frame_callback_call_info_create(ten_nodejs_tsfn_t *js_cb, - ten_error_t *error) { - ten_nodejs_send_audio_frame_callback_call_info_t *info = - TEN_MALLOC(sizeof(ten_nodejs_send_audio_frame_callback_call_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_nodejs_send_audio_frame_callback_call_ctx_t * +ten_nodejs_send_audio_frame_callback_call_ctx_create(ten_nodejs_tsfn_t *js_cb, + ten_error_t *error) { + ten_nodejs_send_audio_frame_callback_call_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_nodejs_send_audio_frame_callback_call_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->js_cb = js_cb; - info->error = error; + ctx->js_cb = js_cb; + ctx->error = error; - return info; + return ctx; } -static void ten_nodejs_send_audio_frame_callback_call_info_destroy( - ten_nodejs_send_audio_frame_callback_call_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_nodejs_send_audio_frame_callback_call_ctx_destroy( + ten_nodejs_send_audio_frame_callback_call_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->error) { - ten_error_destroy(info->error); - info->error = NULL; + if (ctx->error) { + ten_error_destroy(ctx->error); + ctx->error = NULL; } - TEN_FREE(info); + TEN_FREE(ctx); } static void tsfn_proxy_send_audio_frame_callback(napi_env env, napi_value js_cb, void *context, void *audio_frame) { - ten_nodejs_send_audio_frame_callback_call_info_t *info = audio_frame; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_send_audio_frame_callback_call_ctx_t *ctx = audio_frame; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_error = NULL; - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { js_error = js_undefined(env); @@ -90,9 +90,9 @@ static void tsfn_proxy_send_audio_frame_callback(napi_env env, napi_value js_cb, napi_call_function(env, js_undefined(env), js_cb, 1, argv, NULL); ASSERT_IF_NAPI_FAIL(status == napi_ok, "Failed to call JS callback", NULL); - ten_nodejs_tsfn_release(info->js_cb); + ten_nodejs_tsfn_release(ctx->js_cb); - ten_nodejs_send_audio_frame_callback_call_info_destroy(info); + ten_nodejs_send_audio_frame_callback_call_ctx_destroy(ctx); } static void proxy_send_audio_frame_callback(ten_env_t *ten_env, @@ -102,10 +102,10 @@ static void proxy_send_audio_frame_callback(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_audio_frame_info_t *info = user_audio_frame; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_send_audio_frame_ctx_t *ctx = user_audio_frame; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); @@ -115,15 +115,14 @@ static void proxy_send_audio_frame_callback(ten_env_t *ten_env, ten_error_copy(cloned_error, err); } - ten_nodejs_send_audio_frame_callback_call_info_t *call_info = - ten_nodejs_send_audio_frame_callback_call_info_create(js_cb, - cloned_error); + ten_nodejs_send_audio_frame_callback_call_ctx_t *call_info = + ten_nodejs_send_audio_frame_callback_call_ctx_create(js_cb, cloned_error); TEN_ASSERT(call_info, "Failed to create callback call info."); - bool rc = ten_nodejs_tsfn_invoke(info->js_cb, call_info); + bool rc = ten_nodejs_tsfn_invoke(ctx->js_cb, call_info); TEN_ASSERT(rc, "Should not happen."); - ten_env_notify_send_audio_frame_info_destroy(info); + ten_env_notify_send_audio_frame_ctx_destroy(ctx); } static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, @@ -132,17 +131,16 @@ static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_audio_frame_info_t *info = user_audio_frame; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_send_audio_frame_ctx_t *ctx = user_audio_frame; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); - bool rc = - ten_env_send_audio_frame(ten_env, info->c_audio_frame, - proxy_send_audio_frame_callback, info, &err); + bool rc = ten_env_send_audio_frame( + ten_env, ctx->c_audio_frame, proxy_send_audio_frame_callback, ctx, &err); if (!rc) { - proxy_send_audio_frame_callback(ten_env, NULL, info, &err); + proxy_send_audio_frame_callback(ten_env, NULL, ctx, &err); } ten_error_deinit(&err); @@ -182,8 +180,8 @@ napi_value ten_nodejs_ten_env_send_audio_frame(napi_env env, ten_error_t err; ten_error_init(&err); - ten_env_notify_send_audio_frame_info_t *notify_info = - ten_env_notify_send_audio_frame_info_create( + ten_env_notify_send_audio_frame_ctx_t *notify_info = + ten_env_notify_send_audio_frame_ctx_create( ten_shared_ptr_clone(audio_frame_bridge->msg.msg), cb_tsfn); TEN_ASSERT(notify_info, "Failed to create notify info."); @@ -203,7 +201,7 @@ napi_value ten_nodejs_ten_env_send_audio_frame(napi_env env, // The JS callback will not be called, so release the TSFN here. ten_nodejs_tsfn_release(cb_tsfn); - ten_env_notify_send_audio_frame_info_destroy(notify_info); + ten_env_notify_send_audio_frame_ctx_destroy(notify_info); } ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_cmd.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_cmd.c index 34724ac02e..44a9126f9e 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_cmd.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_cmd.c @@ -12,92 +12,92 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_send_cmd_info_t { +typedef struct ten_env_notify_send_cmd_ctx_t { ten_shared_ptr_t *c_cmd; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_send_cmd_info_t; +} ten_env_notify_send_cmd_ctx_t; -typedef struct ten_nodejs_send_cmd_callback_call_info_t { +typedef struct ten_nodejs_send_cmd_callback_call_ctx_t { ten_nodejs_tsfn_t *js_cb; ten_shared_ptr_t *c_cmd_result; ten_error_t *error; -} ten_nodejs_send_cmd_callback_call_info_t; +} ten_nodejs_send_cmd_callback_call_ctx_t; -static ten_env_notify_send_cmd_info_t *ten_env_notify_send_cmd_info_create( +static ten_env_notify_send_cmd_ctx_t *ten_env_notify_send_cmd_ctx_create( ten_shared_ptr_t *c_cmd, ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_send_cmd_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_cmd_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_cmd_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_cmd_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_cmd = c_cmd; - info->js_cb = js_cb; + ctx->c_cmd = c_cmd; + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_send_cmd_info_destroy( - ten_env_notify_send_cmd_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_cmd_ctx_destroy( + ten_env_notify_send_cmd_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_cmd) { - ten_shared_ptr_destroy(info->c_cmd); - info->c_cmd = NULL; + if (ctx->c_cmd) { + ten_shared_ptr_destroy(ctx->c_cmd); + ctx->c_cmd = NULL; } - info->js_cb = NULL; + ctx->js_cb = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } -static ten_nodejs_send_cmd_callback_call_info_t * -ten_nodejs_send_cmd_callback_call_info_create(ten_nodejs_tsfn_t *js_cb, - ten_shared_ptr_t *c_cmd_result, - ten_error_t *error) { - ten_nodejs_send_cmd_callback_call_info_t *info = - TEN_MALLOC(sizeof(ten_nodejs_send_cmd_callback_call_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_nodejs_send_cmd_callback_call_ctx_t * +ten_nodejs_send_cmd_callback_call_ctx_create(ten_nodejs_tsfn_t *js_cb, + ten_shared_ptr_t *c_cmd_result, + ten_error_t *error) { + ten_nodejs_send_cmd_callback_call_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_nodejs_send_cmd_callback_call_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->js_cb = js_cb; - info->c_cmd_result = c_cmd_result; - info->error = error; + ctx->js_cb = js_cb; + ctx->c_cmd_result = c_cmd_result; + ctx->error = error; - return info; + return ctx; } -static void ten_nodejs_send_cmd_callback_call_info_destroy( - ten_nodejs_send_cmd_callback_call_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_nodejs_send_cmd_callback_call_ctx_destroy( + ten_nodejs_send_cmd_callback_call_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_cmd_result) { - ten_shared_ptr_destroy(info->c_cmd_result); - info->c_cmd_result = NULL; + if (ctx->c_cmd_result) { + ten_shared_ptr_destroy(ctx->c_cmd_result); + ctx->c_cmd_result = NULL; } - if (info->error) { - ten_error_destroy(info->error); - info->error = NULL; + if (ctx->error) { + ten_error_destroy(ctx->error); + ctx->error = NULL; } - TEN_FREE(info); + TEN_FREE(ctx); } static void tsfn_proxy_send_cmd_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_send_cmd_callback_call_info_t *info = data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_send_cmd_callback_call_ctx_t *ctx = data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_error = NULL; napi_value js_cmd_result = NULL; - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { js_error = js_undefined(env); } - if (info->c_cmd_result) { - js_cmd_result = ten_nodejs_cmd_result_wrap(env, info->c_cmd_result); + if (ctx->c_cmd_result) { + js_cmd_result = ten_nodejs_cmd_result_wrap(env, ctx->c_cmd_result); ASSERT_IF_NAPI_FAIL(js_cmd_result, "Failed to create JS Msg", NULL); } else { js_cmd_result = js_undefined(env); @@ -108,9 +108,9 @@ static void tsfn_proxy_send_cmd_callback(napi_env env, napi_value js_cb, napi_call_function(env, js_undefined(env), js_cb, 2, argv, NULL); ASSERT_IF_NAPI_FAIL(status == napi_ok, "Failed to call JS callback", NULL); - ten_nodejs_tsfn_release(info->js_cb); + ten_nodejs_tsfn_release(ctx->js_cb); - ten_nodejs_send_cmd_callback_call_info_destroy(info); + ten_nodejs_send_cmd_callback_call_ctx_destroy(ctx); } static void proxy_send_cmd_callback(ten_env_t *ten_env, ten_shared_ptr_t *msg, @@ -118,10 +118,10 @@ static void proxy_send_cmd_callback(ten_env_t *ten_env, ten_shared_ptr_t *msg, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_cmd_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_send_cmd_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); @@ -136,15 +136,15 @@ static void proxy_send_cmd_callback(ten_env_t *ten_env, ten_shared_ptr_t *msg, cloned_msg = ten_shared_ptr_clone(msg); } - ten_nodejs_send_cmd_callback_call_info_t *call_info = - ten_nodejs_send_cmd_callback_call_info_create(js_cb, cloned_msg, - cloned_error); + ten_nodejs_send_cmd_callback_call_ctx_t *call_info = + ten_nodejs_send_cmd_callback_call_ctx_create(js_cb, cloned_msg, + cloned_error); TEN_ASSERT(call_info, "Failed to create callback call info."); - bool rc = ten_nodejs_tsfn_invoke(info->js_cb, call_info); + bool rc = ten_nodejs_tsfn_invoke(ctx->js_cb, call_info); TEN_ASSERT(rc, "Should not happen."); - ten_env_notify_send_cmd_info_destroy(info); + ten_env_notify_send_cmd_ctx_destroy(ctx); } static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { @@ -152,16 +152,16 @@ static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_cmd_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_send_cmd_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); - bool rc = ten_env_send_cmd(ten_env, info->c_cmd, proxy_send_cmd_callback, - info, &err); + bool rc = + ten_env_send_cmd(ten_env, ctx->c_cmd, proxy_send_cmd_callback, ctx, &err); if (!rc) { - proxy_send_cmd_callback(ten_env, NULL, info, &err); + proxy_send_cmd_callback(ten_env, NULL, ctx, &err); } ten_error_deinit(&err); @@ -200,8 +200,8 @@ napi_value ten_nodejs_ten_env_send_cmd(napi_env env, napi_callback_info info) { ten_error_t err; ten_error_init(&err); - ten_env_notify_send_cmd_info_t *notify_info = - ten_env_notify_send_cmd_info_create( + ten_env_notify_send_cmd_ctx_t *notify_info = + ten_env_notify_send_cmd_ctx_create( ten_shared_ptr_clone(cmd_bridge->msg.msg), cb_tsfn); TEN_ASSERT(notify_info, "Failed to create notify info."); @@ -221,7 +221,7 @@ napi_value ten_nodejs_ten_env_send_cmd(napi_env env, napi_callback_info info) { // The JS callback will not be called, so release the TSFN here. ten_nodejs_tsfn_release(cb_tsfn); - ten_env_notify_send_cmd_info_destroy(notify_info); + ten_env_notify_send_cmd_ctx_destroy(notify_info); } ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_data.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_data.c index 30e9670f62..9ebf861977 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_data.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_data.c @@ -8,76 +8,76 @@ #include "include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_send_data_info_t { +typedef struct ten_env_notify_send_data_ctx_t { ten_shared_ptr_t *c_data; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_send_data_info_t; +} ten_env_notify_send_data_ctx_t; -typedef struct ten_nodejs_send_data_callback_call_info_t { +typedef struct ten_nodejs_send_data_callback_call_ctx_t { ten_nodejs_tsfn_t *js_cb; ten_error_t *error; -} ten_nodejs_send_data_callback_call_info_t; +} ten_nodejs_send_data_callback_call_ctx_t; -static ten_env_notify_send_data_info_t *ten_env_notify_send_data_info_create( +static ten_env_notify_send_data_ctx_t *ten_env_notify_send_data_ctx_create( ten_shared_ptr_t *c_data, ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_send_data_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_data_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_data_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_data_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_data = c_data; - info->js_cb = js_cb; + ctx->c_data = c_data; + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_send_data_info_destroy( - ten_env_notify_send_data_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_data_ctx_destroy( + ten_env_notify_send_data_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_data) { - ten_shared_ptr_destroy(info->c_data); - info->c_data = NULL; + if (ctx->c_data) { + ten_shared_ptr_destroy(ctx->c_data); + ctx->c_data = NULL; } - info->js_cb = NULL; + ctx->js_cb = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } -static ten_nodejs_send_data_callback_call_info_t * -ten_nodejs_send_data_callback_call_info_create(ten_nodejs_tsfn_t *js_cb, - ten_error_t *error) { - ten_nodejs_send_data_callback_call_info_t *info = - TEN_MALLOC(sizeof(ten_nodejs_send_data_callback_call_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_nodejs_send_data_callback_call_ctx_t * +ten_nodejs_send_data_callback_call_ctx_create(ten_nodejs_tsfn_t *js_cb, + ten_error_t *error) { + ten_nodejs_send_data_callback_call_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_nodejs_send_data_callback_call_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->js_cb = js_cb; - info->error = error; + ctx->js_cb = js_cb; + ctx->error = error; - return info; + return ctx; } -static void ten_nodejs_send_data_callback_call_info_destroy( - ten_nodejs_send_data_callback_call_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_nodejs_send_data_callback_call_ctx_destroy( + ten_nodejs_send_data_callback_call_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->error) { - ten_error_destroy(info->error); - info->error = NULL; + if (ctx->error) { + ten_error_destroy(ctx->error); + ctx->error = NULL; } - TEN_FREE(info); + TEN_FREE(ctx); } static void tsfn_proxy_send_data_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_send_data_callback_call_info_t *info = data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_send_data_callback_call_ctx_t *ctx = data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_error = NULL; - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { js_error = js_undefined(env); @@ -88,9 +88,9 @@ static void tsfn_proxy_send_data_callback(napi_env env, napi_value js_cb, napi_call_function(env, js_undefined(env), js_cb, 1, argv, NULL); ASSERT_IF_NAPI_FAIL(status == napi_ok, "Failed to call JS callback", NULL); - ten_nodejs_tsfn_release(info->js_cb); + ten_nodejs_tsfn_release(ctx->js_cb); - ten_nodejs_send_data_callback_call_info_destroy(info); + ten_nodejs_send_data_callback_call_ctx_destroy(ctx); } static void proxy_send_data_callback(ten_env_t *ten_env, ten_shared_ptr_t *msg, @@ -98,10 +98,10 @@ static void proxy_send_data_callback(ten_env_t *ten_env, ten_shared_ptr_t *msg, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_data_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_send_data_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); @@ -111,14 +111,14 @@ static void proxy_send_data_callback(ten_env_t *ten_env, ten_shared_ptr_t *msg, ten_error_copy(cloned_error, err); } - ten_nodejs_send_data_callback_call_info_t *call_info = - ten_nodejs_send_data_callback_call_info_create(js_cb, cloned_error); + ten_nodejs_send_data_callback_call_ctx_t *call_info = + ten_nodejs_send_data_callback_call_ctx_create(js_cb, cloned_error); TEN_ASSERT(call_info, "Failed to create callback call info."); - bool rc = ten_nodejs_tsfn_invoke(info->js_cb, call_info); + bool rc = ten_nodejs_tsfn_invoke(ctx->js_cb, call_info); TEN_ASSERT(rc, "Should not happen."); - ten_env_notify_send_data_info_destroy(info); + ten_env_notify_send_data_ctx_destroy(ctx); } static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, @@ -127,16 +127,16 @@ static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_data_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_send_data_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); - bool rc = ten_env_send_data(ten_env, info->c_data, proxy_send_data_callback, - info, &err); + bool rc = ten_env_send_data(ten_env, ctx->c_data, proxy_send_data_callback, + ctx, &err); if (!rc) { - proxy_send_data_callback(ten_env, NULL, info, &err); + proxy_send_data_callback(ten_env, NULL, ctx, &err); } ten_error_deinit(&err); @@ -175,8 +175,8 @@ napi_value ten_nodejs_ten_env_send_data(napi_env env, napi_callback_info info) { ten_error_t err; ten_error_init(&err); - ten_env_notify_send_data_info_t *notify_info = - ten_env_notify_send_data_info_create( + ten_env_notify_send_data_ctx_t *notify_info = + ten_env_notify_send_data_ctx_create( ten_shared_ptr_clone(data_bridge->msg.msg), cb_tsfn); TEN_ASSERT(notify_info, "Failed to create notify info."); @@ -196,7 +196,7 @@ napi_value ten_nodejs_ten_env_send_data(napi_env env, napi_callback_info info) { // The JS callback will not be called, so release the TSFN here. ten_nodejs_tsfn_release(cb_tsfn); - ten_env_notify_send_data_info_destroy(notify_info); + ten_env_notify_send_data_ctx_destroy(notify_info); } ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_video_frame.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_video_frame.c index 116cb27eda..55c6daacca 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_video_frame.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_send_video_frame.c @@ -8,78 +8,78 @@ #include "include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_send_video_frame_info_t { +typedef struct ten_env_notify_send_video_frame_ctx_t { ten_shared_ptr_t *c_video_frame; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_send_video_frame_info_t; +} ten_env_notify_send_video_frame_ctx_t; -typedef struct ten_nodejs_send_video_frame_callback_call_info_t { +typedef struct ten_nodejs_send_video_frame_callback_call_ctx_t { ten_nodejs_tsfn_t *js_cb; ten_error_t *error; -} ten_nodejs_send_video_frame_callback_call_info_t; +} ten_nodejs_send_video_frame_callback_call_ctx_t; -static ten_env_notify_send_video_frame_info_t * -ten_env_notify_send_video_frame_info_create(ten_shared_ptr_t *c_video_frame, - ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_send_video_frame_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_video_frame_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_send_video_frame_ctx_t * +ten_env_notify_send_video_frame_ctx_create(ten_shared_ptr_t *c_video_frame, + ten_nodejs_tsfn_t *js_cb) { + ten_env_notify_send_video_frame_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_video_frame_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_video_frame = c_video_frame; - info->js_cb = js_cb; + ctx->c_video_frame = c_video_frame; + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_send_video_frame_info_destroy( - ten_env_notify_send_video_frame_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_video_frame_ctx_destroy( + ten_env_notify_send_video_frame_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_video_frame) { - ten_shared_ptr_destroy(info->c_video_frame); - info->c_video_frame = NULL; + if (ctx->c_video_frame) { + ten_shared_ptr_destroy(ctx->c_video_frame); + ctx->c_video_frame = NULL; } - info->js_cb = NULL; + ctx->js_cb = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } -static ten_nodejs_send_video_frame_callback_call_info_t * -ten_nodejs_send_video_frame_callback_call_info_create(ten_nodejs_tsfn_t *js_cb, - ten_error_t *error) { - ten_nodejs_send_video_frame_callback_call_info_t *info = - TEN_MALLOC(sizeof(ten_nodejs_send_video_frame_callback_call_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_nodejs_send_video_frame_callback_call_ctx_t * +ten_nodejs_send_video_frame_callback_call_ctx_create(ten_nodejs_tsfn_t *js_cb, + ten_error_t *error) { + ten_nodejs_send_video_frame_callback_call_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_nodejs_send_video_frame_callback_call_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->js_cb = js_cb; - info->error = error; + ctx->js_cb = js_cb; + ctx->error = error; - return info; + return ctx; } -static void ten_nodejs_send_video_frame_callback_call_info_destroy( - ten_nodejs_send_video_frame_callback_call_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_nodejs_send_video_frame_callback_call_ctx_destroy( + ten_nodejs_send_video_frame_callback_call_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->error) { - ten_error_destroy(info->error); - info->error = NULL; + if (ctx->error) { + ten_error_destroy(ctx->error); + ctx->error = NULL; } - TEN_FREE(info); + TEN_FREE(ctx); } static void tsfn_proxy_send_video_frame_callback(napi_env env, napi_value js_cb, void *context, void *video_frame) { - ten_nodejs_send_video_frame_callback_call_info_t *info = video_frame; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_send_video_frame_callback_call_ctx_t *ctx = video_frame; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_error = NULL; - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { js_error = js_undefined(env); @@ -90,9 +90,9 @@ static void tsfn_proxy_send_video_frame_callback(napi_env env, napi_value js_cb, napi_call_function(env, js_undefined(env), js_cb, 1, argv, NULL); ASSERT_IF_NAPI_FAIL(status == napi_ok, "Failed to call JS callback", NULL); - ten_nodejs_tsfn_release(info->js_cb); + ten_nodejs_tsfn_release(ctx->js_cb); - ten_nodejs_send_video_frame_callback_call_info_destroy(info); + ten_nodejs_send_video_frame_callback_call_ctx_destroy(ctx); } static void proxy_send_video_frame_callback(ten_env_t *ten_env, @@ -102,10 +102,10 @@ static void proxy_send_video_frame_callback(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_video_frame_info_t *info = user_video_frame; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_send_video_frame_ctx_t *ctx = user_video_frame; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); @@ -115,15 +115,14 @@ static void proxy_send_video_frame_callback(ten_env_t *ten_env, ten_error_copy(cloned_error, err); } - ten_nodejs_send_video_frame_callback_call_info_t *call_info = - ten_nodejs_send_video_frame_callback_call_info_create(js_cb, - cloned_error); + ten_nodejs_send_video_frame_callback_call_ctx_t *call_info = + ten_nodejs_send_video_frame_callback_call_ctx_create(js_cb, cloned_error); TEN_ASSERT(call_info, "Failed to create callback call info."); - bool rc = ten_nodejs_tsfn_invoke(info->js_cb, call_info); + bool rc = ten_nodejs_tsfn_invoke(ctx->js_cb, call_info); TEN_ASSERT(rc, "Should not happen."); - ten_env_notify_send_video_frame_info_destroy(info); + ten_env_notify_send_video_frame_ctx_destroy(ctx); } static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, @@ -132,17 +131,16 @@ static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_video_frame_info_t *info = user_video_frame; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_send_video_frame_ctx_t *ctx = user_video_frame; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); - bool rc = - ten_env_send_video_frame(ten_env, info->c_video_frame, - proxy_send_video_frame_callback, info, &err); + bool rc = ten_env_send_video_frame( + ten_env, ctx->c_video_frame, proxy_send_video_frame_callback, ctx, &err); if (!rc) { - proxy_send_video_frame_callback(ten_env, NULL, info, &err); + proxy_send_video_frame_callback(ten_env, NULL, ctx, &err); } ten_error_deinit(&err); @@ -182,8 +180,8 @@ napi_value ten_nodejs_ten_env_send_video_frame(napi_env env, ten_error_t err; ten_error_init(&err); - ten_env_notify_send_video_frame_info_t *notify_info = - ten_env_notify_send_video_frame_info_create( + ten_env_notify_send_video_frame_ctx_t *notify_info = + ten_env_notify_send_video_frame_ctx_create( ten_shared_ptr_clone(video_frame_bridge->msg.msg), cb_tsfn); TEN_ASSERT(notify_info, "Failed to create notify info."); @@ -203,7 +201,7 @@ napi_value ten_nodejs_ten_env_send_video_frame(napi_env env, // The JS callback will not be called, so release the TSFN here. ten_nodejs_tsfn_release(cb_tsfn); - ten_env_notify_send_video_frame_info_destroy(notify_info); + ten_env_notify_send_video_frame_ctx_destroy(notify_info); } ten_error_deinit(&err); diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property.c index 3bf8192000..0b215e3ddc 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property.c @@ -8,37 +8,37 @@ #include "ten_utils/lib/error.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_set_property_info_t { +typedef struct ten_env_notify_set_property_ctx_t { ten_string_t path; ten_value_t *value; ten_nodejs_tsfn_t *js_cb; -} ten_env_notify_set_property_info_t; +} ten_env_notify_set_property_ctx_t; -static ten_env_notify_set_property_info_t * -ten_env_notify_set_property_info_create(const void *path, ten_value_t *value, - ten_nodejs_tsfn_t *js_cb) { - ten_env_notify_set_property_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_set_property_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_set_property_ctx_t * +ten_env_notify_set_property_ctx_create(const void *path, ten_value_t *value, + ten_nodejs_tsfn_t *js_cb) { + ten_env_notify_set_property_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_set_property_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_from_c_str(&info->path, path, strlen(path)); - info->value = value; - info->js_cb = js_cb; + ten_string_init_from_c_str(&ctx->path, path, strlen(path)); + ctx->value = value; + ctx->js_cb = js_cb; - return info; + return ctx; } -static void ten_env_notify_set_property_info_destroy( - ten_env_notify_set_property_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_set_property_ctx_destroy( + ten_env_notify_set_property_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_string_deinit(&info->path); + ten_string_deinit(&ctx->path); - if (info->value) { - ten_value_destroy(info->value); + if (ctx->value) { + ten_value_destroy(ctx->value); } - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, @@ -47,18 +47,18 @@ static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_set_property_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_set_property_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_nodejs_tsfn_t *js_cb = info->js_cb; + ten_nodejs_tsfn_t *js_cb = ctx->js_cb; TEN_ASSERT(js_cb && ten_nodejs_tsfn_check_integrity(js_cb, false), "Should not happen."); ten_error_t err; ten_error_init(&err); - bool rc = ten_env_set_property(ten_env, ten_string_get_raw_str(&info->path), - info->value, &err); + bool rc = ten_env_set_property(ten_env, ten_string_get_raw_str(&ctx->path), + ctx->value, &err); ten_error_t *cloned_error = NULL; if (!rc) { @@ -66,8 +66,8 @@ static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, ten_error_copy(cloned_error, &err); } - ten_nodejs_set_property_call_info_t *call_info = - ten_nodejs_set_property_call_info_create(js_cb, rc, cloned_error); + ten_nodejs_set_property_call_ctx_t *call_info = + ten_nodejs_set_property_call_ctx_create(js_cb, rc, cloned_error); TEN_ASSERT(call_info, "Should not happen."); bool call_js_rc = ten_nodejs_tsfn_invoke(js_cb, call_info); @@ -75,10 +75,10 @@ static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, if (rc) { // The ownership of the value is transferred to the runtime. - info->value = NULL; + ctx->value = NULL; } - ten_env_notify_set_property_info_destroy(info); + ten_env_notify_set_property_ctx_destroy(ctx); ten_error_deinit(&err); } @@ -94,14 +94,14 @@ bool ten_nodejs_ten_env_set_property_value(ten_nodejs_ten_env_t *self, TEN_ASSERT(cb_tsfn && ten_nodejs_tsfn_check_integrity(cb_tsfn, true), "Invalid argument."); - ten_env_notify_set_property_info_t *info = - ten_env_notify_set_property_info_create(path, value, cb_tsfn); - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_set_property_ctx_t *ctx = + ten_env_notify_set_property_ctx_create(path, value, cb_tsfn); + TEN_ASSERT(ctx, "Should not happen."); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_set_property, info, false, + ten_env_proxy_notify_set_property, ctx, false, error)) { - ten_env_notify_set_property_info_destroy(info); + ten_env_notify_set_property_ctx_destroy(ctx); return false; } diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_from_json.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_from_json.c index d4dad67f46..3b405412f2 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_from_json.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_from_json.c @@ -15,17 +15,17 @@ static void tsfn_proxy_set_property_from_json_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_set_property_call_info_t *info = - (ten_nodejs_set_property_call_info_t *)data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_set_property_call_ctx_t *ctx = + (ten_nodejs_set_property_call_ctx_t *)data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_error = NULL; - if (info->success) { + if (ctx->success) { js_error = js_undefined(env); } else { - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { ten_error_t err; @@ -45,9 +45,9 @@ static void tsfn_proxy_set_property_from_json_callback(napi_env env, status == napi_ok, "Failed to call JS callback of TenEnv::setPropertyFromJson: %d", status); - ten_nodejs_tsfn_release(info->cb_tsfn); + ten_nodejs_tsfn_release(ctx->cb_tsfn); - ten_nodejs_set_property_call_info_destroy(info); + ten_nodejs_set_property_call_ctx_destroy(ctx); } napi_value ten_nodejs_ten_env_set_property_from_json(napi_env env, diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_number.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_number.c index 2f9c56f5de..31dd997a55 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_number.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_number.c @@ -12,17 +12,17 @@ static void tsfn_proxy_set_property_number_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_set_property_call_info_t *info = - (ten_nodejs_set_property_call_info_t *)data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_set_property_call_ctx_t *ctx = + (ten_nodejs_set_property_call_ctx_t *)data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_error = NULL; - if (info->success) { + if (ctx->success) { js_error = js_undefined(env); } else { - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { ten_error_t err; @@ -42,9 +42,9 @@ static void tsfn_proxy_set_property_number_callback(napi_env env, status == napi_ok, "Failed to call JS callback of TenEnv::setPropertyNumber: %d", status); - ten_nodejs_tsfn_release(info->cb_tsfn); + ten_nodejs_tsfn_release(ctx->cb_tsfn); - ten_nodejs_set_property_call_info_destroy(info); + ten_nodejs_set_property_call_ctx_destroy(ctx); } napi_value ten_nodejs_ten_env_set_property_number(napi_env env, diff --git a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_string.c b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_string.c index be2b24a675..7081b4f75b 100644 --- a/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_string.c +++ b/core/src/ten_runtime/binding/nodejs/native/ten_env/ten_env_set_property_string.c @@ -10,17 +10,17 @@ static void tsfn_proxy_set_property_string_callback(napi_env env, napi_value js_cb, void *context, void *data) { - ten_nodejs_set_property_call_info_t *info = - (ten_nodejs_set_property_call_info_t *)data; - TEN_ASSERT(info, "Should not happen."); + ten_nodejs_set_property_call_ctx_t *ctx = + (ten_nodejs_set_property_call_ctx_t *)data; + TEN_ASSERT(ctx, "Should not happen."); napi_value js_error = NULL; - if (info->success) { + if (ctx->success) { js_error = js_undefined(env); } else { - if (info->error) { - js_error = ten_nodejs_create_error(env, info->error); + if (ctx->error) { + js_error = ten_nodejs_create_error(env, ctx->error); ASSERT_IF_NAPI_FAIL(js_error, "Failed to create JS error", NULL); } else { ten_error_t err; @@ -40,9 +40,9 @@ static void tsfn_proxy_set_property_string_callback(napi_env env, status == napi_ok, "Failed to call JS callback of TenEnv::setPropertyNumber: %d", status); - ten_nodejs_tsfn_release(info->cb_tsfn); + ten_nodejs_tsfn_release(ctx->cb_tsfn); - ten_nodejs_set_property_call_info_destroy(info); + ten_nodejs_set_property_call_ctx_destroy(ctx); } napi_value ten_nodejs_ten_env_set_property_string(napi_env env, 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 b43f363341..08e0d08fb9 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 @@ -16,34 +16,34 @@ #include "ten_utils/value/value.h" #include "ten_utils/value/value_get.h" -typedef struct ten_env_notify_get_property_info_t { +typedef struct ten_env_notify_get_property_ctx_t { ten_string_t path; ten_value_t *c_value; ten_event_t *completed; -} ten_env_notify_get_property_info_t; +} ten_env_notify_get_property_ctx_t; -static ten_env_notify_get_property_info_t * -ten_env_notify_get_property_info_create(const void *path) { - ten_env_notify_get_property_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_get_property_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_get_property_ctx_t * +ten_env_notify_get_property_ctx_create(const void *path) { + ten_env_notify_get_property_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_get_property_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_formatted(&info->path, "%s", path); - info->c_value = NULL; - info->completed = ten_event_create(0, 1); + ten_string_init_formatted(&ctx->path, "%s", path); + ctx->c_value = NULL; + ctx->completed = ten_event_create(0, 1); - return info; + return ctx; } -static void ten_env_notify_get_property_info_destroy( - ten_env_notify_get_property_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_get_property_ctx_destroy( + ten_env_notify_get_property_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_string_deinit(&info->path); - info->c_value = NULL; - ten_event_destroy(info->completed); + ten_string_deinit(&ctx->path); + ctx->c_value = NULL; + ten_event_destroy(ctx->completed); - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, @@ -52,21 +52,21 @@ static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_get_property_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_get_property_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); ten_value_t *c_value = - ten_env_peek_property(ten_env, ten_string_get_raw_str(&info->path), &err); + ten_env_peek_property(ten_env, ten_string_get_raw_str(&ctx->path), &err); // Because this value will be passed out of the TEN world and back into the // Python world, and these two worlds are in different threads, copy semantics // are used to avoid thread safety issues. - info->c_value = c_value ? ten_value_clone(c_value) : NULL; + ctx->c_value = c_value ? ten_value_clone(c_value) : NULL; - ten_event_set(info->completed); + ten_event_set(ctx->completed); ten_error_deinit(&err); } @@ -80,24 +80,24 @@ static ten_value_t *ten_py_ten_property_get_and_check_if_exists( ten_error_t err; ten_error_init(&err); - ten_env_notify_get_property_info_t *info = - ten_env_notify_get_property_info_create(path); + ten_env_notify_get_property_ctx_t *ctx = + ten_env_notify_get_property_ctx_create(path); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_get_property, info, false, + ten_env_proxy_notify_get_property, ctx, false, &err)) { goto done; } PyThreadState *saved_py_thread_state = PyEval_SaveThread(); - ten_event_wait(info->completed, -1); + ten_event_wait(ctx->completed, -1); PyEval_RestoreThread(saved_py_thread_state); - c_value = info->c_value; + c_value = ctx->c_value; done: ten_error_deinit(&err); - ten_env_notify_get_property_info_destroy(info); + ten_env_notify_get_property_ctx_destroy(ctx); return c_value; } diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property_async.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property_async.c index c84624647b..e8d1b0be80 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property_async.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property_async.c @@ -21,41 +21,41 @@ typedef void (*ten_py_get_property_cb)(ten_env_t *ten_env, ten_value_t *value, ten_error_t *error, PyObject *py_cb_func); -typedef struct ten_env_notify_get_property_async_info_t { +typedef struct ten_env_notify_get_property_async_ctx_t { ten_string_t path; PyObject *py_cb_func; ten_py_get_property_cb cb; -} ten_env_notify_get_property_async_info_t; +} ten_env_notify_get_property_async_ctx_t; -static ten_env_notify_get_property_async_info_t * -ten_env_notify_get_property_async_info_create(const char *path, - PyObject *py_cb_func, - ten_py_get_property_cb cb) { - ten_env_notify_get_property_async_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_get_property_async_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_get_property_async_ctx_t * +ten_env_notify_get_property_async_ctx_create(const char *path, + PyObject *py_cb_func, + ten_py_get_property_cb cb) { + ten_env_notify_get_property_async_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_get_property_async_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_formatted(&info->path, "%s", path); - info->py_cb_func = py_cb_func; - info->cb = cb; + ten_string_init_formatted(&ctx->path, "%s", path); + ctx->py_cb_func = py_cb_func; + ctx->cb = cb; if (py_cb_func != NULL) { Py_INCREF(py_cb_func); } - return info; + return ctx; } -static void ten_env_notify_get_property_async_info_destroy( - ten_env_notify_get_property_async_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_get_property_async_ctx_destroy( + ten_env_notify_get_property_async_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_string_deinit(&info->path); + ten_string_deinit(&ctx->path); - info->py_cb_func = NULL; - info->cb = NULL; + ctx->py_cb_func = NULL; + ctx->cb = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, @@ -64,23 +64,23 @@ static void ten_env_proxy_notify_get_property(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_get_property_async_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_get_property_async_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); ten_value_t *c_value = - ten_env_peek_property(ten_env, ten_string_get_raw_str(&info->path), &err); + ten_env_peek_property(ten_env, ten_string_get_raw_str(&ctx->path), &err); if (c_value) { - info->cb(ten_env, c_value, NULL, info->py_cb_func); + ctx->cb(ten_env, c_value, NULL, ctx->py_cb_func); } else { - info->cb(ten_env, NULL, &err, info->py_cb_func); + ctx->cb(ten_env, NULL, &err, ctx->py_cb_func); } ten_error_deinit(&err); - ten_env_notify_get_property_async_info_destroy(info); + ten_env_notify_get_property_async_ctx_destroy(ctx); } static bool ten_py_get_property_async(ten_py_ten_env_t *self, const char *path, @@ -91,16 +91,16 @@ static bool ten_py_get_property_async(ten_py_ten_env_t *self, const char *path, bool success = true; - ten_env_notify_get_property_async_info_t *info = - ten_env_notify_get_property_async_info_create(path, py_cb_func, cb); + ten_env_notify_get_property_async_ctx_t *ctx = + ten_env_notify_get_property_async_ctx_create(path, py_cb_func, cb); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_get_property, info, false, + ten_env_proxy_notify_get_property, ctx, false, error)) { if (py_cb_func) { Py_XDECREF(py_cb_func); } - ten_env_notify_get_property_async_info_destroy(info); + ten_env_notify_get_property_async_ctx_destroy(ctx); success = false; ten_py_raise_py_runtime_error_exception("Failed to get property"); } 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 1fc8dc9fe3..d2b11afbeb 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 @@ -13,30 +13,30 @@ #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_init_property_info_t { +typedef struct ten_env_notify_init_property_ctx_t { ten_string_t value; ten_event_t *completed; -} ten_env_notify_init_property_info_t; +} ten_env_notify_init_property_ctx_t; -typedef struct ten_env_notify_init_property_async_info_t { +typedef struct ten_env_notify_init_property_async_ctx_t { ten_string_t value; PyObject *py_cb_func; -} ten_env_notify_init_property_async_info_t; +} ten_env_notify_init_property_async_ctx_t; -static ten_env_notify_init_property_info_t * -ten_env_notify_init_property_info_create(const void *value, size_t value_len) { - ten_env_notify_init_property_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_init_property_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_init_property_ctx_t * +ten_env_notify_init_property_ctx_create(const void *value, size_t value_len) { + ten_env_notify_init_property_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_init_property_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_formatted(&info->value, "%.*s", value_len, value); - info->completed = ten_event_create(0, 1); + ten_string_init_formatted(&ctx->value, "%.*s", value_len, value); + ctx->completed = ten_event_create(0, 1); - return info; + return ctx; } -static void ten_env_notify_init_property_info_destroy( - ten_env_notify_init_property_info_t *self) { +static void ten_env_notify_init_property_ctx_destroy( + ten_env_notify_init_property_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); ten_string_deinit(&self->value); @@ -45,26 +45,26 @@ static void ten_env_notify_init_property_info_destroy( TEN_FREE(self); } -static ten_env_notify_init_property_async_info_t * -ten_env_notify_init_property_async_info_create(const void *value, - size_t value_len, - PyObject *py_cb_func) { - ten_env_notify_init_property_async_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_init_property_async_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_init_property_async_ctx_t * +ten_env_notify_init_property_async_ctx_create(const void *value, + size_t value_len, + PyObject *py_cb_func) { + ten_env_notify_init_property_async_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_init_property_async_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_formatted(&info->value, "%.*s", value_len, value); - info->py_cb_func = py_cb_func; + ten_string_init_formatted(&ctx->value, "%.*s", value_len, value); + ctx->py_cb_func = py_cb_func; if (py_cb_func != NULL) { Py_INCREF(py_cb_func); } - return info; + return ctx; } -static void ten_env_notify_init_property_async_info_destroy( - ten_env_notify_init_property_async_info_t *self) { +static void ten_env_notify_init_property_async_ctx_destroy( + ten_env_notify_init_property_async_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); ten_string_deinit(&self->value); @@ -79,16 +79,16 @@ static void ten_env_proxy_notify_init_property_from_json(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_init_property_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_init_property_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); - ten_env_init_property_from_json(ten_env, ten_string_get_raw_str(&info->value), + ten_env_init_property_from_json(ten_env, ten_string_get_raw_str(&ctx->value), &err); - ten_event_set(info->completed); + ten_event_set(ctx->completed); ten_error_deinit(&err); } @@ -99,14 +99,14 @@ static void ten_env_proxy_notify_init_property_from_json_async( TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_init_property_async_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_init_property_async_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); bool rc = ten_env_init_property_from_json( - ten_env, ten_string_get_raw_str(&info->value), &err); + ten_env, ten_string_get_raw_str(&ctx->value), &err); // About to call the Python function, so it's necessary to ensure that the // GIL @@ -125,14 +125,14 @@ static void ten_env_proxy_notify_init_property_from_json_async( arglist = Py_BuildValue("(O)", py_error); } - PyObject *result = PyObject_CallObject(info->py_cb_func, arglist); + PyObject *result = PyObject_CallObject(ctx->py_cb_func, arglist); Py_XDECREF(result); // Ensure cleanup if an error occurred. bool err_occurred = ten_py_check_and_clear_py_error(); TEN_ASSERT(!err_occurred, "Should not happen."); Py_XDECREF(arglist); - Py_XDECREF(info->py_cb_func); + Py_XDECREF(ctx->py_cb_func); if (py_error) { ten_py_error_invalidate(py_error); @@ -142,7 +142,7 @@ static void ten_env_proxy_notify_init_property_from_json_async( ten_error_deinit(&err); - ten_env_notify_init_property_async_info_destroy(info); + ten_env_notify_init_property_async_ctx_destroy(ctx); } PyObject *ten_py_ten_env_init_property_from_json(PyObject *self, @@ -166,21 +166,21 @@ PyObject *ten_py_ten_env_init_property_from_json(PyObject *self, ten_error_t err; ten_error_init(&err); - ten_env_notify_init_property_info_t *info = - ten_env_notify_init_property_info_create(json_str, strlen(json_str)); + ten_env_notify_init_property_ctx_t *ctx = + ten_env_notify_init_property_ctx_create(json_str, strlen(json_str)); if (!ten_env_proxy_notify(py_ten_env->c_ten_env_proxy, - ten_env_proxy_notify_init_property_from_json, info, + ten_env_proxy_notify_init_property_from_json, ctx, false, NULL)) { goto done; } PyThreadState *saved_py_thread_state = PyEval_SaveThread(); - ten_event_wait(info->completed, -1); + ten_event_wait(ctx->completed, -1); PyEval_RestoreThread(saved_py_thread_state); done: - ten_env_notify_init_property_info_destroy(info); + ten_env_notify_init_property_ctx_destroy(ctx); ten_error_deinit(&err); Py_RETURN_NONE; @@ -218,15 +218,15 @@ PyObject *ten_py_ten_env_init_property_from_json_async(PyObject *self, bool success = true; - ten_env_notify_init_property_async_info_t *info = - ten_env_notify_init_property_async_info_create(json_str, strlen(json_str), - py_cb_func); + ten_env_notify_init_property_async_ctx_t *ctx = + ten_env_notify_init_property_async_ctx_create(json_str, strlen(json_str), + py_cb_func); if (!ten_env_proxy_notify(py_ten_env->c_ten_env_proxy, ten_env_proxy_notify_init_property_from_json_async, - info, false, &err)) { + ctx, false, &err)) { Py_XDECREF(py_cb_func); - ten_env_notify_init_property_async_info_destroy(info); + ten_env_notify_init_property_async_ctx_destroy(ctx); ten_py_raise_py_value_error_exception("Failed to init property from json"); 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 47d1479854..afad357bcc 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 @@ -13,38 +13,37 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_log_info_t { +typedef struct ten_env_notify_log_ctx_t { int32_t level; const char *func_name; const char *file_name; size_t line_no; const char *msg; ten_event_t *completed; -} ten_env_notify_log_info_t; +} ten_env_notify_log_ctx_t; -static ten_env_notify_log_info_t *ten_env_notify_log_info_create( +static ten_env_notify_log_ctx_t *ten_env_notify_log_ctx_create( int32_t level, const char *func_name, const char *file_name, size_t line_no, const char *msg) { - ten_env_notify_log_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_log_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); - - info->level = level; - info->func_name = func_name; - info->file_name = file_name; - info->line_no = line_no; - info->msg = msg; - info->completed = ten_event_create(0, 1); - - return info; + ten_env_notify_log_ctx_t *ctx = TEN_MALLOC(sizeof(ten_env_notify_log_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); + + ctx->level = level; + ctx->func_name = func_name; + ctx->file_name = file_name; + ctx->line_no = line_no; + ctx->msg = msg; + ctx->completed = ten_event_create(0, 1); + + return ctx; } -static void ten_env_notify_log_info_destroy(ten_env_notify_log_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_log_ctx_destroy(ten_env_notify_log_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - ten_event_destroy(info->completed); + ten_event_destroy(ctx->completed); - TEN_FREE(info); + TEN_FREE(ctx); } static void ten_env_proxy_notify_log(ten_env_t *ten_env, void *user_data) { @@ -52,13 +51,13 @@ static void ten_env_proxy_notify_log(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_log_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_log_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - ten_env_log(ten_env, info->level, info->func_name, info->file_name, - info->line_no, info->msg); + ten_env_log(ten_env, ctx->level, ctx->func_name, ctx->file_name, ctx->line_no, + ctx->msg); - ten_event_set(info->completed); + ten_event_set(ctx->completed); } PyObject *ten_py_ten_env_log(PyObject *self, PyObject *args) { @@ -85,8 +84,8 @@ PyObject *ten_py_ten_env_log(PyObject *self, PyObject *args) { ten_error_t err; ten_error_init(&err); - ten_env_notify_log_info_t *info = - ten_env_notify_log_info_create(level, func_name, file_name, line_no, msg); + ten_env_notify_log_ctx_t *ctx = + ten_env_notify_log_ctx_create(level, func_name, file_name, line_no, msg); if (py_ten_env->c_ten_env->attach_to == TEN_ENV_ATTACH_TO_ADDON) { // TODO(Wei): This function is currently specifically designed for the addon @@ -95,23 +94,23 @@ PyObject *ten_py_ten_env_log(PyObject *self, PyObject *args) { // in the future, these hacks made specifically for the addon can be // completely removed, and comprehensive thread safety checking can be // implemented. - ten_env_log_without_check_thread(py_ten_env->c_ten_env, info->level, - info->func_name, info->file_name, - info->line_no, info->msg); + ten_env_log_without_check_thread(py_ten_env->c_ten_env, ctx->level, + ctx->func_name, ctx->file_name, + ctx->line_no, ctx->msg); } else { if (!ten_env_proxy_notify(py_ten_env->c_ten_env_proxy, - ten_env_proxy_notify_log, info, false, &err)) { + ten_env_proxy_notify_log, ctx, false, &err)) { goto done; } PyThreadState *saved_py_thread_state = PyEval_SaveThread(); - ten_event_wait(info->completed, -1); + ten_event_wait(ctx->completed, -1); PyEval_RestoreThread(saved_py_thread_state); } done: ten_error_deinit(&err); - ten_env_notify_log_info_destroy(info); + ten_env_notify_log_ctx_destroy(ctx); Py_RETURN_NONE; } 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 239494c271..e5021016b0 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 @@ -14,50 +14,50 @@ #include "ten_utils/lib/error.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_return_result_info_t { +typedef struct ten_env_notify_return_result_ctx_t { ten_shared_ptr_t *c_cmd; ten_shared_ptr_t *c_target_cmd; PyObject *py_cb_func; -} ten_env_notify_return_result_info_t; +} ten_env_notify_return_result_ctx_t; -static ten_env_notify_return_result_info_t * -ten_env_notify_return_result_info_create(ten_shared_ptr_t *c_cmd, - ten_shared_ptr_t *c_target_cmd, - PyObject *py_cb_func) { +static ten_env_notify_return_result_ctx_t * +ten_env_notify_return_result_ctx_create(ten_shared_ptr_t *c_cmd, + ten_shared_ptr_t *c_target_cmd, + PyObject *py_cb_func) { TEN_ASSERT(c_cmd, "Invalid argument."); - ten_env_notify_return_result_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_return_result_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_return_result_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_return_result_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_cmd = c_cmd; - info->c_target_cmd = c_target_cmd; - info->py_cb_func = py_cb_func; + ctx->c_cmd = c_cmd; + ctx->c_target_cmd = c_target_cmd; + ctx->py_cb_func = py_cb_func; if (py_cb_func) { Py_INCREF(py_cb_func); } - return info; + return ctx; } -static void ten_env_notify_return_result_info_destroy( - ten_env_notify_return_result_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_return_result_ctx_destroy( + ten_env_notify_return_result_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_cmd) { - ten_shared_ptr_destroy(info->c_cmd); - info->c_cmd = NULL; + if (ctx->c_cmd) { + ten_shared_ptr_destroy(ctx->c_cmd); + ctx->c_cmd = NULL; } - if (info->c_target_cmd) { - ten_shared_ptr_destroy(info->c_target_cmd); - info->c_target_cmd = NULL; + if (ctx->c_target_cmd) { + ten_shared_ptr_destroy(ctx->c_target_cmd); + ctx->c_target_cmd = NULL; } - info->py_cb_func = NULL; + ctx->py_cb_func = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_return_result_callback(ten_env_t *ten_env, @@ -108,30 +108,30 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_return_result_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_return_result_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); bool rc = false; - if (info->py_cb_func == NULL) { - if (info->c_target_cmd) { - rc = ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, NULL, + if (ctx->py_cb_func == NULL) { + if (ctx->c_target_cmd) { + rc = ten_env_return_result(ten_env, ctx->c_cmd, ctx->c_target_cmd, NULL, NULL, &err); } else { - rc = ten_env_return_result_directly(ten_env, info->c_cmd, NULL, NULL, - &err); + rc = + ten_env_return_result_directly(ten_env, ctx->c_cmd, NULL, NULL, &err); } } else { - if (info->c_target_cmd) { - rc = ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, - proxy_return_result_callback, info->py_cb_func, + if (ctx->c_target_cmd) { + rc = ten_env_return_result(ten_env, ctx->c_cmd, ctx->c_target_cmd, + proxy_return_result_callback, ctx->py_cb_func, &err); } else { - rc = ten_env_return_result_directly(ten_env, info->c_cmd, + rc = ten_env_return_result_directly(ten_env, ctx->c_cmd, proxy_return_result_callback, - info->py_cb_func, &err); + ctx->py_cb_func, &err); } if (!rc) { @@ -148,7 +148,7 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, PyObject *arglist = Py_BuildValue("(OO)", py_ten_env->actual_py_ten_env, py_err); - PyObject *result = PyObject_CallObject(info->py_cb_func, arglist); + PyObject *result = PyObject_CallObject(ctx->py_cb_func, arglist); Py_XDECREF(result); // Ensure cleanup if an error occurred. bool err_occurred = ten_py_check_and_clear_py_error(); @@ -166,7 +166,7 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, ten_error_deinit(&err); - ten_env_notify_return_result_info_destroy(info); + ten_env_notify_return_result_ctx_destroy(ctx); } PyObject *ten_py_ten_env_return_result(PyObject *self, PyObject *args) { @@ -202,15 +202,15 @@ PyObject *ten_py_ten_env_return_result(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_result_cmd = ten_shared_ptr_clone(py_cmd_result->msg.c_msg); - ten_env_notify_return_result_info_t *notify_info = - ten_env_notify_return_result_info_create(c_result_cmd, c_target_cmd, - cb_func); + ten_env_notify_return_result_ctx_t *notify_info = + ten_env_notify_return_result_ctx_create(c_result_cmd, c_target_cmd, + cb_func); bool rc = ten_env_proxy_notify(py_ten_env->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); + ten_env_notify_return_result_ctx_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to return result."); goto done; @@ -266,13 +266,13 @@ PyObject *ten_py_ten_env_return_result_directly(PyObject *self, ten_shared_ptr_t *c_result_cmd = ten_shared_ptr_clone(py_cmd_result->msg.c_msg); - ten_env_notify_return_result_info_t *notify_info = - ten_env_notify_return_result_info_create(c_result_cmd, NULL, cb_func); + ten_env_notify_return_result_ctx_t *notify_info = + ten_env_notify_return_result_ctx_create(c_result_cmd, NULL, cb_func); if (!ten_env_proxy_notify(py_ten_env->c_ten_env_proxy, ten_env_proxy_notify_return_result, notify_info, false, &err)) { - ten_env_notify_return_result_info_destroy(notify_info); + ten_env_notify_return_result_ctx_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception( "Failed to return result directly."); 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 d8c5382825..7e399605eb 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 @@ -12,42 +12,42 @@ #include "ten_utils/macro/mark.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_send_audio_frame_info_t { +typedef struct ten_env_notify_send_audio_frame_ctx_t { ten_shared_ptr_t *c_audio_frame; PyObject *py_cb_func; -} ten_env_notify_send_audio_frame_info_t; +} ten_env_notify_send_audio_frame_ctx_t; -static ten_env_notify_send_audio_frame_info_t * -ten_env_notify_send_audio_frame_info_create(ten_shared_ptr_t *c_audio_frame, - PyObject *py_cb_func) { +static ten_env_notify_send_audio_frame_ctx_t * +ten_env_notify_send_audio_frame_ctx_create(ten_shared_ptr_t *c_audio_frame, + PyObject *py_cb_func) { TEN_ASSERT(c_audio_frame, "Invalid argument."); - ten_env_notify_send_audio_frame_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_audio_frame_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_audio_frame_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_audio_frame_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_audio_frame = c_audio_frame; - info->py_cb_func = py_cb_func; + ctx->c_audio_frame = c_audio_frame; + ctx->py_cb_func = py_cb_func; if (py_cb_func != NULL) { Py_INCREF(py_cb_func); } - return info; + return ctx; } -static void ten_env_notify_send_audio_frame_info_destroy( - ten_env_notify_send_audio_frame_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_audio_frame_ctx_destroy( + ten_env_notify_send_audio_frame_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_audio_frame) { - ten_shared_ptr_destroy(info->c_audio_frame); - info->c_audio_frame = NULL; + if (ctx->c_audio_frame) { + ten_shared_ptr_destroy(ctx->c_audio_frame); + ctx->c_audio_frame = NULL; } - info->py_cb_func = NULL; + ctx->py_cb_func = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_send_audio_frame_callback( @@ -99,7 +99,7 @@ static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_audio_frame_info_t *notify_info = notify_info_; + ten_env_notify_send_audio_frame_ctx_t *notify_info = notify_info_; TEN_ASSERT(notify_info, "Invalid argument."); ten_error_t err; @@ -143,7 +143,7 @@ static void ten_env_proxy_notify_send_audio_frame(ten_env_t *ten_env, ten_error_deinit(&err); - ten_env_notify_send_audio_frame_info_destroy(notify_info); + ten_env_notify_send_audio_frame_ctx_destroy(notify_info); } PyObject *ten_py_ten_env_send_audio_frame(PyObject *self, PyObject *args) { @@ -174,8 +174,8 @@ PyObject *ten_py_ten_env_send_audio_frame(PyObject *self, PyObject *args) { ten_shared_ptr_t *cloned_audio_frame = ten_shared_ptr_clone(py_audio_frame->msg.c_msg); - ten_env_notify_send_audio_frame_info_t *notify_info = - ten_env_notify_send_audio_frame_info_create(cloned_audio_frame, cb_func); + ten_env_notify_send_audio_frame_ctx_t *notify_info = + ten_env_notify_send_audio_frame_ctx_create(cloned_audio_frame, cb_func); if (!ten_env_proxy_notify(py_ten_env->c_ten_env_proxy, ten_env_proxy_notify_send_audio_frame, notify_info, @@ -184,7 +184,7 @@ PyObject *ten_py_ten_env_send_audio_frame(PyObject *self, PyObject *args) { Py_XDECREF(cb_func); } - ten_env_notify_send_audio_frame_info_destroy(notify_info); + ten_env_notify_send_audio_frame_ctx_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to send audio_frame."); goto done; 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 a116143826..fa3a19a94a 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 @@ -18,43 +18,43 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_send_cmd_info_t { +typedef struct ten_env_notify_send_cmd_ctx_t { ten_shared_ptr_t *c_cmd; PyObject *py_cb_func; bool is_ex; -} ten_env_notify_send_cmd_info_t; +} ten_env_notify_send_cmd_ctx_t; -static ten_env_notify_send_cmd_info_t *ten_env_notify_send_cmd_info_create( +static ten_env_notify_send_cmd_ctx_t *ten_env_notify_send_cmd_ctx_create( ten_shared_ptr_t *c_cmd, PyObject *py_cb_func, bool is_ex) { TEN_ASSERT(c_cmd, "Invalid argument."); - ten_env_notify_send_cmd_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_cmd_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_cmd_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_cmd_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_cmd = c_cmd; - info->py_cb_func = py_cb_func; - info->is_ex = is_ex; + ctx->c_cmd = c_cmd; + ctx->py_cb_func = py_cb_func; + ctx->is_ex = is_ex; if (py_cb_func != NULL) { Py_INCREF(py_cb_func); } - return info; + return ctx; } -static void ten_env_notify_send_cmd_info_destroy( - ten_env_notify_send_cmd_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_cmd_ctx_destroy( + ten_env_notify_send_cmd_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_cmd) { - ten_shared_ptr_destroy(info->c_cmd); - info->c_cmd = NULL; + if (ctx->c_cmd) { + ten_shared_ptr_destroy(ctx->c_cmd); + ctx->c_cmd = NULL; } - info->py_cb_func = NULL; + ctx->py_cb_func = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_send_xxx_callback(ten_env_t *ten_env, @@ -120,7 +120,7 @@ static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_cmd_info_t *notify_info = user_data; + ten_env_notify_send_cmd_ctx_t *notify_info = user_data; ten_error_t err; ten_error_init(&err); @@ -168,7 +168,7 @@ static void ten_env_proxy_notify_send_cmd(ten_env_t *ten_env, void *user_data) { ten_error_deinit(&err); - ten_env_notify_send_cmd_info_destroy(notify_info); + ten_env_notify_send_cmd_ctx_destroy(notify_info); } PyObject *ten_py_ten_env_send_cmd(PyObject *self, PyObject *args) { @@ -204,8 +204,8 @@ PyObject *ten_py_ten_env_send_cmd(PyObject *self, PyObject *args) { } ten_shared_ptr_t *cloned_cmd = ten_shared_ptr_clone(py_cmd->msg.c_msg); - ten_env_notify_send_cmd_info_t *notify_info = - ten_env_notify_send_cmd_info_create(cloned_cmd, cb_func, is_ex); + ten_env_notify_send_cmd_ctx_t *notify_info = + ten_env_notify_send_cmd_ctx_create(cloned_cmd, cb_func, is_ex); if (!ten_env_proxy_notify(py_ten_env->c_ten_env_proxy, ten_env_proxy_notify_send_cmd, notify_info, false, @@ -214,7 +214,7 @@ PyObject *ten_py_ten_env_send_cmd(PyObject *self, PyObject *args) { Py_XDECREF(cb_func); } - ten_env_notify_send_cmd_info_destroy(notify_info); + ten_env_notify_send_cmd_ctx_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to send cmd."); goto done; 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 330b3356cf..f5c00d0c05 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 @@ -12,41 +12,41 @@ #include "ten_utils/macro/mark.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_send_data_info_t { +typedef struct ten_env_notify_send_data_ctx_t { ten_shared_ptr_t *c_data; PyObject *py_cb_func; -} ten_env_notify_send_data_info_t; +} ten_env_notify_send_data_ctx_t; -static ten_env_notify_send_data_info_t *ten_env_notify_send_data_info_create( +static ten_env_notify_send_data_ctx_t *ten_env_notify_send_data_ctx_create( ten_shared_ptr_t *c_data, PyObject *py_cb_func) { TEN_ASSERT(c_data, "Invalid argument."); - ten_env_notify_send_data_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_data_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_data_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_data_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_data = c_data; - info->py_cb_func = py_cb_func; + ctx->c_data = c_data; + ctx->py_cb_func = py_cb_func; if (py_cb_func != NULL) { Py_INCREF(py_cb_func); } - return info; + return ctx; } -static void ten_env_notify_send_data_info_destroy( - ten_env_notify_send_data_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_data_ctx_destroy( + ten_env_notify_send_data_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_data) { - ten_shared_ptr_destroy(info->c_data); - info->c_data = NULL; + if (ctx->c_data) { + ten_shared_ptr_destroy(ctx->c_data); + ctx->c_data = NULL; } - info->py_cb_func = NULL; + ctx->py_cb_func = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_send_data_callback(ten_env_t *ten_env, @@ -98,7 +98,7 @@ static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_data_info_t *notify_info = user_data; + ten_env_notify_send_data_ctx_t *notify_info = user_data; TEN_ASSERT(notify_info, "Invalid argument."); ten_error_t err; @@ -142,7 +142,7 @@ static void ten_env_proxy_notify_send_data(ten_env_t *ten_env, ten_error_deinit(&err); - ten_env_notify_send_data_info_destroy(notify_info); + ten_env_notify_send_data_ctx_destroy(notify_info); } PyObject *ten_py_ten_env_send_data(PyObject *self, PyObject *args) { @@ -172,8 +172,8 @@ PyObject *ten_py_ten_env_send_data(PyObject *self, PyObject *args) { } ten_shared_ptr_t *cloned_data = ten_shared_ptr_clone(py_data->msg.c_msg); - ten_env_notify_send_data_info_t *notify_info = - ten_env_notify_send_data_info_create(cloned_data, cb_func); + ten_env_notify_send_data_ctx_t *notify_info = + ten_env_notify_send_data_ctx_create(cloned_data, cb_func); if (!ten_env_proxy_notify(py_ten_env->c_ten_env_proxy, ten_env_proxy_notify_send_data, notify_info, false, @@ -182,7 +182,7 @@ PyObject *ten_py_ten_env_send_data(PyObject *self, PyObject *args) { Py_XDECREF(cb_func); } - ten_env_notify_send_data_info_destroy(notify_info); + ten_env_notify_send_data_ctx_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to send data."); goto done; 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 0697e2abe2..3774abb309 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 @@ -12,42 +12,42 @@ #include "ten_utils/macro/mark.h" #include "ten_utils/macro/memory.h" -typedef struct ten_env_notify_send_video_frame_info_t { +typedef struct ten_env_notify_send_video_frame_ctx_t { ten_shared_ptr_t *c_video_frame; PyObject *py_cb_func; -} ten_env_notify_send_video_frame_info_t; +} ten_env_notify_send_video_frame_ctx_t; -static ten_env_notify_send_video_frame_info_t * -ten_env_notify_send_video_frame_info_create(ten_shared_ptr_t *c_video_frame, - PyObject *py_cb_func) { +static ten_env_notify_send_video_frame_ctx_t * +ten_env_notify_send_video_frame_ctx_create(ten_shared_ptr_t *c_video_frame, + PyObject *py_cb_func) { TEN_ASSERT(c_video_frame, "Invalid argument."); - ten_env_notify_send_video_frame_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_send_video_frame_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_env_notify_send_video_frame_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_send_video_frame_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->c_video_frame = c_video_frame; - info->py_cb_func = py_cb_func; + ctx->c_video_frame = c_video_frame; + ctx->py_cb_func = py_cb_func; if (py_cb_func != NULL) { Py_INCREF(py_cb_func); } - return info; + return ctx; } -static void ten_env_notify_send_video_frame_info_destroy( - ten_env_notify_send_video_frame_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); +static void ten_env_notify_send_video_frame_ctx_destroy( + ten_env_notify_send_video_frame_ctx_t *ctx) { + TEN_ASSERT(ctx, "Invalid argument."); - if (info->c_video_frame) { - ten_shared_ptr_destroy(info->c_video_frame); - info->c_video_frame = NULL; + if (ctx->c_video_frame) { + ten_shared_ptr_destroy(ctx->c_video_frame); + ctx->c_video_frame = NULL; } - info->py_cb_func = NULL; + ctx->py_cb_func = NULL; - TEN_FREE(info); + TEN_FREE(ctx); } static void proxy_send_video_frame_callback( @@ -99,7 +99,7 @@ static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_send_video_frame_info_t *notify_info = notify_info_; + ten_env_notify_send_video_frame_ctx_t *notify_info = notify_info_; TEN_ASSERT(notify_info, "Invalid argument."); ten_error_t err; @@ -143,7 +143,7 @@ static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, ten_error_deinit(&err); - ten_env_notify_send_video_frame_info_destroy(notify_info); + ten_env_notify_send_video_frame_ctx_destroy(notify_info); } PyObject *ten_py_ten_env_send_video_frame(PyObject *self, PyObject *args) { @@ -174,8 +174,8 @@ PyObject *ten_py_ten_env_send_video_frame(PyObject *self, PyObject *args) { ten_shared_ptr_t *cloned_video_frame = ten_shared_ptr_clone(py_video_frame->msg.c_msg); - ten_env_notify_send_video_frame_info_t *notify_info = - ten_env_notify_send_video_frame_info_create(cloned_video_frame, cb_func); + ten_env_notify_send_video_frame_ctx_t *notify_info = + ten_env_notify_send_video_frame_ctx_create(cloned_video_frame, cb_func); if (!ten_env_proxy_notify(py_ten_env->c_ten_env_proxy, ten_env_proxy_notify_send_video_frame, notify_info, @@ -184,7 +184,7 @@ PyObject *ten_py_ten_env_send_video_frame(PyObject *self, PyObject *args) { Py_XDECREF(cb_func); } - ten_env_notify_send_video_frame_info_destroy(notify_info); + ten_env_notify_send_video_frame_ctx_destroy(notify_info); success = false; ten_py_raise_py_runtime_error_exception("Failed to send video_frame."); goto done; 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 b7977485d2..5a99c0c1a0 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 @@ -15,29 +15,29 @@ #include "ten_utils/value/value.h" #include "ten_utils/value/value_json.h" -typedef struct ten_env_notify_set_property_info_t { +typedef struct ten_env_notify_set_property_ctx_t { bool result; ten_string_t path; ten_value_t *c_value; ten_event_t *completed; -} ten_env_notify_set_property_info_t; +} ten_env_notify_set_property_ctx_t; -static ten_env_notify_set_property_info_t * -ten_env_notify_set_property_info_create(const void *path, ten_value_t *value) { - ten_env_notify_set_property_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_set_property_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_set_property_ctx_t * +ten_env_notify_set_property_ctx_create(const void *path, ten_value_t *value) { + ten_env_notify_set_property_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_set_property_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - info->result = true; - ten_string_init_formatted(&info->path, "%s", path); - info->c_value = value; - info->completed = ten_event_create(0, 1); + ctx->result = true; + ten_string_init_formatted(&ctx->path, "%s", path); + ctx->c_value = value; + ctx->completed = ten_event_create(0, 1); - return info; + return ctx; } -static void ten_env_notify_set_property_info_destroy( - ten_env_notify_set_property_info_t *self) { +static void ten_env_notify_set_property_ctx_destroy( + ten_env_notify_set_property_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); ten_string_deinit(&self->path); @@ -53,17 +53,17 @@ static void ten_env_proxy_notify_set_property(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_set_property_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_set_property_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); ten_error_t err; ten_error_init(&err); - info->result = ten_env_set_property( - ten_env, ten_string_get_raw_str(&info->path), info->c_value, &err); - TEN_ASSERT(info->result, "Should not happen."); + ctx->result = ten_env_set_property( + ten_env, ten_string_get_raw_str(&ctx->path), ctx->c_value, &err); + TEN_ASSERT(ctx->result, "Should not happen."); - ten_event_set(info->completed); + ten_event_set(ctx->completed); ten_error_deinit(&err); } @@ -76,21 +76,21 @@ static void ten_py_ten_env_set_property(ten_py_ten_env_t *self, ten_error_t err; ten_error_init(&err); - ten_env_notify_set_property_info_t *info = - ten_env_notify_set_property_info_create(path, value); + ten_env_notify_set_property_ctx_t *ctx = + ten_env_notify_set_property_ctx_create(path, value); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_set_property, info, false, + ten_env_proxy_notify_set_property, ctx, false, &err)) { goto done; } PyThreadState *saved_py_thread_state = PyEval_SaveThread(); - ten_event_wait(info->completed, -1); + ten_event_wait(ctx->completed, -1); PyEval_RestoreThread(saved_py_thread_state); done: - ten_env_notify_set_property_info_destroy(info); + ten_env_notify_set_property_ctx_destroy(ctx); ten_error_deinit(&err); } diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_set_property_async.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_set_property_async.c index 2f3c70c3da..5115307c90 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_set_property_async.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_set_property_async.c @@ -16,33 +16,33 @@ #include "ten_utils/value/value.h" #include "ten_utils/value/value_json.h" -typedef struct ten_env_notify_set_property_async_info_t { +typedef struct ten_env_notify_set_property_async_ctx_t { ten_string_t path; ten_value_t *c_value; PyObject *py_cb_func; -} ten_env_notify_set_property_async_info_t; +} ten_env_notify_set_property_async_ctx_t; -static ten_env_notify_set_property_async_info_t * -ten_env_notify_set_property_async_info_create(const void *path, - ten_value_t *value, - PyObject *py_cb_func) { - ten_env_notify_set_property_async_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_set_property_async_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); +static ten_env_notify_set_property_async_ctx_t * +ten_env_notify_set_property_async_ctx_create(const void *path, + ten_value_t *value, + PyObject *py_cb_func) { + ten_env_notify_set_property_async_ctx_t *ctx = + TEN_MALLOC(sizeof(ten_env_notify_set_property_async_ctx_t)); + TEN_ASSERT(ctx, "Failed to allocate memory."); - ten_string_init_formatted(&info->path, "%s", path); - info->c_value = value; - info->py_cb_func = py_cb_func; + ten_string_init_formatted(&ctx->path, "%s", path); + ctx->c_value = value; + ctx->py_cb_func = py_cb_func; if (py_cb_func != NULL) { Py_INCREF(py_cb_func); } - return info; + return ctx; } -static void ten_env_notify_set_property_async_info_destroy( - ten_env_notify_set_property_async_info_t *self) { +static void ten_env_notify_set_property_async_ctx_destroy( + ten_env_notify_set_property_async_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); ten_string_deinit(&self->path); @@ -58,16 +58,16 @@ static void ten_env_proxy_notify_set_property_async(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_notify_set_property_async_info_t *info = user_data; - TEN_ASSERT(info, "Should not happen."); + ten_env_notify_set_property_async_ctx_t *ctx = user_data; + TEN_ASSERT(ctx, "Should not happen."); - TEN_ASSERT(info->py_cb_func, "Invalid argument."); + TEN_ASSERT(ctx->py_cb_func, "Invalid argument."); ten_error_t err; ten_error_init(&err); - bool rc = ten_env_set_property(ten_env, ten_string_get_raw_str(&info->path), - info->c_value, &err); + bool rc = ten_env_set_property(ten_env, ten_string_get_raw_str(&ctx->path), + ctx->c_value, &err); // About to call the Python function, so it's necessary to ensure that the GIL // has been acquired. @@ -88,14 +88,14 @@ static void ten_env_proxy_notify_set_property_async(ten_env_t *ten_env, ten_error_deinit(&err); - PyObject *result = PyObject_CallObject(info->py_cb_func, arglist); + PyObject *result = PyObject_CallObject(ctx->py_cb_func, arglist); Py_XDECREF(result); // Ensure cleanup if an error occurred. bool err_occurred = ten_py_check_and_clear_py_error(); TEN_ASSERT(!err_occurred, "Should not happen."); Py_XDECREF(arglist); - Py_XDECREF(info->py_cb_func); + Py_XDECREF(ctx->py_cb_func); if (py_error) { ten_py_error_invalidate(py_error); @@ -103,7 +103,7 @@ static void ten_env_proxy_notify_set_property_async(ten_env_t *ten_env, ten_py_gil_state_release_internal(prev_state); - ten_env_notify_set_property_async_info_destroy(info); + ten_env_notify_set_property_async_ctx_destroy(ctx); } static bool ten_py_ten_env_set_property_async(ten_py_ten_env_t *self, @@ -117,14 +117,14 @@ static bool ten_py_ten_env_set_property_async(ten_py_ten_env_t *self, bool success = true; - ten_env_notify_set_property_async_info_t *info = - ten_env_notify_set_property_async_info_create(path, value, py_cb_func); + ten_env_notify_set_property_async_ctx_t *ctx = + ten_env_notify_set_property_async_ctx_create(path, value, py_cb_func); if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_set_property_async, info, - false, err)) { + ten_env_proxy_notify_set_property_async, ctx, false, + err)) { Py_XDECREF(py_cb_func); - ten_env_notify_set_property_async_info_destroy(info); + ten_env_notify_set_property_async_ctx_destroy(ctx); success = false; ten_py_raise_py_runtime_error_exception("Failed to set property"); } diff --git a/core/src/ten_runtime/engine/internal/remote_interface.c b/core/src/ten_runtime/engine/internal/remote_interface.c index 7b40bd681b..af3098ff12 100644 --- a/core/src/ten_runtime/engine/internal/remote_interface.c +++ b/core/src/ten_runtime/engine/internal/remote_interface.c @@ -68,12 +68,12 @@ static size_t ten_engine_weak_remotes_cnt_in_specified_uri(ten_engine_t *self, return cnt; } -static ten_engine_on_protocol_created_info_t * -ten_engine_on_protocol_created_info_create(ten_engine_on_remote_created_cb_t cb, - void *user_data) { - ten_engine_on_protocol_created_info_t *self = - (ten_engine_on_protocol_created_info_t *)TEN_MALLOC( - sizeof(ten_engine_on_protocol_created_info_t)); +static ten_engine_on_protocol_created_ctx_t * +ten_engine_on_protocol_created_ctx_create(ten_engine_on_remote_created_cb_t cb, + void *user_data) { + ten_engine_on_protocol_created_ctx_t *self = + (ten_engine_on_protocol_created_ctx_t *)TEN_MALLOC( + sizeof(ten_engine_on_protocol_created_ctx_t)); self->cb = cb; self->user_data = user_data; @@ -81,8 +81,8 @@ ten_engine_on_protocol_created_info_create(ten_engine_on_remote_created_cb_t cb, return self; } -static void ten_engine_on_protocol_created_info_destroy( - ten_engine_on_protocol_created_info_t *self) { +static void ten_engine_on_protocol_created_ctx_destroy( + ten_engine_on_protocol_created_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); TEN_FREE(self); @@ -254,8 +254,8 @@ static void ten_engine_on_remote_protocol_created(ten_env_t *ten_env, TEN_ASSERT(self && ten_engine_check_integrity(self, true), "Should not happen."); - ten_engine_on_protocol_created_info_t *info = - (ten_engine_on_protocol_created_info_t *)cb_data; + ten_engine_on_protocol_created_ctx_t *ctx = + (ten_engine_on_protocol_created_ctx_t *)cb_data; ten_connection_t *connection = ten_connection_create(protocol); TEN_ASSERT(connection, "Should not happen."); @@ -269,11 +269,11 @@ static void ten_engine_on_remote_protocol_created(ten_env_t *ten_env, ten_string_get_raw_str(&protocol->uri), self, connection); TEN_ASSERT(remote, "Should not happen."); - if (info->cb) { - info->cb(self, remote, info->user_data); + if (ctx->cb) { + ctx->cb(self, remote, ctx->user_data); } - ten_engine_on_protocol_created_info_destroy(info); + ten_engine_on_protocol_created_ctx_destroy(ctx); } static bool ten_engine_create_remote_async( @@ -288,18 +288,18 @@ static bool ten_engine_create_remote_async( ten_error_t err; ten_error_init(&err); - ten_engine_on_protocol_created_info_t *info = - ten_engine_on_protocol_created_info_create(on_remote_created_cb, cb_data); - TEN_ASSERT(info, "Failed to allocate memory."); + ten_engine_on_protocol_created_ctx_t *ctx = + ten_engine_on_protocol_created_ctx_create(on_remote_created_cb, cb_data); + TEN_ASSERT(ctx, "Failed to allocate memory."); bool rc = ten_addon_create_protocol_with_uri( self->ten_env, uri, TEN_PROTOCOL_ROLE_OUT_DEFAULT, - ten_engine_on_remote_protocol_created, info, &err); + ten_engine_on_remote_protocol_created, ctx, &err); if (!rc) { TEN_LOGE("Failed to create protocol for %s. err: %s", uri, ten_error_errmsg(&err)); ten_error_deinit(&err); - ten_engine_on_protocol_created_info_destroy(info); + ten_engine_on_protocol_created_ctx_destroy(ctx); return false; } diff --git a/core/src/ten_runtime/engine/on_xxx.c b/core/src/ten_runtime/engine/on_xxx.c index 30e7e8a2a4..af57a57057 100644 --- a/core/src/ten_runtime/engine/on_xxx.c +++ b/core/src/ten_runtime/engine/on_xxx.c @@ -198,10 +198,10 @@ void ten_engine_on_addon_create_extension_group_done(void *self_, void *arg) { TEN_ASSERT(self && ten_engine_check_integrity(self, true), "Should not happen."); - ten_extension_context_on_addon_create_extension_group_done_info_t *info = arg; - TEN_ASSERT(info, "Should not happen."); + ten_extension_context_on_addon_create_extension_group_done_ctx_t *ctx = arg; + TEN_ASSERT(ctx, "Should not happen."); - ten_extension_group_t *extension_group = info->extension_group; + ten_extension_group_t *extension_group = ctx->extension_group; TEN_ASSERT(extension_group && // TEN_NOLINTNEXTLINE(thread-check) // thread-check: The extension thread has not been created @@ -210,9 +210,9 @@ void ten_engine_on_addon_create_extension_group_done(void *self_, void *arg) { "Should not happen."); ten_extension_context_on_addon_create_extension_group_done( - self->ten_env, extension_group, info->addon_context); + self->ten_env, extension_group, ctx->addon_context); - ten_extension_context_on_addon_create_extension_group_done_info_destroy(info); + ten_extension_context_on_addon_create_extension_group_done_ctx_destroy(ctx); } void ten_engine_on_addon_destroy_extension_group_done(void *self_, void *arg) { @@ -229,10 +229,10 @@ void ten_engine_on_addon_destroy_extension_group_done(void *self_, void *arg) { addon_context); } -ten_engine_thread_on_addon_create_protocol_done_info_t * -ten_engine_thread_on_addon_create_protocol_done_info_create(void) { - ten_engine_thread_on_addon_create_protocol_done_info_t *self = TEN_MALLOC( - sizeof(ten_engine_thread_on_addon_create_protocol_done_info_t)); +ten_engine_thread_on_addon_create_protocol_done_ctx_t * +ten_engine_thread_on_addon_create_protocol_done_ctx_create(void) { + ten_engine_thread_on_addon_create_protocol_done_ctx_t *self = + TEN_MALLOC(sizeof(ten_engine_thread_on_addon_create_protocol_done_ctx_t)); self->protocol = NULL; self->addon_context = NULL; @@ -240,8 +240,8 @@ ten_engine_thread_on_addon_create_protocol_done_info_create(void) { return self; } -static void ten_engine_thread_on_addon_create_protocol_done_info_destroy( - ten_engine_thread_on_addon_create_protocol_done_info_t *self) { +static void ten_engine_thread_on_addon_create_protocol_done_ctx_destroy( + ten_engine_thread_on_addon_create_protocol_done_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); TEN_FREE(self); } @@ -251,11 +251,11 @@ void ten_engine_thread_on_addon_create_protocol_done(void *self, void *arg) { TEN_ASSERT(engine && ten_engine_check_integrity(engine, true), "Should not happen."); - ten_engine_thread_on_addon_create_protocol_done_info_t *info = arg; - TEN_ASSERT(info, "Should not happen."); + ten_engine_thread_on_addon_create_protocol_done_ctx_t *ctx = arg; + TEN_ASSERT(ctx, "Should not happen."); - ten_protocol_t *protocol = info->protocol; - ten_addon_context_t *addon_context = info->addon_context; + ten_protocol_t *protocol = ctx->protocol; + ten_addon_context_t *addon_context = ctx->addon_context; TEN_ASSERT(addon_context, "Should not happen."); if (addon_context->create_instance_done_cb) { @@ -264,5 +264,5 @@ void ten_engine_thread_on_addon_create_protocol_done(void *self, void *arg) { } ten_addon_context_destroy(addon_context); - ten_engine_thread_on_addon_create_protocol_done_info_destroy(info); + ten_engine_thread_on_addon_create_protocol_done_ctx_destroy(ctx); } diff --git a/core/src/ten_runtime/extension_context/ten_env/on_xxx.c b/core/src/ten_runtime/extension_context/ten_env/on_xxx.c index 9f399049ed..62068796d3 100644 --- a/core/src/ten_runtime/extension_context/ten_env/on_xxx.c +++ b/core/src/ten_runtime/extension_context/ten_env/on_xxx.c @@ -75,11 +75,11 @@ void ten_extension_context_on_addon_destroy_extension_group_done( ten_addon_context_destroy(addon_context); } -ten_extension_context_on_addon_create_extension_group_done_info_t * -ten_extension_context_on_addon_create_extension_group_done_info_create(void) { - ten_extension_context_on_addon_create_extension_group_done_info_t *self = +ten_extension_context_on_addon_create_extension_group_done_ctx_t * +ten_extension_context_on_addon_create_extension_group_done_ctx_create(void) { + ten_extension_context_on_addon_create_extension_group_done_ctx_t *self = TEN_MALLOC(sizeof( - ten_extension_context_on_addon_create_extension_group_done_info_t)); + ten_extension_context_on_addon_create_extension_group_done_ctx_t)); self->addon_context = NULL; self->extension_group = NULL; @@ -87,8 +87,8 @@ ten_extension_context_on_addon_create_extension_group_done_info_create(void) { return self; } -void ten_extension_context_on_addon_create_extension_group_done_info_destroy( - ten_extension_context_on_addon_create_extension_group_done_info_t *self) { +void ten_extension_context_on_addon_create_extension_group_done_ctx_destroy( + ten_extension_context_on_addon_create_extension_group_done_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); TEN_FREE(self); } diff --git a/core/src/ten_runtime/extension_thread/on_xxx.c b/core/src/ten_runtime/extension_thread/on_xxx.c index 105bd60e1a..0c0d42fc65 100644 --- a/core/src/ten_runtime/extension_thread/on_xxx.c +++ b/core/src/ten_runtime/extension_thread/on_xxx.c @@ -206,18 +206,18 @@ void ten_extension_thread_on_addon_create_extension_done(void *self_, ten_extension_group_check_integrity(extension_group, true), "Should not happen."); - ten_extension_thread_on_addon_create_extension_done_info_t *info = arg; + ten_extension_thread_on_addon_create_extension_done_ctx_t *ctx = arg; TEN_ASSERT(arg, "Should not happen."); - ten_extension_t *extension = info->extension; + ten_extension_t *extension = ctx->extension; ten_extension_inherit_thread_ownership(extension, self); TEN_ASSERT(extension && ten_extension_check_integrity(extension, true), "Should not happen."); ten_extension_group_on_addon_create_extension_done( - extension_group->ten_env, extension, info->addon_context); + extension_group->ten_env, extension, ctx->addon_context); - ten_extension_thread_on_addon_create_extension_done_info_destroy(info); + ten_extension_thread_on_addon_create_extension_done_ctx_destroy(ctx); } void ten_extension_thread_on_addon_destroy_extension_done(void *self_, @@ -252,7 +252,7 @@ void ten_extension_thread_create_extension_instance(void *self_, void *arg) { TEN_ASSERT(ten_extension_thread_check_integrity(self, true), "Invalid use of extension_thread %p.", self); - ten_addon_on_create_extension_instance_info_t *addon_instance_info = arg; + ten_addon_on_create_extension_instance_ctx_t *addon_instance_info = arg; TEN_ASSERT(addon_instance_info, "Should not happen."); ten_addon_create_instance_async( @@ -261,7 +261,7 @@ void ten_extension_thread_create_extension_instance(void *self_, void *arg) { ten_string_get_raw_str(&addon_instance_info->instance_name), addon_instance_info->cb, addon_instance_info->cb_data); - ten_addon_on_create_extension_instance_info_destroy(addon_instance_info); + ten_addon_on_create_extension_instance_ctx_destroy(addon_instance_info); } void ten_extension_thread_destroy_addon_instance(void *self_, void *arg) { @@ -270,7 +270,7 @@ void ten_extension_thread_destroy_addon_instance(void *self_, void *arg) { TEN_ASSERT(ten_extension_thread_check_integrity(self, true), "Invalid use of extension_thread %p.", self); - ten_addon_on_destroy_instance_info_t *destroy_instance_info = arg; + ten_addon_on_destroy_instance_ctx_t *destroy_instance_info = arg; TEN_ASSERT(destroy_instance_info, "Should not happen."); ten_addon_host_destroy_instance_async( @@ -278,13 +278,13 @@ void ten_extension_thread_destroy_addon_instance(void *self_, void *arg) { destroy_instance_info->instance, destroy_instance_info->cb, destroy_instance_info->cb_data); - ten_addon_on_destroy_instance_info_destroy(destroy_instance_info); + ten_addon_on_destroy_instance_ctx_destroy(destroy_instance_info); } -ten_extension_thread_on_addon_create_extension_done_info_t * -ten_extension_thread_on_addon_create_extension_done_info_create(void) { - ten_extension_thread_on_addon_create_extension_done_info_t *self = TEN_MALLOC( - sizeof(ten_extension_thread_on_addon_create_extension_done_info_t)); +ten_extension_thread_on_addon_create_extension_done_ctx_t * +ten_extension_thread_on_addon_create_extension_done_ctx_create(void) { + ten_extension_thread_on_addon_create_extension_done_ctx_t *self = TEN_MALLOC( + sizeof(ten_extension_thread_on_addon_create_extension_done_ctx_t)); self->addon_context = NULL; self->extension = NULL; @@ -292,8 +292,8 @@ ten_extension_thread_on_addon_create_extension_done_info_create(void) { return self; } -void ten_extension_thread_on_addon_create_extension_done_info_destroy( - ten_extension_thread_on_addon_create_extension_done_info_t *self) { +void ten_extension_thread_on_addon_create_extension_done_ctx_destroy( + ten_extension_thread_on_addon_create_extension_done_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); TEN_FREE(self); } diff --git a/core/src/ten_runtime/test/env_tester.c b/core/src/ten_runtime/test/env_tester.c index b0ec1d5076..338b5cd9f4 100644 --- a/core/src/ten_runtime/test/env_tester.c +++ b/core/src/ten_runtime/test/env_tester.c @@ -81,7 +81,7 @@ typedef struct ten_extension_tester_send_cmd_info_t { ten_env_tester_cmd_result_handler_func_t handler; void *handler_user_data; ten_error_t *err; -} ten_env_tester_send_cmd_info_t; +} ten_env_tester_send_cmd_ctx_t; typedef struct ten_extension_tester_send_msg_info_t { ten_extension_tester_t *tester; @@ -89,7 +89,7 @@ typedef struct ten_extension_tester_send_msg_info_t { ten_env_tester_error_handler_func_t handler; void *handler_user_data; ten_error_t *err; -} ten_env_tester_send_msg_info_t; +} ten_env_tester_send_msg_ctx_t; typedef struct ten_extension_tester_return_result_info_t { ten_extension_tester_t *tester; @@ -98,18 +98,17 @@ typedef struct ten_extension_tester_return_result_info_t { ten_env_tester_error_handler_func_t handler; void *handler_user_data; ten_error_t *err; -} ten_env_tester_return_result_info_t; +} ten_env_tester_return_result_ctx_t; -static ten_env_tester_send_cmd_info_t * -ten_extension_tester_send_cmd_info_create( +static ten_env_tester_send_cmd_ctx_t *ten_extension_tester_send_cmd_ctx_create( ten_extension_tester_t *tester, ten_shared_ptr_t *cmd, ten_env_tester_cmd_result_handler_func_t handler, void *handler_user_data) { TEN_ASSERT( tester && ten_extension_tester_check_integrity(tester, true) && cmd, "Invalid argument."); - ten_env_tester_send_cmd_info_t *self = - TEN_MALLOC(sizeof(ten_env_tester_send_cmd_info_t)); + ten_env_tester_send_cmd_ctx_t *self = + TEN_MALLOC(sizeof(ten_env_tester_send_cmd_ctx_t)); TEN_ASSERT(self, "Failed to allocate memory."); self->tester = tester; @@ -122,8 +121,8 @@ ten_extension_tester_send_cmd_info_create( return self; } -static void ten_extension_tester_send_cmd_info_destroy( - ten_env_tester_send_cmd_info_t *self) { +static void ten_extension_tester_send_cmd_ctx_destroy( + ten_env_tester_send_cmd_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); if (self->cmd) { @@ -141,16 +140,15 @@ static void ten_extension_tester_send_cmd_info_destroy( TEN_FREE(self); } -static ten_env_tester_send_msg_info_t * -ten_extension_tester_send_msg_info_create( +static ten_env_tester_send_msg_ctx_t *ten_extension_tester_send_msg_ctx_create( ten_extension_tester_t *tester, ten_shared_ptr_t *msg, ten_env_tester_error_handler_func_t handler, void *handler_user_data) { TEN_ASSERT( tester && ten_extension_tester_check_integrity(tester, true) && msg, "Invalid argument."); - ten_env_tester_send_msg_info_t *self = - TEN_MALLOC(sizeof(ten_env_tester_send_msg_info_t)); + ten_env_tester_send_msg_ctx_t *self = + TEN_MALLOC(sizeof(ten_env_tester_send_msg_ctx_t)); TEN_ASSERT(self, "Failed to allocate memory."); self->tester = tester; @@ -162,8 +160,8 @@ ten_extension_tester_send_msg_info_create( return self; } -static void ten_extension_tester_send_msg_info_destroy( - ten_env_tester_send_msg_info_t *self) { +static void ten_extension_tester_send_msg_ctx_destroy( + ten_env_tester_send_msg_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); if (self->msg) { @@ -177,8 +175,8 @@ static void ten_extension_tester_send_msg_info_destroy( TEN_FREE(self); } -static ten_env_tester_return_result_info_t * -ten_extension_tester_return_result_info_create( +static ten_env_tester_return_result_ctx_t * +ten_extension_tester_return_result_ctx_create( ten_extension_tester_t *tester, ten_shared_ptr_t *result, ten_shared_ptr_t *target_cmd, ten_env_tester_error_handler_func_t handler, void *handler_user_data) { @@ -186,8 +184,8 @@ ten_extension_tester_return_result_info_create( result && target_cmd, "Invalid argument."); - ten_env_tester_return_result_info_t *self = - TEN_MALLOC(sizeof(ten_env_tester_return_result_info_t)); + ten_env_tester_return_result_ctx_t *self = + TEN_MALLOC(sizeof(ten_env_tester_return_result_ctx_t)); TEN_ASSERT(self, "Failed to allocate memory."); self->tester = tester; @@ -200,8 +198,8 @@ ten_extension_tester_return_result_info_create( return self; } -static void ten_extension_tester_return_result_info_destroy( - ten_env_tester_return_result_info_t *self) { +static void ten_extension_tester_return_result_ctx_destroy( + ten_env_tester_return_result_ctx_t *self) { TEN_ASSERT(self, "Invalid argument."); if (self->result) { @@ -225,13 +223,13 @@ static void ten_extension_tester_execute_error_handler_task(void *self, TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, true), "Invalid argument."); - ten_env_tester_send_msg_info_t *send_msg_info = arg; + ten_env_tester_send_msg_ctx_t *send_msg_info = arg; TEN_ASSERT(send_msg_info, "Invalid argument."); send_msg_info->handler(tester->ten_env_tester, send_msg_info->handler_user_data, send_msg_info->err); - ten_extension_tester_send_msg_info_destroy(send_msg_info); + ten_extension_tester_send_msg_ctx_destroy(send_msg_info); } static void ten_extension_tester_execute_cmd_result_handler_task(void *self, @@ -240,13 +238,13 @@ static void ten_extension_tester_execute_cmd_result_handler_task(void *self, TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, true), "Invalid argument."); - ten_env_tester_send_cmd_info_t *send_cmd_info = arg; + ten_env_tester_send_cmd_ctx_t *send_cmd_info = arg; TEN_ASSERT(send_cmd_info, "Invalid argument."); send_cmd_info->handler(tester->ten_env_tester, send_cmd_info->cmd_result, send_cmd_info->handler_user_data, send_cmd_info->err); - ten_extension_tester_send_cmd_info_destroy(send_cmd_info); + ten_extension_tester_send_cmd_ctx_destroy(send_cmd_info); } static void ten_extension_tester_execute_return_result_handler_task(void *self, @@ -255,25 +253,25 @@ static void ten_extension_tester_execute_return_result_handler_task(void *self, TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, true), "Invalid argument."); - ten_env_tester_return_result_info_t *return_result_info = arg; + ten_env_tester_return_result_ctx_t *return_result_info = arg; TEN_ASSERT(return_result_info, "Invalid argument."); return_result_info->handler(tester->ten_env_tester, return_result_info->handler_user_data, return_result_info->err); - ten_extension_tester_return_result_info_destroy(return_result_info); + ten_extension_tester_return_result_ctx_destroy(return_result_info); } static void send_cmd_callback(ten_env_t *ten_env, ten_shared_ptr_t *cmd_result, void *callback_user_data, ten_error_t *err) { TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_tester_send_cmd_info_t *send_cmd_info = callback_user_data; + ten_env_tester_send_cmd_ctx_t *send_cmd_info = callback_user_data; TEN_ASSERT(send_cmd_info, "Invalid argument."); if (!send_cmd_info->handler) { - ten_extension_tester_send_cmd_info_destroy(send_cmd_info); + ten_extension_tester_send_cmd_ctx_destroy(send_cmd_info); return; } @@ -309,11 +307,11 @@ static void send_data_like_msg_callback(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_tester_send_msg_info_t *send_msg_info = callback_user_data; + ten_env_tester_send_msg_ctx_t *send_msg_info = callback_user_data; TEN_ASSERT(send_msg_info, "Invalid argument."); if (!send_msg_info->handler) { - ten_extension_tester_send_msg_info_destroy(send_msg_info); + ten_extension_tester_send_msg_ctx_destroy(send_msg_info); return; } @@ -333,11 +331,11 @@ static void return_result_callback(ten_env_t *self, void *user_data, ten_error_t *err) { TEN_ASSERT(self && ten_env_check_integrity(self, true), "Should not happen."); - ten_env_tester_return_result_info_t *return_result_info = user_data; + ten_env_tester_return_result_ctx_t *return_result_info = user_data; TEN_ASSERT(return_result_info, "Invalid argument."); if (!return_result_info->handler) { - ten_extension_tester_return_result_info_destroy(return_result_info); + ten_extension_tester_return_result_ctx_destroy(return_result_info); return; } @@ -359,7 +357,7 @@ static void test_extension_ten_env_send_cmd(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_tester_send_cmd_info_t *send_cmd_info = user_data; + ten_env_tester_send_cmd_ctx_t *send_cmd_info = user_data; TEN_ASSERT(send_cmd_info, "Invalid argument."); TEN_ASSERT(send_cmd_info->cmd && ten_msg_check_integrity(send_cmd_info->cmd), "Should not happen."); @@ -388,7 +386,7 @@ static void test_extension_ten_env_send_cmd(ten_env_t *ten_env, } if (!rc) { - ten_extension_tester_send_cmd_info_destroy(send_cmd_info); + ten_extension_tester_send_cmd_ctx_destroy(send_cmd_info); } } @@ -397,7 +395,7 @@ static void test_extension_ten_env_return_result(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_tester_return_result_info_t *return_result_info = user_data; + ten_env_tester_return_result_ctx_t *return_result_info = user_data; TEN_ASSERT(return_result_info, "Invalid argument."); ten_error_t *err = ten_error_create(); @@ -425,7 +423,7 @@ static void test_extension_ten_env_return_result(ten_env_t *ten_env, } if (!rc) { - ten_extension_tester_return_result_info_destroy(return_result_info); + ten_extension_tester_return_result_ctx_destroy(return_result_info); } } @@ -434,7 +432,7 @@ static void test_extension_ten_env_send_data(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_tester_send_msg_info_t *send_msg_info = user_data; + ten_env_tester_send_msg_ctx_t *send_msg_info = user_data; TEN_ASSERT(send_msg_info, "Invalid argument."); TEN_ASSERT(send_msg_info->msg && ten_msg_check_integrity(send_msg_info->msg), "Should not happen."); @@ -463,7 +461,7 @@ static void test_extension_ten_env_send_data(ten_env_t *ten_env, } if (!rc) { - ten_extension_tester_send_msg_info_destroy(send_msg_info); + ten_extension_tester_send_msg_ctx_destroy(send_msg_info); } } @@ -472,7 +470,7 @@ static void test_extension_ten_env_send_audio_frame(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_tester_send_msg_info_t *send_msg_info = user_audio_frame; + ten_env_tester_send_msg_ctx_t *send_msg_info = user_audio_frame; TEN_ASSERT(send_msg_info, "Invalid argument."); TEN_ASSERT(send_msg_info->msg && ten_msg_check_integrity(send_msg_info->msg), "Should not happen."); @@ -502,7 +500,7 @@ static void test_extension_ten_env_send_audio_frame(ten_env_t *ten_env, } if (!rc) { - ten_extension_tester_send_msg_info_destroy(send_msg_info); + ten_extension_tester_send_msg_ctx_destroy(send_msg_info); } } @@ -511,7 +509,7 @@ static void test_extension_ten_env_send_video_frame(ten_env_t *ten_env, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); - ten_env_tester_send_msg_info_t *send_msg_info = user_video_frame; + ten_env_tester_send_msg_ctx_t *send_msg_info = user_video_frame; TEN_ASSERT(send_msg_info, "Invalid argument."); TEN_ASSERT(send_msg_info->msg && ten_msg_check_integrity(send_msg_info->msg), "Should not happen."); @@ -541,7 +539,7 @@ static void test_extension_ten_env_send_video_frame(ten_env_t *ten_env, } if (!rc) { - ten_extension_tester_send_msg_info_destroy(send_msg_info); + ten_extension_tester_send_msg_ctx_destroy(send_msg_info); } } @@ -549,8 +547,8 @@ bool ten_env_tester_send_cmd(ten_env_tester_t *self, ten_shared_ptr_t *cmd, ten_env_tester_cmd_result_handler_func_t handler, void *user_data, ten_error_t *err) { TEN_ASSERT(self && ten_env_tester_check_integrity(self), "Invalid argument."); - ten_env_tester_send_cmd_info_t *send_cmd_info = - ten_extension_tester_send_cmd_info_create( + ten_env_tester_send_cmd_ctx_t *send_cmd_info = + ten_extension_tester_send_cmd_ctx_create( self->tester, ten_shared_ptr_clone(cmd), handler, user_data); TEN_ASSERT(self->tester->test_extension_ten_env_proxy, "Invalid argument."); @@ -558,7 +556,7 @@ bool ten_env_tester_send_cmd(ten_env_tester_t *self, ten_shared_ptr_t *cmd, test_extension_ten_env_send_cmd, send_cmd_info, false, err); if (!rc) { - ten_extension_tester_send_cmd_info_destroy(send_cmd_info); + ten_extension_tester_send_cmd_ctx_destroy(send_cmd_info); } return rc; @@ -571,8 +569,8 @@ bool ten_env_tester_return_result( ten_error_t *error) { TEN_ASSERT(self && ten_env_tester_check_integrity(self), "Invalid argument."); - ten_env_tester_return_result_info_t *return_result_info = - ten_extension_tester_return_result_info_create( + ten_env_tester_return_result_ctx_t *return_result_info = + ten_extension_tester_return_result_ctx_create( self->tester, ten_shared_ptr_clone(result), ten_shared_ptr_clone(target_cmd), error_handler, user_data); TEN_ASSERT(return_result_info, "Allocation failed."); @@ -582,7 +580,7 @@ bool ten_env_tester_return_result( test_extension_ten_env_return_result, return_result_info, false, error); if (!rc) { - ten_extension_tester_return_result_info_destroy(return_result_info); + ten_extension_tester_return_result_ctx_destroy(return_result_info); } return rc; @@ -593,8 +591,8 @@ bool ten_env_tester_send_data(ten_env_tester_t *self, ten_shared_ptr_t *data, void *user_data, ten_error_t *err) { TEN_ASSERT(self && ten_env_tester_check_integrity(self), "Invalid argument."); - ten_env_tester_send_msg_info_t *send_msg_info = - ten_extension_tester_send_msg_info_create( + ten_env_tester_send_msg_ctx_t *send_msg_info = + ten_extension_tester_send_msg_ctx_create( self->tester, ten_shared_ptr_clone(data), handler, user_data); TEN_ASSERT(self->tester->test_extension_ten_env_proxy, "Invalid argument."); @@ -602,7 +600,7 @@ bool ten_env_tester_send_data(ten_env_tester_t *self, ten_shared_ptr_t *data, test_extension_ten_env_send_data, send_msg_info, false, err); if (!rc) { - ten_extension_tester_send_msg_info_destroy(send_msg_info); + ten_extension_tester_send_msg_ctx_destroy(send_msg_info); } return rc; @@ -614,8 +612,8 @@ bool ten_env_tester_send_audio_frame( ten_error_t *err) { TEN_ASSERT(self && ten_env_tester_check_integrity(self), "Invalid argument."); - ten_env_tester_send_msg_info_t *send_msg_info = - ten_extension_tester_send_msg_info_create( + ten_env_tester_send_msg_ctx_t *send_msg_info = + ten_extension_tester_send_msg_ctx_create( self->tester, ten_shared_ptr_clone(audio_frame), handler, user_data); TEN_ASSERT(self->tester->test_extension_ten_env_proxy, "Invalid argument."); @@ -623,7 +621,7 @@ bool ten_env_tester_send_audio_frame( test_extension_ten_env_send_audio_frame, send_msg_info, false, err); if (!rc) { - ten_extension_tester_send_msg_info_destroy(send_msg_info); + ten_extension_tester_send_msg_ctx_destroy(send_msg_info); } return rc; @@ -635,8 +633,8 @@ bool ten_env_tester_send_video_frame( ten_error_t *err) { TEN_ASSERT(self && ten_env_tester_check_integrity(self), "Invalid argument."); - ten_env_tester_send_msg_info_t *send_msg_info = - ten_extension_tester_send_msg_info_create( + ten_env_tester_send_msg_ctx_t *send_msg_info = + ten_extension_tester_send_msg_ctx_create( self->tester, ten_shared_ptr_clone(video_frame), handler, user_data); TEN_ASSERT(self->tester->test_extension_ten_env_proxy, "Invalid argument."); @@ -644,7 +642,7 @@ bool ten_env_tester_send_video_frame( test_extension_ten_env_send_video_frame, send_msg_info, false, err); if (!rc) { - ten_extension_tester_send_msg_info_destroy(send_msg_info); + ten_extension_tester_send_msg_ctx_destroy(send_msg_info); } return rc;