From 1038cc3211d8d60603657dfeef9a4bbbce1fab90 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Mon, 25 Nov 2013 00:00:03 +0100 Subject: [PATCH] device: Implement Adapter property In order to not only rely on a specific naming scheme, the device Adapter path is now exported as a property. --- doc/device-api.txt | 3 +++ src/device.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/doc/device-api.txt b/doc/device-api.txt index 0852368..94efcfa 100644 --- a/doc/device-api.txt +++ b/doc/device-api.txt @@ -33,3 +33,6 @@ Method void Push(dict attributes) org.neard.Error.InvalidArguments org.neard.Error.InProgress +Properties object Adapter [readonly] + + The object path of the adapter the device belongs to. diff --git a/src/device.c b/src/device.c index 5e67443..a6598e0 100644 --- a/src/device.c +++ b/src/device.c @@ -225,12 +225,39 @@ error: return __near_error_failed(msg, -err); } +static gboolean property_get_adapter(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *user_data) +{ + struct near_device *device = user_data; + struct near_adapter *adapter; + const char *path; + + adapter = __near_adapter_get(device->adapter_idx); + if (!adapter) + return FALSE; + + path = __near_adapter_get_path(adapter); + if (!path) + return FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); + + return TRUE; + +} + static const GDBusMethodTable device_methods[] = { { GDBUS_ASYNC_METHOD("Push", GDBUS_ARGS({"attributes", "a{sv}"}), NULL, push_ndef) }, { }, }; +static const GDBusPropertyTable device_properties[] = { + { "Adapter", "o", property_get_adapter }, + + { } +}; + void __near_device_remove(struct near_device *device) { char *path = device->path; @@ -346,9 +373,9 @@ bool __near_device_register_interface(struct near_device *device) DBG("connection %p", connection); return g_dbus_register_interface(connection, device->path, - NFC_DEVICE_INTERFACE, - device_methods, NULL, NULL, - device, NULL); + NFC_DEVICE_INTERFACE, + device_methods, NULL, + device_properties, device, NULL); } int __near_device_listen(struct near_device *device, near_device_io_cb cb) -- 2.7.4