From c8e6bbc864f5661d6523f632bde09de6012f2370 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Thu, 21 Nov 2024 17:43:59 +0800 Subject: [PATCH] modify Signed-off-by: chen0088 --- .../native_distributedhardwarefwk_js.h | 11 ++++++- .../src/native_distributedhardwarefwk_js.cpp | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/napi/include/native_distributedhardwarefwk_js.h b/interfaces/kits/napi/include/native_distributedhardwarefwk_js.h index 777bd3fa..6f500540 100644 --- a/interfaces/kits/napi/include/native_distributedhardwarefwk_js.h +++ b/interfaces/kits/napi/include/native_distributedhardwarefwk_js.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -22,11 +22,20 @@ #include "napi/native_node_api.h" #include "cJSON.h" +constexpr int32_t ALL = 0; +constexpr int32_t CAMERA = 1; +constexpr int32_t SCREEN = 8; +constexpr int32_t MODEM_MIC = 256; +constexpr int32_t MODEM_SPEAKER = 512; +constexpr int32_t MIC = 1024; +constexpr int32_t SPEAKER = 2048; + class DistributedHardwareManager { public: explicit DistributedHardwareManager(napi_env env, napi_value thisVar); ~DistributedHardwareManager(); static napi_value Init(napi_env env, napi_value exports); + static void InitDistributedHardwareType(napi_env env, napi_value exports); static napi_value PauseDistributedHardware(napi_env env, napi_callback_info info); static napi_value ResumeDistributedHardware(napi_env env, napi_callback_info info); static napi_value StopDistributedHardware(napi_env env, napi_callback_info info); diff --git a/interfaces/kits/napi/src/native_distributedhardwarefwk_js.cpp b/interfaces/kits/napi/src/native_distributedhardwarefwk_js.cpp index ab12ee53..dad90c49 100644 --- a/interfaces/kits/napi/src/native_distributedhardwarefwk_js.cpp +++ b/interfaces/kits/napi/src/native_distributedhardwarefwk_js.cpp @@ -291,6 +291,38 @@ napi_value DistributedHardwareManager::Init(napi_env env, napi_value exports) return exports; } +void DistributedHardwareManager::InitDistributedHardwareType(napi_env env, napi_value exports) +{ + char propertyName[] = "DistributedHardwareType"; + napi_value all = nullptr; + napi_value camera = nullptr; + napi_value screen = nullptr; + napi_value modemMic = nullptr; + napi_value modemSpk = nullptr; + napi_value mic = nullptr; + napi_value speaker = nullptr; + napi_create_int32(env, ALL, &all); + napi_create_int32(env, CAMERA, &camera); + napi_create_int32(env, SCREEN, &screen); + napi_create_int32(env, MODEM_MIC, &modemMic); + napi_create_int32(env, MODEM_SPEAKER, &modemSpk); + napi_create_int32(env, MIC, &mic); + napi_create_int32(env, SPEAKER, &speaker); + napi_property_descriptor desc[] = { + DECLARE_NAPI_STATIC_PROPERTY("ALL", all), + DECLARE_NAPI_STATIC_PROPERTY("CAMERA", camera), + DECLARE_NAPI_STATIC_PROPERTY("SCREEN", screen), + DECLARE_NAPI_STATIC_PROPERTY("MODEM_MIC", modemMic), + DECLARE_NAPI_STATIC_PROPERTY("MODEM_SPEAKER", modemSpk), + DECLARE_NAPI_STATIC_PROPERTY("MIC", mic), + DECLARE_NAPI_STATIC_PROPERTY("SPEAKER", speaker) + }; + napi_value obj = nullptr; + napi_create_object(env, &obj); + napi_define_properties(env, obj, sizeof(desc) / sizeof(desc[0]), desc); + napi_set_named_property(env, exports, propertyName, obj); +} + /* * Function registering all props and functions of ohos.distributedhardware */ @@ -298,6 +330,7 @@ static napi_value Export(napi_env env, napi_value exports) { DHLOGI("Export is called!"); DistributedHardwareManager::Init(env, exports); + DistributedHardwareManager::InitDistributedHardwareType(env, exports); return exports; }