summaryrefslogtreecommitdiff
path: root/src/modules/ecore/system/upower/ecore_system_upower.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-08-10 23:23:06 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-08-10 23:23:06 +0900
commit393040a9fea35f41cdf5e5f70de15764795f160d (patch)
tree384d327cbbef7ca3d0744b1226181d5291c0f6ea /src/modules/ecore/system/upower/ecore_system_upower.c
parent1e9d4bf28f88b6eb4dd073ac63519f9ea58ba94e (diff)
adjust (as discussed) to have enums for memory and battery state.
Diffstat (limited to '')
-rw-r--r--src/modules/ecore/system/upower/ecore_system_upower.c77
1 files changed, 66 insertions, 11 deletions
diff --git a/src/modules/ecore/system/upower/ecore_system_upower.c b/src/modules/ecore/system/upower/ecore_system_upower.c
index d89c4b91e8..5a9d2dbde1 100644
--- a/src/modules/ecore/system/upower/ecore_system_upower.c
+++ b/src/modules/ecore/system/upower/ecore_system_upower.c
@@ -32,6 +32,20 @@ static Eldbus_Proxy *_proxy = NULL;
32#endif 32#endif
33#define DBG(...) EINA_LOG_DOM_DBG(_log_dom, __VA_ARGS__) 33#define DBG(...) EINA_LOG_DOM_DBG(_log_dom, __VA_ARGS__)
34 34
35static Eina_Bool _ecore_on_battery = EINA_FALSE;
36static Eina_Bool _ecore_low_battery = EINA_FALSE;
37
38static void
39_battery_eval(void)
40{
41 if (_ecore_low_battery)
42 ecore_power_state_set(ECORE_POWER_STATE_LOW);
43 else if (_ecore_on_battery)
44 ecore_power_state_set(ECORE_POWER_STATE_BATTERY);
45 else
46 ecore_power_state_set(ECORE_POWER_STATE_MAINS);
47}
48
35static void 49static void
36_on_low_battery_from_variant(Eldbus_Message_Iter *variant) 50_on_low_battery_from_variant(Eldbus_Message_Iter *variant)
37{ 51{
@@ -44,7 +58,8 @@ _on_low_battery_from_variant(Eldbus_Message_Iter *variant)
44 } 58 }
45 59
46 DBG("OnLowBattery=%hhu", val); 60 DBG("OnLowBattery=%hhu", val);
47 ecore_low_battery_set(val); 61 _ecore_low_battery = val;
62 _battery_eval();
48} 63}
49 64
50static void 65static void
@@ -76,6 +91,50 @@ _on_low_battery_get(Eldbus_Proxy *proxy)
76} 91}
77 92
78static void 93static void
94_on_battery_from_variant(Eldbus_Message_Iter *variant)
95{
96 Eina_Bool val;
97
98 if (!eldbus_message_iter_get_and_next(variant, 'b', &val))
99 {
100 ERR("Error getting OnBattery.");
101 return;
102 }
103
104 DBG("OnBattery=%hhu", val);
105 _ecore_on_battery = val;
106 _battery_eval();
107}
108
109static void
110_on_battery_get_cb(void *data EINA_UNUSED, const Eldbus_Message *msg,
111 Eldbus_Pending *pending EINA_UNUSED)
112{
113 Eldbus_Message_Iter *variant;
114 const char *errname, *errmsg;
115
116 if (eldbus_message_error_get(msg, &errname, &errmsg))
117 {
118 ERR("Message error %s - %s", errname, errmsg);
119 return;
120 }
121 if (!eldbus_message_arguments_get(msg, "v", &variant))
122 {
123 ERR("Error getting arguments.");
124 return;
125 }
126
127 _on_battery_from_variant(variant);
128}
129
130static void
131_on_battery_get(Eldbus_Proxy *proxy)
132{
133 eldbus_proxy_property_get(proxy, "OnBattery",
134 _on_battery_get_cb, NULL);
135}
136
137static void
79_props_changed(void *data, const Eldbus_Message *msg) 138_props_changed(void *data, const Eldbus_Message *msg)
80{ 139{
81 Eldbus_Proxy *proxy = data; 140 Eldbus_Proxy *proxy = data;
@@ -95,22 +154,18 @@ _props_changed(void *data, const Eldbus_Message *msg)
95 Eldbus_Message_Iter *var; 154 Eldbus_Message_Iter *var;
96 if (!eldbus_message_iter_arguments_get(entry, "sv", &key, &var)) 155 if (!eldbus_message_iter_arguments_get(entry, "sv", &key, &var))
97 continue; 156 continue;
98 printf("changed on low battery\n"); 157 if (strcmp(key, "OnBattery") == 0)
158 _on_battery_from_variant(var);
99 if (strcmp(key, "OnLowBattery") == 0) 159 if (strcmp(key, "OnLowBattery") == 0)
100 { 160 _on_low_battery_from_variant(var);
101 _on_low_battery_from_variant(var);
102 return;
103 }
104 } 161 }
105 162
106 while (eldbus_message_iter_get_and_next(invalidated, 's', &prop)) 163 while (eldbus_message_iter_get_and_next(invalidated, 's', &prop))
107 { 164 {
108 printf("invalidated on low battery\n"); 165 if (strcmp(prop, "OnBattery") == 0)
166 _on_battery_get(proxy);
109 if (strcmp(prop, "OnLowBattery") == 0) 167 if (strcmp(prop, "OnLowBattery") == 0)
110 { 168 _on_low_battery_get(proxy);
111 _on_low_battery_get(proxy);
112 return;
113 }
114 } 169 }
115} 170}
116 171