1 /* 2 * Copyright (c) 2023-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 #ifndef HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_PROCESSOR_PROXY_H 16 #define HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_PROCESSOR_PROXY_H 17 18 #include <string> 19 20 #include "app_event_observer.h" 21 #include "app_event_processor.h" 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 namespace HiAppEvent { 26 class AppEventProcessorProxy : public AppEventObserver, public std::enable_shared_from_this<AppEventProcessorProxy> { 27 public: AppEventProcessorProxy(const std::string & name,std::shared_ptr<AppEventProcessor> processor)28 AppEventProcessorProxy(const std::string& name, std::shared_ptr<AppEventProcessor> processor) 29 : AppEventObserver(name), processor_(processor), userIdVersion_(-1), userPropertyVersion_(-1) {} 30 ~AppEventProcessorProxy() = default; 31 32 void OnEvents(const std::vector<std::shared_ptr<AppEventPack>>& events) override; 33 bool VerifyEvent(std::shared_ptr<AppEventPack> event) override; 34 bool IsRealTimeEvent(std::shared_ptr<AppEventPack> event) override; 35 void OnTrigger(const TriggerCondition& triggerCond) override; 36 ReportConfig GetReportConfig(); 37 void SetReportConfig(const ReportConfig& reportConfig); 38 // used to identify the processor with the same config 39 int64_t GenerateHashCode(); 40 41 private: 42 void GetValidUserIds(std::vector<UserId>& userIds); 43 void GetValidUserProperties(std::vector<UserProperty>& userProperties); 44 void QueryEventsFromDb(std::vector<std::shared_ptr<AppEventPack>>& events); 45 46 private: 47 std::shared_ptr<AppEventProcessor> processor_; 48 int64_t userIdVersion_; 49 int64_t userPropertyVersion_; 50 std::vector<UserId> userIds_; 51 std::vector<UserProperty> userProperties_; 52 ReportConfig reportConfig_; 53 int64_t hashCode_ = 0; 54 std::mutex mutex_; 55 }; 56 } // namespace HiAppEvent 57 } // namespace HiviewDFX 58 } // namespace OHOS 59 #endif // HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_APP_EVENT_PROCESSOR_PROXY_H 60