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 41 struct OnTriggerContext { 42 ~OnTriggerContext(); 43 int row = 0; 44 int size = 0; 45 std::function<void(int, int, int64_t)> onTrigger = nullptr; 46 AppEventPackageHolderImpl* holder = nullptr; 47 }; 48 49 struct OnReceiveContext { 50 ~OnReceiveContext(); 51 std::function<void(char*, CArrRetAppEventGroup)> onReceive = nullptr; 52 std::string domain = ""; 53 std::vector<std::shared_ptr<OHOS::HiviewDFX::AppEventPack>> events; 54 }; 55 56 struct WatcherContext { 57 ~WatcherContext(); 58 OnTriggerContext* triggerContext = nullptr; 59 OnReceiveContext* receiveContext = nullptr; 60 }; 61 62 class AppEventWatcherImpl : public HiviewDFX::AppEventWatcher { 63 public: 64 AppEventWatcherImpl( 65 const std::string& name, 66 const std::vector<HiviewDFX::AppEventFilter>& filters, 67 HiviewDFX::TriggerCondition cond); 68 ~AppEventWatcherImpl() override; 69 void InitTrigger(void (*callbackRef)(int, int, int64_t)); 70 void InitHolder(AppEventPackageHolderImpl* holder); 71 void InitReceiver(void (*callbackRef)(char*, CArrRetAppEventGroup)); 72 void OnEvents(const std::vector<std::shared_ptr<OHOS::HiviewDFX::AppEventPack>>& events) override; 73 bool IsRealTimeEvent(std::shared_ptr<OHOS::HiviewDFX::AppEventPack> event) override; 74 protected: 75 void OnTrigger(const HiviewDFX::TriggerCondition& triggerCond) override; 76 private: 77 WatcherContext* context_; 78 }; 79 } // HiAppEvent 80 } // CJSystemapi 81 } // OHOS 82 83 #endif 84