Skip to content

Commit c30111f

Browse files
sunxilinhalajohn
andauthored
feat: add startGraphCmd in go binding (#789)
Co-authored-by: Hu Yueh-Wei <wei.hu.tw@gmail.com>
1 parent 0f8225d commit c30111f

File tree

28 files changed

+1125
-3
lines changed

28 files changed

+1125
-3
lines changed

core/include_internal/ten_runtime/binding/cpp/detail/addon_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
} \
4646
TEN_CONSTRUCTOR(____ten_addon_##NAME##_registrar____) { \
4747
/* Add addon registration function into addon manager. */ \
48+
TEN_LOGD("Registering addon: %s", #NAME); \
4849
ten_addon_manager_t *manager = ten_addon_manager_get_instance(); \
4950
bool success = ten_addon_manager_add_addon( \
5051
manager, "addon_loader", #NAME, \
5152
____ten_addon_##NAME##_register_handler__, NULL, NULL); \
53+
TEN_LOGD("Registered addon: %s", #NAME); \
5254
if (!success) { \
5355
TEN_LOGF("Failed to register addon: %s", #NAME); \
5456
/* NOLINTNEXTLINE(concurrency-mt-unsafe) */ \

core/src/ten_runtime/addon/addon_autoload.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ static bool load_all_dynamic_libraries_under_path(const char *path) {
120120
goto continue_loop;
121121
}
122122

123+
TEN_LOGD("Loading module: %s", ten_string_get_raw_str(file_path));
124+
123125
void *module_handle = ten_module_load(file_path, 1);
124126
if (!module_handle) {
125127
TEN_LOGE("Failed to load module: %s", ten_string_get_raw_str(file_path));

core/src/ten_runtime/binding/go/interface/ten_runtime/cmd.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ type Cmd interface {
2626
Clone() (Cmd, error)
2727
}
2828

29+
// StartGraphCmd is the interface for the start graph command.
30+
type StartGraphCmd interface {
31+
Cmd
32+
33+
SetPredefinedGraphName(predefinedGraphName string) error
34+
SetGraphFromJSONBytes(graphJSONBytes []byte) error
35+
SetLongRunningMode(longRunningMode bool) error
36+
}
37+
2938
// NewCmd creates a custom cmd which is intended to be sent to another
3039
// extension using tenEnv.SendCmd().
3140
func NewCmd(cmdName string) (Cmd, error) {
@@ -106,6 +115,24 @@ func NewCmd(cmdName string) (Cmd, error) {
106115
return newCmd(bridge), nil
107116
}
108117

118+
// NewStartGraphCmd creates a new start graph command.
119+
func NewStartGraphCmd() (StartGraphCmd, error) {
120+
var bridge C.uintptr_t
121+
err := withCGOLimiter(func() error {
122+
cStatus := C.ten_go_cmd_create_start_graph_cmd(
123+
&bridge,
124+
)
125+
e := withCGoError(&cStatus)
126+
127+
return e
128+
})
129+
if err != nil {
130+
return nil, err
131+
}
132+
133+
return newStartGraphCmd(bridge), nil
134+
}
135+
109136
type cmd struct {
110137
*msg
111138
}
@@ -116,6 +143,16 @@ func newCmd(bridge C.uintptr_t) *cmd {
116143
}
117144
}
118145

146+
type startGraphCmd struct {
147+
*cmd
148+
}
149+
150+
func newStartGraphCmd(bridge C.uintptr_t) *startGraphCmd {
151+
return &startGraphCmd{
152+
cmd: newCmd(bridge),
153+
}
154+
}
155+
119156
func (p *cmd) Clone() (Cmd, error) {
120157
var bridge C.uintptr_t
121158
err := withCGOLimiter(func() error {
@@ -141,4 +178,51 @@ func (p *cmd) Clone() (Cmd, error) {
141178
return newCmd(bridge), nil
142179
}
143180

181+
func (p *startGraphCmd) SetPredefinedGraphName(
182+
predefinedGraphName string,
183+
) error {
184+
defer p.keepAlive()
185+
186+
err := withCGOLimiter(func() error {
187+
apiStatus := C.ten_go_cmd_start_graph_set_predefined_graph_name(
188+
p.getCPtr(),
189+
unsafe.Pointer(unsafe.StringData(predefinedGraphName)),
190+
C.int(len(predefinedGraphName)),
191+
)
192+
return withCGoError(&apiStatus)
193+
})
194+
195+
return err
196+
}
197+
198+
func (p *startGraphCmd) SetGraphFromJSONBytes(graphJSONBytes []byte) error {
199+
defer p.keepAlive()
200+
201+
err := withCGOLimiter(func() error {
202+
apiStatus := C.ten_go_cmd_start_graph_set_graph_from_json_bytes(
203+
p.getCPtr(),
204+
unsafe.Pointer(unsafe.SliceData(graphJSONBytes)),
205+
C.int(len(graphJSONBytes)),
206+
)
207+
return withCGoError(&apiStatus)
208+
})
209+
210+
return err
211+
}
212+
213+
func (p *startGraphCmd) SetLongRunningMode(longRunningMode bool) error {
214+
defer p.keepAlive()
215+
216+
err := withCGOLimiter(func() error {
217+
apiStatus := C.ten_go_cmd_start_graph_set_long_running_mode(
218+
p.getCPtr(),
219+
C.bool(longRunningMode),
220+
)
221+
return withCGoError(&apiStatus)
222+
})
223+
224+
return err
225+
}
226+
144227
var _ Cmd = new(cmd)
228+
var _ StartGraphCmd = new(startGraphCmd)

core/src/ten_runtime/binding/go/interface/ten_runtime/cmd.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ ten_go_handle_t ten_go_cmd_result_get_detail(uintptr_t bridge_addr);
5454

5555
ten_go_error_t ten_go_cmd_result_get_detail_json_and_size(
5656
uintptr_t bridge_addr, uintptr_t *json_str_len, const char **json_str);
57+
58+
ten_go_error_t ten_go_cmd_create_start_graph_cmd(uintptr_t *bridge);
59+
60+
ten_go_error_t ten_go_cmd_start_graph_set_predefined_graph_name(
61+
uintptr_t bridge_addr, const void *predefined_graph_name,
62+
int predefined_graph_name_len);
63+
64+
ten_go_error_t ten_go_cmd_start_graph_set_graph_from_json_bytes(
65+
uintptr_t bridge_addr, const void *json_bytes, int json_bytes_len);
66+
67+
ten_go_error_t ten_go_cmd_start_graph_set_long_running_mode(
68+
uintptr_t bridge_addr, bool long_running_mode);

core/src/ten_runtime/binding/go/native/msg/cmd/cmd.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ten_runtime/binding/go/interface/ten_runtime/msg.h"
1515
#include "ten_runtime/common/status_code.h"
1616
#include "ten_runtime/msg/cmd/cmd.h"
17+
#include "ten_runtime/msg/cmd/start_graph/cmd.h"
1718
#include "ten_runtime/msg/cmd_result/cmd_result.h"
1819
#include "ten_utils/lib/error.h"
1920
#include "ten_utils/lib/smart_ptr.h"
@@ -218,3 +219,105 @@ ten_go_error_t ten_go_cmd_result_clone(uintptr_t bridge_addr,
218219

219220
return cgo_error;
220221
}
222+
223+
ten_go_error_t ten_go_cmd_create_start_graph_cmd(uintptr_t *bridge) {
224+
ten_go_error_t cgo_error;
225+
ten_go_error_init_with_error_code(&cgo_error, TEN_ERROR_CODE_OK);
226+
227+
ten_shared_ptr_t *c_cmd = ten_cmd_start_graph_create();
228+
TEN_ASSERT(c_cmd && ten_cmd_check_integrity(c_cmd), "Should not happen.");
229+
230+
ten_go_msg_t *msg_bridge = ten_go_msg_create(c_cmd);
231+
TEN_ASSERT(msg_bridge, "Should not happen.");
232+
233+
*bridge = (uintptr_t)msg_bridge;
234+
ten_shared_ptr_destroy(c_cmd);
235+
236+
return cgo_error;
237+
}
238+
239+
ten_go_error_t ten_go_cmd_start_graph_set_predefined_graph_name(
240+
uintptr_t bridge_addr, const void *predefined_graph_name,
241+
int predefined_graph_name_len) {
242+
ten_go_msg_t *msg_bridge = ten_go_msg_reinterpret(bridge_addr);
243+
TEN_ASSERT(msg_bridge && ten_go_msg_check_integrity(msg_bridge),
244+
"Should not happen.");
245+
246+
ten_go_error_t cgo_error;
247+
ten_go_error_init_with_error_code(&cgo_error, TEN_ERROR_CODE_OK);
248+
249+
ten_string_t predefined_graph_name_str;
250+
ten_string_init_from_c_str_with_size(&predefined_graph_name_str,
251+
predefined_graph_name,
252+
predefined_graph_name_len);
253+
254+
ten_error_t err;
255+
TEN_ERROR_INIT(err);
256+
257+
bool success = ten_cmd_start_graph_set_predefined_graph_name(
258+
ten_go_msg_c_msg(msg_bridge),
259+
ten_string_get_raw_str(&predefined_graph_name_str), &err);
260+
261+
if (!success) {
262+
ten_go_error_set(&cgo_error, ten_error_code(&err), ten_error_message(&err));
263+
}
264+
265+
ten_error_deinit(&err);
266+
ten_string_deinit(&predefined_graph_name_str);
267+
268+
return cgo_error;
269+
}
270+
271+
ten_go_error_t ten_go_cmd_start_graph_set_graph_from_json_bytes(
272+
uintptr_t bridge_addr, const void *json_bytes, int json_bytes_len) {
273+
ten_go_msg_t *msg_bridge = ten_go_msg_reinterpret(bridge_addr);
274+
TEN_ASSERT(msg_bridge && ten_go_msg_check_integrity(msg_bridge),
275+
"Should not happen.");
276+
277+
ten_go_error_t cgo_error;
278+
ten_go_error_init_with_error_code(&cgo_error, TEN_ERROR_CODE_OK);
279+
280+
ten_string_t json_str_str;
281+
ten_string_init_from_c_str_with_size(&json_str_str, json_bytes,
282+
json_bytes_len);
283+
284+
ten_error_t err;
285+
TEN_ERROR_INIT(err);
286+
287+
bool success = ten_cmd_start_graph_set_graph_from_json_str(
288+
ten_go_msg_c_msg(msg_bridge), ten_string_get_raw_str(&json_str_str),
289+
&err);
290+
291+
if (!success) {
292+
ten_go_error_set(&cgo_error, ten_error_code(&err), ten_error_message(&err));
293+
}
294+
295+
ten_error_deinit(&err);
296+
ten_string_deinit(&json_str_str);
297+
298+
return cgo_error;
299+
}
300+
301+
ten_go_error_t ten_go_cmd_start_graph_set_long_running_mode(
302+
uintptr_t bridge_addr, bool long_running_mode) {
303+
ten_go_msg_t *msg_bridge = ten_go_msg_reinterpret(bridge_addr);
304+
TEN_ASSERT(msg_bridge && ten_go_msg_check_integrity(msg_bridge),
305+
"Should not happen.");
306+
307+
ten_go_error_t cgo_error;
308+
ten_go_error_init_with_error_code(&cgo_error, TEN_ERROR_CODE_OK);
309+
310+
ten_error_t err;
311+
TEN_ERROR_INIT(err);
312+
313+
bool success = ten_cmd_start_graph_set_long_running_mode(
314+
ten_go_msg_c_msg(msg_bridge), long_running_mode, &err);
315+
316+
if (!success) {
317+
ten_go_error_set(&cgo_error, ten_error_code(&err), ten_error_message(&err));
318+
}
319+
320+
ten_error_deinit(&err);
321+
322+
return cgo_error;
323+
}

core/src/ten_runtime/binding/python/interface/ten_runtime/async_ten_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async def set_property_from_json(
166166
self, path: str, json_str: str
167167
) -> Optional[TenError]:
168168
q = asyncio.Queue(maxsize=1)
169-
err = self._internal.set_property_string_async(
169+
err = self._internal.set_property_from_json_async(
170170
path,
171171
json_str,
172172
lambda error: self._error_handler(error, q),

tests/ten_runtime/integration/go/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ group("go") {
3232
"send_data_go",
3333
"send_video_frame_go",
3434
"start_app_sync_go",
35+
"start_graph_go",
36+
"start_predefined_graph_go",
3537
"three_extension_cmd_go",
3638
"transfer_pointer_go",
3739
"two_extension_one_group_cmd_go",
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Copyright © 2025 Agora
3+
# This file is part of TEN Framework, an open source project.
4+
# Licensed under the Apache License, Version 2.0, with certain conditions.
5+
# Refer to the "LICENSE" file in the root directory for more information.
6+
#
7+
import("//build/ten_runtime/feature/test.gni")
8+
import("//build/ten_runtime/ten.gni")
9+
10+
ten_package_test_prepare_app("start_graph_go_app") {
11+
src_app = "default_app_go"
12+
src_app_language = "go"
13+
generated_app_src_root_dir_name = "start_graph_go_app"
14+
15+
replace_paths_after_install_app = [
16+
"start_graph_go_app/manifest.json",
17+
"start_graph_go_app/property.json",
18+
"start_graph_go_app/ten_packages/extension/default_extension_go/extension.go",
19+
"start_graph_go_app/ten_packages/extension/default_extension_go/go.mod",
20+
"start_graph_go_app/ten_packages/extension/default_extension_go/manifest.json",
21+
"start_graph_go_app/ten_packages/extension/default_extension_go/property.json",
22+
]
23+
24+
if (ten_enable_go_app_leak_check) {
25+
replace_paths_after_install_app += [ "start_graph_go_app/main.go" ]
26+
}
27+
28+
deps = [
29+
"//core/src/ten_manager",
30+
"//packages/core_apps/default_app_go:upload_default_app_go_to_server",
31+
"//packages/core_extensions/default_extension_go:upload_default_extension_go_to_server",
32+
"//packages/example_extensions/simple_http_server_cpp:upload_simple_http_server_cpp_to_server",
33+
]
34+
}
35+
36+
ten_package_test_prepare_auxiliary_resources("start_graph_go_app_test_files") {
37+
resources = [
38+
"__init__.py",
39+
"test_case.py",
40+
]
41+
42+
utils_files = exec_script("//.gnfiles/build/scripts/glob_file.py",
43+
[
44+
"--dir",
45+
rebase_path("//tests/utils/**/*"),
46+
"--dir-base",
47+
rebase_path("//tests/utils"),
48+
"--recursive",
49+
"--only-output-file",
50+
],
51+
"json")
52+
53+
foreach(utils_file, utils_files) {
54+
utils_file_rel_path = utils_file.relative_path
55+
resources +=
56+
[ "//tests/utils/${utils_file_rel_path}=>utils/${utils_file_rel_path}" ]
57+
}
58+
}
59+
60+
group("start_graph_go") {
61+
deps = [
62+
":start_graph_go_app",
63+
":start_graph_go_app_test_files",
64+
]
65+
}

tests/ten_runtime/integration/go/start_graph_go/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)