split battery module device backend into separate files to make it more manageable...
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 17 May 2010 07:17:59 +0000 (07:17 +0000)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 17 May 2010 07:17:59 +0000 (07:17 +0000)
still no functionality change

SVN revision: 48940

configure.ac
src/modules/battery/Makefile.am
src/modules/battery/e_mod_dbus.c [new file with mode: 0644]
src/modules/battery/e_mod_main.c
src/modules/battery/e_mod_main.h
src/modules/battery/e_mod_udev.c [new file with mode: 0644]

index dc0eb6d..5e33386 100644 (file)
@@ -246,14 +246,17 @@ AC_ARG_ENABLE([device-udev],
    AC_CACHE_VAL([e_cv_want_device_udev], [e_cv_want_device_udev=no]))
 
 if test "x$e_cv_want_device_udev" = "xyes";then
-      device_backend=eeze_udev
-      AC_DEFINE_UNQUOTED([HAVE_EEZE_UDEV],[1],[enable udev support])
+  device_backend=eeze_udev
+  AC_DEFINE_UNQUOTED([HAVE_EEZE_UDEV],[1],[enable udev support])
 else
-      device_backend=ehal
+  device_backend=ehal
 fi
-
 AC_MSG_RESULT($device_backend)
 
+#will uncomment once this works
+#AM_CONDITIONAL([HAVE_EEZE_UDEV], [test "x${device_backend}" = "xeeze_udev"])
+AM_CONDITIONAL([HAVE_EEZE_UDEV], [test "x${device_backend}" = "x"])
+
 # doxygen program for documentation building
 
 EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"])
index a3a9f18..fbe780b 100644 (file)
@@ -1,6 +1,12 @@
 MAINTAINERCLEANFILES = Makefile.in
 MODULE = battery
 
+if HAVE_EEZE_UDEV
+  DEVICE_FILE = e_mod_udev.c
+else
+  DEVICE_FILE = e_mod_dbus.c
+endif
+
 # data files for the module
 filesdir = $(libdir)/enlightenment/modules/$(MODULE)
 files_DATA = \
