1 /* 2 * Copyright (c) 2022 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 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 #ifndef HISYSEVENT_PLUGIN_H 16 #define HISYSEVENT_PLUGIN_H 17 18 #include "hisysevent_plugin_config.pb.h" 19 #include "hisysevent_plugin_result.pb.h" 20 #include "logging.h" 21 #include "plugin_module_api.h" 22 23 #include <stdio.h> 24 #include <atomic> 25 #include <mutex> 26 #include <thread> 27 #include <vector> 28 29 class HisyseventPlugin { 30 public: 31 HisyseventPlugin(); 32 ~HisyseventPlugin(); 33 int Start(const uint8_t* configData, uint32_t configSize); 34 int Stop(); 35 void Run(void); 36 37 int SetWriter(WriterStruct* writer); 38 39 private: 40 bool InitHisyseventCmd(); 41 42 std::string GetCmdline(); 43 static FILE* CustomPopen(char* const command[], const char* type); 44 static int CustomPclose(FILE* fp); 45 46 bool ParseSyseventLineInfo(const char* data, size_t len, HisyseventInfo &dataProto); 47 48 private: 49 std::vector<char*> fullCmd_; 50 51 std::mutex mutex_; 52 std::thread workThread_; 53 std::atomic<bool> running_ = true; 54 55 std::unique_ptr<FILE, int (*)(FILE*)> fp_; 56 57 HisyseventConfig protoConfig_; 58 std::vector<char> protoBuffer_; 59 WriterStruct* resultWriter_ = nullptr; 60 }; 61 #endif // !HISYSEVENT_PLUGIN_H 62