Skip to content

Commit

Permalink
fix: refine codes
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Dec 2, 2024
1 parent eda3d37 commit be4c39b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions core/include/ten_runtime/ten_env/internal/return.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ typedef void (*ten_env_return_result_error_handler_func_t)(ten_env_t *self,
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_return_result_error_handler_func_t error_handler,
void *error_handler_data, ten_error_t *err);
void *error_handler_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_return_result_error_handler_func_t error_handler,
void *error_handler_data, ten_error_t *err);
void *error_handler_user_data, ten_error_t *err);
11 changes: 9 additions & 2 deletions core/src/ten_runtime/binding/go/interface/ten/ten_env_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ package ten
//#include "ten_env.h"
import "C"

func (p *tenEnv) ReturnResult(statusCmd CmdResult, cmd Cmd, handler ErrorHandler) error {
func (p *tenEnv) ReturnResult(
statusCmd CmdResult,
cmd Cmd,
handler ErrorHandler,
) error {
if statusCmd == nil {
return newTenError(
ErrnoInvalidArgument,
Expand Down Expand Up @@ -54,7 +58,10 @@ func (p *tenEnv) ReturnResult(statusCmd CmdResult, cmd Cmd, handler ErrorHandler
return err
}

func (p *tenEnv) ReturnResultDirectly(statusCmd CmdResult, handler ErrorHandler) error {
func (p *tenEnv) ReturnResultDirectly(
statusCmd CmdResult,
handler ErrorHandler,
) error {
if statusCmd == nil {
return newTenError(
ErrnoInvalidArgument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
#include "ten_runtime/binding/go/interface/ten/msg.h"
#include "ten_runtime/binding/go/interface/ten/ten_env.h"
#include "ten_runtime/common/errno.h"
#include "ten_runtime/common/status_code.h"
#include "ten_runtime/msg/cmd_result/cmd_result.h"
#include "ten_runtime/ten_env/internal/return.h"
#include "ten_runtime/ten_env_proxy/ten_env_proxy.h"
#include "ten_utils/lib/alloc.h"
#include "ten_utils/lib/error.h"
#include "ten_utils/log/log.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/value/value.h"

typedef struct ten_env_notify_return_result_info_t {
ten_shared_ptr_t *c_cmd;
Expand Down
22 changes: 12 additions & 10 deletions core/src/ten_runtime/ten_env/internal/return.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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_return_result_error_handler_func_t error_handler,
void *error_handler_data, ten_error_t *err) {
void *error_handler_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 @@ -53,10 +53,11 @@ static bool ten_env_return_result_internal(
if (result && error_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
// sending was successful.
error_handler(self, error_handler_data, NULL);
// returning was successful.
error_handler(self, error_handler_user_data, NULL);
}

if (err_new_created) {
Expand All @@ -71,7 +72,7 @@ static bool ten_env_return_result_internal(
bool ten_env_return_result_directly(
ten_env_t *self, ten_shared_ptr_t *result_cmd,
ten_env_return_result_error_handler_func_t error_handler,
void *error_handler_data, ten_error_t *err) {
void *error_handler_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 All @@ -81,13 +82,14 @@ bool ten_env_return_result_directly(
"The target cmd must be a cmd result.");

return ten_env_return_result_internal(self, result_cmd, NULL, NULL,
error_handler, error_handler_data, err);
error_handler, error_handler_user_data,
err);
}

bool ten_env_return_result(
ten_env_t *self, ten_shared_ptr_t *result_cmd, ten_shared_ptr_t *target_cmd,
ten_env_return_result_error_handler_func_t error_handler,
void *error_handler_data, ten_error_t *err) {
void *error_handler_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 All @@ -98,8 +100,8 @@ bool ten_env_return_result(
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_data, err);
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);
}

0 comments on commit be4c39b

Please sign in to comment.