• 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 ANI_APP_EVENT_WATCHER_H
17 #define ANI_APP_EVENT_WATCHER_H
18 
19 #include <ani.h>
20 
21 #include "app_event_watcher.h"
22 #include "event_handler.h"
23 #include "hiappevent_ani_error_code.h"
24 
25 namespace OHOS {
26 namespace HiviewDFX {
27 struct OnTriggerContext {
28     ~OnTriggerContext();
29     ani_vm* vm = nullptr;
30     ani_ref onTrigger {};
31     ani_ref holder {};
32 };
33 
34 struct OnReceiveContext {
35     ~OnReceiveContext();
36     ani_vm* vm = nullptr;
37     ani_ref onReceive {};
38 };
39 
40 class AniAppEventWatcher : public AppEventWatcher {
41 public:
42     AniAppEventWatcher(
43         const std::string& name,
44         const std::vector<AppEventFilter>& filters,
45         TriggerCondition cond);
46     ani_status AniSendEvent(const std::function<void()> cb, const std::string& name);
47     void InitTrigger(ani_env *env, ani_ref trigger);
48     void InitHolder(ani_env *env, ani_ref holder);
49     void InitReceiver(ani_env *env, ani_ref receiver);
50     bool IsRealTimeEvent(std::shared_ptr<AppEventPack> event) override;
51     void OnEvents(const std::vector<std::shared_ptr<AppEventPack>>& events) override;
52 
53 protected:
54     void OnTrigger(const TriggerCondition& triggerCond) override;
55 
56 private:
57     std::shared_ptr<OnTriggerContext> triggerContext_ = nullptr;
58     std::shared_ptr<OnReceiveContext> receiveContext_ = nullptr;
59     std::shared_ptr<OHOS::AppExecFwk::EventHandler> mainHandler_ = nullptr;
60 };
61 } // namespace HiviewDFX
62 } // namespace OHOS
63 #endif // ANI_APP_EVENT_WATCHER_H
64