From ef9ff1de9daac9e3882b66319e908926f9c584c8 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Tue, 24 Sep 2024 22:53:17 +0800 Subject: [PATCH] feat: add ten:builtin_extension_group --- .../builtin/builtin_extension_group.h | 4 +-- core/src/ten_runtime/app/ten_env/on_xxx.c | 3 -- .../builtin/builtin_extension_group.c | 33 ++++++++++++------- core/src/ten_runtime/global/on_load.c | 5 +++ 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/core/include_internal/ten_runtime/extension_group/builtin/builtin_extension_group.h b/core/include_internal/ten_runtime/extension_group/builtin/builtin_extension_group.h index 94e371e696..a53d1aac25 100644 --- a/core/include_internal/ten_runtime/extension_group/builtin/builtin_extension_group.h +++ b/core/include_internal/ten_runtime/extension_group/builtin/builtin_extension_group.h @@ -21,6 +21,6 @@ TEN_RUNTIME_PRIVATE_API void ten_builtin_extension_group_addon_destroy_instance( TEN_UNUSED ten_addon_t *addon, ten_env_t *ten_env, void *_extension_group, void *context); -TEN_RUNTIME_PRIVATE_API void ten_register_builtin_extension_group(void); +TEN_RUNTIME_PRIVATE_API void ten_builtin_extension_group_addon_register(void); -TEN_RUNTIME_PRIVATE_API void ten_unregister_builtin_extension_group(void); +TEN_RUNTIME_PRIVATE_API void ten_builtin_extension_group_addon_unregister(void); diff --git a/core/src/ten_runtime/app/ten_env/on_xxx.c b/core/src/ten_runtime/app/ten_env/on_xxx.c index bfd5654a54..bf3a5fc1be 100644 --- a/core/src/ten_runtime/app/ten_env/on_xxx.c +++ b/core/src/ten_runtime/app/ten_env/on_xxx.c @@ -89,7 +89,6 @@ static void ten_app_on_configure_done_internal(ten_app_t *self) { } ten_addon_load_all(&err); - ten_register_builtin_extension_group(); if (!ten_app_get_predefined_graphs_from_property(self)) { return; @@ -223,6 +222,4 @@ void ten_app_on_deinit_done(ten_env_t *ten_env) { ten_env_close(self->ten_env); ten_runloop_stop(self->loop); - - ten_unregister_builtin_extension_group(); } 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 4ba35d4649..16f5214bbd 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 @@ -203,19 +203,28 @@ void ten_builtin_extension_group_addon_destroy_instance( ten_env_on_destroy_instance_done(ten_env, context, NULL); } -void ten_register_builtin_extension_group(void) { - // Register the test_extension_group addon. - ten_addon_t *builtin_extension_group_addon = - ten_addon_create(ten_builtin_extension_group_addon_on_init, NULL, - ten_builtin_extension_group_addon_create_instance, - ten_builtin_extension_group_addon_destroy_instance); - +static ten_addon_t builtin_extension_group_addon = { + NULL, + TEN_ADDON_SIGNATURE, + ten_builtin_extension_group_addon_on_init, + NULL, + NULL, + NULL, + ten_builtin_extension_group_addon_create_instance, + ten_builtin_extension_group_addon_destroy_instance, + NULL, + NULL, +}; + +// Because the name registered by this `builtin_extension_group` is a special +// name (`ten:builtin_extension_group`), with a `:` in the middle, we can't use +// the convenient macro `TEN_REGISTER_ADDON_AS_EXTENSION_GROUP`. We have to use +// an inner register method instead. However, the meaning is exactly the same. +void ten_builtin_extension_group_addon_register(void) { ten_addon_register_extension_group(TEN_STR_BUILTIN_EXTENSION_GROUP, - builtin_extension_group_addon); + &builtin_extension_group_addon); } -void ten_unregister_builtin_extension_group(void) { - ten_addon_t *addon = - ten_addon_unregister_extension_group(TEN_STR_BUILTIN_EXTENSION_GROUP); - ten_addon_destroy(addon); +void ten_builtin_extension_group_addon_unregister(void) { + ten_addon_unregister_extension_group(TEN_STR_BUILTIN_EXTENSION_GROUP); } diff --git a/core/src/ten_runtime/global/on_load.c b/core/src/ten_runtime/global/on_load.c index 56352d79e0..90cd96a7e5 100644 --- a/core/src/ten_runtime/global/on_load.c +++ b/core/src/ten_runtime/global/on_load.c @@ -5,6 +5,7 @@ // Refer to the "LICENSE" file in the root directory for more information. // #include "include_internal/ten_runtime/common/log.h" +#include "include_internal/ten_runtime/extension_group/builtin/builtin_extension_group.h" #include "include_internal/ten_runtime/global/global.h" #include "include_internal/ten_runtime/global/signal.h" #include "include_internal/ten_utils/backtrace/backtrace.h" @@ -33,9 +34,13 @@ TEN_CONSTRUCTOR(ten_runtime_on_load) { ten_global_setup_signal_stuff(); ten_log_global_init(); ten_log_global_set_output_level(DEFAULT_LOG_OUTPUT_LEVEL); + + ten_builtin_extension_group_addon_register(); } TEN_DESTRUCTOR(ten_runtime_on_unload) { + ten_builtin_extension_group_addon_unregister(); + ten_global_deinit(); ten_log_global_deinit(); ten_backtrace_destroy_global();