[PATCH obexd 3/7 v3] client: Add filters to PhonebookAccess.List and PhonebookAccess.Search

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

This avoid D-Bus round trips and is more aligned with what has been
proposed for MessageAccess interface.
---
 client/pbap.c | 115 ++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 76 insertions(+), 39 deletions(-)

diff --git a/client/pbap.c b/client/pbap.c
index 3fb1443..b1157e3 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -574,35 +574,24 @@ static struct obc_transfer *pull_phonebook(struct pbap_data *pbap,
 
 static DBusMessage *pull_vcard_listing(struct pbap_data *pbap,
 					DBusMessage *message, const char *name,
-					guint8 order, char *searchval, guint8 attrib,
-					guint16 count, guint16 offset)
+					GObexApparam *apparam)
 {
 	struct pending_request *request;
 	struct obc_transfer *transfer;
 	guint8 buf[272];
 	gsize len;
 	GError *err = NULL;
-	GObexApparam *apparam;
 	DBusMessage *reply;
 
+	len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
+	g_obex_apparam_free(apparam);
+
 	transfer = obc_transfer_get("x-bt/vcard-listing", name, NULL, &err);
 	if (transfer == NULL)
 		goto fail;
 
-	apparam = g_obex_apparam_set_uint8(NULL, ORDER_TAG, order);
-	apparam = g_obex_apparam_set_uint8(apparam, SEARCHATTRIB_TAG, attrib);
-	apparam = g_obex_apparam_set_string(apparam, SEARCHVALUE_TAG,
-								searchval);
-	apparam = g_obex_apparam_set_uint16(apparam, MAXLISTCOUNT_TAG, count);
-	apparam = g_obex_apparam_set_uint16(apparam, LISTSTARTOFFSET_TAG,
-								offset);
-
-	len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
-
 	obc_transfer_set_params(transfer, buf, len);
 
-	g_obex_apparam_free(apparam);
-
 	request = pending_request_new(pbap, message);
 	if (obc_session_queue(pbap->session, transfer,
 				pull_vcard_listing_callback, request, &err))
@@ -881,34 +870,33 @@ static DBusMessage *pbap_list(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
 	struct pbap_data *pbap = user_data;
+	GObexApparam *apparam;
+	DBusMessageIter args;
 
 	if (!pbap->path)
 		return g_dbus_create_error(message,
 					ERROR_INTERFACE ".Forbidden",
 					"Call Select first of all");
 
-	return pull_vcard_listing(pbap, message, "", pbap->order, "",
-				ATTRIB_NAME, DEFAULT_COUNT, DEFAULT_OFFSET);
-}
+	dbus_message_iter_init(message, &args);
 
-static DBusMessage *pbap_search(DBusConnection *connection,
-					DBusMessage *message, void *user_data)
-{
-	struct pbap_data *pbap = user_data;
-	char *field, *value;
-	guint8 attrib;
+	apparam = g_obex_apparam_set_uint16(NULL, MAXLISTCOUNT_TAG,
+							DEFAULT_COUNT);
+	apparam = g_obex_apparam_set_uint16(apparam, LISTSTARTOFFSET_TAG,
+							DEFAULT_OFFSET);
 
-	if (dbus_message_get_args(message, NULL,
-			DBUS_TYPE_STRING, &field,
-			DBUS_TYPE_STRING, &value,
-			DBUS_TYPE_INVALID) == FALSE)
+	if (parse_filters(apparam, &args) == NULL) {
+		g_obex_apparam_free(apparam);
 		return g_dbus_create_error(message,
 				ERROR_INTERFACE ".InvalidArguments", NULL);
+	}
 
-	if (!pbap->path)
-		return g_dbus_create_error(message,
-					ERROR_INTERFACE ".Forbidden",
-					"Call Select first of all");
+	return pull_vcard_listing(pbap, message, "", apparam);
+}
+
+static GObexApparam *parse_attribute(GObexApparam *apparam, const char *field)
+{
+	guint8 attrib;
 
 	if (!field || g_str_equal(field, ""))
 		attrib = ATTRIB_NAME;
@@ -919,11 +907,58 @@ static DBusMessage *pbap_search(DBusConnection *connection,
 	else if (!g_ascii_strcasecmp(field, "sound"))
 		attrib = ATTRIB_SOUND;
 	else
+		return NULL;
+
+	return g_obex_apparam_set_uint8(apparam, SEARCHATTRIB_TAG, attrib);
+}
+
+static DBusMessage *pbap_search(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct pbap_data *pbap = user_data;
+	char *field, *value;
+	GObexApparam *apparam;
+	DBusMessageIter args;
+
+	if (!pbap->path)
+		return g_dbus_create_error(message,
+					ERROR_INTERFACE ".Forbidden",
+					"Call Select first of all");
+
+	dbus_message_iter_init(message, &args);
+
+	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+
+	dbus_message_iter_get_basic(&args, &field);
+	dbus_message_iter_next(&args);
+
+	apparam = parse_attribute(NULL, field);
+	if (apparam == NULL)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+
+	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+
+	dbus_message_iter_get_basic(&args, &value);
+	dbus_message_iter_next(&args);
+
+	apparam = g_obex_apparam_set_uint16(apparam, MAXLISTCOUNT_TAG,
+							DEFAULT_COUNT);
+	apparam = g_obex_apparam_set_uint16(apparam, LISTSTARTOFFSET_TAG,
+							DEFAULT_OFFSET);
+	apparam = g_obex_apparam_set_string(apparam, SEARCHVALUE_TAG, value);
+
+	if (parse_filters(apparam, &args) == NULL) {
+		g_obex_apparam_free(apparam);
 		return g_dbus_create_error(message,
 				ERROR_INTERFACE ".InvalidArguments", NULL);
+	}
 
-	return pull_vcard_listing(pbap, message, "", pbap->order, value,
-					attrib, DEFAULT_COUNT, DEFAULT_OFFSET);
+	return pull_vcard_listing(pbap, message, "", apparam);
 }
 
 static DBusMessage *pbap_get_size(DBusConnection *connection,
@@ -1090,12 +1125,14 @@ static const GDBusMethodTable pbap_methods[] = {
 					{ "properties", "a{sv}" }),
 			pbap_pull_vcard) },
 	{ GDBUS_ASYNC_METHOD("List",
-				NULL, GDBUS_ARGS({ "vcard_listing", "a(ss)" }),
-				pbap_list) },
+			GDBUS_ARGS({ "filters", "a{sv}" }),
+			GDBUS_ARGS({ "vcard_listing", "a(ss)" }),
+			pbap_list) },
 	{ GDBUS_ASYNC_METHOD("Search",
-				GDBUS_ARGS({ "field", "s" }, { "value", "s" }),
-				GDBUS_ARGS({ "vcard_listing", "a(ss)" }),
-				pbap_search) },
+			GDBUS_ARGS({ "field", "s" }, { "value", "s" },
+					{ "filters", "a{sv}" }),
+			GDBUS_ARGS({ "vcard_listing", "a(ss)" }),
+			pbap_search) },
 	{ GDBUS_ASYNC_METHOD("GetSize",
 				NULL, GDBUS_ARGS({ "size", "q" }),
 				pbap_get_size) },
-- 
1.7.11.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux