diff --git a/.vscode/launch.json b/.vscode/launch.json index 9e3cc37ba..4f40cfca5 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.GetFloat64TypeButIntValue" + "--gtest_filter=PropertyTest.GetInt32" ], "cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/", "env": { diff --git a/core/include/ten_runtime/binding/cpp/detail/app.h b/core/include/ten_runtime/binding/cpp/detail/app.h index 041e2e9ec..7ef571f98 100644 --- a/core/include/ten_runtime/binding/cpp/detail/app.h +++ b/core/include/ten_runtime/binding/cpp/detail/app.h @@ -52,19 +52,16 @@ class app_t { return false; } - return ten_app_run( - c_app, run_in_background, - err != nullptr ? err->get_internal_representation() : nullptr); + return ten_app_run(c_app, run_in_background, + err != nullptr ? err->get_c_error() : nullptr); } bool close(error_t *err = nullptr) { - return ten_app_close( - c_app, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_app_close(c_app, err != nullptr ? err->get_c_error() : nullptr); } bool wait(error_t *err = nullptr) { - return ten_app_wait( - c_app, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_app_wait(c_app, err != nullptr ? err->get_c_error() : nullptr); } protected: 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 809dd9ef0..b702e390b 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 @@ -36,18 +36,16 @@ class audio_frame_t : public msg_t { static std::unique_ptr create(const char *audio_frame_name, error_t *err = nullptr) { if (audio_frame_name == nullptr || strlen(audio_frame_name) == 0) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, + 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_internal_representation() : nullptr); + ten_msg_set_name(c_frame, audio_frame_name, + err != nullptr ? err->get_c_error() : nullptr); return std::make_unique(c_frame, ctor_passkey_t()); } @@ -130,8 +128,7 @@ class audio_frame_t : public msg_t { ten_buf_t *data = ten_audio_frame_peek_buf(c_msg); if (!ten_msg_add_locked_res_buf( - c_msg, data->data, - err != nullptr ? err->get_internal_representation() : nullptr)) { + c_msg, data->data, err != nullptr ? err->get_c_error() : nullptr)) { return buf_t{}; } @@ -143,8 +140,7 @@ class audio_frame_t : public msg_t { bool unlock_buf(buf_t &buf, error_t *err = nullptr) { const uint8_t *data = buf.data(); if (!ten_msg_remove_locked_res_buf( - c_msg, data, - err != nullptr ? err->get_internal_representation() : nullptr)) { + c_msg, data, err != nullptr ? err->get_c_error() : nullptr)) { return false; } 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 9f4f86003..dfecf55ac 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 @@ -33,9 +33,8 @@ class cmd_t : public msg_t { public: static std::unique_ptr create(const char *cmd_name, error_t *err = nullptr) { - ten_shared_ptr_t *c_cmd = ten_cmd_create( - cmd_name, - err != nullptr ? err->get_internal_representation() : nullptr); + ten_shared_ptr_t *c_cmd = + ten_cmd_create(cmd_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/cmd/start_graph.h b/core/include/ten_runtime/binding/cpp/detail/msg/cmd/start_graph.h index 4d9af28be..ee7360cd4 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/cmd/start_graph.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/cmd/start_graph.h @@ -44,19 +44,18 @@ class cmd_start_graph_t : public cmd_t { error_t *err = nullptr) { return ten_cmd_start_graph_set_predefined_graph_name( c_msg, predefined_graph_name, - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); } bool set_graph_from_json(const char *json_str, error_t *err = nullptr) { return ten_cmd_start_graph_set_graph_from_json_str( - c_msg, json_str, - err != nullptr ? err->get_internal_representation() : nullptr); + c_msg, json_str, err != nullptr ? err->get_c_error() : nullptr); } bool set_long_running_mode(bool long_running_mode, error_t *err = nullptr) { return ten_cmd_start_graph_set_long_running_mode( c_msg, long_running_mode, - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); } // @{ diff --git a/core/include/ten_runtime/binding/cpp/detail/msg/cmd_result.h b/core/include/ten_runtime/binding/cpp/detail/msg/cmd_result.h index 5f7ab79b1..bcd422eb2 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/cmd_result.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/cmd_result.h @@ -50,18 +50,17 @@ class cmd_result_t : public msg_t { bool is_final(error_t *err = nullptr) const { return ten_cmd_result_is_final( - c_msg, err != nullptr ? err->get_internal_representation() : nullptr); + c_msg, err != nullptr ? err->get_c_error() : nullptr); } bool is_completed(error_t *err = nullptr) const { return ten_cmd_result_is_completed( - c_msg, err != nullptr ? err->get_internal_representation() : nullptr); + c_msg, err != nullptr ? err->get_c_error() : nullptr); } bool set_final(bool final, error_t *err = nullptr) { return ten_cmd_result_set_final( - c_msg, final, - err != nullptr ? err->get_internal_representation() : nullptr); + c_msg, final, err != nullptr ? err->get_c_error() : nullptr); } // @{ 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 04d532c28..08f1c8a4b 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/data.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/data.h @@ -38,17 +38,16 @@ class data_t : public msg_t { static std::unique_ptr create(const char *data_name, error_t *err = nullptr) { if (data_name == nullptr || strlen(data_name) == 0) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Data name cannot be empty."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Data name cannot be empty."); } return nullptr; } auto *c_data = ten_data_create(); - ten_msg_set_name( - c_data, data_name, - err != nullptr ? err->get_internal_representation() : nullptr); + ten_msg_set_name(c_data, data_name, + err != nullptr ? err->get_c_error() : nullptr); return std::make_unique(c_data, ctor_passkey_t()); } @@ -65,7 +64,7 @@ class data_t : public msg_t { buf_t lock_buf(error_t *err = nullptr) { if (!ten_msg_add_locked_res_buf( c_msg, ten_data_peek_buf(c_msg)->data, - err != nullptr ? err->get_internal_representation() : nullptr)) { + err != nullptr ? err->get_c_error() : nullptr)) { return {}; } @@ -77,8 +76,7 @@ class data_t : public msg_t { bool unlock_buf(buf_t &buf, error_t *err = nullptr) { if (!ten_msg_remove_locked_res_buf( - c_msg, buf.data(), - err != nullptr ? err->get_internal_representation() : nullptr)) { + c_msg, buf.data(), err != nullptr ? err->get_c_error() : nullptr)) { return false; } 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 8a63e1cbd..e557cbfee 100644 --- a/core/include/ten_runtime/binding/cpp/detail/msg/msg.h +++ b/core/include/ten_runtime/binding/cpp/detail/msg/msg.h @@ -59,9 +59,9 @@ class msg_t { TEN_MSG_TYPE get_type(error_t *err = nullptr) const { if (c_msg == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Invalid TEN message."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Invalid TEN message."); } return TEN_MSG_TYPE_INVALID; } @@ -73,8 +73,8 @@ class msg_t { TEN_ASSERT(c_msg, "Should not happen."); if (c_msg == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), TEN_ERRNO_GENERIC, + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_GENERIC, "Invalid TEN message."); } return ""; @@ -89,35 +89,35 @@ class msg_t { TEN_ASSERT(c_msg, "Should not happen."); if (c_msg == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Invalid TEN message."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Invalid TEN message."); } return false; } return ten_msg_clear_and_set_dest( c_msg, uri, graph, extension_group_name, extension_name, - err != nullptr ? err->get_internal_representation() : nullptr); + 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_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), TEN_ERRNO_GENERIC, + 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_internal_representation() : nullptr); + 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_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), TEN_ERRNO_GENERIC, + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_GENERIC, "Invalid TEN message."); } return ""; @@ -140,8 +140,8 @@ class msg_t { TEN_ASSERT(c_msg, "Should not happen."); if (c_msg == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), TEN_ERRNO_GENERIC, + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_GENERIC, "Invalid TEN message."); } return false; @@ -150,16 +150,14 @@ class msg_t { bool result = true; ten_json_t *c_json = ten_json_from_string( - json_str, - err != nullptr ? err->get_internal_representation() : nullptr); + 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_internal_representation() : nullptr); + 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) @@ -177,16 +175,15 @@ class msg_t { TEN_ASSERT(path && strlen(path), "path should not be empty."); if (c_msg == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Invalid TEN message."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Invalid TEN message."); } return false; } return ten_msg_is_property_exist( - c_msg, path, - err != nullptr ? err->get_internal_representation() : nullptr); + c_msg, path, err != nullptr ? err->get_c_error() : nullptr); } virtual uint8_t get_property_uint8(const char *path, error_t *err) { @@ -194,8 +191,8 @@ class msg_t { if (c_value == nullptr) { return 0; } - return ten_value_get_uint8( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_uint8(c_value, + err != nullptr ? err->get_c_error() : nullptr); } uint8_t get_property_uint8(const char *path) { @@ -207,8 +204,8 @@ class msg_t { if (c_value == nullptr) { return 0; } - return ten_value_get_uint16( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_uint16(c_value, + err != nullptr ? err->get_c_error() : nullptr); } uint16_t get_property_uint16(const char *path) { @@ -220,8 +217,8 @@ class msg_t { if (c_value == nullptr) { return 0; } - return ten_value_get_uint32( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_uint32(c_value, + err != nullptr ? err->get_c_error() : nullptr); } uint32_t get_property_uint32(const char *path) { @@ -233,8 +230,8 @@ class msg_t { if (c_value == nullptr) { return 0; } - return ten_value_get_uint64( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_uint64(c_value, + err != nullptr ? err->get_c_error() : nullptr); } uint64_t get_property_uint64(const char *path) { @@ -246,8 +243,8 @@ class msg_t { if (c_value == nullptr) { return 0; } - return ten_value_get_int8( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_int8(c_value, + err != nullptr ? err->get_c_error() : nullptr); } int8_t get_property_int8(const char *path) { @@ -259,8 +256,8 @@ class msg_t { if (c_value == nullptr) { return 0; } - return ten_value_get_int16( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_int16(c_value, + err != nullptr ? err->get_c_error() : nullptr); } int16_t get_property_int16(const char *path) { @@ -272,8 +269,8 @@ class msg_t { if (c_value == nullptr) { return 0; } - return ten_value_get_int32( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_int32(c_value, + err != nullptr ? err->get_c_error() : nullptr); } int32_t get_property_int32(const char *path) { @@ -285,8 +282,8 @@ class msg_t { if (c_value == nullptr) { return 0; } - return ten_value_get_int64( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_int64(c_value, + err != nullptr ? err->get_c_error() : nullptr); } int64_t get_property_int64(const char *path) { @@ -298,8 +295,8 @@ class msg_t { if (c_value == nullptr) { return 0.0F; } - return ten_value_get_float32( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_float32(c_value, + err != nullptr ? err->get_c_error() : nullptr); } float get_property_float32(const char *path) { @@ -311,8 +308,8 @@ class msg_t { if (c_value == nullptr) { return 0.0F; } - return ten_value_get_float64( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_float64(c_value, + err != nullptr ? err->get_c_error() : nullptr); } double get_property_float64(const char *path) { @@ -324,7 +321,8 @@ class msg_t { if (c_value == nullptr) { return ""; } - return ten_value_peek_raw_str(c_value); + return ten_value_peek_raw_str( + c_value, err != nullptr ? err->get_c_error() : nullptr); } std::string get_property_string(const char *path) { @@ -336,8 +334,8 @@ class msg_t { if (c_value == nullptr) { return nullptr; } - return ten_value_get_ptr( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_ptr(c_value, + err != nullptr ? err->get_c_error() : nullptr); } void *get_property_ptr(const char *path) { @@ -349,8 +347,8 @@ class msg_t { if (c_value == nullptr) { return false; } - return ten_value_get_bool( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + return ten_value_get_bool(c_value, + err != nullptr ? err->get_c_error() : nullptr); } bool get_property_bool(const char *path) { @@ -381,9 +379,9 @@ class msg_t { TEN_ASSERT(path && strlen(path), "path should not be empty."); if (c_msg == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Invalid TEN message."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Invalid TEN message."); } return ""; } @@ -503,9 +501,9 @@ class msg_t { virtual bool set_property(const char *path, void *value, error_t *err) { if (value == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Invalid argment."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Invalid argment."); } return false; } @@ -519,9 +517,9 @@ class msg_t { virtual bool set_property(const char *path, const char *value, error_t *err) { if (value == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Invalid argment."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Invalid argment."); } return false; } @@ -545,9 +543,9 @@ class msg_t { virtual bool set_property(const char *path, const ten::buf_t &value, error_t *err) { if (value.data() == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Invalid argment."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Invalid argment."); } return false; } @@ -565,7 +563,7 @@ class msg_t { TEN_ASSERT(c_msg, "Should not happen."); ten_json_t *c_json = ten_json_from_string( - json, err != nullptr ? err->get_internal_representation() : nullptr); + json, err != nullptr ? err->get_c_error() : nullptr); if (c_json == nullptr) { return false; } @@ -599,8 +597,7 @@ class msg_t { TEN_ASSERT(c_msg, "Should not happen."); bool rc = ten_msg_set_property( - c_msg, path, value, - err != nullptr ? err->get_internal_representation() : nullptr); + c_msg, path, value, err != nullptr ? err->get_c_error() : nullptr); if (!rc) { ten_value_destroy(value); @@ -621,9 +618,8 @@ class msg_t { ten_value_t *peek_property_value(const char *path, error_t *err) const { TEN_ASSERT(c_msg, "Should not happen."); - return ten_msg_peek_property( - c_msg, path, - err != nullptr ? err->get_internal_representation() : nullptr); + return ten_msg_peek_property(c_msg, path, + err != nullptr ? err->get_c_error() : 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 acba01f74..809e8099a 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 @@ -36,18 +36,16 @@ class video_frame_t : public msg_t { static std::unique_ptr create(const char *video_frame_name, error_t *err = nullptr) { if (video_frame_name == nullptr || strlen(video_frame_name) == 0) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, + 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_internal_representation() : nullptr); + ten_msg_set_name(c_frame, video_frame_name, + err != nullptr ? err->get_c_error() : nullptr); return std::make_unique(c_frame, ctor_passkey_t()); } @@ -100,7 +98,7 @@ class video_frame_t : public msg_t { buf_t lock_buf(error_t *err = nullptr) const { if (!ten_msg_add_locked_res_buf( c_msg, ten_video_frame_peek_data(c_msg)->data, - err != nullptr ? err->get_internal_representation() : nullptr)) { + err != nullptr ? err->get_c_error() : nullptr)) { return buf_t{}; } @@ -113,8 +111,7 @@ class video_frame_t : public msg_t { bool unlock_buf(buf_t &buf, error_t *err = nullptr) { const uint8_t *data = buf.data(); if (!ten_msg_remove_locked_res_buf( - c_msg, data, - err != nullptr ? err->get_internal_representation() : nullptr)) { + c_msg, data, err != nullptr ? err->get_c_error() : nullptr)) { return false; } diff --git a/core/include/ten_runtime/binding/cpp/detail/ten_env.h b/core/include/ten_runtime/binding/cpp/detail/ten_env.h index 681344b41..0f8ce7495 100644 --- a/core/include/ten_runtime/binding/cpp/detail/ten_env.h +++ b/core/include/ten_runtime/binding/cpp/detail/ten_env.h @@ -84,9 +84,9 @@ class ten_env_t { } if (data->get_underlying_msg() == nullptr) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "Invalid data."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "Invalid data."); } return false; } @@ -94,17 +94,16 @@ class ten_env_t { auto rc = false; if (error_handler == nullptr) { - rc = ten_env_send_data( - c_ten_env, data->get_underlying_msg(), nullptr, nullptr, - err != nullptr ? err->get_internal_representation() : nullptr); + rc = ten_env_send_data(c_ten_env, data->get_underlying_msg(), nullptr, + nullptr, + err != nullptr ? err->get_c_error() : nullptr); } else { auto *error_handler_ptr = new error_handler_func_t(std::move(error_handler)); - rc = ten_env_send_data( - c_ten_env, data->get_underlying_msg(), proxy_handle_error, - error_handler_ptr, - err != nullptr ? err->get_internal_representation() : nullptr); + rc = ten_env_send_data(c_ten_env, data->get_underlying_msg(), + proxy_handle_error, error_handler_ptr, + err != nullptr ? err->get_c_error() : nullptr); if (!rc) { delete error_handler_ptr; } @@ -137,15 +136,14 @@ class ten_env_t { if (error_handler == nullptr) { rc = ten_env_send_video_frame( c_ten_env, frame->get_underlying_msg(), nullptr, nullptr, - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); } else { auto *error_handler_ptr = new error_handler_func_t(std::move(error_handler)); rc = ten_env_send_video_frame( c_ten_env, frame->get_underlying_msg(), proxy_handle_error, - error_handler_ptr, - err != nullptr ? err->get_internal_representation() : nullptr); + error_handler_ptr, err != nullptr ? err->get_c_error() : nullptr); if (!rc) { delete error_handler_ptr; } @@ -178,15 +176,14 @@ class ten_env_t { if (error_handler == nullptr) { rc = ten_env_send_audio_frame( c_ten_env, frame->get_underlying_msg(), nullptr, nullptr, - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); } else { auto *error_handler_ptr = new error_handler_func_t(std::move(error_handler)); rc = ten_env_send_audio_frame( c_ten_env, frame->get_underlying_msg(), proxy_handle_error, - error_handler_ptr, - err != nullptr ? err->get_internal_representation() : nullptr); + error_handler_ptr, err != nullptr ? err->get_c_error() : nullptr); if (!rc) { delete error_handler_ptr; } @@ -215,7 +212,7 @@ class ten_env_t { auto rc = ten_env_return_result_directly( c_ten_env, cmd->get_underlying_msg(), - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); if (rc) { // The 'cmd' has been returned, so we should release the ownership of @@ -243,7 +240,7 @@ class ten_env_t { auto rc = ten_env_return_result( c_ten_env, cmd->get_underlying_msg(), target_cmd->get_underlying_msg(), - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); if (rc) { if (cmd->is_final()) { @@ -267,16 +264,15 @@ class ten_env_t { TEN_ASSERT(c_ten_env, "Should not happen."); if ((path == nullptr) || (strlen(path) == 0)) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "path should not be empty."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "path should not be empty."); } return false; } return ten_env_is_property_exist( - c_ten_env, path, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, path, err != nullptr ? err->get_c_error() : nullptr); } bool init_property_from_json(const char *json_str, error_t *err = nullptr) { @@ -288,17 +284,16 @@ class ten_env_t { } return ten_env_init_property_from_json( - c_ten_env, json_str, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, json_str, err != nullptr ? err->get_c_error() : nullptr); } std::string get_property_to_json(const char *path, error_t *err = nullptr) { std::string result; if ((path == nullptr) || (strlen(path) == 0)) { - if (err != nullptr && err->get_internal_representation() != nullptr) { - ten_error_set(err->get_internal_representation(), - TEN_ERRNO_INVALID_ARGUMENT, "path should not be empty."); + if (err != nullptr && err->get_c_error() != nullptr) { + ten_error_set(err->get_c_error(), TEN_ERRNO_INVALID_ARGUMENT, + "path should not be empty."); } return result; } @@ -329,8 +324,7 @@ class ten_env_t { bool set_property_from_json(const char *path, const char *json_str, error_t *err = nullptr) { ten_json_t *c_json = ten_json_from_string( - json_str, - err != nullptr ? err->get_internal_representation() : nullptr); + json_str, err != nullptr ? err->get_c_error() : nullptr); if (c_json == nullptr) { return false; } @@ -346,8 +340,17 @@ class ten_env_t { if (c_value == nullptr) { return 0; } - return ten_value_get_uint8( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_uint8(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } uint16_t get_property_uint16(const char *path, error_t *err = nullptr) { @@ -355,8 +358,17 @@ class ten_env_t { if (c_value == nullptr) { return 0; } - return ten_value_get_uint16( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_uint16(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } uint32_t get_property_uint32(const char *path, error_t *err = nullptr) { @@ -364,8 +376,17 @@ class ten_env_t { if (c_value == nullptr) { return 0; } - return ten_value_get_uint32( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_uint32(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } uint64_t get_property_uint64(const char *path, error_t *err = nullptr) { @@ -373,8 +394,17 @@ class ten_env_t { if (c_value == nullptr) { return 0; } - return ten_value_get_uint64( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_uint64(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } int8_t get_property_int8(const char *path, error_t *err = nullptr) { @@ -382,8 +412,17 @@ class ten_env_t { if (c_value == nullptr) { return 0; } - return ten_value_get_int8( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_int8(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } int16_t get_property_int16(const char *path, error_t *err = nullptr) { @@ -391,8 +430,17 @@ class ten_env_t { if (c_value == nullptr) { return 0; } - return ten_value_get_int16( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_int16(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } int32_t get_property_int32(const char *path, error_t *err = nullptr) { @@ -400,8 +448,17 @@ class ten_env_t { if (c_value == nullptr) { return 0; } - return ten_value_get_int32( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_int32(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } int64_t get_property_int64(const char *path, error_t *err = nullptr) { @@ -409,8 +466,17 @@ class ten_env_t { if (c_value == nullptr) { return 0; } - return ten_value_get_int64( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_int64(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } float get_property_float32(const char *path, error_t *err = nullptr) { @@ -418,8 +484,17 @@ class ten_env_t { if (c_value == nullptr) { return 0.0F; } - return ten_value_get_float32( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_float32(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } double get_property_float64(const char *path, error_t *err = nullptr) { @@ -427,8 +502,17 @@ class ten_env_t { if (c_value == nullptr) { return 0.0F; } - return ten_value_get_float64( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto result = ten_value_get_float64(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } std::string get_property_string(const char *path, error_t *err = nullptr) { @@ -436,7 +520,21 @@ class ten_env_t { if (c_value == nullptr) { return ""; } - return ten_value_peek_raw_str(c_value); + + error_t cpp_err; + const auto *result = ten_value_peek_raw_str(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + if (result != nullptr) { + return result; + } else { + return ""; + } } void *get_property_ptr(const char *path, error_t *err = nullptr) { @@ -444,8 +542,17 @@ class ten_env_t { if (c_value == nullptr) { return nullptr; } - return ten_value_get_ptr( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + + error_t cpp_err; + auto *result = ten_value_get_ptr(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } bool get_property_bool(const char *path, error_t *err = nullptr) { @@ -454,8 +561,16 @@ class ten_env_t { return false; } - return ten_value_get_bool( - c_value, err != nullptr ? err->get_internal_representation() : nullptr); + error_t cpp_err; + auto result = ten_value_get_bool(c_value, cpp_err.get_c_error()); + if (!cpp_err.is_success()) { + TEN_LOGW("Failed to get property %s because of incorrect type.", path); + } + if (err != nullptr) { + ten_error_copy(err->get_c_error(), cpp_err.get_c_error()); + } + + return result; } bool set_property(const char *path, int8_t value, error_t *err = nullptr) { @@ -528,16 +643,14 @@ class ten_env_t { bool is_cmd_connected(const char *cmd_name, error_t *err = nullptr) { TEN_ASSERT(c_ten_env, "Should not happen."); return ten_env_is_cmd_connected( - c_ten_env, cmd_name, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, cmd_name, err != nullptr ? err->get_c_error() : nullptr); } bool on_configure_done(error_t *err = nullptr) { TEN_ASSERT(c_ten_env, "Should not happen."); bool rc = ten_env_on_configure_done( - c_ten_env, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, err != nullptr ? err->get_c_error() : nullptr); return rc; } @@ -546,8 +659,7 @@ class ten_env_t { TEN_ASSERT(c_ten_env, "Should not happen."); bool rc = ten_env_on_init_done( - c_ten_env, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, err != nullptr ? err->get_c_error() : nullptr); return rc; } @@ -555,22 +667,19 @@ class ten_env_t { bool on_deinit_done(error_t *err = nullptr) { TEN_ASSERT(c_ten_env, "Should not happen."); return ten_env_on_deinit_done( - c_ten_env, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, err != nullptr ? err->get_c_error() : nullptr); } bool on_start_done(error_t *err = nullptr) { TEN_ASSERT(c_ten_env, "Should not happen."); - return ten_env_on_start_done( - c_ten_env, - err != nullptr ? err->get_internal_representation() : nullptr); + return ten_env_on_start_done(c_ten_env, + err != nullptr ? err->get_c_error() : nullptr); } bool on_stop_done(error_t *err = nullptr) { TEN_ASSERT(c_ten_env, "Should not happen."); - return ten_env_on_stop_done( - c_ten_env, - err != nullptr ? err->get_internal_representation() : nullptr); + return ten_env_on_stop_done(c_ten_env, + err != nullptr ? err->get_c_error() : nullptr); } bool on_create_instance_done(void *instance, void *context, @@ -578,8 +687,7 @@ class ten_env_t { bool on_destroy_instance_done(void *context, error_t *err = nullptr) { bool rc = ten_env_on_destroy_instance_done( - c_ten_env, context, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, context, err != nullptr ? err->get_c_error() : nullptr); return rc; } @@ -679,17 +787,15 @@ class ten_env_t { } if (result_handler == nullptr) { - rc = send_cmd_func( - c_ten_env, cmd->get_underlying_msg(), nullptr, nullptr, - err != nullptr ? err->get_internal_representation() : nullptr); + rc = send_cmd_func(c_ten_env, cmd->get_underlying_msg(), nullptr, nullptr, + err != nullptr ? err->get_c_error() : nullptr); } else { auto *result_handler_ptr = new result_handler_func_t(std::move(result_handler)); - rc = send_cmd_func( - c_ten_env, cmd->get_underlying_msg(), proxy_handle_result, - result_handler_ptr, - err != nullptr ? err->get_internal_representation() : nullptr); + rc = send_cmd_func(c_ten_env, cmd->get_underlying_msg(), + proxy_handle_result, result_handler_ptr, + err != nullptr ? err->get_c_error() : nullptr); if (!rc) { delete result_handler_ptr; } @@ -710,9 +816,8 @@ class ten_env_t { ten_value_t *peek_property_value(const char *path, error_t *err) { TEN_ASSERT(c_ten_env, "Should not happen."); - return ten_env_peek_property( - c_ten_env, path, - err != nullptr ? err->get_internal_representation() : nullptr); + return ten_env_peek_property(c_ten_env, path, + err != nullptr ? err->get_c_error() : nullptr); } /** @@ -723,8 +828,7 @@ class ten_env_t { TEN_ASSERT(c_ten_env, "Should not happen."); bool rc = ten_env_set_property( - c_ten_env, path, value, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, path, value, err != nullptr ? err->get_c_error() : nullptr); if (!rc) { ten_value_destroy(value); diff --git a/core/include/ten_runtime/binding/cpp/detail/ten_env_impl.h b/core/include/ten_runtime/binding/cpp/detail/ten_env_impl.h index af850f111..c1110ba2d 100644 --- a/core/include/ten_runtime/binding/cpp/detail/ten_env_impl.h +++ b/core/include/ten_runtime/binding/cpp/detail/ten_env_impl.h @@ -38,7 +38,7 @@ inline bool ten_env_t::on_create_instance_done(void *instance, void *context, bool rc = ten_env_on_create_instance_done( c_ten_env, c_instance, cpp_context->c_context, - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); delete cpp_context; diff --git a/core/include/ten_runtime/binding/cpp/detail/ten_env_proxy.h b/core/include/ten_runtime/binding/cpp/detail/ten_env_proxy.h index 26c2111e7..6886bf7bc 100644 --- a/core/include/ten_runtime/binding/cpp/detail/ten_env_proxy.h +++ b/core/include/ten_runtime/binding/cpp/detail/ten_env_proxy.h @@ -109,8 +109,7 @@ class ten_env_proxy_t { } return ten_env_proxy_acquire_lock_mode( - c_ten_env_proxy, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env_proxy, err != nullptr ? err->get_c_error() : nullptr); } bool acquire_lock_mode() { return acquire_lock_mode(nullptr); } @@ -122,8 +121,7 @@ class ten_env_proxy_t { } return ten_env_proxy_release_lock_mode( - c_ten_env_proxy, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env_proxy, err != nullptr ? err->get_c_error() : nullptr); } bool release_lock_mode() { return release_lock_mode(nullptr); } @@ -131,9 +129,9 @@ class ten_env_proxy_t { bool notify(notify_std_func_t &¬ify_func, bool sync, error_t *err) { auto *info = new proxy_notify_info_t(std::move(notify_func)); - auto rc = ten_env_proxy_notify( - c_ten_env_proxy, proxy_notify, info, sync, - err != nullptr ? err->get_internal_representation() : nullptr); + auto rc = + ten_env_proxy_notify(c_ten_env_proxy, proxy_notify, info, sync, + err != nullptr ? err->get_c_error() : nullptr); if (!rc) { delete info; } @@ -157,9 +155,9 @@ class ten_env_proxy_t { bool sync, error_t *err) { auto *info = new proxy_notify_info_t(std::move(notify_func), user_data); - auto rc = ten_env_proxy_notify( - c_ten_env_proxy, proxy_notify, info, sync, - err != nullptr ? err->get_internal_representation() : nullptr); + auto rc = + ten_env_proxy_notify(c_ten_env_proxy, proxy_notify, info, sync, + err != nullptr ? err->get_c_error() : nullptr); if (!rc) { delete info; } @@ -194,7 +192,7 @@ class ten_env_proxy_t { // } // return ten_proxy_acquire( // c_ten_env_proxy, - // err != nullptr ? err->get_internal_representation() : nullptr); + // err != nullptr ? err->get_c_error() : nullptr); // } // // bool release(error_t *err = nullptr) { @@ -204,7 +202,7 @@ class ten_env_proxy_t { // } // bool rc = ten_proxy_release( // c_ten_env_proxy, - // err != nullptr ? err->get_internal_representation() : nullptr); + // err != nullptr ? err->get_c_error() : nullptr); // TEN_ASSERT(rc, "Should not happen."); // return rc; // } diff --git a/core/include/ten_runtime/binding/cpp/detail/test/env_tester.h b/core/include/ten_runtime/binding/cpp/detail/test/env_tester.h index aea41126d..2ae10bbe4 100644 --- a/core/include/ten_runtime/binding/cpp/detail/test/env_tester.h +++ b/core/include/ten_runtime/binding/cpp/detail/test/env_tester.h @@ -40,8 +40,7 @@ class ten_env_tester_t { bool on_start_done(error_t *err = nullptr) { TEN_ASSERT(c_ten_env_tester, "Should not happen."); return ten_env_tester_on_start_done( - c_ten_env_tester, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env_tester, err != nullptr ? err->get_c_error() : nullptr); } bool send_cmd( @@ -60,7 +59,7 @@ class ten_env_tester_t { if (result_handler == nullptr) { rc = ten_env_tester_send_cmd( c_ten_env_tester, cmd->get_underlying_msg(), nullptr, nullptr, - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); } else { auto *result_handler_ptr = new ten_env_tester_send_cmd_result_handler_func_t( @@ -68,8 +67,7 @@ class ten_env_tester_t { rc = ten_env_tester_send_cmd( c_ten_env_tester, cmd->get_underlying_msg(), proxy_handle_result, - result_handler_ptr, - err != nullptr ? err->get_internal_representation() : nullptr); + result_handler_ptr, err != nullptr ? err->get_c_error() : nullptr); if (!rc) { delete result_handler_ptr; } @@ -97,9 +95,9 @@ class ten_env_tester_t { return rc; } - rc = ten_env_tester_send_data( - c_ten_env_tester, data->get_underlying_msg(), - err != nullptr ? err->get_internal_representation() : nullptr); + rc = + ten_env_tester_send_data(c_ten_env_tester, data->get_underlying_msg(), + err != nullptr ? err->get_c_error() : nullptr); if (rc) { // Only when the data has been sent successfully, we should give back the @@ -126,7 +124,7 @@ class ten_env_tester_t { rc = ten_env_tester_send_audio_frame( c_ten_env_tester, audio_frame->get_underlying_msg(), - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); if (rc) { // Only when the audio_frame has been sent successfully, we should give @@ -153,7 +151,7 @@ class ten_env_tester_t { rc = ten_env_tester_send_video_frame( c_ten_env_tester, video_frame->get_underlying_msg(), - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); if (rc) { // Only when the video_frame has been sent successfully, we should give @@ -170,8 +168,7 @@ class ten_env_tester_t { bool stop_test(error_t *err = nullptr) { TEN_ASSERT(c_ten_env_tester, "Should not happen."); return ten_env_tester_stop_test( - c_ten_env_tester, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env_tester, err != nullptr ? err->get_c_error() : nullptr); } private: diff --git a/core/include/ten_runtime/binding/cpp/detail/test/env_tester_proxy.h b/core/include/ten_runtime/binding/cpp/detail/test/env_tester_proxy.h index 1a67f6cee..e7b56d516 100644 --- a/core/include/ten_runtime/binding/cpp/detail/test/env_tester_proxy.h +++ b/core/include/ten_runtime/binding/cpp/detail/test/env_tester_proxy.h @@ -105,7 +105,7 @@ class ten_env_tester_proxy_t { auto rc = ten_env_tester_proxy_notify( c_ten_env_tester_proxy, proxy_notify, info, - err != nullptr ? err->get_internal_representation() : nullptr); + err != nullptr ? err->get_c_error() : nullptr); if (!rc) { delete info; } diff --git a/core/include/ten_utils/lang/cpp/lib/error.h b/core/include/ten_utils/lang/cpp/lib/error.h index ecace45e3..232465e11 100644 --- a/core/include/ten_utils/lang/cpp/lib/error.h +++ b/core/include/ten_utils/lang/cpp/lib/error.h @@ -36,7 +36,7 @@ class error_t { const char *errmsg() { return ten_error_errmsg(c_error); } // Internal use only. - ten_error_t *get_internal_representation() { return c_error; } + ten_error_t *get_c_error() { return c_error; } private: ten_error_t *c_error; diff --git a/core/include/ten_utils/lang/cpp/lib/value.h b/core/include/ten_utils/lang/cpp/lib/value.h index 0b8f0801c..27f105495 100644 --- a/core/include/ten_utils/lang/cpp/lib/value.h +++ b/core/include/ten_utils/lang/cpp/lib/value.h @@ -359,7 +359,7 @@ class value_t { std::vector result; auto size = ten_value_array_size(c_value_); for (size_t i = 0; i < size; ++i) { - auto *v = ten_value_array_peek(c_value_, i); + auto *v = ten_value_array_peek(c_value_, i, nullptr); TEN_ASSERT(v, "Invalid argument."); result.push_back(value_t(ten_value_clone(v))); @@ -397,7 +397,7 @@ class value_t { (void)err; // TODO(Liu): pass `err` to the underlying function. - const char *result = ten_value_peek_raw_str(c_value_); + const char *result = ten_value_peek_raw_str(c_value_, err); if (result != nullptr) { return result; } else { diff --git a/core/include/ten_utils/lib/error.h b/core/include/ten_utils/lib/error.h index 98de6c6cf..5fd6e7d20 100644 --- a/core/include/ten_utils/lib/error.h +++ b/core/include/ten_utils/lib/error.h @@ -36,6 +36,8 @@ TEN_UTILS_API void ten_error_deinit(ten_error_t *self); TEN_UTILS_API ten_error_t *ten_error_create(void); +TEN_UTILS_API void ten_error_copy(ten_error_t *self, ten_error_t *other); + // Set error info, return true if set success, false otherwise. TEN_UTILS_API bool ten_error_set(ten_error_t *self, ten_errno_t err_no, const char *fmt, ...); diff --git a/core/include/ten_utils/value/value_get.h b/core/include/ten_utils/value/value_get.h index d85f235b8..5f61fddb1 100644 --- a/core/include/ten_utils/value/value_get.h +++ b/core/include/ten_utils/value/value_get.h @@ -47,7 +47,8 @@ TEN_UTILS_API bool ten_value_get_bool(ten_value_t *self, ten_error_t *err); TEN_UTILS_API ten_string_t *ten_value_peek_string(ten_value_t *self); -TEN_UTILS_API const char *ten_value_peek_raw_str(ten_value_t *self); +TEN_UTILS_API const char *ten_value_peek_raw_str(ten_value_t *self, + ten_error_t *err); TEN_UTILS_API void *ten_value_get_ptr(ten_value_t *self, ten_error_t *err); @@ -55,5 +56,5 @@ 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_value_t *ten_value_array_peek(ten_value_t *self, - size_t index); +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/cpp/detail/ten_env_impl.h b/core/include_internal/ten_runtime/binding/cpp/detail/ten_env_impl.h index 0b778639e..f4c3f7069 100644 --- a/core/include_internal/ten_runtime/binding/cpp/detail/ten_env_impl.h +++ b/core/include_internal/ten_runtime/binding/cpp/detail/ten_env_impl.h @@ -20,8 +20,7 @@ inline bool ten_env_t::init_manifest_from_json(const char *json, error_t *err) { } return ten_env_init_manifest_from_json( - c_ten_env, json, - err != nullptr ? err->get_internal_representation() : nullptr); + c_ten_env, json, err != nullptr ? err->get_c_error() : nullptr); } } // namespace ten diff --git a/core/src/ten_manager/src/solver/display.lp b/core/src/ten_manager/src/solver/display.lp index f43ea8ca7..ccf2f700d 100644 --- a/core/src/ten_manager/src/solver/display.lp +++ b/core/src/ten_manager/src/solver/display.lp @@ -1,3 +1,10 @@ +% +% 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. +% + %=============================================================================- % Display Results % diff --git a/core/src/ten_manager/src/solver/input_sample.lp b/core/src/ten_manager/src/solver/input_sample.lp index ac8904359..9cbb894b3 100644 --- a/core/src/ten_manager/src/solver/input_sample.lp +++ b/core/src/ten_manager/src/solver/input_sample.lp @@ -1,3 +1,10 @@ +% +% 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. +% + %----------------------------------------------------------------------------- % Facts %----------------------------------------------------------------------------- diff --git a/core/src/ten_manager/src/solver/main.lp b/core/src/ten_manager/src/solver/main.lp index 2154a3bc7..a431234cb 100644 --- a/core/src/ten_manager/src/solver/main.lp +++ b/core/src/ten_manager/src/solver/main.lp @@ -1,3 +1,10 @@ +% +% 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. +% + % The rule for predicate names: Predicate names ending with '_declared' are % defined by the user (from Clingo's perspective). diff --git a/core/src/ten_runtime/addon/protocol/protocol.c b/core/src/ten_runtime/addon/protocol/protocol.c index 810353d05..ced0de3ed 100644 --- a/core/src/ten_runtime/addon/protocol/protocol.c +++ b/core/src/ten_runtime/addon/protocol/protocol.c @@ -73,7 +73,8 @@ static bool ten_addon_protocol_match_protocol(ten_addon_host_t *self, addon_protocol_value && ten_value_check_integrity(addon_protocol_value), "Should not happen."); - const char *addon_protocol = ten_value_peek_raw_str(addon_protocol_value); + const char *addon_protocol = + ten_value_peek_raw_str(addon_protocol_value, NULL); if (!strcmp(addon_protocol, protocol)) { found = true; break; diff --git a/core/src/ten_runtime/addon/ten_env/on_xxx.c b/core/src/ten_runtime/addon/ten_env/on_xxx.c index c779b215d..c02d7b5b2 100644 --- a/core/src/ten_runtime/addon/ten_env/on_xxx.c +++ b/core/src/ten_runtime/addon/ten_env/on_xxx.c @@ -57,16 +57,16 @@ void ten_addon_on_init_done(ten_env_t *self) { exit(EXIT_FAILURE); } - ten_error_deinit(&err); - ten_value_t *manifest_name_value = ten_value_object_peek(&addon_host->manifest, TEN_STR_NAME); const char *manifest_name = NULL; if (manifest_name_value) { - manifest_name = ten_value_peek_raw_str(manifest_name_value); + manifest_name = ten_value_peek_raw_str(manifest_name_value, &err); } + ten_error_deinit(&err); + if (manifest_name) { TEN_ASSERT(manifest_name, "Should not happen."); diff --git a/core/src/ten_runtime/app/metadata.c b/core/src/ten_runtime/app/metadata.c index aca6b97cc..e9a935146 100644 --- a/core/src/ten_runtime/app/metadata.c +++ b/core/src/ten_runtime/app/metadata.c @@ -88,8 +88,8 @@ bool ten_app_init_uri(ten_app_t *self, ten_value_t *value) { ten_string_t default_url; ten_string_init_formatted(&default_url, TEN_STR_LOCALHOST); - const char *url_str = ten_value_peek_raw_str(value) - ? ten_value_peek_raw_str(value) + const char *url_str = ten_value_peek_raw_str(value, NULL) + ? ten_value_peek_raw_str(value, NULL) : ten_string_get_raw_str(&default_url); ten_string_set_from_c_str(&self->uri, url_str, strlen(url_str)); @@ -120,8 +120,8 @@ bool ten_app_init_log_file(ten_app_t *self, ten_value_t *value) { ten_string_t log_file; ten_string_init(&log_file); - ten_string_init_from_c_str(&log_file, ten_value_peek_raw_str(value), - strlen(ten_value_peek_raw_str(value))); + ten_string_init_from_c_str(&log_file, ten_value_peek_raw_str(value, NULL), + strlen(ten_value_peek_raw_str(value, NULL))); if (!ten_string_is_empty(&log_file)) { ten_log_global_set_output_to_file(ten_string_get_raw_str(&log_file)); diff --git a/core/src/ten_runtime/app/predefined_graph.c b/core/src/ten_runtime/app/predefined_graph.c index e902c9656..cff2d3030 100644 --- a/core/src/ten_runtime/app/predefined_graph.c +++ b/core/src/ten_runtime/app/predefined_graph.c @@ -351,8 +351,8 @@ bool ten_app_get_predefined_graphs_from_property(ten_app_t *self) { } ten_string_set_from_c_str( &predefined_graph_info->name, - ten_value_peek_raw_str(predefined_graph_info_name_value), - strlen(ten_value_peek_raw_str(predefined_graph_info_name_value))); + ten_value_peek_raw_str(predefined_graph_info_name_value, &err), + strlen(ten_value_peek_raw_str(predefined_graph_info_name_value, &err))); ten_value_t *predefined_graph_info_auto_start_value = ten_value_object_peek(predefined_graph_info_value, TEN_STR_AUTO_START); @@ -399,7 +399,7 @@ bool ten_app_get_predefined_graphs_from_property(ten_app_t *self) { goto done; } - const char *type = ten_value_peek_raw_str(type_value); + const char *type = ten_value_peek_raw_str(type_value, &err); // Only the extension node is preferred. result = ten_c_string_is_equal(type, TEN_STR_EXTENSION); diff --git a/core/src/ten_runtime/binding/go/native/value/value.c b/core/src/ten_runtime/binding/go/native/value/value.c index 782438cd0..4cdb42d9f 100644 --- a/core/src/ten_runtime/binding/go/native/value/value.c +++ b/core/src/ten_runtime/binding/go/native/value/value.c @@ -126,7 +126,7 @@ void ten_go_ten_value_get_type_and_size(ten_value_t *self, uint8_t *type, } case TEN_TYPE_STRING: { - const char *str = ten_value_peek_raw_str(self); + const char *str = ten_value_peek_raw_str(self, NULL); TEN_ASSERT(str, "Should not happen."); *size = strlen(str); @@ -149,7 +149,7 @@ void ten_go_ten_value_get_string(ten_value_t *self, void *value, return; } - const char *str_value = ten_value_peek_raw_str(self); + const char *str_value = ten_value_peek_raw_str(self, NULL); TEN_ASSERT(str_value, "Should not happen"); // The value is a pointer to a GO slice which has no space for the null diff --git a/core/src/ten_runtime/binding/python/interface/ten/test.py b/core/src/ten_runtime/binding/python/interface/ten/test.py index 79191354c..d73b3ab7b 100644 --- a/core/src/ten_runtime/binding/python/interface/ten/test.py +++ b/core/src/ten_runtime/binding/python/interface/ten/test.py @@ -65,7 +65,8 @@ def _import_package_from_path(self, addon_base_dir_str: str) -> None: sys.path.insert(0, str(addon_base_dir.parent)) importlib.import_module(addon_base_dir.name) - # =-=-= + # TODO(Wei): This should be done during the `on_configure_done` of the + # test app. _AddonManager.register_all_addons(None) @final 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 51d9b3107..b8dddbb62 100644 --- a/core/src/ten_runtime/binding/python/native/msg/msg.c +++ b/core/src/ten_runtime/binding/python/native/msg/msg.c @@ -303,7 +303,7 @@ PyObject *ten_py_msg_get_property_string(PyObject *self, PyObject *args) { return NULL; } - const char *value = ten_value_peek_raw_str(c_value); + const char *value = ten_value_peek_raw_str(c_value, &err); PyObject *res = Py_BuildValue("s", value); diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property.c index 1c5b5900d..87db3ddb0 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_get_property.c @@ -209,7 +209,7 @@ PyObject *ten_py_ten_env_get_property_string(PyObject *self, PyObject *args) { path); } - const char *str_value = ten_value_peek_raw_str(value); + const char *str_value = ten_value_peek_raw_str(value, NULL); if (!str_value) { ten_value_destroy(value); diff --git a/core/src/ten_runtime/common/loc.c b/core/src/ten_runtime/common/loc.c index c41da0fe9..c9750b61d 100644 --- a/core/src/ten_runtime/common/loc.c +++ b/core/src/ten_runtime/common/loc.c @@ -352,7 +352,7 @@ void ten_loc_set_from_value(ten_loc_t *self, ten_value_t *value) { if (app_value) { TEN_ASSERT(ten_value_is_string(app_value), "Should not happen."); - const char *app_str = ten_value_peek_raw_str(app_value); + const char *app_str = ten_value_peek_raw_str(app_value, NULL); if (app_str && strlen(app_str) > 0) { ten_string_set_from_c_str(&self->app_uri, app_str, strlen(app_str)); } @@ -361,7 +361,7 @@ void ten_loc_set_from_value(ten_loc_t *self, ten_value_t *value) { if (graph_value) { TEN_ASSERT(ten_value_is_string(graph_value), "Should not happen."); - const char *graph_str = ten_value_peek_raw_str(graph_value); + const char *graph_str = ten_value_peek_raw_str(graph_value, NULL); if (graph_str && strlen(graph_str) > 0) { ten_string_set_from_c_str(&self->graph_id, graph_str, strlen(graph_str)); } @@ -371,7 +371,8 @@ void ten_loc_set_from_value(ten_loc_t *self, ten_value_t *value) { TEN_ASSERT(ten_value_is_string(extension_group_value), "Should not happen."); - const char *group_name_str = ten_value_peek_raw_str(extension_group_value); + const char *group_name_str = + ten_value_peek_raw_str(extension_group_value, NULL); if (group_name_str && strlen(group_name_str) > 0) { ten_string_set_from_c_str(&self->extension_group_name, group_name_str, strlen(group_name_str)); @@ -381,7 +382,8 @@ void ten_loc_set_from_value(ten_loc_t *self, ten_value_t *value) { if (extension_value) { TEN_ASSERT(ten_value_is_string(extension_value), "Should not happen."); - const char *extension_name_str = ten_value_peek_raw_str(extension_value); + const char *extension_name_str = + ten_value_peek_raw_str(extension_value, NULL); if (extension_name_str && strlen(extension_name_str) > 0) { ten_string_set_from_c_str(&self->extension_name, extension_name_str, strlen(extension_name_str)); diff --git a/core/src/ten_runtime/engine/msg_interface/cmd_result.c b/core/src/ten_runtime/engine/msg_interface/cmd_result.c index 1d74796bc..171875a44 100644 --- a/core/src/ten_runtime/engine/msg_interface/cmd_result.c +++ b/core/src/ten_runtime/engine/msg_interface/cmd_result.c @@ -163,7 +163,7 @@ static bool ten_engine_handle_cmd_result_for_cmd_start_graph( TEN_ASSERT(ten_value_is_string(err_msg_value), "Should not happen."); ten_engine_return_error_for_cmd_start_graph( self, original_start_graph_cmd, - ten_value_peek_raw_str(err_msg_value)); + ten_value_peek_raw_str(err_msg_value, err)); } else { ten_engine_return_error_for_cmd_start_graph( self, original_start_graph_cmd, "Failed to start engine in app [%s].", diff --git a/core/src/ten_runtime/extension/internal/metadata.c b/core/src/ten_runtime/extension/internal/metadata.c index 62237d34a..06d8a58de 100644 --- a/core/src/ten_runtime/extension/internal/metadata.c +++ b/core/src/ten_runtime/extension/internal/metadata.c @@ -191,7 +191,7 @@ static bool ten_extension_graph_property_resolve_placeholders( return true; case TEN_TYPE_STRING: { - const char *str_value = ten_value_peek_raw_str(curr_value); + const char *str_value = ten_value_peek_raw_str(curr_value, err); if (ten_c_str_is_placeholder(str_value)) { ten_placeholder_t placeholder; ten_placeholder_init(&placeholder); diff --git a/core/src/ten_runtime/extension/msg_dest_info/value.c b/core/src/ten_runtime/extension/msg_dest_info/value.c index f71b513de..e2382f9ae 100644 --- a/core/src/ten_runtime/extension/msg_dest_info/value.c +++ b/core/src/ten_runtime/extension/msg_dest_info/value.c @@ -145,7 +145,7 @@ ten_shared_ptr_t *ten_msg_dest_info_from_value( const char *name = ""; if (name_value) { - name = ten_value_peek_raw_str(name_value); + name = ten_value_peek_raw_str(name_value, err); } self = ten_msg_dest_info_create(name); 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 b07e60f9d..92061f4c2 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 @@ -149,8 +149,8 @@ bool ten_raw_cmd_custom_set_ten_property(ten_msg_t *self, ten_list_t *paths, ten_string_get_raw_str(&item->obj_item_str))) { if (ten_value_is_string(value)) { ten_value_set_string_with_size( - &self->name, ten_value_peek_raw_str(value), - strlen(ten_value_peek_raw_str(value))); + &self->name, ten_value_peek_raw_str(value, &tmp_err), + strlen(ten_value_peek_raw_str(value, &tmp_err))); success = true; } else { success = false; diff --git a/core/src/ten_runtime/msg/cmd_base/cmd/timer/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd/timer/cmd.c index f363e7c8a..1772b5a24 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd/timer/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd/timer/cmd.c @@ -198,8 +198,8 @@ bool ten_raw_cmd_timer_set_ten_property(ten_msg_t *self, ten_list_t *paths, ten_string_get_raw_str(&item->obj_item_str))) { if (ten_value_is_string(value)) { ten_value_set_string_with_size( - &self->name, ten_value_peek_raw_str(value), - strlen(ten_value_peek_raw_str(value))); + &self->name, ten_value_peek_raw_str(value, &tmp_err), + strlen(ten_value_peek_raw_str(value, &tmp_err))); success = true; } else { success = false; diff --git a/core/src/ten_runtime/msg/cmd_base/cmd_result/cmd.c b/core/src/ten_runtime/msg/cmd_base/cmd_result/cmd.c index 5a4c00324..8a3ab677f 100644 --- a/core/src/ten_runtime/msg/cmd_base/cmd_result/cmd.c +++ b/core/src/ten_runtime/msg/cmd_base/cmd_result/cmd.c @@ -356,7 +356,7 @@ bool ten_raw_cmd_result_validate_schema(ten_msg_t *status_msg, "Invalid argument."); const char *original_cmd_name = - ten_value_peek_raw_str(&cmd_result->original_cmd_name); + ten_value_peek_raw_str(&cmd_result->original_cmd_name, err); TEN_ASSERT(original_cmd_name && strlen(original_cmd_name), "Invalid argument."); diff --git a/core/src/ten_runtime/msg/cmd_base/field/cmd_id.c b/core/src/ten_runtime/msg/cmd_base/field/cmd_id.c index 595d21146..a45bdb453 100644 --- a/core/src/ten_runtime/msg/cmd_base/field/cmd_id.c +++ b/core/src/ten_runtime/msg/cmd_base/field/cmd_id.c @@ -20,7 +20,7 @@ void ten_cmd_base_copy_cmd_id(ten_msg_t *self, ten_msg_t *src, ten_string_set_formatted( ten_value_peek_string(&((ten_cmd_base_t *)self)->cmd_id), "%s", - ten_value_peek_raw_str(&((ten_cmd_base_t *)src)->cmd_id)); + ten_value_peek_raw_str(&((ten_cmd_base_t *)src)->cmd_id, NULL)); } bool ten_cmd_base_process_cmd_id(ten_msg_t *self, diff --git a/core/src/ten_runtime/msg/cmd_base/field/seq_id.c b/core/src/ten_runtime/msg/cmd_base/field/seq_id.c index 6354ba417..752b8f2bf 100644 --- a/core/src/ten_runtime/msg/cmd_base/field/seq_id.c +++ b/core/src/ten_runtime/msg/cmd_base/field/seq_id.c @@ -20,7 +20,7 @@ void ten_cmd_base_copy_seq_id(ten_msg_t *self, ten_msg_t *src, ten_string_set_formatted( ten_value_peek_string(&((ten_cmd_base_t *)self)->seq_id), "%s", - ten_value_peek_raw_str(&((ten_cmd_base_t *)src)->seq_id)); + ten_value_peek_raw_str(&((ten_cmd_base_t *)src)->seq_id, NULL)); } bool ten_cmd_base_process_seq_id(ten_msg_t *self, diff --git a/core/src/ten_runtime/msg/data/data.c b/core/src/ten_runtime/msg/data/data.c index 621b84c8d..369487614 100644 --- a/core/src/ten_runtime/msg/data/data.c +++ b/core/src/ten_runtime/msg/data/data.c @@ -196,8 +196,8 @@ bool ten_raw_data_like_set_ten_property(ten_msg_t *self, ten_list_t *paths, ten_string_get_raw_str(&item->obj_item_str))) { if (ten_value_is_string(value)) { ten_value_init_string_with_size( - &self->name, ten_value_peek_raw_str(value), - strlen(ten_value_peek_raw_str(value))); + &self->name, ten_value_peek_raw_str(value, &tmp_err), + strlen(ten_value_peek_raw_str(value, &tmp_err))); success = true; } else { success = false; diff --git a/core/src/ten_runtime/msg/field/name.c b/core/src/ten_runtime/msg/field/name.c index 332b4533c..5f7d592e2 100644 --- a/core/src/ten_runtime/msg/field/name.c +++ b/core/src/ten_runtime/msg/field/name.c @@ -32,7 +32,7 @@ bool ten_raw_msg_name_process(ten_msg_t *self, if (name_field.value_is_changed_after_process) { TEN_MSG_TYPE msg_type_spec_by_name = ten_msg_type_from_unique_name_string( - ten_value_peek_raw_str(name_field.field_value)); + ten_value_peek_raw_str(name_field.field_value, err)); if (msg_type_spec_by_name != TEN_MSG_TYPE_INVALID) { self->type = msg_type_spec_by_name; } diff --git a/core/src/ten_runtime/msg/field/type.c b/core/src/ten_runtime/msg/field/type.c index b0913ffc2..72ffb549e 100644 --- a/core/src/ten_runtime/msg/field/type.c +++ b/core/src/ten_runtime/msg/field/type.c @@ -79,7 +79,7 @@ bool ten_raw_msg_type_process(ten_msg_t *self, if (type_field.value_is_changed_after_process) { self->type = ten_msg_type_from_type_string( - ten_value_peek_raw_str(type_field.field_value)); + ten_value_peek_raw_str(type_field.field_value, err)); } ten_value_destroy(type_value); diff --git a/core/src/ten_runtime/msg/msg.c b/core/src/ten_runtime/msg/msg.c index 614c878b7..7a3116b03 100644 --- a/core/src/ten_runtime/msg/msg.c +++ b/core/src/ten_runtime/msg/msg.c @@ -973,7 +973,7 @@ static bool ten_raw_msg_dump_internal(ten_msg_t *msg, ten_error_t *err, ten_json_t *msg_json = ten_raw_msg_to_json_include_internal_field(msg, err); TEN_ASSERT(msg_json, "Failed to convert msg type(%s), name(%s) to JSON.", ten_msg_type_to_string(msg->type), - ten_value_peek_raw_str(&msg->name)); + ten_value_peek_raw_str(&msg->name, err)); if (!msg_json) { return false; } @@ -1211,7 +1211,7 @@ bool ten_msg_has_locked_res(ten_shared_ptr_t *self) { static const char *ten_raw_msg_get_name(ten_msg_t *self) { TEN_ASSERT(self && ten_raw_msg_check_integrity(self), "Should not happen."); - return ten_value_peek_raw_str(&self->name); + return ten_value_peek_raw_str(&self->name, NULL); } const char *ten_msg_get_name(ten_shared_ptr_t *self) { 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 9e531f7be..1bc63dd99 100644 --- a/core/src/ten_runtime/msg/video_frame/video_frame.c +++ b/core/src/ten_runtime/msg/video_frame/video_frame.c @@ -286,7 +286,7 @@ bool ten_raw_video_frame_set_ten_property(ten_msg_t *self, ten_list_t *paths, case TEN_VALUE_PATH_ITEM_TYPE_OBJECT_ITEM: { if (!strcmp(TEN_STR_PIXEL_FMT, ten_string_get_raw_str(&item->obj_item_str))) { - const char *pixel_fmt_str = ten_value_peek_raw_str(value); + const char *pixel_fmt_str = ten_value_peek_raw_str(value, err); ten_raw_video_frame_set_pixel_fmt( video_frame, ten_video_frame_pixel_fmt_from_string(pixel_fmt_str)); diff --git a/core/src/ten_runtime/msg_conversion/msg_conversion/base.c b/core/src/ten_runtime/msg_conversion/msg_conversion/base.c index a533f876a..e56fc44ad 100644 --- a/core/src/ten_runtime/msg_conversion/msg_conversion/base.c +++ b/core/src/ten_runtime/msg_conversion/msg_conversion/base.c @@ -81,7 +81,7 @@ ten_msg_conversion_t *ten_msg_conversion_from_value(ten_value_t *value, return NULL; } - const char *type_str = ten_value_peek_raw_str(type_value); + const char *type_str = ten_value_peek_raw_str(type_value, err); if (!type_str) { TEN_ASSERT(0, "Should not happen."); return NULL; diff --git a/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/fixed_value.c b/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/fixed_value.c index b4d1a9568..6a9dd6804 100644 --- a/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/fixed_value.c +++ b/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/fixed_value.c @@ -130,7 +130,7 @@ bool ten_msg_conversion_per_property_rule_fixed_value_to_json( } case TEN_TYPE_STRING: { - const char *value_str = ten_value_peek_raw_str(self->value); + const char *value_str = ten_value_peek_raw_str(self->value, err); ten_json_object_set_new(json, TEN_STR_VALUE, ten_json_create_string(value_str)); break; diff --git a/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/from_original.c b/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/from_original.c index 80eef4661..0eff469f1 100644 --- a/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/from_original.c +++ b/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/from_original.c @@ -91,9 +91,10 @@ bool ten_msg_conversion_per_property_rule_from_original_from_value( TEN_ASSERT(value, "Invalid argument."); ten_msg_conversion_per_property_rule_from_original_init(self); - ten_string_set_formatted(&self->original_path, - ten_value_peek_raw_str(ten_value_object_peek( - value, TEN_STR_ORIGINAL_PATH))); + ten_string_set_formatted( + &self->original_path, + ten_value_peek_raw_str( + ten_value_object_peek(value, TEN_STR_ORIGINAL_PATH), err)); return true; } diff --git a/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/rule.c b/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/rule.c index 7898c7c96..25f5740eb 100644 --- a/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/rule.c +++ b/core/src/ten_runtime/msg_conversion/msg_conversion/per_property/rule.c @@ -223,10 +223,10 @@ ten_msg_conversion_per_property_rule_from_value(ten_value_t *value, ten_string_set_formatted( &self->property_path, "%s", - ten_value_peek_raw_str(ten_value_object_peek(value, TEN_STR_PATH))); + ten_value_peek_raw_str(ten_value_object_peek(value, TEN_STR_PATH), err)); const char *conversion_mode_str = ten_value_peek_raw_str( - ten_value_object_peek(value, TEN_STR_CONVERSION_MODE)); + ten_value_object_peek(value, TEN_STR_CONVERSION_MODE), err); self->conversion_mode = ten_msg_conversion_per_property_rule_conversion_mode_from_string( diff --git a/core/src/ten_utils/lib/sys/general/error.c b/core/src/ten_utils/lib/sys/general/error.c index 6702fe6c3..ad699ae92 100644 --- a/core/src/ten_utils/lib/sys/general/error.c +++ b/core/src/ten_utils/lib/sys/general/error.c @@ -8,9 +8,9 @@ #include -#include "ten_utils/macro/check.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/string.h" +#include "ten_utils/macro/check.h" #include "ten_utils/macro/memory.h" bool ten_error_check_integrity(ten_error_t *self) { @@ -46,6 +46,14 @@ ten_error_t *ten_error_create(void) { return self; } +void ten_error_copy(ten_error_t *self, ten_error_t *other) { + TEN_ASSERT(self && ten_error_check_integrity(self), "Invalid argument"); + TEN_ASSERT(other && ten_error_check_integrity(other), "Invalid argument"); + + self->err_no = other->err_no; + ten_string_copy(&self->err_msg, &other->err_msg); +} + bool ten_error_prepend_errmsg(ten_error_t *self, const char *fmt, ...) { TEN_ASSERT(self && ten_error_check_integrity(self), "Invalid argument"); diff --git a/core/src/ten_utils/lib/sys/general/placeholder.c b/core/src/ten_utils/lib/sys/general/placeholder.c index 7d9cd35d9..cf0089db4 100644 --- a/core/src/ten_utils/lib/sys/general/placeholder.c +++ b/core/src/ten_utils/lib/sys/general/placeholder.c @@ -195,7 +195,7 @@ bool ten_placeholder_resolve(ten_placeholder_t *self, ten_value_reset_to_null(placeholder_value); } else { const char *default_value = - ten_value_peek_raw_str(&self->default_value); + ten_value_peek_raw_str(&self->default_value, err); TEN_LOGI( "Environment variable %s is not found, using default value %s.", diff --git a/core/src/ten_utils/schema/keywords/keyword_required.c b/core/src/ten_utils/schema/keywords/keyword_required.c index e8e37770f..cb2068a37 100644 --- a/core/src/ten_utils/schema/keywords/keyword_required.c +++ b/core/src/ten_utils/schema/keywords/keyword_required.c @@ -234,7 +234,7 @@ ten_schema_keyword_t *ten_schema_keyword_required_create_from_value( break; } - const char *required_property = ten_value_peek_raw_str(item); + const char *required_property = ten_value_peek_raw_str(item, NULL); TEN_ASSERT(required_property, "Should not happen."); ten_list_push_str_back(&self->required_properties, required_property); diff --git a/core/src/ten_utils/schema/keywords/keyword_type.c b/core/src/ten_utils/schema/keywords/keyword_type.c index fe90d098b..f95504b53 100644 --- a/core/src/ten_utils/schema/keywords/keyword_type.c +++ b/core/src/ten_utils/schema/keywords/keyword_type.c @@ -191,7 +191,7 @@ ten_schema_keyword_t *ten_schema_keyword_type_create_from_value( return NULL; } - TEN_TYPE type = ten_type_from_string(ten_value_peek_raw_str(value)); + TEN_TYPE type = ten_type_from_string(ten_value_peek_raw_str(value, NULL)); if (type == TEN_TYPE_INVALID) { TEN_ASSERT(0, "Invalid TEN type."); return NULL; diff --git a/core/src/ten_utils/value/value_get.c b/core/src/ten_utils/value/value_get.c index da24240c7..272dcdb0a 100644 --- a/core/src/ten_utils/value/value_get.c +++ b/core/src/ten_utils/value/value_get.c @@ -13,6 +13,7 @@ #include "ten_utils/container/list_node.h" #include "ten_utils/lib/error.h" #include "ten_utils/lib/string.h" +#include "ten_utils/log/log.h" #include "ten_utils/macro/check.h" #include "ten_utils/value/type.h" #include "ten_utils/value/type_operation.h" @@ -36,32 +37,38 @@ int8_t ten_value_get_int8(ten_value_t *self, ten_error_t *err) { if (self->content.int16 >= -INT8_MAX && self->content.int16 <= INT8_MAX) { return (int8_t)self->content.int16; } + break; case TEN_TYPE_INT32: if (self->content.int32 >= -INT8_MAX && self->content.int32 <= INT8_MAX) { return (int8_t)self->content.int32; } + break; case TEN_TYPE_INT64: if (self->content.int64 >= -INT8_MAX && self->content.int64 <= INT8_MAX) { return (int8_t)self->content.int64; } + break; case TEN_TYPE_UINT8: if (self->content.uint8 <= INT8_MAX) { return (int8_t)self->content.uint8; } + break; case TEN_TYPE_UINT16: if (self->content.uint16 <= INT8_MAX) { return (int8_t)self->content.uint16; } + break; case TEN_TYPE_UINT32: if (self->content.uint32 <= INT8_MAX) { return (int8_t)self->content.uint32; } + break; case TEN_TYPE_UINT64: if (self->content.uint64 <= INT8_MAX) { return (int8_t)self->content.uint64; } + break; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -93,27 +100,31 @@ int16_t ten_value_get_int16(ten_value_t *self, ten_error_t *err) { self->content.int32 <= INT16_MAX) { return (int16_t)self->content.int32; } + break; case TEN_TYPE_INT64: if (self->content.int64 >= -INT16_MAX && self->content.int64 <= INT16_MAX) { return (int16_t)self->content.int64; } + break; case TEN_TYPE_UINT8: return (int16_t)self->content.uint8; case TEN_TYPE_UINT16: if (self->content.uint16 <= INT16_MAX) { return (int16_t)self->content.uint16; } + break; case TEN_TYPE_UINT32: if (self->content.uint32 <= INT16_MAX) { return (int16_t)self->content.uint32; } + break; case TEN_TYPE_UINT64: if (self->content.uint64 <= INT16_MAX) { return (int16_t)self->content.uint64; } + break; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -147,6 +158,7 @@ int32_t ten_value_get_int32(ten_value_t *self, ten_error_t *err) { self->content.int64 <= INT32_MAX) { return (int32_t)self->content.int64; } + break; case TEN_TYPE_UINT8: return self->content.uint8; case TEN_TYPE_UINT16: @@ -155,12 +167,13 @@ int32_t ten_value_get_int32(ten_value_t *self, ten_error_t *err) { if (self->content.uint32 <= INT32_MAX) { return (int32_t)self->content.uint32; } + break; case TEN_TYPE_UINT64: if (self->content.uint64 <= INT32_MAX) { return (int32_t)self->content.uint64; } + break; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -201,8 +214,8 @@ int64_t ten_value_get_int64(ten_value_t *self, ten_error_t *err) { if (self->content.uint64 <= INT64_MAX) { return (int64_t)self->content.uint64; } + break; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -231,32 +244,38 @@ uint8_t ten_value_get_uint8(ten_value_t *self, ten_error_t *err) { if (self->content.uint64 <= UINT8_MAX) { return (uint8_t)self->content.uint16; } + break; case TEN_TYPE_UINT32: if (self->content.uint64 <= UINT8_MAX) { return (uint8_t)self->content.uint32; } + break; case TEN_TYPE_UINT64: if (self->content.uint64 <= UINT8_MAX) { return (uint8_t)self->content.uint64; } + break; case TEN_TYPE_INT8: if (self->content.int8 >= 0) { return (uint8_t)self->content.int8; } + break; case TEN_TYPE_INT16: if (self->content.int16 >= 0 && self->content.int16 <= UINT8_MAX) { return (uint8_t)self->content.int16; } + break; case TEN_TYPE_INT32: if (self->content.int32 >= 0 && self->content.int32 <= UINT8_MAX) { return (uint8_t)self->content.int32; } + break; case TEN_TYPE_INT64: if (self->content.int64 >= 0 && self->content.int64 <= UINT8_MAX) { return (uint8_t)self->content.int64; } + break; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -287,28 +306,33 @@ uint16_t ten_value_get_uint16(ten_value_t *self, ten_error_t *err) { if (self->content.uint64 <= UINT16_MAX) { return (uint16_t)self->content.uint32; } + break; case TEN_TYPE_UINT64: if (self->content.uint64 <= UINT16_MAX) { return (uint16_t)self->content.uint64; } + break; case TEN_TYPE_INT8: if (self->content.int8 >= 0) { return (uint16_t)self->content.int8; } + break; case TEN_TYPE_INT16: if (self->content.int16 >= 0) { return (uint16_t)self->content.int16; } + break; case TEN_TYPE_INT32: if (self->content.int32 >= 0 && self->content.int64 <= UINT16_MAX) { return (uint16_t)self->content.int32; } + break; case TEN_TYPE_INT64: if (self->content.int64 >= 0 && self->content.int64 <= UINT16_MAX) { return (uint16_t)self->content.int64; } + break; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -341,24 +365,28 @@ uint32_t ten_value_get_uint32(ten_value_t *self, ten_error_t *err) { if (self->content.uint64 <= UINT32_MAX) { return (uint32_t)self->content.uint64; } + break; case TEN_TYPE_INT8: if (self->content.int8 >= 0) { return (uint32_t)self->content.int8; } + break; case TEN_TYPE_INT16: if (self->content.int16 >= 0) { return (uint32_t)self->content.int16; } + break; case TEN_TYPE_INT32: if (self->content.int32 >= 0) { return (uint32_t)self->content.int32; } + break; case TEN_TYPE_INT64: if (self->content.int64 >= 0 && self->content.int64 <= UINT32_MAX) { return (uint32_t)self->content.int64; } + break; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -393,20 +421,23 @@ uint64_t ten_value_get_uint64(ten_value_t *self, ten_error_t *err) { if (self->content.int8 >= 0) { return (uint64_t)self->content.int8; } + break; case TEN_TYPE_INT16: if (self->content.int16 >= 0) { return (uint64_t)self->content.int16; } + break; case TEN_TYPE_INT32: if (self->content.int32 >= 0) { return (uint64_t)self->content.int32; } + break; case TEN_TYPE_INT64: if (self->content.int64 >= 0) { return (uint64_t)self->content.int64; } + break; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -436,8 +467,8 @@ float ten_value_get_float32(ten_value_t *self, ten_error_t *err) { self->content.float64 <= FLT_MAX) { return (float)self->content.float64; } + break; default: - TEN_ASSERT(0, "Should not happen."); return 0.0F; } @@ -465,7 +496,6 @@ double ten_value_get_float64(ten_value_t *self, ten_error_t *err) { case TEN_TYPE_FLOAT64: return self->content.float64; default: - TEN_ASSERT(0, "Should not happen."); break; } @@ -557,8 +587,7 @@ ten_string_t *ten_value_peek_string(ten_value_t *self) { } } -// TODO(Liu): add error context. -const char *ten_value_peek_raw_str(ten_value_t *self) { +const char *ten_value_peek_raw_str(ten_value_t *self, ten_error_t *err) { if (!self) { return NULL; } @@ -576,13 +605,23 @@ TEN_TYPE ten_value_get_type(ten_value_t *self) { return self->type; } -ten_value_t *ten_value_array_peek(ten_value_t *self, size_t index) { +ten_value_t *ten_value_array_peek(ten_value_t *self, size_t index, + ten_error_t *err) { if (!self) { return NULL; } TEN_ASSERT(ten_value_check_integrity(self), "Invalid argument."); + if (!ten_value_is_array(self)) { + if (err) { + ten_error_set(err, TEN_ERRNO_GENERIC, + "The conversion from %s to array is unfit.", + ten_type_to_string(self->type)); + } + return NULL; + } + if (index >= ten_list_size(&self->content.array)) { return NULL; } @@ -593,6 +632,6 @@ ten_value_t *ten_value_array_peek(ten_value_t *self, size_t index) { } } - TEN_ASSERT(0, "Invalid argument."); + TEN_ASSERT(0, "Should not happen."); return NULL; } diff --git a/core/src/ten_utils/value/value_object.c b/core/src/ten_utils/value/value_object.c index 61842b997..46ddca7a2 100644 --- a/core/src/ten_utils/value/value_object.c +++ b/core/src/ten_utils/value/value_object.c @@ -71,7 +71,7 @@ const char *ten_value_object_peek_string(ten_value_t *self, const char *key) { return NULL; } - const char *result = ten_value_peek_raw_str(v); + const char *result = ten_value_peek_raw_str(v, NULL); return result; } diff --git a/packages/core_protocols/msgpack/common/value.c b/packages/core_protocols/msgpack/common/value.c index 5494c9e04..62412916f 100644 --- a/packages/core_protocols/msgpack/common/value.c +++ b/packages/core_protocols/msgpack/common/value.c @@ -607,8 +607,9 @@ void ten_msgpack_value_serialize(ten_value_t *value, msgpack_packer *pck) { TEN_ASSERT(rc == 0, "Should not happen."); break; case TEN_TYPE_STRING: - rc = msgpack_pack_str_with_body(pck, ten_value_peek_raw_str(value), - strlen(ten_value_peek_raw_str(value))); + rc = msgpack_pack_str_with_body( + pck, ten_value_peek_raw_str(value, &err), + strlen(ten_value_peek_raw_str(value, &err))); TEN_ASSERT(rc == 0, "Should not happen."); break; case TEN_TYPE_BOOL: diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/property.json b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/property.json index 29c13fca5..fa497515d 100644 --- a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/property.json +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/property.json @@ -14,7 +14,6 @@ "addon": "extension_a", "extension_group": "nodetest", "property": { - "env_not_set": "${env:ENV_NOT_SET}", "env_not_set_has_default": "${env:ENV_NOT_SET|}" } } diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go index ec317a82e..3c73c53a2 100644 --- a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go @@ -19,12 +19,6 @@ type baseExtension struct { func (ext *baseExtension) OnStart(tenEnv ten.TenEnv) { tenEnv.LogDebug("OnStart") - // The environment variable 'ENV_NOT_SET' is not set, but the property - // should exist. - if _, err := tenEnv.GetPropertyString("env_not_set"); err == nil { - panic("The type should be mismatched, as the default value is not set.") - } - if prop, err := tenEnv.GetPropertyString("env_not_set_has_default"); err != nil && prop != "" { panic("The default value should be used.") diff --git a/tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/property.json b/tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/property.json index 339acac38..0ae17ca16 100644 --- a/tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/property.json +++ b/tests/ten_runtime/integration/python/get_set_prop_python/get_set_prop_python_app/property.json @@ -21,7 +21,6 @@ "addon": "default_extension_python", "extension_group": "default_extension_group", "property": { - "env_not_set": "${env:ENV_NOT_SET}", "env_not_set_has_default": "${env:ENV_NOT_SET|}" } }, 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 b48cd1dca..b05825ae2 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 @@ -39,19 +39,6 @@ def __test_thread_routine(self, ten_env: TenEnv): def on_start(self, ten_env: TenEnv) -> None: ten_env.log_debug("on_start") - # The environment variable 'ENV_NOT_SET' used in the property is not - # set, but the property should exist. - assert ten_env.is_property_exist("env_not_set") is True - - try: - _ = ten_env.get_property_string("env_not_set") - - # Should not reach here, as the above line should throw an - # exception. - assert False - except Exception as e: - print(e) - assert ten_env.is_property_exist("env_not_set_has_default") is True try: diff --git a/tests/ten_runtime/smoke/BUILD.gn b/tests/ten_runtime/smoke/BUILD.gn index 7ec2edbd3..dc361c473 100644 --- a/tests/ten_runtime/smoke/BUILD.gn +++ b/tests/ten_runtime/smoke/BUILD.gn @@ -39,6 +39,7 @@ ten_executable("ten_runtime_smoke_test") { "extension_test", "graph_test", "log_test", + "msg_property", "msg_test", "notify_test", "property", diff --git a/tests/ten_runtime/smoke/extension_test/BUILD.gn b/tests/ten_runtime/smoke/extension_test/BUILD.gn index 7d470da2e..1172aff76 100644 --- a/tests/ten_runtime/smoke/extension_test/BUILD.gn +++ b/tests/ten_runtime/smoke/extension_test/BUILD.gn @@ -37,7 +37,6 @@ glob("extension_test") { "graph", "graph_name", "lock", - "msg_property", "multi_dest", "outer_thread", "path", diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/BUILD.gn b/tests/ten_runtime/smoke/msg_property/BUILD.gn similarity index 100% rename from tests/ten_runtime/smoke/extension_test/msg_property/BUILD.gn rename to tests/ten_runtime/smoke/msg_property/BUILD.gn diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_invalid.cc b/tests/ten_runtime/smoke/msg_property/msg_property_invalid.cc similarity index 93% rename from tests/ten_runtime/smoke/extension_test/msg_property/msg_property_invalid.cc rename to tests/ten_runtime/smoke/msg_property/msg_property_invalid.cc index 2687bd1ba..32e493bba 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_invalid.cc +++ b/tests/ten_runtime/smoke/msg_property/msg_property_invalid.cc @@ -7,7 +7,7 @@ #include "gtest/gtest.h" #include "include_internal/ten_runtime/binding/cpp/ten.h" -TEST(ExtensionTest, MsgPropertyInvalid) { // NOLINT +TEST(MsgPropertyTest, Invalid) { // NOLINT auto cmd = ten::cmd_t::create("test"); auto result = cmd->set_property("b", static_cast(nullptr)); diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_c_string.cc b/tests/ten_runtime/smoke/msg_property/msg_property_send_c_string.cc similarity index 98% rename from tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_c_string.cc rename to tests/ten_runtime/smoke/msg_property/msg_property_send_c_string.cc index a71f6111f..f88ee7669 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_c_string.cc +++ b/tests/ten_runtime/smoke/msg_property/msg_property_send_c_string.cc @@ -99,7 +99,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(msg_property_send_c_string__extension_2, } // namespace -TEST(ExtensionTest, MsgPropertySendCString) { // NOLINT +TEST(MsgPropertyTest, SendCString) { // NOLINT // Start app. auto *app_thread = ten_thread_create("app thread", test_app_thread_main, nullptr); diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_ptr.cc b/tests/ten_runtime/smoke/msg_property/msg_property_send_cpp_ptr.cc similarity index 99% rename from tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_ptr.cc rename to tests/ten_runtime/smoke/msg_property/msg_property_send_cpp_ptr.cc index e8251c3c2..7a61d270e 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_ptr.cc +++ b/tests/ten_runtime/smoke/msg_property/msg_property_send_cpp_ptr.cc @@ -124,7 +124,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(msg_property_send_cpp_ptr__extension_2, } // namespace -TEST(ExtensionTest, MsgPropertySendCppPtr) { // NOLINT +TEST(MsgPropertyTest, SendCppPtr) { // NOLINT // Start app. auto *app_thread = ten_thread_create("app thread", test_app_thread_main, nullptr); diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_string.cc b/tests/ten_runtime/smoke/msg_property/msg_property_send_cpp_string.cc similarity index 98% rename from tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_string.cc rename to tests/ten_runtime/smoke/msg_property/msg_property_send_cpp_string.cc index 2bf688a14..3571854cb 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_cpp_string.cc +++ b/tests/ten_runtime/smoke/msg_property/msg_property_send_cpp_string.cc @@ -97,7 +97,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(msg_property_send_cpp_string__extension_2, } // namespace -TEST(ExtensionTest, MsgPropertySendCppString) { // NOLINT +TEST(MsgPropertyTest, SendCppString) { // NOLINT // Start app. auto *app_thread = ten_thread_create("app thread", test_app_thread_main, nullptr); diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_float_ptr.cc b/tests/ten_runtime/smoke/msg_property/msg_property_send_float_ptr.cc similarity index 99% rename from tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_float_ptr.cc rename to tests/ten_runtime/smoke/msg_property/msg_property_send_float_ptr.cc index 8a91c3441..25b8a713f 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_float_ptr.cc +++ b/tests/ten_runtime/smoke/msg_property/msg_property_send_float_ptr.cc @@ -106,7 +106,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(msg_property_send_float_ptr__extension_2, } // namespace -TEST(ExtensionTest, MsgPropertySendFloatPtr) { // NOLINT +TEST(MsgPropertyTest, SendFloatPtr) { // NOLINT // Start app. auto *app_thread = ten_thread_create("app thread", test_app_thread_main, nullptr); diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int.cc b/tests/ten_runtime/smoke/msg_property/msg_property_send_int.cc similarity index 99% rename from tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int.cc rename to tests/ten_runtime/smoke/msg_property/msg_property_send_int.cc index 748042e37..0b6521b07 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int.cc +++ b/tests/ten_runtime/smoke/msg_property/msg_property_send_int.cc @@ -98,7 +98,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(msg_property_send_int__extension_2, } // namespace -TEST(ExtensionTest, MsgPropertySendInt) { // NOLINT +TEST(MsgPropertyTest, SendInt) { // NOLINT // Start app. auto *app_thread = ten_thread_create("app thread", test_app_thread_main, nullptr); diff --git a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int32_ptr.cc b/tests/ten_runtime/smoke/msg_property/msg_property_send_int32_ptr.cc similarity index 99% rename from tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int32_ptr.cc rename to tests/ten_runtime/smoke/msg_property/msg_property_send_int32_ptr.cc index 14c50537d..f48eedfd0 100644 --- a/tests/ten_runtime/smoke/extension_test/msg_property/msg_property_send_int32_ptr.cc +++ b/tests/ten_runtime/smoke/msg_property/msg_property_send_int32_ptr.cc @@ -106,7 +106,7 @@ TEN_CPP_REGISTER_ADDON_AS_EXTENSION(msg_property_send_int32_ptr__extension_2, } // namespace -TEST(ExtensionTest, MsgPropertySendInt32Ptr) { // NOLINT +TEST(MsgPropertyTest, SendInt32Ptr) { // NOLINT // Start app. auto *app_thread = ten_thread_create("app thread", test_app_thread_main, nullptr); diff --git a/tests/ten_runtime/smoke/property/property_get_int32.cc b/tests/ten_runtime/smoke/property/property_get_int32.cc index d389523ff..db57a208c 100644 --- a/tests/ten_runtime/smoke/property/property_get_int32.cc +++ b/tests/ten_runtime/smoke/property/property_get_int32.cc @@ -27,8 +27,46 @@ 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()) == "hello_world") { - auto prop_value = ten_env.get_property_int32("app:" PROP_NAME); - if (prop_value == PROP_VAL) { + auto int8_prop_value = ten_env.get_property_int8("app:" PROP_NAME); + EXPECT_EQ(int8_prop_value, 0); + + auto int16_prop_value = ten_env.get_property_int16("app:" PROP_NAME); + EXPECT_EQ(int16_prop_value, PROP_VAL); + + auto int32_prop_value = ten_env.get_property_int32("app:" PROP_NAME); + EXPECT_EQ(int32_prop_value, PROP_VAL); + + auto int64_prop_value = ten_env.get_property_int64("app:" PROP_NAME); + EXPECT_EQ(int64_prop_value, PROP_VAL); + + auto uint8_prop_value = ten_env.get_property_uint8("app:" PROP_NAME); + EXPECT_EQ(uint8_prop_value, 0); + + auto uint16_prop_value = ten_env.get_property_uint16("app:" PROP_NAME); + EXPECT_EQ(uint16_prop_value, PROP_VAL); + + auto uint32_prop_value = ten_env.get_property_uint32("app:" PROP_NAME); + EXPECT_EQ(uint32_prop_value, PROP_VAL); + + auto uint64_prop_value = ten_env.get_property_uint64("app:" PROP_NAME); + EXPECT_EQ(uint64_prop_value, PROP_VAL); + + auto float32_prop_value = ten_env.get_property_float32("app:" PROP_NAME); + EXPECT_EQ(float32_prop_value, 0.0); + + auto float64_prop_value = ten_env.get_property_float64("app:" PROP_NAME); + EXPECT_EQ(float64_prop_value, 0.0); + + auto string_prop_value = ten_env.get_property_string("app:" PROP_NAME); + EXPECT_EQ(string_prop_value, ""); + + auto *ptr_prop_value = ten_env.get_property_ptr("app:" PROP_NAME); + EXPECT_EQ(ptr_prop_value, nullptr); + + auto bool_prop_value = ten_env.get_property_bool("app:" PROP_NAME); + EXPECT_EQ(bool_prop_value, false); + + if (int32_prop_value == PROP_VAL) { auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK); cmd_result->set_property("detail", "hello world, too"); ten_env.return_result(std::move(cmd_result), std::move(cmd)); diff --git a/tests/ten_utils/unit/ten_schema_test.cc b/tests/ten_utils/unit/ten_schema_test.cc index e12198ed3..7c7b3312e 100644 --- a/tests/ten_utils/unit/ten_schema_test.cc +++ b/tests/ten_utils/unit/ten_schema_test.cc @@ -413,7 +413,7 @@ TEST(SchemaTest, AdjustArray) { // NOLINT ten_error_t err; ten_error_init(&err); - auto *value_one = ten_value_array_peek(value, 0); + auto *value_one = ten_value_array_peek(value, 0, &err); ASSERT_EQ(true, ten_value_get_int32(value_one, &err) == 1); bool success = ten_schema_adjust_value_type(schema, value, &err);