spa: bluez: modemmanager: Fix NameOwnerChanged

Get the ModemManager interfaces when the ModemManager starts after native
HFP has started.

Also add log topic to be able to select log level for modemmanager plugin
part.
This commit is contained in:
Frédéric Danis 2025-11-10 10:36:11 +01:00 committed by Wim Taymans
parent 3372d8f102
commit b940d9f3a1

View file

@ -10,6 +10,10 @@
#include "modemmanager.h"
SPA_LOG_TOPIC_DEFINE_STATIC(log_topic, "spa.bluez5.modemmanager");
#undef SPA_LOG_TOPIC_DEFAULT
#define SPA_LOG_TOPIC_DEFAULT &log_topic
#define DBUS_INTERFACE_OBJECTMANAGER "org.freedesktop.DBus.ObjectManager"
struct modem {
@ -412,6 +416,26 @@ static void mm_get_managed_objects_reply(DBusPendingCall *pending, void *user_da
}
}
static bool mm_get_managed_objects(struct impl *this)
{
spa_autoptr(DBusMessage) m = dbus_message_new_method_call(MM_DBUS_SERVICE,
"/org/freedesktop/ModemManager1",
DBUS_INTERFACE_OBJECTMANAGER,
"GetManagedObjects");
if (m == NULL)
return false;
dbus_message_set_auto_start(m, false);
this->pending = send_with_reply(this->conn, m, mm_get_managed_objects_reply, this);
if (!this->pending) {
spa_log_error(this->log, "dbus call failure");
return false;
}
return true;
}
static void call_free(struct call *call)
{
spa_list_remove(&call->link);
@ -488,8 +512,12 @@ static DBusHandlerResult mm_filter_cb(DBusConnection *bus, DBusMessage *m, void
mm_clean_modem(this);
}
if (new_owner && *new_owner)
if (new_owner && *new_owner) {
spa_log_debug(this->log, "ModemManager daemon appeared (%s)", new_owner);
if (!mm_get_managed_objects(this))
goto finish;
}
}
} else if (dbus_message_is_signal(m, DBUS_INTERFACE_OBJECTMANAGER, DBUS_SIGNAL_INTERFACES_ADDED)) {
DBusMessageIter arg_i;
@ -1080,21 +1108,9 @@ void *mm_register(struct spa_log *log, void *dbus_connection, const struct spa_d
if (add_filters(this) < 0)
return NULL;
spa_autoptr(DBusMessage) m = dbus_message_new_method_call(MM_DBUS_SERVICE,
"/org/freedesktop/ModemManager1",
DBUS_INTERFACE_OBJECTMANAGER,
"GetManagedObjects");
if (m == NULL)
if (!mm_get_managed_objects(this))
return NULL;
dbus_message_set_auto_start(m, false);
this->pending = send_with_reply(this->conn, m, mm_get_managed_objects_reply, this);
if (!this->pending) {
spa_log_error(this->log, "dbus call failure");
return NULL;
}
return spa_steal_ptr(this);
}