Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove extension field in ten_loc_t #53

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
"args": [
"--gtest_filter=StandaloneTest.New"
"--gtest_filter=ExtensionTest.TwoThreadsAttemptToSuspend7"
],
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
"env": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class extension_t {
TEN_ASSERT(stop_graph_cmd, "Should not happen.");

ten_msg_clear_and_set_dest(stop_graph_cmd, "localhost", nullptr, nullptr,
nullptr, nullptr, nullptr);
nullptr, nullptr);
ten_env_send_cmd(ten_env.get_c_ten_env(), stop_graph_cmd, nullptr, nullptr,
nullptr);
ten_shared_ptr_destroy(stop_graph_cmd);
Expand Down
4 changes: 2 additions & 2 deletions core/include/ten_runtime/binding/cpp/internal/msg/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

#include <string>

#include "ten_utils/macro/check.h"
#include "ten_runtime/common/errno.h"
#include "ten_runtime/msg/msg.h"
#include "ten_utils/lang/cpp/lib/error.h"
#include "ten_utils/lang/cpp/lib/value.h"
#include "ten_utils/lib/buf.h"
#include "ten_utils/lib/json.h"
#include "ten_utils/lib/smart_ptr.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/value/value.h"
#include "ten_utils/value/value_get.h"
#include "ten_utils/value/value_json.h"
Expand Down Expand Up @@ -96,7 +96,7 @@ class msg_t {
}

return ten_msg_clear_and_set_dest(
c_msg_, uri, graph, extension_group_name, extension_name, nullptr,
c_msg_, uri, graph, extension_group_name, extension_name,
err != nullptr ? err->get_internal_representation() : nullptr);
}

Expand Down
2 changes: 1 addition & 1 deletion core/include/ten_runtime/msg/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ TEN_RUNTIME_API ten_value_t *ten_msg_peek_property(ten_shared_ptr_t *self,
TEN_RUNTIME_API bool ten_msg_clear_and_set_dest(
ten_shared_ptr_t *self, const char *app_uri, const char *graph_name,
const char *extension_group_name, const char *extension_name,
ten_extension_t *extension, ten_error_t *err);
ten_error_t *err);

TEN_RUNTIME_API bool ten_msg_from_json(ten_shared_ptr_t *self, ten_json_t *json,
ten_error_t *err);
Expand Down
35 changes: 15 additions & 20 deletions core/include_internal/ten_runtime/common/loc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@ typedef struct ten_extension_t ten_extension_t;
// Something like the 'type' information in an object-oriented programming
// language, which is how to 'create' the object instance.
// Therefore, the static information of a extension is the information
// relevant to the creating logic of a extension instance. Ex: the uri tags of
// the app, the extension name of the extension group and the extension.
// relevant to the creating logic of a extension instance. Ex: the addon
// name of the extension group and the extension.
typedef struct ten_loc_t {
ten_signature_t signature;

ten_string_t app_uri;
ten_string_t graph_name;
ten_string_t extension_group_name;
ten_string_t extension_name;

// The following field is for caching purpose. It's the ten_extension_t
// corresponding to the above 'uri' and 'extension_name'.
ten_extension_t *extension;
} ten_loc_t;

TEN_RUNTIME_PRIVATE_API bool ten_loc_check_integrity(ten_loc_t *self);
Expand All @@ -57,46 +53,45 @@ TEN_RUNTIME_PRIVATE_API ten_loc_t *ten_loc_clone(ten_loc_t *src);
TEN_RUNTIME_PRIVATE_API void ten_loc_copy(ten_loc_t *self, ten_loc_t *src);

TEN_RUNTIME_PRIVATE_API void ten_loc_init_from_loc(ten_loc_t *self,
ten_loc_t *src);
ten_loc_t *src);

TEN_RUNTIME_PRIVATE_API void ten_loc_init_from_value(ten_loc_t *self,
ten_value_t *value);
ten_value_t *value);

TEN_RUNTIME_PRIVATE_API void ten_loc_set(ten_loc_t *self, const char *app_uri,
const char *graph_name,
const char *extension_group_name,
const char *extension_name,
ten_extension_t *extension);
const char *graph_name,
const char *extension_group_name,
const char *extension_name);

TEN_RUNTIME_PRIVATE_API bool ten_loc_is_empty(ten_loc_t *self);

TEN_RUNTIME_PRIVATE_API void ten_loc_clear(ten_loc_t *self);

