mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
pipewire: module-jackdbus-detect: use dbus helpers
This commit is contained in:
parent
499468c19f
commit
67375965b6
1 changed files with 17 additions and 43 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
#include <spa/utils/string.h>
|
#include <spa/utils/string.h>
|
||||||
#include <spa/utils/result.h>
|
#include <spa/utils/result.h>
|
||||||
#include <spa/support/dbus.h>
|
#include <spa/support/dbus.h>
|
||||||
|
#include <spa-private/dbus-helpers.h>
|
||||||
|
|
||||||
#include "pipewire/context.h"
|
#include "pipewire/context.h"
|
||||||
#include "pipewire/impl-client.h"
|
#include "pipewire/impl-client.h"
|
||||||
|
|
@ -179,28 +180,15 @@ static const struct pw_impl_module_events module_events = {
|
||||||
.destroy = module_destroy,
|
.destroy = module_destroy,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void set_pending_call(struct impl *impl, DBusPendingCall *pending)
|
|
||||||
{
|
|
||||||
if (impl->pending_call != NULL) {
|
|
||||||
dbus_pending_call_cancel(impl->pending_call);
|
|
||||||
dbus_pending_call_unref(impl->pending_call);
|
|
||||||
}
|
|
||||||
impl->pending_call = pending;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void on_is_started_received(DBusPendingCall *pending,
|
static void on_is_started_received(DBusPendingCall *pending,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
struct impl *impl = user_data;
|
struct impl *impl = user_data;
|
||||||
DBusMessage *m;
|
spa_auto(DBusError) error = DBUS_ERROR_INIT;
|
||||||
DBusError error;
|
|
||||||
dbus_bool_t started = false;
|
dbus_bool_t started = false;
|
||||||
|
|
||||||
m = dbus_pending_call_steal_reply(pending);
|
spa_assert(impl->pending_call == pending);
|
||||||
dbus_pending_call_unref(pending);
|
spa_autoptr(DBusMessage) m = steal_reply_and_unref(&impl->pending_call);
|
||||||
impl->pending_call = NULL;
|
|
||||||
|
|
||||||
dbus_error_init(&error);
|
|
||||||
|
|
||||||
if (!m) {
|
if (!m) {
|
||||||
pw_log_error("Failed to receive reply");
|
pw_log_error("Failed to receive reply");
|
||||||
|
|
@ -221,7 +209,6 @@ static void on_is_started_received(DBusPendingCall *pending,
|
||||||
dbus_message_get_args(m, &error,
|
dbus_message_get_args(m, &error,
|
||||||
DBUS_TYPE_BOOLEAN, &started,
|
DBUS_TYPE_BOOLEAN, &started,
|
||||||
DBUS_TYPE_INVALID);
|
DBUS_TYPE_INVALID);
|
||||||
dbus_message_unref(m);
|
|
||||||
|
|
||||||
if (dbus_error_is_set(&error)) {
|
if (dbus_error_is_set(&error)) {
|
||||||
pw_log_warn("Could not get jackdbus state: %s", error.message);
|
pw_log_warn("Could not get jackdbus state: %s", error.message);
|
||||||
|
|
@ -234,37 +221,31 @@ static void on_is_started_received(DBusPendingCall *pending,
|
||||||
return;
|
return;
|
||||||
error:
|
error:
|
||||||
impl->is_started = false;
|
impl->is_started = false;
|
||||||
dbus_error_free(&error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_jack_running(struct impl *impl)
|
static void check_jack_running(struct impl *impl)
|
||||||
{
|
{
|
||||||
DBusMessage *m;
|
|
||||||
DBusPendingCall *pending;
|
|
||||||
|
|
||||||
impl->is_started = false;
|
impl->is_started = false;
|
||||||
|
cancel_and_unref(&impl->pending_call);
|
||||||
|
|
||||||
m = dbus_message_new_method_call(JACK_SERVICE_NAME,
|
spa_autoptr(DBusMessage) m = dbus_message_new_method_call(JACK_SERVICE_NAME,
|
||||||
JACK_INTERFACE_PATH,
|
JACK_INTERFACE_PATH,
|
||||||
JACK_INTERFACE_NAME,
|
JACK_INTERFACE_NAME,
|
||||||
"IsStarted");
|
"IsStarted");
|
||||||
|
if (!m)
|
||||||
|
return;
|
||||||
|
|
||||||
dbus_connection_send_with_reply(impl->bus, m, &pending, -1);
|
impl->pending_call = send_with_reply(impl->bus, m, on_is_started_received, impl);
|
||||||
dbus_pending_call_set_notify(pending, on_is_started_received, impl, NULL);
|
|
||||||
|
|
||||||
set_pending_call(impl, pending);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static DBusHandlerResult filter_handler(DBusConnection *connection,
|
static DBusHandlerResult filter_handler(DBusConnection *connection,
|
||||||
DBusMessage *message, void *user_data)
|
DBusMessage *message, void *user_data)
|
||||||
{
|
{
|
||||||
struct impl *impl = user_data;
|
struct impl *impl = user_data;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
dbus_error_init(&error);
|
|
||||||
|
|
||||||
if (dbus_message_is_signal(message, "org.freedesktop.DBus",
|
if (dbus_message_is_signal(message, "org.freedesktop.DBus",
|
||||||
"NameOwnerChanged")) {
|
"NameOwnerChanged")) {
|
||||||
|
spa_auto(DBusError) error = DBUS_ERROR_INIT;
|
||||||
const char *name, *old, *new;
|
const char *name, *old, *new;
|
||||||
if (!dbus_message_get_args(message, &error,
|
if (!dbus_message_get_args(message, &error,
|
||||||
DBUS_TYPE_STRING, &name,
|
DBUS_TYPE_STRING, &name,
|
||||||
|
|
@ -273,14 +254,14 @@ static DBusHandlerResult filter_handler(DBusConnection *connection,
|
||||||
DBUS_TYPE_INVALID)) {
|
DBUS_TYPE_INVALID)) {
|
||||||
pw_log_error("Failed to get OwnerChanged args: %s",
|
pw_log_error("Failed to get OwnerChanged args: %s",
|
||||||
error.message);
|
error.message);
|
||||||
goto not_handled;
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||||
}
|
}
|
||||||
if (!spa_streq(name, JACK_SERVICE_NAME))
|
if (!spa_streq(name, JACK_SERVICE_NAME))
|
||||||
goto not_handled;
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||||
|
|
||||||
pw_log_info("NameOwnerChanged %s -> %s", old, new);
|
pw_log_info("NameOwnerChanged %s -> %s", old, new);
|
||||||
if (spa_streq(new, "")) {
|
if (spa_streq(new, "")) {
|
||||||
set_pending_call(impl, NULL);
|
cancel_and_unref(&impl->pending_call);
|
||||||
set_started(impl, false);
|
set_started(impl, false);
|
||||||
} else {
|
} else {
|
||||||
check_jack_running(impl);
|
check_jack_running(impl);
|
||||||
|
|
@ -297,21 +278,15 @@ static DBusHandlerResult filter_handler(DBusConnection *connection,
|
||||||
set_started(impl, false);
|
set_started(impl, false);
|
||||||
}
|
}
|
||||||
return DBUS_HANDLER_RESULT_HANDLED;
|
return DBUS_HANDLER_RESULT_HANDLED;
|
||||||
|
|
||||||
not_handled:
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_dbus_connection(struct impl *impl)
|
static int init_dbus_connection(struct impl *impl)
|
||||||
{
|
{
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
impl->bus = spa_dbus_connection_get(impl->conn);
|
impl->bus = spa_dbus_connection_get(impl->conn);
|
||||||
if (impl->bus == NULL)
|
if (impl->bus == NULL)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
dbus_error_init(&error);
|
spa_auto(DBusError) error = DBUS_ERROR_INIT;
|
||||||
|
|
||||||
/* XXX: we don't handle dbus reconnection yet, so ref the handle instead */
|
/* XXX: we don't handle dbus reconnection yet, so ref the handle instead */
|
||||||
dbus_connection_ref(impl->bus);
|
dbus_connection_ref(impl->bus);
|
||||||
|
|
@ -347,7 +322,6 @@ static int init_dbus_connection(struct impl *impl)
|
||||||
return 0;
|
return 0;
|
||||||
error:
|
error:
|
||||||
pw_log_error("Failed to add listener: %s", error.message);
|
pw_log_error("Failed to add listener: %s", error.message);
|
||||||
dbus_error_free(&error);
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue