From 79c5c559d399a08c9d154500d52514f02ef767e6 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Wed, 8 Jan 2025 12:01:17 +0800 Subject: [PATCH] feat: allow the start graph action to return a failure error (#523) --- .../ten_runtime/addon/extension/extension.h | 4 ++- .../ten_runtime/addon/extension/extension.c | 6 ++++- .../builtin/builtin_extension_group.c | 25 ++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/core/include_internal/ten_runtime/addon/extension/extension.h b/core/include_internal/ten_runtime/addon/extension/extension.h index 82c58cc15..15ee42609 100644 --- a/core/include_internal/ten_runtime/addon/extension/extension.h +++ b/core/include_internal/ten_runtime/addon/extension/extension.h @@ -20,6 +20,7 @@ typedef struct ten_extension_t ten_extension_t; typedef struct ten_addon_create_extension_done_ctx_t { ten_list_t *results; + ten_string_t extension_name; ten_error_t err; } ten_addon_create_extension_done_ctx_t; @@ -28,7 +29,8 @@ TEN_RUNTIME_PRIVATE_API ten_addon_store_t *ten_extension_get_global_store(void); TEN_RUNTIME_PRIVATE_API void ten_addon_unregister_all_extension(void); TEN_RUNTIME_PRIVATE_API ten_addon_create_extension_done_ctx_t * -ten_addon_create_extension_done_ctx_create(ten_list_t *results); +ten_addon_create_extension_done_ctx_create(ten_list_t *results, + const char *extension_name); TEN_RUNTIME_PRIVATE_API void ten_addon_create_extension_done_ctx_destroy( ten_addon_create_extension_done_ctx_t *self); diff --git a/core/src/ten_runtime/addon/extension/extension.c b/core/src/ten_runtime/addon/extension/extension.c index c3e1fd238..c8d467a7a 100644 --- a/core/src/ten_runtime/addon/extension/extension.c +++ b/core/src/ten_runtime/addon/extension/extension.c @@ -65,12 +65,15 @@ void ten_addon_on_create_extension_instance_ctx_destroy( } ten_addon_create_extension_done_ctx_t * -ten_addon_create_extension_done_ctx_create(ten_list_t *results) { +ten_addon_create_extension_done_ctx_create(ten_list_t *results, + const char *extension_name) { ten_addon_create_extension_done_ctx_t *self = TEN_MALLOC(sizeof(ten_addon_create_extension_done_ctx_t)); TEN_ASSERT(self, "Failed to allocate memory."); self->results = results; + ten_string_init_from_c_str(&self->extension_name, extension_name, + strlen(extension_name)); ten_error_init(&self->err); return self; @@ -80,6 +83,7 @@ void ten_addon_create_extension_done_ctx_destroy( ten_addon_create_extension_done_ctx_t *self) { TEN_ASSERT(self, "Should not happen."); + ten_string_deinit(&self->extension_name); ten_error_deinit(&self->err); TEN_FREE(self); diff --git a/core/src/ten_runtime/extension_group/builtin/builtin_extension_group.c b/core/src/ten_runtime/extension_group/builtin/builtin_extension_group.c index 978f126b5..e1cd98a7f 100644 --- a/core/src/ten_runtime/extension_group/builtin/builtin_extension_group.c +++ b/core/src/ten_runtime/extension_group/builtin/builtin_extension_group.c @@ -32,6 +32,7 @@ #include "ten_runtime/ten_env/internal/return.h" #include "ten_runtime/ten_env/ten_env.h" #include "ten_utils/container/list_ptr.h" +#include "ten_utils/lib/string.h" #include "ten_utils/log/log.h" #include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" @@ -50,6 +51,10 @@ static void on_addon_create_extension_done(ten_env_t *ten_env, ten_env_get_attach_to(ten_env) == TEN_ENV_ATTACH_TO_EXTENSION_GROUP, "Invalid argument."); + ten_addon_create_extension_done_ctx_t *ctx = + (ten_addon_create_extension_done_ctx_t *)cb_data; + TEN_ASSERT(ctx, "Should not happen."); + ten_extension_group_t *extension_group = ten_env_get_attached_target(ten_env); TEN_ASSERT(extension_group && ten_extension_group_check_integrity(extension_group, true), @@ -61,15 +66,12 @@ static void on_addon_create_extension_done(ten_env_t *ten_env, TEN_ASSERT(ten_extension_check_integrity(extension, true), "Invalid argument."); - ten_addon_create_extension_done_ctx_t *ctx = - (ten_addon_create_extension_done_ctx_t *)cb_data; - TEN_ASSERT(ctx, "Should not happen."); + TEN_LOGI("Success to create extension %s", + ten_string_get_raw_str(&ctx->extension_name)); ten_list_t *results = ctx->results; TEN_ASSERT(results, "Should not happen."); - ten_addon_create_extension_done_ctx_destroy(ctx); - ten_list_push_ptr_back(results, extension, NULL); if (ten_list_size(results) == @@ -86,6 +88,9 @@ static void on_addon_create_extension_done(ten_env_t *ten_env, } else { // Failed to create the extension, failure path. + TEN_LOGI("Failed to create extension %s", + ten_string_get_raw_str(&ctx->extension_name)); + ten_extension_context_t *extension_context = extension_group->extension_context; TEN_ASSERT(extension_context && ten_extension_context_check_integrity( @@ -114,6 +119,8 @@ static void on_addon_create_extension_done(ten_env_t *ten_env, NULL); ten_env_send_cmd(ten_env, stop_graph_cmd, NULL, NULL, NULL); } + + ten_addon_create_extension_done_ctx_destroy(ctx); } static void on_addon_destroy_instance_done(ten_env_t *ten_env, @@ -166,6 +173,11 @@ static void ten_builtin_extension_group_on_create_extensions( ten_env_on_create_extensions_done(ten_env, results, NULL); ten_list_destroy(results); + TEN_LOGI( + "%s is a group without any extensions, so it is considered that all " + "extensions have been successfully created.", + ten_string_get_raw_str(&self->name)); + // This extension group is empty, so it can be considered that all the // required extensions have been successfully created. return; @@ -184,7 +196,8 @@ static void ten_builtin_extension_group_on_create_extensions( ten_string_t *extension_instance_name = &extension_name_info->instance_name; ten_addon_create_extension_done_ctx_t *ctx = - ten_addon_create_extension_done_ctx_create(results); + ten_addon_create_extension_done_ctx_create( + results, ten_string_get_raw_str(extension_instance_name)); bool res = ten_addon_create_extension( ten_env, ten_string_get_raw_str(extension_addon_name),