Skip to content

Commit 161505a

Browse files
committed
refactor: remove extension group name from message handling functions and update related tests
1 parent 918dc52 commit 161505a

File tree

18 files changed

+156
-63
lines changed

18 files changed

+156
-63
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"request": "launch",
138138
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
139139
"args": [
140-
"--gtest_filter=ExtensionTest.CommandInvalidExtensionGroup"
140+
"--gtest_filter=BasicTest.ThrowExceptionInExtension"
141141
],
142142
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
143143
"env": {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class extension_t : public binding_handle_t {
133133
TEN_ASSERT(stop_graph_cmd, "Should not happen.");
134134

135135
ten_msg_clear_and_set_dest(stop_graph_cmd, "localhost", nullptr, nullptr,
136-
nullptr, nullptr);
136+
nullptr);
137137
ten_env_send_cmd(ten_env.get_c_ten_env(), stop_graph_cmd, nullptr, nullptr,
138138
nullptr, nullptr);
139139
ten_shared_ptr_destroy(stop_graph_cmd);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class msg_t {
7070
}
7171

7272
return ten_msg_clear_and_set_dest(
73-
c_msg, uri, graph, extension_group_name, extension_name,
73+
c_msg, uri, graph, extension_name,
7474
err != nullptr ? err->get_c_error() : nullptr);
7575
}
7676

core/include/ten_runtime/msg/msg.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ TEN_RUNTIME_API ten_value_t *ten_msg_peek_property(ten_shared_ptr_t *self,
7474
const char *path,
7575
ten_error_t *err);
7676

77-
TEN_RUNTIME_API bool ten_msg_clear_and_set_dest(
78-
ten_shared_ptr_t *self, const char *app_uri, const char *graph_id,
79-
const char *extension_group_name, const char *extension_name,
80-
ten_error_t *err);
77+
TEN_RUNTIME_API bool ten_msg_clear_and_set_dest(ten_shared_ptr_t *self,
78+
const char *app_uri,
79+
const char *graph_id,
80+
const char *extension_name,
81+
ten_error_t *err);
8182

8283
TEN_RUNTIME_API bool ten_msg_from_json(ten_shared_ptr_t *self, ten_json_t *json,
8384
ten_error_t *err);

