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" |
| 12 | |
| 13 | |
| 14 | gboolean |
| 15 | get_threshold_state (SensorIntegerThreshold *sen, |
| 16 | GDBusMethodInvocation *invocation, |
| 17 | gpointer user_data) |
| 18 | { |
| 19 | guint state = sensor_integer_threshold_get_state(sen); |
| 20 | sensor_integer_threshold_complete_get_state(sen,invocation,state); |
| 21 | return TRUE; |
| 22 | } |
| 23 | |
| 24 | |
| 25 | gboolean |
| 26 | set_thresholds (SensorIntegerThreshold *sen, |
| 27 | GDBusMethodInvocation *invocation, |
| 28 | guint lc, |
| 29 | guint lw, |
| 30 | guint uw, |
| 31 | guint uc, |
| 32 | gpointer user_data) |
| 33 | { |
| 34 | sensor_integer_threshold_set_lower_critical(sen,lc); |
| 35 | sensor_integer_threshold_set_lower_warning(sen,lw); |
| 36 | sensor_integer_threshold_set_upper_warning(sen,uw); |
| 37 | sensor_integer_threshold_set_upper_critical(sen,uc); |
| 38 | sensor_integer_threshold_complete_set(sen,invocation); |
| 39 | sensor_integer_threshold_set_state(sen,NORMAL); |
| 40 | return TRUE; |
| 41 | } |
| 42 | |
| 43 | |
| 44 | void check_thresholds(SensorIntegerThreshold* sensor,guint value) |
| 45 | { |
| 46 | threshold_states current_state = sensor_integer_threshold_get_state(sensor); |
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 47 | //if (current_state != NOT_SET) |
| 48 | //{ |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 49 | threshold_states state = NORMAL; |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 50 | if (value < sensor_integer_threshold_get_lower_critical(sensor)) { |
| 51 | state = LOWER_CRITICAL; |
| 52 | } |
| 53 | else if(value < sensor_integer_threshold_get_lower_warning(sensor)) { |
| 54 | state = LOWER_WARNING; |
| 55 | } |
| 56 | else if(value > sensor_integer_threshold_get_upper_critical(sensor)) { |
| 57 | state = UPPER_CRITICAL; |
| 58 | } |
| 59 | else if(value > sensor_integer_threshold_get_upper_warning(sensor)) { |
| 60 | state = UPPER_WARNING; |
| 61 | } |
| 62 | // only emit signal if threshold state changes |
| 63 | if (state != sensor_integer_threshold_get_state(sensor)) |
| 64 | { |
| 65 | sensor_integer_threshold_set_state(sensor,state); |
| 66 | if (state == LOWER_CRITICAL || state == UPPER_CRITICAL) |
| 67 | { |
| 68 | sensor_integer_threshold_emit_critical(sensor); |
| 69 | g_print("Critical\n"); |
| 70 | } |
| 71 | else if (state == LOWER_WARNING || state == UPPER_WARNING) |
| 72 | { |
| 73 | sensor_integer_threshold_emit_warning(sensor); |
| 74 | g_print("Warning\n"); |
| 75 | } |
| 76 | } |
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 77 | //} |
Norman James | e759492 | 2015-08-27 14:25:24 -0500 | [diff] [blame] | 78 | } |
| 79 | |