Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor!: replace to/from_json with get/set_property_to/from_json #394

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_linux_ubuntu1804.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_linux_ubuntu2204.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
},
{
Expand Down
1 change: 0 additions & 1 deletion build/ten_runtime/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ class audio_frame_t : public msg_t {
};

public:
static std::unique_ptr<audio_frame_t> create(const char *audio_frame_name,
static std::unique_ptr<audio_frame_t> 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.");
}
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<audio_frame_t>(c_frame, ctor_passkey_t());
}
Expand Down
4 changes: 2 additions & 2 deletions core/include/ten_runtime/binding/cpp/detail/msg/cmd/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class cmd_t : public msg_t {
};

public:
static std::unique_ptr<cmd_t> create(const char *cmd_name,
static std::unique_ptr<cmd_t> 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<cmd_t>(c_cmd, ctor_passkey_t());
}
Expand Down
5 changes: 2 additions & 3 deletions core/include/ten_runtime/binding/cpp/detail/msg/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<data_t>(c_data, ctor_passkey_t());
}
Expand Down
86 changes: 13 additions & 73 deletions core/include/ten_runtime/binding/cpp/detail/msg/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ class video_frame_t : public msg_t {
};

public:
static std::unique_ptr<video_frame_t> create(const char *video_frame_name,
static std::unique_ptr<video_frame_t> 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.");
}
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<video_frame_t>(c_frame, ctor_passkey_t());
}
Expand Down
3 changes: 2 additions & 1 deletion core/include/ten_runtime/msg/audio_frame/audio_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/include/ten_runtime/msg/cmd/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
8 changes: 5 additions & 3 deletions core/include/ten_runtime/msg/data/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
3 changes: 2 additions & 1 deletion core/include/ten_runtime/msg/video_frame/video_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions core/include/ten_utils/value/value_get.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 0 additions & 6 deletions core/include_internal/ten_runtime/binding/python/msg/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading
Loading