core/include_internal/ten_runtime/msg/msg.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ TEN_RUNTIME_PRIVATE_API void ten_msg_set_src_to_extension_group(
9191
TEN_RUNTIME_PRIVATE_API void ten_msg_clear_and_set_dest_from_msg_src(
9292
ten_shared_ptr_t *self, ten_shared_ptr_t *cmd);
9393

94-
TEN_RUNTIME_PRIVATE_API void ten_raw_msg_add_dest(
95-
ten_msg_t *self, const char *app_uri, const char *graph_id,
96-
const char *extension_group_name, const char *extension_name);
94+
TEN_RUNTIME_PRIVATE_API void ten_raw_msg_add_dest(ten_msg_t *self,
95+
const char *app_uri,
96+
const char *graph_id,
97+
const char *extension_name);
9798

9899
TEN_RUNTIME_PRIVATE_API void ten_raw_msg_clear_dest(ten_msg_t *self);
99100

core/src/ten_runtime/addon/addon.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,24 @@ static void ten_app_create_addon_instance(ten_app_t *app,
373373
ten_string_get_raw_str(&addon_context->instance_name);
374374
TEN_ASSERT(instance_name, "Should not happen.");
375375

376-
if (ten_c_string_is_empty(addon_name) ||
377-
ten_c_string_is_empty(instance_name)) {
378-
TEN_LOGI(
379-
"The addon name or instance name is empty, will not create the addon "
380-
"instance.");
376+
if (addon_context->flow ==
377+
TEN_ADDON_CONTEXT_FLOW_ENGINE_CREATE_EXTENSION_GROUP) {
378+
if (ten_c_string_is_empty(addon_name)) {
379+
TEN_LOGI("The addon name is empty, will not create the extension group.");
381380

382-
ten_app_notify_create_addon_instance_failed(app, addon_context);
383-
return;
381+
ten_app_notify_create_addon_instance_failed(app, addon_context);
382+
return;
383+
}
384+
} else {
385+
if (ten_c_string_is_empty(addon_name) ||
386+
ten_c_string_is_empty(instance_name)) {
387+
TEN_LOGI(
388+
"The addon name or instance name is empty, will not create the addon "
389+
"instance.");
390+
391+
ten_app_notify_create_addon_instance_failed(app, addon_context);
392+
return;
393+
}
384394
}
385395

386396
TEN_LOGD("Try to find addon for %s", addon_name);

core/src/ten_runtime/app/predefined_graph.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ ten_app_build_start_graph_cmd_to_start_predefined_graph(
8282
ten_shared_ptr_t *start_graph_cmd = ten_cmd_start_graph_create();
8383
TEN_ASSERT(start_graph_cmd, "Should not happen.");
8484

85-
ten_msg_clear_and_set_dest(start_graph_cmd, app_uri, NULL, NULL, NULL, err);
85+
ten_msg_clear_and_set_dest(start_graph_cmd, app_uri, NULL, NULL, err);
8686

8787
void *json_ctx = ten_json_create_new_ctx();
8888
ten_json_t start_graph_cmd_json = TEN_JSON_INIT_VAL(json_ctx, true);
8989
ten_json_init_object(&start_graph_cmd_json);
9090

9191
ten_json_t ten_json = TEN_JSON_INIT_VAL(json_ctx, false);
92-
bool success = ten_json_object_peek_or_create_object(
93-
&start_graph_cmd_json, TEN_STR_TEN, &ten_json);
92+
bool success = ten_json_object_peek_or_create_object(&start_graph_cmd_json,
93+
TEN_STR_TEN, &ten_json);
9494
TEN_ASSERT(success, "Should not happen.");
9595

9696
ten_json_t nodes_json = TEN_JSON_INIT_VAL(json_ctx, false);
@@ -193,7 +193,7 @@ static void ten_app_start_auto_start_predefined_graph_result_handler(
193193

194194
ten_shared_ptr_t *close_app_cmd = ten_cmd_close_app_create();
195195
ten_msg_clear_and_set_dest(close_app_cmd, ten_string_get_raw_str(&app->uri),
196-
NULL, NULL, NULL, err);
196+
NULL, NULL, err);
197197
ten_env_send_cmd(ten_env, close_app_cmd, NULL, NULL, NULL, err);
198198
}
199199
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,6 @@ ten_go_error_t ten_go_msg_set_dest(uintptr_t bridge_addr, const void *app_uri,
846846
bool rc = ten_msg_clear_and_set_dest(
847847
ten_go_msg_c_msg(self), ten_string_get_raw_str(&app_uri_str),
848848
ten_string_get_raw_str(&graph_id_str),
849-
ten_string_get_raw_str(&extension_group_str),
850849
ten_string_get_raw_str(&extension_str), &err);
851850

852851
if (!rc) {

core/src/ten_runtime/binding/nodejs/native/msg/msg.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ static napi_value ten_nodejs_msg_set_dest(napi_env env,
126126

127127
bool rc = ten_msg_clear_and_set_dest(
128128
msg_bridge->msg, ten_string_get_raw_str(&app_uri),
129-
ten_string_get_raw_str(&graph_id),
130-
ten_string_get_raw_str(&extension_group),
131-
ten_string_get_raw_str(&extension), &err);
129+
ten_string_get_raw_str(&graph_id), ten_string_get_raw_str(&extension),
130+
&err);
132131
if (!rc) {
133132
ten_string_t code_str;
134133
ten_string_init_formatted(&code_str, "%d", ten_error_code(&err));

core/src/ten_runtime/binding/python/native/msg/msg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ PyObject *ten_py_msg_set_dest(PyObject *self, TEN_UNUSED PyObject *args) {
127127
ten_error_t err;
128128
TEN_ERROR_INIT(err);
129129

130-
bool rc = ten_msg_clear_and_set_dest(
131-
c_msg, app_uri, graph_id, extension_group_name, extension_name, &err);
130+
bool rc = ten_msg_clear_and_set_dest(c_msg, app_uri, graph_id, extension_name,
131+
&err);
132132

133133
if (!rc) {
134134
ten_py_raise_py_value_error_exception(ten_error_message(&err));

core/src/ten_runtime/common/loc.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ bool ten_loc_check_integrity(ten_loc_t *self) {
2525
return false;
2626
}
2727

28-
if (!ten_string_is_empty(&self->extension_name)) {
29-
if (ten_string_is_empty(&self->extension_group_name)) {
30-
return false;
31-
}
32-
}
33-
3428
return true;
3529
}
3630

core/src/ten_runtime/engine/internal/extension_interface.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ static void ten_engine_on_all_extension_threads_are_ready(
188188
// down directly.
189189
ten_shared_ptr_t *stop_graph_cmd = ten_cmd_stop_graph_create();
190190
ten_msg_clear_and_set_dest(stop_graph_cmd, ten_app_get_uri(app),
191-
ten_engine_get_id(self, false), NULL, NULL,
192-
NULL);
191+
ten_engine_get_id(self, false), NULL, NULL);
193192

194193
ten_env_send_cmd(self->ten_env, stop_graph_cmd, NULL, NULL, NULL, NULL);
195194

core/src/ten_runtime/engine/msg_interface/start_graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void ten_engine_handle_cmd_start_graph(ten_engine_t *self,
106106
// Correct the destination information of the 'start_graph' command.
107107
ten_msg_clear_and_set_dest(child_cmd, dest_uri_c_str,
108108
ten_string_get_raw_str(&self->graph_id),
109-
NULL, NULL, err);
109+
NULL, err);
110110

111111
ten_path_t *out_path = (ten_path_t *)ten_path_table_add_out_path(
112112
self->path_table, child_cmd);

core/src/ten_runtime/msg/msg.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,33 +107,28 @@ void ten_msg_set_src_to_loc(ten_shared_ptr_t *self, ten_loc_t *loc) {
107107
// information to one which is specified through the parameters.
108108
static bool ten_raw_msg_clear_and_set_dest(ten_msg_t *self, const char *uri,
109109
const char *graph_id,
110-
const char *extension_group_name,
111110
const char *extension_name,
112111
TEN_UNUSED ten_error_t *err) {
113112
TEN_ASSERT(self, "Should not happen.");
114113
TEN_ASSERT(ten_raw_msg_check_integrity(self), "Should not happen.");
115114
TEN_ASSERT((uri != NULL || extension_name != NULL), "Should not happen.");
116115

117116
ten_list_clear(&self->dest_loc);
118-
ten_list_push_ptr_back(
119-
&self->dest_loc,
120-
ten_loc_create(uri, graph_id, extension_group_name, extension_name),
121-
(ten_ptr_listnode_destroy_func_t)ten_loc_destroy);
117+
ten_list_push_ptr_back(&self->dest_loc,
118+
ten_loc_create(uri, graph_id, "", extension_name),
119+
(ten_ptr_listnode_destroy_func_t)ten_loc_destroy);
122120

123121
return true;
124122
}
125123

126124
void ten_raw_msg_add_dest(ten_msg_t *self, const char *uri,
127-
const char *graph_id,
128-
const char *extension_group_name,
129-
const char *extension_name) {
125+
const char *graph_id, const char *extension_name) {
130126
TEN_ASSERT(self, "Should not happen.");
131127
TEN_ASSERT(ten_raw_msg_check_integrity(self), "Should not happen.");
132128

133-
ten_list_push_ptr_back(
134-
&self->dest_loc,
135-
ten_loc_create(uri, graph_id, extension_group_name, extension_name),
136-
(ten_ptr_listnode_destroy_func_t)ten_loc_destroy);
129+
ten_list_push_ptr_back(&self->dest_loc,
130+
ten_loc_create(uri, graph_id, "", extension_name),
131+
(ten_ptr_listnode_destroy_func_t)ten_loc_destroy);
137132
}
138133

139134
void ten_raw_msg_clear_dest(ten_msg_t *self) {
@@ -153,7 +148,6 @@ static void ten_raw_msg_clear_and_set_dest_from_msg_src(ten_msg_t *self,
153148
ten_raw_msg_clear_and_set_dest(
154149
self, ten_string_get_raw_str(&raw_msg->src_loc.app_uri),
155150
ten_string_get_raw_str(&raw_msg->src_loc.graph_id),
156-
ten_string_get_raw_str(&raw_msg->src_loc.extension_group_name),
157151
ten_string_get_raw_str(&raw_msg->src_loc.extension_name), NULL);
158152
}
159153

@@ -363,14 +357,12 @@ void ten_msg_set_src_engine_if_unspecified(ten_shared_ptr_t *self,
363357

364358
bool ten_msg_clear_and_set_dest(ten_shared_ptr_t *self, const char *uri,
365359
const char *graph_id,
366-
const char *extension_group_name,
367360
const char *extension_name, ten_error_t *err) {
368361
TEN_ASSERT(self, "Should not happen.");
369362
TEN_ASSERT(ten_msg_check_integrity(self), "Should not happen.");
370363

371364
return ten_raw_msg_clear_and_set_dest(ten_msg_get_raw_msg(self), uri,
372-
graph_id, extension_group_name,
373-
extension_name, err);
365+
graph_id, extension_name, err);
374366
}
375367

376368
void ten_raw_msg_clear_and_set_dest_to_loc(ten_msg_t *self, ten_loc_t *loc) {
@@ -380,11 +372,10 @@ void ten_raw_msg_clear_and_set_dest_to_loc(ten_msg_t *self, ten_loc_t *loc) {
380372
if (!loc) {
381373
ten_raw_msg_clear_dest(self);
382374
} else {
383-
ten_raw_msg_clear_and_set_dest(
384-
self, ten_string_get_raw_str(&loc->app_uri),
385-
ten_string_get_raw_str(&loc->graph_id),
386-
ten_string_get_raw_str(&loc->extension_group_name),
387-
ten_string_get_raw_str(&loc->extension_name), NULL);
375+
ten_raw_msg_clear_and_set_dest(self, ten_string_get_raw_str(&loc->app_uri),
376+
ten_string_get_raw_str(&loc->graph_id),
377+
ten_string_get_raw_str(&loc->extension_name),
378+
NULL);
388379
}
389380
}
390381

core/src/ten_runtime/test/env_tester.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ static void test_app_ten_env_send_close_app_cmd(ten_env_t *ten_env,
841841
ten_msg_set_src_to_app(close_app_cmd, app);
842842

843843
bool rc = ten_msg_clear_and_set_dest(close_app_cmd, ten_app_get_uri(app),
844-
NULL, NULL, NULL, NULL);
844+
NULL, NULL, NULL);
845845
TEN_ASSERT(rc, "Should not happen.");
846846

847847
rc = ten_env_send_cmd(ten_env, close_app_cmd, NULL, NULL, NULL, NULL);

core/src/ten_runtime/test/extension_tester.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ static void test_app_ten_env_send_start_graph_cmd(ten_env_t *ten_env,
283283
// result handler specified below.
284284
ten_msg_set_src(cmd, ten_app_get_uri(app), NULL, NULL, NULL);
285285

286-
bool rc = ten_msg_clear_and_set_dest(cmd, ten_app_get_uri(app), NULL, NULL,
287-
NULL, NULL);
286+
bool rc =
287+
ten_msg_clear_and_set_dest(cmd, ten_app_get_uri(app), NULL, NULL, NULL);
288288
TEN_ASSERT(rc, "Should not happen.");
289289

290290
// Set up a result handler so that the returned `cmd_result` can be

tests/common/client/tcp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ bool ten_test_tcp_client_send_msg(ten_test_tcp_client_t *self,
191191

192192
if (ten_msg_get_dest_cnt(msg) == 0) {
193193
ten_msg_clear_and_set_dest(msg, ten_string_get_raw_str(&self->app_id), NULL,
194-
NULL, NULL, NULL);
194+
NULL, NULL);
195195
}
196196

197197
ten_list_t msgs = TEN_LIST_INIT_VAL;
@@ -291,8 +291,7 @@ bool ten_test_tcp_client_send_data(ten_test_tcp_client_t *self,
291291
ten_data_set_buf_with_move(msg, &buf);
292292

293293
ten_msg_clear_and_set_dest(msg, ten_string_get_raw_str(&self->app_id),
294-
graph_id, extension_group_name, extension_name,
295-
NULL);
294+
graph_id, extension_name, NULL);
296295

297296
bool rc = ten_test_tcp_client_send_msg(self, msg);
298297
ten_shared_ptr_destroy(msg);

0 commit comments

Comments
 (0)