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

feat: add msg pointer in send_xxx callback #601

Merged
merged 1 commit into from
Jan 24, 2025
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
4 changes: 2 additions & 2 deletions core/include/ten_runtime/binding/cpp/detail/ten_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ class ten_env_t {
bool init_manifest_from_json(const char *json_str, error_t *err);

static void proxy_handle_return_error(::ten_env_t *ten_env,
ten_shared_ptr_t *result,
ten_shared_ptr_t *target_cmd,
ten_shared_ptr_t *c_cmd_result,
ten_shared_ptr_t *c_target_cmd,
void *user_data, ::ten_error_t *err) {
TEN_ASSERT(ten_env, "Should not happen.");

Expand Down
8 changes: 4 additions & 4 deletions core/include/ten_runtime/ten_env/internal/return.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

TEN_RUNTIME_API bool ten_env_return_result(
ten_env_t *self, ten_shared_ptr_t *result, ten_shared_ptr_t *target_cmd,
ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err);
ten_env_msg_result_handler_func_t handler, void *user_data,
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_return_result_directly(
ten_env_t *self, ten_shared_ptr_t *cmd,
ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err);
ten_env_msg_result_handler_func_t handler, void *user_data,
ten_error_t *err);
35 changes: 18 additions & 17 deletions core/include/ten_runtime/ten_env/internal/send.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,37 @@
typedef struct ten_env_t ten_env_t;
typedef struct ten_extension_t ten_extension_t;

typedef void (*ten_env_msg_result_handler_func_t)(
ten_env_t *ten_env, ten_shared_ptr_t *cmd_result, ten_shared_ptr_t *msg,
void *result_handler_user_data, ten_error_t *err);
typedef void (*ten_env_msg_result_handler_func_t)(ten_env_t *ten_env,
ten_shared_ptr_t *cmd_result,
ten_shared_ptr_t *msg,
void *user_data,
ten_error_t *err);

typedef bool (*ten_env_send_cmd_func_t)(
ten_env_t *self, ten_shared_ptr_t *cmd,
ten_env_msg_result_handler_func_t result_handler,
void *result_handler_user_data, ten_error_t *err);
ten_env_msg_result_handler_func_t handler, void *user_data,
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_send_cmd(
ten_env_t *self, ten_shared_ptr_t *cmd,
ten_env_msg_result_handler_func_t result_handler,
void *result_handler_user_data, ten_error_t *err);
TEN_RUNTIME_API bool ten_env_send_cmd(ten_env_t *self, ten_shared_ptr_t *cmd,
ten_env_msg_result_handler_func_t handler,
void *user_data, ten_error_t *err);

TEN_RUNTIME_API bool ten_env_send_cmd_ex(
ten_env_t *self, ten_shared_ptr_t *cmd,
ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err);
ten_env_msg_result_handler_func_t handler, void *user_data,
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_send_data(
ten_env_t *self, ten_shared_ptr_t *data,
ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err);
ten_env_msg_result_handler_func_t handler, void *user_data,
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_send_video_frame(
ten_env_t *self, ten_shared_ptr_t *frame,
ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err);
ten_env_msg_result_handler_func_t handler, void *user_data,
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_send_audio_frame(
ten_env_t *self, ten_shared_ptr_t *frame,
ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err);
ten_env_msg_result_handler_func_t handler, void *user_data,
ten_error_t *err);
23 changes: 7 additions & 16 deletions core/include/ten_runtime/test/env_tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,34 @@ TEN_RUNTIME_API bool ten_env_tester_on_start_done(ten_env_tester_t *self,
TEN_RUNTIME_API bool ten_env_tester_on_stop_done(ten_env_tester_t *self,
ten_error_t *err);

typedef void (*ten_env_tester_cmd_result_handler_func_t)(
ten_env_tester_t *self, ten_shared_ptr_t *cmd_result, ten_shared_ptr_t *cmd,
typedef void (*ten_env_tester_msg_result_handler_func_t)(
ten_env_tester_t *self, ten_shared_ptr_t *cmd_result, ten_shared_ptr_t *msg,
void *user_data, ten_error_t *error);

typedef void (*ten_env_tester_return_result_handler_func_t)(
ten_env_tester_t *self, ten_shared_ptr_t *cmd_result,
ten_shared_ptr_t *target_cmd, void *user_data, ten_error_t *error);

typedef void (*ten_env_tester_error_handler_func_t)(ten_env_tester_t *self,
ten_shared_ptr_t *msg,
void *user_data,
ten_error_t *error);

TEN_RUNTIME_API bool ten_env_tester_send_cmd(
ten_env_tester_t *self, ten_shared_ptr_t *cmd,
ten_env_tester_cmd_result_handler_func_t handler, void *user_data,
ten_env_tester_msg_result_handler_func_t handler, void *user_data,
ten_error_t *error);

TEN_RUNTIME_API bool ten_env_tester_send_data(
ten_env_tester_t *self, ten_shared_ptr_t *data,
ten_env_tester_error_handler_func_t handler, void *user_data,
ten_env_tester_msg_result_handler_func_t handler, void *user_data,
ten_error_t *error);

TEN_RUNTIME_API bool ten_env_tester_send_audio_frame(
ten_env_tester_t *self, ten_shared_ptr_t *audio_frame,
ten_env_tester_error_handler_func_t handler, void *user_data,
ten_env_tester_msg_result_handler_func_t handler, void *user_data,
ten_error_t *error);

TEN_RUNTIME_API bool ten_env_tester_send_video_frame(
ten_env_tester_t *self, ten_shared_ptr_t *video_frame,
ten_env_tester_error_handler_func_t handler, void *user_data,
ten_env_tester_msg_result_handler_func_t handler, void *user_data,
ten_error_t *error);

TEN_RUNTIME_API bool ten_env_tester_return_result(
ten_env_tester_t *self, ten_shared_ptr_t *result,
ten_shared_ptr_t *target_cmd,
ten_env_tester_return_result_handler_func_t error_handler, void *user_data,
ten_env_tester_msg_result_handler_func_t handler, void *user_data,
ten_error_t *error);

TEN_RUNTIME_API bool ten_env_tester_stop_test(ten_env_tester_t *self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static void ten_env_notify_return_result_ctx_destroy(
}

static void proxy_handle_return_error(ten_env_t *ten_env,
ten_shared_ptr_t *cmd_result,
ten_shared_ptr_t *target_cmd,
ten_shared_ptr_t *c_cmd_result,
ten_shared_ptr_t *c_target_cmd,
void *user_data, ten_error_t *err) {
TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true),
"Should not happen.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ static void tsfn_proxy_return_result_callback(napi_env env, napi_value js_cb,
}

static void proxy_return_result_error_callback(ten_env_t *self,
ten_shared_ptr_t *cmd_result,
ten_shared_ptr_t *target_cmd,
ten_shared_ptr_t *c_cmd_result,
ten_shared_ptr_t *c_target_cmd,
void *user_data,
ten_error_t *err) {
TEN_ASSERT(self && ten_env_check_integrity(self, true), "Should not happen.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ static void tsfn_proxy_return_result_directly_callback(napi_env env,
}

static void proxy_return_result_directly_error_callback(
ten_env_t *self, ten_shared_ptr_t *cmd_result, ten_shared_ptr_t *target_cmd,
void *user_data, ten_error_t *error) {
ten_env_t *self, ten_shared_ptr_t *c_cmd_result,
ten_shared_ptr_t *c_target_cmd, void *user_data, ten_error_t *error) {
TEN_ASSERT(self && ten_env_check_integrity(self, true), "Should not happen.");

ten_env_notify_return_result_directly_ctx_t *ctx = user_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static void ten_env_notify_return_result_ctx_destroy(
}

static void proxy_return_result_callback(ten_env_t *ten_env,
ten_shared_ptr_t *cmd_result,
ten_shared_ptr_t *target_cmd,
ten_shared_ptr_t *c_cmd_result,
ten_shared_ptr_t *c_target_cmd,
void *callback_info,
ten_error_t *err) {
TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "include_internal/ten_runtime/binding/python/test/env_tester.h"
#include "ten_runtime/test/env_tester.h"
#include "ten_runtime/test/env_tester_proxy.h"
#include "ten_utils/lib/smart_ptr.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/macro/mark.h"
#include "ten_utils/macro/memory.h"

typedef struct ten_py_ten_env_tester_send_audio_frame_ctx_t {
Expand Down Expand Up @@ -45,10 +47,10 @@ static void ten_py_ten_env_tester_send_audio_frame_ctx_destroy(
TEN_FREE(ctx);
}

static void proxy_send_audio_frame_callback(ten_env_tester_t *self,
ten_shared_ptr_t *c_audio_frame,
void *user_audio_frame,
ten_error_t *error) {
static void proxy_send_audio_frame_callback(
ten_env_tester_t *self, TEN_UNUSED ten_shared_ptr_t *c_cmd_result,
ten_shared_ptr_t *c_audio_frame, void *user_audio_frame,
ten_error_t *error) {
TEN_ASSERT(self && ten_env_tester_check_integrity(self, true),
"Should not happen.");
TEN_ASSERT(user_audio_frame, "Should not happen.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "include_internal/ten_runtime/binding/python/test/env_tester.h"
#include "ten_runtime/test/env_tester.h"
#include "ten_runtime/test/env_tester_proxy.h"
#include "ten_utils/lib/smart_ptr.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/macro/mark.h"
#include "ten_utils/macro/memory.h"

typedef struct ten_py_ten_env_tester_send_data_ctx_t {
Expand Down Expand Up @@ -46,6 +48,7 @@ static void ten_py_ten_env_tester_send_data_ctx_destroy(
}

static void proxy_send_data_callback(ten_env_tester_t *self,
TEN_UNUSED ten_shared_ptr_t *c_cmd_result,
ten_shared_ptr_t *c_data, void *user_data,
ten_error_t *error) {
TEN_ASSERT(self && ten_env_tester_check_integrity(self, true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ten_runtime/test/env_tester_proxy.h"
#include "ten_utils/lib/smart_ptr.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/macro/mark.h"
#include "ten_utils/macro/memory.h"

typedef struct ten_py_ten_env_tester_send_video_frame_ctx_t {
Expand Down Expand Up @@ -46,10 +47,10 @@ static void ten_py_ten_env_tester_send_video_frame_ctx_destroy(
TEN_FREE(ctx);
}

static void proxy_send_video_frame_callback(ten_env_tester_t *self,
ten_shared_ptr_t *c_video_frame,
void *user_video_frame,
ten_error_t *error) {
static void proxy_send_video_frame_callback(
ten_env_tester_t *self, TEN_UNUSED ten_shared_ptr_t *c_cmd_result,
ten_shared_ptr_t *c_video_frame, void *user_video_frame,
ten_error_t *error) {
TEN_ASSERT(self && ten_env_tester_check_integrity(self, true),
"Should not happen.");
TEN_ASSERT(user_video_frame, "Should not happen.");
Expand Down
38 changes: 18 additions & 20 deletions core/src/ten_runtime/ten_env/internal/return.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

static bool ten_env_return_result_internal(
ten_env_t *self, ten_shared_ptr_t *result_cmd, const char *cmd_id,
const char *seq_id, ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err) {
const char *seq_id, ten_env_msg_result_handler_func_t handler,
void *user_data, ten_error_t *err) {
TEN_ASSERT(self, "Invalid argument.");
TEN_ASSERT(ten_env_check_integrity(self, true), "Invalid use of ten_env %p.",
self);
Expand Down Expand Up @@ -93,14 +93,14 @@ static bool ten_env_return_result_internal(
break;
}

if (result && error_handler) {
if (result && handler) {
// If the method synchronously returns true, it means that the callback must
// be called.
//
// We temporarily assume that the message enqueue represents success;
// therefore, in this case, we set the error to NULL to indicate that the
// returning was successful.
error_handler(self, NULL, NULL, error_handler_user_data, NULL);
handler(self, NULL, NULL, user_data, NULL);
}

if (err_new_created) {
Expand All @@ -112,39 +112,37 @@ static bool ten_env_return_result_internal(

// If the 'cmd' has already been a command in the backward path, a extension
// could use this API to return the 'cmd' further.
bool ten_env_return_result_directly(
ten_env_t *self, ten_shared_ptr_t *result_cmd,
ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err) {
bool ten_env_return_result_directly(ten_env_t *self,
ten_shared_ptr_t *cmd_result,
ten_env_msg_result_handler_func_t handler,
void *user_data, ten_error_t *err) {
TEN_ASSERT(self, "Invalid argument.");
TEN_ASSERT(ten_env_check_integrity(self, true), "Invalid use of ten_env %p.",
self);
TEN_ASSERT(result_cmd && ten_cmd_base_check_integrity(result_cmd),
TEN_ASSERT(cmd_result && ten_cmd_base_check_integrity(cmd_result),
"Should not happen.");
TEN_ASSERT(ten_msg_get_type(result_cmd) == TEN_MSG_TYPE_CMD_RESULT,
TEN_ASSERT(ten_msg_get_type(cmd_result) == TEN_MSG_TYPE_CMD_RESULT,
"The target cmd must be a cmd result.");

return ten_env_return_result_internal(self, result_cmd, NULL, NULL,
error_handler, error_handler_user_data,
err);
return ten_env_return_result_internal(self, cmd_result, NULL, NULL, handler,
user_data, err);
}

bool ten_env_return_result(ten_env_t *self, ten_shared_ptr_t *result_cmd,
bool ten_env_return_result(ten_env_t *self, ten_shared_ptr_t *cmd_result,
ten_shared_ptr_t *target_cmd,
ten_env_msg_result_handler_func_t error_handler,
void *error_handler_user_data, ten_error_t *err) {
ten_env_msg_result_handler_func_t handler,
void *user_data, ten_error_t *err) {
TEN_ASSERT(self, "Invalid argument.");
TEN_ASSERT(ten_env_check_integrity(self, true), "Invalid use of ten_env %p.",
self);
TEN_ASSERT(result_cmd && ten_cmd_base_check_integrity(result_cmd),
TEN_ASSERT(cmd_result && ten_cmd_base_check_integrity(cmd_result),
"Should not happen.");
TEN_ASSERT((target_cmd ? ten_cmd_base_check_integrity(target_cmd) : true),
"Should not happen.");
TEN_ASSERT(ten_msg_get_type(target_cmd) != TEN_MSG_TYPE_CMD_RESULT,
"The target cmd should not be a cmd result.");

return ten_env_return_result_internal(
self, result_cmd, ten_cmd_base_get_cmd_id(target_cmd),
ten_cmd_base_get_seq_id(target_cmd), error_handler,
error_handler_user_data, err);
self, cmd_result, ten_cmd_base_get_cmd_id(target_cmd),
ten_cmd_base_get_seq_id(target_cmd), handler, user_data, err);
}
Loading
Loading