1 /* 2 * Copyright (c) 2023 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 OHOS_HIVIEWDFX_DATA_PUBLISHER_H 17 #define OHOS_HIVIEWDFX_DATA_PUBLISHER_H 18 19 #include <map> 20 #include <set> 21 #include <string> 22 #include <vector> 23 24 #include "data_share_dao.h" 25 #include "event_loop.h" 26 #include "event_query_wrapper_builder.h" 27 #include "sys_event.h" 28 #include "sys_event_query.h" 29 #include "sys_event_query_wrapper.h" 30 31 namespace OHOS { 32 namespace HiviewDFX { 33 34 class BaseEventQueryWrapper; 35 36 class DataPublisher { 37 public: 38 DataPublisher(); ~DataPublisher()39 ~DataPublisher() {}; 40 41 public: 42 int32_t AddSubscriber(int32_t uid, const std::vector<std::string> &events); 43 int32_t RemoveSubscriber(int32_t uid); 44 void OnSysEvent(std::shared_ptr<OHOS::HiviewDFX::SysEvent> &event); 45 void AddExportTask(std::shared_ptr<BaseEventQueryWrapper> queryWrapper, int64_t timestamp, int32_t uid); 46 int64_t GetTimeStampByUid(int32_t uid); 47 void SetWorkLoop(std::shared_ptr<EventLoop> looper); 48 49 private: 50 void InitSubscriber(); 51 bool CreateHiviewTempDir(); 52 void HandleAppUninstallEvent(std::shared_ptr<OHOS::HiviewDFX::SysEvent> &event); 53 void HandleSubscribeTask(std::shared_ptr<OHOS::HiviewDFX::SysEvent> &event, 54 std::string srcPath, std::string timeStr); 55 std::shared_ptr<DataShareDao> GetDataShareDao(); 56 57 private: 58 std::map<std::string, std::set<int>> eventRelationMap_; 59 std::map<int32_t, int64_t> uidTimeStampMap_; 60 std::shared_ptr<EventLoop> looper_; 61 }; 62 } // namespace HiviewDFX 63 } // namespace OHOS 64 65 #endif // OHOS_HIVIEWDFX_DATA_PUBLISHER_H