-
Notifications
You must be signed in to change notification settings - Fork 1
/
mis-mce.c
82 lines (70 loc) · 1.95 KB
/
mis-mce.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "maemo-input-sounds.h"
void mis_mce_init(struct private_data *priv) {
DBusError error;
dbus_error_init(&error);
priv->dbus_system = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if (!priv->dbus_system) {
if (dbus_error_is_set(&error)) {
LOG_ERROR1("Failed to get DBUS connection: %s",
error.message);
dbus_error_free(&error);
} else
LOG_ERROR("Failed to get DBUS connection");
goto done;
}
dbus_connection_setup_with_g_main(priv->dbus_system, NULL);
dbus_connection_add_filter(priv->dbus_system, mis_dbus_mce_filter, priv,
NULL);
dbus_bus_add_match(priv->dbus_system,
"type='signal',path='" MCE_SIGNAL_PATH
"',interface='" MCE_SIGNAL_IF "',member='"
MCE_TKLOCK_MODE_SIG "'", &error);
if (dbus_error_is_set(&error)) {
dbus_error_free(&error);
LOG_ERROR("failed to add match for tklock");
return;
}
done:
priv->device_state &= MODE_TKLOCK_LOCKED_MASK;
return;
}
void mis_mce_exit(struct private_data *priv) {
(void)priv;
}
DBusHandlerResult mis_dbus_mce_filter(DBusConnection * conn,
DBusMessage * msg, void *data) {
struct private_data *priv = data;
DBusMessageIter iter;
const char *value = NULL;
if (!conn) {
LOG_ERROR("conn == NULL");
goto done;
}
if (!msg) {
LOG_ERROR("msg == NULL");
goto done;
}
if (!priv) {
LOG_ERROR("priv == NULL");
goto done;
}
if (dbus_message_is_signal(msg, MCE_SIGNAL_IF, MCE_TKLOCK_MODE_SIG)) {
value = NULL;
dbus_message_iter_init(msg, &iter);
if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
{
dbus_message_iter_get_basic(&iter, &value);
LOG_VERBOSE1("mce says tklock %s", value);
dbus_message_iter_get_basic(&iter, &value);
if (g_str_equal(value, MCE_TK_UNLOCKED))
priv->device_state &= MODE_TKLOCK_LOCKED_MASK;
else
priv->device_state |= MODE_TKLOCK_UNLOCKED;
} else {
LOG_VERBOSE
("mce send a non-string tklock_mode_ind signal");
}
}
done:
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}