75 lines
2.4 KiB
C++
75 lines
2.4 KiB
C++
#include "napi/native_api.h"
|
|
#include "hilog/log.h"
|
|
#include "Add/Add.h"
|
|
#include "NativeEGLOCCT/common.h"
|
|
#include "NativeEGLOCCT/NativeManager.h"
|
|
|
|
static napi_value NativeLoadSoTest(napi_env env, napi_callback_info info)
|
|
{
|
|
size_t argc = 2;
|
|
napi_value args[2] = {nullptr};
|
|
|
|
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
|
|
|
napi_valuetype valuetype0;
|
|
napi_typeof(env, args[0], &valuetype0);
|
|
|
|
napi_valuetype valuetype1;
|
|
napi_typeof(env, args[1], &valuetype1);
|
|
|
|
double value0;
|
|
napi_get_value_double(env, args[0], &value0);
|
|
|
|
double value1;
|
|
napi_get_value_double(env, args[1], &value1);
|
|
|
|
auto _sum=Add(value0,value1);
|
|
napi_value sum;
|
|
napi_create_double(env, _sum, &sum);
|
|
|
|
return sum;
|
|
}
|
|
|
|
namespace NativeOpenCAX {
|
|
EXTERN_C_START
|
|
static napi_value Init(napi_env env, napi_value exports) {
|
|
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Init", "Init begins");
|
|
if ((env == nullptr) || (exports == nullptr)) {
|
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Init", "env or exports is null");
|
|
return nullptr;
|
|
}
|
|
napi_property_descriptor desc[] = {
|
|
// [StartExclude napi_init_part]
|
|
{"createNativeNode", nullptr, NativeManager::createNativeNode, nullptr, nullptr, nullptr,napi_default, nullptr },
|
|
{"loadModel", nullptr, NativeManager::NapiLoadModel, nullptr, nullptr, nullptr, napi_default, nullptr},
|
|
{"setFrameRate", nullptr, NativeManager::SetFrameRate, nullptr, nullptr, nullptr, napi_default, nullptr},
|
|
{"setNeedSoftKeyboard", nullptr, NativeManager::SetNeedSoftKeyboard, nullptr, nullptr, nullptr, napi_default,nullptr},
|
|
{"nativeLoadTest", nullptr, NativeLoadSoTest, nullptr, nullptr, nullptr, napi_default, nullptr},
|
|
};
|
|
napi_status status = napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
|
|
if (status != napi_ok) {
|
|
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Init", "Failed to define properties.");
|
|
return nullptr;
|
|
}
|
|
return exports;
|
|
}
|
|
|
|
EXTERN_C_END
|
|
|
|
// 编写接口的描述信息,根据实际需要可以修改对应参数
|
|
static napi_module OpenCAXModel = {
|
|
.nm_version = 1,
|
|
.nm_flags = 0,
|
|
.nm_filename = nullptr,
|
|
.nm_register_func = Init,
|
|
.nm_modname = "opencax",
|
|
.nm_priv = ((void*)0),
|
|
.reserved = { 0 }
|
|
};
|
|
}
|
|
extern "C" __attribute__((constructor))
|
|
void RegisterOpenCAXModule(void)
|
|
{
|
|
napi_module_register(&NativeOpenCAX::OpenCAXModel);
|
|
}
|