1 /*
2 * Copyright (C) 2022 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 #include <cstdio>
17 #include <cstring>
18 #include <pthread.h>
19 #include <unistd.h>
20
21 #include "hilog_wrapper.h"
22 #include "napi_accessibility_event_info.h"
23 #include "napi_accessibility_system_ability_client.h"
24 #include "napi/native_api.h"
25 #include "napi/native_node_api.h"
26
27 EXTERN_C_START
28 /*
29 * function for module exports
30 */
Init(napi_env env,napi_value exports)31 static napi_value Init(napi_env env, napi_value exports)
32 {
33 napi_property_descriptor desc[] = {
34 DECLARE_NAPI_FUNCTION("isOpenAccessibility", NAccessibilityClient::IsOpenAccessibility),
35 DECLARE_NAPI_FUNCTION("isOpenAccessibilitySync", NAccessibilityClient::IsOpenAccessibilitySync),
36 DECLARE_NAPI_FUNCTION("isOpenTouchGuide", NAccessibilityClient::IsOpenTouchExploration),
37 DECLARE_NAPI_FUNCTION("isOpenTouchGuideSync", NAccessibilityClient::IsOpenTouchExplorationSync),
38 DECLARE_NAPI_FUNCTION("getAbilityLists", NAccessibilityClient::GetAbilityList),
39 DECLARE_NAPI_FUNCTION("getAccessibilityExtensionList", NAccessibilityClient::GetAccessibilityExtensionList),
40 DECLARE_NAPI_FUNCTION("on", NAccessibilityClient::SubscribeState),
41 DECLARE_NAPI_FUNCTION("off", NAccessibilityClient::UnsubscribeState),
42 DECLARE_NAPI_FUNCTION("sendEvent", NAccessibilityClient::SendEvent),
43 DECLARE_NAPI_FUNCTION("sendAccessibilityEvent", NAccessibilityClient::SendAccessibilityEvent),
44 DECLARE_NAPI_FUNCTION("getCaptionsManager", NAccessibilityClient::GetCaptionsManager),
45 };
46
47 NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
48
49 auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance();
50 (void)instance.InitializeContext();
51 NAccessibilityClient::DefineJSCaptionsManager(env);
52 NAccessibilityClient::DefineJSCaptionsStyle(env);
53 NAccessibilityEventInfo::DefineJSAccessibilityEventInfo(env, exports);
54 NAccessibilityClient::accessibilityStateListeners_->SubscribeToFramework();
55 NAccessibilityClient::touchGuideStateListeners_->SubscribeToFramework();
56 NAccessibilityClient::captionListeners_->SubscribeToFramework();
57 HILOG_INFO("-----Init end------");
58 return exports;
59 }
60 EXTERN_C_END
61
62 /*
63 * Module define
64 */
65 static napi_module _module = {
66 .nm_version = 1,
67 .nm_flags = 0,
68 .nm_filename = nullptr,
69 .nm_register_func = Init,
70 .nm_modname = "accessibility",
71 .nm_priv = ((void*)0),
72 .reserved = {0},
73 };
74 /*
75 * Module register function
76 */
RegisterNapiAccessibilityModule(void)77 extern "C" __attribute__((constructor)) void RegisterNapiAccessibilityModule(void)
78 {
79 napi_module_register(&_module);
80 }
81