diff --git a/.github/workflows/build_linux_ubuntu1804.yml b/.github/workflows/build_linux_ubuntu1804.yml index d18879536a..dc95180d8e 100644 --- a/.github/workflows/build_linux_ubuntu1804.yml +++ b/.github/workflows/build_linux_ubuntu1804.yml @@ -52,7 +52,7 @@ jobs: echo $PATH go env -w GOFLAGS="-buildvcs=false" rustup default nightly - tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=false log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_enable_package_manager=false ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true + tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=false log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_package_manager=false ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true tgn build linux x64 ${{ matrix.build_type }} tree -I 'gen|obj' out diff --git a/.github/workflows/build_linux_ubuntu2204.yml b/.github/workflows/build_linux_ubuntu2204.yml index 85f0aa89d5..f9920b7aed 100644 --- a/.github/workflows/build_linux_ubuntu2204.yml +++ b/.github/workflows/build_linux_ubuntu2204.yml @@ -58,7 +58,7 @@ jobs: go env -w GOFLAGS="-buildvcs=false" go1.20.12 download rustup default nightly - tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=${{ matrix.compiler == 'gcc' && 'false' || 'true' }} log_level=1 enable_serialized_actions=true ten_enable_private_tests=false ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true ten_enable_go_lint=true + tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=${{ matrix.compiler == 'gcc' && 'false' || 'true' }} log_level=1 enable_serialized_actions=true ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true ten_enable_go_lint=true tgn build linux x64 ${{ matrix.build_type }} tree -I 'gen|obj' out diff --git a/.github/workflows/build_mac.yml b/.github/workflows/build_mac.yml index 9d2a88d051..7dd4ec642a 100644 --- a/.github/workflows/build_mac.yml +++ b/.github/workflows/build_mac.yml @@ -77,7 +77,7 @@ jobs: export PATH=$(pwd)/core/ten_gn:$PATH echo $PATH - tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_private_tests=false ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true ten_enable_python_binding=false + tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true ten_enable_python_binding=false tgn build mac arm64 ${{ matrix.build_type }} tree -I 'gen|obj' out @@ -239,7 +239,7 @@ jobs: export PATH=$(pwd)/core/ten_gn:$PATH echo $PATH - tgn gen mac x64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_private_tests=false ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true ten_enable_python_binding=false + tgn gen mac x64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true ten_enable_python_binding=false tgn build mac x64 ${{ matrix.build_type }} tree -I 'gen|obj' out @@ -402,7 +402,7 @@ jobs: export PATH=$(pwd)/core/ten_gn:$PATH echo $PATH - tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_private_tests=false ten_rust_enable_gen_cargo_config=false ten_enable_ten_rust_apis=false + tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_rust_enable_gen_cargo_config=false ten_enable_ten_rust_apis=false tgn build mac arm64 ${{ matrix.build_type }} diff --git a/.github/workflows/build_win.yml b/.github/workflows/build_win.yml index b9fbe453b5..4f35a05a6c 100644 --- a/.github/workflows/build_win.yml +++ b/.github/workflows/build_win.yml @@ -65,7 +65,7 @@ jobs: - name: Build run: | $ENV:PATH += ";$PWD/core/ten_gn" - tgn gen win x64 ${{ matrix.build_type }} -- vs_version=2022 log_level=1 enable_serialized_actions=true ten_enable_private_tests=false ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true ten_enable_python_binding=false ten_enable_go_binding=false + tgn gen win x64 ${{ matrix.build_type }} -- vs_version=2022 log_level=1 enable_serialized_actions=true ten_rust_enable_gen_cargo_config=false ten_enable_cargo_clean=true ten_enable_python_binding=false ten_enable_go_binding=false tgn build win x64 ${{ matrix.build_type }} - name: Run Tests (ten_utils_unit_test) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4e01fea3ba..a8dd8c291b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -137,7 +137,7 @@ "request": "launch", "program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test", "args": [ - "--gtest_filter=PropertyTest.GetInt32" + "--gtest_filter=ExtensionTest.CommandInvalidExtension2" ], "cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/", "env": { @@ -569,30 +569,30 @@ "name": "app (Python Main) (cppdbg, launch)", "type": "cppdbg", "request": "launch", - "program": "/usr/bin/python3", + "program": "/home/wei/.python_venv/bin/python", "args": [ "main.py" ], "environment": [ { "name": "PYTHONPATH", - "value": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/system/ten_runtime_python/lib:${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/system/ten_runtime_python/interface" + "value": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/system/ten_runtime_python/lib:${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/system/ten_runtime_python/interface" }, { "name": "TEN_APP_BASE_DIR", - "value": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/" + "value": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/" }, { "name": "LD_PRELOAD", - "value": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/system/ten_runtime/lib/libasan.so" + "value": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/system/ten_runtime/lib/libasan.so" }, { "name": "PYTHONMALLOC", "value": "malloc" } ], - "cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app", - "additionalSOLibSearchPath": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/system/ten_runtime_python/lib:${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/system/ten_runtime/lib", + "cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app", + "additionalSOLibSearchPath": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/system/ten_runtime_python/lib:${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/system/ten_runtime/lib", "MIMode": "gdb", }, { diff --git a/build/ten_runtime/options.gni b/build/ten_runtime/options.gni index d542dbfeda..b34d8e7934 100644 --- a/build/ten_runtime/options.gni +++ b/build/ten_runtime/options.gni @@ -58,7 +58,6 @@ declare_args() { ten_enable_unit_tests = true ten_enable_smoke_tests = true ten_enable_integration_tests = true - ten_enable_private_tests = false } ten_runtime_common_defines = common_defines diff --git a/core/include/ten_runtime/binding/cpp/detail/msg/audio_frame.h b/core/include/ten_runtime/binding/cpp/detail/msg/audio_frame.h index b702e390bb..f41b884409 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/audio_frame.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/audio_frame.h @@ -33,9 +33,9 @@ class audio_frame_t : public msg_t { }; public: - static std::unique_ptr create(const char *audio_frame_name, + static std::unique_ptr create(const char *name, error_t *err = nullptr) { - if (audio_frame_name == nullptr || strlen(audio_frame_name) == 0) { + if (name == nullptr || strlen(name) == 0) { if (err != nullptr && err->get_c_error() != nullptr) { ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, "audio frame name cannot be empty."); @@ -43,9 +43,8 @@ class audio_frame_t : public msg_t { return nullptr; } - auto *c_frame = ten_audio_frame_create(); - ten_msg_set_name(c_frame, audio_frame_name, - err != nullptr ? err->get_c_error() : nullptr); + auto *c_frame = ten_audio_frame_create( + name, err != nullptr ? err->get_c_error() : nullptr); return std::make_unique(c_frame, ctor_passkey_t()); } diff --git a/core/include/ten_runtime/binding/cpp/detail/msg/cmd/cmd.h b/core/include/ten_runtime/binding/cpp/detail/msg/cmd/cmd.h index dfecf55acc..f671f937c6 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/cmd/cmd.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/cmd/cmd.h @@ -31,10 +31,10 @@ class cmd_t : public msg_t { }; public: - static std::unique_ptr create(const char *cmd_name, + static std::unique_ptr create(const char *name, error_t *err = nullptr) { ten_shared_ptr_t *c_cmd = - ten_cmd_create(cmd_name, err != nullptr ? err->get_c_error() : nullptr); + ten_cmd_create(name, err != nullptr ? err->get_c_error() : nullptr); return std::make_unique(c_cmd, ctor_passkey_t()); } diff --git a/core/include/ten_runtime/binding/cpp/detail/msg/data.h b/core/include/ten_runtime/binding/cpp/detail/msg/data.h index 08f1c8a4b0..22239cc453 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/data.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/data.h @@ -45,9 +45,8 @@ class data_t : public msg_t { return nullptr; } - auto *c_data = ten_data_create(); - ten_msg_set_name(c_data, data_name, - err != nullptr ? err->get_c_error() : nullptr); + auto *c_data = ten_data_create( + data_name, err != nullptr ? err->get_c_error() : nullptr); return std::make_unique(c_data, ctor_passkey_t()); } diff --git a/core/include/ten_runtime/binding/cpp/detail/msg/msg.h b/core/include/ten_runtime/binding/cpp/detail/msg/msg.h index e557cbfee5..1afae5028e 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/msg.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/msg.h @@ -17,7 +17,6 @@ #include "ten_utils/lib/buf.h" #include "ten_utils/lib/json.h" #include "ten_utils/lib/smart_ptr.h" -#include "ten_utils/log/log.h" #include "ten_utils/macro/check.h" #include "ten_utils/value/value.h" #include "ten_utils/value/value_get.h" @@ -101,75 +100,6 @@ class msg_t { err != nullptr ? err->get_c_error() : nullptr); } - std::string to_json(error_t *err = nullptr) const { - TEN_ASSERT(c_msg, "Should not happen."); - - if (c_msg == nullptr) { - if (err != nullptr && err->get_c_error() != nullptr) { - ten_error_set(err->get_c_error(), TEN_ERRNO_GENERIC, - "Invalid TEN message."); - } - return ""; - } - - ten_json_t *c_json = - ten_msg_to_json(c_msg, err != nullptr ? err->get_c_error() : nullptr); - TEN_ASSERT(c_json, "Failed to get json from TEN C message."); - if (c_json == nullptr) { - if (err != nullptr && err->get_c_error() != nullptr) { - ten_error_set(err->get_c_error(), TEN_ERRNO_GENERIC, - "Invalid TEN message."); - } - return ""; - } - - bool must_free = false; - const char *json_str = ten_json_to_string(c_json, nullptr, &must_free); - TEN_ASSERT(json_str, "Failed to get JSON string from JSON."); - std::string res = json_str; - - ten_json_destroy(c_json); - if (must_free) { - TEN_FREE( - json_str); // NOLINT(cppcoreguidelines-no-malloc, hicpp-no-malloc) - } - return res; - } - - bool from_json(const char *json_str, error_t *err = nullptr) { - TEN_ASSERT(c_msg, "Should not happen."); - - if (c_msg == nullptr) { - if (err != nullptr && err->get_c_error() != nullptr) { - ten_error_set(err->get_c_error(), TEN_ERRNO_GENERIC, - "Invalid TEN message."); - } - return false; - } - - bool result = true; - - ten_json_t *c_json = ten_json_from_string( - json_str, err != nullptr ? err->get_c_error() : nullptr); - if (c_json == nullptr) { - result = false; - goto done; // NOLINT(hicpp-avoid-goto,cppcoreguidelines-avoid-goto) - } - - result = ten_msg_from_json(c_msg, c_json, - err != nullptr ? err->get_c_error() : nullptr); - if (!result) { - TEN_LOGW("Failed to set message content."); - goto done; // NOLINT(hicpp-avoid-goto,cppcoreguidelines-avoid-goto) - } - - done: - if (c_json != nullptr) { - ten_json_destroy(c_json); - } - return result; - } - bool is_property_exist(const char *path, error_t *err = nullptr) { TEN_ASSERT(c_msg, "Should not happen."); TEN_ASSERT(path && strlen(path), "path should not be empty."); @@ -374,10 +304,8 @@ class msg_t { return get_property_buf(path, nullptr); } - std::string get_property_to_json(const char *path, + std::string get_property_to_json(const char *path = nullptr, error_t *err = nullptr) const { - TEN_ASSERT(path && strlen(path), "path should not be empty."); - if (c_msg == nullptr) { if (err != nullptr && err->get_c_error() != nullptr) { ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, @@ -394,6 +322,10 @@ class msg_t { } ten_json_t *c_json = ten_value_to_json(value); if (c_json == nullptr) { + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_GENERIC, + "Invalid TEN message."); + } return result; } @@ -562,6 +494,14 @@ class msg_t { error_t *err = nullptr) { TEN_ASSERT(c_msg, "Should not happen."); + if (c_msg == nullptr) { + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_GENERIC, + "Invalid TEN message."); + } + return false; + } + ten_json_t *c_json = ten_json_from_string( json, err != nullptr ? err->get_c_error() : nullptr); if (c_json == nullptr) { diff --git a/core/include/ten_runtime/binding/cpp/detail/msg/video_frame.h b/core/include/ten_runtime/binding/cpp/detail/msg/video_frame.h index 809e8099a4..08e604bf0d 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/video_frame.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/video_frame.h @@ -33,9 +33,9 @@ class video_frame_t : public msg_t { }; public: - static std::unique_ptr create(const char *video_frame_name, + static std::unique_ptr create(const char *name, error_t *err = nullptr) { - if (video_frame_name == nullptr || strlen(video_frame_name) == 0) { + if (name == nullptr || strlen(name) == 0) { if (err != nullptr && err->get_c_error() != nullptr) { ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, "Video frame name cannot be empty."); @@ -43,9 +43,8 @@ class video_frame_t : public msg_t { return nullptr; } - auto *c_frame = ten_video_frame_create(); - ten_msg_set_name(c_frame, video_frame_name, - err != nullptr ? err->get_c_error() : nullptr); + auto *c_frame = ten_video_frame_create( + name, err != nullptr ? err->get_c_error() : nullptr); return std::make_unique(c_frame, ctor_passkey_t()); } diff --git a/core/include/ten_runtime/msg/audio_frame/audio_frame.h b/core/include/ten_runtime/msg/audio_frame/audio_frame.h index 86cf21edd2..0f947ec1b2 100644 --- a/core/include/ten_runtime/msg/audio_frame/audio_frame.h +++ b/core/include/ten_runtime/msg/audio_frame/audio_frame.h @@ -29,7 +29,8 @@ typedef enum TEN_AUDIO_FRAME_DATA_FMT { typedef struct ten_audio_frame_t ten_audio_frame_t; -TEN_RUNTIME_API ten_shared_ptr_t *ten_audio_frame_create(void); +TEN_RUNTIME_API ten_shared_ptr_t *ten_audio_frame_create(const char *name, + ten_error_t *err); TEN_RUNTIME_API int64_t ten_audio_frame_get_timestamp(ten_shared_ptr_t *self); TEN_RUNTIME_API bool ten_audio_frame_set_timestamp(ten_shared_ptr_t *self, diff --git a/core/include/ten_runtime/msg/cmd/cmd.h b/core/include/ten_runtime/msg/cmd/cmd.h index fa8c3f7be7..1195d9be36 100644 --- a/core/include/ten_runtime/msg/cmd/cmd.h +++ b/core/include/ten_runtime/msg/cmd/cmd.h @@ -11,5 +11,5 @@ #include "ten_utils/lib/error.h" #include "ten_utils/lib/smart_ptr.h" -TEN_RUNTIME_API ten_shared_ptr_t *ten_cmd_create(const char *cmd_name, +TEN_RUNTIME_API ten_shared_ptr_t *ten_cmd_create(const char *name, ten_error_t *err); diff --git a/core/include/ten_runtime/msg/data/data.h b/core/include/ten_runtime/msg/data/data.h index cfce3bdb65..9a158f34f4 100644 --- a/core/include/ten_runtime/msg/data/data.h +++ b/core/include/ten_runtime/msg/data/data.h @@ -16,11 +16,13 @@ typedef struct ten_data_t ten_data_t; -TEN_RUNTIME_API ten_shared_ptr_t *ten_data_create(void); +TEN_RUNTIME_API ten_shared_ptr_t *ten_data_create(const char *name, + ten_error_t *err); TEN_RUNTIME_API ten_buf_t *ten_data_peek_buf(ten_shared_ptr_t *self); TEN_RUNTIME_API void ten_data_set_buf_with_move(ten_shared_ptr_t *self, - ten_buf_t *buf); + ten_buf_t *buf); -TEN_RUNTIME_API uint8_t *ten_data_alloc_buf(ten_shared_ptr_t *self, size_t size); +TEN_RUNTIME_API uint8_t *ten_data_alloc_buf(ten_shared_ptr_t *self, + size_t size); diff --git a/core/include/ten_runtime/msg/video_frame/video_frame.h b/core/include/ten_runtime/msg/video_frame/video_frame.h index d04c558b95..9a137fa288 100644 --- a/core/include/ten_runtime/msg/video_frame/video_frame.h +++ b/core/include/ten_runtime/msg/video_frame/video_frame.h @@ -34,7 +34,8 @@ typedef enum TEN_PIXEL_FMT { typedef struct ten_video_frame_t ten_video_frame_t; -TEN_RUNTIME_API ten_shared_ptr_t *ten_video_frame_create(void); +TEN_RUNTIME_API ten_shared_ptr_t *ten_video_frame_create(const char *name, + ten_error_t *err); TEN_RUNTIME_API int32_t ten_video_frame_get_width(ten_shared_ptr_t *self); TEN_RUNTIME_API bool ten_video_frame_set_width(ten_shared_ptr_t *self, diff --git a/core/include/ten_utils/value/value_get.h b/core/include/ten_utils/value/value_get.h index 5f61fddb1b..ca1f61aa16 100644 --- a/core/include/ten_utils/value/value_get.h +++ b/core/include/ten_utils/value/value_get.h @@ -56,5 +56,7 @@ TEN_UTILS_API ten_buf_t *ten_value_peek_buf(ten_value_t *self); TEN_UTILS_API ten_list_t *ten_value_peek_array(ten_value_t *self); +TEN_UTILS_API ten_list_t *ten_value_peek_object(ten_value_t *self); + TEN_UTILS_API ten_value_t *ten_value_array_peek(ten_value_t *self, size_t index, ten_error_t *err); diff --git a/core/include_internal/ten_runtime/binding/python/msg/msg.h b/core/include_internal/ten_runtime/binding/python/msg/msg.h index c629699b76..7d104356fb 100644 --- a/core/include_internal/ten_runtime/binding/python/msg/msg.h +++ b/core/include_internal/ten_runtime/binding/python/msg/msg.h @@ -22,12 +22,6 @@ typedef struct ten_py_msg_t { ten_shared_ptr_t *c_msg; } ten_py_msg_t; -TEN_RUNTIME_PRIVATE_API PyObject *ten_py_msg_to_json(PyObject *self, - PyObject *args); - -TEN_RUNTIME_PRIVATE_API PyObject *ten_py_msg_from_json(PyObject *self, - PyObject *args); - TEN_RUNTIME_PRIVATE_API PyObject *ten_py_msg_get_name(PyObject *self, PyObject *args); diff --git a/core/include_internal/ten_runtime/msg/audio_frame/audio_frame.h b/core/include_internal/ten_runtime/msg/audio_frame/audio_frame.h index dbf8b6e6d0..2a5aeb4530 100644 --- a/core/include_internal/ten_runtime/msg/audio_frame/audio_frame.h +++ b/core/include_internal/ten_runtime/msg/audio_frame/audio_frame.h @@ -57,6 +57,11 @@ typedef struct ten_audio_frame_t { ten_value_t is_eof; // bool } ten_audio_frame_t; +TEN_RUNTIME_PRIVATE_API ten_shared_ptr_t *ten_audio_frame_create_empty(void); + +TEN_RUNTIME_API ten_shared_ptr_t *ten_audio_frame_create_with_name_len( + const char *name, size_t name_len, ten_error_t *err); + TEN_RUNTIME_PRIVATE_API void ten_raw_audio_frame_destroy( ten_audio_frame_t *self); diff --git a/core/include_internal/ten_runtime/msg/cmd_base/cmd/custom/cmd.h b/core/include_internal/ten_runtime/msg/cmd_base/cmd/custom/cmd.h index c4c042b970..6fb151e1b7 100644 --- a/core/include_internal/ten_runtime/msg/cmd_base/cmd/custom/cmd.h +++ b/core/include_internal/ten_runtime/msg/cmd_base/cmd/custom/cmd.h @@ -13,6 +13,7 @@ #include "include_internal/ten_runtime/msg/loop_fields.h" #include "ten_utils/container/list.h" #include "ten_utils/lib/error.h" +#include "ten_utils/lib/smart_ptr.h" #include "ten_utils/value/value.h" typedef struct ten_msg_t ten_msg_t; @@ -29,10 +30,16 @@ TEN_RUNTIME_PRIVATE_API ten_msg_t *ten_raw_cmd_custom_as_msg_clone( TEN_RUNTIME_PRIVATE_API ten_json_t *ten_raw_cmd_custom_to_json( ten_msg_t *self, ten_error_t *err); -TEN_RUNTIME_API ten_shared_ptr_t *ten_cmd_custom_create(void); +TEN_RUNTIME_API ten_shared_ptr_t *ten_cmd_custom_create_empty(void); -TEN_RUNTIME_PRIVATE_API ten_cmd_t *ten_raw_cmd_custom_create( - const char *cmd_name); +TEN_RUNTIME_PRIVATE_API ten_cmd_t *ten_raw_cmd_custom_create(const char *name, + ten_error_t *err); + +TEN_RUNTIME_PRIVATE_API ten_shared_ptr_t *ten_cmd_custom_create( + const char *name, ten_error_t *err); + +TEN_RUNTIME_API ten_shared_ptr_t *ten_cmd_custom_create_with_name_len( + const char *name, size_t name_len, ten_error_t *err); TEN_RUNTIME_PRIVATE_API bool ten_raw_cmd_custom_loop_all_fields( ten_msg_t *self, ten_raw_msg_process_one_field_func_t cb, void *user_data, diff --git a/core/include_internal/ten_runtime/msg/data/data.h b/core/include_internal/ten_runtime/msg/data/data.h index 42ca0e026b..2513898d51 100644 --- a/core/include_internal/ten_runtime/msg/data/data.h +++ b/core/include_internal/ten_runtime/msg/data/data.h @@ -14,7 +14,6 @@ #include "include_internal/ten_runtime/msg/msg.h" #include "ten_utils/container/list.h" #include "ten_utils/lib/error.h" -#include "ten_utils/lib/json.h" #define TEN_DATA_SIGNATURE 0xC579EAD75E1BB0FCU @@ -24,6 +23,11 @@ typedef struct ten_data_t { ten_value_t buf; } ten_data_t; +TEN_RUNTIME_PRIVATE_API ten_shared_ptr_t *ten_data_create_empty(void); + +TEN_RUNTIME_API ten_shared_ptr_t *ten_data_create_with_name_len( + const char *name, size_t name_len, ten_error_t *err); + TEN_RUNTIME_PRIVATE_API bool ten_raw_data_like_set_ten_property( ten_msg_t *self, ten_list_t *paths, ten_value_t *value, ten_error_t *err); diff --git a/core/include_internal/ten_runtime/msg/msg.h b/core/include_internal/ten_runtime/msg/msg.h index a4350f831b..57bdfb1925 100644 --- a/core/include_internal/ten_runtime/msg/msg.h +++ b/core/include_internal/ten_runtime/msg/msg.h @@ -300,6 +300,11 @@ TEN_RUNTIME_PRIVATE_API bool ten_raw_msg_set_name(ten_msg_t *self, const char *msg_name, ten_error_t *err); +TEN_RUNTIME_PRIVATE_API bool ten_raw_msg_set_name_with_len(ten_msg_t *self, + const char *msg_name, + size_t msg_name_len, + ten_error_t *err); + /** * @brief Set the 'graph_id' in the dest loc to the specified value. */ @@ -308,10 +313,10 @@ ten_msg_set_dest_engine_if_unspecified_or_predefined_graph_name( ten_shared_ptr_t *self, ten_engine_t *target_engine, ten_list_t *predefined_graph_infos); -TEN_RUNTIME_API bool ten_msg_set_name_with_size(ten_shared_ptr_t *self, - const char *msg_name, - size_t msg_name_len, - ten_error_t *err); +TEN_RUNTIME_PRIVATE_API bool ten_msg_set_name_with_len(ten_shared_ptr_t *self, + const char *msg_name, + size_t msg_name_len, + ten_error_t *err); inline TEN_MSG_TYPE ten_raw_msg_get_type(ten_msg_t *self) { TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); diff --git a/core/include_internal/ten_runtime/msg/video_frame/video_frame.h b/core/include_internal/ten_runtime/msg/video_frame/video_frame.h index d485333b80..7028f7cc2b 100644 --- a/core/include_internal/ten_runtime/msg/video_frame/video_frame.h +++ b/core/include_internal/ten_runtime/msg/video_frame/video_frame.h @@ -30,6 +30,11 @@ typedef struct ten_video_frame_t { ten_value_t data; // buf } ten_video_frame_t; +TEN_RUNTIME_PRIVATE_API ten_shared_ptr_t *ten_video_frame_create_empty(void); + +TEN_RUNTIME_API ten_shared_ptr_t *ten_video_frame_create_with_name_len( + const char *name, size_t name_len, ten_error_t *err); + TEN_RUNTIME_PRIVATE_API bool ten_raw_video_frame_check_integrity( ten_video_frame_t *self); diff --git a/core/src/ten_runtime/binding/go/interface/ten/msg.go b/core/src/ten_runtime/binding/go/interface/ten/msg.go index 6d3c35eae4..922bbeb029 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/msg.go +++ b/core/src/ten_runtime/binding/go/interface/ten/msg.go @@ -12,7 +12,6 @@ import "C" import ( "runtime" - "unsafe" ) // MsgType is an alias of `TEN_MSG_TYPE` from TEN runtime. @@ -47,7 +46,6 @@ type Msg interface { GetType() MsgType GetName() (string, error) - ToJSON() string iProperty } @@ -201,21 +199,6 @@ func (p *msg) getType() MsgType { return (MsgType)(C.ten_go_msg_get_type(p.cPtr)) } -func (p *msg) ToJSON() string { - return p.process(func() any { - return p.toJSON() - }).(string) -} - -func (p *msg) toJSON() string { - defer p.keepAlive() - - cString := C.ten_go_msg_to_json(p.cPtr) - defer C.free(unsafe.Pointer(cString)) - - return C.GoString(cString) -} - func (p *msg) GetName() (string, error) { defer p.keepAlive() diff --git a/core/src/ten_runtime/binding/go/interface/ten/msg.h b/core/src/ten_runtime/binding/go/interface/ten/msg.h index 9f3efcef6c..f100614a59 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/msg.h +++ b/core/src/ten_runtime/binding/go/interface/ten/msg.h @@ -17,8 +17,6 @@ typedef struct ten_go_value_t ten_go_value_t; int ten_go_msg_get_type(uintptr_t bridge_addr); -const char *ten_go_msg_to_json(uintptr_t bridge_addr); - /** * @brief Get the type and size of a property of the msg. This function is * called before getting property from the GO side, as the GO side needs to do diff --git a/core/src/ten_runtime/binding/go/interface/ten/msg_property.go b/core/src/ten_runtime/binding/go/interface/ten/msg_property.go index dfb964edf5..1a4f999f8e 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/msg_property.go +++ b/core/src/ten_runtime/binding/go/interface/ten/msg_property.go @@ -698,13 +698,6 @@ func (p *msg) setPropertyFromJSONBytes(path string, value []byte) error { // structure is already known beforehand through certain methods, GetProperty // can be used to retrieve individual fields. func (p *msg) SetPropertyFromJSONBytes(path string, value []byte) error { - if len(path) == 0 || len(value) == 0 { - return newTenError( - ErrnoInvalidArgument, - "the property path and value are required", - ) - } - return withCGO(func() error { return p.setPropertyFromJSONBytes(path, value) }) @@ -775,13 +768,6 @@ func (p *msg) getPropertyToJSONBytes(path string) ([]byte, error) { // This function uses a bytes pool to improve the performance. ReleaseBytes is // recommended to be called after the []byte is no longer used. func (p *msg) GetPropertyToJSONBytes(path string) ([]byte, error) { - if len(path) == 0 { - return nil, newTenError( - ErrnoInvalidArgument, - "the property path is required.", - ) - } - return withCGOLimiterHasReturnValue[[]byte](func() ([]byte, error) { return p.getPropertyToJSONBytes(path) }) diff --git a/core/src/ten_runtime/binding/go/native/msg/audio_frame/audio_frame.c b/core/src/ten_runtime/binding/go/native/msg/audio_frame/audio_frame.c index 809a36822e..8acfce5e21 100644 --- a/core/src/ten_runtime/binding/go/native/msg/audio_frame/audio_frame.c +++ b/core/src/ten_runtime/binding/go/native/msg/audio_frame/audio_frame.c @@ -10,26 +10,25 @@ #include "include_internal/ten_runtime/binding/go/internal/common.h" #include "include_internal/ten_runtime/binding/go/msg/msg.h" +#include "include_internal/ten_runtime/msg/audio_frame/audio_frame.h" #include "include_internal/ten_runtime/msg/msg.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/common/errno.h" -#include "ten_runtime/msg/audio_frame/audio_frame.h" #include "ten_runtime/msg/msg.h" #include "ten_utils/lib/error.h" #include "ten_utils/macro/check.h" -ten_go_error_t ten_go_audio_frame_create(const void *msg_name, int msg_name_len, +ten_go_error_t ten_go_audio_frame_create(const void *name, int name_len, uintptr_t *bridge_addr) { TEN_ASSERT(bridge_addr, "Invalid argument."); ten_go_error_t cgo_error; ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); - ten_shared_ptr_t *c_audio_frame = ten_audio_frame_create(); + ten_shared_ptr_t *c_audio_frame = + ten_audio_frame_create_with_name_len(name, name_len, NULL); TEN_ASSERT(c_audio_frame, "Should not happen."); - ten_msg_set_name_with_size(c_audio_frame, msg_name, msg_name_len, NULL); - ten_go_msg_t *bridge = ten_go_msg_create(c_audio_frame); *bridge_addr = (uintptr_t)bridge; diff --git a/core/src/ten_runtime/binding/go/native/msg/cmd/cmd.c b/core/src/ten_runtime/binding/go/native/msg/cmd/cmd.c index 113d485178..045c04dc8e 100644 --- a/core/src/ten_runtime/binding/go/native/msg/cmd/cmd.c +++ b/core/src/ten_runtime/binding/go/native/msg/cmd/cmd.c @@ -23,18 +23,17 @@ ten_go_handle_t tenGoCreateCmdResult(uintptr_t); -ten_go_error_t ten_go_cmd_create_cmd(const void *cmd_name, int cmd_name_len, +ten_go_error_t ten_go_cmd_create_cmd(const void *name, int name_len, uintptr_t *bridge) { - TEN_ASSERT(cmd_name && cmd_name_len > 0, "Should not happen."); + TEN_ASSERT(name && name_len > 0, "Should not happen."); ten_go_error_t cgo_error; ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); - ten_shared_ptr_t *cmd = ten_cmd_custom_create(); + ten_shared_ptr_t *cmd = + ten_cmd_custom_create_with_name_len(name, name_len, NULL); TEN_ASSERT(cmd && ten_cmd_check_integrity(cmd), "Should not happen."); - ten_msg_set_name_with_size(cmd, cmd_name, cmd_name_len, NULL); - ten_go_msg_t *msg_bridge = ten_go_msg_create(cmd); TEN_ASSERT(msg_bridge, "Should not happen."); diff --git a/core/src/ten_runtime/binding/go/native/msg/data/data.c b/core/src/ten_runtime/binding/go/native/msg/data/data.c index 18c8bb6c8d..7fbb3b7291 100644 --- a/core/src/ten_runtime/binding/go/native/msg/data/data.c +++ b/core/src/ten_runtime/binding/go/native/msg/data/data.c @@ -8,6 +8,7 @@ #include "include_internal/ten_runtime/binding/go/internal/common.h" #include "include_internal/ten_runtime/binding/go/msg/msg.h" +#include "include_internal/ten_runtime/msg/data/data.h" #include "include_internal/ten_runtime/msg/msg.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/common/errno.h" @@ -16,18 +17,17 @@ #include "ten_utils/lib/smart_ptr.h" #include "ten_utils/macro/check.h" -ten_go_error_t ten_go_data_create(const void *msg_name, int msg_name_len, +ten_go_error_t ten_go_data_create(const void *name, int name_len, uintptr_t *bridge) { TEN_ASSERT(bridge, "Should not happen."); ten_go_error_t cgo_error; ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); - ten_shared_ptr_t *c_data = ten_data_create(); + ten_shared_ptr_t *c_data = + ten_data_create_with_name_len(name, name_len, NULL); TEN_ASSERT(c_data, "Should not happen."); - ten_msg_set_name_with_size(c_data, msg_name, msg_name_len, NULL); - ten_go_msg_t *data_bridge = ten_go_msg_create(c_data); TEN_ASSERT(data_bridge && ten_go_msg_check_integrity(data_bridge), "Should not happen."); diff --git a/core/src/ten_runtime/binding/go/native/msg/msg.c b/core/src/ten_runtime/binding/go/native/msg/msg.c index 361fe71816..611e8a5a42 100644 --- a/core/src/ten_runtime/binding/go/native/msg/msg.c +++ b/core/src/ten_runtime/binding/go/native/msg/msg.c @@ -103,26 +103,6 @@ int ten_go_msg_get_type(uintptr_t bridge_addr) { return type; } -const char *ten_go_msg_to_json(uintptr_t bridge_addr) { - ten_go_msg_t *msg_bridge = ten_go_msg_reinterpret(bridge_addr); - TEN_ASSERT(msg_bridge && ten_go_msg_check_integrity(msg_bridge), - "Should not happen."); - - ten_json_t *json = ten_msg_to_json(msg_bridge->c_msg, NULL); - if (!json) { - return NULL; - } - - TEN_ASSERT(json, "Failed to get json from TEN C message."); - - bool must_free = false; - const char *json_str = ten_json_to_string(json, NULL, &must_free); - TEN_ASSERT(json_str, "Failed to get JSON string from JSON."); - - ten_json_destroy(json); - return json_str; -} - static ten_value_t *ten_go_msg_property_get_and_check_if_exists( ten_go_msg_t *self, const void *path, ten_go_handle_t path_len, ten_go_error_t *status) { diff --git a/core/src/ten_runtime/binding/go/native/msg/video_frame/video_frame.c b/core/src/ten_runtime/binding/go/native/msg/video_frame/video_frame.c index e3f2679020..47af259d26 100644 --- a/core/src/ten_runtime/binding/go/native/msg/video_frame/video_frame.c +++ b/core/src/ten_runtime/binding/go/native/msg/video_frame/video_frame.c @@ -11,24 +11,24 @@ #include "include_internal/ten_runtime/binding/go/internal/common.h" #include "include_internal/ten_runtime/binding/go/msg/msg.h" #include "include_internal/ten_runtime/msg/msg.h" +#include "include_internal/ten_runtime/msg/video_frame/video_frame.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/common/errno.h" #include "ten_runtime/msg/msg.h" #include "ten_runtime/msg/video_frame/video_frame.h" #include "ten_utils/macro/check.h" -ten_go_error_t ten_go_video_frame_create(const void *msg_name, int msg_name_len, +ten_go_error_t ten_go_video_frame_create(const void *name, int name_len, uintptr_t *bridge_addr) { TEN_ASSERT(bridge_addr, "Invalid argument."); ten_go_error_t cgo_error; ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); - ten_shared_ptr_t *c_video_frame = ten_video_frame_create(); + ten_shared_ptr_t *c_video_frame = + ten_video_frame_create_with_name_len(name, name_len, NULL); TEN_ASSERT(c_video_frame, "Should not happen."); - ten_msg_set_name_with_size(c_video_frame, msg_name, msg_name_len, NULL); - ten_go_msg_t *bridge = ten_go_msg_create(c_video_frame); *bridge_addr = (uintptr_t)bridge; diff --git a/core/src/ten_runtime/binding/python/interface/ten/audio_frame.py b/core/src/ten_runtime/binding/python/interface/ten/audio_frame.py index 9bccdcb2ee..be09226f26 100644 --- a/core/src/ten_runtime/binding/python/interface/ten/audio_frame.py +++ b/core/src/ten_runtime/binding/python/interface/ten/audio_frame.py @@ -4,8 +4,11 @@ # Licensed under the Apache License, Version 2.0, with certain conditions. # Refer to the "LICENSE" file in the root directory for more information. # -from libten_runtime_python import _AudioFrame from enum import IntEnum +from typing import Type, TypeVar +from libten_runtime_python import _AudioFrame + +T = TypeVar("T", bound="AudioFrame") # AudioFrameDataFmt values. These definitions need to be the same as the @@ -23,67 +26,26 @@ def __init__(self): raise NotImplementedError("Use AudioFrame.create instead.") @classmethod - def create(cls, msg_name: str): - instance = cls.__new__(cls) - instance.set_name(msg_name) - return instance - - def alloc_buf(self, size: int) -> None: - return _AudioFrame.alloc_buf(self, size) - - def lock_buf(self) -> memoryview: - return _AudioFrame.lock_buf(self) - - def unlock_buf(self, buf: memoryview) -> None: - return _AudioFrame.unlock_buf(self, buf) - - def get_buf(self) -> bytearray: - return _AudioFrame.get_buf(self) - - def get_timestamp(self) -> int: - return _AudioFrame.get_timestamp(self) - - def set_timestamp(self, timestamp: int) -> None: - return _AudioFrame.set_timestamp(self, timestamp) - - def get_sample_rate(self) -> int: - return _AudioFrame.get_sample_rate(self) - - def set_sample_rate(self, sample_rate: int) -> None: - return _AudioFrame.set_sample_rate(self, sample_rate) - - def get_samples_per_channel(self) -> int: - return _AudioFrame.get_samples_per_channel(self) - - def set_samples_per_channel(self, samples_per_channel: int) -> None: - return _AudioFrame.set_samples_per_channel(self, samples_per_channel) - - def get_bytes_per_sample(self) -> int: - return _AudioFrame.get_bytes_per_sample(self) - - def set_bytes_per_sample(self, bytes_per_sample: int) -> None: - return _AudioFrame.set_bytes_per_sample(self, bytes_per_sample) - - def get_number_of_channels(self) -> int: - return _AudioFrame.get_number_of_channels(self) - - def set_number_of_channels(self, number_of_channels: int) -> None: - return _AudioFrame.set_number_of_channels(self, number_of_channels) - - def get_data_fmt(self) -> AudioFrameDataFmt: - return AudioFrameDataFmt(_AudioFrame.get_data_fmt(self)) - - def set_data_fmt(self, data_fmt: AudioFrameDataFmt) -> None: - return _AudioFrame.set_data_fmt(self, data_fmt.value) - - def get_line_size(self) -> int: - return _AudioFrame.get_line_size(self) - - def set_line_size(self, line_size: int) -> None: - return _AudioFrame.set_line_size(self, line_size) - - def is_eof(self) -> bool: - return _AudioFrame.is_eof(self) - - def set_eof(self, is_eof: bool) -> None: - return _AudioFrame.set_eof(self, is_eof) + def create(cls: Type[T], name: str) -> T: + return cls.__new__(cls, name) + + alloc_buf = _AudioFrame.alloc_buf + lock_buf = _AudioFrame.lock_buf + unlock_buf = _AudioFrame.unlock_buf + get_buf = _AudioFrame.get_buf + get_timestamp = _AudioFrame.get_timestamp + set_timestamp = _AudioFrame.set_timestamp + get_sample_rate = _AudioFrame.get_sample_rate + set_sample_rate = _AudioFrame.set_sample_rate + get_samples_per_channel = _AudioFrame.get_samples_per_channel + set_samples_per_channel = _AudioFrame.set_samples_per_channel + get_bytes_per_sample = _AudioFrame.get_bytes_per_sample + set_bytes_per_sample = _AudioFrame.set_bytes_per_sample + get_number_of_channels = _AudioFrame.get_number_of_channels + set_number_of_channels = _AudioFrame.set_number_of_channels + get_data_fmt = _AudioFrame.get_data_fmt + set_data_fmt = _AudioFrame.set_data_fmt + get_line_size = _AudioFrame.get_line_size + set_line_size = _AudioFrame.set_line_size + is_eof = _AudioFrame.is_eof + set_eof = _AudioFrame.set_eof diff --git a/core/src/ten_runtime/binding/python/interface/ten/cmd.py b/core/src/ten_runtime/binding/python/interface/ten/cmd.py index d941d2b891..5ee6b87686 100644 --- a/core/src/ten_runtime/binding/python/interface/ten/cmd.py +++ b/core/src/ten_runtime/binding/python/interface/ten/cmd.py @@ -4,16 +4,16 @@ # Licensed under the Apache License, Version 2.0, with certain conditions. # Refer to the "LICENSE" file in the root directory for more information. # +from typing import Type, TypeVar from libten_runtime_python import _Cmd +T = TypeVar("T", bound="Cmd") -class Cmd(_Cmd): - def __new__(cls, name: str): - return super().__new__(cls, name) +class Cmd(_Cmd): def __init__(self): raise NotImplementedError("Use Cmd.create instead.") @classmethod - def create(cls, name: str): + def create(cls: Type[T], name: str) -> T: return cls.__new__(cls, name) diff --git a/core/src/ten_runtime/binding/python/interface/ten/data.py b/core/src/ten_runtime/binding/python/interface/ten/data.py index 7876360dd7..0274e2fc41 100644 --- a/core/src/ten_runtime/binding/python/interface/ten/data.py +++ b/core/src/ten_runtime/binding/python/interface/ten/data.py @@ -4,27 +4,21 @@ # Licensed under the Apache License, Version 2.0, with certain conditions. # Refer to the "LICENSE" file in the root directory for more information. # +from typing import Type, TypeVar from libten_runtime_python import _Data +T = TypeVar("T", bound="Data") + class Data(_Data): def __init__(self): raise NotImplementedError("Use Data.create instead.") @classmethod - def create(cls, msg_name: str): - instance = cls.__new__(cls) - instance.set_name(msg_name) - return instance - - def alloc_buf(self, size: int) -> None: - return _Data.alloc_buf(self, size) - - def lock_buf(self) -> memoryview: - return _Data.lock_buf(self) - - def unlock_buf(self, buf: memoryview) -> None: - return _Data.unlock_buf(self, buf) + def create(cls: Type[T], name: str) -> T: + return cls.__new__(cls, name) - def get_buf(self) -> bytearray: - return _Data.get_buf(self) + alloc_buf = _Data.alloc_buf + lock_buf = _Data.lock_buf + unlock_buf = _Data.unlock_buf + get_buf = _Data.get_buf diff --git a/core/src/ten_runtime/binding/python/interface/ten/libten_runtime_python.pyi b/core/src/ten_runtime/binding/python/interface/ten/libten_runtime_python.pyi index 2d4a2903f6..7cc470eddb 100644 --- a/core/src/ten_runtime/binding/python/interface/ten/libten_runtime_python.pyi +++ b/core/src/ten_runtime/binding/python/interface/ten/libten_runtime_python.pyi @@ -18,8 +18,6 @@ class _TenError: def err_msg(self) -> str: ... class _Msg: - def to_json(self) -> str: ... - def from_json(self, json_str: str): ... def get_name(self) -> str: ... def set_name(self, name: str) -> None: ... def set_dest( @@ -29,8 +27,8 @@ class _Msg: extension_group: str | None, extension: str | None, ) -> None: ... - def set_property_from_json(self, key: str, json_str: str) -> None: ... - def get_property_to_json(self, key: str) -> str: ... + def set_property_from_json(self, path: str, json: str) -> None: ... + def get_property_to_json(self, path: str | None = None) -> str: ... def get_property_int(self, path: str) -> int: ... def set_property_int(self, path: str, value: int) -> None: ... def get_property_string(self, path: str) -> str: ... @@ -53,12 +51,14 @@ class _CmdResult(_Msg): def is_completed(self) -> bool: ... class _Data(_Msg): + def __new__(cls, name: str): ... def alloc_buf(self, size: int) -> None: ... def lock_buf(self) -> memoryview: ... def unlock_buf(self, buf: memoryview) -> None: ... def get_buf(self) -> bytearray: ... class _VideoFrame(_Msg): + def __new__(cls, name: str): ... def alloc_buf(self, size: int) -> None: ... def lock_buf(self) -> memoryview: ... def unlock_buf(self, buf: memoryview) -> None: ... @@ -75,6 +75,7 @@ class _VideoFrame(_Msg): def set_eof(self, eof: bool) -> None: ... class _AudioFrame(_Msg): + def __new__(cls, name: str): ... def alloc_buf(self, size: int) -> None: ... def lock_buf(self) -> memoryview: ... def unlock_buf(self, buf: memoryview) -> None: ... diff --git a/core/src/ten_runtime/binding/python/interface/ten/msg.py b/core/src/ten_runtime/binding/python/interface/ten/msg.py deleted file mode 100644 index 743ecbf470..0000000000 --- a/core/src/ten_runtime/binding/python/interface/ten/msg.py +++ /dev/null @@ -1,65 +0,0 @@ -# -# Copyright © 2024 Agora -# This file is part of TEN Framework, an open source project. -# Licensed under the Apache License, Version 2.0, with certain conditions. -# Refer to the "LICENSE" file in the root directory for more information. -# -from libten_runtime_python import _Msg - - -class Msg(_Msg): - def to_json(self) -> str: - return _Msg.to_json(self) - - def from_json(self, json_str: str): - return _Msg.from_json(self, json_str) - - def get_name(self) -> str: - return _Msg.get_name(self) - - def set_dest( - self, - app_uri: str | None, - graph_id: str | None, - extension_group: str | None, - extension: str | None, - ) -> None: - return _Msg.set_dest( - self, app_uri, graph_id, extension_group, extension - ) - - def set_property_from_json(self, key: str, json: str) -> None: - return _Msg.set_property_from_json(self, key, json) - - def get_property_to_json(self, key: str) -> str: - return _Msg.get_property_to_json(self, key) - - def set_property_string(self, key: str, value: str) -> None: - return _Msg.set_property_string(self, key, value) - - def get_property_string(self, key: str) -> str: - return _Msg.get_property_string(self, key) - - def get_property_int(self, key: str) -> int: - return _Msg.get_property_int(self, key) - - def set_property_int(self, key: str, value: int) -> None: - return _Msg.set_property_int(self, key, value) - - def get_property_bool(self, key: str) -> bool: - return _Msg.get_property_bool(self, key) - - def set_property_bool(self, key: str, value: bool) -> None: - return _Msg.set_property_bool(self, key, value) - - def get_property_float(self, path: str) -> float: - return _Msg.get_property_float(self, path) - - def set_property_float(self, path: str, value: float) -> None: - return _Msg.set_property_float(self, path, value) - - def get_property_buf(self, path: str) -> bytearray: - return _Msg.get_property_buf(self, path) - - def set_property_buf(self, path: str, value: bytes) -> None: - return _Msg.set_property_buf(self, path, value) diff --git a/core/src/ten_runtime/binding/python/interface/ten/video_frame.py b/core/src/ten_runtime/binding/python/interface/ten/video_frame.py index 7b032bda51..92620db57d 100644 --- a/core/src/ten_runtime/binding/python/interface/ten/video_frame.py +++ b/core/src/ten_runtime/binding/python/interface/ten/video_frame.py @@ -4,8 +4,11 @@ # Licensed under the Apache License, Version 2.0, with certain conditions. # Refer to the "LICENSE" file in the root directory for more information. # -from libten_runtime_python import _VideoFrame from enum import IntEnum +from typing import Type, TypeVar +from libten_runtime_python import _VideoFrame + +T = TypeVar("T", bound="VideoFrame") # PixelFmt values. These definitions need to be the same as the PixelFmt @@ -29,49 +32,20 @@ def __init__(self): raise NotImplementedError("Use VideoFrame.create instead.") @classmethod - def create(cls, msg_name: str): - instance = cls.__new__(cls) - instance.set_name(msg_name) - return instance - - def alloc_buf(self, size: int) -> None: - return _VideoFrame.alloc_buf(self, size) - - def lock_buf(self) -> memoryview: - return _VideoFrame.lock_buf(self) - - def unlock_buf(self, buf: memoryview) -> None: - return _VideoFrame.unlock_buf(self, buf) - - def get_buf(self) -> bytearray: - return _VideoFrame.get_buf(self) - - def get_width(self) -> int: - return _VideoFrame.get_width(self) - - def set_width(self, width: int) -> None: - return _VideoFrame.set_width(self, width) - - def get_height(self) -> int: - return _VideoFrame.get_height(self) - - def set_height(self, height: int) -> None: - return _VideoFrame.set_height(self, height) - - def get_timestamp(self) -> int: - return _VideoFrame.get_timestamp(self) - - def set_timestamp(self, timestamp: int) -> None: - return _VideoFrame.set_timestamp(self, timestamp) - - def get_pixel_fmt(self) -> PixelFmt: - return PixelFmt(_VideoFrame.get_pixel_fmt(self)) - - def set_pixel_fmt(self, pixel_fmt: PixelFmt) -> None: - return _VideoFrame.set_pixel_fmt(self, pixel_fmt.value) - - def is_eof(self) -> bool: - return _VideoFrame.is_eof(self) - - def set_eof(self, eof: bool) -> None: - return _VideoFrame.set_eof(self, eof) + def create(cls: Type[T], name: str) -> T: + return cls.__new__(cls, name) + + alloc_buf = _VideoFrame.alloc_buf + lock_buf = _VideoFrame.lock_buf + unlock_buf = _VideoFrame.unlock_buf + get_buf = _VideoFrame.get_buf + get_width = _VideoFrame.get_width + set_width = _VideoFrame.set_width + get_height = _VideoFrame.get_height + set_height = _VideoFrame.set_height + get_timestamp = _VideoFrame.get_timestamp + set_timestamp = _VideoFrame.set_timestamp + get_pixel_fmt = _VideoFrame.get_pixel_fmt + set_pixel_fmt = _VideoFrame.set_pixel_fmt + is_eof = _VideoFrame.is_eof + set_eof = _VideoFrame.set_eof diff --git a/core/src/ten_runtime/binding/python/native/msg/audio_frame.c b/core/src/ten_runtime/binding/python/native/msg/audio_frame.c index d75b53aa3f..205ce835b1 100644 --- a/core/src/ten_runtime/binding/python/native/msg/audio_frame.c +++ b/core/src/ten_runtime/binding/python/native/msg/audio_frame.c @@ -32,23 +32,25 @@ static ten_py_audio_frame_t *ten_py_audio_frame_create_internal( } static ten_py_audio_frame_t *ten_py_audio_frame_init( - ten_py_audio_frame_t *py_audio_frame, TEN_UNUSED PyObject *args, - TEN_UNUSED PyObject *kw) { + ten_py_audio_frame_t *py_audio_frame, const char *name) { TEN_ASSERT(py_audio_frame && ten_py_msg_check_integrity((ten_py_msg_t *)py_audio_frame), "Invalid argument."); - py_audio_frame->msg.c_msg = - ten_msg_create_from_msg_type(TEN_MSG_TYPE_AUDIO_FRAME); + py_audio_frame->msg.c_msg = ten_audio_frame_create(name, NULL); return py_audio_frame; } -PyObject *ten_py_audio_frame_create(PyTypeObject *type, - TEN_UNUSED PyObject *args, +PyObject *ten_py_audio_frame_create(PyTypeObject *type, PyObject *args, TEN_UNUSED PyObject *kwds) { + const char *name = NULL; + if (!PyArg_ParseTuple(args, "s", &name)) { + return ten_py_raise_py_value_error_exception("Failed to parse arguments."); + } + ten_py_audio_frame_t *audio_frame = ten_py_audio_frame_create_internal(type); - return (PyObject *)ten_py_audio_frame_init(audio_frame, args, kwds); + return (PyObject *)ten_py_audio_frame_init(audio_frame, name); } void ten_py_audio_frame_destroy(PyObject *self) { diff --git a/core/src/ten_runtime/binding/python/native/msg/cmd.c b/core/src/ten_runtime/binding/python/native/msg/cmd.c index 4a68943a87..a98c910c2c 100644 --- a/core/src/ten_runtime/binding/python/native/msg/cmd.c +++ b/core/src/ten_runtime/binding/python/native/msg/cmd.c @@ -11,6 +11,7 @@ #include "include_internal/ten_runtime/msg/msg.h" #include "ten_runtime/msg/cmd/cmd.h" #include "ten_utils/lib/smart_ptr.h" +#include "ten_utils/macro/mark.h" static ten_py_cmd_t *ten_py_cmd_create_internal(PyTypeObject *py_type) { if (!py_type) { @@ -43,7 +44,8 @@ static ten_py_cmd_t *ten_py_cmd_init(ten_py_cmd_t *py_cmd, const char *name) { return py_cmd; } -PyObject *ten_py_cmd_create(PyTypeObject *type, PyObject *args, PyObject *kw) { +PyObject *ten_py_cmd_create(PyTypeObject *type, PyObject *args, + TEN_UNUSED PyObject *kw) { const char *name = NULL; if (!PyArg_ParseTuple(args, "s", &name)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); diff --git a/core/src/ten_runtime/binding/python/native/msg/data.c b/core/src/ten_runtime/binding/python/native/msg/data.c index 36ef6f4abb..2d3eaa1e77 100644 --- a/core/src/ten_runtime/binding/python/native/msg/data.c +++ b/core/src/ten_runtime/binding/python/native/msg/data.c @@ -9,11 +9,11 @@ #include "include_internal/ten_runtime/binding/python/common/error.h" #include "include_internal/ten_runtime/binding/python/msg/msg.h" #include "include_internal/ten_runtime/msg/msg.h" -#include "ten_utils/macro/check.h" #include "pyport.h" #include "ten_runtime/msg/data/data.h" #include "ten_runtime/msg/msg.h" #include "ten_utils/lib/buf.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" static ten_py_data_t *ten_py_data_create_internal(PyTypeObject *py_type) { @@ -30,20 +30,24 @@ static ten_py_data_t *ten_py_data_create_internal(PyTypeObject *py_type) { } static ten_py_data_t *ten_py_data_init(ten_py_data_t *py_data, - TEN_UNUSED PyObject *args, - TEN_UNUSED PyObject *kw) { + const char *name) { TEN_ASSERT(py_data && ten_py_msg_check_integrity((ten_py_msg_t *)py_data), "Invalid argument."); - py_data->msg.c_msg = ten_msg_create_from_msg_type(TEN_MSG_TYPE_DATA); + py_data->msg.c_msg = ten_data_create(name, NULL); return py_data; } -PyObject *ten_py_data_create(PyTypeObject *type, TEN_UNUSED PyObject *args, +PyObject *ten_py_data_create(PyTypeObject *type, PyObject *args, TEN_UNUSED PyObject *kwds) { + const char *name = NULL; + if (!PyArg_ParseTuple(args, "s", &name)) { + return ten_py_raise_py_value_error_exception("Failed to parse arguments."); + } + ten_py_data_t *py_data = ten_py_data_create_internal(type); - return (PyObject *)ten_py_data_init(py_data, args, kwds); + return (PyObject *)ten_py_data_init(py_data, name); } void ten_py_data_destroy(PyObject *self) { diff --git a/core/src/ten_runtime/binding/python/native/msg/msg.c b/core/src/ten_runtime/binding/python/native/msg/msg.c index b8dddbb626..54216433ba 100644 --- a/core/src/ten_runtime/binding/python/native/msg/msg.c +++ b/core/src/ten_runtime/binding/python/native/msg/msg.c @@ -47,81 +47,6 @@ ten_shared_ptr_t *ten_py_msg_move_c_msg(ten_py_msg_t *self) { return c_msg; } -PyObject *ten_py_msg_to_json(PyObject *self, TEN_UNUSED PyObject *args) { - ten_py_msg_t *py_msg = (ten_py_msg_t *)self; - - TEN_ASSERT(py_msg && ten_py_msg_check_integrity(py_msg), "Invalid argument."); - - ten_shared_ptr_t *c_msg = py_msg->c_msg; - if (!c_msg) { - TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); - } - - ten_json_t *msg_json = ten_msg_to_json(c_msg, NULL); - - bool must_free = true; - const char *json_string = ten_json_to_string(msg_json, NULL, &must_free); - PyObject *res = Py_BuildValue("s", json_string); - if (must_free) { - TEN_FREE(json_string); - } - - ten_json_destroy(msg_json); - - return res; -} - -PyObject *ten_py_msg_from_json(PyObject *self, PyObject *args) { - ten_py_msg_t *py_msg = (ten_py_msg_t *)self; - - TEN_ASSERT(py_msg && ten_py_msg_check_integrity(py_msg), "Invalid argument."); - - ten_shared_ptr_t *c_msg = py_msg->c_msg; - if (!c_msg) { - TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); - } - - bool success = true; - - ten_error_t err; - ten_error_init(&err); - - if (PyTuple_GET_SIZE(args) != 1) { - ten_py_raise_py_value_error_exception("from_json requires 1 args."); - - success = false; - goto done; - } - - char *json_str = NULL; - if (!PyArg_ParseTuple(args, "s", &json_str)) { - success = false; - goto done; - } - - ten_json_t *c_json = ten_json_from_string(json_str, &err); - if (!c_json) { - ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); - - success = false; - goto done; - } - - success = ten_msg_from_json(c_msg, c_json, &err); - ten_json_destroy(c_json); - -done: - ten_error_deinit(&err); - - if (success) { - Py_RETURN_NONE; - } else { - return NULL; - } -} - PyObject *ten_py_msg_get_name(PyObject *self, TEN_UNUSED PyObject *args) { ten_py_msg_t *py_msg = (ten_py_msg_t *)self; @@ -130,7 +55,7 @@ PyObject *ten_py_msg_get_name(PyObject *self, TEN_UNUSED PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } const char *name = ten_msg_get_name(c_msg); @@ -148,7 +73,7 @@ PyObject *ten_py_msg_set_name(PyObject *self, TEN_UNUSED PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } const char *name = NULL; @@ -226,20 +151,20 @@ PyObject *ten_py_msg_set_property_string(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; const char *value = NULL; - if (!PyArg_ParseTuple(args, "ss", &key, &value)) { + if (!PyArg_ParseTuple(args, "ss", &path, &value)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key || !value) { + if (!path || !value) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -248,7 +173,7 @@ PyObject *ten_py_msg_set_property_string(PyObject *self, PyObject *args) { ten_value_t *c_value = ten_value_create_string(value); - bool rc = ten_msg_set_property(c_msg, key, c_value, &err); + bool rc = ten_msg_set_property(c_msg, path, c_value, &err); if (!rc) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); } @@ -270,26 +195,26 @@ PyObject *ten_py_msg_get_property_string(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; - if (!PyArg_ParseTuple(args, "s", &key)) { + if (!PyArg_ParseTuple(args, "s", &path)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key) { + if (!path) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); return NULL; } - ten_value_t *c_value = ten_msg_peek_property(c_msg, key, &err); + ten_value_t *c_value = ten_msg_peek_property(c_msg, path, &err); if (!c_value) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -318,26 +243,19 @@ PyObject *ten_py_msg_set_property_from_json(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; const char *json_str = NULL; - if (!PyArg_ParseTuple(args, "ss", &key, &json_str)) { + if (!PyArg_ParseTuple(args, "zs", &path, &json_str)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key || !json_str) { - ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); - ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); - ten_error_deinit(&err); - return NULL; - } - ten_json_t *c_json = ten_json_from_string(json_str, &err); if (!c_json) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); @@ -347,7 +265,7 @@ PyObject *ten_py_msg_set_property_from_json(PyObject *self, PyObject *args) { ten_value_t *value = ten_value_from_json(c_json); - bool rc = ten_msg_set_property(c_msg, key, value, &err); + bool rc = ten_msg_set_property(c_msg, path, value, &err); if (!rc) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_value_destroy(value); @@ -372,26 +290,24 @@ PyObject *ten_py_msg_get_property_to_json(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; - - if (!PyArg_ParseTuple(args, "s", &key)) { - return ten_py_raise_py_value_error_exception("Failed to parse arguments."); + const char *path = NULL; + if (PyTuple_GET_SIZE(args) == 1) { + if (!PyArg_ParseTuple(args, "z", &path)) { + return ten_py_raise_py_value_error_exception( + "Failed to parse arguments."); + } + } else if (PyTuple_GET_SIZE(args) != 0) { + return ten_py_raise_py_value_error_exception( + "Invalid argument count when msg.get_property_to_json."); } ten_error_t err; ten_error_init(&err); - if (!key) { - ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); - ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); - ten_error_deinit(&err); - return NULL; - } - - ten_value_t *c_value = ten_msg_peek_property(c_msg, key, &err); + ten_value_t *c_value = ten_msg_peek_property(c_msg, path, &err); if (!c_value) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -420,26 +336,26 @@ PyObject *ten_py_msg_get_property_int(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; - if (!PyArg_ParseTuple(args, "s", &key)) { + if (!PyArg_ParseTuple(args, "s", &path)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key) { + if (!path) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); return NULL; } - ten_value_t *c_value = ten_msg_peek_property(c_msg, key, &err); + ten_value_t *c_value = ten_msg_peek_property(c_msg, path, &err); if (!c_value) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -466,20 +382,20 @@ PyObject *ten_py_msg_set_property_int(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; int64_t value = 0; - if (!PyArg_ParseTuple(args, "sl", &key, &value)) { + if (!PyArg_ParseTuple(args, "sl", &path, &value)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key) { + if (!path) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -488,7 +404,7 @@ PyObject *ten_py_msg_set_property_int(PyObject *self, PyObject *args) { ten_value_t *c_value = ten_value_create_int64(value); - bool rc = ten_msg_set_property(c_msg, key, c_value, &err); + bool rc = ten_msg_set_property(c_msg, path, c_value, &err); if (!rc) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); } @@ -510,26 +426,26 @@ PyObject *ten_py_msg_get_property_bool(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; - if (!PyArg_ParseTuple(args, "s", &key)) { + if (!PyArg_ParseTuple(args, "s", &path)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key) { + if (!path) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); return NULL; } - ten_value_t *c_value = ten_msg_peek_property(c_msg, key, &err); + ten_value_t *c_value = ten_msg_peek_property(c_msg, path, &err); if (!c_value) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -554,20 +470,20 @@ PyObject *ten_py_msg_set_property_bool(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; int value = 0; - if (!PyArg_ParseTuple(args, "si", &key, &value)) { + if (!PyArg_ParseTuple(args, "si", &path, &value)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key) { + if (!path) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -576,7 +492,7 @@ PyObject *ten_py_msg_set_property_bool(PyObject *self, PyObject *args) { ten_value_t *c_value = ten_value_create_bool(value > 0); - bool rc = ten_msg_set_property(c_msg, key, c_value, &err); + bool rc = ten_msg_set_property(c_msg, path, c_value, &err); if (!rc) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); } @@ -598,26 +514,26 @@ PyObject *ten_py_msg_get_property_float(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; - if (!PyArg_ParseTuple(args, "s", &key)) { + if (!PyArg_ParseTuple(args, "s", &path)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key) { + if (!path) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); return NULL; } - ten_value_t *c_value = ten_msg_peek_property(c_msg, key, &err); + ten_value_t *c_value = ten_msg_peek_property(c_msg, path, &err); if (!c_value) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -644,20 +560,20 @@ PyObject *ten_py_msg_set_property_float(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; double value = 0.0; - if (!PyArg_ParseTuple(args, "sd", &key, &value)) { + if (!PyArg_ParseTuple(args, "sd", &path, &value)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key) { + if (!path) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -666,7 +582,7 @@ PyObject *ten_py_msg_set_property_float(PyObject *self, PyObject *args) { ten_value_t *c_value = ten_value_create_float64(value); - bool rc = ten_msg_set_property(c_msg, key, c_value, &err); + bool rc = ten_msg_set_property(c_msg, path, c_value, &err); if (!rc) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); } @@ -687,26 +603,26 @@ PyObject *ten_py_msg_get_property_buf(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; - if (!PyArg_ParseTuple(args, "s", &key)) { + if (!PyArg_ParseTuple(args, "s", &path)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } ten_error_t err; ten_error_init(&err); - if (!key) { + if (!path) { ten_error_set(&err, TEN_ERRNO_INVALID_ARGUMENT, "Invalid argument."); ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); return NULL; } - ten_value_t *c_value = ten_msg_peek_property(c_msg, key, &err); + ten_value_t *c_value = ten_msg_peek_property(c_msg, path, &err); if (!c_value) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_error_deinit(&err); @@ -735,13 +651,13 @@ PyObject *ten_py_msg_set_property_buf(PyObject *self, PyObject *args) { ten_shared_ptr_t *c_msg = py_msg->c_msg; if (!c_msg) { TEN_ASSERT(0, "Should not happen."); - return ten_py_raise_py_value_error_exception("Cmd is invalidated."); + return ten_py_raise_py_value_error_exception("Msg is invalidated."); } - const char *key = NULL; + const char *path = NULL; Py_buffer py_buf; - if (!PyArg_ParseTuple(args, "sy*", &key, &py_buf)) { + if (!PyArg_ParseTuple(args, "sy*", &path, &py_buf)) { return ten_py_raise_py_value_error_exception("Failed to parse arguments."); } @@ -768,7 +684,7 @@ PyObject *ten_py_msg_set_property_buf(PyObject *self, PyObject *args) { TEN_ASSERT(c_value && ten_value_check_integrity(c_value), "Failed to create value."); - bool rc = ten_msg_set_property(c_msg, key, c_value, &err); + bool rc = ten_msg_set_property(c_msg, path, c_value, &err); if (!rc) { ten_py_raise_py_value_error_exception(ten_error_errmsg(&err)); ten_value_destroy(c_value); diff --git a/core/src/ten_runtime/binding/python/native/msg/type.c b/core/src/ten_runtime/binding/python/native/msg/type.c index 17310b8803..04ab6fabca 100644 --- a/core/src/ten_runtime/binding/python/native/msg/type.c +++ b/core/src/ten_runtime/binding/python/native/msg/type.c @@ -14,17 +14,15 @@ #include "include_internal/ten_runtime/binding/python/msg/video_frame.h" static PyMethodDef ten_py_msg_type_methods[] = { - {"to_json", ten_py_msg_to_json, METH_VARARGS, NULL}, - {"from_json", ten_py_msg_from_json, METH_VARARGS, NULL}, {"get_name", ten_py_msg_get_name, METH_VARARGS, NULL}, {"set_name", ten_py_msg_set_name, METH_VARARGS, NULL}, {"set_dest", ten_py_msg_set_dest, METH_VARARGS, NULL}, - {"get_property_string", ten_py_msg_get_property_string, METH_VARARGS, NULL}, - {"set_property_string", ten_py_msg_set_property_string, METH_VARARGS, NULL}, {"get_property_to_json", ten_py_msg_get_property_to_json, METH_VARARGS, NULL}, {"set_property_from_json", ten_py_msg_set_property_from_json, METH_VARARGS, NULL}, + {"get_property_string", ten_py_msg_get_property_string, METH_VARARGS, NULL}, + {"set_property_string", ten_py_msg_set_property_string, METH_VARARGS, NULL}, {"get_property_int", ten_py_msg_get_property_int, METH_VARARGS, NULL}, {"set_property_int", ten_py_msg_set_property_int, METH_VARARGS, NULL}, {"get_property_float", ten_py_msg_get_property_float, METH_VARARGS, NULL}, diff --git a/core/src/ten_runtime/binding/python/native/msg/video_frame.c b/core/src/ten_runtime/binding/python/native/msg/video_frame.c index 4d220d9db8..54de47b35a 100644 --- a/core/src/ten_runtime/binding/python/native/msg/video_frame.c +++ b/core/src/ten_runtime/binding/python/native/msg/video_frame.c @@ -30,24 +30,26 @@ static ten_py_video_frame_t *ten_py_video_frame_create_internal( } static ten_py_video_frame_t *ten_py_video_frame_init( - ten_py_video_frame_t *py_video_frame, TEN_UNUSED PyObject *args, - TEN_UNUSED PyObject *kw) { + ten_py_video_frame_t *py_video_frame, const char *name) { TEN_ASSERT(py_video_frame && ten_py_msg_check_integrity((ten_py_msg_t *)py_video_frame), "Invalid argument."); - py_video_frame->msg.c_msg = - ten_msg_create_from_msg_type(TEN_MSG_TYPE_VIDEO_FRAME); + py_video_frame->msg.c_msg = ten_video_frame_create(name, NULL); return py_video_frame; } -PyObject *ten_py_video_frame_create(PyTypeObject *type, - TEN_UNUSED PyObject *args, +PyObject *ten_py_video_frame_create(PyTypeObject *type, PyObject *args, TEN_UNUSED PyObject *kwds) { + const char *name = NULL; + if (!PyArg_ParseTuple(args, "s", &name)) { + return ten_py_raise_py_value_error_exception("Failed to parse arguments."); + } + ten_py_video_frame_t *py_video_frame = ten_py_video_frame_create_internal(type); - return (PyObject *)ten_py_video_frame_init(py_video_frame, args, kwds); + return (PyObject *)ten_py_video_frame_init(py_video_frame, name); } void ten_py_video_frame_destroy(PyObject *self) { diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_video_frame.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_video_frame.c index 1268e7f3b8..97eb8d61c0 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_video_frame.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_send_video_frame.c @@ -112,8 +112,7 @@ static void ten_env_proxy_notify_send_video_frame(ten_env_t *ten_env, if (!res) { TEN_LOGE( "Failed to send video_frame, but no callback function is provided. " - "errno: " - "%s, err_msg: %s", + "errno: %d, err_msg: %s", ten_error_errno(&err), ten_error_errmsg(&err)); } } else { diff --git a/core/src/ten_runtime/msg/audio_frame/pcm_frame.c b/core/src/ten_runtime/msg/audio_frame/pcm_frame.c index f59a8ab7af..f324e57567 100644 --- a/core/src/ten_runtime/msg/audio_frame/pcm_frame.c +++ b/core/src/ten_runtime/msg/audio_frame/pcm_frame.c @@ -169,7 +169,7 @@ static void ten_raw_audio_frame_init(ten_audio_frame_t *self) { ten_value_init_bool(&self->is_eof, false); } -static ten_audio_frame_t *ten_raw_audio_frame_create(void) { +static ten_audio_frame_t *ten_raw_audio_frame_create_empty(void) { ten_audio_frame_t *self = TEN_MALLOC(sizeof(ten_audio_frame_t)); TEN_ASSERT(self, "Failed to allocate memory."); @@ -178,10 +178,38 @@ static ten_audio_frame_t *ten_raw_audio_frame_create(void) { return self; } -ten_shared_ptr_t *ten_audio_frame_create(void) { - ten_audio_frame_t *self = ten_raw_audio_frame_create(); +static ten_audio_frame_t *ten_raw_audio_frame_create(const char *name, + ten_error_t *err) { + ten_audio_frame_t *self = ten_raw_audio_frame_create_empty(); + ten_raw_msg_set_name((ten_msg_t *)self, name, err); - return ten_shared_ptr_create(self, ten_raw_audio_frame_destroy); + return self; +} + +static ten_audio_frame_t *ten_raw_audio_frame_create_with_len( + const char *name, size_t name_len, ten_error_t *err) { + ten_audio_frame_t *self = ten_raw_audio_frame_create_empty(); + ten_raw_msg_set_name_with_len((ten_msg_t *)self, name, name_len, err); + + return self; +} + +ten_shared_ptr_t *ten_audio_frame_create_empty(void) { + return ten_shared_ptr_create(ten_raw_audio_frame_create_empty(), + ten_raw_audio_frame_destroy); +} + +ten_shared_ptr_t *ten_audio_frame_create(const char *name, ten_error_t *err) { + return ten_shared_ptr_create(ten_raw_audio_frame_create(name, err), + ten_raw_audio_frame_destroy); +} + +ten_shared_ptr_t *ten_audio_frame_create_with_name_len(const char *name, + size_t name_len, + ten_error_t *err) { + return ten_shared_ptr_create( + ten_raw_audio_frame_create_with_len(name, name_len, err), + ten_raw_audio_frame_destroy); } void ten_raw_audio_frame_destroy(ten_audio_frame_t *self) { diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/cmd.c index 652732b394..32ae3bdb24 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/cmd.c @@ -166,8 +166,8 @@ static TEN_MSG_TYPE ten_cmd_type_from_name_string(const char *name_str) { } } -static ten_cmd_t *ten_raw_cmd_create(const char *cmd_name, ten_error_t *err) { - if (!cmd_name) { +static ten_cmd_t *ten_raw_cmd_create(const char *name, ten_error_t *err) { + if (!name) { if (err) { ten_error_set(err, TEN_ERRNO_GENERIC, "Failed to create cmd without a name."); @@ -175,11 +175,11 @@ static ten_cmd_t *ten_raw_cmd_create(const char *cmd_name, ten_error_t *err) { return NULL; } - TEN_MSG_TYPE cmd_type = ten_cmd_type_from_name_string(cmd_name); + TEN_MSG_TYPE cmd_type = ten_cmd_type_from_name_string(name); switch (cmd_type) { case TEN_MSG_TYPE_CMD: - return ten_raw_cmd_custom_create(cmd_name); + return ten_raw_cmd_custom_create(name, err); case TEN_MSG_TYPE_CMD_STOP_GRAPH: return (ten_cmd_t *)ten_raw_cmd_stop_graph_create(); case TEN_MSG_TYPE_CMD_CLOSE_APP: @@ -195,8 +195,8 @@ static ten_cmd_t *ten_raw_cmd_create(const char *cmd_name, ten_error_t *err) { } } -ten_shared_ptr_t *ten_cmd_create(const char *cmd_name, ten_error_t *err) { - ten_cmd_t *cmd = ten_raw_cmd_create(cmd_name, err); +ten_shared_ptr_t *ten_cmd_create(const char *name, ten_error_t *err) { + ten_cmd_t *cmd = ten_raw_cmd_create(name, err); if (!cmd) { return NULL; } diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/custom/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/custom/cmd.c index 92061f4c23..5c1ba7010a 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/custom/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/custom/cmd.c @@ -51,22 +51,50 @@ static ten_cmd_t *ten_raw_cmd_custom_create_empty(void) { return raw_cmd; } -ten_shared_ptr_t *ten_cmd_custom_create(void) { +ten_shared_ptr_t *ten_cmd_custom_create_empty(void) { return ten_shared_ptr_create(ten_raw_cmd_custom_create_empty(), ten_raw_cmd_custom_destroy); } -ten_cmd_t *ten_raw_cmd_custom_create(const char *cmd_name) { - TEN_ASSERT(cmd_name, "Should not happen."); +ten_cmd_t *ten_raw_cmd_custom_create(const char *name, ten_error_t *err) { + TEN_ASSERT(name, "Should not happen."); ten_cmd_t *cmd = ten_raw_cmd_custom_create_empty(); TEN_ASSERT(cmd && ten_raw_cmd_check_integrity(cmd), "Should not happen."); - ten_raw_msg_set_name((ten_msg_t *)cmd, cmd_name, NULL); + ten_raw_msg_set_name((ten_msg_t *)cmd, name, err); return cmd; } +static ten_cmd_t *ten_raw_cmd_custom_create_with_name_len(const char *name, + size_t name_len, + ten_error_t *err) { + TEN_ASSERT(name, "Should not happen."); + + ten_cmd_t *cmd = ten_raw_cmd_custom_create_empty(); + TEN_ASSERT(cmd && ten_raw_cmd_check_integrity(cmd), "Should not happen."); + + ten_raw_msg_set_name_with_len((ten_msg_t *)cmd, name, name_len, err); + + return cmd; +} + +ten_shared_ptr_t *ten_cmd_custom_create(const char *name, ten_error_t *err) { + TEN_ASSERT(name, "Should not happen."); + return ten_shared_ptr_create(ten_raw_cmd_custom_create(name, err), + ten_raw_cmd_custom_destroy); +} + +ten_shared_ptr_t *ten_cmd_custom_create_with_name_len(const char *name, + size_t name_len, + ten_error_t *err) { + TEN_ASSERT(name, "Should not happen."); + return ten_shared_ptr_create( + ten_raw_cmd_custom_create_with_name_len(name, name_len, err), + ten_raw_cmd_custom_destroy); +} + ten_json_t *ten_raw_cmd_custom_to_json(ten_msg_t *self, ten_error_t *err) { TEN_ASSERT(self && ten_raw_cmd_check_integrity((ten_cmd_t *)self) && ten_raw_msg_get_type(self) == TEN_MSG_TYPE_CMD, diff --git a/core/src/ten_runtime/msg/data/data.c b/core/src/ten_runtime/msg/data/data.c index 3694876145..3bed39f990 100644 --- a/core/src/ten_runtime/msg/data/data.c +++ b/core/src/ten_runtime/msg/data/data.c @@ -35,7 +35,7 @@ bool ten_raw_data_check_integrity(ten_data_t *self) { return true; } -static ten_data_t *ten_raw_data_create(void) { +static ten_data_t *ten_raw_data_create_empty(void) { ten_data_t *self = (ten_data_t *)TEN_MALLOC(sizeof(ten_data_t)); TEN_ASSERT(self, "Failed to allocate memory."); @@ -46,6 +46,25 @@ static ten_data_t *ten_raw_data_create(void) { return self; } +ten_shared_ptr_t *ten_data_create_empty(void) { + ten_data_t *self = ten_raw_data_create_empty(); + return ten_shared_ptr_create(self, ten_raw_data_destroy); +} + +static ten_data_t *ten_raw_data_create(const char *name, ten_error_t *err) { + ten_data_t *self = ten_raw_data_create_empty(); + ten_raw_msg_set_name((ten_msg_t *)self, name, err); + return self; +} + +static ten_data_t *ten_raw_data_create_with_name_len(const char *name, + size_t name_len, + ten_error_t *err) { + ten_data_t *self = ten_raw_data_create_empty(); + ten_raw_msg_set_name_with_len((ten_msg_t *)self, name, name_len, err); + return self; +} + void ten_raw_data_destroy(ten_data_t *self) { TEN_ASSERT(self && ten_raw_data_check_integrity(self), "Should not happen."); @@ -55,8 +74,17 @@ void ten_raw_data_destroy(ten_data_t *self) { TEN_FREE(self); } -ten_shared_ptr_t *ten_data_create(void) { - ten_data_t *self = ten_raw_data_create(); +ten_shared_ptr_t *ten_data_create(const char *name, ten_error_t *err) { + TEN_ASSERT(name, "Invalid argument."); + ten_data_t *self = ten_raw_data_create(name, err); + return ten_shared_ptr_create(self, ten_raw_data_destroy); +} + +ten_shared_ptr_t *ten_data_create_with_name_len(const char *name, + size_t name_len, + ten_error_t *err) { + TEN_ASSERT(name, "Invalid argument."); + ten_data_t *self = ten_raw_data_create_with_name_len(name, name_len, err); return ten_shared_ptr_create(self, ten_raw_data_destroy); } @@ -104,7 +132,7 @@ ten_msg_t *ten_raw_data_as_msg_clone(ten_msg_t *self, ten_raw_msg_get_type(self) == TEN_MSG_TYPE_DATA, "Should not happen."); - ten_data_t *new_data = ten_raw_data_create(); + ten_data_t *new_data = ten_raw_data_create_empty(); TEN_ASSERT(new_data, "Failed to allocate memory."); for (size_t i = 0; i < ten_data_fields_info_size; ++i) { diff --git a/core/src/ten_runtime/msg/msg.c b/core/src/ten_runtime/msg/msg.c index 7a3116b03a..f91142e3f0 100644 --- a/core/src/ten_runtime/msg/msg.c +++ b/core/src/ten_runtime/msg/msg.c @@ -27,13 +27,10 @@ #include "include_internal/ten_utils/value/value_path.h" #include "ten_runtime/app/app.h" #include "ten_runtime/common/errno.h" -#include "ten_runtime/msg/audio_frame/audio_frame.h" #include "ten_runtime/msg/cmd/close_app/cmd.h" #include "ten_runtime/msg/cmd/stop_graph/cmd.h" #include "ten_runtime/msg/cmd_result/cmd_result.h" -#include "ten_runtime/msg/data/data.h" #include "ten_runtime/msg/msg.h" -#include "ten_runtime/msg/video_frame/video_frame.h" #include "ten_runtime/ten_env/ten_env.h" #include "ten_utils/container/list.h" #include "ten_utils/lib/error.h" @@ -846,7 +843,7 @@ ten_shared_ptr_t *ten_msg_create_from_msg_type(TEN_MSG_TYPE msg_type) { case TEN_MSG_TYPE_CMD_CLOSE_APP: return ten_cmd_close_app_create(); case TEN_MSG_TYPE_CMD: - return ten_cmd_custom_create(); + return ten_cmd_custom_create_empty(); case TEN_MSG_TYPE_CMD_START_GRAPH: return ten_cmd_start_graph_create(); case TEN_MSG_TYPE_CMD_STOP_GRAPH: @@ -856,11 +853,11 @@ ten_shared_ptr_t *ten_msg_create_from_msg_type(TEN_MSG_TYPE msg_type) { case TEN_MSG_TYPE_CMD_RESULT: return ten_cmd_result_create_from_cmd(TEN_STATUS_CODE_OK, NULL); case TEN_MSG_TYPE_DATA: - return ten_data_create(); + return ten_data_create_empty(); case TEN_MSG_TYPE_AUDIO_FRAME: - return ten_audio_frame_create(); + return ten_audio_frame_create_empty(); case TEN_MSG_TYPE_VIDEO_FRAME: - return ten_video_frame_create(); + return ten_video_frame_create_empty(); default: return NULL; } @@ -1056,11 +1053,16 @@ static bool ten_raw_msg_set_property(ten_msg_t *self, const char *path, TEN_ASSERT(value && ten_value_check_integrity(value), "Should not happen."); if (!path || !strlen(path)) { - if (err) { - ten_error_set(err, TEN_ERRNO_INVALID_ARGUMENT, - "path should not be empty."); + // If the path is empty, clear and set all properties. + ten_value_deinit(&self->properties); + bool result = ten_value_init_object_with_move(&self->properties, + ten_value_peek_object(value)); + if (result) { + // The contents of `value` have been completely moved into `properties`, + // so the outer `value` wrapper is removed to avoid memory leaks. + ten_value_destroy(value); } - return NULL; + return result; } bool success = true; @@ -1119,14 +1121,6 @@ bool ten_msg_set_property(ten_shared_ptr_t *self, const char *path, TEN_ASSERT(self && ten_msg_check_integrity(self), "Should not happen."); TEN_ASSERT(value && ten_value_check_integrity(value), "Should not happen."); - if (!path || !strlen(path)) { - if (err) { - ten_error_set(err, TEN_ERRNO_INVALID_ARGUMENT, - "path should not be empty."); - } - return NULL; - } - return ten_raw_msg_set_property(ten_shared_ptr_get_data(self), path, value, err); } @@ -1136,11 +1130,8 @@ ten_value_t *ten_raw_msg_peek_property(ten_msg_t *self, const char *path, TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); if (!path || !strlen(path)) { - if (err) { - ten_error_set(err, TEN_ERRNO_INVALID_ARGUMENT, - "path should not be empty."); - } - return NULL; + // If the path is empty, return all properties. + return &self->properties; } ten_value_t *result = NULL; @@ -1194,7 +1185,6 @@ ten_value_t *ten_raw_msg_peek_property(ten_msg_t *self, const char *path, ten_value_t *ten_msg_peek_property(ten_shared_ptr_t *self, const char *path, ten_error_t *err) { TEN_ASSERT(self && ten_msg_check_integrity(self), "Should not happen."); - TEN_ASSERT(path && strlen(path), "path should not be empty."); return ten_raw_msg_peek_property(ten_msg_get_raw_msg(self), path, err); } @@ -1223,10 +1213,8 @@ const char *ten_msg_get_name(ten_shared_ptr_t *self) { return ten_raw_msg_get_name(raw_msg); } -static bool ten_raw_msg_set_name_with_size(ten_msg_t *self, - const char *msg_name, - size_t msg_name_len, - ten_error_t *err) { +bool ten_raw_msg_set_name_with_len(ten_msg_t *self, const char *msg_name, + size_t msg_name_len, ten_error_t *err) { TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); if (msg_name == NULL) { @@ -1245,14 +1233,14 @@ static bool ten_raw_msg_set_name_with_size(ten_msg_t *self, bool ten_raw_msg_set_name(ten_msg_t *self, const char *msg_name, ten_error_t *err) { TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); - return ten_raw_msg_set_name_with_size(self, msg_name, strlen(msg_name), err); + return ten_raw_msg_set_name_with_len(self, msg_name, strlen(msg_name), err); } -bool ten_msg_set_name_with_size(ten_shared_ptr_t *self, const char *msg_name, - size_t msg_name_len, ten_error_t *err) { +bool ten_msg_set_name_with_len(ten_shared_ptr_t *self, const char *msg_name, + size_t msg_name_len, ten_error_t *err) { TEN_ASSERT(self && ten_msg_check_integrity(self), "Should not happen."); - return ten_raw_msg_set_name_with_size(ten_shared_ptr_get_data(self), msg_name, - msg_name_len, err); + return ten_raw_msg_set_name_with_len(ten_shared_ptr_get_data(self), msg_name, + msg_name_len, err); } bool ten_msg_set_name(ten_shared_ptr_t *self, const char *msg_name, diff --git a/core/src/ten_runtime/msg/video_frame/video_frame.c b/core/src/ten_runtime/msg/video_frame/video_frame.c index 1bc63dd99d..ae83070a33 100644 --- a/core/src/ten_runtime/msg/video_frame/video_frame.c +++ b/core/src/ten_runtime/msg/video_frame/video_frame.c @@ -115,7 +115,7 @@ void ten_raw_video_frame_init(ten_video_frame_t *self) { ten_value_init_buf(&self->data, 0); } -static ten_video_frame_t *ten_raw_video_frame_create(void) { +static ten_video_frame_t *ten_raw_video_frame_create_empty(void) { ten_video_frame_t *self = TEN_MALLOC(sizeof(ten_video_frame_t)); TEN_ASSERT(self, "Failed to allocate memory."); @@ -124,6 +124,26 @@ static ten_video_frame_t *ten_raw_video_frame_create(void) { return self; } +static ten_video_frame_t *ten_raw_video_frame_create(const char *name, + ten_error_t *err) { + TEN_ASSERT(name, "Invalid argument."); + + ten_video_frame_t *self = ten_raw_video_frame_create_empty(); + ten_raw_msg_set_name((ten_msg_t *)self, name, err); + + return self; +} + +static ten_video_frame_t *ten_raw_video_frame_create_with_name_len( + const char *name, size_t name_len, ten_error_t *err) { + TEN_ASSERT(name, "Invalid argument."); + + ten_video_frame_t *self = ten_raw_video_frame_create_empty(); + ten_raw_msg_set_name_with_len((ten_msg_t *)self, name, name_len, err); + + return self; +} + void ten_raw_video_frame_destroy(ten_video_frame_t *self) { TEN_ASSERT(self, "Should not happen."); @@ -134,11 +154,24 @@ void ten_raw_video_frame_destroy(ten_video_frame_t *self) { TEN_FREE(self); } -ten_shared_ptr_t *ten_video_frame_create(void) { - return ten_shared_ptr_create(ten_raw_video_frame_create(), +ten_shared_ptr_t *ten_video_frame_create_empty(void) { + return ten_shared_ptr_create(ten_raw_video_frame_create_empty(), ten_raw_video_frame_destroy); } +ten_shared_ptr_t *ten_video_frame_create(const char *name, ten_error_t *err) { + return ten_shared_ptr_create(ten_raw_video_frame_create(name, err), + ten_raw_video_frame_destroy); +} + +ten_shared_ptr_t *ten_video_frame_create_with_name_len(const char *name, + size_t name_len, + ten_error_t *err) { + return ten_shared_ptr_create( + ten_raw_video_frame_create_with_name_len(name, name_len, err), + ten_raw_video_frame_destroy); +} + int32_t ten_video_frame_get_width(ten_shared_ptr_t *self) { TEN_ASSERT(self, "Should not happen."); return ten_raw_video_frame_get_width(ten_shared_ptr_get_data(self)); diff --git a/core/src/ten_utils/value/value_get.c b/core/src/ten_utils/value/value_get.c index 272dcdb0ac..40e4d5c77a 100644 --- a/core/src/ten_utils/value/value_get.c +++ b/core/src/ten_utils/value/value_get.c @@ -18,6 +18,7 @@ #include "ten_utils/value/type.h" #include "ten_utils/value/type_operation.h" #include "ten_utils/value/value.h" +#include "ten_utils/value/value_is.h" #include "ten_utils/value/value_kv.h" int8_t ten_value_get_int8(ten_value_t *self, ten_error_t *err) { @@ -573,6 +574,19 @@ ten_list_t *ten_value_peek_array(ten_value_t *self) { return NULL; } +ten_list_t *ten_value_peek_object(ten_value_t *self) { + if (!self) { + return NULL; + } + + TEN_ASSERT(ten_value_check_integrity(self), "Invalid argument."); + + if (ten_value_is_object(self)) { + return &self->content.object; + } + return NULL; +} + ten_string_t *ten_value_peek_string(ten_value_t *self) { if (!self) { return NULL; diff --git a/packages/example_extensions/ffmpeg_muxer/src/main.cc b/packages/example_extensions/ffmpeg_muxer/src/main.cc index 41f5227db1..58be760db8 100644 --- a/packages/example_extensions/ffmpeg_muxer/src/main.cc +++ b/packages/example_extensions/ffmpeg_muxer/src/main.cc @@ -67,7 +67,8 @@ class muxer_extension_t : public extension_t { const auto *cmd_name = cmd->get_name(); if (std::string(cmd_name) == "start_muxer") { - TEN_LOGE("muxer_extension_t::on_cmd, %s", cmd->to_json().c_str()); + TEN_LOGE("muxer_extension_t::on_cmd, %s", + cmd->get_property_to_json().c_str()); auto settings = read_settings(*cmd); auto output = cmd->get_property_string("output_stream"); diff --git a/packages/example_extensions/pil_demo_python/main.py b/packages/example_extensions/pil_demo_python/main.py index 6f26c0fa21..d5d6837291 100644 --- a/packages/example_extensions/pil_demo_python/main.py +++ b/packages/example_extensions/pil_demo_python/main.py @@ -35,7 +35,7 @@ def on_deinit(self, ten_env: TenEnv) -> None: ten_env.on_deinit_done() def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info(f"on_cmd json: {cmd_json}") cmd_result = CmdResult.create(StatusCode.OK) diff --git a/packages/example_extensions/simple_http_server_cpp/src/main.cc b/packages/example_extensions/simple_http_server_cpp/src/main.cc index ef1a23e8c0..9c28d6edda 100644 --- a/packages/example_extensions/simple_http_server_cpp/src/main.cc +++ b/packages/example_extensions/simple_http_server_cpp/src/main.cc @@ -632,7 +632,7 @@ void send_ten_msg_with_req_body( // Parse the full content of the request and set it to the // command. - cmd->from_json(cmd_json.dump().c_str()); + cmd->set_property_from_json(nullptr, cmd_json.dump().c_str()); // Send out the command to the TEN runtime. ten_env.send_cmd( diff --git a/tests/BUILD.gn b/tests/BUILD.gn index 6e7a3f2ea6..1a062c93ca 100644 --- a/tests/BUILD.gn +++ b/tests/BUILD.gn @@ -25,10 +25,6 @@ group("tests") { "//tests/ten_runtime", ] - if (ten_enable_private_tests) { - deps += [ "private" ] - } - if (ten_enable_package_manager) { deps += [ "local_registry:copy_local_registry" ] diff --git a/tests/common/client/tcp.c b/tests/common/client/tcp.c index fb11b0541f..f69e739bd4 100644 --- a/tests/common/client/tcp.c +++ b/tests/common/client/tcp.c @@ -283,7 +283,7 @@ bool ten_test_tcp_client_send_data(ten_test_tcp_client_t *self, TEN_ASSERT(graph_id && extension_group_name && extension_name && data, "Invalid argument."); - ten_shared_ptr_t *msg = ten_data_create(); + ten_shared_ptr_t *msg = ten_data_create("test", NULL); ten_buf_t buf; ten_buf_init_with_copying_data(&buf, data, size); diff --git a/tests/ten_runtime/integration/cpp/ffmpeg_basic/ffmpeg_basic_app_source/ten_packages/extension/default_extension_cpp/src/main.cc b/tests/ten_runtime/integration/cpp/ffmpeg_basic/ffmpeg_basic_app_source/ten_packages/extension/default_extension_cpp/src/main.cc index 25b062c57d..36a52e47a6 100644 --- a/tests/ten_runtime/integration/cpp/ffmpeg_basic/ffmpeg_basic_app_source/ten_packages/extension/default_extension_cpp/src/main.cc +++ b/tests/ten_runtime/integration/cpp/ffmpeg_basic/ffmpeg_basic_app_source/ten_packages/extension/default_extension_cpp/src/main.cc @@ -21,21 +21,21 @@ class ffmpeg_client_extension : public ten::extension_t { std::unique_ptr cmd_result, ten::error_t * /*error*/) { nlohmann::json cmd_result_json = - nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json::parse(cmd_result->get_property_to_json()); if (cmd_result->get_status_code() != TEN_STATUS_CODE_OK) { TEN_ASSERT(0, "should not happen."); } auto start_muxer_cmd = ten::cmd_t::create("start_muxer"); - start_muxer_cmd->from_json( - nlohmann::to_string(cmd_result_json).c_str()); + start_muxer_cmd->set_property_from_json( + nullptr, nlohmann::to_string(cmd_result_json).c_str()); ten_env.send_cmd( std::move(start_muxer_cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t * /*error*/) { nlohmann::json json = - nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json::parse(cmd_result->get_property_to_json()); if (cmd_result->get_status_code() != TEN_STATUS_CODE_OK) { TEN_ASSERT(0, "should not happen."); } diff --git a/tests/ten_runtime/integration/cpp/ffmpeg_bypass/ffmpeg_bypass_app_source/ten_packages/extension/default_extension_cpp/src/main.cc b/tests/ten_runtime/integration/cpp/ffmpeg_bypass/ffmpeg_bypass_app_source/ten_packages/extension/default_extension_cpp/src/main.cc index ccafdd2a70..0a8dddd14e 100644 --- a/tests/ten_runtime/integration/cpp/ffmpeg_bypass/ffmpeg_bypass_app_source/ten_packages/extension/default_extension_cpp/src/main.cc +++ b/tests/ten_runtime/integration/cpp/ffmpeg_bypass/ffmpeg_bypass_app_source/ten_packages/extension/default_extension_cpp/src/main.cc @@ -21,21 +21,21 @@ class ffmpeg_client_extension : public ten::extension_t { std::unique_ptr cmd_result, TEN_UNUSED ten::error_t * /*error*/) { nlohmann::json cmd_result_json = - nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json::parse(cmd_result->get_property_to_json()); if (cmd_result->get_status_code() != TEN_STATUS_CODE_OK) { TEN_ASSERT(0, "should not happen."); } auto start_muxer_cmd = ten::cmd_t::create("start_muxer"); - start_muxer_cmd->from_json( - nlohmann::to_string(cmd_result_json).c_str()); + start_muxer_cmd->set_property_from_json( + nullptr, nlohmann::to_string(cmd_result_json).c_str()); ten_env.send_cmd( std::move(start_muxer_cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, TEN_UNUSED ten::error_t * /*error*/) { nlohmann::json json = - nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json::parse(cmd_result->get_property_to_json()); if (cmd_result->get_status_code() != TEN_STATUS_CODE_OK) { TEN_ASSERT(0, "should not happen."); } diff --git a/tests/ten_runtime/integration/python/async_extension_basic_python/async_extension_basic_python_app/ten_packages/extension/default_async_extension_python/extension.py b/tests/ten_runtime/integration/python/async_extension_basic_python/async_extension_basic_python_app/ten_packages/extension/default_async_extension_python/extension.py index 5cf7505459..f6cd9dc938 100644 --- a/tests/ten_runtime/integration/python/async_extension_basic_python/async_extension_basic_python_app/ten_packages/extension/default_async_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/async_extension_basic_python/async_extension_basic_python_app/ten_packages/extension/default_async_extension_python/extension.py @@ -32,7 +32,7 @@ async def on_deinit(self, ten_env: AsyncTenEnv) -> None: await asyncio.sleep(0.5) async def on_cmd(self, ten_env: AsyncTenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug(f"on_cmd: {cmd_json}") # Mock async operation, e.g. network, file I/O. diff --git a/tests/ten_runtime/integration/python/async_io_basic_python/async_io_basic_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/async_io_basic_python/async_io_basic_python_app/ten_packages/extension/default_extension_python/extension.py index 4a049b15cd..7c2f21244f 100644 --- a/tests/ten_runtime/integration/python/async_io_basic_python/async_io_basic_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/async_io_basic_python/async_io_basic_python_app/ten_packages/extension/default_extension_python/extension.py @@ -71,7 +71,7 @@ def on_deinit(self, ten_env: TenEnv) -> None: async def on_cmd_async(self, ten_env: TenEnv, cmd: Cmd) -> None: ten_env.log_info("on_cmd_async") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info("on_cmd_async json: " + cmd_json) # Mock async operation, e.g. network, file I/O diff --git a/tests/ten_runtime/integration/python/cpp_app_multi_process_python/cpp_app_multi_process_python_app_source/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/cpp_app_multi_process_python/cpp_app_multi_process_python_app_source/ten_packages/extension/default_extension_python/extension.py index 3361388679..619a92f9fc 100644 --- a/tests/ten_runtime/integration/python/cpp_app_multi_process_python/cpp_app_multi_process_python_app_source/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/cpp_app_multi_process_python/cpp_app_multi_process_python_app_source/ten_packages/extension/default_extension_python/extension.py @@ -70,7 +70,7 @@ def check_hello( ten_env.return_result(respCmd, receivedCmd) def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug("on_cmd json: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app_source/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app_source/ten_packages/extension/default_extension_python/extension.py index aed39e41d0..844a77aba2 100644 --- a/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app_source/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app_source/ten_packages/extension/default_extension_python/extension.py @@ -69,7 +69,7 @@ def check_hello( def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: ten_env.log_info("on_cmd") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info("on_cmd json: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/ten_packages/extension/default_extension_python/extension.py index 64fc93cfbe..90c45b7c4b 100644 --- a/tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/ten_packages/extension/default_extension_python/extension.py @@ -137,7 +137,7 @@ def check_hello( def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: ten_env.log_info("on_cmd") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info("on_cmd json: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/go_app_async_extension_python/go_app_async_extension_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/go_app_async_extension_python/go_app_async_extension_python_app/ten_packages/extension/default_extension_python/extension.py index 0950d24834..3e6d1e4798 100644 --- a/tests/ten_runtime/integration/python/go_app_async_extension_python/go_app_async_extension_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/go_app_async_extension_python/go_app_async_extension_python_app/ten_packages/extension/default_extension_python/extension.py @@ -54,7 +54,7 @@ async def greeting(self, ten_env: AsyncTenEnv) -> CmdResult: return await ten_env.send_cmd(new_cmd) async def on_cmd(self, ten_env: AsyncTenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug("on_cmd: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/go_app_cythonize/go_app_cythonize_app/ten_packages/extension/default_extension_python/extension.pyx b/tests/ten_runtime/integration/python/go_app_cythonize/go_app_cythonize_app/ten_packages/extension/default_extension_python/extension.pyx index 192eda9775..26fa726371 100644 --- a/tests/ten_runtime/integration/python/go_app_cythonize/go_app_cythonize_app/ten_packages/extension/default_extension_python/extension.pyx +++ b/tests/ten_runtime/integration/python/go_app_cythonize/go_app_cythonize_app/ten_packages/extension/default_extension_python/extension.pyx @@ -86,7 +86,7 @@ class DefaultExtension(Extension): ) def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug("on_cmd: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/go_app_partially_cythonize/go_app_partially_cythonize_app/ten_packages/extension/default_extension_python/extension.pyx b/tests/ten_runtime/integration/python/go_app_partially_cythonize/go_app_partially_cythonize_app/ten_packages/extension/default_extension_python/extension.pyx index 192eda9775..26fa726371 100644 --- a/tests/ten_runtime/integration/python/go_app_partially_cythonize/go_app_partially_cythonize_app/ten_packages/extension/default_extension_python/extension.pyx +++ b/tests/ten_runtime/integration/python/go_app_partially_cythonize/go_app_partially_cythonize_app/ten_packages/extension/default_extension_python/extension.pyx @@ -86,7 +86,7 @@ class DefaultExtension(Extension): ) def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug("on_cmd: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/go_app_python/go_app_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/go_app_python/go_app_python_app/ten_packages/extension/default_extension_python/extension.py index 192eda9775..26fa726371 100644 --- a/tests/ten_runtime/integration/python/go_app_python/go_app_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/go_app_python/go_app_python_app/ten_packages/extension/default_extension_python/extension.py @@ -86,7 +86,7 @@ def check_hello( ) def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug("on_cmd: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/large_json_python/large_json_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/large_json_python/large_json_python_app/ten_packages/extension/default_extension_python/extension.py index d809a62abf..5bef5dc058 100644 --- a/tests/ten_runtime/integration/python/large_json_python/large_json_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/large_json_python/large_json_python_app/ten_packages/extension/default_extension_python/extension.py @@ -82,7 +82,7 @@ def on_deinit(self, ten_env: TenEnv) -> None: def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: print("DefaultExtension on_cmd") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() print("DefaultExtension on_cmd json: " + cmd_json) cmd_result = CmdResult.create(StatusCode.OK) diff --git a/tests/ten_runtime/integration/python/multi_process_python/multi_process_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/multi_process_python/multi_process_python_app/ten_packages/extension/default_extension_python/extension.py index 235a718289..037c845184 100644 --- a/tests/ten_runtime/integration/python/multi_process_python/multi_process_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/multi_process_python/multi_process_python_app/ten_packages/extension/default_extension_python/extension.py @@ -62,7 +62,7 @@ def check_hello( def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: ten_env.log_info("on_cmd") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info("on_cmd json: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/multiple_results_python_1/multiple_results_python_1_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/multiple_results_python_1/multiple_results_python_1_app/ten_packages/extension/default_extension_python/extension.py index 2bfb77878e..28ffd5f2bd 100644 --- a/tests/ten_runtime/integration/python/multiple_results_python_1/multiple_results_python_1_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/multiple_results_python_1/multiple_results_python_1_app/ten_packages/extension/default_extension_python/extension.py @@ -44,7 +44,7 @@ def check_hello( ten_env.return_result(respCmd, receivedCmd) def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug(f"on_cmd json: {cmd_json}") if self.name == "default_extension_python_1": diff --git a/tests/ten_runtime/integration/python/multiple_results_python_2/multiple_results_python_2_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/multiple_results_python_2/multiple_results_python_2_app/ten_packages/extension/default_extension_python/extension.py index 27c582fe41..e7a1b21de9 100644 --- a/tests/ten_runtime/integration/python/multiple_results_python_2/multiple_results_python_2_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/multiple_results_python_2/multiple_results_python_2_app/ten_packages/extension/default_extension_python/extension.py @@ -44,7 +44,7 @@ def check_hello( assert False def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug(f"on_cmd json: {cmd_json}") if self.name == "default_extension_python_1": diff --git a/tests/ten_runtime/integration/python/multiple_results_python_3/multiple_results_python_3_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/multiple_results_python_3/multiple_results_python_3_app/ten_packages/extension/default_extension_python/extension.py index 63e496563e..1a3b6c0c59 100644 --- a/tests/ten_runtime/integration/python/multiple_results_python_3/multiple_results_python_3_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/multiple_results_python_3/multiple_results_python_3_app/ten_packages/extension/default_extension_python/extension.py @@ -47,7 +47,7 @@ def check_hello( assert False def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug(f"on_cmd json: {cmd_json}") if self.name == "default_extension_python_1": diff --git a/tests/ten_runtime/integration/python/no_dest_async_python/no_dest_async_python_app/ten_packages/extension/default_async_extension_python/extension.py b/tests/ten_runtime/integration/python/no_dest_async_python/no_dest_async_python_app/ten_packages/extension/default_async_extension_python/extension.py index b36a203e63..a5ab079408 100644 --- a/tests/ten_runtime/integration/python/no_dest_async_python/no_dest_async_python_app/ten_packages/extension/default_async_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/no_dest_async_python/no_dest_async_python_app/ten_packages/extension/default_async_extension_python/extension.py @@ -68,7 +68,7 @@ async def on_deinit(self, ten_env: AsyncTenEnv) -> None: await asyncio.sleep(0.5) async def on_cmd(self, ten_env: AsyncTenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug(f"on_cmd: {cmd_json}") # Mock async operation, e.g. network, file I/O. diff --git a/tests/ten_runtime/integration/python/no_dest_python/no_dest_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/no_dest_python/no_dest_python_app/ten_packages/extension/default_extension_python/extension.py index dd1db02499..6c50321850 100644 --- a/tests/ten_runtime/integration/python/no_dest_python/no_dest_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/no_dest_python/no_dest_python_app/ten_packages/extension/default_extension_python/extension.py @@ -114,7 +114,7 @@ def check_hello( def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: print("DefaultExtension on_cmd") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() print("DefaultExtension on_cmd json: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/resp_handler_yield_python/resp_handler_yield_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/resp_handler_yield_python/resp_handler_yield_python_app/ten_packages/extension/default_extension_python/extension.py index f38dc30fce..a0e8b7f3c0 100644 --- a/tests/ten_runtime/integration/python/resp_handler_yield_python/resp_handler_yield_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/resp_handler_yield_python/resp_handler_yield_python_app/ten_packages/extension/default_extension_python/extension.py @@ -78,7 +78,7 @@ def __handle_cmd(self, ten_env: TenEnv, cmd: Cmd): def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: ten_env.log_info("on_cmd") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info("on_cmd json: " + cmd_json) self.thread = threading.Thread( diff --git a/tests/ten_runtime/integration/python/send_cmd_discard_result_python/send_cmd_discard_result_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/send_cmd_discard_result_python/send_cmd_discard_result_python_app/ten_packages/extension/default_extension_python/extension.py index 3e03b487c0..290c538266 100644 --- a/tests/ten_runtime/integration/python/send_cmd_discard_result_python/send_cmd_discard_result_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/send_cmd_discard_result_python/send_cmd_discard_result_python_app/ten_packages/extension/default_extension_python/extension.py @@ -23,7 +23,7 @@ def on_init(self, ten_env: TenEnv) -> None: ten_env.on_init_done() def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info(f"on_cmd json: {cmd_json}") if self.name == "default_extension_python_1": diff --git a/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/extension/default_extension_python/extension.py index db659df3ef..25d218afbb 100644 --- a/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/send_cmd_python/send_cmd_python_app/ten_packages/extension/default_extension_python/extension.py @@ -73,7 +73,7 @@ def check_hello( def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: ten_env.log_info("on_cmd") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json(None) ten_env.log_info("on_cmd json: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/integration/python/send_data_python/send_data_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/send_data_python/send_data_python_app/ten_packages/extension/default_extension_python/extension.py index bc792a3665..f8246010c8 100644 --- a/tests/ten_runtime/integration/python/send_data_python/send_data_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/send_data_python/send_data_python_app/ten_packages/extension/default_extension_python/extension.py @@ -21,7 +21,7 @@ def on_configure(self, ten_env: TenEnv) -> None: ten_env.on_configure_done() def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() print("DefaultExtension on_cmd json: " + cmd_json) new_data = Data.create("data") diff --git a/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/extension/default_extension_python/extension.py index 0c197720fd..30c7eb3e0a 100644 --- a/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/send_recv_image_python/send_recv_image_python_app/ten_packages/extension/default_extension_python/extension.py @@ -33,7 +33,7 @@ def on_start(self, ten_env: TenEnv) -> None: ten_env.on_start_done() def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info(f"DefaultExtension on_cmd json: {cmd_json}") assert hasattr(self, "request_cmd") != True diff --git a/tests/ten_runtime/integration/python/send_recv_pcm_python/send_recv_pcm_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/send_recv_pcm_python/send_recv_pcm_python_app/ten_packages/extension/default_extension_python/extension.py index ec3c61c88a..fd49601ce6 100644 --- a/tests/ten_runtime/integration/python/send_recv_pcm_python/send_recv_pcm_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/send_recv_pcm_python/send_recv_pcm_python_app/ten_packages/extension/default_extension_python/extension.py @@ -38,7 +38,7 @@ def on_start(self, ten_env: TenEnv) -> None: ten_env.on_start_done() def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() print("DefaultExtension on_cmd json: " + cmd_json) self.request_cmd = cmd diff --git a/tests/ten_runtime/integration/python/standalone_test_python/default_extension_python/extension.py b/tests/ten_runtime/integration/python/standalone_test_python/default_extension_python/extension.py index ad7f9f95e8..ed5d722524 100644 --- a/tests/ten_runtime/integration/python/standalone_test_python/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/standalone_test_python/default_extension_python/extension.py @@ -32,14 +32,17 @@ def return_if_all_data_received(self, ten_env: TenEnv) -> None: def on_data(self, ten_env: TenEnv, data: Data) -> None: if data.get_name() == "test": - ten_env.log_info("DefaultExtension on_data: " + data.to_json()) + ten_env.log_info( + "DefaultExtension on_data: " + data.get_property_to_json() + ) self.recv_data_count += 1 self.return_if_all_data_received(ten_env) def on_audio_frame(self, ten_env: TenEnv, audio_frame: AudioFrame) -> None: if audio_frame.get_name() == "test": ten_env.log_info( - "DefaultExtension on_audio_frame: " + audio_frame.to_json() + "DefaultExtension on_audio_frame: " + + audio_frame.get_property_to_json() ) self.recv_data_count += 1 self.return_if_all_data_received(ten_env) @@ -47,13 +50,14 @@ def on_audio_frame(self, ten_env: TenEnv, audio_frame: AudioFrame) -> None: def on_video_frame(self, ten_env: TenEnv, video_frame: VideoFrame) -> None: if video_frame.get_name() == "test": ten_env.log_info( - "DefaultExtension on_video_frame: " + video_frame.to_json() + "DefaultExtension on_video_frame: " + + video_frame.get_property_to_json() ) self.recv_data_count += 1 self.return_if_all_data_received(ten_env) def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_info("DefaultExtension on_cmd json: " + cmd_json) if cmd.get_name() == "hello_world": diff --git a/tests/ten_runtime/integration/python/two_async_exts_one_group_python/two_async_exts_one_group_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/two_async_exts_one_group_python/two_async_exts_one_group_python_app/ten_packages/extension/default_extension_python/extension.py index 6b6779b097..1c11ba5882 100644 --- a/tests/ten_runtime/integration/python/two_async_exts_one_group_python/two_async_exts_one_group_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/two_async_exts_one_group_python/two_async_exts_one_group_python_app/ten_packages/extension/default_extension_python/extension.py @@ -32,7 +32,7 @@ async def on_deinit(self, ten_env: AsyncTenEnv) -> None: await asyncio.sleep(1) async def on_cmd(self, ten_env: AsyncTenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug(f"on_cmd: {cmd_json}") # Mock async operation, e.g. network, file I/O. diff --git a/tests/ten_runtime/integration/python/two_async_exts_python/two_async_exts_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/two_async_exts_python/two_async_exts_python_app/ten_packages/extension/default_extension_python/extension.py index 3d01d25001..6431116937 100644 --- a/tests/ten_runtime/integration/python/two_async_exts_python/two_async_exts_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/two_async_exts_python/two_async_exts_python_app/ten_packages/extension/default_extension_python/extension.py @@ -33,7 +33,7 @@ async def on_deinit(self, ten_env: AsyncTenEnv) -> None: await asyncio.sleep(1) async def on_cmd(self, ten_env: AsyncTenEnv, cmd: Cmd) -> None: - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() ten_env.log_debug(f"on_cmd: {cmd_json}") # Mock async operation, e.g. network, file I/O. diff --git a/tests/ten_runtime/integration/python/unused_addon_python/unused_addon_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/unused_addon_python/unused_addon_python_app/ten_packages/extension/default_extension_python/extension.py index 18a89e5b90..060437ac57 100644 --- a/tests/ten_runtime/integration/python/unused_addon_python/unused_addon_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/unused_addon_python/unused_addon_python_app/ten_packages/extension/default_extension_python/extension.py @@ -82,7 +82,7 @@ def check_hello(self, ten_env: TenEnv, result: CmdResult, receivedCmd: Cmd): def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: print("DefaultExtension on_cmd") - cmd_json = cmd.to_json() + cmd_json = cmd.get_property_to_json() print("DefaultExtension on_cmd json: " + cmd_json) new_cmd = Cmd.create("hello") diff --git a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_6.cc b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_6.cc index 2f50be676e..b2f781549e 100644 --- a/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_6.cc +++ b/tests/ten_runtime/smoke/cmd_conversion/cmd_conversion_path_nested_6.cc @@ -149,7 +149,7 @@ TEST(CmdConversionTest, CmdConversionPathNested6) { // NOLINT hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", "default", "cmd_mapping_path_nested_6__extension_group", "test_extension_1"); - hello_world_cmd->from_json(R"({ + hello_world_cmd->set_property_from_json(nullptr, R"({ "test_group": [{ "aaa": { "test_property": 32 diff --git a/tests/ten_runtime/smoke/data_test/from_json.cc b/tests/ten_runtime/smoke/data_test/from_json.cc index 55d328131e..7a28fad3d0 100644 --- a/tests/ten_runtime/smoke/data_test/from_json.cc +++ b/tests/ten_runtime/smoke/data_test/from_json.cc @@ -26,12 +26,12 @@ class test_extension_1 : public ten::extension_t { hello_world_cmd = std::move(cmd); auto data = ten::data_t::create("data"); - data->from_json( - // clang-format off + data->set_property_from_json(nullptr, + // clang-format off R"({ "payload": 3 })" - // clang-format on + // clang-format on ); ten_env.send_data(std::move(data)); } else if (std::string(cmd->get_name()) == "data_ack") { diff --git a/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_2.cc b/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_2.cc index 0ce8fa23cc..645ab1d143 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_2.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_invalid_extension_2.cc @@ -33,7 +33,8 @@ class test_extension : public ten::extension_t { std::move(test_cmd), [this](ten::ten_env_t &ten_env, std::unique_ptr result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(result->to_json()); + nlohmann::json json = + nlohmann::json::parse(result->get_property_to_json()); auto cmd_result = ten::cmd_result_t::create(result->get_status_code()); cmd_result->set_property("detail", json.value("detail", "")); diff --git a/tests/ten_runtime/smoke/extension_test/command/command_send_enum.cc b/tests/ten_runtime/smoke/extension_test/command/command_send_enum.cc index ca2cd90022..2d4c334236 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_send_enum.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_send_enum.cc @@ -34,7 +34,8 @@ class test_extension_1 : public ten::extension_t { std::move(new_cmd), [this](ten::ten_env_t &ten_env, std::unique_ptr result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(result->to_json()); + nlohmann::json json = + nlohmann::json::parse(result->get_property_to_json()); auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", json.value("detail", "")); diff --git a/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd.cc b/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd.cc index 5de72dcce0..d6510164fa 100644 --- a/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd.cc +++ b/tests/ten_runtime/smoke/extension_test/command/command_stop_graph_actively_through_cmd.cc @@ -78,7 +78,7 @@ class test_extension_4 : public ten::extension_t { }] } })"_json; - stop_graph_cmd->from_json(json.dump().c_str()); + stop_graph_cmd->set_property_from_json(nullptr, json.dump().c_str()); ten_env.send_cmd(std::move(stop_graph_cmd)); } } diff --git a/tests/ten_runtime/smoke/extension_test/dest/specify_dest.cc b/tests/ten_runtime/smoke/extension_test/dest/specify_dest.cc index 6c9dea0bc4..961a500874 100644 --- a/tests/ten_runtime/smoke/extension_test/dest/specify_dest.cc +++ b/tests/ten_runtime/smoke/extension_test/dest/specify_dest.cc @@ -82,7 +82,8 @@ class business_extension : public ten::extension_t { ten::error_t *err) { // Receive the result from plugin_1, and decide the next step based // on the content of the result. - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json["detail"] == "plugin_1_result") { // Successfully completed the interaction with plugin_1, the next // step is to interact with plugin_2. @@ -112,7 +113,8 @@ class business_extension : public ten::extension_t { std::unique_ptr cmd_result, ten::error_t *err) { // Receive result from plugin_2. - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json["detail"] == "plugin_2_result") { // Successfully completed the interaction with plugin_2, // the next step is to return a result to the request diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle.cc index 16eddfe05c..2a7ff6d8c2 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle.cc @@ -39,7 +39,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { if (std::string(cmd->get_name()) == "sum") { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); + nlohmann::json json = nlohmann::json::parse(cmd->get_property_to_json()); if (counter_ == LOOP_CNT) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); @@ -56,7 +56,8 @@ class test_extension : public ten::extension_t { json["total"] = std::to_string(total); - TEN_UNUSED bool const rc = cmd->from_json(json.dump().c_str()); + TEN_UNUSED bool const rc = + cmd->set_property_from_json(nullptr, json.dump().c_str()); TEN_ASSERT(rc, "Should not happen."); ten_env.send_cmd(std::move(cmd)); diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd.cc index 4508dff15f..d7d3ae91df 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd.cc @@ -39,7 +39,7 @@ class test_extension : public ten::extension_t { std::unique_ptr cmd) override { if (std::string(cmd->get_name()) == "sum") { if (counter_ == LOOP_CNT) { - auto json = nlohmann::json::parse(cmd->to_json()); + auto json = nlohmann::json::parse(cmd->get_property_to_json()); auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property_from_json("detail", json.dump().c_str()); ten_env.return_result(std::move(cmd_result), std::move(cmd)); diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd_with_default.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd_with_default.cc index 242e699123..556fc44cca 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd_with_default.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_loop_multiple_circle_through_cmd_with_default.cc @@ -46,7 +46,7 @@ class test_extension : public ten::extension_t { if (std::string(cmd->get_name()) == "sum") { if (counter_ == LOOP_CNT) { - auto json = nlohmann::json::parse(cmd->to_json()); + auto json = nlohmann::json::parse(cmd->get_property_to_json()); auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property_from_json("detail", json.dump().c_str()); ten_env.return_result(std::move(cmd_result), std::move(cmd)); diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon.cc index 16f228d1a7..5539632c23 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon.cc @@ -43,7 +43,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); + nlohmann::json json = nlohmann::json::parse(cmd->get_property_to_json()); if (is_leaf_node_) { json["return_from"] = name_; @@ -62,7 +62,8 @@ class test_extension : public ten::extension_t { json[name_] = name_; } - TEN_UNUSED bool const rc = cmd->from_json(json.dump().c_str()); + TEN_UNUSED bool const rc = + cmd->set_property_from_json(nullptr, json.dump().c_str()); TEN_ASSERT(rc, "Should not happen."); ten_env.send_cmd( @@ -70,7 +71,8 @@ class test_extension : public ten::extension_t { [this, edges](ten::ten_env_t &ten_env, std::unique_ptr result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(result->to_json()); + nlohmann::json json = + nlohmann::json::parse(result->get_property_to_json()); nlohmann::json detail = json["detail"]; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon_one_app.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon_one_app.cc index aeb5992f61..72a5df205d 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon_one_app.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_multiple_polygon_one_app.cc @@ -37,7 +37,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); + nlohmann::json json = nlohmann::json::parse(cmd->get_property_to_json()); if (is_leaf_node_) { json["return_from"] = name_; @@ -54,7 +54,8 @@ class test_extension : public ten::extension_t { json[name_] = name_; } - TEN_UNUSED bool const rc = cmd->from_json(json.dump().c_str()); + TEN_UNUSED bool const rc = + cmd->set_property_from_json(nullptr, json.dump().c_str()); TEN_ASSERT(rc, "Should not happen."); ten_env.send_cmd( @@ -62,7 +63,8 @@ class test_extension : public ten::extension_t { [this, edges](ten::ten_env_t &ten_env, std::unique_ptr result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(result->to_json()); + nlohmann::json json = + nlohmann::json::parse(result->get_property_to_json()); nlohmann::json detail = json["detail"]; if (detail.type() == nlohmann::json::value_t::string) { detail = nlohmann::json::parse(json.value("detail", "{}")); diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_1.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_1.cc index 8c8728c4ac..9bc859480b 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_1.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_1.cc @@ -33,7 +33,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); + nlohmann::json json = nlohmann::json::parse(cmd->get_property_to_json()); if (is_leaf_node_) { json["return_from"] = name_; @@ -50,7 +50,8 @@ class test_extension : public ten::extension_t { json["source"] = name_; } - TEN_UNUSED bool const rc = cmd->from_json(json.dump().c_str()); + TEN_UNUSED bool const rc = + cmd->set_property_from_json(nullptr, json.dump().c_str()); TEN_ASSERT(rc, "Should not happen."); ten_env.send_cmd_ex( @@ -58,7 +59,8 @@ class test_extension : public ten::extension_t { [this, edges](ten::ten_env_t &ten_env, std::unique_ptr result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(result->to_json()); + nlohmann::json json = + nlohmann::json::parse(result->get_property_to_json()); receive_count++; nlohmann::json detail = json["detail"]; diff --git a/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_2.cc b/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_2.cc index 2879dd400e..4e550691f1 100644 --- a/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_2.cc +++ b/tests/ten_runtime/smoke/extension_test/graph/graph_polygon_in_one_app_return_all_2.cc @@ -33,7 +33,7 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); + nlohmann::json json = nlohmann::json::parse(cmd->get_property_to_json()); if (is_leaf_node_) { json["return_from"] = name_; @@ -50,7 +50,8 @@ class test_extension : public ten::extension_t { json["source"] = name_; } - TEN_UNUSED bool const rc = cmd->from_json(json.dump().c_str()); + TEN_UNUSED bool const rc = + cmd->set_property_from_json(nullptr, json.dump().c_str()); TEN_ASSERT(rc, "Should not happen."); ten_env.send_cmd( @@ -58,7 +59,8 @@ class test_extension : public ten::extension_t { [this, edges](ten::ten_env_t &ten_env, std::unique_ptr result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(result->to_json()); + nlohmann::json json = + nlohmann::json::parse(result->get_property_to_json()); receive_count++; nlohmann::json detail = json["detail"]; diff --git a/tests/ten_runtime/smoke/extension_test/graph_name/graph_name_basic.cc b/tests/ten_runtime/smoke/extension_test/graph_name/graph_name_basic.cc index d137e06091..176acd0139 100644 --- a/tests/ten_runtime/smoke/extension_test/graph_name/graph_name_basic.cc +++ b/tests/ten_runtime/smoke/extension_test/graph_name/graph_name_basic.cc @@ -23,11 +23,12 @@ class test_extension : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json data = nlohmann::json::parse(cmd->to_json()); + nlohmann::json data = nlohmann::json::parse(cmd->get_property_to_json()); data["send_from"] = name_; - TEN_UNUSED bool const rc = cmd->from_json(data.dump().c_str()); + TEN_UNUSED bool const rc = + cmd->set_property_from_json(nullptr, data.dump().c_str()); TEN_ASSERT(rc, "Should not happen."); // extension1(app1) -> extension3(app2) -> extension2(app1) -> return diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app.cc index fd3faf4a28..23ea3411e8 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app.cc @@ -26,7 +26,8 @@ \ void on_cmd(ten::ten_env_t &ten_env, \ std::unique_ptr cmd) override { \ - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); \ + nlohmann::json json = \ + nlohmann::json::parse(cmd->get_property_to_json()); \ if (std::string(cmd->get_name()) == "hello_world") { \ auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); \ cmd_result->set_property("detail", "hello world from extension " #N); \ diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler.cc index 51dada8c5e..1f9d5e424a 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler.cc @@ -26,7 +26,8 @@ \ void on_cmd(ten::ten_env_t &ten_env, \ std::unique_ptr cmd) override { \ - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); \ + nlohmann::json json = \ + nlohmann::json::parse(cmd->get_property_to_json()); \ if (std::string(cmd->get_name()) == "hello_world") { \ auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); \ cmd_result->set_property("detail", "hello world from extension " #N); \ diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler_lambda.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler_lambda.cc index 4b1701e5fd..70e433b4cc 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler_lambda.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_multi_app_with_response_handler_lambda.cc @@ -26,7 +26,8 @@ \ void on_cmd(ten::ten_env_t &ten_env, \ std::unique_ptr cmd) override { \ - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); \ + nlohmann::json json = \ + nlohmann::json::parse(cmd->get_property_to_json()); \ if (std::string(cmd->get_name()) == "hello_world") { \ auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); \ cmd_result->set_property("detail", "hello world from extension " #N); \ diff --git a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_one_app.cc b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_one_app.cc index 2f23ba340e..5e0240c62a 100644 --- a/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_one_app.cc +++ b/tests/ten_runtime/smoke/extension_test/multi_dest/multi_dest_in_one_app.cc @@ -89,7 +89,8 @@ class test_extension_1 : public ten::extension_t { \ void on_cmd(ten::ten_env_t &ten_env, \ std::unique_ptr cmd) override { \ - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); \ + nlohmann::json json = \ + nlohmann::json::parse(cmd->get_property_to_json()); \ if (std::string(cmd->get_name()) == "hello_world") { \ auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); \ cmd_result->set_property("detail", "hello world from extension " #N); \ diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_2.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_2.cc index 35db3df29c..a4816645e2 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_2.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_basic_2.cc @@ -50,7 +50,8 @@ class test_predefined_graph : public ten::extension_t { std::move(start_graph_cmd), [&](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (cmd_result->get_status_code() == TEN_STATUS_CODE_OK) { auto hello_world_cmd = ten::cmd_t::create("hello_world"); hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", @@ -63,7 +64,7 @@ class test_predefined_graph : public ten::extension_t { std::unique_ptr cmd_result, ten::error_t *err) { nlohmann::json json = - nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json::parse(cmd_result->get_property_to_json()); if (cmd_result->get_status_code() == TEN_STATUS_CODE_OK) { normal_extension_is_ready = true; diff --git a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_engine_own_eventloop.cc b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_engine_own_eventloop.cc index 59aa18dc9e..f229973b81 100644 --- a/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_engine_own_eventloop.cc +++ b/tests/ten_runtime/smoke/extension_test/predefined_graph/predefined_graph_engine_own_eventloop.cc @@ -18,7 +18,8 @@ class test_predefined_graph : public ten::extension_t { void on_cmd(ten::ten_env_t &ten_env, std::unique_ptr cmd) override { - nlohmann::json const request = nlohmann::json::parse(cmd->to_json()); + nlohmann::json const request = + nlohmann::json::parse(cmd->get_property_to_json()); TEN_LOGD("extension receives: %s", request.dump().c_str()); nlohmann::json const detail = {{"id", 1}, {"name", "a"}}; diff --git a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_async_basic.cc b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_async_basic.cc index 56e0f798f7..66aa72dec2 100644 --- a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_async_basic.cc +++ b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_async_basic.cc @@ -24,23 +24,25 @@ class test_extension_1 : public ten::extension_t { if (std::string(cmd->get_name()) == "hello_world_1") { auto test_string = std::make_shared("test test test"); - ten_env.send_cmd( - std::move(cmd), [test_string](ten::ten_env_t &ten_env, - std::unique_ptr cmd, - ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); - if (json.value("detail", "") == "hello world, too" && - *test_string == "test test test") { - cmd->set_property("detail", "hello world 1, too"); - ten_env.return_result_directly(std::move(cmd)); - } - }); + ten_env.send_cmd(std::move(cmd), + [test_string](ten::ten_env_t &ten_env, + std::unique_ptr cmd, + ten::error_t *err) { + nlohmann::json json = + nlohmann::json::parse(cmd->get_property_to_json()); + if (json.value("detail", "") == "hello world, too" && + *test_string == "test test test") { + cmd->set_property("detail", "hello world 1, too"); + ten_env.return_result_directly(std::move(cmd)); + } + }); } else if (std::string(cmd->get_name()) == "hello_world_2") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world, too") { cmd_result->set_property("detail", "hello world 2, too"); ten_env.return_result_directly(std::move(cmd_result)); @@ -53,7 +55,8 @@ class test_extension_1 : public ten::extension_t { std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world, too") { cmd_result->set_property("detail", "hello world 3, too"); ten_env.return_result_directly(std::move(cmd_result)); @@ -85,7 +88,8 @@ class test_extension_1 : public ten::extension_t { [cmd_shared](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world, too") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 5, too"); diff --git a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic.cc b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic.cc index 4568dc3ebb..53903b600a 100644 --- a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic.cc +++ b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic.cc @@ -24,24 +24,26 @@ class test_extension_1 : public ten::extension_t { if (std::string(cmd->get_name()) == "hello_world_1") { auto test_string = std::make_shared("test test test"); - ten_env.send_cmd( - std::move(cmd), [test_string](ten::ten_env_t &ten_env, - std::unique_ptr cmd, - ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); + ten_env.send_cmd(std::move(cmd), + [test_string](ten::ten_env_t &ten_env, + std::unique_ptr cmd, + ten::error_t *err) { + nlohmann::json json = + nlohmann::json::parse(cmd->get_property_to_json()); - if (json.value("detail", "") == "hello world 1, too" && - *test_string == "test test test") { - cmd->set_property("detail", "hello world 1, too"); - ten_env.return_result_directly(std::move(cmd)); - } - }); + if (json.value("detail", "") == "hello world 1, too" && + *test_string == "test test test") { + cmd->set_property("detail", "hello world 1, too"); + ten_env.return_result_directly(std::move(cmd)); + } + }); } else if (std::string(cmd->get_name()) == "hello_world_2") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world 2, too") { cmd_result->set_property("detail", "hello world 2, too"); ten_env.return_result_directly(std::move(cmd_result)); @@ -52,7 +54,8 @@ class test_extension_1 : public ten::extension_t { std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world 3, too") { cmd_result->set_property("detail", "hello world 3, too"); ten_env.return_result_directly(std::move(cmd_result)); @@ -83,7 +86,8 @@ class test_extension_1 : public ten::extension_t { [cmd_shared](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world 6, too") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 5, too"); diff --git a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic_wait_in_on_start.cc b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic_wait_in_on_start.cc index 2ff3c14e70..cd51b93aa3 100644 --- a/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic_wait_in_on_start.cc +++ b/tests/ten_runtime/smoke/extension_test/resp_handler/resp_handler_basic_wait_in_on_start.cc @@ -30,24 +30,26 @@ class test_extension_1 : public ten::extension_t { if (std::string(cmd->get_name()) == "hello_world_1") { auto test_string = std::make_shared("test test test"); - ten_env.send_cmd( - std::move(cmd), [test_string](ten::ten_env_t &ten_env, - std::unique_ptr cmd, - ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd->to_json()); + ten_env.send_cmd(std::move(cmd), + [test_string](ten::ten_env_t &ten_env, + std::unique_ptr cmd, + ten::error_t *err) { + nlohmann::json json = + nlohmann::json::parse(cmd->get_property_to_json()); - if (json.value("detail", "") == "hello world 1, too" && - *test_string == "test test test") { - cmd->set_property("detail", "hello world 1, too"); - ten_env.return_result_directly(std::move(cmd)); - } - }); + if (json.value("detail", "") == "hello world 1, too" && + *test_string == "test test test") { + cmd->set_property("detail", "hello world 1, too"); + ten_env.return_result_directly(std::move(cmd)); + } + }); } else if (std::string(cmd->get_name()) == "hello_world_2") { ten_env.send_cmd( std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world 2, too") { cmd_result->set_property("detail", "hello world 2, too"); ten_env.return_result_directly(std::move(cmd_result)); @@ -58,7 +60,8 @@ class test_extension_1 : public ten::extension_t { std::move(cmd), [](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world 3, too") { cmd_result->set_property("detail", "hello world 3, too"); ten_env.return_result_directly(std::move(cmd_result)); @@ -89,7 +92,8 @@ class test_extension_1 : public ten::extension_t { [cmd_shared](ten::ten_env_t &ten_env, std::unique_ptr cmd_result, ten::error_t *err) { - nlohmann::json json = nlohmann::json::parse(cmd_result->to_json()); + nlohmann::json json = + nlohmann::json::parse(cmd_result->get_property_to_json()); if (json.value("detail", "") == "hello world 6, too") { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world 5, too"); diff --git a/tests/ten_runtime/unit/ten_msg_test.cc b/tests/ten_runtime/unit/ten_msg_test.cc index 92b4593790..76977a8b9a 100644 --- a/tests/ten_runtime/unit/ten_msg_test.cc +++ b/tests/ten_runtime/unit/ten_msg_test.cc @@ -11,12 +11,12 @@ #include "ten_utils/lib/smart_ptr.h" TEST(TenMsgTest, create) { - ten_shared_ptr_t *data = ten_data_create(); + ten_shared_ptr_t *data = ten_data_create("test", nullptr); ten_shared_ptr_destroy(data); - ten_shared_ptr_t *audio_frame = ten_audio_frame_create(); + ten_shared_ptr_t *audio_frame = ten_audio_frame_create("test", nullptr); ten_shared_ptr_destroy(audio_frame); - ten_shared_ptr_t *video_frame = ten_video_frame_create(); + ten_shared_ptr_t *video_frame = ten_video_frame_create("test", nullptr); ten_shared_ptr_destroy(video_frame); }