blob: adf8f5e5e6698f037465bd6b29de9939289e8c7a [file] [log] [blame]
Norman Jamese7594922015-08-27 14:25:24 -05001#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 Jamese7594922015-08-27 14:25:24 -050011#include "sensor_threshold.h"
Norman James5d78b4d2015-09-05 13:34:34 -050012#include "openbmc.h"
Norman Jamese7594922015-08-27 14:25:24 -050013
14gboolean
Norman James5d78b4d2015-09-05 13:34:34 -050015get_threshold_state (SensorThreshold *sen,
Norman Jamese7594922015-08-27 14:25:24 -050016 GDBusMethodInvocation *invocation,
17 gpointer user_data)
18{
Norman James5d78b4d2015-09-05 13:34:34 -050019 guint state = sensor_threshold_get_state(sen);
20 sensor_threshold_complete_get_state(sen,invocation,state);
Norman Jamese7594922015-08-27 14:25:24 -050021 return TRUE;
22}
23
24
Norman Jamese7594922015-08-27 14:25:24 -050025
Norman James5d78b4d2015-09-05 13:34:34 -050026void check_thresholds(SensorThreshold* sensor,GVariant* value)
Norman Jamese7594922015-08-27 14:25:24 -050027{
Norman James5d78b4d2015-09-05 13:34:34 -050028 threshold_states current_state = sensor_threshold_get_state(sensor);
Norman James471ab592015-08-30 22:29:40 -050029 //if (current_state != NOT_SET)
30 //{
Norman Jamese7594922015-08-27 14:25:24 -050031 threshold_states state = NORMAL;
Norman James5d78b4d2015-09-05 13:34:34 -050032 if (VARIANT_COMPARE(value,sensor_threshold_get_lower_critical(sensor)) < 0) {
Norman Jamese7594922015-08-27 14:25:24 -050033 state = LOWER_CRITICAL;
34 }
Norman James5d78b4d2015-09-05 13:34:34 -050035 else if(VARIANT_COMPARE(value,sensor_threshold_get_lower_warning(sensor)) < 0) {
Norman Jamese7594922015-08-27 14:25:24 -050036 state = LOWER_WARNING;
37 }
Norman James5d78b4d2015-09-05 13:34:34 -050038 else if(VARIANT_COMPARE(value,sensor_threshold_get_upper_critical(sensor)) > 0) {
Norman Jamese7594922015-08-27 14:25:24 -050039 state = UPPER_CRITICAL;
40 }
Norman James5d78b4d2015-09-05 13:34:34 -050041 else if(VARIANT_COMPARE(value,sensor_threshold_get_upper_warning(sensor)) > 0) {
Norman Jamese7594922015-08-27 14:25:24 -050042 state = UPPER_WARNING;
43 }
44 // only emit signal if threshold state changes
Norman James5d78b4d2015-09-05 13:34:34 -050045 if (state != sensor_threshold_get_state(sensor))
Norman Jamese7594922015-08-27 14:25:24 -050046 {
Norman James5d78b4d2015-09-05 13:34:34 -050047 sensor_threshold_set_state(sensor,state);
Norman Jamese7594922015-08-27 14:25:24 -050048 if (state == LOWER_CRITICAL || state == UPPER_CRITICAL)
49 {
Norman James5d78b4d2015-09-05 13:34:34 -050050 sensor_threshold_emit_critical(sensor);
Norman Jamese7594922015-08-27 14:25:24 -050051 }
52 else if (state == LOWER_WARNING || state == UPPER_WARNING)
53 {
Norman James5d78b4d2015-09-05 13:34:34 -050054 sensor_threshold_emit_warning(sensor);
Norman James90baede2015-09-02 20:32:49 -050055 }
56 else if (state == NORMAL)
57 {
Norman James5d78b4d2015-09-05 13:34:34 -050058 sensor_threshold_emit_normal(sensor);
Norman Jamese7594922015-08-27 14:25:24 -050059 }
60 }
Norman James471ab592015-08-30 22:29:40 -050061 //}
Norman Jamese7594922015-08-27 14:25:24 -050062}
63