1 Star 0 Fork 13

胖子的梦/ani_cookbook

forked from Xingwa/ani_cookbook 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
async_work_helper.cpp 2.13 KB
一键复制 编辑 原始数据 按行查看 历史
Xingwa 提交于 2025-02-15 17:57 +08:00 . Add sync_work_ helper code, not work yet
#include <ani.h>
#include <array>
#include <iostream>
typedef void (*ani_async_workaround_execute_callback)(ani_env env,
void* data);
typedef void (*ani_async__workaround_complete_callback)(ani_env env,
ani_status status,
void* data);
struct native_data {
void *data;
ani_async_workaround_execute_callback execute;
ani_async__workaround_complete_callback complete;
};
typedef native_data ani_sync_work_handle_t;
ani_status ani_create_sync_work_handle(
ani_async_workaround_execute_callback excute,
ani_async__workaround_complete_callback complete,
void *data,
ani_sync_work_handle_t **result){
auto w = new native_data();
w->execute = excute;
w->complete = complete;
w->data;
*result = w;
return ANI_OK;
}
static void execute(ani_env *env, ani_object obj)
{
}
static int complete(ani_env *env, ani_object obj)
{
return 0;
}
static void AsyncTest(ani_env *env, ani_class cls, ani_object obj)
{
}
ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
{
ani_env *env;
if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
std::cerr << "Unsupported ANI_VERSION_1" << std::endl;
return ANI_ERROR;
}
static const char *className = "Lasync_work_helper/AsyncWorkHelper;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
return ANI_ERROR;
}
std::array methods = {
ani_native_function {"execute", ":V", reinterpret_cast<void *>(execute)},
ani_native_function {"complete", ":I", reinterpret_cast<void *>(complete)},
ani_native_function {"AsyncTest", "Lasync_work_helper/AsyncWorkHelper;:V", reinterpret_cast<void *>(AsyncTest)},
};
if (ANI_OK != env->Class_BindNativeMethods(cls, methods.data(), methods.size())) {
std::cerr << "Cannot bind native methods to '" << className << "'" << std::endl;
return ANI_ERROR;
};
*result = ANI_VERSION_1;
return ANI_OK;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pangzidemeng/ani_cookbook.git
git@gitee.com:pangzidemeng/ani_cookbook.git
pangzidemeng
ani_cookbook
ani_cookbook
master

搜索帮助