1 /* 2 * Copyright (c) 2021-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 #ifndef JS_REGISTER_MODULE_H 17 #define JS_REGISTER_MODULE_H 18 19 #include <cstdio> 20 #include <cstring> 21 #include <iostream> 22 #include <list> 23 #include <map> 24 25 #include "napi/native_api.h" 26 #include "napi/native_node_api.h" 27 #include "utils/log.h" 28 29 #include "define_multimodal.h" 30 #include "key_event.h" 31 #include "key_option.h" 32 33 #define SUCCESS_CODE 0 34 #define ERROR_CODE (-1) 35 #define UNREGISTERED_CODE (-2) 36 #define PRE_KEY_MAX_COUNT 4 37 38 enum JS_CALLBACK_EVENT { 39 JS_CALLBACK_EVENT_FAILED = -1, 40 JS_CALLBACK_EVENT_SUCCESS = 1, 41 JS_CALLBACK_EVENT_EXIST = 2, 42 JS_CALLBACK_EVENT_NOT_EXIST = 3, 43 }; 44 45 namespace OHOS { 46 namespace MMI { 47 struct KeyEventMonitorInfo { 48 napi_env env{ nullptr }; 49 napi_async_work asyncWork{ nullptr }; 50 std::string eventType; 51 std::string name; 52 napi_value handle{ nullptr }; 53 std::shared_ptr<KeyEvent> keyEvent{ nullptr }; 54 napi_ref callback[1]{ nullptr }; 55 int32_t subscribeId{ 0 }; 56 std::shared_ptr<KeyOption> keyOption{ nullptr }; 57 std::function<void()> delCallback; ~KeyEventMonitorInfoKeyEventMonitorInfo58 ~KeyEventMonitorInfo() { 59 if (delCallback) { 60 delCallback(); 61 } 62 } 63 }; 64 typedef std::map<std::string, std::list<KeyEventMonitorInfo *>> Callbacks; 65 } // namespace MMI 66 } // namespace OHOS 67 #endif // JS_REGISTER_MODULE_H