1 /* 2 * Copyright (c) 2021-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 SYS_EVENT_SOURCE_H 17 #define SYS_EVENT_SOURCE_H 18 19 #include <atomic> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "event_json_parser.h" 25 #include "event_server.h" 26 #include "event_source.h" 27 #include "i_controller.h" 28 #include "pipeline.h" 29 #include "platform_monitor.h" 30 #include "base/raw_data.h" 31 #include "sys_event_service_adapter.h" 32 #include "sys_event_stat.h" 33 34 namespace OHOS { 35 namespace HiviewDFX { 36 class SysEventSource; 37 38 class SysEventReceiver : public EventReceiver { 39 public: SysEventReceiver(SysEventSource & source)40 explicit SysEventReceiver(SysEventSource& source): eventSource(source) {}; ~SysEventReceiver()41 ~SysEventReceiver() override {}; 42 void HandlerEvent(std::shared_ptr<EventRaw::RawData> rawData) override; 43 private: 44 SysEventSource& eventSource; 45 }; 46 47 class SysEventSource : public EventSource, public SysEventServiceBase { 48 public: SysEventSource()49 SysEventSource() {}; ~SysEventSource()50 ~SysEventSource() {}; 51 void OnLoad() override; 52 void OnUnload() override; 53 void StartEventSource() override; 54 void Recycle(PipelineEvent *event) override; 55 void PauseDispatch(std::weak_ptr<Plugin> plugin) override; 56 bool CheckEvent(std::shared_ptr<Event> event); 57 bool PublishPipelineEvent(std::shared_ptr<PipelineEvent> event); 58 void Dump(int fd, const std::vector<std::string>& cmds) override; 59 void OnConfigUpdate(const std::string& localCfgPath, const std::string& cloudCfgPath) override; 60 void UpdateTestType(const std::string& testType); 61 62 private: 63 void InitController(); 64 bool IsValidSysEvent(const std::shared_ptr<SysEvent> event); 65 std::shared_ptr<SysEvent> Convert2SysEvent(std::shared_ptr<Event>& event); 66 void DecorateSysEvent(const std::shared_ptr<SysEvent> event, const BaseInfo& info, uint64_t id); 67 bool IsDuplicateEvent(const uint64_t eventId); 68 69 private: 70 EventServer eventServer_; 71 PlatformMonitor platformMonitor_; 72 std::unique_ptr<SysEventStat> sysEventStat_ = nullptr; 73 std::shared_ptr<EventJsonParser> sysEventParser_ = nullptr; 74 std::shared_ptr<IController> controller_; 75 std::atomic<bool> isConfigUpdated_ { false }; 76 std::string testType_; 77 std::list<uint64_t> eventIdList_; 78 }; 79 } // namespace HiviewDFX 80 } // namespace OHOS 81 #endif // SYS_EVENT_SOURCE_H