All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/3] unit: Add gdbus/client_set_string_property
@ 2013-02-26 14:31 Luiz Augusto von Dentz
  2013-02-26 14:31 ` [PATCH BlueZ 2/3] unit: Add gdbus/client_string_changed Luiz Augusto von Dentz
  2013-02-26 14:31 ` [PATCH BlueZ 3/3] gdbus: Fix not calling property_changed callback Luiz Augusto von Dentz
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2013-02-26 14:31 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 unit/test-gdbus-client.c | 112 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 109 insertions(+), 3 deletions(-)

diff --git a/unit/test-gdbus-client.c b/unit/test-gdbus-client.c
index 7fc97ed..679c27d 100644
--- a/unit/test-gdbus-client.c
+++ b/unit/test-gdbus-client.c
@@ -35,6 +35,7 @@ struct context {
 	GMainLoop *main_loop;
 	DBusConnection *dbus_conn;
 	GDBusClient *dbus_client;
+	void *data;
 	guint timeout_source;
 };
 
@@ -98,6 +99,7 @@ static void destroy_context(struct context *context)
 
 	g_main_loop_unref(context->main_loop);
 
+	g_free(context->data);
 	g_free(context);
 }
 
@@ -353,9 +355,9 @@ static void proxy_get_string(GDBusProxy *proxy, void *user_data)
 static gboolean get_string(const GDBusPropertyTable *property,
 					DBusMessageIter *iter, void *data)
 {
-	const char *string = "value";
+	struct context *context = data;
 
-	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &string);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &context->data);
 
 	return TRUE;
 }
@@ -371,10 +373,11 @@ static void client_get_string_property(void)
 	if (context == NULL)
 		return;
 
+	context->data = g_strdup("value");
 	g_dbus_register_interface(context->dbus_conn,
 				SERVICE_PATH, SERVICE_NAME,
 				methods, signals, string_properties,
-				NULL, NULL);
+				context, NULL);
 
 	context->dbus_client = g_dbus_client_new(context->dbus_conn,
 						SERVICE_NAME, SERVICE_PATH);
@@ -592,6 +595,106 @@ static void client_get_uint64_property(void)
 	destroy_context(context);
 }
 
+static void property_set_success(const DBusError *err, void *user_data)
+{
+	g_assert(!dbus_error_is_set(err));
+}
+
+static void proxy_set_string(GDBusProxy *proxy, void *user_data)
+{
+	DBusMessageIter iter;
+	const char *string;
+
+	if (g_test_verbose())
+		g_print("proxy %s found\n",
+					g_dbus_proxy_get_interface(proxy));
+
+	g_assert(g_dbus_proxy_get_property(proxy, "String", &iter));
+	g_assert(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING);
+
+	dbus_message_iter_get_basic(&iter, &string);
+	g_assert(g_strcmp0(string, "value") == 0);
+
+	string = "value1";
+	g_assert(g_dbus_proxy_set_property_basic(proxy, "String",
+					DBUS_TYPE_STRING, &string,
+					property_set_success, user_data,
+					NULL));
+}
+
+static void property_string_changed(GDBusProxy *proxy, const char *name,
+					DBusMessageIter *iter, void *user_data)
+{
+	struct context *context = user_data;
+	const char *string;
+
+	if (g_test_verbose())
+		g_print("property %s changed\n", name);
+
+	g_assert(g_strcmp0(name, "String") == 0);
+	g_assert(dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING);
+
+	dbus_message_iter_get_basic(iter, &string);
+	g_assert(g_strcmp0(string, "value1") == 0);
+
+	g_dbus_client_unref(context->dbus_client);
+}
+
+static void set_string(const GDBusPropertyTable *property,
+			DBusMessageIter *iter, GDBusPendingPropertySet id,
+			void *data)
+{
+	struct context *context = data;
+	const char *string;
+
+	g_assert(dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING);
+
+	dbus_message_iter_get_basic(iter, &string);
+	g_assert(g_strcmp0(string, "value1") == 0);
+
+	g_free(context->data);
+	context->data = g_strdup(string);
+
+	g_dbus_emit_property_changed(context->dbus_conn, SERVICE_PATH,
+						SERVICE_NAME, "String");
+
+	g_dbus_pending_property_success(id);
+}
+
+static void client_set_string_property(void)
+{
+	struct context *context = create_context();
+	static const GDBusPropertyTable string_properties[] = {
+		{ "String", "s", get_string, set_string },
+		{ },
+	};
+
+	if (context == NULL)
+		return;
+
+	context->data = g_strdup("value");
+	g_dbus_register_interface(context->dbus_conn,
+				SERVICE_PATH, SERVICE_NAME,
+				methods, signals, string_properties,
+				context, NULL);
+
+	context->dbus_client = g_dbus_client_new(context->dbus_conn,
+						SERVICE_NAME, SERVICE_PATH);
+
+	g_dbus_client_set_disconnect_watch(context->dbus_client,
+						disconnect_handler, context);
+	g_dbus_client_set_proxy_handlers(context->dbus_client, proxy_set_string,
+						NULL, property_string_changed,
+						context);
+
+	g_main_loop_run(context->main_loop);
+
+	g_dbus_unregister_interface(context->dbus_conn,
+					SERVICE_PATH, SERVICE_NAME);
+
+	destroy_context(context);
+}
+
 int main(int argc, char *argv[])
 {
 	g_test_init(&argc, &argv, NULL);
@@ -616,5 +719,8 @@ int main(int argc, char *argv[])
 	g_test_add_func("/gdbus/client_get_dict_property",
 						client_get_dict_property);
 
+	g_test_add_func("/gdbus/client_set_string_property",
+						client_set_string_property);
+
 	return g_test_run();
 }
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH BlueZ 2/3] unit: Add gdbus/client_string_changed
  2013-02-26 14:31 [PATCH BlueZ 1/3] unit: Add gdbus/client_set_string_property Luiz Augusto von Dentz
