-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yass: add setProtectFd for open harmony
Ref: #698.
- Loading branch information
1 parent
acd60e2
commit 0fdff1e
Showing
4 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
global: RegisterEntryModule; | ||
local: *; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2024 Chilledheart */ | ||
#ifdef __OHOS__ | ||
|
||
#include "harmony/yass.hpp" | ||
|
||
#include "core/logging.hpp" | ||
|
||
#include <napi/native_api.h> | ||
#include <js_native_api.h> | ||
#include <js_native_api_types.h> | ||
|
||
static napi_value setProtectFdCallbackThis = nullptr; | ||
static napi_value setProtectFdCallbackFunc = nullptr; | ||
|
||
static napi_value setProtectFdCallback(napi_env env, napi_callback_info info) { | ||
napi_status status; | ||
|
||
size_t argc = 1; | ||
napi_value args[1] = {nullptr}; | ||
status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); | ||
if (status != napi_ok) { | ||
LOG(WARNING) << "napi_get_cb_info: " << status; | ||
return 0; | ||
} | ||
|
||
napi_value cb = args[0]; | ||
napi_valuetype type; | ||
status = napi_typeof(env, cb, &type); | ||
if (status != napi_ok) { | ||
LOG(WARNING) << "napi_typeof: " << status; | ||
return 0; | ||
} | ||
|
||
if (type != napi_function) { | ||
LOG(WARNING) << "invalid type: " << type << " expected: napi_function"; | ||
return 0; | ||
} | ||
|
||
napi_value global; | ||
status = napi_get_global(env, &global); | ||
if (status != napi_ok) { | ||
LOG(WARNING) << "napi_get_global: " << status; | ||
return 0; | ||
} | ||
|
||
setProtectFdCallbackThis = global; | ||
setProtectFdCallbackFunc = cb; | ||
|
||
return 0; | ||
} | ||
|
||
static napi_value Init(napi_env env, napi_value exports) { | ||
napi_property_descriptor desc[] = { | ||
{"setProtectFdCallback", nullptr, setProtectFdCallback, nullptr, nullptr, nullptr, napi_default, nullptr}, | ||
}; | ||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); | ||
return exports; | ||
} | ||
|
||
static napi_module demoModule = { | ||
.nm_version = 1, | ||
.nm_flags = 0, | ||
.nm_filename = nullptr, | ||
.nm_register_func = Init, | ||
.nm_modname = "entry", | ||
.nm_priv = ((void *)0), | ||
.reserved = {0}, | ||
}; | ||
|
||
extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { | ||
napi_module_register(&demoModule); | ||
} | ||
|
||
#endif // __OHOS__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2024 Chilledheart */ | ||
#ifndef _H_HARMONY_YASS_HPP | ||
#define _H_HARMONY_YASS_HPP | ||
|
||
#ifdef __OHOS__ | ||
|
||
__attribute__((visibility ("default"))) | ||
extern "C" void RegisterEntryModule(void); | ||
|
||
#endif // __OHOS__ | ||
|
||
#endif // _H_HARMONY_YASS_HPP |