1 /* 2 * Copyright (c) 2021 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 <memory> 20 #include <string> 21 #include <vector> 22 23 #include "event_json_parser.h" 24 #include "event_server.h" 25 #include "event_source.h" 26 #include "pipeline.h" 27 #include "plugin.h" 28 #include "platform_monitor.h" 29 #include "base/raw_data.h" 30 #include "sys_event_stat.h" 31 32 namespace OHOS { 33 namespace HiviewDFX { 34 class SysEventSource; 35 36 class SysEventParser { 37 public: SysEventParser(PipelineEventProducer * producer)38 explicit SysEventParser(PipelineEventProducer* producer): pipeProducer(producer) {}; ~SysEventParser()39 ~SysEventParser() {}; 40 std::shared_ptr<PipelineEvent> Parser(std::shared_ptr<EventRaw::RawData> rawData) const; 41 private: 42 PipelineEventProducer* pipeProducer; 43 }; 44 45 class SysEventReceiver : public EventReceiver { 46 public: SysEventReceiver(SysEventSource & source)47 explicit SysEventReceiver(SysEventSource& source): eventSource(source) {}; ~SysEventReceiver()48 ~SysEventReceiver() override {}; 49 void HandlerEvent(std::shared_ptr<EventRaw::RawData> rawData) override; 50 private: 51 SysEventSource& eventSource; 52 }; 53 54 class SysEventSource : public EventSource { 55 public: SysEventSource()56 SysEventSource() {}; ~SysEventSource()57 ~SysEventSource() {}; 58 void OnLoad() override; 59 void OnUnload() override; 60 void StartEventSource() override; 61 void Recycle(PipelineEvent *event) override; 62 void PauseDispatch(std::weak_ptr<Plugin> plugin) override; 63 bool CheckValidSysEvent(std::shared_ptr<Event> event); 64 bool PublishPipelineEvent(std::shared_ptr<PipelineEvent> event); 65 void Dump(int fd, const std::vector<std::string>& cmds) override; 66 67 private: 68 EventServer eventServer; 69 PlatformMonitor platformMonitor_; 70 std::unique_ptr<SysEventStat> sysEventStat_ = nullptr; 71 std::shared_ptr<EventJsonParser> sysEventParser_ = nullptr; 72 std::shared_ptr<SysEvent> Convert2SysEvent(std::shared_ptr<Event>& event); 73 }; 74 } // namespace HiviewDFX 75 } // namespace OHOS 76 #endif // SYS_EVENT_SOURCE_H