mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
so part
Signed-off-by: zhuhan <2281542033@qq.com> Change-Id: I01304b72d8c96631f1290900bf60e1fa0b5407d0
This commit is contained in:
@@ -52,7 +52,7 @@ ohos_shared_library("abilitystage") {
|
||||
}
|
||||
|
||||
ohos_shared_library("abilitystage_napi") {
|
||||
sources = [ "ability_stage_module.cpp" ]
|
||||
sources = [ "ability_stage_napi_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":ability_stage_abc",
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_ability_stage_js_start[];
|
||||
extern const char _binary_ability_stage_js_end[];
|
||||
extern const char _binary_ability_stage_abc_start[];
|
||||
extern const char _binary_ability_stage_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
#ifndef ENABLE_ERRCODE
|
||||
.nm_version = 0,
|
||||
.nm_filename = "application/libabilitystage_napi.so/ability_stage.js",
|
||||
.nm_modname = "application.AbilityStage",
|
||||
#endif
|
||||
};
|
||||
extern "C" __attribute__((constructor))
|
||||
#ifndef ENABLE_ERRCODE
|
||||
void NAPI_application_AbilityStage_AutoRegister()
|
||||
#endif
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
#ifndef ENABLE_ERRCODE
|
||||
void NAPI_application_AbilityStage_GetJSCode(const char **buf, int *bufLen)
|
||||
#endif
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_ability_stage_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_ability_stage_js_end - _binary_ability_stage_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// ability_stage JS register
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
#ifndef ENABLE_ERRCODE
|
||||
void NAPI_application_AbilityStage_GetABCCode(const char **buf, int *buflen)
|
||||
#endif
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_ability_stage_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_ability_stage_abc_end - _binary_ability_stage_abc_start;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import("//build/ohos.gni")
|
||||
ohos_shared_library("configurationconstant_napi") {
|
||||
include_dirs = []
|
||||
|
||||
sources = [ "configuration_constant_module.cpp" ]
|
||||
sources = [ "configuration_constant_napi_module.cpp" ]
|
||||
|
||||
deps = []
|
||||
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "res_common.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
static napi_status SetEnumItem(napi_env env, napi_value object, const char* name, int32_t value)
|
||||
{
|
||||
napi_status status;
|
||||
napi_value itemName;
|
||||
napi_value itemValue;
|
||||
|
||||
NAPI_CALL_BASE(env, status = napi_create_string_utf8(env, name, NAPI_AUTO_LENGTH, &itemName), status);
|
||||
NAPI_CALL_BASE(env, status = napi_create_int32(env, value, &itemValue), status);
|
||||
|
||||
NAPI_CALL_BASE(env, status = napi_set_property(env, object, itemName, itemValue), status);
|
||||
NAPI_CALL_BASE(env, status = napi_set_property(env, object, itemValue, itemName), status);
|
||||
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
static napi_value InitColorModeObject(napi_env env)
|
||||
{
|
||||
napi_value object;
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "COLOR_MODE_NOT_SET", Global::Resource::COLOR_MODE_NOT_SET));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "COLOR_MODE_DARK", Global::Resource::DARK));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "COLOR_MODE_LIGHT", Global::Resource::LIGHT));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static napi_value InitTimeFormatObject(napi_env env)
|
||||
{
|
||||
napi_value object;
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "HOUR_NOT_SET", Global::Resource::HOUR_NOT_SET));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "HOUR_12", Global::Resource::HOUR_12));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "HOUR_24", Global::Resource::HOUR_24));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static napi_value InitDirectionObject(napi_env env)
|
||||
{
|
||||
napi_value object;
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "DIRECTION_NOT_SET", Global::Resource::DIRECTION_NOT_SET));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "DIRECTION_VERTICAL", Global::Resource::DIRECTION_VERTICAL));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "DIRECTION_HORIZONTAL", Global::Resource::DIRECTION_HORIZONTAL));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static napi_value InitScreenDensityObject(napi_env env)
|
||||
{
|
||||
napi_value object;
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "SCREEN_DENSITY_NOT_SET", Global::Resource::SCREEN_DENSITY_NOT_SET));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "SCREEN_DENSITY_SDPI", Global::Resource::SCREEN_DENSITY_SDPI));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "SCREEN_DENSITY_MDPI", Global::Resource::SCREEN_DENSITY_MDPI));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "SCREEN_DENSITY_LDPI", Global::Resource::SCREEN_DENSITY_LDPI));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "SCREEN_DENSITY_XLDPI", Global::Resource::SCREEN_DENSITY_XLDPI));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "SCREEN_DENSITY_XXLDPI", Global::Resource::SCREEN_DENSITY_XXLDPI));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "SCREEN_DENSITY_XXXLDPI", Global::Resource::SCREEN_DENSITY_XXXLDPI));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/*
|
||||
* The module initialization.
|
||||
*/
|
||||
static napi_value ConfigurationConstantInit(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_value colorMode = InitColorModeObject(env);
|
||||
NAPI_ASSERT(env, colorMode != nullptr, "failed to create color mode object");
|
||||
|
||||
napi_value time24 = InitTimeFormatObject(env);
|
||||
NAPI_ASSERT(env, time24 != nullptr, "failed to create time format object");
|
||||
|
||||
napi_value direction = InitDirectionObject(env);
|
||||
NAPI_ASSERT(env, direction != nullptr, "failed to create direction object");
|
||||
|
||||
napi_value screenDensity = InitScreenDensityObject(env);
|
||||
NAPI_ASSERT(env, screenDensity != nullptr, "failed to create screen density object");
|
||||
|
||||
napi_property_descriptor exportObjs[] = {
|
||||
DECLARE_NAPI_PROPERTY("ColorMode", colorMode),
|
||||
DECLARE_NAPI_PROPERTY("Time24", time24),
|
||||
DECLARE_NAPI_PROPERTY("Direction", direction),
|
||||
DECLARE_NAPI_PROPERTY("ScreenDensity", screenDensity),
|
||||
};
|
||||
|
||||
napi_status status = napi_define_properties(env, exports, sizeof(exportObjs) / sizeof(exportObjs[0]), exportObjs);
|
||||
NAPI_ASSERT(env, status == napi_ok, "failed to define properties for exports");
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
/*
|
||||
* The module definition.
|
||||
*/
|
||||
static napi_module _module = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = ConfigurationConstantInit,
|
||||
#ifndef ENABLE_ERRCODE
|
||||
.nm_modname = "application.ConfigurationConstant",
|
||||
#endif
|
||||
.nm_priv = (static_cast<void *>(0)),
|
||||
.reserved = {0}
|
||||
};
|
||||
|
||||
/*
|
||||
* The module registration.
|
||||
*/
|
||||
extern "C" __attribute__((constructor)) void RegisterModule(void)
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
@@ -35,7 +35,7 @@ gen_js_obj("service_extension_ability_abc") {
|
||||
}
|
||||
|
||||
ohos_shared_library("serviceextensionability_napi") {
|
||||
sources = [ "service_extension_ability_module.cpp" ]
|
||||
sources = [ "service_extension_ability_napi_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":service_extension_ability_abc",
|
||||
|
||||
@@ -54,38 +54,4 @@ void NAPI_app_ability_ServiceExtensionAbility_GetABCCode(const char **buf, int *
|
||||
*buflen = _binary_service_extension_ability_abc_end - _binary_service_extension_ability_abc_start;
|
||||
}
|
||||
}
|
||||
#else
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "application/libserviceextensionability_napi.so/service_extension_ability.js",
|
||||
.nm_modname = "application.ServiceExtensionAbility",
|
||||
};
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_application_ServiceExtensionAbility_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_ServiceExtensionAbility_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_service_extension_ability_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_service_extension_ability_js_end - _binary_service_extension_ability_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_ServiceExtensionAbility_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_service_extension_ability_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_service_extension_ability_abc_end - _binary_service_extension_ability_abc_start;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_service_extension_ability_js_start[];
|
||||
extern const char _binary_service_extension_ability_js_end[];
|
||||
extern const char _binary_service_extension_ability_abc_start[];
|
||||
extern const char _binary_service_extension_ability_abc_end[]; //zhuhan
|
||||
|
||||
#ifndef ENABLE_ERRCODE
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "application/libserviceextensionability_napi.so/service_extension_ability.js",
|
||||
.nm_modname = "application.ServiceExtensionAbility",
|
||||
};
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_application_ServiceExtensionAbility_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_ServiceExtensionAbility_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_service_extension_ability_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_service_extension_ability_js_end - _binary_service_extension_ability_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_ServiceExtensionAbility_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_service_extension_ability_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_service_extension_ability_abc_end - _binary_service_extension_ability_abc_start;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user