[PATCH v3 5/8] obexd: Add RegisterNotifications function

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

 



From: Christian Fetzer <christian.fetzer@xxxxxxxxxxxx>

This allows applications to register for all different types
of MAP event reports.

In response to this call, the MSE should connect to the local MNS
instance.
---
 doc/obex-api.txt   |  6 ++++
 obexd/client/map.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/doc/obex-api.txt b/doc/obex-api.txt
index 759c4d8..ef5d85e 100644
--- a/doc/obex-api.txt
+++ b/doc/obex-api.txt
@@ -651,6 +651,12 @@ Methods		void SetFolder(string name)
 			Possible errors: org.bluez.obex.Error.InvalidArguments
 					 org.bluez.obex.Error.Failed
 
+		void RegisterNotifications(boolean)
+
+			Register / unregister reception of notifications.
+
+			Possible errors: org.bluez.obex.Error.InvalidArguments
+					 org.bluez.obex.Error.Failed
 
 Filter:		uint16 Offset:
 
diff --git a/obexd/client/map.c b/obexd/client/map.c
index 669ba9b..5b69978 100644
--- a/obexd/client/map.c
+++ b/obexd/client/map.c
@@ -1512,6 +1512,7 @@ static DBusMessage *push_message(struct map_data *map,
 
 	transfer = obc_transfer_put("x-bt/message", folder, filename,
 								NULL, 0, &err);
+
 	if (transfer == NULL) {
 		g_obex_apparam_free(apparam);
 		goto fail;
@@ -1654,6 +1655,87 @@ static DBusMessage *map_push_message(DBusConnection *connection,
 	return push_message(map, message, filename, folder, apparam);
 }
 
+static void notification_registration_cb(struct obc_session *session,
+				struct obc_transfer *transfer,
+				GError *err, void *user_data)
+{
+	struct map_data *map = user_data;
+	DBusMessage *reply;
+
+	if (err != NULL) {
+		reply = g_dbus_create_error(map->msg,
+						ERROR_INTERFACE ".Failed",
+						"%s", err->message);
+		goto done;
+	}
+
+	reply = dbus_message_new_method_return(map->msg);
+
+done:
+	g_dbus_send_message(conn, reply);
+	dbus_message_unref(map->msg);
+}
+
+static DBusMessage *set_notification_registration(struct map_data *map,
+							DBusMessage *message,
+							GObexApparam *apparam)
+{
+	struct obc_transfer *transfer;
+	GError *err = NULL;
+	DBusMessage *reply;
+	char contents[2];
+
+	contents[0] = FILLER_BYTE;
+	contents[1] = '\0';
+
+	transfer = obc_transfer_put("x-bt/MAP-NotificationRegistration", NULL,
+					NULL, contents, sizeof(contents), &err);
+
+	if (transfer == NULL) {
+		g_obex_apparam_free(apparam);
+		goto fail;
+	}
+
+	obc_transfer_set_apparam(transfer, apparam);
+
+	if (obc_session_queue(map->session, transfer,
+				notification_registration_cb, map, &err)) {
+		map->msg = dbus_message_ref(message);
+		return NULL;
+	}
+
+fail:
+	reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+								err->message);
+	g_error_free(err);
+	return reply;
+}
+
+
+static DBusMessage *map_register_notifications(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct map_data *map = user_data;
+	GObexApparam *apparam;
+	gboolean status;
+
+	if (map->mas_instance_id < 0)
+		return g_dbus_create_error(message,
+					ERROR_INTERFACE ".Failed",
+					"Unknown MAS instance id");
+
+	if (dbus_message_get_args(message, NULL, DBUS_TYPE_BOOLEAN, &status,
+					DBUS_TYPE_INVALID) == FALSE)
+		return g_dbus_create_error(message,
+					ERROR_INTERFACE ".InvalidArguments",
+					NULL);
+
+	apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_NOTIFICATIONSTATUS,
+							status ? 0x01 : 0x00);
+
+	return set_notification_registration(map, message, apparam);
+}
+
 static const GDBusMethodTable map_methods[] = {
 	{ GDBUS_ASYNC_METHOD("SetFolder",
 				GDBUS_ARGS({ "name", "s" }), NULL,
@@ -1680,6 +1762,10 @@ static const GDBusMethodTable map_methods[] = {
 			GDBUS_ARGS({ "transfer", "o" },
 						{ "properties", "a{sv}" }),
 			map_push_message) },
+	{ GDBUS_ASYNC_METHOD("RegisterNotifications",
+			GDBUS_ARGS({ "status", "b" }),
+			NULL,
+			map_register_notifications) },
 	{ }
 };
 
-- 
1.8.1.5

--
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