Skip to content

Commit

Permalink
feat: add more in extension standalone testing (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Oct 1, 2024
1 parent 62f6aa7 commit 99b0921
Show file tree
Hide file tree
Showing 58 changed files with 1,503 additions and 530 deletions.
3 changes: 3 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Diagnostics:
UnusedIncludes: Strict
# Refer to https://github.com/llvm/llvm-project/issues/109037#issuecomment-2359938252
ClangTidy:
Remove: boost-use-ranges
Includes:
IgnoreHeader: ten_config\.h
InlayHints:
Expand Down
31 changes: 15 additions & 16 deletions core/include/ten_runtime/binding/cpp/internal/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ namespace ten {
class app_t {
public:
app_t()
: app_(ten_app_create(cpp_app_on_configure_cb_wrapper,
cpp_app_on_init_cb_wrapper, nullptr, nullptr)),
ten_(new ten_env_t(ten_app_get_ten_env(app_))) {
TEN_ASSERT(ten_, "Should not happen.");
: c_app(ten_app_create(cpp_app_on_configure_cb_wrapper,
cpp_app_on_init_cb_wrapper, nullptr, nullptr)),
cpp_ten_env(new ten_env_t(ten_app_get_ten_env(c_app))) {
TEN_ASSERT(cpp_ten_env, "Should not happen.");
ten_binding_handle_set_me_in_target_lang(
reinterpret_cast<ten_binding_handle_t *>(app_),
reinterpret_cast<ten_binding_handle_t *>(c_app),
static_cast<void *>(this));
}

virtual ~app_t() {
ten_app_destroy(app_);
app_ = nullptr;
ten_app_destroy(c_app);
c_app = nullptr;

TEN_ASSERT(ten_, "Should not happen.");
delete ten_;
TEN_ASSERT(cpp_ten_env, "Should not happen.");
delete cpp_ten_env;
}

// @{
Expand All @@ -47,25 +47,24 @@ class app_t {
app_t &operator=(app_t &&) = delete;
// @}

// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
bool run(bool run_in_background = false, error_t *err = nullptr) {
if (app_ == nullptr) {
if (c_app == nullptr) {
return false;
}

return ten_app_run(
app_, run_in_background,
c_app, run_in_background,
err != nullptr ? err->get_internal_representation() : nullptr);
}

bool close(error_t *err = nullptr) {
return ten_app_close(
app_, err != nullptr ? err->get_internal_representation() : nullptr);
c_app, err != nullptr ? err->get_internal_representation() : nullptr);
}

bool wait(error_t *err = nullptr) {
return ten_app_wait(
app_, err != nullptr ? err->get_internal_representation() : nullptr);
c_app, err != nullptr ? err->get_internal_representation() : nullptr);
}

protected:
Expand Down Expand Up @@ -180,8 +179,8 @@ class app_t {
}
}

::ten_app_t *app_ = nullptr;
ten_env_t *ten_;
::ten_app_t *c_app = nullptr;
ten_env_t *cpp_ten_env;
};

} // namespace ten
6 changes: 2 additions & 4 deletions core/include/ten_runtime/binding/cpp/internal/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class extension_t {
reinterpret_cast<ten_binding_handle_t *>(c_extension),
static_cast<void *>(this));

cpp_ten_env = new ten_env_t(ten_extension_get_ten(c_extension));
cpp_ten_env = new ten_env_t(ten_extension_get_ten_env(c_extension));
TEN_ASSERT(cpp_ten_env, "Should not happen.");
}

