---
profiles/proximity/immalert.c | 5 ++--
profiles/proximity/linkloss.c | 5 ++--
profiles/proximity/reporter.c | 62 +++++++++++++++----------------------------
3 files changed, 25 insertions(+), 47 deletions(-)
diff --git a/profiles/proximity/immalert.c b/profiles/proximity/immalert.c
index 77b4966..ff40bdf 100644
--- a/profiles/proximity/immalert.c
+++ b/profiles/proximity/immalert.c
@@ -137,9 +137,8 @@ static void imm_alert_emit_alert_signal(struct connected_device *condev,
DBG("alert %s remote %s", alert_level_str, path);
- emit_property_changed(path,
- PROXIMITY_REPORTER_INTERFACE, "ImmediateAlertLevel",
- DBUS_TYPE_STRING, &alert_level_str);
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), path,
+ PROXIMITY_REPORTER_INTERFACE, "ImmediateAlertLevel");
}
static void imm_alert_remove_condev(struct connected_device *condev)
diff --git a/profiles/proximity/linkloss.c b/profiles/proximity/linkloss.c
index 40510d8..de92be7 100644
--- a/profiles/proximity/linkloss.c
+++ b/profiles/proximity/linkloss.c
@@ -138,9 +138,8 @@ static void link_loss_emit_alert_signal(struct connected_device *condev)
DBG("alert %s remote %s", alert_level_str, path);
- emit_property_changed(path,
- PROXIMITY_REPORTER_INTERFACE, "LinkLossAlertLevel",
- DBUS_TYPE_STRING, &alert_level_str);
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), path,
+ PROXIMITY_REPORTER_INTERFACE, "LinkLossAlertLevel");
}
static uint8_t link_loss_alert_lvl_read(struct attribute *a,
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index 6ec5f73..1d98ba9 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -139,56 +139,36 @@ static void register_tx_power(struct btd_adapter *adapter)
g_assert(h - start_handle == svc_size);
}
-static DBusMessage *get_properties(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static gboolean property_get_link_loss_level(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
{
- DBusMessageIter iter;
- DBusMessageIter dict;
- DBusMessage *reply = NULL;
- const char *linkloss_level, *immalert_level;
struct btd_device *device = data;
+ const char *level;
- reply = dbus_message_new_method_return(msg);
- if (!reply)
- return NULL;
-
- linkloss_level = link_loss_get_alert_level(device);
- immalert_level = imm_alert_get_level(device);
+ level = link_loss_get_alert_level(device);
- dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &level);
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict))
- goto err;
+ return TRUE;
+}
- dict_append_entry(&dict, "LinkLossAlertLevel", DBUS_TYPE_STRING,
- &linkloss_level);
- dict_append_entry(&dict, "ImmediateAlertLevel", DBUS_TYPE_STRING,
- &immalert_level);
+static gboolean property_get_immediate_alert_level(
+ const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct btd_device *device = data;
+ const char *level;
- if (!dbus_message_iter_close_container(&iter, &dict))
- goto err;
+ level = imm_alert_get_level(device);
- return reply;
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &level);
-err:
- if (reply)
- dbus_message_unref(reply);
- return btd_error_failed(msg, "not enough memory");
+ return TRUE;
}
-static const GDBusMethodTable reporter_methods[] = {
- { GDBUS_METHOD("GetProperties",
- NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
- get_properties) },
- { }
-};
-
-static const GDBusSignalTable reporter_signals[] = {
- { GDBUS_SIGNAL("PropertyChanged",
- GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+static const GDBusPropertyTable reporter_device_properties[] = {
+ { "LinkLossAlertLevel", "s", property_get_link_loss_level },
+ { "ImmediateAlertLevel", "s", property_get_immediate_alert_level },
{ }
};
@@ -216,8 +196,8 @@ static void register_reporter_device(struct btd_device *device,
g_dbus_register_interface(btd_get_dbus_connection(), path,
PROXIMITY_REPORTER_INTERFACE,
- reporter_methods, reporter_signals,
- NULL, device, NULL);
+ NULL, NULL, reporter_device_properties,
+ device, NULL);
btd_device_ref(device);
radapter->devices = g_slist_prepend(radapter->devices, device);
--
1.8.0
Hi Andrzej,
On Fri, Nov 09, 2012, Andrzej Kaczmarek wrote:
> ---
> profiles/proximity/immalert.c | 5 ++--
> profiles/proximity/linkloss.c | 5 ++--
> profiles/proximity/reporter.c | 62 +++++++++++++++----------------------------
> 3 files changed, 25 insertions(+), 47 deletions(-)
All patches in this set have been applied. Thanks.
Johan
---
test/test-proximity | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/test/test-proximity b/test/test-proximity
index b08a62a..3cb98cc 100755
--- a/test/test-proximity
+++ b/test/test-proximity
@@ -13,10 +13,12 @@ import dbus
import dbus.mainloop.glib
from optparse import OptionParser, make_option
-def property_changed(name, value):
+def properties_changed(interface, changed, invalidated):
+ if interface != "org.bluez.ProximityMonitor":
+ return
- print("PropertyChanged('%s', '%s')" % (name, value))
- mainloop.quit()
+ for name, value in changed.iteritems():
+ print("Property %s changed: %s" % (name, str(value)))
if __name__ == "__main__":
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -54,15 +56,19 @@ if __name__ == "__main__":
device_path = adapter.FindDevice(options.address)
- bus.add_signal_receiver(property_changed, bus_name="org.bluez",
- dbus_interface="org.bluez.ProximityMonitor",
- signal_name="PropertyChanged")
+ bus.add_signal_receiver(properties_changed, bus_name="org.bluez",
+ path=device_path,
+ dbus_interface="org.freedesktop.DBus.Properties",
+ signal_name="PropertiesChanged")
proximity = dbus.Interface(bus.get_object("org.bluez",
device_path), "org.bluez.ProximityMonitor")
+ device_prop = dbus.Interface(bus.get_object("org.bluez", device_path),
+ "org.freedesktop.DBus.Properties")
+
print("Proximity SetProperty('%s', '%s')" % (args[0], args[1]))
- proximity.SetProperty(args[0], args[1])
+ device_prop.Set("org.bluez.ProximityMonitor", args[0], args[1])
mainloop = gobject.MainLoop()
mainloop.run()
--
1.8.0
---
profiles/proximity/monitor.c | 214 ++++++++++++++++++++++---------------------
1 file changed, 111 insertions(+), 103 deletions(-)
diff --git a/profiles/proximity/monitor.c b/profiles/proximity/monitor.c
index e45fa4a..ba61e1b 100644
--- a/profiles/proximity/monitor.c
+++ b/profiles/proximity/monitor.c
@@ -160,9 +160,8 @@ static void linkloss_written(guint8 status, const guint8 *pdu, guint16 plen,
DBG("Link Loss Alert Level written");
- emit_property_changed(path,
- PROXIMITY_INTERFACE, "LinkLossAlertLevel",
- DBUS_TYPE_STRING, &monitor->linklosslevel);
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), path,
+ PROXIMITY_INTERFACE, "LinkLossAlertLevel");
}
static void char_discovered_cb(GSList *characteristics, guint8 status,
@@ -289,9 +288,10 @@ static gboolean immediate_timeout(gpointer user_data)
g_free(monitor->immediatelevel);
monitor->immediatelevel = g_strdup("none");
- emit_property_changed(path,
- PROXIMITY_INTERFACE, "ImmediateAlertLevel",
- DBUS_TYPE_STRING, &monitor->immediatelevel);
+
+
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), path,
+ PROXIMITY_INTERFACE, "ImmediateAlertLevel");
return FALSE;
}
@@ -304,9 +304,9 @@ static void immediate_written(gpointer user_data)
g_free(monitor->fallbacklevel);
monitor->fallbacklevel = NULL;
- emit_property_changed(path,
- PROXIMITY_INTERFACE, "ImmediateAlertLevel",
- DBUS_TYPE_STRING, &monitor->immediatelevel);
+
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), path,
+ PROXIMITY_INTERFACE, "ImmediateAlertLevel");
monitor->immediateto = g_timeout_add_seconds(IMMEDIATE_TIMEOUT,
immediate_timeout, monitor);
@@ -390,9 +390,9 @@ static void attio_disconnected_cb(gpointer user_data)
g_free(monitor->immediatelevel);
monitor->immediatelevel = g_strdup("none");
- emit_property_changed(path,
- PROXIMITY_INTERFACE, "ImmediateAlertLevel",
- DBUS_TYPE_STRING, &monitor->immediatelevel);
+
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), path,
+ PROXIMITY_INTERFACE, "ImmediateAlertLevel");
}
static gboolean level_is_valid(const char *level)
@@ -402,17 +402,38 @@ static gboolean level_is_valid(const char *level)
g_str_equal("high", level));
}
-static DBusMessage *set_link_loss_alert(DBusConnection *conn, DBusMessage *msg,
- const char *level, void *data)
+static gboolean property_get_link_loss_level(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct monitor *monitor = data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+ &monitor->linklosslevel);
+
+ return TRUE;
+}
+
+static void property_set_link_loss_level(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, GDBusPendingPropertySet id, void *data)
{
struct monitor *monitor = data;
struct btd_device *device = monitor->device;
+ const char *level;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return g_dbus_pending_property_error(id,
+ ERROR_INTERFACE ".InvalidArguments",
+ "Invalid arguments in method call");
+
+ dbus_message_iter_get_basic(iter, &level);
if (!level_is_valid(level))
- return btd_error_invalid_args(msg);
+ return g_dbus_pending_property_error(id,
+ ERROR_INTERFACE ".InvalidArguments",
+ "Invalid arguments in method call");
if (g_strcmp0(monitor->linklosslevel, level) == 0)
- return dbus_message_new_method_return(msg);
+ goto done;
g_free(monitor->linklosslevel);
monitor->linklosslevel = g_strdup(level);
@@ -424,19 +445,55 @@ static DBusMessage *set_link_loss_alert(DBusConnection *conn, DBusMessage *msg,
if (monitor->attrib)
write_alert_level(monitor);
- return dbus_message_new_method_return(msg);
+done:
+ g_dbus_pending_property_success(id);
+}
+
+static gboolean property_exists_link_loss_level(
+ const GDBusPropertyTable *property, void *data)
+{
+ struct monitor *monitor = data;
+
+ if (!monitor->enabled.linkloss)
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean property_get_immediate_alert_level(
+ const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct monitor *monitor = data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+ &monitor->immediatelevel);
+
+ return TRUE;
}
-static DBusMessage *set_immediate_alert(DBusConnection *conn, DBusMessage *msg,
- const char *level, void *data)
+static void property_set_immediate_alert_level(
+ const GDBusPropertyTable *property, DBusMessageIter *iter,
+ GDBusPendingPropertySet id, void *data)
{
struct monitor *monitor = data;
+ struct btd_device *device = monitor->device;
+ const char *level;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return g_dbus_pending_property_error(id,
+ ERROR_INTERFACE ".InvalidArguments",
+ "Invalid arguments in method call");
+
+ dbus_message_iter_get_basic(iter, &level);
if (!level_is_valid(level))
- return btd_error_invalid_args(msg);
+ return g_dbus_pending_property_error(id,
+ ERROR_INTERFACE ".InvalidArguments",
+ "Invalid arguments in method call");
if (g_strcmp0(monitor->immediatelevel, level) == 0)
- return dbus_message_new_method_return(msg);
+ goto done;
if (monitor->immediateto) {
g_source_remove(monitor->immediateto);
@@ -456,109 +513,60 @@ static DBusMessage *set_immediate_alert(DBusConnection *conn, DBusMessage *msg,
* when the Proximity Monitor starts.
*/
if (monitor->attioid == 0)
- monitor->attioid = btd_device_add_attio_callback(monitor->device,
+ monitor->attioid = btd_device_add_attio_callback(device,
attio_connected_cb,
attio_disconnected_cb,
monitor);
else if (monitor->attrib)
write_immediate_alert(monitor);
- return dbus_message_new_method_return(msg);
+done:
+ g_dbus_pending_property_success(id);
}
-static DBusMessage *get_properties(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static gboolean property_exists_immediate_alert_level(
+ const GDBusPropertyTable *property, void *data)
{
struct monitor *monitor = data;
- DBusMessageIter iter;
- DBusMessageIter dict;
- DBusMessage *reply;
-
- reply = dbus_message_new_method_return(msg);
- if (!reply)
- return NULL;
-
- dbus_message_iter_init_append(reply, &iter);
-
- dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
- if (monitor->enabled.linkloss)
- dict_append_entry(&dict, "LinkLossAlertLevel",
- DBUS_TYPE_STRING, &monitor->linklosslevel);
-
- if (monitor->enabled.findme || monitor->enabled.pathloss)
- dict_append_entry(&dict, "ImmediateAlertLevel",
- DBUS_TYPE_STRING, &monitor->immediatelevel);
-
- if (monitor->enabled.pathloss)
- dict_append_entry(&dict, "SignalLevel",
- DBUS_TYPE_STRING, &monitor->signallevel);
-
- dbus_message_iter_close_container(&iter, &dict);
+ if (!(monitor->enabled.findme || monitor->enabled.pathloss))
+ return FALSE;
- return reply;
+ return TRUE;
}
-static DBusMessage *set_property(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static gboolean property_get_signal_level(
+ const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
{
struct monitor *monitor = data;
- const char *property;
- DBusMessageIter iter;
- DBusMessageIter sub;
- const char *level;
- if (!dbus_message_iter_init(msg, &iter))
- return btd_error_invalid_args(msg);
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+ &monitor->signallevel);
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return btd_error_invalid_args(msg);
-
- dbus_message_iter_get_basic(&iter, &property);
- dbus_message_iter_next(&iter);
-
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
- return btd_error_invalid_args(msg);
-
- dbus_message_iter_recurse(&iter, &sub);
-
- if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING)
- return btd_error_invalid_args(msg);
-
- dbus_message_iter_get_basic(&sub, &level);
-
- if (g_str_equal("ImmediateAlertLevel", property)) {
- if (monitor->enabled.findme == FALSE &&
- monitor->enabled.pathloss == FALSE)
- return btd_error_not_available(msg);
+ return TRUE;
+}
- return set_immediate_alert(conn, msg, level, data);
- } else if (g_str_equal("LinkLossAlertLevel", property)) {
- if (monitor->enabled.linkloss == FALSE)
- return btd_error_not_available(msg);
+static gboolean property_exists_signal_level(const GDBusPropertyTable *property,
+ void *data)
+{
+ struct monitor *monitor = data;
- return set_link_loss_alert(conn, msg, level, data);
- }
+ if (!monitor->enabled.pathloss)
+ return FALSE;
- return btd_error_invalid_args(msg);
+ return TRUE;
}
-static const GDBusMethodTable monitor_methods[] = {
- { GDBUS_METHOD("GetProperties",
- NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
- get_properties) },
- { GDBUS_ASYNC_METHOD("SetProperty",
- GDBUS_ARGS({ "name", "s" }, { "value", "v" }), NULL,
- set_property) },
- { }
-};
-
-static const GDBusSignalTable monitor_signals[] = {
- { GDBUS_SIGNAL("PropertyChanged",
- GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+static const GDBusPropertyTable monitor_device_properties[] = {
+ { "LinkLossAlertLevel", "s", property_get_link_loss_level,
+ property_set_link_loss_level,
+ property_exists_link_loss_level },
+ { "ImmediateAlertLevel", "s", property_get_immediate_alert_level,
+ property_set_immediate_alert_level,
+ property_exists_immediate_alert_level },
+ { "SignalLevel", "s", property_get_signal_level, NULL,
+ property_exists_signal_level },
{ }
};
@@ -605,8 +613,8 @@ int monitor_register(struct btd_device *device,
if (g_dbus_register_interface(btd_get_dbus_connection(), path,
PROXIMITY_INTERFACE,
- monitor_methods, monitor_signals,
- NULL, monitor, monitor_destroy) == FALSE) {
+ NULL, NULL, monitor_device_properties,
+ monitor, monitor_destroy) == FALSE) {
error("D-Bus failed to register %s interface",
PROXIMITY_INTERFACE);
monitor_destroy(monitor);
--
1.8.0
---
doc/proximity-api.txt | 36 ++----------------------------------
1 file changed, 2 insertions(+), 34 deletions(-)
diff --git a/doc/proximity-api.txt b/doc/proximity-api.txt
index c8eae50..b68a4fe 100644
--- a/doc/proximity-api.txt
+++ b/doc/proximity-api.txt
@@ -11,27 +11,7 @@ Service org.bluez
Interface org.bluez.ProximityMonitor
Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-Methods dict GetProperties()
-
- Returns all properties for the interface. See the
- properties section for available properties.
-
- void SetProperty(string name, variant value)
-
- Changes the value of the specified property. Only
- properties that are listed as read-write are changeable.
- On success this will emit a PropertyChanged signal.
-
- Possible Errors: org.bluez.Error.InvalidArguments
-
-Signals PropertyChanged(string name, variant value)
-
- This signal indicates a changed value of a given
- property.
-
-Properties
-
- string SignalLevel[readonly]
+Properties string SignalLevel [readonly]
Alert indicating that a threshold has been reached.
Possible values: "unknown", "good", "regular", "weak"
@@ -63,19 +43,7 @@ Service org.bluez
Interface org.bluez.ProximityReporter
Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-Methods dict GetProperties()
-
- Returns all properties for the interface. See the
- properties section for available properties.
-
-Signals PropertyChanged(string name, variant value)
-
- This signal indicates a changed value of a given
- property.
-
-Properties
-
- string ImmediateAlertLevel [readonly]
+Properties string ImmediateAlertLevel [readonly]
This property indicates that Immediate Alert Level
characteristic in the local Immediate Alert Service
--
1.8.0