• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ONSCREEN_NAPI_H
17 #define ONSCREEN_NAPI_H
18 
19 #include <uv.h>
20 
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 
24 #include "on_screen_data.h"
25 #include "on_screen_manager.h"
26 #include "on_screen_napi_data.h"
27 
28 namespace OHOS {
29 namespace Msdp {
30 namespace DeviceStatus {
31 namespace OnScreen {
32 class OnScreenNapi {
33 public:
34     explicit OnScreenNapi(napi_env env, napi_value thisVar);
35     ~OnScreenNapi();
36 
37     static napi_value Init(napi_env env, napi_value exports);
38     static napi_value GetPageContentNapi(napi_env env, napi_callback_info info);
39     static napi_value SendControlEventNapi(napi_env env, napi_callback_info info);
40 
41 private:
42     static bool ConstructOnScreen(napi_env env, napi_value jsThis);
43     static bool GetContentOption(napi_env env, napi_value *args, size_t argc, ContentOption &option);
44     static bool GetControlEvent(napi_env env, napi_value *args, size_t argc, ControlEvent &event);
45     // utils
46     static bool SetInt32Property(napi_env env, napi_value targetObj, int32_t value, const char *propName);
47     static bool SetInt64Property(napi_env env, napi_value targetObj, int64_t value, const char *propName);
48     static bool SetStringProperty(napi_env env, napi_value targetObj, const std::string &value, const char *propName);
49     static bool ConstructParagraphObj(napi_env env, napi_value &retObj, const Paragraph &value);
50     static bool SetParagraphVecProperty(napi_env env, napi_value targetObj, const std::vector<Paragraph> paragraphs,
51         const char *propName);
52     static bool GetInt32FromJs(napi_env env, const napi_value &value, const std::string &field,
53         int32_t &result, bool isNecessary);
54     static bool GetInt64FromJs(napi_env env, const napi_value &value, const std::string &field,
55         int64_t &result, bool isNecessary);
56     static bool GetBoolFromJs(napi_env env, const napi_value &value, const std::string &field,
57         bool &result, bool isNecessary);
58     static bool GetParagraphSizeRange(napi_env env, const napi_value &value, const std::string &field,
59         ParagraphSizeRange &range, bool isNecessary);
60     static bool SetPropertyName(napi_env env, napi_value targetObj, const char *propName, napi_value propValue);
61     static bool ConstructPageContentObj(napi_env env, napi_value &pageContentObj,
62         const GetPageContentAsyncContext* ctx);
63     // GetPageContent
64     static bool GetPageContentExec(GetPageContentAsyncContext *asyncContext);
65     static void GetPageContentExecCB(napi_env env, void *data);
66     static void GetPageContentCompCB(napi_env env, napi_status status, void *data);
67     // SendControlEvent
68     static bool SendControlEventExec(SendControlEventAsyncContext *asyncContext);
69     static void SendControlEventExecCB(napi_env env, void *data);
70     static void SendControlEventCompCB(napi_env env, napi_status status, void *data);
71 
72     napi_env env_;
73 };
74 } // namespace OnScreen
75 } // namespace DeviceStatus
76 } // namespace Msdp
77 } // namespace OHOS
78 #endif // ONSCREEN_NAPI_H