blob: dd53fa0699a6c28aa2004c0eeded8491a900dfc4 [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"
12
13
14gboolean
15get_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
25gboolean
26set_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);
Norman James90baede2015-09-02 20:32:49 -050039 //sensor_integer_threshold_set_state(sen,NORMAL);
Norman Jamese7594922015-08-27 14:25:24 -050040 return TRUE;
41}
42
43
44void check_thresholds(SensorIntegerThreshold* sensor,guint value)
45{
46 threshold_states current_state = sensor_integer_threshold_get_state(sensor);
Norman James471ab592015-08-30 22:29:40 -050047 //if (current_state != NOT_SET)
48 //{
Norman Jamese7594922015-08-27 14:25:24 -050049 threshold_states state = NORMAL;
Norman Jamese7594922015-08-27 14:25:24 -050050 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);
Norman Jamese7594922015-08-27 14:25:24 -050069 }
70 else if (state == LOWER_WARNING || state == UPPER_WARNING)
71 {
72 sensor_integer_threshold_emit_warning(sensor);
Norman James90baede2015-09-02 20:32:49 -050073 }
74 else if (state == NORMAL)
75 {
76 sensor_integer_threshold_emit_normal(sensor);
Norman Jamese7594922015-08-27 14:25:24 -050077 }
78 }
Norman James471ab592015-08-30 22:29:40 -050079 //}
Norman Jamese7594922015-08-27 14:25:24 -050080}
81