TEN_RUNTIME_PRIVATE_API bool ten_loc_is_equal(ten_loc_t *self, ten_loc_t *other);
TEN_RUNTIME_PRIVATE_API bool ten_loc_is_equal(ten_loc_t *self,
ten_loc_t *other);

TEN_RUNTIME_PRIVATE_API bool ten_loc_is_equal_with_value(
ten_loc_t *self, const char *app_uri, const char *graph_name,
const char *extension_group_name, const char *extension_name);

TEN_RUNTIME_PRIVATE_API void ten_loc_to_string(ten_loc_t *self,
ten_string_t *result);
ten_string_t *result);

TEN_RUNTIME_PRIVATE_API ten_json_t *ten_loc_to_json(ten_loc_t *self);

TEN_RUNTIME_API ten_loc_t *ten_loc_create(const char *app_uri,
const char *graph_name,
const char *extension_group_name,
const char *extension_name,
ten_extension_t *extension);
const char *graph_name,
const char *extension_group_name,
const char *extension_name);

TEN_RUNTIME_PRIVATE_API void ten_loc_init_empty(ten_loc_t *self);

TEN_RUNTIME_PRIVATE_API void ten_loc_init_from_json(ten_loc_t *self,
ten_json_t *json);
ten_json_t *json);

TEN_RUNTIME_API void ten_loc_destroy(ten_loc_t *self);

TEN_RUNTIME_PRIVATE_API void ten_loc_deinit(ten_loc_t *self);

TEN_RUNTIME_PRIVATE_API void ten_loc_to_json_string(ten_loc_t *self,
ten_string_t *result);
ten_string_t *result);
14 changes: 4 additions & 10 deletions core/include_internal/ten_runtime/msg/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "ten_runtime/ten_config.h"

#include "include_internal/ten_runtime/common/loc.h"
#include "ten_utils/macro/check.h"
#include "ten_runtime/msg/msg.h"
#include "ten_utils/container/list.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/value/value.h"

#define TEN_MSG_SIGNATURE 0xA9FA53F77185F856U
Expand Down Expand Up @@ -97,8 +97,7 @@ TEN_RUNTIME_PRIVATE_API void ten_msg_clear_and_set_dest_from_msg_src(

TEN_RUNTIME_PRIVATE_API void ten_raw_msg_add_dest(
ten_msg_t *self, const char *app_uri, const char *graph_name,
const char *extension_group_name, const char *extension_name,
ten_extension_t *extension);
const char *extension_group_name, const char *extension_name);

TEN_RUNTIME_PRIVATE_API void ten_raw_msg_clear_dest(ten_msg_t *self);

Expand All @@ -120,15 +119,13 @@ TEN_RUNTIME_PRIVATE_API ten_loc_t *ten_raw_msg_get_first_dest_loc(

TEN_RUNTIME_PRIVATE_API void ten_raw_msg_set_src(
ten_msg_t *self, const char *app_uri, const char *graph_name,
const char *extension_group_name, const char *extension_name,
ten_extension_t *extension);
const char *extension_group_name, const char *extension_name);

TEN_RUNTIME_PRIVATE_API void ten_msg_set_src(ten_shared_ptr_t *self,
const char *app_uri,
const char *graph_name,
const char *extension_group_name,
const char *extension_name,
ten_extension_t *extension);
const char *extension_name);

