[PATCH 5/6] addon-input: Store the button name in InputData
Guillem Jover
guillem.jover at nokia.com
Fri Oct 31 17:30:15 PDT 2008
Split the emit condition code into its own function.
---
hald/linux/addons/addon-input.c | 60 ++++++++++++++++++++------------------
1 files changed, 32 insertions(+), 28 deletions(-)
diff --git a/hald/linux/addons/addon-input.c b/hald/linux/addons/addon-input.c
index e0b8a27..a4a763f 100644
--- a/hald/linux/addons/addon-input.c
+++ b/hald/linux/addons/addon-input.c
@@ -165,6 +165,7 @@ static char *key_name[KEY_MAX + 1] = {
typedef struct _InputData InputData;
struct _InputData
{
+ char *button_type;
gboolean button_has_state;
gboolean button_state;
char udi[1]; /*variable size*/
@@ -175,6 +176,27 @@ static GMainLoop *gmain = NULL;
static GHashTable *inputs = NULL;
static GList *devices = NULL;
+static void
+emit_switch_condition (InputData *input_data, gboolean new_state)
+{
+ if (new_state != input_data->button_state) {
+ DBusError error;
+
+ input_data->button_state = new_state;
+
+ dbus_error_init (&error);
+ libhal_device_set_property_bool (ctx, input_data->udi, "button.state.value",
+ input_data->button_state, &error);
+
+ dbus_error_init (&error);
+ libhal_device_emit_condition (ctx, input_data->udi,
+ "ButtonPressed",
+ input_data->button_type,
+ &error);
+ dbus_error_free (&error);
+ }
+}
+
static gboolean
event_io (GIOChannel *channel, GIOCondition condition, gpointer data)
{
@@ -199,30 +221,17 @@ event_io (GIOChannel *channel, GIOCondition condition, gpointer data)
if (input_data->button_has_state &&
event.type == EV_SW) {
- char *name = NULL;
+ long bitmask[NBITS(SW_MAX)];
HAL_INFO (("%s: event.value=%d ; event.code=%d (0x%02x)",
input_data->udi,
event.value, event.code, event.code));
-
switch (event.code) {
case SW_LID:
- name = "lid";
- break;
case SW_TABLET_MODE:
- name = "tablet_mode";
- break;
case SW_HEADPHONE_INSERT:
- name = "headphone_insert";
- break;
case SW_RFKILL_ALL:
- name = "radio";
- break;
- }
- if (name != NULL) {
- long bitmask[NBITS(SW_MAX)];
-
/* check switch state - cuz apparently we get spurious events (or I don't know
* how to use the input layer correctly)
*
@@ -243,21 +252,9 @@ event_io (GIOChannel *channel, GIOCondition condition, gpointer data)
HAL_DEBUG (("ioctl EVIOCGSW failed"));
} else {
int new_state = test_bit (event.code, bitmask);
- if (new_state != input_data->button_state) {
- input_data->button_state = new_state;
-
- dbus_error_init (&error);
- libhal_device_set_property_bool (ctx, input_data->udi, "button.state.value",
- input_data->button_state, &error);
-
- dbus_error_init (&error);
- libhal_device_emit_condition (ctx, input_data->udi,
- "ButtonPressed",
- name,
- &error);
- dbus_error_free (&error);
- }
+ emit_switch_condition (input_data, new_state);
}
+ break;
}
} else if (event.type == EV_KEY && key_name[event.code] != NULL && event.value) {
dbus_error_init (&error);
@@ -277,6 +274,7 @@ destroy_data (InputData *data)
{
HAL_DEBUG (("Input device '%s' destroyed, free data.", data->udi));
+ g_free (data->button_type);
g_free (data);
}
@@ -316,6 +314,7 @@ add_device (LibHalContext *ctx,
InputData *data;
int len = strlen (udi);
const char* device_file;
+ const char *button_type;
data = (InputData*) g_malloc (sizeof (InputData) + len);
@@ -326,6 +325,11 @@ add_device (LibHalContext *ctx,
return;
}
+ button_type = libhal_ps_get_string (properties, "button.type");
+ if (!button_type)
+ button_type = "unknown";
+ data->button_type = g_strdup (button_type);
+
/* button_has_state will be false if the key isn't available*/
data->button_has_state = libhal_ps_get_bool (properties, "button.has_state");
if (data->button_has_state)
--
1.6.0.2
More information about the hal
mailing list