Skip to content

Commit 61afd60

Browse files
committed
fix: refine codes
1 parent 161505a commit 61afd60

File tree

294 files changed

+417
-569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+417
-569
lines changed

core/include/ten_runtime/binding/cpp/detail/msg/msg.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class msg_t {
5656
return ten_msg_get_name(c_msg);
5757
}
5858

59-
bool set_dest(const char *uri, const char *graph,
60-
const char *extension_group_name, const char *extension_name,
59+
bool set_dest(const char *uri, const char *graph, const char *extension_name,
6160
error_t *err = nullptr) const {
6261
TEN_ASSERT(c_msg, "Should not happen.");
6362

core/src/ten_manager/tests/test_case/fs/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,39 @@ mod tests {
2727
temp_file.write_all(test_content)?;
2828
temp_file.flush()?;
2929

30-
// Create options with shorter timeout for testing
30+
// Create options with shorter timeout for testing.
3131
let options = FileWatchOptions {
3232
timeout: Duration::from_secs(5),
3333
buffer_size: 1024,
3434
check_interval: Duration::from_millis(100),
3535
};
3636

37-
// Start watching the file
37+
// Start watching the file.
3838
let mut stream =
3939
watch_file(temp_file.path(), Some(options)).await?;
4040

41-
// Get the first chunk
41+
// Get the first chunk.
4242
let chunk = stream.next().await.expect("Should receive data")?;
4343
assert_eq!(chunk, test_content);
4444

45-
// Write more content to the file
45+
// Write more content to the file.
4646
let more_content = b"More content!";
4747
temp_file.write_all(more_content)?;
4848
temp_file.flush()?;
4949

50-
// Get the second chunk
51-
let chunk =
52-
stream.next().await.expect("Should receive more data")?;
53-
assert_eq!(chunk, more_content);
50+
// Get the second chunk.
51+
let chunk = stream.next().await;
52+
match chunk {
53+
Some(chunk) => match chunk {
54+
Ok(chunk) => assert_eq!(chunk, more_content),
55+
Err(e) => panic!("Should receive more data: {}", e),
56+
},
57+
None => {
58+
panic!("Should receive more data");
59+
}
60+
}
5461

55-
// Stop watching
62+
// Stop watching.
5663
stream.stop();
5764

5865
Ok(())

packages/example_extensions/aio_http_server_python/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def default_handler(self, request: web_request.Request):
3737
# If the command is a 'close_app' command, send it to the app.
3838
if "type" in data["ten"] and data["ten"]["type"] == "close_app":
3939
close_app_cmd = Cmd.create("ten:close_app")
40-
close_app_cmd.set_dest("localhost", None, None, None)
40+
close_app_cmd.set_dest("localhost", None, None)
4141
asyncio.create_task(self.ten_env.send_cmd(close_app_cmd))
4242
return web.Response(status=200, text="OK")
4343
elif "name" in data["ten"]:

packages/example_extensions/ffmpeg_client/src/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ffmpeg_client_extension : public ten::extension_t {
7878

7979
static void close_app(ten::ten_env_t &ten_env) {
8080
auto close_cmd = ten::cmd_close_app_t::create();
81-
close_cmd->set_dest("localhost", "", "", "");
81+
close_cmd->set_dest("localhost", "", "");
8282
ten_env.send_cmd(std::move(close_cmd));
8383
}
8484

packages/example_extensions/simple_http_server_cpp/src/main.cc

Lines changed: 82 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -581,96 +581,97 @@ class http_server_extension_t : public ten::extension_t {
581581
void send_ten_msg_with_req_body(
582582
const std::shared_ptr<http_transaction_data_t> &http_session_data) {
583583
// We are _not_ in the TEN threads, so we need to use ten_env_proxy.
584-
http_session_data->http_server->ten_env_proxy->notify([http_session_data](
585-
ten::ten_env_t
586-
&ten_env) {
587-
// Create a TEN command from the request.
588-
589-
// Parse the received request data and create a command from it
590-
// according to the request content.
591-
auto cmd_json = nlohmann::json::parse(
592-
std::string(reinterpret_cast<char *>(http_session_data->req_buf->data),
593-
ten_buf_get_content_size(http_session_data->req_buf))
594-
.c_str());
595-
596-
std::string method = get_http_method_string(http_session_data->method);
597-
598-
std::unique_ptr<ten::cmd_t> cmd = nullptr;
584+
http_session_data->http_server->ten_env_proxy->notify(
585+
[http_session_data](ten::ten_env_t &ten_env) {
586+
// Create a TEN command from the request.
599587

600-
if (cmd_json.contains("ten")) {
601-
if (cmd_json["ten"].contains("type")) {
602-
// Should be a TEN internal command.
588+
// Parse the received request data and create a command from it
589+
// according to the request content.
590+
auto cmd_json = nlohmann::json::parse(
591+
std::string(
592+
reinterpret_cast<char *>(http_session_data->req_buf->data),
593+
ten_buf_get_content_size(http_session_data->req_buf))
594+
.c_str());
603595

604-
if (cmd_json["ten"]["type"] == "close_app") {
605-
cmd = ten::cmd_close_app_t::create();
596+
std::string method = get_http_method_string(http_session_data->method);
606597

607-
// Set the destination of the command to the localhost.
608-
cmd->set_dest("localhost", nullptr, nullptr, nullptr);
609-
} else {
610-
assert(0 && "Handle more internal command types.");
611-
}
612-
} else if (cmd_json["ten"].contains("name")) {
613-
// Should be a custom command.
614-
615-
cmd = ten::cmd_t::create(
616-
cmd_json["ten"]["name"].get<std::string>().c_str());
617-
618-
// If the cmd_json contains "dest", it means the command should be sent
619-
// to a specific extension.
620-
if (cmd_json["ten"].contains("dest")) {
621-
auto dest = cmd_json["ten"]["dest"];
622-
623-
try {
624-
cmd->set_dest(dest["app"].get<std::string>().c_str(),
625-
dest["graph"].get<std::string>().c_str(),
626-
dest["extension_group"].get<std::string>().c_str(),
627-
dest["extension"].get<std::string>().c_str());
628-
} catch (const std::exception &e) {
629-
TEN_LOGW("Failed to set the destination of the command: %s",
630-
e.what());
598+
std::unique_ptr<ten::cmd_t> cmd = nullptr;
599+
600+
if (cmd_json.contains("ten")) {
601+
if (cmd_json["ten"].contains("type")) {
602+
// Should be a TEN internal command.
603+
604+
if (cmd_json["ten"]["type"] == "close_app") {
605+
cmd = ten::cmd_close_app_t::create();
606+
607+
// Set the destination of the command to the localhost.
608+
cmd->set_dest("localhost", nullptr, nullptr);
609+
} else {
610+
assert(0 && "Handle more internal command types.");
611+
}
612+
} else if (cmd_json["ten"].contains("name")) {
613+
// Should be a custom command.
614+
615+
cmd = ten::cmd_t::create(
616+
cmd_json["ten"]["name"].get<std::string>().c_str());
617+
618+
// If the cmd_json contains "dest", it means the command should be
619+
// sent to a specific extension.
620+
if (cmd_json["ten"].contains("dest")) {
621+
auto dest = cmd_json["ten"]["dest"];
622+
623+
try {
624+
cmd->set_dest(dest["app"].get<std::string>().c_str(),
625+
dest["graph"].get<std::string>().c_str(),
626+
dest["extension"].get<std::string>().c_str());
627+
} catch (const std::exception &e) {
628+
TEN_LOGW("Failed to set the destination of the command: %s",
629+
e.what());
630+
}
631+
}
631632
}
632633
}
633-
}
634-
}
635634

636-
if (cmd == nullptr) {
637-
// Use the method as the command name by default.
638-
cmd = ten::cmd_t::create(method.c_str());
639-
}
635+
if (cmd == nullptr) {
636+
// Use the method as the command name by default.
637+
cmd = ten::cmd_t::create(method.c_str());
638+
}
640639

641-
cmd_json["method"] =
642-
get_http_method_string(http_session_data->method).c_str();
643-
cmd_json["url"] = http_session_data->url.c_str();
644-
645-
// Parse the full content of the request and set it to the
646-
// command.
647-
cmd->set_property_from_json(nullptr, cmd_json.dump().c_str());
648-
649-
// Send out the command to the TEN runtime.
650-
ten_env.send_cmd(
651-
std::move(cmd),
652-
[http_session_data](ten::ten_env_t &ten_env,
653-
std::unique_ptr<ten::cmd_result_t> cmd_result,
654-
ten::error_t *err) {
655-
if (err != nullptr) {
656-
prepare_response_data_from_ten_world(
657-
http_session_data, "The command is not supported. err:" +
658-
std::string(err->error_message()));
659-
return;
660-
}
640+
cmd_json["method"] =
641+
get_http_method_string(http_session_data->method).c_str();
642+
cmd_json["url"] = http_session_data->url.c_str();
661643

662-
auto *ext = static_cast<http_server_extension_t *>(
663-
ten::ten_env_internal_accessor_t::get_attached_target(ten_env));
664-
assert(ext && "Failed to get the attached extension.");
644+
// Parse the full content of the request and set it to the
645+
// command.
646+
cmd->set_property_from_json(nullptr, cmd_json.dump().c_str());
665647

666-
if (!ext->is_stopping) {
667-
// When stopping, do not push more data into libws thread.
668-
// Libws world would clean up itself.
669-
prepare_response_data_from_ten_world(
670-
http_session_data, cmd_result->get_property_to_json("detail"));
671-
}
672-
});
673-
});
648+
// Send out the command to the TEN runtime.
649+
ten_env.send_cmd(
650+
std::move(cmd),
651+
[http_session_data](ten::ten_env_t &ten_env,
652+
std::unique_ptr<ten::cmd_result_t> cmd_result,
653+
ten::error_t *err) {
654+
if (err != nullptr) {
655+
prepare_response_data_from_ten_world(
656+
http_session_data, "The command is not supported. err:" +
657+
std::string(err->error_message()));
658+
return;
659+
}
660+
661+
auto *ext = static_cast<http_server_extension_t *>(
662+
ten::ten_env_internal_accessor_t::get_attached_target(
663+
ten_env));
664+
assert(ext && "Failed to get the attached extension.");
665+
666+
if (!ext->is_stopping) {
667+
// When stopping, do not push more data into libws thread.
668+
// Libws world would clean up itself.
669+
prepare_response_data_from_ten_world(
670+
http_session_data,
671+
cmd_result->get_property_to_json("detail"));
672+
}
673+
});
674+
});
674675
}
675676

676677
void send_ten_msg_without_req_body(

tests/ten_runtime/integration/cpp/check_start_graph/check_start_graph_app/ten_packages/extension/default_extension_cpp/src/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class test_extension : public ten::extension_t {
3030
ten::error_t err;
3131

3232
auto start_graph_cmd = ten::cmd_start_graph_t::create();
33-
start_graph_cmd->set_dest("localhost", nullptr, nullptr, nullptr);
33+
start_graph_cmd->set_dest("localhost", nullptr, nullptr);
3434
bool result = start_graph_cmd->set_graph_from_json(R"({
3535
"nodes": [
3636
{
@@ -75,7 +75,7 @@ class test_extension : public ten::extension_t {
7575
send_invalid_graph(ten_env);
7676

7777
auto start_graph_cmd = ten::cmd_start_graph_t::create();
78-
start_graph_cmd->set_dest("localhost", nullptr, nullptr, nullptr);
78+
start_graph_cmd->set_dest("localhost", nullptr, nullptr);
7979
start_graph_cmd->set_graph_from_json(R"({
8080
"nodes": [
8181
{
@@ -94,7 +94,7 @@ class test_extension : public ten::extension_t {
9494
// The graph check should be passed.
9595
if (cmd_result->get_status_code() == TEN_STATUS_CODE_OK) {
9696
auto close_app = ten::cmd_close_app_t::create();
97-
close_app->set_dest("localhost", nullptr, nullptr, nullptr);
97+
close_app->set_dest("localhost", nullptr, nullptr);
9898
env.send_cmd(std::move(close_app));
9999
} else {
100100
std::cout << "Failed to start graph: "

tests/ten_runtime/integration/cpp/ffmpeg_bypass/ffmpeg_bypass_app/ten_packages/extension/ffmpeg_client/src/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ffmpeg_client_extension : public ten::extension_t {
9494

9595
static void close_app(ten::ten_env_t &ten_env) {
9696
auto close_cmd = ten::cmd_close_app_t::create();
97-
close_cmd->set_dest("localhost", "", "", "");
97+
close_cmd->set_dest("localhost", "", "");
9898
ten_env.send_cmd(std::move(close_cmd));
9999
}
100100

tests/ten_runtime/integration/cpp/graph_env_var_1/client/client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main(int argc, char **argv) {
3434
// Send a user-defined 'hello world' command.
3535
auto hello_world_cmd = ten::cmd_t::create("hello_world");
3636
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr,
37-
"test_extension_group", "test_extension");
37+
"test_extension");
3838
cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd));
3939
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
4040
"Should not happen.");

tests/ten_runtime/integration/cpp/graph_env_var_2/client/client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main(int argc, char **argv) {
3434
// Send a user-defined 'hello world' command.
3535
auto hello_world_cmd = ten::cmd_t::create("hello_world");
3636
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr,
37-
"test_extension_group", "test_extension");
37+
"test_extension");
3838
cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd));
3939
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
4040
"Should not happen.");

tests/ten_runtime/integration/cpp/graph_env_var_3/client/client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main(int argc, char **argv) {
3434
// Send a user-defined 'hello world' command.
3535
auto hello_world_cmd = ten::cmd_t::create("hello_world");
3636
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr,
37-
"test_extension_group", "test_extension");
37+
"test_extension");
3838
cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd));
3939
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
4040
"Should not happen.");

tests/ten_runtime/integration/cpp/hello_world/client/client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main(int argc, char **argv) {
3131
// Send a user-defined 'hello world' command.
3232
auto hello_world_cmd = ten::cmd_t::create("hello_world");
3333
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr,
34-
"test_extension_group", "test_extension");
34+
"test_extension");
3535
cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd));
3636
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
3737
"Should not happen.");

tests/ten_runtime/integration/cpp/long_running/long_running_app/ten_packages/extension/extension_1/src/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class test_extension : public ten::extension_t {
3636
ten_env.send_cmd(std::move(test_cmd));
3737
} else {
3838
auto close_app = ten::cmd_close_app_t::create();
39-
close_app->set_dest("localhost", nullptr, nullptr, nullptr);
39+
close_app->set_dest("localhost", nullptr, nullptr);
4040
ten_env.send_cmd(std::move(close_app));
4141
}
4242
}

tests/ten_runtime/integration/cpp/multi_apps/client/client.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ int main(int argc, char **argv) {
111111

112112
// Send a user-defined 'hello world' command.
113113
auto hello_world_cmd = ten::cmd_t::create("hello_world");
114-
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr,
115-
"test_extension_group", "ext_a");
114+
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr, "ext_a");
116115
cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd));
117116
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
118117
"Should not happen.");