TEN_RUNTIME_PRIVATE_API void ten_msg_set_src_uri(ten_shared_ptr_t *self,
const char *app_uri);
Expand All @@ -152,9 +149,6 @@ TEN_RUNTIME_PRIVATE_API void ten_raw_msg_clear_and_set_dest_to_loc(
TEN_RUNTIME_PRIVATE_API void ten_msg_set_src_to_app(ten_shared_ptr_t *self,
ten_app_t *app);

TEN_RUNTIME_PRIVATE_API ten_extension_t *
ten_msg_try_to_find_dest_extension_in_fast_path(ten_shared_ptr_t *msg);

TEN_RUNTIME_PRIVATE_API bool ten_msg_type_to_handle_when_closing(
ten_shared_ptr_t *msg);

Expand Down
36 changes: 11 additions & 25 deletions core/src/ten_runtime/common/loc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#include "include_internal/ten_runtime/common/constant_str.h"
#include "include_internal/ten_runtime/extension/extension.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/lib/alloc.h"
#include "ten_utils/lib/json.h"
#include "ten_utils/lib/string.h"
#include "ten_utils/macro/check.h"

bool ten_loc_check_integrity(ten_loc_t *self) {
TEN_ASSERT(self, "Should not happen.");
Expand Down Expand Up @@ -42,12 +42,10 @@ ten_loc_t *ten_loc_create_empty(void) {

ten_loc_t *ten_loc_create(const char *app_uri, const char *graph_name,
const char *extension_group_name,
const char *extension_name,
ten_extension_t *extension) {
const char *extension_name) {
ten_loc_t *self = ten_loc_create_empty();

ten_loc_set(self, app_uri, graph_name, extension_group_name, extension_name,
extension);
ten_loc_set(self, app_uri, graph_name, extension_group_name, extension_name);
TEN_ASSERT(ten_loc_check_integrity(self), "Should not happen.");

return self;
Expand All @@ -56,11 +54,11 @@ ten_loc_t *ten_loc_create(const char *app_uri, const char *graph_name,
ten_loc_t *ten_loc_clone(ten_loc_t *src) {
TEN_ASSERT(src && ten_loc_check_integrity(src), "Should not happen.");

ten_loc_t *self = ten_loc_create(
ten_string_get_raw_str(&src->app_uri),
ten_string_get_raw_str(&src->graph_name),
ten_string_get_raw_str(&src->extension_group_name),
ten_string_get_raw_str(&src->extension_name), src->extension);
ten_loc_t *self =
ten_loc_create(ten_string_get_raw_str(&src->app_uri),
ten_string_get_raw_str(&src->graph_name),
ten_string_get_raw_str(&src->extension_group_name),
ten_string_get_raw_str(&src->extension_name));

TEN_ASSERT(ten_loc_check_integrity(self), "Should not happen.");

Expand Down Expand Up @@ -90,8 +88,6 @@ void ten_loc_init_empty(ten_loc_t *self) {
ten_string_init(&self->graph_name);
ten_string_init(&self->extension_group_name);
ten_string_init(&self->extension_name);

self->extension = NULL;
}

void ten_loc_init_from_loc(ten_loc_t *self, ten_loc_t *src) {
Expand All @@ -101,7 +97,7 @@ void ten_loc_init_from_loc(ten_loc_t *self, ten_loc_t *src) {
ten_loc_set(self, ten_string_get_raw_str(&src->app_uri),
ten_string_get_raw_str(&src->graph_name),
ten_string_get_raw_str(&src->extension_group_name),
ten_string_get_raw_str(&src->extension_name), src->extension);
ten_string_get_raw_str(&src->extension_name));

TEN_ASSERT(ten_loc_check_integrity(self), "Should not happen.");
}
Expand All @@ -115,17 +111,11 @@ void ten_loc_deinit(ten_loc_t *self) {
ten_string_deinit(&self->graph_name);
ten_string_deinit(&self->extension_group_name);
ten_string_deinit(&self->extension_name);

self->extension = NULL;
}

void ten_loc_set(ten_loc_t *self, const char *app_uri, const char *graph_name,
const char *extension_group_name, const char *extension_name,
ten_extension_t *extension) {
TEN_ASSERT(self && (extension ? ten_string_is_equal_c_str(&extension->name,
extension_name)
: true),
"Should not happen.");
const char *extension_group_name, const char *extension_name) {
TEN_ASSERT(self, "Should not happen.");

ten_string_init_formatted(&self->app_uri, "%s", app_uri ? app_uri : "");
ten_string_init_formatted(&self->graph_name, "%s",
Expand All @@ -135,8 +125,6 @@ void ten_loc_set(ten_loc_t *self, const char *app_uri, const char *graph_name,
ten_string_init_formatted(&self->extension_name, "%s",
extension_name ? extension_name : "");

self->extension = extension;

TEN_ASSERT(ten_loc_check_integrity(self), "Should not happen.");
}

Expand All @@ -159,8 +147,6 @@ void ten_loc_clear(ten_loc_t *self) {
ten_string_clear(&self->graph_name);
ten_string_clear(&self->extension_group_name);
ten_string_clear(&self->extension_name);

self->extension = NULL;
}

bool ten_loc_is_equal(ten_loc_t *self, ten_loc_t *other) {
Expand Down
8 changes: 1 addition & 7 deletions core/src/ten_runtime/engine/msg_interface/close_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include "include_internal/ten_runtime/msg/cmd_base/cmd/stop_graph/cmd.h"
#include "include_internal/ten_runtime/msg/msg.h"
#include "include_internal/ten_runtime/remote/remote.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/lib/smart_ptr.h"
#include "ten_utils/lib/string.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/macro/mark.h"

void ten_engine_handle_cmd_stop_graph(ten_engine_t *self, ten_shared_ptr_t *cmd,
Expand All @@ -32,12 +32,6 @@ void ten_engine_handle_cmd_stop_graph(ten_engine_t *self, ten_shared_ptr_t *cmd,
// used to return the cmd_result when the engine is shut down later.
self->cmd_stop_graph = ten_shared_ptr_clone(cmd);

// Engine should not cache any pointers to the src extension.
ten_loc_t *src_loc = ten_msg_get_src_loc(self->cmd_stop_graph);
TEN_ASSERT(src_loc && ten_loc_check_integrity(src_loc),
"Should not happen");
src_loc->extension = NULL;

ten_engine_close_async(self);
} else {
// Close other engine. Send the command to app.
Expand Down
4 changes: 2 additions & 2 deletions core/src/ten_runtime/engine/msg_interface/start_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#include "include_internal/ten_runtime/path/path_group.h"
#include "include_internal/ten_runtime/remote/remote.h"
#include "include_internal/ten_utils/log/log.h"
#include "ten_utils/macro/check.h"
#include "include_internal/ten_utils/value/value.h"
#include "ten_runtime/msg/cmd_result/cmd_result.h"
#include "ten_utils/container/list.h"
#include "ten_utils/container/list_ptr.h"
#include "ten_utils/lib/error.h"
#include "ten_utils/macro/check.h"

void ten_engine_handle_cmd_start_graph(ten_engine_t *self,
ten_shared_ptr_t *cmd,
Expand Down Expand Up @@ -82,7 +82,7 @@ void ten_engine_handle_cmd_start_graph(ten_engine_t *self,
// Correct the destination information of the 'start_graph' command.
ten_msg_clear_and_set_dest(child_cmd, dest_uri_c_str,
ten_string_get_raw_str(&self->graph_name),
NULL, NULL, NULL, err);
NULL, NULL, err);

ten_path_t *out_path = (ten_path_t *)ten_path_table_add_out_path(
self->path_table, child_cmd);
Expand Down
16 changes: 7 additions & 9 deletions core/src/ten_runtime/extension/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,15 +722,13 @@ bool ten_extension_handle_out_msg(ten_extension_t *self, ten_shared_ptr_t *msg,
const bool msg_is_cmd = ten_msg_is_cmd_base(msg);
bool msg_is_cmd_result = false;

if (msg_is_cmd) {
if (ten_msg_get_type(msg) == TEN_MSG_TYPE_CMD_RESULT) {
msg_is_cmd_result = true;

// The backward path should strictly follow the information recorded
// in the path table, therefore, users should not 'override' the
// destination location in this case.
ten_msg_clear_dest(msg);
}
if (ten_msg_get_type(msg) == TEN_MSG_TYPE_CMD_RESULT) {
msg_is_cmd_result = true;

// The backward path should strictly follow the information recorded
// in the path table, therefore, users should not 'override' the
// destination location in this case.
ten_msg_clear_dest(msg);
}

ten_msg_correct_dest(msg, self->extension_context->engine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "include_internal/ten_runtime/extension/extension.h"
#include "include_internal/ten_runtime/extension/msg_dest_info/msg_dest_info.h"
#include "include_internal/ten_runtime/msg_conversion/msg_conversion/msg_conversion.h"
#include "ten_utils/macro/check.h"
#include "ten_runtime/common/errno.h"
#include "ten_utils/container/list.h"
#include "ten_utils/container/list_node_ptr.h"
Expand All @@ -22,6 +21,7 @@
#include "ten_utils/lib/error.h"
#include "ten_utils/lib/smart_ptr.h"
#include "ten_utils/lib/string.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/value/value.h"

ten_extension_info_t *ten_extension_info_create(void) {
Expand Down Expand Up @@ -196,7 +196,7 @@ ten_shared_ptr_t *get_extension_info_in_extensions_info(
ten_extension_info_t *self = ten_extension_info_create();

ten_loc_set(&self->loc, app_uri, graph_name, extension_group_name,
extension_instance_name, NULL);
extension_instance_name);

// Add the extension addon name if we know it now.
if (extension_addon_name && strlen(extension_addon_name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ten_shared_ptr_t *get_extension_group_info_in_extension_groups_info(
ten_extension_group_info_t *self = ten_extension_group_info_create();

ten_loc_set(&self->loc, app_uri, graph_name, extension_group_instance_name,
NULL, NULL);
NULL);

// Add the extension group addon name if we know it now.
if (strlen(extension_group_addon_name)) {
Expand Down
Loading
Loading