~ubuntu-branches/debian/sid/gsmartcontrol/sid

« back to all changes in this revision

Viewing changes to src/applib/smartctl_parser.h

  • Committer: Package Import Robot
  • Author(s): Giuseppe Iuculano
  • Date: 2013-05-31 11:41:52 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130531114152-5ljhkuswwpt4kdwo
Tags: 0.8.7-1
* [314881d] Updated debian/watch
* [18ebada] Imported Upstream version 0.8.7
* [c2a1f1b] debian/rules: Provide build-arch and build-indep
* [d3036a4] Enabled Hardening Options
* [2edfb87] Refreshed patches and removed patches apllied upstream
* [ac3b953] Bump to standard versions 3.9.4
* [292c276] Remove quilt from depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**************************************************************************
2
2
 Copyright:
3
 
      (C) 2008 - 2011  Alexander Shaduri <ashaduri 'at' gmail.com>
 
3
      (C) 2008 - 2012  Alexander Shaduri <ashaduri 'at' gmail.com>
4
4
 License: See LICENSE_gsmartcontrol.txt
5
5
***************************************************************************/
 
6
/// \file
 
7
/// \author Alexander Shaduri
 
8
/// \ingroup applib
 
9
/// \weakgroup applib
 
10
/// @{
6
11
 
7
12
#ifndef SMARTCTL_PARSER_H
8
13
#define SMARTCTL_PARSER_H
14
19
 
15
20
 
16
21
 
 
22
/// Smartctl parser.
 
23
/// Note: ALL parse_* functions (except parse_full() and parse_version())
 
24
/// expect data in unix-newline format!
17
25
class SmartctlParser {
18
26
 
19
27
        public:
20
28
 
 
29
                /// Property list
21
30
                typedef std::vector<StorageProperty> prop_list_t;
22
31
 
23
 
                // Note: ALL parse_* functions (except parse_full() and parse_version())
24
 
                // expect data in unix-newline format!
25
 
 
26
 
 
27
 
                // Parse full "smartctl -a" output
 
32
 
 
33
                /// Parse full "smartctl -a" output
28
34
                bool parse_full(const std::string& s);
29
35
 
30
36
 
31
 
                // supply any output of smartctl here.
 
37
                /// Supply any output of smartctl here, the smartctl version will be retrieved.
32
38
                static bool parse_version(const std::string& s, std::string& version, std::string& version_full);
33
39
 
34
40
 
35
 
                // check that the version of smartctl output can be parsed with this parser.
 
41
                /// Check that the version of smartctl output can be parsed with this parser.
36
42
                static bool check_version(const std::string& version_str, const std::string& version_full_str);
37
43
 
38
44
 
39
 
                // convert e.g. "1,000,204,886,016 bytes" to 1.00 TiB [931.51 GB, 1000204886016 bytes]
 
45
                /// Convert e.g. "1,000,204,886,016 bytes" to 1.00 TiB [931.51 GB, 1000204886016 bytes]
40
46
                static std::string parse_byte_size(const std::string& str, uint64_t& bytes, bool extended);
41
47
 
42
48
 
43
49
                // You don't really need to call these functions, use the ones above.
44
50
 
45
51
 
46
 
                // Parse the section part (with "=== .... ===" header) - info or data sections.
 
52
                /// Parse the section part (with "=== .... ===" header) - info or data sections.
47
53
                bool parse_section(const std::string& header, const std::string& body);
48
54
 
49
55
 
50
 
                // Parse the info section (without "===" header)
 
56
                /// Parse the info section (without "===" header)
51
57
                bool parse_section_info(const std::string& body);
52
58
 
53
 
                // Parse a component (one line) of the info section
 
59
                /// Parse a component (one line) of the info section
54
60
                bool parse_section_info_property(StorageProperty& p);
55
61
 
56
62
 
57
 
                // Parse the Data section (without "===" header)
 
63
                /// Parse the Data section (without "===" header)
58
64
                bool parse_section_data(const std::string& body);
59
65
 
60
 
