Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: remove is_cmd_connected api #356

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions core/include/ten_runtime/binding/cpp/detail/ten_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,6 @@ class ten_env_t {
return set_property_impl(path, ten_value_create_buf_with_move(buf), err);
}

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_c_error() : nullptr);
}

bool on_configure_done(error_t *err = nullptr) {
TEN_ASSERT(c_ten_env, "Should not happen.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_set_property_from_json(
TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_is_property_exist(
PyObject *self, PyObject *args);

TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_is_cmd_connected(
PyObject *self, PyObject *args);

TEN_RUNTIME_PRIVATE_API PyObject *ten_py_ten_env_get_property_int(
PyObject *self, PyObject *args);

Expand Down
11 changes: 0 additions & 11 deletions core/src/ten_runtime/binding/go/interface/ten/ten_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ type TenEnv interface {
OnDeinitDone() error
OnCreateInstanceDone(instance any, context uintptr) error

IsCmdConnected(cmdName string) (bool, error)

iProperty
InitPropertyFromJSONBytes(value []byte) error

Expand Down Expand Up @@ -359,15 +357,6 @@ func (p *tenEnv) OnCreateInstanceDone(instance any, context uintptr) error {
return nil
}

func (p *tenEnv) IsCmdConnected(cmdName string) (bool, error) {
return p.process(func() any {
cName := C.CString(cmdName)
defer C.free(unsafe.Pointer(cName))

return bool(C.ten_go_ten_env_is_cmd_connected(p.cPtr, cName))
}).(bool), nil
}

func (p *tenEnv) String() string {
cString := C.ten_go_ten_env_debug_info(p.cPtr)
defer C.free(unsafe.Pointer(cString))
Expand Down
3 changes: 0 additions & 3 deletions core/src/ten_runtime/binding/go/interface/ten/ten_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ ten_go_error_t ten_go_ten_env_send_audio_frame(
uintptr_t bridge_addr, uintptr_t audio_frame_bridge_addr,
ten_go_handle_t handler_id);

bool ten_go_ten_env_is_cmd_connected(uintptr_t bridge_addr,
const char *cmd_name);

bool ten_go_ten_env_addon_create_extension(uintptr_t bridge_addr,
const char *addon_name,
const char *instance_name,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class _TenEnv:
def return_result(self, result: _CmdResult, target_cmd: _Cmd) -> None: ...
def return_result_directly(self, result: _CmdResult) -> None: ...
def is_property_exist(self, path: str) -> bool: ...
def is_cmd_connected(self, msg_name: str) -> bool: ...
def init_property_from_json(self, json_str: str) -> None: ...
def log(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ def return_result_directly(self, result: CmdResult) -> None:
def is_property_exist(self, path: str) -> bool:
return self._internal.is_property_exist(path)

def is_cmd_connected(self, msg_name: str) -> bool:
return self._internal.is_cmd_connected(msg_name)

def get_property_int(self, path: str) -> int:
return self._internal.get_property_int(path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ PyTypeObject *ten_py_ten_env_type(void) {
NULL},
{"is_property_exist", ten_py_ten_env_is_property_exist, METH_VARARGS,
NULL},
{"is_cmd_connected", ten_py_ten_env_is_cmd_connected, METH_VARARGS, NULL},
{"init_property_from_json", ten_py_ten_env_init_property_from_json,
METH_VARARGS, NULL},
{"log", ten_py_ten_env_log, METH_VARARGS, NULL},
Expand Down

This file was deleted.

32 changes: 16 additions & 16 deletions packages/example_extensions/simple_http_server_cpp/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -634,19 +634,19 @@ void send_ten_msg_with_req_body(
// command.
cmd->from_json(cmd_json.dump().c_str());

if (cmd->get_type() == TEN_MSG_TYPE_CMD &&
!ten_env.is_cmd_connected(cmd->get_name())) {
prepare_response_data_from_ten_world(http_session_data,
"The command is not supported.");
return;
}

// Send out the command to the TEN runtime.
ten_env.send_cmd(
std::move(cmd),
[http_session_data](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd,
ten::error_t * /*error*/) {
ten::error_t *error) {
if (error != nullptr) {
prepare_response_data_from_ten_world(
http_session_data, "The command is not supported. err:" +
std::string(error->errmsg()));
return;
}

auto *ext = static_cast<http_server_extension_t *>(
ten_env.get_attached_target());
assert(ext && "Failed to get the attached extension.");
Expand All @@ -673,19 +673,19 @@ void send_ten_msg_without_req_body(
cmd->set_property("method", method);
cmd->set_property("url", http_session_data->url);

if (cmd->get_type() == TEN_MSG_TYPE_CMD &&
!ten_env.is_cmd_connected(cmd->get_name())) {
prepare_response_data_from_ten_world(http_session_data,
"The command is not supported.");
return;
}

// Send out the command to the TEN runtime.
ten_env.send_cmd(
std::move(cmd),
[http_session_data](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd,
ten::error_t * /*error*/) {
ten::error_t *error) {
if (error != nullptr) {
prepare_response_data_from_ten_world(
http_session_data, "The command is not supported. err:" +
std::string(error->errmsg()));
return;
}

auto *ext = static_cast<http_server_extension_t *>(
ten_env.get_attached_target());
assert(ext && "Failed to get the attached extension.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ func (p *extensionB) OnCmd(
go func() {
fmt.Println("extensionB OnCmd")

connected, err := tenEnv.IsCmdConnected("cmd_not_exist")
if err != nil || connected {
panic("Should not happen.")
}

cmdName, _ := cmd.GetName()
if cmdName == "B" {
var count uint32 = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ async def on_cmd(self, ten_env: AsyncTenEnv, cmd: Cmd) -> None:
# Mock async operation, e.g. network, file I/O.
await asyncio.sleep(0.5)

assert ten_env.is_cmd_connected("hello") is True
assert ten_env.is_cmd_connected("unknown_cmd") is False

# Send a new command to other extensions and wait for the result. The
# result will be returned to the original sender.
new_cmd = Cmd.create("hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ class test_extension_1 : public ten::extension_t {

void on_cmd(ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_t> cmd) override {
const auto *cmd_name = cmd->get_name();
auto res = ten_env.is_cmd_connected(cmd_name);
if (res) {
ten_env.send_cmd(std::move(cmd));
} else {
auto rc = ten_env.send_cmd(std::move(cmd));
if (!rc) {
auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK);
cmd_result->set_property("detail", "can not find a way out");
ten_env.return_result(std::move(cmd_result), std::move(cmd));
Expand Down
Loading