xref: /aosp_15_r20/system/dmesgd/dmesg_parser.h (revision 325a5df984070639bfcfcc2d7b58a6181e21cf50)
1*325a5df9SAndroid Build Coastguard Worker /*
2*325a5df9SAndroid Build Coastguard Worker  * Copyright 2022, The Android Open Source Project
3*325a5df9SAndroid Build Coastguard Worker  *
4*325a5df9SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*325a5df9SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*325a5df9SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*325a5df9SAndroid Build Coastguard Worker  *
8*325a5df9SAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
9*325a5df9SAndroid Build Coastguard Worker  *
10*325a5df9SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*325a5df9SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*325a5df9SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*325a5df9SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*325a5df9SAndroid Build Coastguard Worker  * limitations under the License.
15*325a5df9SAndroid Build Coastguard Worker  */
16*325a5df9SAndroid Build Coastguard Worker 
17*325a5df9SAndroid Build Coastguard Worker #pragma once
18*325a5df9SAndroid Build Coastguard Worker 
19*325a5df9SAndroid Build Coastguard Worker #include <regex>
20*325a5df9SAndroid Build Coastguard Worker #include <string>
21*325a5df9SAndroid Build Coastguard Worker 
22*325a5df9SAndroid Build Coastguard Worker namespace dmesg_parser {
23*325a5df9SAndroid Build Coastguard Worker 
24*325a5df9SAndroid Build Coastguard Worker class DmesgParser {
25*325a5df9SAndroid Build Coastguard Worker   public:
26*325a5df9SAndroid Build Coastguard Worker     DmesgParser();
27*325a5df9SAndroid Build Coastguard Worker     void ProcessLine(const std::string& line);
28*325a5df9SAndroid Build Coastguard Worker     bool ReportReady() const;
29*325a5df9SAndroid Build Coastguard Worker     std::string ReportType() const;
30*325a5df9SAndroid Build Coastguard Worker     std::string ReportTitle() const;
31*325a5df9SAndroid Build Coastguard Worker     std::string FlushReport();
32*325a5df9SAndroid Build Coastguard Worker 
33*325a5df9SAndroid Build Coastguard Worker   private:
34*325a5df9SAndroid Build Coastguard Worker     std::string StripSensitiveData(const std::string& line) const;
35*325a5df9SAndroid Build Coastguard Worker 
36*325a5df9SAndroid Build Coastguard Worker     bool report_ready_;
37*325a5df9SAndroid Build Coastguard Worker     std::string last_report_;
38*325a5df9SAndroid Build Coastguard Worker     std::regex bug_pattern_, ignore_pattern_, addr64_pattern_;
39*325a5df9SAndroid Build Coastguard Worker     std::regex task_line_pattern_, task_delimiter_pattern_;
40*325a5df9SAndroid Build Coastguard Worker     std::string current_report_;
41*325a5df9SAndroid Build Coastguard Worker     std::string current_task_, current_tool_, current_title_;
42*325a5df9SAndroid Build Coastguard Worker };
43*325a5df9SAndroid Build Coastguard Worker 
44*325a5df9SAndroid Build Coastguard Worker }  // namespace dmesg_parser
45