Skip to content

Commit

Permalink
feat!: remove send_json (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Nov 21, 2024
1 parent d450749 commit d898d62
Show file tree
Hide file tree
Showing 85 changed files with 506 additions and 2,416 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@
"name": "app (C/C++) (lldb, launch)",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/cpp/hello_world/hello_world_app/bin/hello_world_app_source",
"program": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/cpp/check_start_graph/check_start_graph_app/bin/check_start_graph_source",
"args": [],
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/cpp/hello_world/hello_world_app",
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/cpp/check_start_graph/check_start_graph_app",
"env": {
"ASAN_OPTIONS": "use_sigaltstack=0",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ class cmd_start_graph_t : public cmd_t {
: cmd_t(ten_cmd_start_graph_create()) {};
~cmd_start_graph_t() override = default;

bool set_predefined_graph_name(const char *predefined_graph_name,
error_t *err = nullptr) {
return ten_cmd_start_graph_set_predefined_graph_name(
c_msg, predefined_graph_name,
err != nullptr ? err->get_internal_representation() : nullptr);
}

bool set_nodes_and_connections_from_json(const char *json_str,
error_t *err = nullptr) {
return ten_cmd_start_graph_init_from_json_str(
c_msg, json_str,
err != nullptr ? err->get_internal_representation() : nullptr);
}

// @{
cmd_start_graph_t(cmd_start_graph_t &other) = delete;
cmd_start_graph_t(cmd_start_graph_t &&other) = delete;
Expand Down
75 changes: 5 additions & 70 deletions core/include/ten_runtime/binding/cpp/internal/ten_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,83 +69,18 @@ class ten_env_t {
ten_env_t &operator=(const ten_env_t &&) = delete;
// @}

bool send_cmd_ex(std::unique_ptr<cmd_t> &&cmd,
result_handler_func_t &&result_handler = nullptr,
error_t *err = nullptr) {
return send_cmd_internal(std::move(cmd), std::move(result_handler), true,
err);
}

bool send_cmd(std::unique_ptr<cmd_t> &&cmd,
result_handler_func_t &&result_handler = nullptr,
error_t *err = nullptr) {
return send_cmd_internal(std::move(cmd), std::move(result_handler), false,
err);
}

bool send_json_ex(const char *json_str,
result_handler_func_t &&result_handler = nullptr,
error_t *err = nullptr) {
TEN_ASSERT(c_ten_env, "Should not happen.");

if (json_str == nullptr) {
TEN_ASSERT(0, "Invalid argument.");
return false;
}

ten_json_t *c_json = ten_json_from_string(
json_str,
err != nullptr ? err->get_internal_representation() : nullptr);
if (c_json == nullptr) {
return false;
}

bool rc = false;

if (result_handler == nullptr) {
rc = ten_env_send_json(
c_ten_env, c_json, nullptr, nullptr,
err != nullptr ? err->get_internal_representation() : nullptr);
} else {
auto *result_handler_ptr =
new result_handler_func_t(std::move(result_handler));

rc = ten_env_send_json(
c_ten_env, c_json, proxy_handle_result, result_handler_ptr,
err != nullptr ? err->get_internal_representation() : nullptr);

if (!rc) {
delete result_handler_ptr;
}
}

ten_json_destroy(c_json);

if (!rc) {
TEN_LOGE("Failed to send_json: %s", json_str);
}

return rc;
}

bool send_json(const char *json_str,
result_handler_func_t &&result_handler = nullptr,
error_t *err = nullptr) {
TEN_ASSERT(c_ten_env, "Should not happen.");

if (result_handler) {
return send_json_ex(
json_str,
[result_handler](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result) {
if (cmd_result->is_completed()) {
result_handler(ten_env, std::move(cmd_result));
}
},
err);
} else {
return send_json_ex(json_str, nullptr, err);
}
bool send_cmd_ex(std::unique_ptr<cmd_t> &&cmd,
result_handler_func_t &&result_handler = nullptr,
error_t *err = nullptr) {
return send_cmd_internal(std::move(cmd), std::move(result_handler), true,
err);
}

bool send_data(std::unique_ptr<data_t> &&data, error_t *err = nullptr) {
Expand Down
8 changes: 8 additions & 0 deletions core/include/ten_runtime/msg/cmd/start_graph/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@

#include "ten_runtime/ten_config.h"

#include "ten_utils/lib/error.h"
#include "ten_utils/lib/smart_ptr.h"

typedef struct ten_msg_t ten_msg_t;
typedef struct ten_cmd_start_graph_t ten_cmd_start_graph_t;

TEN_RUNTIME_API ten_shared_ptr_t *ten_cmd_start_graph_create(void);

TEN_RUNTIME_API bool ten_cmd_start_graph_set_predefined_graph_name(
ten_shared_ptr_t *self, const char *predefined_graph_name,
ten_error_t *err);

TEN_RUNTIME_API bool ten_cmd_start_graph_init_from_json_str(
ten_shared_ptr_t *self, const char *json_str, ten_error_t *err);
5 changes: 0 additions & 5 deletions core/include/ten_runtime/ten_env/internal/send.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ TEN_RUNTIME_API bool ten_env_send_cmd_ex(
ten_env_cmd_result_handler_func_t result_handler,
void *result_handler_user_data, ten_error_t *err);

TEN_RUNTIME_API bool ten_env_send_json(
ten_env_t *self, ten_json_t *json,
ten_env_cmd_result_handler_func_t result_handler,
void *result_handler_user_data, ten_error_t *err);

TEN_RUNTIME_API bool ten_env_send_data(ten_env_t *self, ten_shared_ptr_t *data,
ten_error_t *err);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ class cmd_timer_t : public cmd_t {
: cmd_t(ten_cmd_timer_create()) {}
~cmd_timer_t() override = default;

bool set_timer_id(uint32_t timer_id) {
return ten_cmd_timer_set_timer_id(c_msg, timer_id);
}

bool set_times(int32_t times) {
return ten_cmd_timer_set_times(c_msg, times);
}

bool set_timeout_in_us(int64_t timeout_in_us) {
return ten_cmd_timer_set_timeout_in_us(c_msg, timeout_in_us);
}

// @{
cmd_timer_t(cmd_timer_t &other) = delete;
cmd_timer_t(cmd_timer_t &&other) = delete;
Expand Down
3 changes: 3 additions & 0 deletions core/include_internal/ten_runtime/binding/python/msg/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ TEN_RUNTIME_PRIVATE_API PyObject *ten_py_msg_get_name(PyObject *self,
TEN_RUNTIME_PRIVATE_API PyObject *ten_py_msg_set_name(PyObject *self,
PyObject *args);

TEN_RUNTIME_PRIVATE_API PyObject *ten_py_msg_set_dest(PyObject *self,
PyObject *args);

TEN_RUNTIME_PRIVATE_API PyObject *ten_py_msg_set_property_string(
PyObject *self, PyObject *args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct ten_py_ten_env_t {

// Mark whether the gil state need to be released after 'on_deinit_done'.
bool need_to_release_gil_state;
PyThreadState* py_thread_state;
PyThreadState *py_thread_state;
} ten_py_ten_env_t;

TEN_RUNTIME_PRIVATE_API bool ten_py_ten_env_check_integrity(
Expand Down Expand Up @@ -60,9 +60,6 @@ TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_on_deinit_done(PyObject *self,
TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_on_create_instance_done(
PyObject *self, PyObject *args);

TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_send_json(PyObject *self,
PyObject *args);

TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_send_cmd(PyObject *self,
PyObject *args);

Expand All @@ -75,9 +72,6 @@ TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_send_video_frame(
TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_send_audio_frame(
PyObject *self, PyObject *args);

TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_return_json(PyObject *self,
PyObject *args);

TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_return_result(PyObject *self,
PyObject *args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_start_graph_get_long_running_mode(
TEN_RUNTIME_PRIVATE_API bool ten_cmd_start_graph_get_long_running_mode(
ten_shared_ptr_t *self);

TEN_RUNTIME_PRIVATE_API void ten_cmd_start_graph_set_predefined_graph_name(
ten_shared_ptr_t *self, const char *predefined_graph_name);

TEN_RUNTIME_PRIVATE_API ten_string_t *
ten_raw_cmd_start_graph_get_predefined_graph_name(ten_cmd_start_graph_t *self);

Expand Down
17 changes: 10 additions & 7 deletions core/include_internal/ten_runtime/msg/cmd_base/cmd/timer/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,37 @@ TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timer_check_type_and_name(
ten_msg_t *self, const char *type_str, const char *name_str,
ten_error_t *err);

TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_timer_set_timer_id(
TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timer_set_timer_id(
ten_cmd_timer_t *self, uint32_t timer_id);

TEN_RUNTIME_PRIVATE_API void ten_raw_cmd_timer_set_times(ten_cmd_timer_t *self,
int32_t times);
TEN_RUNTIME_API bool ten_raw_cmd_timer_set_times(ten_cmd_timer_t *self,
int32_t times);

TEN_RUNTIME_PRIVATE_API uint32_t
ten_raw_cmd_timer_get_timer_id(ten_cmd_timer_t *self);

TEN_RUNTIME_PRIVATE_API uint32_t
ten_cmd_timer_get_timer_id(ten_shared_ptr_t *self);

TEN_RUNTIME_PRIVATE_API void ten_cmd_timer_set_timer_id(ten_shared_ptr_t *self,
uint32_t timer_id);
TEN_RUNTIME_API bool ten_cmd_timer_set_timer_id(ten_shared_ptr_t *self,
uint32_t timer_id);

TEN_RUNTIME_PRIVATE_API uint64_t
ten_raw_cmd_timer_get_timeout_in_us(ten_cmd_timer_t *self);

TEN_RUNTIME_PRIVATE_API uint64_t
ten_cmd_timer_get_timeout_in_us(ten_shared_ptr_t *self);

TEN_RUNTIME_API bool ten_cmd_timer_set_timeout_in_us(ten_shared_ptr_t *self,
uint64_t timeout_in_us);

TEN_RUNTIME_PRIVATE_API int32_t
ten_raw_cmd_timer_get_times(ten_cmd_timer_t *self);

TEN_RUNTIME_PRIVATE_API int32_t ten_cmd_timer_get_times(ten_shared_ptr_t *self);

TEN_RUNTIME_PRIVATE_API void ten_cmd_timer_set_times(ten_shared_ptr_t *self,
int32_t times);
TEN_RUNTIME_API bool ten_cmd_timer_set_times(ten_shared_ptr_t *self,
int32_t times);

TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_timer_as_msg_init_from_json(
ten_msg_t *self, ten_json_t *json, ten_error_t *err);
Expand Down
14 changes: 0 additions & 14 deletions core/src/ten_runtime/app/msg_interface/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,20 +374,6 @@ static void ten_app_handle_in_msgs_sync(ten_app_t *self) {
// NULL. Ex: send the following cmd from extension in engine whose
// 'graph_id' is A.
//
// ten_env.send_json(
// {
// "_ten": {
// "name": "demo",
// "dest": [
// {
// "app": "localhost",
// "graph": "graph_id_of_another_engine"
// }
// ]
// }
// }
// )
//
// * If the 'cmd' is sent to another engine (whose 'graph_id' is B) from
// the client side, after the physical connection between the client and
// current engine (whose 'graph_id' is A) has been established, the
Expand Down
63 changes: 0 additions & 63 deletions core/src/ten_runtime/binding/go/interface/ten/ten_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ type TenEnv interface {
postSyncJob(payload job) any
postAsyncJob(payload job) any

SendJSON(json string, handler ResultHandler) error
SendJSONBytes(json []byte, handler ResultHandler) error
SendCmd(cmd Cmd, handler ResultHandler) error
SendData(data Data) error
SendVideoFrame(videoFrame VideoFrame) error
Expand Down Expand Up @@ -137,67 +135,6 @@ func (p *tenEnv) postAsyncJob(payload job) any {
return p.process(payload)
}

func (p *tenEnv) sendJSON(
bytes unsafe.Pointer,
size int,
handler ResultHandler,
) error {
cb := goHandleNil
if handler != nil {
cb = newGoHandle(handler)
}

apiStatus := C.ten_go_ten_env_send_json(
p.cPtr,
bytes,
C.int(size),
cHandle(cb),
)
err := withGoStatus(&apiStatus)

return err
}

// SendJSON sends a json string to TEN runtime, and the handler function will be
// called when the result (i.e., CmdResult) is received. The result will be
// discarded if the handler is nil.
func (p *tenEnv) SendJSON(json string, handler ResultHandler) error {
if len(json) == 0 {
return newTenError(
ErrnoInvalidArgument,
"json data is required.",
)
}

return withCGO(func() error {
return p.sendJSON(
unsafe.Pointer(unsafe.StringData(json)),
len(json),
handler,
)
})
}

// SendJSONBytes sends a json bytes to TEN runtime, and the handler function
// will be called when the result (i.e., CmdResult) is received. The result
// will be discarded if the handler is nil.
func (p *tenEnv) SendJSONBytes(json []byte, handler ResultHandler) error {
if len(json) == 0 {
return newTenError(
ErrnoInvalidArgument,
"json data is required.",
)
}

return withCGO(func() error {
return p.sendJSON(
unsafe.Pointer(unsafe.SliceData(json)),
len(json),
handler,
)
})
}

func (p *tenEnv) SendCmd(cmd Cmd, handler ResultHandler) error {
if cmd == nil {
return newTenError(
Expand Down
Loading

0 comments on commit d898d62

Please sign in to comment.