@@ -21,7 +27,9 @@ pkgdir                 = $(libdir)/enlightenment/modules/$(MODULE)/$(MODULE_ARCH
 pkg_LTLIBRARIES        = module.la
 module_la_SOURCES      = e_mod_main.c \
                          e_mod_main.h \
-                        e_mod_config.c
+                        e_mod_config.c \
+                        $(DEVICE_FILE)
+
 module_la_LIBADD       = @e_libs@ @cf_libs@ @dlopen_libs@
 module_la_LDFLAGS      = -module -avoid-version
 module_la_DEPENDENCIES = $(top_builddir)/config.h
diff --git a/src/modules/battery/e_mod_dbus.c b/src/modules/battery/e_mod_dbus.c
new file mode 100644 (file)
index 0000000..167525a
--- /dev/null
@@ -0,0 +1,391 @@
+#include "e.h"
+#include "e_mod_main.h"
+
+void
+_battery_dbus_shutdown(void)
+{
+   E_DBus_Connection *conn;
+   Ac_Adapter *ac;
+   Battery *bat;
+   
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   if (battery_config->dbus.have)
+     {
+        dbus_pending_call_cancel(battery_config->dbus.have);
+        battery_config->dbus.have = NULL;
+     }
+   if (battery_config->dbus.dev_add)
+     {
+        e_dbus_signal_handler_del(conn, battery_config->dbus.dev_add);
+        battery_config->dbus.dev_add = NULL;
+     }
+   if (battery_config->dbus.dev_del)
+     {
+        e_dbus_signal_handler_del(conn, battery_config->dbus.dev_del);
+        battery_config->dbus.dev_del = NULL;
+     }
+   EINA_LIST_FREE(device_ac_adapters, ac)
+     {
+        e_dbus_signal_handler_del(conn, ac->prop_change);
+        eina_stringshare_del(ac->udi);
+       eina_stringshare_del(ac->product);
+        free(ac);
+     }
+   EINA_LIST_FREE(device_batteries, bat)
+     {
+        e_dbus_signal_handler_del(conn, bat->prop_change);
+        eina_stringshare_del(bat->udi);
+       eina_stringshare_del(bat->technology);
+       eina_stringshare_del(bat->type);
+       eina_stringshare_del(bat->charge_units);
+       eina_stringshare_del(bat->model);
+       eina_stringshare_del(bat->vendor);
+        free(bat);
+     }
+}
+
+void
+_battery_dbus_battery_props(void *data, void *reply_data, DBusError *error __UNUSED__)
+{
+   E_Hal_Properties *ret = reply_data;
+   Battery *bat = data;
+   int err = 0;
+   const char *str;
+   uint64_t tmp;
+
+   if (dbus_error_is_set(error))
+     {
+        dbus_error_free(error);
+        return;
+     }
+   if (!ret) return;
+
+#undef GET_BOOL
+#undef GET_INT
+#undef GET_STR
+#define GET_BOOL(val, s) bat->val = e_hal_property_bool_get(ret, s, &err)
+#define GET_INT(val, s) bat->val = e_hal_property_int_get(ret, s, &err)
+#define GET_STR(val, s) \
+   if (bat->val) eina_stringshare_del(bat->val); \
+   bat->val = NULL; \
+   str = e_hal_property_string_get(ret, s, &err); \
+   if (str) \
+     { \
+        bat->val = eina_stringshare_add(str); \
+     }
+   
+   GET_BOOL(present, "battery.present");
+   GET_STR(technology, "battery.reporting.technology");
+   GET_STR(model, "battery.model");
+   GET_STR(vendor, "battery.vendor");
+   GET_STR(type, "battery.type");
+   GET_STR(charge_units, "battery.reporting.unit");
+   GET_INT(percent, "battery.charge_level.percentage");
+   GET_BOOL(can_charge, "battery.is_rechargeable");
+   GET_INT(current_charge, "battery.charge_level.current");
+   GET_INT(charge_rate, "battery.charge_level.rate");
+   GET_INT(design_charge, "battery.charge_level.design");
+   GET_INT(last_full_charge, "battery.charge_level.last_full");
+   GET_INT(time_left, "battery.remaining_time");
+   GET_INT(time_full, "battery.remaining_time");
+   /* conform to upower */
+   if (e_hal_property_bool_get(ret, "battery.rechargeable.is_charging", &err))
+     bat->state = 1;
+   else
+     bat->state = 2;
+   bat->got_prop = 1;
+   _battery_device_update();
+}
+
+void
+_battery_dbus_ac_adapter_props(void *data, void *reply_data, DBusError *error __UNUSED__)
+{
+   E_Hal_Properties *ret = reply_data;
+   Ac_Adapter *ac = data;
+   int err = 0;
+   const char *str;
+
+   if (dbus_error_is_set(error))
+     {
+        dbus_error_free(error);
+        return;
+     }
+   if (!ret) return;
+   
+#undef GET_BOOL
+#undef GET_STR
+#define GET_BOOL(val, s) ac->val = e_hal_property_bool_get(ret, s, &err)
+#define GET_STR(val, s) \
+   if (ac->val) eina_stringshare_del(ac->val); \
+   ac->val = NULL; \
+   str = e_hal_property_string_get(ret, s, &err); \
+   if (str) \
+     { \
+        ac->val = eina_stringshare_add(str); \
+     }
+   
+   GET_BOOL(present, "ac_adapter.present");
+   GET_STR(product, "info.product");
+   _battery_device_update();
+}
+
+void
+_battery_dbus_battery_property_changed(void *data, DBusMessage *msg __UNUSED__)
+{
+   E_DBus_Connection *conn;
+   
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   // FIXME: e_dbus doesnt allow us to track this pending call
+   e_hal_device_get_all_properties(conn, ((Battery *)data)->udi,
+                                   _battery_dbus_battery_props, data);
+}
+
+void
+_battery_dbus_ac_adapter_property_changed(void *data, DBusMessage *msg __UNUSED__)
+{
+   E_DBus_Connection *conn;
+   
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   // FIXME: e_dbus doesnt allow us to track this pending call
+   e_hal_device_get_all_properties(conn, ((Ac_Adapter *)data)->udi,
+                                   _battery_dbus_ac_adapter_props, data);
+}
+
+void
+_battery_dbus_battery_add(const char *udi)
+{
+   E_DBus_Connection *conn;
+   Battery *bat;
+
+   bat = _battery_battery_find(udi);
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   if (!bat)
+     {
+        bat = E_NEW(Battery, 1);
+        if (!bat) return;
+        bat->udi = eina_stringshare_add(udi);
+        device_batteries = eina_list_append(device_batteries, bat);
+        bat->prop_change =
+     e_dbus_signal_handler_add(conn, E_HAL_SENDER, udi,
+                               E_HAL_DEVICE_INTERFACE, "PropertyModified",
+                               _battery_dbus_battery_property_changed,
+                               bat);
+     }
+   // FIXME: e_dbus doesnt allow us to track this pending call
+   e_hal_device_get_all_properties(conn, udi, 
+                                   _battery_dbus_battery_props, bat);
+
+   _battery_device_update();
+}
+
+void
+_battery_dbus_battery_del(const char *udi)
+{
+   E_DBus_Connection *conn;
+   Eina_List *l;
+   Battery *bat;
+   
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   bat = _battery_battery_find(udi);
+   if (bat)
+     {
+        e_dbus_signal_handler_del(conn, bat->prop_change);
+        l = eina_list_data_find(device_batteries, bat);
+        eina_stringshare_del(bat->udi);
+        free(bat);
+        device_batteries = eina_list_remove_list(device_batteries, l);
+        return;
+     }
+   _battery_device_update();
+}
+
+void
+_battery_dbus_ac_adapter_add(const char *udi)
+{
+   E_DBus_Connection *conn;
+   Ac_Adapter *ac;
+
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   ac = E_NEW(Ac_Adapter, 1);
+   if (!ac) return;
+   ac->udi = eina_stringshare_add(udi);
+   device_ac_adapters = eina_list_append(device_ac_adapters, ac);
+   ac->prop_change =
+     e_dbus_signal_handler_add(conn, E_HAL_SENDER, udi,
+                               E_HAL_DEVICE_INTERFACE, "PropertyModified",
+                               _battery_dbus_ac_adapter_property_changed, 
+                               ac);
+   // FIXME: e_dbus doesnt allow us to track this pending call
+   e_hal_device_get_all_properties(conn, udi, 
+                                   _battery_dbus_ac_adapter_props, ac);
+   _battery_device_update();
+}
+
+void
+_battery_dbus_ac_adapter_del(const char *udi)
+{
+   E_DBus_Connection *conn;
+   Eina_List *l;
+   Ac_Adapter *ac;
+   
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   ac = _battery_ac_adapter_find(udi);
+   if (ac)
+     {
+        e_dbus_signal_handler_del(conn, ac->prop_change);
+        l = eina_list_data_find(device_ac_adapters, ac);
+        eina_stringshare_del(ac->udi);
+        free(ac);
+        device_ac_adapters = eina_list_remove_list(device_ac_adapters, l);
+        return;
+     }
+   _battery_device_update();
+}
+
+void
+_battery_dbus_find_battery(void *user_data __UNUSED__, void *reply_data, DBusError *err __UNUSED__)
+{
+   Eina_List *l;
+   char *device;
+   E_Hal_Manager_Find_Device_By_Capability_Return *ret;
+
+   ret = reply_data;
+   if (dbus_error_is_set(err))
+     {
+        dbus_error_free(err);
+        return;
+     }
+   if (!ret) return;
+
+   if (eina_list_count(ret->strings) < 1) return;
+   EINA_LIST_FOREACH(ret->strings, l, device)
+     _battery_dbus_battery_add(device);
+}
+
+void
+_battery_dbus_find_ac(void *user_data __UNUSED__, void *reply_data, DBusError *err __UNUSED__)
+{
+   Eina_List *l;
+   char *device;
+   E_Hal_Manager_Find_Device_By_Capability_Return *ret;
+
+   
+   ret = reply_data;
+   if (dbus_error_is_set(err))
+     {
+        dbus_error_free(err);
+        return;
+     }
+   if (!ret) return;
+
+   if (eina_list_count(ret->strings) < 1) return;
+   EINA_LIST_FOREACH(ret->strings, l, device)
+     _battery_dbus_ac_adapter_add(device);
+
+}
+
+void
+_battery_dbus_is_battery(void *user_data, void *reply_data, DBusError *err)
+{
+   char *udi = user_data;
+   E_Hal_Device_Query_Capability_Return *ret;
+
+   
+   ret = reply_data;
+   if (dbus_error_is_set(err))
+     {
+        dbus_error_free(err);
+        goto error;
+     }
+   if (!ret) goto error;
+   if (ret->boolean)
+     _battery_dbus_battery_add(udi);
+   error:
+   eina_stringshare_del(udi);
+}
+
+void
+_battery_dbus_is_ac_adapter(void *user_data, void *reply_data, DBusError *err)
+{
+   char *udi = user_data;
+   E_Hal_Device_Query_Capability_Return *ret;
+
+   
+   ret = reply_data;
+   if (dbus_error_is_set(err))
+     {
+        dbus_error_free(err);
+        goto error;
+     }
+   if (!ret) goto error;
+
+   if (ret->boolean)
+     _battery_dbus_ac_adapter_add(udi);
+   error:
+   eina_stringshare_del(udi);
+}
+
+void
+_battery_dbus_dev_add(void *data __UNUSED__, DBusMessage *msg)
+{
+   DBusError err;
+   char *udi = NULL;
+   E_DBus_Connection *conn;
+   
+   dbus_error_init(&err);
+   dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
+   if (!udi) return;
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   // FIXME: e_dbus doesnt allow us to track this pending call
+   e_hal_device_query_capability(conn, udi, "battery",
+                                 _battery_dbus_is_battery, (void*)eina_stringshare_add(udi));
+   e_hal_device_query_capability(conn, udi, "ac_adapter",
+                                 _battery_dbus_is_ac_adapter, (void*)eina_stringshare_add(udi));
+}
+
+void
+_battery_dbus_dev_del(void *data __UNUSED__, DBusMessage *msg)
+{
+   DBusError err;
+   char *udi = NULL;
+   
+   dbus_error_init(&err);
+   dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
+   if (!udi) return;
+   _battery_dbus_battery_del(udi);
+   _battery_dbus_ac_adapter_del(udi);
+}
+
+void
+_battery_dbus_have_dbus(void)
+{
+   E_DBus_Connection *conn;
+
+   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+   if (!conn) return;
+   
+   // FIXME: e_dbus doesnt allow us to track this pending call
+   e_hal_manager_find_device_by_capability
+     (conn, "battery", _battery_dbus_find_battery, NULL);
+   e_hal_manager_find_device_by_capability
+     (conn, "ac_adapter", _battery_dbus_find_ac, NULL);
+   battery_config->dbus.dev_add = 
+     e_dbus_signal_handler_add(conn, E_HAL_SENDER,
+                               E_HAL_MANAGER_PATH,
+                               E_HAL_MANAGER_INTERFACE,
+                               "DeviceAdded", _battery_dbus_dev_add, NULL);
+   battery_config->dbus.dev_del = 
+     e_dbus_signal_handler_add(conn, E_HAL_SENDER,
+                               E_HAL_MANAGER_PATH,
+                               E_HAL_MANAGER_INTERFACE,
+                               "DeviceRemoved", _battery_dbus_dev_del, NULL);
+   init_time = ecore_time_get();
+}
index fbd4911..8dee7cd 100644 (file)
@@ -4,12 +4,6 @@
 #include "e.h"
 #include "e_mod_main.h"
 
-#define UNKNOWN 0
-#define NOSUBSYSTEM 1
-#define SUBSYSTEM 2
-
-#define POPUP_DEBOUNCE_CYCLES  2
-
 /* gadcon requirements */
 static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
 static void _gc_shutdown(E_Gadcon_Client *gcc);
@@ -252,279 +246,12 @@ _battery_face_cb_menu_configure(void *data __UNUSED__, E_Menu *m, E_Menu_Item *m
    e_int_config_battery_module(m->zone->container, NULL);
 }
 
-/* dbus stuff */
-typedef struct __Battery _Battery;
-typedef struct _Ac_Adapter Ac_Adapter;
-
-struct __Battery
-{
-   const char *udi;
-#ifdef HAVE_EUDEV
-   Eeze_Udev_Watch *watch;
-#else
-   E_DBus_Signal_Handler *prop_change;
-#endif
-   Eina_Bool present:1;
-   Eina_Bool can_charge:1;
-   int state;
-   int percent;
-   int current_charge;
-   int design_charge;
-   int last_full_charge;
-   int charge_rate;
-   int time_full;
-   int time_left;
-   const char *technology;
-   const char *type;
-   const char *charge_units;
-   const char *model;
-   const char *vendor;
-   Eina_Bool got_prop:1;
-};
-
-struct _Ac_Adapter
-{
-   const char *udi;
-#ifdef HAVE_EUDEV
-   Eeze_Udev_Watch *watch;
-#else
-   E_DBus_Signal_Handler *prop_change;
-#endif
-   Eina_Bool present:1;
-   const char *product;
-};
-
-static void _battery_dbus_update(void);
-static void _battery_dbus_shutdown(void);
-static void _battery_dbus_battery_props(void *data, void *reply_data, DBusError *error);
-static void _battery_dbus_ac_adapter_props(void *data, void *reply_data, DBusError *error);
-static void _battery_dbus_battery_property_changed(void *data, DBusMessage *msg);
-static void _battery_dbus_battery_add(const char *udi);
-static void _battery_dbus_battery_del(const char *udi);
-static _Battery *_battery_dbus_battery_find(const char *udi);
-static void _battery_dbus_ac_adapter_add(const char *udi);
-static void _battery_dbus_ac_adapter_del(const char *udi);
-static Ac_Adapter *_battery_dbus_ac_adapter_find(const char *udi);
-static void _battery_dbus_find_battery(void *user_data, void *reply_data, DBusError *err);
-static void _battery_dbus_find_ac(void *user_data, void *reply_data, DBusError *err);
-static void _battery_dbus_is_battery(void *user_data, void *reply_data, DBusError *err);
-static void _battery_dbus_is_ac_adapter(void *user_data, void *reply_data, DBusError *err);
-static void _battery_dbus_dev_add(void *data, DBusMessage *msg);
-static void _battery_dbus_dev_del(void *data, DBusMessage *msg);
-static void _battery_dbus_have_dbus(void);
-
-static Eina_List *device_batteries = NULL;
-static Eina_List *device_ac_adapters = NULL;
-static double init_time = 0;
-
-static void
-_battery_dbus_shutdown(void)
-{
-   E_DBus_Connection *conn;
-   Ac_Adapter *ac;
-   _Battery *bat;
-   
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   if (battery_config->dbus.have)
-     {
-        dbus_pending_call_cancel(battery_config->dbus.have);
-        battery_config->dbus.have = NULL;
-     }
-   if (battery_config->dbus.dev_add)
-     {
-        e_dbus_signal_handler_del(conn, battery_config->dbus.dev_add);
-        battery_config->dbus.dev_add = NULL;
-     }
-   if (battery_config->dbus.dev_del)
-     {
-        e_dbus_signal_handler_del(conn, battery_config->dbus.dev_del);
-        battery_config->dbus.dev_del = NULL;
-     }
-   EINA_LIST_FREE(device_ac_adapters, ac)
-     {
-        e_dbus_signal_handler_del(conn, ac->prop_change);
-        eina_stringshare_del(ac->udi);
-       eina_stringshare_del(ac->product);
-        free(ac);
-     }
-   EINA_LIST_FREE(device_batteries, bat)
-     {
-        e_dbus_signal_handler_del(conn, bat->prop_change);
-        eina_stringshare_del(bat->udi);
-       eina_stringshare_del(bat->technology);
-       eina_stringshare_del(bat->type);
-       eina_stringshare_del(bat->charge_units);
-       eina_stringshare_del(bat->model);
-       eina_stringshare_del(bat->vendor);
-        free(bat);
-     }
-}
-
-static void
-_battery_dbus_battery_props(void *data, void *reply_data, DBusError *error __UNUSED__)
-{
-   E_Hal_Properties *ret = reply_data;
-   _Battery *bat = data;
-   int err = 0;
-   const char *str;
-   uint64_t tmp;
-
-   if (dbus_error_is_set(error))
-     {
-        dbus_error_free(error);
-        return;
-     }
-   if (!ret) return;
-
-#undef GET_BOOL
-#undef GET_INT
-#undef GET_STR
-#define GET_BOOL(val, s) bat->val = e_hal_property_bool_get(ret, s, &err)
-#define GET_INT(val, s) bat->val = e_hal_property_int_get(ret, s, &err)
-#define GET_STR(val, s) \
-   if (bat->val) eina_stringshare_del(bat->val); \
-   bat->val = NULL; \
-   str = e_hal_property_string_get(ret, s, &err); \
-   if (str) \
-     { \
-        bat->val = eina_stringshare_add(str); \
-     }
-   
-   GET_BOOL(present, "battery.present");
-   GET_STR(technology, "battery.reporting.technology");
-   GET_STR(model, "battery.model");
-   GET_STR(vendor, "battery.vendor");
-   GET_STR(type, "battery.type");
-   GET_STR(charge_units, "battery.reporting.unit");
-   GET_INT(percent, "battery.charge_level.percentage");
-   GET_BOOL(can_charge, "battery.is_rechargeable");
-   GET_INT(current_charge, "battery.charge_level.current");
-   GET_INT(charge_rate, "battery.charge_level.rate");
-   GET_INT(design_charge, "battery.charge_level.design");
-   GET_INT(last_full_charge, "battery.charge_level.last_full");
-   GET_INT(time_left, "battery.remaining_time");
-   GET_INT(time_full, "battery.remaining_time");
-   /* conform to upower */
-   if (e_hal_property_bool_get(ret, "battery.rechargeable.is_charging", &err))
-     bat->state = 1;
-   else
-     bat->state = 2;
-   bat->got_prop = 1;
-   _battery_dbus_update();
-}
-
-static void
-_battery_dbus_ac_adapter_props(void *data, void *reply_data, DBusError *error __UNUSED__)
-{
-   E_Hal_Properties *ret = reply_data;
-   Ac_Adapter *ac = data;
-   int err = 0;
-   const char *str;
-
-   if (dbus_error_is_set(error))
-     {
-        dbus_error_free(error);
-        return;
-     }
-   if (!ret) return;
-   
-#undef GET_BOOL
-#undef GET_STR
-#define GET_BOOL(val, s) ac->val = e_hal_property_bool_get(ret, s, &err)
-#define GET_STR(val, s) \
-   if (ac->val) eina_stringshare_del(ac->val); \
-   ac->val = NULL; \
-   str = e_hal_property_string_get(ret, s, &err); \
-   if (str) \
-     { \
-        ac->val = eina_stringshare_add(str); \
-     }
-   
-   GET_BOOL(present, "ac_adapter.present");
-   GET_STR(product, "info.product");
-   _battery_dbus_update();
-}
-
-static void
-_battery_dbus_battery_property_changed(void *data, DBusMessage *msg __UNUSED__)
-{
-   E_DBus_Connection *conn;
-   
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   // FIXME: e_dbus doesnt allow us to track this pending call
-   e_hal_device_get_all_properties(conn, ((_Battery *)data)->udi,
-                                   _battery_dbus_battery_props, data);
-}
-
-static void
-_battery_dbus_ac_adapter_property_changed(void *data, DBusMessage *msg __UNUSED__)
-{
-   E_DBus_Connection *conn;
-   
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   // FIXME: e_dbus doesnt allow us to track this pending call
-   e_hal_device_get_all_properties(conn, ((Ac_Adapter *)data)->udi,
-                                   _battery_dbus_ac_adapter_props, data);
-}
-
-static void
-_battery_dbus_battery_add(const char *udi)
-{
-   E_DBus_Connection *conn;
-   _Battery *bat;
-
-   bat = _battery_dbus_battery_find(udi);
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   if (!bat)
-     {
-        bat = E_NEW(_Battery, 1);
-        if (!bat) return;
-        bat->udi = eina_stringshare_add(udi);
-        device_batteries = eina_list_append(device_batteries, bat);
-        bat->prop_change =
-     e_dbus_signal_handler_add(conn, E_HAL_SENDER, udi,
-                               E_HAL_DEVICE_INTERFACE, "PropertyModified",
-                               _battery_dbus_battery_property_changed,
-                               bat);
-     }
-   // FIXME: e_dbus doesnt allow us to track this pending call
-   e_hal_device_get_all_properties(conn, udi, 
-                                   _battery_dbus_battery_props, bat);
-
-   _battery_dbus_update();
-}
-
-static void
-_battery_dbus_battery_del(const char *udi)
-{
-   E_DBus_Connection *conn;
-   Eina_List *l;
-   _Battery *bat;
-   
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   bat = _battery_dbus_battery_find(udi);
-   if (bat)
-     {
-        e_dbus_signal_handler_del(conn, bat->prop_change);
-        l = eina_list_data_find(device_batteries, bat);
-        eina_stringshare_del(bat->udi);
-        free(bat);
-        device_batteries = eina_list_remove_list(device_batteries, l);
-        return;
-     }
-   _battery_dbus_update();
-}
 
-static _Battery *
-_battery_dbus_battery_find(const char *udi)
+Battery *
+_battery_battery_find(const char *udi)
 {
    Eina_List *l;
-   _Battery *bat;
+   Battery *bat;
    EINA_LIST_FOREACH(device_batteries, l, bat)
      {
         if (!strcmp(udi, bat->udi)) return bat;
@@ -533,53 +260,8 @@ _battery_dbus_battery_find(const char *udi)
    return NULL;     
 }
 
-static void
-_battery_dbus_ac_adapter_add(const char *udi)
-{
-   E_DBus_Connection *conn;
-   Ac_Adapter *ac;
-
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   ac = E_NEW(Ac_Adapter, 1);
-   if (!ac) return;
-   ac->udi = eina_stringshare_add(udi);
-   device_ac_adapters = eina_list_append(device_ac_adapters, ac);
-   ac->prop_change =
-     e_dbus_signal_handler_add(conn, E_HAL_SENDER, udi,
-                               E_HAL_DEVICE_INTERFACE, "PropertyModified",
-                               _battery_dbus_ac_adapter_property_changed, 
-                               ac);
-   // FIXME: e_dbus doesnt allow us to track this pending call
-   e_hal_device_get_all_properties(conn, udi, 
-                                   _battery_dbus_ac_adapter_props, ac);
-   _battery_dbus_update();
-}
-
-static void
-_battery_dbus_ac_adapter_del(const char *udi)
-{
-   E_DBus_Connection *conn;
-   Eina_List *l;
-   Ac_Adapter *ac;
-   
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   ac = _battery_dbus_ac_adapter_find(udi);
-   if (ac)
-     {
-        e_dbus_signal_handler_del(conn, ac->prop_change);
-        l = eina_list_data_find(device_ac_adapters, ac);
-        eina_stringshare_del(ac->udi);
-        free(ac);
-        device_ac_adapters = eina_list_remove_list(device_ac_adapters, l);
-        return;
-     }
-   _battery_dbus_update();
-}
-
-static Ac_Adapter *
-_battery_dbus_ac_adapter_find(const char *udi)
+Ac_Adapter *
+_battery_ac_adapter_find(const char *udi)
 {
    Eina_List *l;
    Ac_Adapter *ac;
@@ -591,152 +273,8 @@ _battery_dbus_ac_adapter_find(const char *udi)
    return NULL;     
 }
 
-static void
-_battery_dbus_find_battery(void *user_data __UNUSED__, void *reply_data, DBusError *err __UNUSED__)
-{
-   Eina_List *l;
-   char *device;
-   E_Hal_Manager_Find_Device_By_Capability_Return *ret;
-
-   ret = reply_data;
-   if (dbus_error_is_set(err))
-     {
-        dbus_error_free(err);
-        return;
-     }
-   if (!ret) return;
-
-   if (eina_list_count(ret->strings) < 1) return;
-   EINA_LIST_FOREACH(ret->strings, l, device)
-     _battery_dbus_battery_add(device);
-}
-
-static void
-_battery_dbus_find_ac(void *user_data __UNUSED__, void *reply_data, DBusError *err __UNUSED__)
-{
-   Eina_List *l;
-   char *device;
-   E_Hal_Manager_Find_Device_By_Capability_Return *ret;
-
-   
-   ret = reply_data;
-   if (dbus_error_is_set(err))
-     {
-        dbus_error_free(err);
-        return;
-     }
-   if (!ret) return;
-
-   if (eina_list_count(ret->strings) < 1) return;
-   EINA_LIST_FOREACH(ret->strings, l, device)
-     _battery_dbus_ac_adapter_add(device);
-
-}
-
-static void
-_battery_dbus_is_battery(void *user_data, void *reply_data, DBusError *err)
-{
-   char *udi = user_data;
-   E_Hal_Device_Query_Capability_Return *ret;
-
-   
-   ret = reply_data;
-   if (dbus_error_is_set(err))
-     {
-        dbus_error_free(err);
-        goto error;
-     }
-   if (!ret) goto error;
-   if (ret->boolean)
-     _battery_dbus_battery_add(udi);
-   error:
-   eina_stringshare_del(udi);
-}
-
-static void
-_battery_dbus_is_ac_adapter(void *user_data, void *reply_data, DBusError *err)
-{
-   char *udi = user_data;
-   E_Hal_Device_Query_Capability_Return *ret;
-
-   
-   ret = reply_data;
-   if (dbus_error_is_set(err))
-     {
-        dbus_error_free(err);
-        goto error;
-     }
-   if (!ret) goto error;
-
-   if (ret->boolean)
-     _battery_dbus_ac_adapter_add(udi);
-   error:
-   eina_stringshare_del(udi);
-}
-
-static void
-_battery_dbus_dev_add(void *data __UNUSED__, DBusMessage *msg)
-{
-   DBusError err;
-   char *udi = NULL;
-   E_DBus_Connection *conn;
-   
-   dbus_error_init(&err);
-   dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
-   if (!udi) return;
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   // FIXME: e_dbus doesnt allow us to track this pending call
-   e_hal_device_query_capability(conn, udi, "battery",
-                                 _battery_dbus_is_battery, (void*)eina_stringshare_add(udi));
-   e_hal_device_query_capability(conn, udi, "ac_adapter",
-                                 _battery_dbus_is_ac_adapter, (void*)eina_stringshare_add(udi));
-}
-
-static void
-_battery_dbus_dev_del(void *data __UNUSED__, DBusMessage *msg)
-{
-   DBusError err;
-   char *udi = NULL;
-   
-   dbus_error_init(&err);
-   dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
-   if (!udi) return;
-   _battery_dbus_battery_del(udi);
-   _battery_dbus_ac_adapter_del(udi);
-}
-
-static void
-_battery_dbus_have_dbus(void)
-{
-   E_DBus_Connection *conn;
-
-   conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-   if (!conn) return;
-   
-   // FIXME: e_dbus doesnt allow us to track this pending call
-   e_hal_manager_find_device_by_capability
-     (conn, "battery", _battery_dbus_find_battery, NULL);
-   e_hal_manager_find_device_by_capability
-     (conn, "ac_adapter", _battery_dbus_find_ac, NULL);
-   battery_config->dbus.dev_add = 
-     e_dbus_signal_handler_add(conn, E_HAL_SENDER,
-                               E_HAL_MANAGER_PATH,
-                               E_HAL_MANAGER_INTERFACE,
-                               "DeviceAdded", _battery_dbus_dev_add, NULL);
-   battery_config->dbus.dev_del = 
-     e_dbus_signal_handler_add(conn, E_HAL_SENDER,
-                               E_HAL_MANAGER_PATH,
-                               E_HAL_MANAGER_INTERFACE,
-                               "DeviceRemoved", _battery_dbus_dev_del, NULL);
-   init_time = ecore_time_get();
-}
-  
-/* end dbus stuff */
-
-
-static void
-_battery_dbus_update(void)
+void
+_battery_device_update(void)
 {
    Eina_List *l;
    int full = -1;
@@ -751,14 +289,14 @@ _battery_dbus_update(void)
    
    for (l = device_ac_adapters; l; l = l->next)
      {
-        _Battery *ac;
+        Battery *ac;
         
         ac = l->data;
         if (ac->present) acnum++;
      }
    for (l = device_batteries; l; l = l->next)
      {
-        _Battery *bat;
+        Battery *bat;
         
         bat = l->data;
        if (!bat->got_prop)
index b6f4162..db13a6d 100644 (file)
@@ -12,6 +12,12 @@ typedef struct _Config       Config;
 #define CHECK_PMU       3
 #define CHECK_SYS_ACPI  4
 
+#define UNKNOWN 0
+#define NOSUBSYSTEM 1
+#define SUBSYSTEM 2
+
+#define POPUP_DEBOUNCE_CYCLES  2
+
 struct _Config
 {
    /* saved * loaded config values */
@@ -49,6 +55,70 @@ struct _Config
 #endif
 };
 
+typedef struct _Battery Battery;
+typedef struct _Ac_Adapter Ac_Adapter;
+
+struct _Battery
+{
+   const char *udi;
+#ifdef HAVE_EUDEV
+   Eeze_Udev_Watch *watch;
+#else
+   E_DBus_Signal_Handler *prop_change;
+#endif
+   Eina_Bool present:1;
+   Eina_Bool can_charge:1;
+   int state;
+   int percent;
+   int current_charge;
+   int design_charge;
+   int last_full_charge;
+   int charge_rate;
+   int time_full;
+   int time_left;
+   const char *technology;
+   const char *type;
+   const char *charge_units;
+   const char *model;
+   const char *vendor;
+   Eina_Bool got_prop:1;
+};
+
+struct _Ac_Adapter
+{
+   const char *udi;
+#ifdef HAVE_EUDEV
+   Eeze_Udev_Watch *watch;
+#else
+   E_DBus_Signal_Handler *prop_change;
+#endif
+   Eina_Bool present:1;
+   const char *product;
+};
+
+void _battery_dbus_battery_props(void *data, void *reply_data, DBusError *error);
+void _battery_dbus_ac_adapter_props(void *data, void *reply_data, DBusError *error);
+void _battery_dbus_battery_property_changed(void *data, DBusMessage *msg);
+void _battery_dbus_battery_add(const char *udi);
+void _battery_dbus_battery_del(const char *udi);
+Battery *_battery_battery_find(const char *udi);
+void _battery_dbus_ac_adapter_add(const char *udi);
+void _battery_dbus_ac_adapter_del(const char *udi);
+Ac_Adapter *_battery_ac_adapter_find(const char *udi);
+void _battery_dbus_find_battery(void *user_data, void *reply_data, DBusError *err);
+void _battery_dbus_find_ac(void *user_data, void *reply_data, DBusError *err);
+void _battery_dbus_is_battery(void *user_data, void *reply_data, DBusError *err);
+void _battery_dbus_is_ac_adapter(void *user_data, void *reply_data, DBusError *err);
+void _battery_dbus_dev_add(void *data, DBusMessage *msg);
+void _battery_dbus_dev_del(void *data, DBusMessage *msg);
+void _battery_dbus_have_dbus(void);
+void _battery_dbus_shutdown(void);
+void _battery_device_update(void);
+
+Eina_List *device_batteries;
+Eina_List *device_ac_adapters;
+double init_time;
+
 EAPI extern E_Module_Api e_modapi;
 
 EAPI void *e_modapi_init     (E_Module *m);
diff --git a/src/modules/battery/e_mod_udev.c b/src/modules/battery/e_mod_udev.c
new file mode 100644 (file)
index 0000000..e69de29