Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 1 | #include <stdint.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <unistd.h> |
| 7 | #include <argp.h> |
| 8 | #include <sys/stat.h> |
| 9 | #include <sys/mman.h> |
| 10 | |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 11 | #include "sensor_threshold.h" |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 12 | #include "openbmc.h" |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 13 | |
| 14 | gboolean |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 15 | get_threshold_state (SensorThreshold *sen, |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 16 | GDBusMethodInvocation *invocation, |
| 17 | gpointer user_data) |
| 18 | { |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 19 | guint state = sensor_threshold_get_state(sen); |
| 20 | sensor_threshold_complete_get_state(sen,invocation,state); |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 21 | return TRUE; |
| 22 | } |
| 23 | |
| 24 | |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 25 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 26 | void check_thresholds(SensorThreshold* sensor,GVariant* value) |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 27 | { |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 28 | threshold_states current_state = sensor_threshold_get_state(sensor); |
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 29 | //if (current_state != NOT_SET) |
| 30 | //{ |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 31 | threshold_states state = NORMAL; |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 32 | if (VARIANT_COMPARE(value,sensor_threshold_get_lower_critical(sensor)) < 0) { |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 33 | state = LOWER_CRITICAL; |
| 34 | } |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 35 | else if(VARIANT_COMPARE(value,sensor_threshold_get_lower_warning(sensor)) < 0) { |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 36 | state = LOWER_WARNING; |
| 37 | } |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 38 | else if(VARIANT_COMPARE(value,sensor_threshold_get_upper_critical(sensor)) > 0) { |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 39 | state = UPPER_CRITICAL; |
| 40 | } |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 41 | else if(VARIANT_COMPARE(value,sensor_threshold_get_upper_warning(sensor)) > 0) { |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 42 | state = UPPER_WARNING; |
| 43 | } |
| 44 | // only emit signal if threshold state changes |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 45 | if (state != sensor_threshold_get_state(sensor)) |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 46 | { |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 47 | sensor_threshold_set_state(sensor,state); |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 48 | if (state == LOWER_CRITICAL || state == UPPER_CRITICAL) |
| 49 | { |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 50 | sensor_threshold_emit_critical(sensor); |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 51 | } |
| 52 | else if (state == LOWER_WARNING || state == UPPER_WARNING) |
| 53 | { |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 54 | sensor_threshold_emit_warning(sensor); |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 55 | } |
| 56 | else if (state == NORMAL) |
| 57 | { |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 58 | sensor_threshold_emit_normal(sensor); |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 59 | } |
| 60 | } |
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 61 | //} |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 62 | } |
| 63 | |