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
This commit is contained in:
Christopher Michael 2010-05-16 05:26:29 +00:00
parent c011256d5c
commit 903caca63b
5 changed files with 188 additions and 12 deletions

View File

@ -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 = \

129
src/bin/e_acpi.c Normal file
View File

@ -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"
*/

37
src/bin/e_acpi.h Normal file
View File

@ -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

View File

@ -138,3 +138,4 @@
#include "e_scale.h"
#include "e_widget_toolbar.h"
#include "e_widget_toolbook.h"
#include "e_acpi.h"

View File

@ -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,6 +923,13 @@ 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 */