Expand Down Expand Up @@ -127,7 +127,7 @@ class extension_t {
friend class extension_group_t;

using cpp_extension_on_cmd_func_t =
void (extension_t:: *)(ten_env_t &, std::unique_ptr<cmd_t>);
void (extension_t::*)(ten_env_t &, std::unique_ptr<cmd_t>);

static void issue_stop_graph_cmd(ten_env_t &ten_env) {
// Issue a 'close engine' command, and in order to gain the maximum
Expand Down Expand Up @@ -213,8 +213,6 @@ class extension_t {
::ten_env_t *ten_env, ten_shared_ptr_t *cmd,
cpp_extension_on_cmd_func_t on_cmd_func);

// This function would be called when the extension does _not_ enable the
// command binding mechanism.
static void proxy_on_cmd(ten_extension_t *extension, ::ten_env_t *ten_env,
ten_shared_ptr_t *cmd) {
proxy_on_cmd_internal(extension, ten_env, cmd, &extension_t::on_cmd);
Expand Down
16 changes: 8 additions & 8 deletions core/include/ten_runtime/binding/cpp/internal/extension_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class app_t;
class extension_group_t {
public:
virtual ~extension_group_t() {
TEN_ASSERT(c_extension_group_, "Should not happen.");
ten_extension_group_destroy(c_extension_group_);
TEN_ASSERT(c_extension_group, "Should not happen.");
ten_extension_group_destroy(c_extension_group);

TEN_ASSERT(cpp_ten_env, "Should not happen.");
delete cpp_ten_env;
Expand All @@ -43,19 +43,19 @@ class extension_group_t {
// @{
// Internal use only.
::ten_extension_group_t *get_c_extension_group() const {
return c_extension_group_;
return c_extension_group;
}
// @}

protected:
explicit extension_group_t(const std::string &name)
: c_extension_group_(ten_extension_group_create(
: c_extension_group(ten_extension_group_create(
name.c_str(), proxy_on_configure, proxy_on_init, proxy_on_deinit,
proxy_on_create_extensions, proxy_on_destroy_extensions)),
cpp_ten_env(new ten_env_t(
ten_extension_group_get_ten_env(c_extension_group_))) {
cpp_ten_env(
new ten_env_t(ten_extension_group_get_ten_env(c_extension_group))) {
ten_binding_handle_set_me_in_target_lang(
reinterpret_cast<ten_binding_handle_t *>(c_extension_group_), this);
reinterpret_cast<ten_binding_handle_t *>(c_extension_group), this);

TEN_ASSERT(cpp_ten_env, "Should not happen.");
}
Expand Down Expand Up @@ -205,7 +205,7 @@ class extension_group_t {
cpp_extension_group->on_destroy_extensions(*cpp_ten_env, extensions_vector);
}

::ten_extension_group_t *c_extension_group_;
::ten_extension_group_t *c_extension_group;
ten_env_t *cpp_ten_env;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace ten {
inline void extension_t::proxy_on_cmd_internal(
ten_extension_t *extension, ::ten_env_t *ten_env, ten_shared_ptr_t *cmd,
cpp_extension_on_cmd_func_t on_cmd_func) {
TEN_ASSERT(extension && ten_env, "Should not happen.");
TEN_ASSERT(extension && ten_env && cmd, "Should not happen.");

auto *cpp_extension =
static_cast<extension_t *>(ten_binding_handle_get_me_in_target_lang(
Expand Down
44 changes: 22 additions & 22 deletions core/include/ten_runtime/binding/cpp/internal/msg/audio_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,78 +70,78 @@ class audio_frame_t : public msg_t {
~audio_frame_t() override = default;

int64_t get_timestamp(error_t *err = nullptr) const {
return ten_audio_frame_get_timestamp(c_msg_);
return ten_audio_frame_get_timestamp(c_msg);
}
bool set_timestamp(int64_t timestamp, error_t *err = nullptr) {
return ten_audio_frame_set_timestamp(c_msg_, timestamp);
return ten_audio_frame_set_timestamp(c_msg, timestamp);
}

int32_t get_sample_rate(error_t *err = nullptr) const {
return ten_audio_frame_get_sample_rate(c_msg_);
return ten_audio_frame_get_sample_rate(c_msg);
}
bool set_sample_rate(int32_t sample_rate, error_t *err = nullptr) {
return ten_audio_frame_set_sample_rate(c_msg_, sample_rate);
return ten_audio_frame_set_sample_rate(c_msg, sample_rate);
}

uint64_t get_channel_layout(error_t *err = nullptr) const {
return ten_audio_frame_get_channel_layout(c_msg_);
return ten_audio_frame_get_channel_layout(c_msg);
}
bool set_channel_layout(uint64_t channel_layout, error_t *err = nullptr) {
return ten_audio_frame_set_channel_layout(c_msg_, channel_layout);
return ten_audio_frame_set_channel_layout(c_msg, channel_layout);
}

int32_t get_samples_per_channel(error_t *err = nullptr) const {
return ten_audio_frame_get_samples_per_channel(c_msg_);
return ten_audio_frame_get_samples_per_channel(c_msg);
}
bool set_samples_per_channel(int32_t samples_per_channel,
error_t *err = nullptr) {
return ten_audio_frame_set_samples_per_channel(c_msg_, samples_per_channel);
return ten_audio_frame_set_samples_per_channel(c_msg, samples_per_channel);
}

int32_t get_bytes_per_sample(error_t *err = nullptr) const {
return ten_audio_frame_get_bytes_per_sample(c_msg_);
return ten_audio_frame_get_bytes_per_sample(c_msg);
}
bool set_bytes_per_sample(int32_t size, error_t *err = nullptr) {
return ten_audio_frame_set_bytes_per_sample(c_msg_, size);
return ten_audio_frame_set_bytes_per_sample(c_msg, size);
}

int32_t get_number_of_channels(error_t *err = nullptr) const {
return ten_audio_frame_get_number_of_channel(c_msg_);
return ten_audio_frame_get_number_of_channel(c_msg);
}
bool set_number_of_channels(int32_t number, error_t *err = nullptr) {
return ten_audio_frame_set_number_of_channel(c_msg_, number);
return ten_audio_frame_set_number_of_channel(c_msg, number);
}

TEN_AUDIO_FRAME_DATA_FMT get_data_fmt(error_t *err = nullptr) const {
return ten_audio_frame_get_data_fmt(c_msg_);
return ten_audio_frame_get_data_fmt(c_msg);
}
bool set_data_fmt(TEN_AUDIO_FRAME_DATA_FMT format, error_t *err = nullptr) {
return ten_audio_frame_set_data_fmt(c_msg_, format);
return ten_audio_frame_set_data_fmt(c_msg, format);
}

int32_t get_line_size(error_t *err = nullptr) const {
return ten_audio_frame_get_line_size(c_msg_);
return ten_audio_frame_get_line_size(c_msg);
}
bool set_line_size(int32_t line_size, error_t *err = nullptr) {
return ten_audio_frame_set_line_size(c_msg_, line_size);
return ten_audio_frame_set_line_size(c_msg, line_size);
}

bool is_eof(error_t *err = nullptr) const {
return ten_audio_frame_is_eof(c_msg_);
return ten_audio_frame_is_eof(c_msg);
}
bool set_is_eof(bool is_eof, error_t *err = nullptr) {
return ten_audio_frame_set_is_eof(c_msg_, is_eof);
return ten_audio_frame_set_is_eof(c_msg, is_eof);
}

bool alloc_buf(size_t size, error_t *err = nullptr) {
return ten_audio_frame_alloc_data(c_msg_, size) != nullptr;
return ten_audio_frame_alloc_data(c_msg, size) != nullptr;
}

buf_t lock_buf(error_t *err = nullptr) const {
ten_buf_t *data = ten_audio_frame_peek_data(c_msg_);
ten_buf_t *data = ten_audio_frame_peek_data(c_msg);

if (!ten_msg_add_locked_res_buf(
c_msg_, data->data,
c_msg, data->data,
err != nullptr ? err->get_internal_representation() : nullptr)) {
return buf_t{};
}
Expand All @@ -154,7 +154,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,
c_msg, data,
err != nullptr ? err->get_internal_representation() : nullptr)) {
return false;
}
Expand Down
13 changes: 7 additions & 6 deletions core/include/ten_runtime/binding/cpp/internal/msg/cmd/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <memory>

#include "ten_utils/macro/check.h"
#include "ten_runtime/binding/cpp/internal/msg/msg.h"
#include "ten_runtime/msg/cmd/cmd.h"
#include "ten_runtime/msg/msg.h"
Expand All @@ -19,11 +18,10 @@
namespace ten {

class extension_t;
class extension_tester_t;

class cmd_t : public msg_t {
private:
friend extension_t;

// Passkey Idiom.
struct ctor_passkey_t {
private:
Expand Down Expand Up @@ -74,11 +72,14 @@ class cmd_t : public msg_t {
// @}

private:
friend extension_t;
friend extension_tester_t;

void clone_internal(const cmd_t &cmd) noexcept {
if (cmd.c_msg_ != nullptr) {
c_msg_ = ten_msg_clone(cmd.c_msg_, nullptr);
if (cmd.c_msg != nullptr) {
c_msg = ten_msg_clone(cmd.c_msg, nullptr);
} else {
c_msg_ = nullptr;
c_msg = nullptr;
}
}
};
Expand Down
14 changes: 8 additions & 6 deletions core/include/ten_runtime/binding/cpp/internal/msg/cmd_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
namespace ten {

class extension_t;
class ten_env_tester_t;

class cmd_result_t : public msg_t {
private:
friend extension_t;
friend ten_env_t;

// Passkey Idiom.
struct ctor_passkey_t {
private:
Expand All @@ -46,17 +44,17 @@ class cmd_result_t : public msg_t {
~cmd_result_t() override = default;

TEN_STATUS_CODE get_status_code(error_t *err = nullptr) const {
return ten_cmd_result_get_status_code(c_msg_);
return ten_cmd_result_get_status_code(c_msg);
}

bool get_is_final(error_t *err = nullptr) const {
return ten_cmd_result_get_is_final(
c_msg_, err != nullptr ? err->get_internal_representation() : nullptr);
c_msg, err != nullptr ? err->get_internal_representation() : nullptr);
}

bool set_is_final(bool is_final, error_t *err = nullptr) {
return ten_cmd_result_set_is_final(
c_msg_, is_final,
c_msg, is_final,
err != nullptr ? err->get_internal_representation() : nullptr);
}

Expand All @@ -68,6 +66,10 @@ class cmd_result_t : public msg_t {
// @}

private:
friend extension_t;
friend ten_env_tester_t;
friend ten_env_t;

static std::unique_ptr<cmd_result_t> create(ten_shared_ptr_t *cmd,
error_t *err = nullptr) {
return std::make_unique<cmd_result_t>(cmd, ctor_passkey_t());
Expand Down
Loading

0 comments on commit 99b0921

Please sign in to comment.