Skip to content

Commit

Permalink
refactor: rename all callback_info_t to ctx_t (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Jan 2, 2025
1 parent 76e37c3 commit a82e134
Show file tree
Hide file tree
Showing 60 changed files with 1,489 additions and 1,501 deletions.
25 changes: 12 additions & 13 deletions core/include_internal/ten_runtime/addon/addon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions core/include_internal/ten_runtime/addon/protocol/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions core/include_internal/ten_runtime/app/on_xxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
29 changes: 14 additions & 15 deletions core/include_internal/ten_runtime/binding/nodejs/ten_env/ten_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions core/include_internal/ten_runtime/engine/on_xxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions core/include_internal/ten_runtime/extension_thread/on_xxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 20 additions & 20 deletions core/src/ten_runtime/addon/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/ten_runtime/addon/extension/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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),
Expand Down
Loading

0 comments on commit a82e134

Please sign in to comment.