diff --git a/core/include/ten_runtime/binding/cpp/internal/ten_env.h b/core/include/ten_runtime/binding/cpp/internal/ten_env.h index 73b76928e5..e6a6702b83 100644 --- a/core/include/ten_runtime/binding/cpp/internal/ten_env.h +++ b/core/include/ten_runtime/binding/cpp/internal/ten_env.h @@ -49,11 +49,6 @@ class ten_env_internal_accessor_t; using result_handler_func_t = std::function)>; -using addon_create_extension_async_cb_t = - std::function; - -using addon_destroy_extension_async_cb_t = std::function; - using set_property_async_cb_t = std::function; @@ -593,32 +588,6 @@ class ten_env_t { err != nullptr ? err->get_internal_representation() : nullptr); } - bool addon_create_extension_async( - const char *addon_name, const char *instance_name, - addon_create_extension_async_cb_t &&cb = nullptr, - error_t *err = nullptr) { - if (cb == nullptr) { - return ten_addon_create_extension( - c_ten_env, addon_name, instance_name, nullptr, nullptr, - err != nullptr ? err->get_internal_representation() : nullptr); - } else { - auto *cb_ptr = new addon_create_extension_async_cb_t(std::move(cb)); - - return ten_addon_create_extension( - c_ten_env, addon_name, instance_name, - proxy_addon_create_extension_async_cb, cb_ptr, - err != nullptr ? err->get_internal_representation() : nullptr); - } - } - - bool addon_destroy_extension(ten::extension_t *extension, - error_t *err = nullptr); - - bool addon_destroy_extension_async( - ten::extension_t *extension, - addon_destroy_extension_async_cb_t &&cb = nullptr, - error_t *err = nullptr); - bool on_configure_done(error_t *err = nullptr) { TEN_ASSERT(c_ten_env, "Should not happen."); @@ -660,15 +629,6 @@ class ten_env_t { err != nullptr ? err->get_internal_representation() : nullptr); } - bool on_create_extensions_done(const std::vector &extensions, - error_t *err = nullptr); - - bool on_destroy_extensions_done(error_t *err = nullptr) { - return ten_env_on_destroy_extensions_done( - c_ten_env, - err != nullptr ? err->get_internal_representation() : nullptr); - } - bool on_create_instance_done(void *instance, void *context, error_t *err = nullptr); @@ -900,35 +860,6 @@ class ten_env_t { } } - static void proxy_addon_create_extension_async_cb(::ten_env_t *ten_env, - void *instance, - void *cb_data) { - auto *addon_create_extension_async_cb = - static_cast(cb_data); - auto *cpp_ten_env = - static_cast(ten_binding_handle_get_me_in_target_lang( - reinterpret_cast(ten_env))); - - (*addon_create_extension_async_cb)( - *cpp_ten_env, - *static_cast( - ten_binding_handle_get_me_in_target_lang( - reinterpret_cast(instance)))); - delete addon_create_extension_async_cb; - } - - static void proxy_addon_destroy_extension_async_cb(::ten_env_t *ten_env, - void *cb_data) { - auto *addon_destroy_extension_async_cb = - static_cast(cb_data); - auto *cpp_ten_env = - static_cast(ten_binding_handle_get_me_in_target_lang( - reinterpret_cast(ten_env))); - - (*addon_destroy_extension_async_cb)(*cpp_ten_env); - delete addon_destroy_extension_async_cb; - } - static void proxy_set_property_callback(::ten_env_t *ten_env, bool res, void *cb_data, ten_error_t *err) { auto *callback = static_cast(cb_data); diff --git a/core/include/ten_runtime/binding/cpp/internal/ten_env_impl.h b/core/include/ten_runtime/binding/cpp/internal/ten_env_impl.h index de52c713e4..4563932df5 100644 --- a/core/include/ten_runtime/binding/cpp/internal/ten_env_impl.h +++ b/core/include/ten_runtime/binding/cpp/internal/ten_env_impl.h @@ -45,35 +45,4 @@ inline bool ten_env_t::on_create_instance_done(void *instance, void *context, return rc; } -inline bool ten_env_t::on_create_extensions_done( - const std::vector &extensions, error_t *err) { - ten_list_t c_extensions = TEN_LIST_INIT_VAL; - - for (const auto &extension : extensions) { - ten_list_push_ptr_back(&c_extensions, extension->get_c_extension(), - nullptr); - } - - return ten_env_on_create_extensions_done( - c_ten_env, &c_extensions, - err != nullptr ? err->get_internal_representation() : nullptr); -} - -inline bool ten_env_t::addon_destroy_extension_async( - ten::extension_t *extension, addon_destroy_extension_async_cb_t &&cb, - error_t *err) { - if (cb == nullptr) { - return ten_addon_destroy_extension( - c_ten_env, extension->get_c_extension(), nullptr, nullptr, - err != nullptr ? err->get_internal_representation() : nullptr); - } else { - auto *cb_ptr = new addon_destroy_extension_async_cb_t(std::move(cb)); - - return ten_addon_destroy_extension( - c_ten_env, extension->get_c_extension(), - proxy_addon_destroy_extension_async_cb, cb_ptr, - err != nullptr ? err->get_internal_representation() : nullptr); - } -} - } // namespace ten diff --git a/core/src/ten_runtime/binding/go/interface/ten/prop.go b/core/src/ten_runtime/binding/go/interface/ten/prop.go index 500519e99e..6d809b7900 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/prop.go +++ b/core/src/ten_runtime/binding/go/interface/ten/prop.go @@ -266,10 +266,6 @@ type iProperty interface { GetPropertyToJSONBytes(path string) ([]byte, error) } -type iPropertyContainerForAsyncGeneric interface { - postAsyncJob(payload job) any -} - // The purpose of having this function is because there are two types of // getProperty: // diff --git a/core/src/ten_runtime/binding/go/interface/ten/ten_env.go b/core/src/ten_runtime/binding/go/interface/ten/ten_env.go index 3aa0daa1fe..4f96872b05 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/ten_env.go +++ b/core/src/ten_runtime/binding/go/interface/ten/ten_env.go @@ -25,9 +25,6 @@ type ( // TenEnv represents the interface for the TEN (Run Time Environment) component. type TenEnv interface { - postSyncJob(payload job) any - postAsyncJob(payload job) any - SendCmd(cmd Cmd, handler ResultHandler) error SendData(data Data) error SendVideoFrame(videoFrame VideoFrame) error @@ -41,26 +38,11 @@ type TenEnv interface { OnStartDone() error OnStopDone() error OnDeinitDone() error - - OnCreateExtensionsDone(extensions ...Extension) error - OnDestroyExtensionsDone() error - OnCreateInstanceDone(instance any, context uintptr) error IsCmdConnected(cmdName string) (bool, error) - AddonCreateExtensionAsync( - addonName string, - instanceName string, - callback func(tenEnv TenEnv, p Extension), - ) error - AddonDestroyExtensionAsync( - ext Extension, - callback func(tenEnv TenEnv), - ) error - iProperty - InitPropertyFromJSONBytes(value []byte) error LogVerbose(msg string) @@ -71,6 +53,9 @@ type TenEnv interface { LogFatal(msg string) Log(level LogLevel, msg string) + // Private functions. + postSyncJob(payload job) any + postAsyncJob(payload job) any logInternal(level LogLevel, msg string, skip int) } @@ -85,8 +70,7 @@ type TenEnv interface { // in my code; I just want to make sure it's true." If 'ten' doesn't implement // Ten, you'll know as soon as you try to compile. var ( - _ TenEnv = new(tenEnv) - _ iPropertyContainerForAsyncGeneric = new(tenEnv) + _ TenEnv = new(tenEnv) ) type tenAttachTo uint8 @@ -322,36 +306,6 @@ func (p *tenEnv) OnDeinitDone() error { return nil } -func (p *tenEnv) OnCreateExtensionsDone(extensions ...Extension) error { - if len(extensions) == 0 { - return nil - } - - var extensionArray []C.uintptr_t - for _, v := range extensions { - extension, ok := v.(*extension) - if !ok { - panic("Invalid extension type") - } - - extensionArray = append(extensionArray, extension.cPtr) - } - - C.ten_go_ten_env_on_create_extensions_done( - p.cPtr, - unsafe.Pointer(unsafe.SliceData(extensionArray)), - C.int(len(extensions)), - ) - - return nil -} - -func (p *tenEnv) OnDestroyExtensionsDone() error { - C.ten_go_ten_env_on_destroy_extensions_done(p.cPtr) - - return nil -} - func (p *tenEnv) OnCreateInstanceDone(instance any, context uintptr) error { switch instance := instance.(type) { case *extension: @@ -372,59 +326,6 @@ func (p *tenEnv) IsCmdConnected(cmdName string) (bool, error) { }).(bool), nil } -func (p *tenEnv) AddonCreateExtensionAsync( - addonName string, - instanceName string, - callback func(tenEnv TenEnv, p Extension), -) error { - handlerID := newhandle(callback) - - cAddonName := C.CString(addonName) - defer C.free(unsafe.Pointer(cAddonName)) - - cInstanceName := C.CString(instanceName) - defer C.free(unsafe.Pointer(cInstanceName)) - - res := bool( - C.ten_go_ten_env_addon_create_extension( - p.cPtr, - cAddonName, - cInstanceName, - C.uintptr_t(handlerID), - ), - ) - if !res { - return newTenError( - ErrnoGeneric, - fmt.Sprintf("failed to find addon: %s", addonName), - ) - } - - return nil -} - -func (p *tenEnv) AddonDestroyExtensionAsync( - ext Extension, - callback func(tenEnv TenEnv), -) error { - extension, ok := ext.(*extension) - if !ok { - return newTenError( - ErrnoInvalidArgument, - "wrong extension type.", - ) - } - - handlerID := newhandle(callback) - - C.ten_go_ten_env_addon_destroy_extension( - p.cPtr, - extension.cPtr, - C.uintptr_t(handlerID), - ) - return nil -} - func (p *tenEnv) String() string { cString := C.ten_go_ten_env_debug_info(p.cPtr) defer C.free(unsafe.Pointer(cString)) diff --git a/core/src/ten_runtime/binding/go/interface/ten/ten_env.h b/core/src/ten_runtime/binding/go/interface/ten/ten_env.h index 118c4ec510..e1ea3231e1 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/ten_env.h +++ b/core/src/ten_runtime/binding/go/interface/ten/ten_env.h @@ -31,11 +31,6 @@ void ten_go_ten_env_on_stop_done(uintptr_t bridge_addr); void ten_go_ten_env_on_deinit_done(uintptr_t bridge_addr); -void ten_go_ten_env_on_create_extensions_done( - uintptr_t bridge_addr, const void *extension_bridge_array, int size); - -void ten_go_ten_env_on_destroy_extensions_done(uintptr_t bridge_addr); - void ten_go_ten_env_on_create_instance_done(uintptr_t bridge_addr, uintptr_t instance_bridge_addr, uintptr_t context_addr); diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_create_extension_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_create_extension_done.c deleted file mode 100644 index 367d12c36d..0000000000 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_create_extension_done.c +++ /dev/null @@ -1,112 +0,0 @@ -// -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to the "LICENSE" file in the root directory for more information. -// -#include -#include - -#include "include_internal/ten_runtime/binding/go/extension/extension.h" -#include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" -#include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" -#include "include_internal/ten_runtime/ten_env/ten_env.h" -#include "ten_runtime/binding/go/interface/ten/ten_env.h" -#include "ten_runtime/ten_env_proxy/ten_env_proxy.h" -#include "ten_utils/lib/alloc.h" -#include "ten_utils/macro/check.h" - -typedef struct ten_env_notify_on_create_extensions_done_info_t { - ten_list_t result; -} ten_env_notify_on_create_extensions_done_info_t; - -static ten_env_notify_on_create_extensions_done_info_t * -ten_env_notify_on_create_extensions_done_info_create(ten_list_t *result) { - TEN_ASSERT(result, "Invalid argument."); - - ten_env_notify_on_create_extensions_done_info_t *info = - TEN_MALLOC(sizeof(ten_env_notify_on_create_extensions_done_info_t)); - TEN_ASSERT(info, "Failed to allocate memory."); - - ten_list_init(&info->result); - ten_list_swap(&info->result, result); - - return info; -} - -static void ten_env_notify_on_create_extensions_done_info_destroy( - ten_env_notify_on_create_extensions_done_info_t *info) { - TEN_ASSERT(info, "Invalid argument."); - - ten_list_clear(&info->result); - - TEN_FREE(info); -} - -static void ten_notify_proxy_on_create_extensions_done(ten_env_t *ten_env, - void *user_data) { - TEN_ASSERT(user_data, "Invalid argument."); - TEN_ASSERT( - ten_env && - ten_env_check_integrity( - ten_env, - ten_env->attach_to != TEN_ENV_ATTACH_TO_ADDON ? true : false), - "Should not happen."); - - ten_env_notify_on_create_extensions_done_info_t *info = user_data; - - ten_error_t err; - ten_error_init(&err); - - bool rc = ten_env_on_create_extensions_done(ten_env, &info->result, &err); - TEN_ASSERT(rc, "Should not happen."); - - ten_error_deinit(&err); - - ten_env_notify_on_create_extensions_done_info_destroy(info); -} - -void ten_go_ten_env_on_create_extensions_done( - uintptr_t bridge_addr, const void *extension_bridge_array, int size) { - ten_go_ten_env_t *self = ten_go_ten_env_reinterpret(bridge_addr); - TEN_ASSERT(self && ten_go_ten_env_check_integrity(self), - "Should not happen."); - - ten_list_t result = TEN_LIST_INIT_VAL; - - if (size == 0) { - goto done; - } - - uintptr_t *extensions = (uintptr_t *)extension_bridge_array; - for (int i = 0; i < size; i++) { - ten_go_extension_t *extension_bridge = - ten_go_extension_reinterpret(extensions[i]); - ten_list_push_ptr_back( - &result, ten_go_extension_c_extension(extension_bridge), NULL); - } - -done: - TEN_GO_TEN_ENV_IS_ALIVE_REGION_BEGIN(self, {}); - - ten_error_t err; - ten_error_init(&err); - - ten_env_notify_on_create_extensions_done_info_t - *on_create_extensions_done_info = - ten_env_notify_on_create_extensions_done_info_create(&result); - - if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_notify_proxy_on_create_extensions_done, - on_create_extensions_done_info, false, &err)) { - TEN_LOGD("TEN/GO failed to on_create_extensions_done."); - - ten_env_notify_on_create_extensions_done_info_destroy( - on_create_extensions_done_info); - } - - ten_error_deinit(&err); - TEN_GO_TEN_ENV_IS_ALIVE_REGION_END(self); -ten_is_close: - return; -} diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_delete_extension_done.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_delete_extension_done.c deleted file mode 100644 index b6e4ef477c..0000000000 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_on_delete_extension_done.c +++ /dev/null @@ -1,54 +0,0 @@ -// -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to the "LICENSE" file in the root directory for more information. -// -#include - -#include "include_internal/ten_runtime/binding/go/ten_env/ten_env.h" -#include "include_internal/ten_runtime/binding/go/ten_env/ten_env_internal.h" -#include "ten_runtime/binding/go/interface/ten/ten_env.h" -#include "ten_runtime/ten_env_proxy/ten_env_proxy.h" -#include "ten_utils/macro/check.h" -#include "ten_utils/macro/mark.h" - -static void ten_env_proxy_notify_on_destroy_extensions_done( - ten_env_t *ten_env, TEN_UNUSED void *user_data) { - TEN_ASSERT( - ten_env && - ten_env_check_integrity( - ten_env, - ten_env->attach_to != TEN_ENV_ATTACH_TO_ADDON ? true : false), - "Should not happen."); - - ten_error_t err; - ten_error_init(&err); - - bool rc = ten_env_on_destroy_extensions_done(ten_env, &err); - TEN_ASSERT(rc, "Should not happen."); - - ten_error_deinit(&err); -} - -void ten_go_ten_env_on_destroy_extensions_done(uintptr_t bridge_addr) { - ten_go_ten_env_t *self = ten_go_ten_env_reinterpret(bridge_addr); - TEN_ASSERT(self && ten_go_ten_env_check_integrity(self), - "Should not happen."); - - TEN_GO_TEN_ENV_IS_ALIVE_REGION_BEGIN(self, {}); - - ten_error_t err; - ten_error_init(&err); - - if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_on_destroy_extensions_done, - NULL, false, &err)) { - TEN_LOGD("TEN/GO failed to on_destroy_extensions_done."); - } - - ten_error_deinit(&err); - TEN_GO_TEN_ENV_IS_ALIVE_REGION_END(self); -ten_is_close: - return; -} diff --git a/core/src/ten_runtime/binding/python/interface/ten/addon.py b/core/src/ten_runtime/binding/python/interface/ten/addon.py index ac460a1a6c..b60c68793d 100644 --- a/core/src/ten_runtime/binding/python/interface/ten/addon.py +++ b/core/src/ten_runtime/binding/python/interface/ten/addon.py @@ -16,17 +16,48 @@ class Addon(_Addon): @classmethod def _load_all(cls): base_dir = cls._find_app_base_dir() + + # Read manifest.json under base_dir. + manifest_path = os.path.join(base_dir, "manifest.json") + if not os.path.isfile(manifest_path): + raise FileNotFoundError("manifest.json not found in base_dir") + + with open(manifest_path, "r") as f: + manifest = json.load(f) + + # Note: The logic for loading extensions based on the `dependencies` + # specified in the app's `manifest.json` is currently implemented + # separately in both C and Python where addons need to be loaded. Since + # the logic is fairly simple, a standalone implementation is directly + # written at each required location. In the future, this could be + # consolidated into a unified implementation in C, which could then be + # reused across multiple languages. However, this would require handling + # cross-language information exchange, which may not necessarily be + # cost-effective. + + # Collect names of extensions from dependencies. + extension_names = [] + dependencies = manifest.get("dependencies", []) + for dep in dependencies: + if dep.get("type") == "extension": + extension_names.append(dep.get("name")) + for module in glob(os.path.join(base_dir, "ten_packages/extension/*")): if os.path.isdir(module): module_name = os.path.basename(module) - spec = importlib.util.find_spec( - "ten_packages.extension.{}".format(module_name) - ) - if spec is not None: - _ = importlib.import_module( + + if module_name in extension_names: + # Proceed to load the module. + spec = importlib.util.find_spec( "ten_packages.extension.{}".format(module_name) ) - print("imported module: {}".format(module_name)) + if spec is not None: + _ = importlib.import_module( + "ten_packages.extension.{}".format(module_name) + ) + print("imported module: {}".format(module_name)) + else: + print("Skipping module: {}".format(module_name)) @classmethod def _load_from_path(cls, path): diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go index ddff0d482b..85f6a9a78e 100644 --- a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go @@ -50,7 +50,8 @@ func (p *extensionA) OnCmd( panic("should not happen") } - fmt.Println("getPropertyAsync agora error, ", err) + fmt.Println("GetPropertyString error, ", err) + statusCode, _ := cs.GetStatusCode() cmdResult, _ := ten.NewCmdResult(statusCode) cmdResult.SetPropertyString("detail", detail)