Skip to content

Commit

Permalink
chore: remove extension_group relevant interface (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Nov 25, 2024
1 parent b59cde3 commit f57aa21
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 385 deletions.
69 changes: 0 additions & 69 deletions core/include/ten_runtime/binding/cpp/internal/ten_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ class ten_env_internal_accessor_t;
using result_handler_func_t =
std::function<void(ten_env_t &, std::unique_ptr<cmd_result_t>)>;

using addon_create_extension_async_cb_t =
std::function<void(ten_env_t &, ten::extension_t &)>;

using addon_destroy_extension_async_cb_t = std::function<void(ten_env_t &)>;

using set_property_async_cb_t =
std::function<void(ten_env_t &, bool, error_t *err)>;

Expand Down Expand Up @@ -593,32 +588,6 @@ class ten_env_t {
err != nullptr ? err->get_internal_representation() : nullptr);
}

bool addon_create_extension_async(
const char *addon_name, const char *instance_name,
addon_create_extension_async_cb_t &&cb = nullptr,
error_t *err = nullptr) {
if (cb == nullptr) {
return ten_addon_create_extension(
c_ten_env, addon_name, instance_name, nullptr, nullptr,
err != nullptr ? err->get_internal_representation() : nullptr);
} else {
auto *cb_ptr = new addon_create_extension_async_cb_t(std::move(cb));

return ten_addon_create_extension(
c_ten_env, addon_name, instance_name,
proxy_addon_create_extension_async_cb, cb_ptr,
err != nullptr ? err->get_internal_representation() : nullptr);
}
}

bool addon_destroy_extension(ten::extension_t *extension,
error_t *err = nullptr);

bool addon_destroy_extension_async(
ten::extension_t *extension,
addon_destroy_extension_async_cb_t &&cb = nullptr,
error_t *err = nullptr);

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

Expand Down Expand Up @@ -660,15 +629,6 @@ class ten_env_t {
err != nullptr ? err->get_internal_representation() : nullptr);
}

bool on_create_extensions_done(const std::vector<extension_t *> &extensions,
error_t *err = nullptr);

bool on_destroy_extensions_done(error_t *err = nullptr) {
return ten_env_on_destroy_extensions_done(
c_ten_env,
err != nullptr ? err->get_internal_representation() : nullptr);
}

bool on_create_instance_done(void *instance, void *context,
error_t *err = nullptr);

Expand Down Expand Up @@ -900,35 +860,6 @@ class ten_env_t {
}
}

static void proxy_addon_create_extension_async_cb(::ten_env_t *ten_env,
void *instance,
void *cb_data) {
auto *addon_create_extension_async_cb =
static_cast<addon_create_extension_async_cb_t *>(cb_data);
auto *cpp_ten_env =
static_cast<ten_env_t *>(ten_binding_handle_get_me_in_target_lang(
reinterpret_cast<ten_binding_handle_t *>(ten_env)));

(*addon_create_extension_async_cb)(
*cpp_ten_env,
*static_cast<ten::extension_t *>(
ten_binding_handle_get_me_in_target_lang(
reinterpret_cast<ten_binding_handle_t *>(instance))));
delete addon_create_extension_async_cb;
}

static void proxy_addon_destroy_extension_async_cb(::ten_env_t *ten_env,
void *cb_data) {
auto *addon_destroy_extension_async_cb =
static_cast<addon_destroy_extension_async_cb_t *>(cb_data);
auto *cpp_ten_env =
static_cast<ten_env_t *>(ten_binding_handle_get_me_in_target_lang(
reinterpret_cast<ten_binding_handle_t *>(ten_env)));

(*addon_destroy_extension_async_cb)(*cpp_ten_env);
delete addon_destroy_extension_async_cb;
}

static void proxy_set_property_callback(::ten_env_t *ten_env, bool res,
void *cb_data, ten_error_t *err) {
auto *callback = static_cast<set_property_async_cb_t *>(cb_data);
Expand Down
31 changes: 0 additions & 31 deletions core/include/ten_runtime/binding/cpp/internal/ten_env_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,4 @@ inline bool ten_env_t::on_create_instance_done(void *instance, void *context,
return rc;
}

inline bool ten_env_t::on_create_extensions_done(
const std::vector<extension_t *> &extensions, error_t *err) {
ten_list_t c_extensions = TEN_LIST_INIT_VAL;

for (const auto &extension : extensions) {
ten_list_push_ptr_back(&c_extensions, extension->get_c_extension(),
nullptr);
}

return ten_env_on_create_extensions_done(
c_ten_env, &c_extensions,
err != nullptr ? err->get_internal_representation() : nullptr);
}

inline bool ten_env_t::addon_destroy_extension_async(
ten::extension_t *extension, addon_destroy_extension_async_cb_t &&cb,
error_t *err) {
if (cb == nullptr) {
return ten_addon_destroy_extension(
c_ten_env, extension->get_c_extension(), nullptr, nullptr,
err != nullptr ? err->get_internal_representation() : nullptr);
} else {
auto *cb_ptr = new addon_destroy_extension_async_cb_t(std::move(cb));

return ten_addon_destroy_extension(
c_ten_env, extension->get_c_extension(),
proxy_addon_destroy_extension_async_cb, cb_ptr,
err != nullptr ? err->get_internal_representation() : nullptr);
}
}

} // namespace ten
4 changes: 0 additions & 4 deletions core/src/ten_runtime/binding/go/interface/ten/prop.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ type iProperty interface {
GetPropertyToJSONBytes(path string) ([]byte, error)
}

