diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-02-23 17:20:36 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2006-02-23 17:20:36 +0000 |
commit | 82910fb546cb26314aece2b0e3628212af68a319 (patch) | |
tree | 4a11265ffd76b9e10d2710f11e8eed62941ebae2 /hcid/dbus-device.c | |
parent | a8088aa488e3f9446b32ea4ad31295c94f3f2a8a (diff) |
Add last seen and last used functions
Diffstat (limited to 'hcid/dbus-device.c')
-rw-r--r-- | hcid/dbus-device.c | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/hcid/dbus-device.c b/hcid/dbus-device.c index 49e56ea7..80b42b93 100644 --- a/hcid/dbus-device.c +++ b/hcid/dbus-device.c @@ -601,14 +601,60 @@ static DBusMessage* handle_dev_discover_service_req(DBusMessage *msg, void *data static DBusMessage* handle_dev_last_seen_req(DBusMessage *msg, void *data) { - /*FIXME: */ - return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NOT_IMPLEMENTED); + struct hci_dbus_data *dbus_data = data; + DBusMessageIter iter; + DBusMessage *reply; + char filename[PATH_MAX + 1]; + char addr[18], *addr_ptr, *str; + + get_device_address(dbus_data->dev_id, addr, sizeof(addr)); + + snprintf(filename, PATH_MAX, "%s/%s/lastseen", STORAGEDIR, addr); + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_get_basic(&iter, &addr_ptr); + + str = textfile_get(filename, addr_ptr); + if (!str) + return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | ENXIO); + + reply = dbus_message_new_method_return(msg); + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &str, + DBUS_TYPE_INVALID); + + free(str); + + return reply; } static DBusMessage* handle_dev_last_used_req(DBusMessage *msg, void *data) { - /*FIXME: */ - return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NOT_IMPLEMENTED); + struct hci_dbus_data *dbus_data = data; + DBusMessageIter iter; + DBusMessage *reply; + char filename[PATH_MAX + 1]; + char addr[18], *addr_ptr, *str; + + get_device_address(dbus_data->dev_id, addr, sizeof(addr)); + + snprintf(filename, PATH_MAX, "%s/%s/lastused", STORAGEDIR, addr); + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_get_basic(&iter, &addr_ptr); + + str = textfile_get(filename, addr_ptr); + if (!str) + return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | ENXIO); + + reply = dbus_message_new_method_return(msg); + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &str, + DBUS_TYPE_INVALID); + + free(str); + + return reply; } static DBusMessage* handle_dev_get_remote_name_req(DBusMessage *msg, void *data) |