@ 2013-02-26 14:31 ` Luiz Augusto von Dentz
  2013-02-26 14:31 ` [PATCH BlueZ 3/3] gdbus: Fix not calling property_changed callback Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2013-02-26 14:31 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 unit/test-gdbus-client.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/unit/test-gdbus-client.c b/unit/test-gdbus-client.c
index 679c27d..ed7a943 100644
--- a/unit/test-gdbus-client.c
+++ b/unit/test-gdbus-client.c
@@ -695,6 +695,64 @@ static void client_set_string_property(void)
 	destroy_context(context);
 }
 
+static gboolean string_exists(const GDBusPropertyTable *property, void *data)
+{
+	struct context *context = data;
+
+	return context->data != NULL;
+}
+
+static void proxy_string_changed(GDBusProxy *proxy, void *user_data)
+{
+	struct context *context = user_data;
+	DBusMessageIter iter;
+
+	if (g_test_verbose())
+		g_print("proxy %s found\n",
+					g_dbus_proxy_get_interface(proxy));
+
+	g_assert(!g_dbus_proxy_get_property(proxy, "String", &iter));
+
+	context->data = g_strdup("value1");
+
+	g_dbus_emit_property_changed(context->dbus_conn, SERVICE_PATH,
+						SERVICE_NAME, "String");
+}
+
+static void client_string_changed(void)
+{
+	struct context *context = create_context();
+	static const GDBusPropertyTable string_properties[] = {
+		{ "String", "s", get_string, NULL, string_exists },
+		{ },
+	};
+
+	if (context == NULL)
+		return;
+
+	g_dbus_register_interface(context->dbus_conn,
+				SERVICE_PATH, SERVICE_NAME,
+				methods, signals, string_properties,
+				context, NULL);
+
+	context->dbus_client = g_dbus_client_new(context->dbus_conn,
+						SERVICE_NAME, SERVICE_PATH);
+
+	g_dbus_client_set_disconnect_watch(context->dbus_client,
+						disconnect_handler, context);
+	g_dbus_client_set_proxy_handlers(context->dbus_client,
+						proxy_string_changed, NULL,
+						property_string_changed,
+						context);
+
+	g_main_loop_run(context->main_loop);
+
+	g_dbus_unregister_interface(context->dbus_conn,
+					SERVICE_PATH, SERVICE_NAME);
+
+	destroy_context(context);
+}
+
 int main(int argc, char *argv[])
 {
 	g_test_init(&argc, &argv, NULL);
@@ -722,5 +780,8 @@ int main(int argc, char *argv[])
 	g_test_add_func("/gdbus/client_set_string_property",
 						client_set_string_property);
 
+	g_test_add_func("/gdbus/client_string_changed",
+						client_string_changed);
+
 	return g_test_run();
 }
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH BlueZ 3/3] gdbus: Fix not calling property_changed callback
  2013-02-26 14:31 [PATCH BlueZ 1/3] unit: Add gdbus/client_set_string_property Luiz Augusto von Dentz
  2013-02-26 14:31 ` [PATCH BlueZ 2/3] unit: Add gdbus/client_string_changed Luiz Augusto von Dentz
@ 2013-02-26 14:31 ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2013-02-26 14:31 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

In case a property did not appear by the time proxy_added was called
property_changed has to be called if it appear latter otherwise the
application will be unaware of it.
---
 gdbus/client.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/gdbus/client.c b/gdbus/client.c
index 369e3ac..2a7d2e1 100644
--- a/gdbus/client.c
+++ b/gdbus/client.c
@@ -205,6 +205,7 @@ static void prop_entry_free(gpointer data)
 static void add_property(GDBusProxy *proxy, const char *name,
 				DBusMessageIter *iter, gboolean send_changed)
 {
+	GDBusClient *client = proxy->client;
 	DBusMessageIter value;
 	struct prop_entry *prop;
 
@@ -215,20 +216,8 @@ static void add_property(GDBusProxy *proxy, const char *name,
 
 	prop = g_hash_table_lookup(proxy->prop_list, name);
 	if (prop != NULL) {
-		GDBusClient *client = proxy->client;
-
 		prop_entry_update(prop, &value);
-
-		if (proxy->prop_func)
-			proxy->prop_func(proxy, name, &value, proxy->prop_data);
-
-		if (client == NULL || send_changed == FALSE)
-			return;
-
-		if (client->property_changed)
-			client->property_changed(proxy, name, &value,
-							client->user_data);
-		return;
+		goto done;
 	}
 
 	prop = prop_entry_new(name, &value);
@@ -237,8 +226,16 @@ static void add_property(GDBusProxy *proxy, const char *name,
 
 	g_hash_table_replace(proxy->prop_list, prop->name, prop);
 
+done:
 	if (proxy->prop_func)
 		proxy->prop_func(proxy, name, &value, proxy->prop_data);
+
+	if (client == NULL || send_changed == FALSE)
+		return;
+
+	if (client->property_changed)
+		client->property_changed(proxy, name, &value,
+							client->user_data);
 }
 
 static void update_properties(GDBusProxy *proxy, DBusMessageIter *iter,
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-26 14:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-26 14:31 [PATCH BlueZ 1/3] unit: Add gdbus/client_set_string_property Luiz Augusto von Dentz
2013-02-26 14:31 ` [PATCH BlueZ 2/3] unit: Add gdbus/client_string_changed Luiz Augusto von Dentz
2013-02-26 14:31 ` [PATCH BlueZ 3/3] gdbus: Fix not calling property_changed callback Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.