• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "common.h"
21 #include "logging.h"
22 #include "plugin_module_api.h"
23 
24 #include <atomic>
25 #include <cstdio>
26 #include <mutex>
27 #include <thread>
28 #include <vector>
29 
30 class HisyseventPlugin {
31 public:
32     HisyseventPlugin();
33     ~HisyseventPlugin();
34     int Start(const uint8_t* configData, uint32_t configSize);
35     int Stop();
36     void Run(void);
37 
38     int SetWriter(WriterStruct* writer);
39 
40 private:
41     std::string GetFullCmd();
42     bool InitHisyseventCmd();
43 
44     bool ParseSyseventLineInfo(const char* data, size_t len, HisyseventInfo& dataProto);
45 
46     bool WriteResult(const HisyseventInfo& dataProto);
47 
48 private:
49     std::atomic<uint64_t> id_;
50     std::vector<std::string> fullCmd_;
51 
52     std::thread workThread_;
53     std::atomic<bool> running_ = true;
54 
55     std::unique_ptr<FILE, std::function<int (FILE*)>> fp_;
56 
57     HisyseventConfig protoConfig_;
58     std::vector<char> protoBuffer_;
59     WriterStruct* resultWriter_ = nullptr;
60 
61     volatile pid_t childPid_ = -1;
62     int pipeFds_[2] = {-1, -1};
63 };
64 #endif // !HISYSEVENT_PLUGIN_H
65