summaryrefslogtreecommitdiffstats
path: root/audio/telephony-maemo.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-12-02 17:59:56 +0200
committerJohan Hedberg <johan.hedberg@nokia.com>2008-12-08 16:10:58 +0200
commit3ce142207a553ffa14bbec2145547c867bf31b9f (patch)
treeae163524a940eb5d6b9ca48bf7067a644c65cc79 /audio/telephony-maemo.c
parent5894e16ca75e96262e6c63e5f417a89b434ccec9 (diff)
Implement preliminary support for fetching a HAL battery object
Diffstat (limited to 'audio/telephony-maemo.c')
-rw-r--r--audio/telephony-maemo.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/audio/telephony-maemo.c b/audio/telephony-maemo.c
index dad32c5b..3bae0b83 100644
--- a/audio/telephony-maemo.c
+++ b/audio/telephony-maemo.c
@@ -1376,11 +1376,54 @@ done:
dbus_message_unref(reply);
}
+static void hal_find_device_reply(DBusPendingCall *call, void *user_data)
+{
+ DBusError err;
+ DBusMessage *reply;
+ DBusMessageIter iter, sub;;
+ const char *path;
+ int type;
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&err);
+ if (dbus_set_error_from_message(&err, reply)) {
+ error("hald replied with an error: %s, %s",
+ err.name, err.message);
+ dbus_error_free(&err);
+ goto done;
+ }
+
+ dbus_message_iter_init(reply, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
+ error("Unexpected signature in GetCallInfoAll return");
+ goto done;
+ }
+
+ dbus_message_iter_recurse(&iter, &sub);
+
+ type = dbus_message_iter_get_arg_type(&sub);
+
+ if (type != DBUS_TYPE_OBJECT_PATH) {
+ error("No hal device with battery capability found");
+ goto done;
+ }
+
+ dbus_message_iter_get_basic(&sub, &path);
+
+ debug("telephony-maemo: found battery device at %s", path);
+
+done:
+ dbus_message_unref(reply);
+}
+
int telephony_init(void)
{
DBusMessage *msg;
DBusPendingCall *call;
char match_string[128];
+ const char *battery_cap = "battery";
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
@@ -1420,6 +1463,28 @@ int telephony_init(void)
dbus_pending_call_unref(call);
dbus_message_unref(msg);
+ msg = dbus_message_new_method_call("org.freedesktop.Hal",
+ "/org/freedesktop/Hal/Manager",
+ "org.freedesktop.Hal.Manager",
+ "FindDeviceByCapability");
+ if (!msg) {
+ error("Unable to allocate new D-Bus message");
+ return -ENOMEM;
+ }
+
+ dbus_message_append_args(msg, DBUS_TYPE_STRING, &battery_cap,
+ DBUS_TYPE_INVALID);
+
+ if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+ error("Sending FindDeviceByCapability failed");
+ dbus_message_unref(msg);
+ return -EIO;
+ }
+
+ dbus_pending_call_set_notify(call, hal_find_device_reply, NULL, NULL);
+ dbus_pending_call_unref(call);
+ dbus_message_unref(msg);
+
return 0;
}