summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Houston <smhouston88@gmail.com>2018-08-08 09:36:32 -0500
committerStephen Houston <smhouston88@gmail.com>2018-08-08 09:36:32 -0500
commit68efc4f96baa7b6972c848f365615670fecdc37d (patch)
treefe830ad805bd6f601ac4ada90021ed6436766344
parente886e026a4aaab568c5ea10b4bd7478a05868b1c (diff)
Batman: Update to latest upower dbus api.
-rw-r--r--batman/src/batman_upower.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/batman/src/batman_upower.c b/batman/src/batman_upower.c
index 82b58a4..628c283 100644
--- a/batman/src/batman_upower.c
+++ b/batman/src/batman_upower.c
@@ -3,6 +3,8 @@
3#define BUS "org.freedesktop.UPower" 3#define BUS "org.freedesktop.UPower"
4#define PATH "/org/freedesktop/UPower" 4#define PATH "/org/freedesktop/UPower"
5#define IFACE "org.freedesktop.UPower" 5#define IFACE "org.freedesktop.UPower"
6#define IFACE_DEVICE "org.freedesktop.UPower.Device"
7#define IFACE_PROPERTIES "org.freedesktop.DBus.Properties"
6 8
7extern Eina_List *batman_device_batteries; 9extern Eina_List *batman_device_batteries;
8extern Eina_List *batman_device_ac_adapters; 10extern Eina_List *batman_device_ac_adapters;
@@ -10,6 +12,8 @@ extern double batman_init_time;
10 12
11static Eldbus_Connection *conn; 13static Eldbus_Connection *conn;
12static Eldbus_Proxy *upower_proxy; 14static Eldbus_Proxy *upower_proxy;
15static Eldbus_Proxy *upower_proxy_bat;
16static Eldbus_Proxy *upower_proxy_ac;
13 17
14typedef struct _Upower_Data Upower_Data; 18typedef struct _Upower_Data Upower_Data;
15struct _Upower_Data 19struct _Upower_Data
@@ -90,7 +94,7 @@ _process_ac(Eldbus_Proxy *proxy, Instance *inst)
90 ac->proxy = proxy; 94 ac->proxy = proxy;
91 ac->udi = eina_stringshare_add(eldbus_object_path_get(eldbus_proxy_object_get(proxy))); 95 ac->udi = eina_stringshare_add(eldbus_object_path_get(eldbus_proxy_object_get(proxy)));
92 eldbus_proxy_property_get_all(proxy, _ac_get_all_cb, ac); 96 eldbus_proxy_property_get_all(proxy, _ac_get_all_cb, ac);
93 eldbus_proxy_signal_handler_add(proxy, "Changed", _ac_changed_cb, ac); 97 eldbus_proxy_signal_handler_add(upower_proxy_ac, "PropertiesChanged", _ac_changed_cb, ac);
94 batman_device_ac_adapters = eina_list_append(batman_device_ac_adapters, ac); 98 batman_device_ac_adapters = eina_list_append(batman_device_ac_adapters, ac);
95 return; 99 return;
96 100
@@ -220,7 +224,7 @@ _process_battery(Eldbus_Proxy *proxy, Instance *inst)
220 bat->proxy = proxy; 224 bat->proxy = proxy;
221 bat->udi = eina_stringshare_add(eldbus_object_path_get(eldbus_proxy_object_get(proxy))); 225 bat->udi = eina_stringshare_add(eldbus_object_path_get(eldbus_proxy_object_get(proxy)));
222 eldbus_proxy_property_get_all(proxy, _bat_get_all_cb, bat); 226 eldbus_proxy_property_get_all(proxy, _bat_get_all_cb, bat);
223 eldbus_proxy_signal_handler_add(proxy, "Changed", _bat_changed_cb, bat); 227 eldbus_proxy_signal_handler_add(upower_proxy_bat, "PropertiesChanged", _bat_changed_cb, bat);
224 batman_device_batteries = eina_list_append(batman_device_batteries, bat); 228 batman_device_batteries = eina_list_append(batman_device_batteries, bat);
225 _batman_device_update(bat->inst); 229 _batman_device_update(bat->inst);
226} 230}
@@ -233,14 +237,25 @@ _device_type_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending E
233 Eldbus_Object *obj; 237 Eldbus_Object *obj;
234 unsigned int type; 238 unsigned int type;
235 239
240 const char *path = eldbus_pending_path_get(pending);
236 if (!eldbus_message_arguments_get(msg, "v", &variant)) 241 if (!eldbus_message_arguments_get(msg, "v", &variant))
237 goto error; 242 goto error;
238 243
239 eldbus_message_iter_arguments_get(variant, "u", &type); 244 eldbus_message_iter_arguments_get(variant, "u", &type);
240 if (type == 1) 245 if (type == 1)
241 _process_ac(ud->proxy, ud->inst); 246 {
247 obj = eldbus_object_get(conn, BUS, path);
248 EINA_SAFETY_ON_FALSE_RETURN(obj);
249 upower_proxy_ac = eldbus_proxy_get(obj, IFACE_PROPERTIES);
250 _process_ac(ud->proxy, ud->inst);
251 }
242 else if (type == 2) 252 else if (type == 2)
243 _process_battery(ud->proxy, ud->inst); 253 {
254 obj = eldbus_object_get(conn, BUS, path);
255 EINA_SAFETY_ON_FALSE_RETURN(obj);
256 upower_proxy_bat = eldbus_proxy_get(obj, IFACE_PROPERTIES);
257 _process_battery(ud->proxy, ud->inst);
258 }
244 else 259 else
245 goto error; 260 goto error;
246 261
@@ -265,7 +280,7 @@ _process_enumerate_path(const char *path, Instance *inst)
265 280
266 obj = eldbus_object_get(conn, BUS, path); 281 obj = eldbus_object_get(conn, BUS, path);
267 EINA_SAFETY_ON_FALSE_RETURN(obj); 282 EINA_SAFETY_ON_FALSE_RETURN(obj);
268 proxy = eldbus_proxy_get(obj, "org.freedesktop.UPower.Device"); 283 proxy = eldbus_proxy_get(obj, IFACE_DEVICE);
269 ud = calloc(1, sizeof(Upower_Data)); 284 ud = calloc(1, sizeof(Upower_Data));
270 if (!ud) 285 if (!ud)
271 { 286 {
@@ -365,9 +380,10 @@ _batman_upower_start(Instance *inst)
365 upower_proxy = eldbus_proxy_get(obj, IFACE); 380 upower_proxy = eldbus_proxy_get(obj, IFACE);
366 EINA_SAFETY_ON_NULL_GOTO(upower_proxy, proxy_error); 381 EINA_SAFETY_ON_NULL_GOTO(upower_proxy, proxy_error);
367 382
368 eldbus_proxy_call(upower_proxy, "EnumerateDevices", _enumerate_cb, inst, -1, "");
369 eldbus_proxy_signal_handler_add(upower_proxy, "DeviceAdded", _device_added_cb, inst); 383 eldbus_proxy_signal_handler_add(upower_proxy, "DeviceAdded", _device_added_cb, inst);
370 eldbus_proxy_signal_handler_add(upower_proxy, "DeviceRemoved", _device_removed_cb, inst); 384 eldbus_proxy_signal_handler_add(upower_proxy, "DeviceRemoved", _device_removed_cb, inst);
385 eldbus_proxy_call(upower_proxy, "EnumerateDevices", _enumerate_cb, inst, -1, "");
386
371 return 1; 387 return 1;
372 388
373proxy_error: 389proxy_error:
@@ -400,6 +416,16 @@ _batman_upower_stop(void)
400 upower_proxy = NULL; 416 upower_proxy = NULL;
401 eldbus_object_unref(obj); 417 eldbus_object_unref(obj);
402 obj = NULL; 418 obj = NULL;
419 obj = eldbus_proxy_object_get(upower_proxy_ac);
420 eldbus_proxy_unref(upower_proxy_ac);
421 upower_proxy_ac = NULL;
422 eldbus_object_unref(obj);
423 obj = NULL;
424 obj = eldbus_proxy_object_get(upower_proxy_bat);
425 eldbus_proxy_unref(upower_proxy_bat);
426 upower_proxy_bat = NULL;
427 eldbus_object_unref(obj);
428 obj = NULL;
403 eldbus_connection_unref(conn); 429 eldbus_connection_unref(conn);
404 conn = NULL; 430 conn = NULL;
405} 431}