                // Parse subsections of Data section
 
66
                /// Parse subsections of Data section
61
67
                bool parse_section_data_subsection_health(const std::string& sub);
62
68
                bool parse_section_data_subsection_capabilities(const std::string& sub);
63
69
                bool parse_section_data_subsection_attributes(const std::string& sub);
65
71
                bool parse_section_data_subsection_selftest_log(const std::string& sub);
66
72
                bool parse_section_data_subsection_selective_selftest_log(const std::string& sub);
67
73
 
68
 
                // Check the capabilities for internal properties we can use.
 
74
                /// Check the capabilities for internal properties we can use.
69
75
                bool parse_section_data_internal_capabilities(StorageProperty& cap);
70
76
 
71
77
 
72
 
 
73
 
 
 
78
                /// Clear parsed data
74
79
                void clear()
75
80
                {
76
81
                        data_full_.clear();
82
87
                }
83
88
 
84
89
 
 
90
                /// Get "full" data, as passed to parse_full().
85
91
                std::string get_data_full() const
86
92
                {
87
93
                        return data_full_;
88
94
                }
 
95
 
89
96
/*
90
97
                std::string get_data_section_info() const
91
98
                {
97
104
                        return data_section_data_;
98
105
                }
99
106
*/
 
107
 
 
108
                /// Get parse error message. Call this only if parsing doesn't succeed,
 
109
                /// to get a friendly error message.
100
110
                std::string get_error_msg() const
101
111
                {
102
112
                        return "Cannot parse smartctl output: " + error_msg_;
103
113
                }
104
114
 
105
115
 
 
116
                /// Get parse result properties
106
117
                const prop_list_t& get_properties() const
107
118
                {
108
119
                        return properties_;
113
124
        private:
114
125
 
115
126
 
116
 
                // adds a property into property list, looks up and sets its description
 
127
                /// Add a property into property list, look up and set its description
117
128
                void add_property(StorageProperty p);
118
129
 
119
130
 
 
131
                /// Set "full" data ("smartctl -a" output)
120
132
                void set_data_full(const std::string& s)
121
133
                {
122
134
                        data_full_ = s;
123
135
                }
124
136
 
 
137
 
 
138
                /// Set "info" section data ("smartctl -i" output, or the first part of "smartctl -a" output)
125
139
                void set_data_section_info(const std::string& s)
126
140
                {
127
141
                        data_section_info_ = s;
128
142
                }
129
143
 
 
144
 
 
145
                /// Parse "data" section data (the second part of "smartctl -a" output).
130
146
                void set_data_section_data(const std::string& s)
131
147
                {
132
148
                        data_section_data_ = s;
133
149
                }
134
150
 
135
151
 
 
152
                /// Set error message
136
153
                void set_error_msg(const std::string& s)
137
154
                {
138
155
                        error_msg_ = s;
140
157
 
141
158
 
142
159
 
143
 
                prop_list_t properties_;
144
 
 
145
 
                // These are filled by the appropriate parse_* functions
146
 
                std::string data_full_;
147
 
                std::string data_section_info_;
148
 
                std::string data_section_data_;
149
 
 
150
 
                std::string error_msg_;  // on error this will be filled with displayable message
 
160
                prop_list_t properties_;  ///< Parsed data properties
 
161
 
 
162
                std::string data_full_;  ///< full data, filled by parse_full()
 
163
                std::string data_section_info_;  ///< "info" section data, filled by parse_section_info()
 
164
                std::string data_section_data_;  ///< "data" section data, filled by parse_section_data()
 
165
 
 
166
                std::string error_msg_;  ///< This will be filled with some displayable message on error
151
167
 
152
168
 
153
169
};
157
173
 
158
174
 
159
175
 
160
 
 
161
 
 
162
 
 
163
 
 
164
 
 
165
 
 
166
176
#endif
 
177
 
 
178
/// @}