From 903caca63bc47798f0148058b8ce69786e416938 Mon Sep 17 00:00:00 2001 From: Christopher Michael Date: Sun, 16 May 2010 05:26:29 +0000 Subject: [PATCH] Add start of ACPI code. Does not actually parse yet tho. Add e_acpi_init to startup (it safely returns if acpid is not running). Fix some formatting in e_main. SVN revision: 48910 --- src/bin/Makefile.am | 4 +- src/bin/e_acpi.c | 129 +++++++++++++++++++++++++++++++++++++++++++ src/bin/e_acpi.h | 37 +++++++++++++ src/bin/e_includes.h | 1 + src/bin/e_main.c | 29 ++++++---- 5 files changed, 188 insertions(+), 12 deletions(-) create mode 100644 src/bin/e_acpi.c create mode 100644 src/bin/e_acpi.h diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 93c92706f..aa7f35107 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -167,7 +167,8 @@ e_slidecore.h \ e_widget_flist.h \ e_scale.h \ e_widget_toolbar.h \ -e_widget_toolbook.h +e_widget_toolbook.h \ +e_acpi.h enlightenment_src = \ e_user.c \ @@ -305,6 +306,7 @@ e_widget_flist.c \ e_scale.c \ e_widget_toolbar.c \ e_widget_toolbook.c \ +e_acpi.c \ $(ENLIGHTENMENTHEADERS) enlightenment_SOURCES = \ diff --git a/src/bin/e_acpi.c b/src/bin/e_acpi.c new file mode 100644 index 000000000..304d2e8a4 --- /dev/null +++ b/src/bin/e_acpi.c @@ -0,0 +1,129 @@ +#include "e.h" + +/* local function prototypes */ +static int _e_acpi_cb_server_del(void *data __UNUSED__, int type __UNUSED__, void *event); +static int _e_acpi_cb_server_data(void *data __UNUSED__, int type __UNUSED__, void *event); +static void _e_acpi_cb_event_free(void *data __UNUSED__, void *event); + +/* local variables */ +static Ecore_Con_Server *_e_acpid = NULL; +static Eina_List *_e_acpid_hdls = NULL; + +/* public variables */ +EAPI int E_EVENT_ACPI_LID = 0; +EAPI int E_EVENT_ACPI_BATTERY = 0; +EAPI int E_EVENT_ACPI_BUTTON = 0; +EAPI int E_EVENT_ACPI_SLEEP = 0; +EAPI int E_EVENT_ACPI_WIFI = 0; + +/* public functions */ +EAPI int +e_acpi_init(void) +{ + E_EVENT_ACPI_LID = ecore_event_type_new(); + E_EVENT_ACPI_BATTERY = ecore_event_type_new(); + E_EVENT_ACPI_BUTTON = ecore_event_type_new(); + E_EVENT_ACPI_SLEEP = ecore_event_type_new(); + E_EVENT_ACPI_WIFI = ecore_event_type_new(); + + /* check for running acpid */ + if (!ecore_file_exists("/var/run/acpid.socket")) return 1; + + /* try to connect to acpid socket */ + _e_acpid = ecore_con_server_connect(ECORE_CON_LOCAL_SYSTEM, + "/var/run/acpid.socket", -1, NULL); + if (!_e_acpid) return 1; + + /* setup handlers */ + _e_acpid_hdls = + eina_list_append(_e_acpid_hdls, + ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, + _e_acpi_cb_server_del, NULL)); + _e_acpid_hdls = + eina_list_append(_e_acpid_hdls, + ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, + _e_acpi_cb_server_data, NULL)); + return 1; +} + +EAPI int +e_acpi_shutdown(void) +{ + Ecore_Event_Handler *hdl; + + /* cleanup event handlers */ + EINA_LIST_FREE(_e_acpid_hdls, hdl) + ecore_event_handler_del(hdl); + + /* kill the server if existing */ + if (_e_acpid) ecore_con_server_del(_e_acpid); + _e_acpid = NULL; + return 1; +} + +/* local functions */ +static int +_e_acpi_cb_server_del(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + Ecore_Con_Event_Server_Del *ev; + Ecore_Event_Handler *hdl; + + ev = event; + if (ev->server != _e_acpid) return 1; + + /* cleanup event handlers */ + EINA_LIST_FREE(_e_acpid_hdls, hdl) + ecore_event_handler_del(hdl); + + /* kill the server if existing */ + if (_e_acpid) ecore_con_server_del(_e_acpid); + _e_acpid = NULL; + return 1; +} + +static int +_e_acpi_cb_server_data(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + Ecore_Con_Event_Server_Data *ev; + int res; + + ev = event; + + res = fwrite(ev->data, ev->size, 1, stdout); + printf("\n"); + + /* TODO: Need to parse this data and raise events according to + * the type of acpi object. See ACPI notes below */ + + /* raise the event + + E_Event_Acpi *acpi_event; + + acpi_event = E_NEW(E_Event_Acpi, 1); + acpi_event->device = "battery"; + acpi_event->bus_id = "BAT0"; + acpi_event->event_type = "BATTERY_STATUS_CHANGED"; // make these standard E_ACPI enums + acpi_event->event_data = 1; // change to something more meaningful + ecore_event_add(E_EVENT_ACPI_LID, acpi_event, _e_acpi_cb_event_free, NULL); + */ + + return 1; +} + +static void +_e_acpi_cb_event_free(void *data __UNUSED__, void *event) +{ + E_FREE(event); +} + + +/* ACPI NOTES + * + * http://www.columbia.edu/~ariel/acpi/acpi_howto.txt (Section 6.4) + * + * Typical data looks like: + * completed event "processor CPU0 00000080 00000004" + * received event "ac_adapter AC 00000080 00000001" + * received event "battery BAT0 00000080 00000001" + * received event "button/power PBTN 00000080 00000001" + */ diff --git a/src/bin/e_acpi.h b/src/bin/e_acpi.h new file mode 100644 index 000000000..6025b393d --- /dev/null +++ b/src/bin/e_acpi.h @@ -0,0 +1,37 @@ +#ifdef E_TYPEDEFS + +/* enum for various event types */ +typedef enum _E_Acpi_Type +{ + E_ACPI_TYPE_UNKNOWN = 0, + E_ACPI_TYPE_LID, + E_ACPI_TYPE_BATTERY, + E_ACPI_TYPE_BUTTON, + E_ACPI_TYPE_SLEEP, + E_ACPI_TYPE_WIFI +} E_Acpi_Type; + +/* struct used to pass to event handlers */ +typedef struct _E_Event_Acpi E_Event_Acpi; + +#else +# ifndef E_ACPI_H +# define E_ACPI_H + +struct _E_Event_Acpi +{ + void *data; + int size; +}; + +EAPI int e_acpi_init(void); +EAPI int e_acpi_shutdown(void); + +extern EAPI int E_EVENT_ACPI_LID; +extern EAPI int E_EVENT_ACPI_BATTERY; +extern EAPI int E_EVENT_ACPI_BUTTON; +extern EAPI int E_EVENT_ACPI_SLEEP; +extern EAPI int E_EVENT_ACPI_WIFI; + +# endif +#endif diff --git a/src/bin/e_includes.h b/src/bin/e_includes.h index 4f2187d78..244c5d37b 100644 --- a/src/bin/e_includes.h +++ b/src/bin/e_includes.h @@ -138,3 +138,4 @@ #include "e_scale.h" #include "e_widget_toolbar.h" #include "e_widget_toolbook.h" +#include "e_acpi.h" diff --git a/src/bin/e_main.c b/src/bin/e_main.c index d21316d55..cb9a63c9b 100644 --- a/src/bin/e_main.c +++ b/src/bin/e_main.c @@ -751,8 +751,8 @@ main(int argc, char **argv) /* setup screensaver */ if (!e_screensaver_init()) { - e_error_message_show(_("Enlightenment cannot configure the X screensaver.")); - _e_main_shutdown(-1); + e_error_message_show(_("Enlightenment cannot configure the X screensaver.")); + _e_main_shutdown(-1); } e_init_status_set(_("Setup Desklock")); @@ -760,8 +760,8 @@ main(int argc, char **argv) /* setup desklock */ if (!e_desklock_init()) { - e_error_message_show(_("Enlightenment cannot set up its desk locking system.")); - _e_main_shutdown(-1); + e_error_message_show(_("Enlightenment cannot set up its desk locking system.")); + _e_main_shutdown(-1); } _e_main_shutdown_push(e_desklock_shutdown); @@ -775,7 +775,7 @@ main(int argc, char **argv) } _e_main_shutdown_push(e_popup_shutdown); - if (locked && ((!e_config->show_splash) && (!after_restart))) + if ((locked) && ((!e_config->show_splash) && (!after_restart))) e_desklock_show(); TS("msgbus"); @@ -923,21 +923,28 @@ main(int argc, char **argv) } _e_main_shutdown_push(e_gadcon_shutdown); + e_init_status_set(_("Setup ACPI")); + TS("acpi"); + /* acpi init will never fail. It always returns one even if acpid + * is not running, so no need to trap the return */ + e_acpi_init(); + _e_main_shutdown_push(e_acpi_shutdown); + e_init_status_set(_("Setup DPMS")); TS("dpms"); /* setup dpms */ if (!e_dpms_init()) { - e_error_message_show(_("Enlightenment cannot configure the DPMS settings.")); - _e_main_shutdown(-1); + e_error_message_show(_("Enlightenment cannot configure the DPMS settings.")); + _e_main_shutdown(-1); } e_init_status_set(_("Setup Powersave modes")); TS("powersave"); if (!e_powersave_init()) { - e_error_message_show(_("Enlightenment cannot set up its powersave modes.")); - _e_main_shutdown(-1); + e_error_message_show(_("Enlightenment cannot set up its powersave modes.")); + _e_main_shutdown(-1); } _e_main_shutdown_push(e_powersave_shutdown); @@ -956,8 +963,8 @@ main(int argc, char **argv) /* setup mouse accel */ if (!e_mouse_init()) { - e_error_message_show(_("Enlightenment cannot configure the mouse settings.")); - _e_main_shutdown(-1); + e_error_message_show(_("Enlightenment cannot configure the mouse settings.")); + _e_main_shutdown(-1); } _e_main_shutdown_push(e_actions_shutdown);