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 #ifndef HIAPPEVENT_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_APP_EVENT_WATCHER_H 16 #define HIAPPEVENT_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_APP_EVENT_WATCHER_H 17 18 #include "app_event_watcher.h" 19 #include "napi/native_api.h" 20 #include "napi/native_node_api.h" 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 struct OnTriggerContext { 25 OnTriggerContext(); 26 ~OnTriggerContext(); 27 napi_env env; 28 napi_ref onTrigger; 29 napi_ref holder; 30 int row; 31 int size; 32 }; 33 34 class NapiAppEventWatcher : public AppEventWatcher { 35 public: 36 NapiAppEventWatcher(const std::string& name, const std::map<std::string, unsigned int>& filters, 37 TriggerCondition cond); 38 ~NapiAppEventWatcher(); 39 void OnTrigger(int row, int size) override; 40 void InitTrigger(const napi_env env, const napi_value trigger); 41 void InitHolder(const napi_env env, const napi_value holder); 42 43 private: 44 OnTriggerContext* context_; 45 }; 46 } // namespace HiviewDFX 47 } // namespace OHOS 48 #endif // HIAPPEVENT_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_APP_EVENT_WATCHER_H 49