type iPropertyContainerForAsyncGeneric interface {
postAsyncJob(payload job) any
}

// The purpose of having this function is because there are two types of
// getProperty:
//
Expand Down
107 changes: 4 additions & 103 deletions core/src/ten_runtime/binding/go/interface/ten/ten_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ type (

// TenEnv represents the interface for the TEN (Run Time Environment) component.
type TenEnv interface {
postSyncJob(payload job) any
postAsyncJob(payload job) any

SendCmd(cmd Cmd, handler ResultHandler) error
SendData(data Data) error
SendVideoFrame(videoFrame VideoFrame) error
Expand All @@ -41,26 +38,11 @@ type TenEnv interface {
OnStartDone() error
OnStopDone() error
OnDeinitDone() error

OnCreateExtensionsDone(extensions ...Extension) error
OnDestroyExtensionsDone() error

OnCreateInstanceDone(instance any, context uintptr) error

IsCmdConnected(cmdName string) (bool, error)

AddonCreateExtensionAsync(
addonName string,
instanceName string,
callback func(tenEnv TenEnv, p Extension),
) error
AddonDestroyExtensionAsync(
ext Extension,
callback func(tenEnv TenEnv),
) error

iProperty

InitPropertyFromJSONBytes(value []byte) error

LogVerbose(msg string)
Expand All @@ -71,6 +53,9 @@ type TenEnv interface {
LogFatal(msg string)
Log(level LogLevel, msg string)

// Private functions.
postSyncJob(payload job) any
postAsyncJob(payload job) any
logInternal(level LogLevel, msg string, skip int)
}

Expand All @@ -85,8 +70,7 @@ type TenEnv interface {
// in my code; I just want to make sure it's true." If 'ten' doesn't implement
// Ten, you'll know as soon as you try to compile.
var (
_ TenEnv = new(tenEnv)
_ iPropertyContainerForAsyncGeneric = new(tenEnv)
_ TenEnv = new(tenEnv)
)

type tenAttachTo uint8
Expand Down Expand Up @@ -322,36 +306,6 @@ func (p *tenEnv) OnDeinitDone() error {
return nil
}

func (p *tenEnv) OnCreateExtensionsDone(extensions ...Extension) error {
if len(extensions) == 0 {
return nil
}

var extensionArray []C.uintptr_t
for _, v := range extensions {
extension, ok := v.(*extension)
if !ok {
panic("Invalid extension type")
}

extensionArray = append(extensionArray, extension.cPtr)
}

C.ten_go_ten_env_on_create_extensions_done(
p.cPtr,
unsafe.Pointer(unsafe.SliceData(extensionArray)),
C.int(len(extensions)),
)

return nil
}

func (p *tenEnv) OnDestroyExtensionsDone() error {
C.ten_go_ten_env_on_destroy_extensions_done(p.cPtr)

return nil
}

func (p *tenEnv) OnCreateInstanceDone(instance any, context uintptr) error {
switch instance := instance.(type) {
case *extension:
Expand All @@ -372,59 +326,6 @@ func (p *tenEnv) IsCmdConnected(cmdName string) (bool, error) {
}).(bool), nil
}

func (p *tenEnv) AddonCreateExtensionAsync(
addonName string,
instanceName string,
callback func(tenEnv TenEnv, p Extension),
) error {
handlerID := newhandle(callback)

cAddonName := C.CString(addonName)
defer C.free(unsafe.Pointer(cAddonName))

cInstanceName := C.CString(instanceName)
defer C.free(unsafe.Pointer(cInstanceName))

res := bool(
C.ten_go_ten_env_addon_create_extension(
p.cPtr,
cAddonName,
cInstanceName,
C.uintptr_t(handlerID),
),
)
if !res {
return newTenError(
ErrnoGeneric,
fmt.Sprintf("failed to find addon: %s", addonName),
)
}

return nil
}

func (p *tenEnv) AddonDestroyExtensionAsync(
ext Extension,
callback func(tenEnv TenEnv),
) error {
extension, ok := ext.(*extension)
if !ok {
return newTenError(
ErrnoInvalidArgument,
"wrong extension type.",
)
}

handlerID := newhandle(callback)

C.ten_go_ten_env_addon_destroy_extension(
p.cPtr,
extension.cPtr,
C.uintptr_t(handlerID),
)
return nil
}

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

void ten_go_ten_env_on_deinit_done(uintptr_t bridge_addr);

void ten_go_ten_env_on_create_extensions_done(
uintptr_t bridge_addr, const void *extension_bridge_array, int size);

void ten_go_ten_env_on_destroy_extensions_done(uintptr_t bridge_addr);

void ten_go_ten_env_on_create_instance_done(uintptr_t bridge_addr,
uintptr_t instance_bridge_addr,
uintptr_t context_addr);
Expand Down
Loading

0 comments on commit f57aa21

Please sign in to comment.