1 /*
2  * Copyright (C) 2003-2015 FreeIPMI Core Team
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18 
19 #ifndef TOOL_SENSOR_COMMON_H
20 #define TOOL_SENSOR_COMMON_H
21 
22 #include <stdio.h>
23 #include <stdint.h>
24 
25 #include <freeipmi/freeipmi.h>
26 
27 #include "pstdout.h"
28 
29 #define UNRECOGNIZED_SENSOR_TYPE            "Unrecognized"
30 
31 #define SENSORS_HEADER_RECORD_ID_STR        "ID"
32 #define SENSORS_HEADER_NAME_STR             "Name"
33 #define SENSORS_HEADER_TYPE_STR             "Type"
34 #define SENSORS_HEADER_STATE_STR            "State"
35 #define SENSORS_HEADER_READING_STR          "Reading"
36 #define SENSORS_HEADER_UNITS_STR            "Units"
37 #define SENSORS_HEADER_EVENT_STR            "Event"
38 
39 /* achu:
40  *
41  * The stack on cygwin is smaller than on unixes, and the ability for
42  * me to get a bigger stack in cygwin is difficult.  The normal unix
43  * ways (i.e. ulimit -s unlimited) don't work.  Some posts online
44  * indicate it's b/c of the way windows works with stack limits.
45  *
46  * So we're just going to use smaller values to deal with the problem.
47  */
48 #ifdef __CYGWIN__
49 #define MAX_SENSOR_RECORD_IDS               128
50 #define MAX_SENSOR_TYPES                    16
51 #else /* !__CYGWIN__ */
52 #if 0
53 /* record id is 16 bits - 65536 */
54 #define MAX_SENSOR_RECORD_IDS               65536
55 #define MAX_SENSOR_TYPES                    256
56 #else  /* !0 */
57 /* achu: pick more reasonable limits than the theoretical maxes */
58 #define MAX_SENSOR_RECORD_IDS               4096
59 #define MAX_SENSOR_TYPES                    128
60 #endif  /* !0 */
61 #endif /* !__CYGWIN__ */
62 #define MAX_SENSOR_TYPES_STRING_LENGTH      256
63 
64 #define SENSOR_PARSE_ALL_STRING             "all"
65 #define SENSOR_PARSE_NONE_STRING            "none"
66 
67 struct sensor_column_width
68 {
69   int record_id;
70   int sensor_name;
71   int sensor_type;
72   int sensor_units;
73 };
74 
75 const char * get_sensor_type_output_string (unsigned int sensor_type);
76 const char * get_oem_sensor_type_output_string (uint8_t sensor_type, uint8_t event_reading_code, uint32_t manufacturer_id, uint16_t product_id);
77 
78 int parse_sensor_types (const char *special_string,
79                         char sensor_types[MAX_SENSOR_TYPES][MAX_SENSOR_TYPES_STRING_LENGTH+1],
80                         unsigned int *sensor_types_length,
81                         const char *arg);
82 
83 int list_sensor_types (void);
84 
85 /* 1 if all valid, 0 if not, -1 on error */
86 int valid_sensor_types (char sensor_types[][MAX_SENSOR_TYPES_STRING_LENGTH+1],
87                         unsigned int sensor_types_length);
88 
89 int get_sensor_units_output_string (pstdout_state_t pstate,
90                                     ipmi_sdr_ctx_t sdr_ctx,
91                                     char *sensor_units_buf,
92                                     unsigned int sensor_units_buflen,
93                                     unsigned int abbreviated_units_flag);
94 
95 int sensor_type_listed (pstdout_state_t pstate,
96                         uint8_t sensor_type,
97                         char sensor_types[][MAX_SENSOR_TYPES_STRING_LENGTH+1],
98                         unsigned int sensor_types_length);
99 
100 int sensor_type_listed_sdr (pstdout_state_t pstate,
101                             ipmi_sdr_ctx_t sdr_ctx,
102                             char sensor_types[][MAX_SENSOR_TYPES_STRING_LENGTH+1],
103                             unsigned int sensor_types_length);
104 
105 /* use normal names, set entity_sensor_names to 0 */
106 int calculate_column_widths (pstdout_state_t pstate,
107                              ipmi_sdr_ctx_t sdr_ctx,
108                              char sensor_types[][MAX_SENSOR_TYPES_STRING_LENGTH+1],
109                              unsigned int sensor_types_length,
110                              unsigned int record_ids[],
111                              unsigned int record_ids_length,
112                              unsigned int non_abbreviated_units,
113                              unsigned int shared_sensors,
114                              unsigned int count_event_only_records,
115                              unsigned int count_device_locator_records,
116                              unsigned int count_oem_records,
117                              int entity_sensor_names,
118                              struct sensor_column_width *column_width);
119 
120 int calculate_column_widths_ignored_sdr_cache (unsigned int non_abbreviated_units,
121                                                struct sensor_column_width *column_width);
122 
123 #endif /* TOOL_SENSOR_COMMON_H */
124