summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2014-12-08 15:02:05 -0500
committerMike Blumenkrantz <zmike@osg.samsung.com>2014-12-08 15:22:19 -0500
commit0c6844707fe8612ff407c6b6c9a837bca43c9e18 (patch)
treee2c5807498f50c9900abc3ec289352531d2fa204
parent6a08788d59c020aea8e0f24dc072630d5ae61c18 (diff)
upower module now errors and kills itself off when unsupported new version detected
0.99.0 removed the OnLowBattery property and added the per-device WarningLevel property. this requires what will effectively be a full rewrite of the module to track all the power levels of all the attached batteries and set the ecore power level somehow based on a combination of their levels since I have no desire to spend any more hours working on and debugging this module which is based on a known-unstable api, I'm making it disable itself if it detects a version >= 0.99.0. hopefully someone will decide to maintain both this and eldbus in the future so that we can more accurately track upstream when they make changes to these things ref T1908 ref T1909
-rw-r--r--src/lib/ecore/Ecore_Common.h4
-rw-r--r--src/modules/ecore/system/upower/ecore_system_upower.c138
2 files changed, 125 insertions, 17 deletions
diff --git a/src/lib/ecore/Ecore_Common.h b/src/lib/ecore/Ecore_Common.h
index 42b2858..a368c0e 100644
--- a/src/lib/ecore/Ecore_Common.h
+++ b/src/lib/ecore/Ecore_Common.h
@@ -858,7 +858,9 @@ enum _Ecore_Power_State /* Power state */
858{ 858{
859 ECORE_POWER_STATE_MAINS, /**< The system is connected to a mains supply of power, thus there is no need to limit processing to save battery life at all. */ 859 ECORE_POWER_STATE_MAINS, /**< The system is connected to a mains supply of power, thus there is no need to limit processing to save battery life at all. */
860 ECORE_POWER_STATE_BATTERY, /**< The system is running off battery power, but is otherwise running normally. */ 860 ECORE_POWER_STATE_BATTERY, /**< The system is running off battery power, but is otherwise running normally. */
861 ECORE_POWER_STATE_LOW /**< The system is low on power (on battery) and the process should do its best to conserve power. For example it may reduce or suspend polling of network resources, turn off animations or reduce framerate etc. */ 861 ECORE_POWER_STATE_LOW, /**< The system is low on power (on battery) and the process should do its best to conserve power. For example it may reduce or suspend polling of network resources, turn off animations or reduce framerate etc. */
862 //ECORE_POWER_STATE_CRITICAL, /**< The system is very low on power (on battery) and the process should begin taking even more conservative action @since 1.13*/
863 //ECORE_POWER_STATE_EMERGENCY /**< The system is extremely low on power (on battery) and the process should prepare for suspend/hibernate/power loss @since 1.13 */
862}; 864};
863typedef enum _Ecore_Power_State Ecore_Power_State; 865typedef enum _Ecore_Power_State Ecore_Power_State;
864 866
diff --git a/src/modules/ecore/system/upower/ecore_system_upower.c b/src/modules/ecore/system/upower/ecore_system_upower.c
index 614c364..d09995b 100644
--- a/src/modules/ecore/system/upower/ecore_system_upower.c
+++ b/src/modules/ecore/system/upower/ecore_system_upower.c
@@ -33,17 +33,26 @@ static Eldbus_Proxy *_proxy = NULL;
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; 35static Eina_Bool _ecore_on_battery = EINA_FALSE;
36static Eina_Bool _ecore_low_battery = EINA_FALSE; 36static unsigned int _ecore_low_battery = 0;
37
38static int uversions[3] = {0}; //major, minor, micro
39static void _ecore_system_upower_shutdown(void);
37 40
38static void 41static void
39_battery_eval(void) 42_battery_eval(void)
40{ 43{
41 if (_ecore_low_battery) 44 if (uversions[0] >= 1) return;
42 ecore_power_state_set(ECORE_POWER_STATE_LOW); 45 if (uversions[1] >= 99)
43 else if (_ecore_on_battery) 46 ecore_power_state_set(_ecore_low_battery);
44 ecore_power_state_set(ECORE_POWER_STATE_BATTERY);
45 else 47 else
46 ecore_power_state_set(ECORE_POWER_STATE_MAINS); 48 {
49 if (_ecore_low_battery)
50 ecore_power_state_set(ECORE_POWER_STATE_LOW);
51 else if (_ecore_on_battery)
52 ecore_power_state_set(ECORE_POWER_STATE_BATTERY);
53 else
54 ecore_power_state_set(ECORE_POWER_STATE_MAINS);
55 }
47} 56}
48 57
49static void 58static void
@@ -63,10 +72,17 @@ _on_low_battery_from_variant(Eldbus_Message_Iter *variant)
63} 72}
64 73
65static void 74static void
75_on_low_battery_from_uint(unsigned int level)
76{
77 DBG("OnLowBattery=%hhu", level);
78 _ecore_low_battery = level;
79 _battery_eval();
80}
81
82static void
66_on_low_battery_get_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, 83_on_low_battery_get_cb(void *data EINA_UNUSED, const Eldbus_Message *msg,
67 Eldbus_Pending *pending EINA_UNUSED) 84 Eldbus_Pending *pending EINA_UNUSED)
68{ 85{
69 Eldbus_Message_Iter *variant;
70 const char *errname, *errmsg; 86 const char *errname, *errmsg;
71 87
72 if (eldbus_message_error_get(msg, &errname, &errmsg)) 88 if (eldbus_message_error_get(msg, &errname, &errmsg))
@@ -74,20 +90,49 @@ _on_low_battery_get_cb(void *data EINA_UNUSED, const Eldbus_Message *msg,
74 ERR("Message error %s - %s", errname, errmsg); 90 ERR("Message error %s - %s", errname, errmsg);
75 return; 91 return;
76 } 92 }
77 if (!eldbus_message_arguments_get(msg, "v", &variant)) 93
94 if (uversions[0] >= 1)
78 { 95 {
79 ERR("Error getting arguments."); 96 ERR("Unsupported new UPower version!");
80 return; 97 return;
81 } 98 }
82 99 if (uversions[1] >= 99)
83 _on_low_battery_from_variant(variant); 100 {
101 unsigned int level;
102
103 if (!eldbus_message_arguments_get(msg, "u", &level))
104 {
105 ERR("Error getting arguments.");
106 return;
107 }
108 _on_low_battery_from_uint(level);
109 }
110 else
111 {
112 Eldbus_Message_Iter *variant;
113
114 if (!eldbus_message_arguments_get(msg, "v", &variant))
115 {
116 ERR("Error getting arguments.");
117 return;
118 }
119 _on_low_battery_from_variant(variant);
120 }
84} 121}
85 122
86static void 123static void
87_on_low_battery_get(Eldbus_Proxy *proxy) 124_on_low_battery_get(Eldbus_Proxy *proxy)
88{ 125{
89 eldbus_proxy_property_get(proxy, "OnLowBattery", 126 /* version specific battery properties */
90 _on_low_battery_get_cb, NULL); 127 if (uversions[0] < 1)
128 {
129 if (uversions[1] >= 99)
130 {/* FIXME: this module needs a huge refactoring since WarningLevel property is per-device */}
131 else
132 eldbus_proxy_property_get(proxy, "OnLowBattery", _on_low_battery_get_cb, NULL);
133 }
134 else
135 CRI("SOMEBODY SHOULD BE MAINTAINING THIS MODULE!!!!!!!");
91} 136}
92 137
93static void 138static void
@@ -156,8 +201,31 @@ _props_changed(void *data, const Eldbus_Message *msg)
156 continue; 201 continue;
157 if (strcmp(key, "OnBattery") == 0) 202 if (strcmp(key, "OnBattery") == 0)
158 _on_battery_from_variant(var); 203 _on_battery_from_variant(var);
159 if (strcmp(key, "OnLowBattery") == 0) 204 if (uversions[0] >= 1)
160 _on_low_battery_from_variant(var); 205 {
206 ERR("Unsupported new UPower version!");
207 return;
208 }
209 if (uversions[1] >= 99)
210 {
211 /* FIXME: this will never be hit since it's on the wrong proxy */
212#if 0
213 if (strcmp(key, "WarningLevel") == 0)
214 {
215 unsigned int level;
216
217 if (!eldbus_message_iter_get_and_next(var, 'u', &level))
218 ERR("Error getting OnBattery.");
219 else
220 _on_low_battery_from_uint(level);
221 }
222#endif
223 }
224 else
225 {
226 if (strcmp(key, "OnLowBattery") == 0)
227 _on_low_battery_from_variant(var);
228 }
161 } 229 }
162 230
163 while (eldbus_message_iter_get_and_next(invalidated, 's', &prop)) 231 while (eldbus_message_iter_get_and_next(invalidated, 's', &prop))
@@ -169,6 +237,43 @@ _props_changed(void *data, const Eldbus_Message *msg)
169 } 237 }
170} 238}
171 239
240static void
241_version_get(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
242{
243 const char *errname, *errmsg, *v;
244 char vers[128], *e;
245 unsigned int i;
246 Eldbus_Message_Iter *variant;
247
248 /* FIXME: if either of these fail...do something? */
249 if (eldbus_message_error_get(msg, &errname, &errmsg))
250 {
251 ERR("Message error %s - %s", errname, errmsg);
252 return;
253 }
254 if ((!eldbus_message_arguments_get(msg, "v", &variant)) ||
255 (!eldbus_message_iter_get_and_next(variant, 's', &v)))
256 {
257 ERR("Error getting version.");
258 return;
259 }
260 e = strncpy(vers, v, sizeof(vers) - 1);
261 for (i = 0; e[0] && (i < 3); i++, e++)
262 {
263 errno = 0;
264 uversions[i] = strtol(e, &e, 10);
265 if (errno) break;
266 }
267 if ((uversions[0] >= 1) || (uversions[1] >= 99))
268 {
269 /* may as well kill the module since it'll do more harm than good */
270 ERR("Unsupported new UPower version!");
271 _ecore_system_upower_shutdown();
272 return;
273 }
274 _on_low_battery_get(data);
275}
276
172static void _upower_name_owner_cb(void *data, 277static void _upower_name_owner_cb(void *data,
173 const char *bus EINA_UNUSED, 278 const char *bus EINA_UNUSED,
174 const char *old_id, 279 const char *old_id,
@@ -180,7 +285,7 @@ static void _upower_name_owner_cb(void *data,
180 old_id, new_id); 285 old_id, new_id);
181 286
182 if ((new_id) && (new_id[0])) 287 if ((new_id) && (new_id[0]))
183 _on_low_battery_get(proxy); 288 eldbus_proxy_property_get(proxy, "DaemonVersion", _version_get, proxy);
184} 289}
185 290
186static void _ecore_system_upower_shutdown(void); 291static void _ecore_system_upower_shutdown(void);
@@ -274,6 +379,7 @@ _ecore_system_upower_shutdown(void)
274 } 379 }
275 380
276 eldbus_shutdown(); 381 eldbus_shutdown();
382 memset(&uversions, 0, sizeof(uversions));
277} 383}
278 384
279EINA_MODULE_INIT(_ecore_system_upower_init); 385EINA_MODULE_INIT(_ecore_system_upower_init);