• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 APPEVENT_WATCHER_IMPL_H
17 #define APPEVENT_WATCHER_IMPL_H
18 
19 #include <vector>
20 #include <functional>
21 
22 #include "appevent_packageholder_impl.h"
23 #include "app_event_watcher.h"
24 #include "cj_lambda.h"
25 #include "hiappevent_base.h"
26 #include "json/json.h"
27 #include "native/ffi_remote_data.h"
28 
29 namespace OHOS {
30 namespace CJSystemapi {
31 namespace HiAppEvent {
32 constexpr uint8_t TYPE_INT = 0;
33 constexpr uint8_t TYPE_FLOAT = 1;
34 constexpr uint8_t TYPE_STRING = 2;
35 constexpr uint8_t TYPE_BOOL = 3;
36 constexpr uint8_t TYPE_ARRINT = 4;
37 constexpr uint8_t TYPE_ARRFLOAT = 5;
38 constexpr uint8_t TYPE_ARRSTRING = 6;
39 constexpr uint8_t TYPE_ARRBOOL = 7;
40 constexpr uint8_t TYPE_INT64 = 8;
41 constexpr uint8_t TYPE_ARRINT64 = 9;
42 
43 struct OnTriggerContext {
44     ~OnTriggerContext();
45     int row = 0;
46     int size = 0;
47     std::function<void(int, int, int64_t)> onTrigger = nullptr;
48     AppEventPackageHolderImpl* holder = nullptr;
49 };
50 
51 struct OnReceiveContext {
52     ~OnReceiveContext();
53     std::function<void(char*, CArrRetAppEventGroup)> onReceive = nullptr;
54     std::string domain = "";
55     std::vector<std::shared_ptr<OHOS::HiviewDFX::AppEventPack>> events;
56 };
57 
58 struct WatcherContext {
59     ~WatcherContext();
60     OnTriggerContext* triggerContext = nullptr;
61     OnReceiveContext* receiveContext = nullptr;
62 };
63 
64 class AppEventWatcherImpl : public HiviewDFX::AppEventWatcher {
65 public:
66     AppEventWatcherImpl(
67         const std::string& name,
68         const std::vector<HiviewDFX::AppEventFilter>& filters,
69         HiviewDFX::TriggerCondition cond);
70     ~AppEventWatcherImpl() override;
71     void InitTrigger(void (*callbackRef)(int, int, int64_t));
72     void InitHolder(AppEventPackageHolderImpl* holder);
73     void InitReceiver(void (*callbackRef)(char*, CArrRetAppEventGroup));
74     void OnEvents(const std::vector<std::shared_ptr<OHOS::HiviewDFX::AppEventPack>>& events) override;
75     bool IsRealTimeEvent(std::shared_ptr<OHOS::HiviewDFX::AppEventPack> event) override;
76 protected:
77     void OnTrigger(const HiviewDFX::TriggerCondition& triggerCond) override;
78 private:
79     WatcherContext* context_;
80 };
81 } // HiAppEvent
82 } // CJSystemapi
83 } // OHOS
84 
85 #endif
86