tests/ten_runtime/integration/go/access_property_go/client/client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) {
1414
auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/");
1515

1616
auto test_cmd = ten::cmd_t::create("test");
17-
test_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", "nodetest", "A");
17+
test_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", "A");
1818
auto cmd_result = client->send_cmd_and_recv_result(std::move(test_cmd));
1919
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
2020
"Should not happen.");

tests/ten_runtime/integration/go/close_app_go/client/client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) {
1515

1616
auto hello_cmd = ten::cmd_t::create("hello");
1717
hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default",
18-
"default_extension_group", "default_extension_go");
18+
"default_extension_go");
1919
auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd));
2020
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
2121
"Should not happen.");

tests/ten_runtime/integration/go/expired_ten_go/client/client.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) {
1515
auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/");
1616

1717
auto hello_cmd = ten::cmd_t::create("hello");
18-
hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default",
19-
"default_extension_group", "extension_a");
18+
hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", "extension_a");
2019
auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd));
2120
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
2221
"Should not happen.");

tests/ten_runtime/integration/go/frequently_cgo_call_go/client/client.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) {
1515
auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/");
1616

1717
auto hello_cmd = ten::cmd_t::create("hello");
18-
hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default",
19-
"default_extension_group", "extension_a");
18+
hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", "extension_a");
2019
auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd));
2120
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
2221
"Should not happen.");

tests/ten_runtime/integration/go/handle_error_go/client/client.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) {
1414
auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8007/");
1515

1616
auto hello_cmd = ten::cmd_t::create("hello");
17-
hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default",
18-
"default_extension_group", "extension_a");
17+
hello_cmd->set_dest("msgpack://127.0.0.1:8007/", "default", "extension_a");
1918
auto cmd_result = client->send_cmd_and_recv_result(std::move(hello_cmd));
2019
TEN_ASSERT(TEN_STATUS_CODE_ERROR == cmd_result->get_status_code(),
2120
"Should not happen.");

0 commit comments

Comments
 (0)