* [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties
@ 2012-10-08 8:11 Luiz Augusto von Dentz
2012-10-08 8:11 ` [WORKAROUND BlueZ 2/3] gdbus: Add fallback to SetProperty Luiz Augusto von Dentz
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2012-10-08 8:11 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds a fallback for GetProperties method when it is not
implemented.
---
This set of patches are workarounds to old properties interface to be able to
test new code until other components are ported.
gdbus/object.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/gdbus/object.c b/gdbus/object.c
index 66431de..e7a4cc3 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -1004,6 +1004,31 @@ static void generic_unregister(DBusConnection *connection, void *user_data)
g_free(data);
}
+static DBusMessage *get_properties(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ struct interface_data *iface = user_data;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(message);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ append_properties(iface, &iter);
+
+ return reply;
+}
+
+static const GDBusMethodTable fallback_methods[] = {
+ { GDBUS_METHOD("GetProperties",
+ NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+ get_properties) },
+ { }
+};
+
static DBusHandlerResult generic_message(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
@@ -1036,6 +1061,23 @@ static DBusHandlerResult generic_message(DBusConnection *connection,
iface->user_data);
}
+ for (method = fallback_methods; method &&
+ method->name && method->function; method++) {
+ if (dbus_message_is_method_call(message, iface->name,
+ method->name) == FALSE)
+ continue;
+
+ if (g_dbus_args_have_signature(method->in_args,
+ message) == FALSE)
+ continue;
+
+ if (check_privilege(connection, message, method,
+ iface) == TRUE)
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ return process_message(connection, message, method, iface);
+ }
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
--
1.7.11.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [WORKAROUND BlueZ 2/3] gdbus: Add fallback to SetProperty 2012-10-08 8:11 [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties Luiz Augusto von Dentz @ 2012-10-08 8:11 ` Luiz Augusto von Dentz 2012-10-08 8:11 ` [WORKAROUND BlueZ 3/3] gdbus: Add fallback to PropertyChanged Luiz Augusto von Dentz 2012-10-08 13:43 ` [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties Marcel Holtmann 2 siblings, 0 replies; 6+ messages in thread From: Luiz Augusto von Dentz @ 2012-10-08 8:11 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> This adds a fallback for SetProperty method when it is not implemented. --- gdbus/object.c | 94 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/gdbus/object.c b/gdbus/object.c index e7a4cc3..8f6cbed 100644 --- a/gdbus/object.c +++ b/gdbus/object.c @@ -827,15 +827,47 @@ static DBusMessage *properties_get_all(DBusConnection *connection, return reply; } +static DBusMessage *property_set(struct interface_data *iface, + DBusMessage *message, const char *name, + DBusMessageIter *iter) +{ + const GDBusPropertyTable *property; + struct property_data *propdata; + + property = find_property(iface->properties, name); + if (property == NULL) + return g_dbus_create_error(message, + DBUS_ERROR_UNKNOWN_PROPERTY, + "No such property '%s'", name); + + if (property->set == NULL) + return g_dbus_create_error(message, + DBUS_ERROR_PROPERTY_READ_ONLY, + "Property '%s' is not writable", name); + + if (property->exists != NULL && + !property->exists(property, iface->user_data)) + return g_dbus_create_error(message, + DBUS_ERROR_UNKNOWN_PROPERTY, + "No such property '%s'", name); + + propdata = g_new(struct property_data, 1); + propdata->id = next_pending_property++; + propdata->message = dbus_message_ref(message); + pending_property_set = g_slist_prepend(pending_property_set, propdata); + + property->set(property, iter, propdata->id, iface->user_data); + + return NULL; +} + static DBusMessage *properties_set(DBusConnection *connection, DBusMessage *message, void *user_data) { struct generic_data *data = user_data; DBusMessageIter iter, sub; struct interface_data *iface; - const GDBusPropertyTable *property; const char *name, *interface; - struct property_data *propdata; if (!dbus_message_iter_init(message, &iter)) return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS, @@ -869,31 +901,7 @@ static DBusMessage *properties_set(DBusConnection *connection, return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS, "No such interface '%s'", interface); - property = find_property(iface->properties, name); - if (property == NULL) - return g_dbus_create_error(message, - DBUS_ERROR_UNKNOWN_PROPERTY, - "No such property '%s'", name); - - if (property->set == NULL) - return g_dbus_create_error(message, - DBUS_ERROR_PROPERTY_READ_ONLY, - "Property '%s' is not writable", name); - - if (property->exists != NULL && - !property->exists(property, iface->user_data)) - return g_dbus_create_error(message, - DBUS_ERROR_UNKNOWN_PROPERTY, - "No such property '%s'", name); - - propdata = g_new(struct property_data, 1); - propdata->id = next_pending_property++; - propdata->message = dbus_message_ref(message); - pending_property_set = g_slist_prepend(pending_property_set, propdata); - - property->set(property, &sub, propdata->id, iface->user_data); - - return NULL; + return property_set(iface, message, name, &sub); } static const GDBusMethodTable properties_methods[] = { @@ -1022,10 +1030,42 @@ static DBusMessage *get_properties(DBusConnection *connection, return reply; } +static DBusMessage *set_property(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + struct interface_data *iface = user_data; + DBusMessageIter iter, sub; + const char *name; + + if (!dbus_message_iter_init(message, &iter)) + return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS, + "No arguments given"); + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) + return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS, + "Invalid argument type: '%c'", + dbus_message_iter_get_arg_type(&iter)); + + dbus_message_iter_get_basic(&iter, &name); + dbus_message_iter_next(&iter); + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) + return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS, + "Invalid argument type: '%c'", + dbus_message_iter_get_arg_type(&iter)); + + dbus_message_iter_recurse(&iter, &sub); + + return property_set(iface, message, name, &sub); +} + static const GDBusMethodTable fallback_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) }, { } }; -- 1.7.11.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [WORKAROUND BlueZ 3/3] gdbus: Add fallback to PropertyChanged 2012-10-08 8:11 [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties Luiz Augusto von Dentz 2012-10-08 8:11 ` [WORKAROUND BlueZ 2/3] gdbus: Add fallback to SetProperty Luiz Augusto von Dentz @ 2012-10-08 8:11 ` Luiz Augusto von Dentz 2012-10-08 13:43 ` [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties Marcel Holtmann 2 siblings, 0 replies; 6+ messages in thread From: Luiz Augusto von Dentz @ 2012-10-08 8:11 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> This adds a fallback for PropertyChanged signal when it is not implemented. --- gdbus/object.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/gdbus/object.c b/gdbus/object.c index 8f6cbed..609378c 100644 --- a/gdbus/object.c +++ b/gdbus/object.c @@ -1587,6 +1587,41 @@ gboolean g_dbus_emit_signal_valist(DBusConnection *connection, name, type, args); } +static void fallback_property_changed(struct generic_data *data, + struct interface_data *iface, + GDBusPropertyTable *p) +{ + DBusMessage *signal; + DBusMessageIter iter, value; + const GDBusSignalTable *s; + + for (s = iface->signals; s && s->name; s++) { + /* Skip if PropertyChanged is present in the signals */ + if (g_str_equal(s->name, "PropertyChanged") == 0) + return; + } + + signal = dbus_message_new_signal(data->path, iface->name, + "PropertyChanged"); + if (signal == NULL) { + error("Unable to allocate new %s.PropertyChanged signal", + iface->name); + return; + } + + dbus_message_iter_init_append(signal, &iter); + + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &p->name); + dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, p->type, + &value); + + p->get(p, &value, iface->user_data); + + dbus_message_iter_close_container(&iter, &value); + + g_dbus_send_message(data->conn, signal); +} + static void process_properties_from_interface(struct generic_data *data, struct interface_data *iface) { @@ -1624,6 +1659,8 @@ static void process_properties_from_interface(struct generic_data *data, continue; append_property(iface, p, &dict); + + fallback_property_changed(data, iface, p); } dbus_message_iter_close_container(&iter, &dict); -- 1.7.11.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties 2012-10-08 8:11 [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties Luiz Augusto von Dentz 2012-10-08 8:11 ` [WORKAROUND BlueZ 2/3] gdbus: Add fallback to SetProperty Luiz Augusto von Dentz 2012-10-08 8:11 ` [WORKAROUND BlueZ 3/3] gdbus: Add fallback to PropertyChanged Luiz Augusto von Dentz @ 2012-10-08 13:43 ` Marcel Holtmann 2012-10-08 14:25 ` Luiz Augusto von Dentz 2 siblings, 1 reply; 6+ messages in thread From: Marcel Holtmann @ 2012-10-08 13:43 UTC (permalink / raw) To: Luiz Augusto von Dentz; +Cc: linux-bluetooth Hi Luiz, > This adds a fallback for GetProperties method when it is not > implemented. > --- > This set of patches are workarounds to old properties interface to be able to > test new code until other components are ported. I am not sure I want this at all. This is a nasty hack. Especially since interfaces that previously had neither or only some of these methods get these methods. Bad idea. It might work inside BlueZ where we always added these methods, but in other projects some of these methods had been left out since the properties where send via signals with the object path being announced. Regards Marcel ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties 2012-10-08 13:43 ` [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties Marcel Holtmann @ 2012-10-08 14:25 ` Luiz Augusto von Dentz 2012-10-08 14:29 ` Luiz Augusto von Dentz 0 siblings, 1 reply; 6+ messages in thread From: Luiz Augusto von Dentz @ 2012-10-08 14:25 UTC (permalink / raw) To: Marcel Holtmann; +Cc: linux-bluetooth Hi Marcel, On Mon, Oct 8, 2012 at 3:43 PM, Marcel Holtmann <marcel@holtmann.org> wrote: > Hi Luiz, > >> This adds a fallback for GetProperties method when it is not >> implemented. >> --- >> This set of patches are workarounds to old properties interface to be able to >> test new code until other components are ported. > > I am not sure I want this at all. This is a nasty hack. > > Especially since interfaces that previously had neither or only some of > these methods get these methods. Bad idea. It might work inside BlueZ > where we always added these methods, but in other projects some of these > methods had been left out since the properties where send via signals > with the object path being announced. Yep, I fully agree this is not meant to be upstream (only perhaps behind a compilation flag or something like that), also this does not work with clients which do use the introspection data like dbus-python because the fallback methods are not part of it the python scripts will just fail. The purpose of these patches is for testing the new code with components such as PulseAudio, oFono, Connman and gnome-shell as we move forward and finish the changes they should no longer be necessary. -- Luiz Augusto von Dentz ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties 2012-10-08 14:25 ` Luiz Augusto von Dentz @ 2012-10-08 14:29 ` Luiz Augusto von Dentz 0 siblings, 0 replies; 6+ messages in thread From: Luiz Augusto von Dentz @ 2012-10-08 14:29 UTC (permalink / raw) To: Marcel Holtmann; +Cc: linux-bluetooth Hi, On Mon, Oct 8, 2012 at 4:25 PM, Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > Hi Marcel, > > On Mon, Oct 8, 2012 at 3:43 PM, Marcel Holtmann <marcel@holtmann.org> wrote: >> Hi Luiz, >> >>> This adds a fallback for GetProperties method when it is not >>> implemented. >>> --- >>> This set of patches are workarounds to old properties interface to be able to >>> test new code until other components are ported. >> >> I am not sure I want this at all. This is a nasty hack. >> >> Especially since interfaces that previously had neither or only some of >> these methods get these methods. Bad idea. It might work inside BlueZ >> where we always added these methods, but in other projects some of these >> methods had been left out since the properties where send via signals >> with the object path being announced. > > Yep, I fully agree this is not meant to be upstream (only perhaps > behind a compilation flag or something like that), also this does not > work with clients which do use the introspection data like dbus-python > because the fallback methods are not part of it the python scripts > will just fail. Actually it does work with our test scripts for some reason. -- Luiz Augusto von Dentz ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-10-08 14:29 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-10-08 8:11 [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties Luiz Augusto von Dentz 2012-10-08 8:11 ` [WORKAROUND BlueZ 2/3] gdbus: Add fallback to SetProperty Luiz Augusto von Dentz 2012-10-08 8:11 ` [WORKAROUND BlueZ 3/3] gdbus: Add fallback to PropertyChanged Luiz Augusto von Dentz 2012-10-08 13:43 ` [WORKAROUND BlueZ 1/3] gdbus: Add fallback to GetProperties Marcel Holtmann 2012-10-08 14:25 ` Luiz Augusto von Dentz 2012-10-08 14:29 ` Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox