@@ -213,13 +213,48 @@ static DBusMessage *register_monitor(DBusConnection *conn, DBusMessage *msg,
return dbus_message_new_method_return(msg);
}
+/* Handles UnregisterMonitor D-Bus call */
+static DBusMessage *unregister_monitor(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ DBusMessageIter args;
+ struct app_match_data match;
+ struct adv_monitor_app *app;
+ struct btd_adv_monitor_manager *manager = user_data;
+
+ if (!dbus_message_iter_init(msg, &args))
+ return btd_error_invalid_args(msg);
+
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
+ return btd_error_invalid_args(msg);
+
+ dbus_message_iter_get_basic(&args, &match.path);
+
+ if (!strlen(match.path) || !g_str_has_prefix(match.path, "/"))
+ return btd_error_invalid_args(msg);
+
+ match.owner = dbus_message_get_sender(msg);
+
+ app = queue_find(manager->apps, app_match, &match);
+ if (!app)
+ return btd_error_does_not_exist(msg);
+
+ queue_remove(manager->apps, app);
+ app_destroy(app);
+
+ btd_info(manager->adapter_id, "Path %s removed along with Adv Monitor "
+ "app %s", match.path, match.owner);
+
+ return dbus_message_new_method_return(msg);
+}
+
static const GDBusMethodTable adv_monitor_methods[] = {
{ GDBUS_EXPERIMENTAL_METHOD("RegisterMonitor",
GDBUS_ARGS({ "application", "o" }),
NULL, register_monitor) },
{ GDBUS_EXPERIMENTAL_ASYNC_METHOD("UnregisterMonitor",
GDBUS_ARGS({ "application", "o" }),
- NULL, NULL) },
+ NULL, unregister_monitor) },
{ }
};