Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refine some codes #471

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions core/include/ten_runtime/extension_group/extension_group.h

This file was deleted.

25 changes: 12 additions & 13 deletions core/include/ten_runtime/ten.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@

#include "ten_runtime/ten_config.h"

#include "ten_runtime/addon/addon.h" // IWYU pragma: export
#include "ten_runtime/addon/extension/extension.h" // IWYU pragma: export
#include "ten_runtime/app/app.h" // IWYU pragma: export
#include "ten_runtime/common/errno.h" // IWYU pragma: export
#include "ten_runtime/extension/extension.h" // IWYU pragma: export
#include "ten_runtime/extension_group/extension_group.h" // IWYU pragma: export
#include "ten_runtime/msg/audio_frame/audio_frame.h" // IWYU pragma: export
#include "ten_runtime/msg/cmd/close_app/cmd.h" // IWYU pragma: export
#include "ten_runtime/msg/cmd_result/cmd_result.h" // IWYU pragma: export
#include "ten_runtime/msg/data/data.h" // IWYU pragma: export
#include "ten_runtime/msg/msg.h" // IWYU pragma: export
#include "ten_runtime/msg/video_frame/video_frame.h" // IWYU pragma: export
#include "ten_runtime/ten_env/ten_env.h" // IWYU pragma: export
#include "ten_runtime/addon/addon.h" // IWYU pragma: export
#include "ten_runtime/addon/extension/extension.h" // IWYU pragma: export
#include "ten_runtime/app/app.h" // IWYU pragma: export
#include "ten_runtime/common/errno.h" // IWYU pragma: export
#include "ten_runtime/extension/extension.h" // IWYU pragma: export
#include "ten_runtime/msg/audio_frame/audio_frame.h" // IWYU pragma: export
#include "ten_runtime/msg/cmd/close_app/cmd.h" // IWYU pragma: export
#include "ten_runtime/msg/cmd_result/cmd_result.h" // IWYU pragma: export
#include "ten_runtime/msg/data/data.h" // IWYU pragma: export
#include "ten_runtime/msg/msg.h" // IWYU pragma: export
#include "ten_runtime/msg/video_frame/video_frame.h" // IWYU pragma: export
#include "ten_runtime/ten_env/ten_env.h" // IWYU pragma: export
7 changes: 2 additions & 5 deletions core/include/ten_utils/lang/cpp/lib/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ class error_t {
error_t(error_t &&) = delete;
error_t &operator=(error_t &&) = delete;

void reset() { ten_error_reset(c_error); }

bool is_success() { return ten_error_is_success(c_error); }

const char *errmsg() { return ten_error_errmsg(c_error); }
const char *err_msg() { return ten_error_errmsg(c_error); }

// Internal use only.
bool is_success() { return ten_error_is_success(c_error); }
ten_error_t *get_c_error() { return c_error; }

private:
Expand Down
3 changes: 3 additions & 0 deletions core/include_internal/ten_runtime/addon/addon_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ typedef struct ten_addon_register_ctx_t {
} ten_addon_register_ctx_t;

typedef struct ten_addon_manager_t {
// Define a registry map to store addon registration functions.
// The key is the addon name (string), and the value is a function that takes
// a register_ctx.
ten_list_t registry; // ten_addon_registration_t*
ten_mutex_t *mutex;
} ten_addon_manager_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "include_internal/ten_runtime/binding/common.h"
#include "include_internal/ten_runtime/metadata/metadata.h"
#include "ten_runtime/binding/common.h"
#include "ten_runtime/extension_group/extension_group.h"
#include "ten_utils/container/list.h"
#include "ten_utils/io/runloop.h"
#include "ten_utils/lib/signature.h"
Expand All @@ -33,6 +32,21 @@ typedef struct ten_addon_host_t ten_addon_host_t;
typedef struct ten_env_t ten_env_t;
typedef struct ten_extension_group_info_t ten_extension_group_info_t;

typedef void (*ten_extension_group_on_configure_func_t)(
ten_extension_group_t *self, ten_env_t *ten_env);

typedef void (*ten_extension_group_on_init_func_t)(ten_extension_group_t *self,
ten_env_t *ten_env);

typedef void (*ten_extension_group_on_deinit_func_t)(
ten_extension_group_t *self, ten_env_t *ten_env);

typedef void (*ten_extension_group_on_create_extensions_func_t)(
ten_extension_group_t *self, ten_env_t *ten_env);

typedef void (*ten_extension_group_on_destroy_extensions_func_t)(
ten_extension_group_t *self, ten_env_t *ten_env, ten_list_t extensions);

typedef enum TEN_EXTENSION_GROUP_STATE {
TEN_EXTENSION_GROUP_STATE_INIT,
TEN_EXTENSION_GROUP_STATE_DEINITING, // on_deinit() is started.
Expand Down Expand Up @@ -79,6 +93,22 @@ typedef struct ten_extension_group_t {
size_t extensions_cnt_of_being_destroyed;
} ten_extension_group_t;

TEN_RUNTIME_API bool ten_extension_group_check_integrity(
ten_extension_group_t *self, bool check_thread);

TEN_RUNTIME_PRIVATE_API ten_extension_group_t *ten_extension_group_create(
const char *name, ten_extension_group_on_configure_func_t on_configure,
ten_extension_group_on_init_func_t on_init,
ten_extension_group_on_deinit_func_t on_deinit,
ten_extension_group_on_create_extensions_func_t on_create_extensions,
ten_extension_group_on_destroy_extensions_func_t on_destroy_extensions);

TEN_RUNTIME_PRIVATE_API void ten_extension_group_destroy(
ten_extension_group_t *self);

TEN_RUNTIME_PRIVATE_API ten_env_t *ten_extension_group_get_ten_env(
ten_extension_group_t *self);

TEN_RUNTIME_PRIVATE_API void ten_extension_group_create_extensions(
ten_extension_group_t *self);

Expand Down Expand Up @@ -106,14 +136,15 @@ TEN_RUNTIME_PRIVATE_API void ten_extension_group_on_destroy_extensions_done(
TEN_RUNTIME_PRIVATE_API void ten_extension_group_on_create_extensions_done(
ten_extension_group_t *self, ten_list_t *extensions);

TEN_RUNTIME_API ten_list_t *
TEN_RUNTIME_PRIVATE_API ten_list_t *
ten_extension_group_get_extension_addon_and_instance_name_pairs(
ten_extension_group_t *self);

TEN_RUNTIME_API void ten_extension_group_set_extension_cnt_of_being_destroyed(
TEN_RUNTIME_PRIVATE_API void
ten_extension_group_set_extension_cnt_of_being_destroyed(
ten_extension_group_t *self, size_t new_cnt);

TEN_RUNTIME_API size_t
TEN_RUNTIME_PRIVATE_API size_t
ten_extension_group_decrement_extension_cnt_of_being_destroyed(
ten_extension_group_t *self);

Expand Down
2 changes: 0 additions & 2 deletions core/src/ten_manager/designer_frontend/src/api/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ export interface BackendNode {

export interface BackendConnection {
app: string;
extension_group: string;
extension: string;
cmd?: {
name: string;
dest: {
app: string;
extension_group: string;
extension: string;
}[];
}[];
Expand Down
4 changes: 2 additions & 2 deletions core/src/ten_manager/src/cmd/cmd_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ pub async fn execute_cmd(
let mut preinstall_chdir_path: Option<PathBuf> = None;

// If `tman install` is run within the scope of an app, then the app and
// those addons (extensions, extension_groups, ...) installed in the app
// directory are all considered initial_input_pkgs.
// those addons (extensions, ...) installed in the app directory are all
// considered initial_input_pkgs.
let mut initial_input_pkgs = vec![];
let mut all_candidates: HashMap<
PkgTypeAndName,
Expand Down
10 changes: 2 additions & 8 deletions core/src/ten_manager/src/cmd_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ pub struct ArgsCfg {
fn get_args_cfg() -> ArgsCfg {
ArgsCfg {
pkg_type: ArgCfg {
possible_values: [
"system",
"protocol",
"extension",
"extension_group",
"app",
]
.to_vec(),
possible_values: ["system", "protocol", "extension", "app"]
.to_vec(),
},
os: ArgCfg {
possible_values: ["linux", "mac", "win"].to_vec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "include_internal/ten_runtime/ten_env/metadata.h"
#include "include_internal/ten_runtime/ten_env/ten_env.h"
#include "ten_runtime/addon/addon.h"
#include "ten_runtime/extension_group/extension_group.h"
#include "ten_runtime/ten.h"
#include "ten_runtime/ten_env/internal/log.h"
#include "ten_runtime/ten_env/ten_env.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
#include "include_internal/ten_runtime/ten_env/ten_env.h"
#include "include_internal/ten_runtime/ten_env/ten_env_proxy.h"
#include "include_internal/ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_utils/macro/check.h"
#include "ten_runtime/extension/extension.h"
#include "ten_runtime/extension_group/extension_group.h"
#include "ten_runtime/ten_env/ten_env.h"
#include "ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_utils/io/runloop.h"
#include "ten_utils/lib/alloc.h"
#include "ten_utils/lib/mutex.h"
#include "ten_utils/lib/thread.h"
#include "ten_utils/macro/check.h"

bool ten_env_proxy_acquire_lock_mode(ten_env_proxy_t *self, ten_error_t *err) {
// The outer thread must ensure the validity of the ten_env_proxy instance.
Expand Down
1 change: 0 additions & 1 deletion core/src/ten_runtime/ten_env_proxy/internal/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "include_internal/ten_runtime/ten_env/ten_env_proxy.h"
#include "include_internal/ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_runtime/extension/extension.h"
#include "ten_runtime/extension_group/extension_group.h"
#include "ten_runtime/ten_env/ten_env.h"
#include "ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_utils/io/runloop.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
#include "include_internal/ten_runtime/ten_env/ten_env.h"
#include "include_internal/ten_runtime/ten_env/ten_env_proxy.h"
#include "include_internal/ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_utils/macro/check.h"
#include "ten_runtime/extension/extension.h"
#include "ten_runtime/extension_group/extension_group.h"
#include "ten_runtime/ten_env/ten_env.h"
#include "ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_utils/lib/mutex.h"
#include "ten_utils/lib/thread.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/macro/memory.h"

bool ten_env_proxy_release_lock_mode(ten_env_proxy_t *self, ten_error_t *err) {
Expand Down
1 change: 0 additions & 1 deletion core/src/ten_runtime/ten_env_proxy/ten_env_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "include_internal/ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_runtime/common/errno.h"
#include "ten_runtime/extension/extension.h"
#include "ten_runtime/extension_group/extension_group.h"
#include "ten_runtime/ten_env/ten_env.h"
#include "ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_utils/io/runloop.h"
Expand Down
1 change: 0 additions & 1 deletion core/src/ten_runtime/test/test_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "include_internal/ten_runtime/test/env_tester.h"
#include "include_internal/ten_runtime/test/extension_tester.h"
#include "ten_runtime/addon/addon.h"
#include "ten_runtime/extension_group/extension_group.h"
#include "ten_runtime/ten.h"
#include "ten_runtime/ten_env/internal/log.h"
#include "ten_runtime/ten_env/internal/on_xxx_done.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ void send_ten_msg_with_req_body(
if (error != nullptr) {
prepare_response_data_from_ten_world(
http_session_data, "The command is not supported. err:" +
std::string(error->errmsg()));
std::string(error->err_msg()));
return;
}

Expand Down Expand Up @@ -682,7 +682,7 @@ void send_ten_msg_without_req_body(
if (error != nullptr) {
prepare_response_data_from_ten_world(
http_session_data, "The command is not supported. err:" +
std::string(error->errmsg()));
std::string(error->err_msg()));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ten_runtime/smoke/dest/no_audio_frame_dest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class test_extension_1 : public ten::extension_t {
ASSERT_EQ(rc, false);
ASSERT_EQ(err.is_success(), false);

TEN_ENV_LOG_ERROR(ten_env, err.errmsg());
TEN_ENV_LOG_ERROR(ten_env, err.err_msg());

auto audio_frame = ten::audio_frame_t::create("audio_frame");
rc = ten_env.send_audio_frame(std::move(audio_frame));
Expand Down
Loading