mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
spa: bluez: use spa_autoptr for DBusMessage
This commit is contained in:
parent
c6c3259a08
commit
6e581deb91
8 changed files with 205 additions and 360 deletions
|
|
@ -198,7 +198,7 @@ static int set_dbus_property(struct impl *backend,
|
|||
int type,
|
||||
void *value)
|
||||
{
|
||||
DBusMessage *m, *r;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
DBusMessageIter iter;
|
||||
DBusError err;
|
||||
|
||||
|
|
@ -212,9 +212,6 @@ static int set_dbus_property(struct impl *backend,
|
|||
dbus_error_init(&err);
|
||||
|
||||
r = dbus_connection_send_with_reply_and_block(backend->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
m = NULL;
|
||||
|
||||
if (r == NULL) {
|
||||
spa_log_error(backend->log, "Transport Set() failed for transport %s (%s)", path, err.message);
|
||||
dbus_error_free(&err);
|
||||
|
|
@ -226,7 +223,6 @@ static int set_dbus_property(struct impl *backend,
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
dbus_message_unref(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -447,7 +443,7 @@ static DBusHandlerResult audio_agent_get_property(DBusConnection *conn, DBusMess
|
|||
const char *interface;
|
||||
const char *property;
|
||||
const char *agent_codec;
|
||||
DBusMessage *r = NULL;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if (!check_signature(m, "ss")) {
|
||||
r = dbus_message_new_error(m, DBUS_ERROR_INVALID_ARGS, "Invalid signature in method call");
|
||||
|
|
@ -488,7 +484,6 @@ fail:
|
|||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
|
|
@ -497,7 +492,7 @@ static DBusHandlerResult audio_agent_getall_properties(DBusConnection *conn, DBu
|
|||
const char *interface;
|
||||
DBusMessageIter iter, array, dict, data;
|
||||
const char *agent_codec;
|
||||
DBusMessage *r = NULL;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if (!check_signature(m, "s")) {
|
||||
r = dbus_message_new_error(m, DBUS_ERROR_INVALID_ARGS, "Invalid signature in method call");
|
||||
|
|
@ -538,7 +533,6 @@ fail:
|
|||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
|
|
@ -560,7 +554,7 @@ static DBusHandlerResult hsphfpd_new_audio_connection(DBusConnection *conn, DBus
|
|||
struct hsphfpd_endpoint *endpoint;
|
||||
struct spa_bt_transport *transport;
|
||||
struct hsphfpd_transport_data *transport_data;
|
||||
DBusMessage *r = NULL;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if (!check_signature(m, "oha{sv}")) {
|
||||
r = dbus_message_new_error(m, DBUS_ERROR_INVALID_ARGS, "Invalid signature in method call");
|
||||
|
|
@ -714,11 +708,8 @@ static DBusHandlerResult hsphfpd_new_audio_connection(DBusConnection *conn, DBus
|
|||
|
||||
fail:
|
||||
if (r) {
|
||||
DBusHandlerResult res = DBUS_HANDLER_RESULT_HANDLED;
|
||||
if (!dbus_connection_send(backend->conn, r, NULL))
|
||||
res = DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
dbus_message_unref(r);
|
||||
return res;
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
}
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
|
|
@ -728,7 +719,6 @@ static DBusHandlerResult audio_agent_endpoint_handler(DBusConnection *c, DBusMes
|
|||
{
|
||||
struct impl *backend = userdata;
|
||||
const char *path, *interface, *member;
|
||||
DBusMessage *r;
|
||||
DBusHandlerResult res;
|
||||
|
||||
path = dbus_message_get_path(m);
|
||||
|
|
@ -739,6 +729,7 @@ static DBusHandlerResult audio_agent_endpoint_handler(DBusConnection *c, DBusMes
|
|||
|
||||
if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||
const char *xml = AUDIO_AGENT_ENDPOINT_INTROSPECT_XML;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if ((r = dbus_message_new_method_return(m)) == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
|
@ -747,7 +738,6 @@ static DBusHandlerResult audio_agent_endpoint_handler(DBusConnection *c, DBusMes
|
|||
if (!dbus_connection_send(backend->conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
res = DBUS_HANDLER_RESULT_HANDLED;
|
||||
} else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Get"))
|
||||
res = audio_agent_get_property(c, m, path, userdata);
|
||||
|
|
@ -793,7 +783,7 @@ static DBusHandlerResult application_object_manager_handler(DBusConnection *c, D
|
|||
{
|
||||
struct impl *backend = userdata;
|
||||
const char *path, *interface, *member;
|
||||
DBusMessage *r;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
path = dbus_message_get_path(m);
|
||||
interface = dbus_message_get_interface(m);
|
||||
|
|
@ -827,16 +817,14 @@ static DBusHandlerResult application_object_manager_handler(DBusConnection *c, D
|
|||
|
||||
if (!dbus_connection_send(backend->conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
dbus_message_unref(r);
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
static void hsphfpd_audio_acquire_reply(DBusPendingCall *pending, void *user_data)
|
||||
{
|
||||
struct spa_bt_transport *transport = user_data;
|
||||
struct impl *backend = SPA_CONTAINER_OF(transport->backend, struct impl, this);
|
||||
DBusMessage *r;
|
||||
const char *transport_path;
|
||||
const char *service_id;
|
||||
const char *agent_path;
|
||||
|
|
@ -847,7 +835,7 @@ static void hsphfpd_audio_acquire_reply(DBusPendingCall *pending, void *user_dat
|
|||
|
||||
backend->acquire_in_progress = false;
|
||||
|
||||
r = steal_reply_and_unref(&pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
|
|
@ -889,8 +877,6 @@ static void hsphfpd_audio_acquire_reply(DBusPendingCall *pending, void *user_dat
|
|||
spa_log_debug(backend->log, "hsphfpd audio acquired");
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
|
||||
if (ret < 0)
|
||||
spa_bt_transport_set_state(transport, SPA_BT_TRANSPORT_STATE_ERROR);
|
||||
else
|
||||
|
|
@ -901,7 +887,7 @@ static int hsphfpd_audio_acquire(void *data, bool optional)
|
|||
{
|
||||
struct spa_bt_transport *transport = data;
|
||||
struct impl *backend = SPA_CONTAINER_OF(transport->backend, struct impl, this);
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
const char *air_codec = HSPHFP_AIR_CODEC_CVSD;
|
||||
const char *agent_codec = HSPHFP_AGENT_CODEC_PCM;
|
||||
DBusPendingCall *call;
|
||||
|
|
@ -927,7 +913,6 @@ static int hsphfpd_audio_acquire(void *data, bool optional)
|
|||
|
||||
dbus_connection_send_with_reply(backend->conn, m, &call, -1);
|
||||
dbus_pending_call_set_notify(call, hsphfpd_audio_acquire_reply, transport, NULL);
|
||||
dbus_message_unref(m);
|
||||
|
||||
backend->acquire_in_progress = true;
|
||||
|
||||
|
|
@ -1176,27 +1161,26 @@ static DBusHandlerResult hsphfpd_parse_interfaces(struct impl *backend, DBusMess
|
|||
static void hsphfpd_get_endpoints_reply(DBusPendingCall *pending, void *user_data)
|
||||
{
|
||||
struct impl *backend = user_data;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter i, array_i;
|
||||
|
||||
r = steal_reply_and_unref(&pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(backend->log, "Failed to get a list of endpoints from hsphfpd: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!spa_streq(dbus_message_get_sender(r), backend->hsphfpd_service_id)) {
|
||||
spa_log_error(backend->log, "Reply for GetManagedObjects() from invalid sender");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_init(r, &i) || !check_signature(r, "a{oa{sa{sv}}}")) {
|
||||
spa_log_error(backend->log, "Invalid arguments in GetManagedObjects() reply");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&i, &array_i);
|
||||
|
|
@ -1209,17 +1193,12 @@ static void hsphfpd_get_endpoints_reply(DBusPendingCall *pending, void *user_dat
|
|||
}
|
||||
|
||||
backend->endpoints_listed = true;
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static int backend_hsphfpd_register(void *data)
|
||||
static int hsphfpd_register(struct impl *backend)
|
||||
{
|
||||
struct impl *backend = data;
|
||||
DBusMessage *m, *r;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
const char *path = APPLICATION_OBJECT_MANAGER_PATH;
|
||||
DBusPendingCall *call;
|
||||
DBusError err;
|
||||
int res;
|
||||
|
||||
|
|
@ -1235,8 +1214,6 @@ static int backend_hsphfpd_register(void *data)
|
|||
dbus_error_init(&err);
|
||||
|
||||
r = dbus_connection_send_with_reply_and_block(backend->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (r == NULL) {
|
||||
if (dbus_error_has_name(&err, "org.freedesktop.DBus.Error.ServiceUnknown")) {
|
||||
spa_log_info(backend->log, "hsphfpd not available: %s",
|
||||
|
|
@ -1254,28 +1231,43 @@ static int backend_hsphfpd_register(void *data)
|
|||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(backend->log, "RegisterApplication() failed: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return -EIO;
|
||||
}
|
||||
dbus_message_unref(r);
|
||||
|
||||
backend->hsphfpd_service_id = strdup(dbus_message_get_sender(r));
|
||||
|
||||
spa_log_debug(backend->log, "Registered to hsphfpd");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hsphfpd_get_endpoints(struct impl *backend)
|
||||
{
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
|
||||
m = dbus_message_new_method_call(HSPHFPD_SERVICE, "/",
|
||||
DBUS_INTERFACE_OBJECTMANAGER, "GetManagedObjects");
|
||||
if (m == NULL)
|
||||
goto finish;
|
||||
return -ENOMEM;
|
||||
|
||||
DBusPendingCall *call;
|
||||
dbus_connection_send_with_reply(backend->conn, m, &call, -1);
|
||||
dbus_pending_call_set_notify(call, hsphfpd_get_endpoints_reply, backend, NULL);
|
||||
dbus_message_unref(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
return -EIO;
|
||||
static int backend_hsphfpd_register(void *data)
|
||||
{
|
||||
int ret = hsphfpd_register(data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = hsphfpd_get_endpoints(data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int backend_hsphfpd_unregistered(void *data)
|
||||
|
|
@ -1467,9 +1459,8 @@ static const struct spa_bt_backend_implementation backend_impl = {
|
|||
|
||||
static bool is_available(struct impl *backend)
|
||||
{
|
||||
DBusMessage *m, *r;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
DBusError err;
|
||||
bool success = false;
|
||||
|
||||
m = dbus_message_new_method_call(HSPHFPD_SERVICE, "/",
|
||||
DBUS_INTERFACE_INTROSPECTABLE, "Introspect");
|
||||
|
|
@ -1478,17 +1469,13 @@ static bool is_available(struct impl *backend)
|
|||
|
||||
dbus_error_init(&err);
|
||||
r = dbus_connection_send_with_reply_and_block(backend->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (r && dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
|
||||
success = true;
|
||||
return true;
|
||||
|
||||
if (r)
|
||||
dbus_message_unref(r);
|
||||
else
|
||||
if (!r)
|
||||
dbus_error_free(&err);
|
||||
|
||||
return success;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct spa_bt_backend *backend_hsphfpd_new(struct spa_bt_monitor *monitor,
|
||||
|
|
|
|||
|
|
@ -177,16 +177,9 @@ struct rfcomm {
|
|||
|
||||
static DBusHandlerResult profile_release(DBusConnection *conn, DBusMessage *m, void *userdata)
|
||||
{
|
||||
DBusMessage *r;
|
||||
|
||||
r = dbus_message_new_error(m, BLUEZ_PROFILE_INTERFACE ".Error.NotImplemented",
|
||||
"Method not implemented");
|
||||
if (r == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
if (!dbus_connection_send(conn, r, NULL))
|
||||
if (!reply_with_error(conn, m, BLUEZ_PROFILE_INTERFACE ".Error.NotImplemented", "Method not implemented"))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
|
|
@ -2195,7 +2188,7 @@ static enum spa_bt_profile path_to_profile(const char *path)
|
|||
static DBusHandlerResult profile_new_connection(DBusConnection *conn, DBusMessage *m, void *userdata)
|
||||
{
|
||||
struct impl *backend = userdata;
|
||||
DBusMessage *r;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
DBusMessageIter it;
|
||||
const char *handler, *path;
|
||||
enum spa_bt_profile profile;
|
||||
|
|
@ -2314,7 +2307,6 @@ static DBusHandlerResult profile_new_connection(DBusConnection *conn, DBusMessag
|
|||
goto fail_need_memory;
|
||||
if (!dbus_connection_send(conn, r, NULL))
|
||||
goto fail_need_memory;
|
||||
dbus_message_unref(r);
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
|
||||
|
|
@ -2327,7 +2319,7 @@ fail_need_memory:
|
|||
static DBusHandlerResult profile_request_disconnection(DBusConnection *conn, DBusMessage *m, void *userdata)
|
||||
{
|
||||
struct impl *backend = userdata;
|
||||
DBusMessage *r;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
const char *handler, *path;
|
||||
struct spa_bt_device *d;
|
||||
enum spa_bt_profile profile = SPA_BT_PROFILE_NULL;
|
||||
|
|
@ -2367,7 +2359,6 @@ static DBusHandlerResult profile_request_disconnection(DBusConnection *conn, DBu
|
|||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
|
|
@ -2375,7 +2366,6 @@ static DBusHandlerResult profile_handler(DBusConnection *c, DBusMessage *m, void
|
|||
{
|
||||
struct impl *backend = userdata;
|
||||
const char *path, *interface, *member;
|
||||
DBusMessage *r;
|
||||
DBusHandlerResult res;
|
||||
|
||||
path = dbus_message_get_path(m);
|
||||
|
|
@ -2386,6 +2376,7 @@ static DBusHandlerResult profile_handler(DBusConnection *c, DBusMessage *m, void
|
|||
|
||||
if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||
const char *xml = PROFILE_INTROSPECT_XML;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if ((r = dbus_message_new_method_return(m)) == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
|
@ -2394,7 +2385,6 @@ static DBusHandlerResult profile_handler(DBusConnection *c, DBusMessage *m, void
|
|||
if (!dbus_connection_send(backend->conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
res = DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
else if (dbus_message_is_method_call(m, BLUEZ_PROFILE_INTERFACE, "Release"))
|
||||
|
|
@ -2412,33 +2402,29 @@ static DBusHandlerResult profile_handler(DBusConnection *c, DBusMessage *m, void
|
|||
static void register_profile_reply(DBusPendingCall *pending, void *user_data)
|
||||
{
|
||||
struct impl *backend = user_data;
|
||||
DBusMessage *r;
|
||||
|
||||
r = steal_reply_and_unref(&pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_is_error(r, BLUEZ_ERROR_NOT_SUPPORTED)) {
|
||||
spa_log_warn(backend->log, "Register profile not supported");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
if (dbus_message_is_error(r, DBUS_ERROR_UNKNOWN_METHOD)) {
|
||||
spa_log_warn(backend->log, "Error registering profile");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(backend->log, "RegisterProfile() failed: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static int register_profile(struct impl *backend, const char *profile, const char *uuid)
|
||||
{
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
DBusMessageIter it[4];
|
||||
dbus_bool_t autoconnect;
|
||||
dbus_uint16_t version, chan, features;
|
||||
|
|
@ -2538,13 +2524,13 @@ static int register_profile(struct impl *backend, const char *profile, const cha
|
|||
|
||||
dbus_connection_send_with_reply(backend->conn, m, &call, -1);
|
||||
dbus_pending_call_set_notify(call, register_profile_reply, backend, NULL);
|
||||
dbus_message_unref(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void unregister_profile(struct impl *backend, const char *profile)
|
||||
{
|
||||
DBusMessage *m, *r;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
DBusError err;
|
||||
|
||||
spa_log_debug(backend->log, "Unregistering Profile %s", profile);
|
||||
|
|
@ -2559,9 +2545,6 @@ static void unregister_profile(struct impl *backend, const char *profile)
|
|||
dbus_error_init(&err);
|
||||
|
||||
r = dbus_connection_send_with_reply_and_block(backend->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
m = NULL;
|
||||
|
||||
if (r == NULL) {
|
||||
spa_log_info(backend->log, "Unregistering Profile %s failed", profile);
|
||||
dbus_error_free(&err);
|
||||
|
|
@ -2572,8 +2555,6 @@ static void unregister_profile(struct impl *backend, const char *profile)
|
|||
spa_log_error(backend->log, "UnregisterProfile() returned error: %s", dbus_message_get_error_name(r));
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static int backend_native_register_profiles(void *data)
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ finish:
|
|||
|
||||
static int _audio_acquire(struct impl *backend, const char *path, uint8_t *codec)
|
||||
{
|
||||
DBusMessage *m, *r;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
DBusError err;
|
||||
int ret = 0;
|
||||
|
||||
|
|
@ -160,9 +160,6 @@ static int _audio_acquire(struct impl *backend, const char *path, uint8_t *codec
|
|||
* XXX: do better here right now.
|
||||
*/
|
||||
r = dbus_connection_send_with_reply_and_block(backend->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
m = NULL;
|
||||
|
||||
if (r == NULL) {
|
||||
spa_log_error(backend->log, "Transport Acquire() failed for transport %s (%s)",
|
||||
path, err.message);
|
||||
|
|
@ -172,8 +169,7 @@ static int _audio_acquire(struct impl *backend, const char *path, uint8_t *codec
|
|||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(backend->log, "Acquire returned error: %s", dbus_message_get_error_name(r));
|
||||
ret = -EIO;
|
||||
goto finish;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (!dbus_message_get_args(r, &err,
|
||||
|
|
@ -182,12 +178,9 @@ static int _audio_acquire(struct impl *backend, const char *path, uint8_t *codec
|
|||
DBUS_TYPE_INVALID)) {
|
||||
spa_log_error(backend->log, "Failed to parse Acquire() reply: %s", err.message);
|
||||
dbus_error_free(&err);
|
||||
ret = -EIO;
|
||||
goto finish;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -462,18 +455,12 @@ static DBusHandlerResult ofono_audio_card_found(struct impl *backend, char *path
|
|||
static DBusHandlerResult ofono_release(DBusConnection *conn, DBusMessage *m, void *userdata)
|
||||
{
|
||||
struct impl *backend = userdata;
|
||||
DBusMessage *r;
|
||||
|
||||
spa_log_warn(backend->log, "release");
|
||||
|
||||
r = dbus_message_new_error(m, OFONO_HF_AUDIO_AGENT_INTERFACE ".Error.NotImplemented",
|
||||
"Method not implemented");
|
||||
if (r == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
if (!dbus_connection_send(conn, r, NULL))
|
||||
if (!reply_with_error(conn, m, OFONO_HF_AUDIO_AGENT_INTERFACE ".Error.NotImplemented", "Method not implemented"))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
|
|
@ -532,7 +519,7 @@ static DBusHandlerResult ofono_new_audio_connection(DBusConnection *conn, DBusMe
|
|||
uint8_t codec;
|
||||
struct spa_bt_transport *t;
|
||||
struct transport_data *td;
|
||||
DBusMessage *r = NULL;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if (dbus_message_get_args(m, NULL,
|
||||
DBUS_TYPE_OBJECT_PATH, &path,
|
||||
|
|
@ -582,11 +569,9 @@ static DBusHandlerResult ofono_new_audio_connection(DBusConnection *conn, DBusMe
|
|||
|
||||
fail:
|
||||
if (r) {
|
||||
DBusHandlerResult res = DBUS_HANDLER_RESULT_HANDLED;
|
||||
if (!dbus_connection_send(backend->conn, r, NULL))
|
||||
res = DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
dbus_message_unref(r);
|
||||
return res;
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
|
|
@ -596,7 +581,6 @@ static DBusHandlerResult ofono_handler(DBusConnection *c, DBusMessage *m, void *
|
|||
{
|
||||
struct impl *backend = userdata;
|
||||
const char *path, *interface, *member;
|
||||
DBusMessage *r;
|
||||
DBusHandlerResult res;
|
||||
|
||||
path = dbus_message_get_path(m);
|
||||
|
|
@ -607,6 +591,7 @@ static DBusHandlerResult ofono_handler(DBusConnection *c, DBusMessage *m, void *
|
|||
|
||||
if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||
const char *xml = OFONO_INTROSPECT_XML;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if ((r = dbus_message_new_method_return(m)) == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
|
@ -615,7 +600,6 @@ static DBusHandlerResult ofono_handler(DBusConnection *c, DBusMessage *m, void *
|
|||
if (!dbus_connection_send(backend->conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
res = DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
else if (dbus_message_is_method_call(m, OFONO_HF_AUDIO_AGENT_INTERFACE, "Release"))
|
||||
|
|
@ -631,22 +615,21 @@ static DBusHandlerResult ofono_handler(DBusConnection *c, DBusMessage *m, void *
|
|||
static void ofono_getcards_reply(DBusPendingCall *pending, void *user_data)
|
||||
{
|
||||
struct impl *backend = user_data;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter i, array_i, struct_i, props_i;
|
||||
|
||||
r = steal_reply_and_unref(&pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(backend->log, "Failed to get a list of handsfree audio cards: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_init(r, &i) || !spa_streq(dbus_message_get_signature(r), "a(oa{sv})")) {
|
||||
spa_log_error(backend->log, "Invalid arguments in GetCards() reply");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&i, &array_i);
|
||||
|
|
@ -663,21 +646,15 @@ static void ofono_getcards_reply(DBusPendingCall *pending, void *user_data)
|
|||
|
||||
dbus_message_iter_next(&array_i);
|
||||
}
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static int backend_ofono_register(void *data)
|
||||
static int ofono_register(struct impl *backend)
|
||||
{
|
||||
struct impl *backend = data;
|
||||
|
||||
DBusMessage *m, *r;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
const char *path = OFONO_AUDIO_CLIENT;
|
||||
uint8_t codecs[2];
|
||||
const uint8_t *pcodecs = codecs;
|
||||
int ncodecs = 0, res;
|
||||
DBusPendingCall *call;
|
||||
DBusError err;
|
||||
|
||||
spa_log_debug(backend->log, "Registering");
|
||||
|
|
@ -698,8 +675,6 @@ static int backend_ofono_register(void *data)
|
|||
dbus_error_init(&err);
|
||||
|
||||
r = dbus_connection_send_with_reply_and_block(backend->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (r == NULL) {
|
||||
if (dbus_error_has_name(&err, "org.freedesktop.DBus.Error.ServiceUnknown")) {
|
||||
spa_log_info(backend->log, "oFono not available: %s",
|
||||
|
|
@ -716,43 +691,58 @@ static int backend_ofono_register(void *data)
|
|||
|
||||
if (dbus_message_is_error(r, OFONO_ERROR_INVALID_ARGUMENTS)) {
|
||||
spa_log_warn(backend->log, "invalid arguments");
|
||||
goto finish;
|
||||
return -EIO;
|
||||
}
|
||||
if (dbus_message_is_error(r, OFONO_ERROR_IN_USE)) {
|
||||
spa_log_warn(backend->log, "already in use");
|
||||
goto finish;
|
||||
return -EIO;
|
||||
}
|
||||
if (dbus_message_is_error(r, DBUS_ERROR_UNKNOWN_METHOD)) {
|
||||
spa_log_warn(backend->log, "Error registering profile");
|
||||
goto finish;
|
||||
return -EIO;
|
||||
}
|
||||
if (dbus_message_is_error(r, DBUS_ERROR_SERVICE_UNKNOWN)) {
|
||||
spa_log_info(backend->log, "oFono not available, disabling");
|
||||
goto finish;
|
||||
return -EIO;
|
||||
}
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(backend->log, "Register() failed: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return -EIO;
|
||||
}
|
||||
dbus_message_unref(r);
|
||||
|
||||
spa_log_debug(backend->log, "registered");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ofono_getcards(struct impl *backend)
|
||||
{
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
|
||||
m = dbus_message_new_method_call(OFONO_SERVICE, "/",
|
||||
OFONO_HF_AUDIO_MANAGER_INTERFACE, "GetCards");
|
||||
if (m == NULL)
|
||||
goto finish;
|
||||
return -ENOMEM;
|
||||
|
||||
DBusPendingCall *call;
|
||||
dbus_connection_send_with_reply(backend->conn, m, &call, -1);
|
||||
dbus_pending_call_set_notify(call, ofono_getcards_reply, backend, NULL);
|
||||
dbus_message_unref(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
return -EIO;
|
||||
static int backend_ofono_register(void *data)
|
||||
{
|
||||
int ret = ofono_register(data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = ofono_getcards(data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DBusHandlerResult ofono_filter_cb(DBusConnection *bus, DBusMessage *m, void *user_data)
|
||||
|
|
@ -851,9 +841,8 @@ static const struct spa_bt_backend_implementation backend_impl = {
|
|||
|
||||
static bool is_available(struct impl *backend)
|
||||
{
|
||||
DBusMessage *m, *r;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
DBusError err;
|
||||
bool success = false;
|
||||
|
||||
m = dbus_message_new_method_call(OFONO_SERVICE, "/",
|
||||
DBUS_INTERFACE_INTROSPECTABLE, "Introspect");
|
||||
|
|
@ -862,17 +851,13 @@ static bool is_available(struct impl *backend)
|
|||
|
||||
dbus_error_init(&err);
|
||||
r = dbus_connection_send_with_reply_and_block(backend->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (r && dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
|
||||
success = true;
|
||||
return true;
|
||||
|
||||
if (r)
|
||||
dbus_message_unref(r);
|
||||
else
|
||||
if (!r)
|
||||
dbus_error_free(&err);
|
||||
|
||||
return success;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct spa_bt_backend *backend_ofono_new(struct spa_bt_monitor *monitor,
|
||||
|
|
|
|||
|
|
@ -221,9 +221,10 @@ static char *battery_get_name(const char *device_path)
|
|||
}
|
||||
|
||||
// Unregister virtual battery of device
|
||||
static void battery_remove(struct spa_bt_device *device) {
|
||||
static void battery_remove(struct spa_bt_device *device)
|
||||
{
|
||||
DBusMessageIter i, entry;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
const char *interface;
|
||||
|
||||
cancel_and_unref(&device->battery_pending_call);
|
||||
|
|
@ -252,8 +253,6 @@ static void battery_remove(struct spa_bt_device *device) {
|
|||
spa_log_error(device->monitor->log, "sending " DBUS_SIGNAL_INTERFACES_REMOVED " failed");
|
||||
}
|
||||
|
||||
dbus_message_unref(m);
|
||||
|
||||
device->has_battery = false;
|
||||
}
|
||||
|
||||
|
|
@ -292,7 +291,7 @@ static void battery_update(struct spa_bt_device *device)
|
|||
{
|
||||
spa_log_debug(device->monitor->log, "updating battery: %s", device->battery_path);
|
||||
|
||||
DBusMessage *msg;
|
||||
spa_autoptr(DBusMessage) msg = NULL;
|
||||
DBusMessageIter iter;
|
||||
|
||||
msg = dbus_message_new_signal(device->battery_path,
|
||||
|
|
@ -308,13 +307,12 @@ static void battery_update(struct spa_bt_device *device)
|
|||
|
||||
if (!dbus_connection_send(device->monitor->conn, msg, NULL))
|
||||
spa_log_error(device->monitor->log, "Error updating battery");
|
||||
|
||||
dbus_message_unref(msg);
|
||||
}
|
||||
|
||||
// Create new virtual battery with value stored in current device object
|
||||
static void battery_create(struct spa_bt_device *device) {
|
||||
DBusMessage *msg;
|
||||
static void battery_create(struct spa_bt_device *device)
|
||||
{
|
||||
spa_autoptr(DBusMessage) msg = NULL;
|
||||
DBusMessageIter iter, entry, dict;
|
||||
msg = dbus_message_new_signal(PIPEWIRE_BATTERY_PROVIDER,
|
||||
DBUS_INTERFACE_OBJECT_MANAGER,
|
||||
|
|
@ -339,8 +337,6 @@ static void battery_create(struct spa_bt_device *device) {
|
|||
return;
|
||||
}
|
||||
|
||||
dbus_message_unref(msg);
|
||||
|
||||
spa_log_debug(device->monitor->log, "Created virtual battery for %s", device->address);
|
||||
device->has_battery = true;
|
||||
}
|
||||
|
|
@ -348,17 +344,15 @@ static void battery_create(struct spa_bt_device *device) {
|
|||
static void on_battery_provider_registered(DBusPendingCall *pending_call,
|
||||
void *data)
|
||||
{
|
||||
DBusMessage *reply;
|
||||
struct spa_bt_device *device = data;
|
||||
|
||||
spa_assert(device->battery_pending_call == pending_call);
|
||||
reply = steal_reply_and_unref(&device->battery_pending_call);
|
||||
spa_autoptr(DBusMessage) reply = steal_reply_and_unref(&device->battery_pending_call);
|
||||
|
||||
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(device->monitor->log, "Failed to register battery provider. Error: %s", dbus_message_get_error_name(reply));
|
||||
spa_log_error(device->monitor->log, "BlueZ Battery Provider is not available, won't retry to register it. Make sure you are running BlueZ 5.56+ with experimental features to use Battery Provider.");
|
||||
device->adapter->battery_provider_unavailable = true;
|
||||
dbus_message_unref(reply);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -368,14 +362,12 @@ static void on_battery_provider_registered(DBusPendingCall *pending_call,
|
|||
|
||||
if (!device->has_battery)
|
||||
battery_create(device);
|
||||
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
// Register Battery Provider for adapter and then create virtual battery for device
|
||||
static void register_battery_provider(struct spa_bt_device *device)
|
||||
{
|
||||
DBusMessage *method_call;
|
||||
spa_autoptr(DBusMessage) method_call = NULL;
|
||||
DBusMessageIter message_iter;
|
||||
|
||||
if (device->battery_pending_call) {
|
||||
|
|
@ -400,13 +392,10 @@ static void register_battery_provider(struct spa_bt_device *device)
|
|||
|
||||
if (!dbus_connection_send_with_reply(device->monitor->conn, method_call, &device->battery_pending_call,
|
||||
DBUS_TIMEOUT_USE_DEFAULT)) {
|
||||
dbus_message_unref(method_call);
|
||||
spa_log_error(device->monitor->log, "Failed to register battery provider");
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_unref(method_call);
|
||||
|
||||
if (!device->battery_pending_call) {
|
||||
spa_log_error(device->monitor->log, "Failed to register battery provider");
|
||||
return;
|
||||
|
|
@ -546,7 +535,7 @@ static DBusHandlerResult endpoint_select_configuration(DBusConnection *conn, DBu
|
|||
const char *path;
|
||||
uint8_t *cap, config[A2DP_MAX_CAPS_SIZE];
|
||||
uint8_t *pconf = (uint8_t *) config;
|
||||
DBusMessage *r;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
DBusError err;
|
||||
int size, res;
|
||||
const struct media_codec *codec;
|
||||
|
|
@ -604,8 +593,6 @@ exit_send:
|
|||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
|
|
@ -618,7 +605,7 @@ static DBusHandlerResult endpoint_select_properties(DBusConnection *conn, DBusMe
|
|||
struct spa_bt_monitor *monitor = userdata;
|
||||
const char *path;
|
||||
DBusMessageIter args, props, iter;
|
||||
DBusMessage *r = NULL;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
int res;
|
||||
const struct media_codec *codec;
|
||||
bool sink;
|
||||
|
|
@ -831,12 +818,8 @@ static DBusHandlerResult endpoint_select_properties(DBusConnection *conn, DBusMe
|
|||
|
||||
dbus_message_iter_close_container(&iter, &dict);
|
||||
|
||||
if (r) {
|
||||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
|
||||
|
|
@ -845,15 +828,8 @@ error_invalid:
|
|||
goto error;
|
||||
|
||||
error:
|
||||
if (r)
|
||||
dbus_message_unref(r);
|
||||
if ((r = dbus_message_new_error(m, "org.bluez.Error.InvalidArguments", err_msg)) == NULL)
|
||||
if (!reply_with_error(conn, m, "org.bluez.Error.InvalidArguments", err_msg))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
if (!dbus_connection_send(conn, r, NULL)) {
|
||||
dbus_message_unref(r);
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
}
|
||||
dbus_message_unref(r);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
|
|
@ -1591,7 +1567,7 @@ static int device_try_connect_profile(struct spa_bt_device *device,
|
|||
const char *profile_uuid)
|
||||
{
|
||||
struct spa_bt_monitor *monitor = device->monitor;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
|
||||
spa_log_info(monitor->log, "device %p %s: profile %s not connected; try ConnectProfile()",
|
||||
device, device->path, profile_uuid);
|
||||
|
|
@ -1605,11 +1581,8 @@ static int device_try_connect_profile(struct spa_bt_device *device,
|
|||
if (m == NULL)
|
||||
return -ENOMEM;
|
||||
dbus_message_append_args(m, DBUS_TYPE_STRING, &profile_uuid, DBUS_TYPE_INVALID);
|
||||
if (!dbus_connection_send(monitor->conn, m, NULL)) {
|
||||
dbus_message_unref(m);
|
||||
if (!dbus_connection_send(monitor->conn, m, NULL))
|
||||
return -EIO;
|
||||
}
|
||||
dbus_message_unref(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -3224,10 +3197,9 @@ static void transport_set_property_volume_reply(DBusPendingCall *pending, void *
|
|||
struct spa_bt_transport *transport = user_data;
|
||||
struct spa_bt_monitor *monitor = transport->monitor;
|
||||
DBusError err = DBUS_ERROR_INIT;
|
||||
DBusMessage *r;
|
||||
|
||||
spa_assert(transport->volume_call == pending);
|
||||
r = steal_reply_and_unref(&transport->volume_call);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&transport->volume_call);
|
||||
|
||||
if (dbus_set_error_from_message(&err, r)) {
|
||||
spa_log_info(monitor->log, "transport %p: set volume failed for transport %s: %s",
|
||||
|
|
@ -3237,14 +3209,12 @@ static void transport_set_property_volume_reply(DBusPendingCall *pending, void *
|
|||
spa_log_debug(monitor->log, "transport %p: set volume complete",
|
||||
transport);
|
||||
}
|
||||
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static void transport_set_property_volume(struct spa_bt_transport *transport, uint16_t value)
|
||||
{
|
||||
struct spa_bt_monitor *monitor = transport->monitor;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
DBusMessageIter it[2];
|
||||
const char *interface = BLUEZ_MEDIA_TRANSPORT_INTERFACE;
|
||||
const char *name = "Volume";
|
||||
|
|
@ -3271,8 +3241,6 @@ static void transport_set_property_volume(struct spa_bt_transport *transport, ui
|
|||
dbus_message_iter_close_container(&it[0], &it[1]);
|
||||
|
||||
ret = dbus_connection_send_with_reply(monitor->conn, m, &transport->volume_call, -1);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (!ret || !transport->volume_call) {
|
||||
res = -EIO;
|
||||
goto fail;
|
||||
|
|
@ -3374,11 +3342,10 @@ static void transport_acquire_reply(DBusPendingCall *pending, void *user_data)
|
|||
struct spa_bt_device *device = transport->device;
|
||||
int ret = 0;
|
||||
DBusError err;
|
||||
DBusMessage *r;
|
||||
struct spa_bt_transport *t, *t_linked;
|
||||
|
||||
spa_assert(transport->acquire_call == pending);
|
||||
r = steal_reply_and_unref(&transport->acquire_call);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&transport->acquire_call);
|
||||
|
||||
spa_bt_device_update_last_bluez_action_time(device);
|
||||
|
||||
|
|
@ -3418,8 +3385,6 @@ static void transport_acquire_reply(DBusPendingCall *pending, void *user_data)
|
|||
transport_sync_volume(transport);
|
||||
|
||||
finish:
|
||||
if (r)
|
||||
dbus_message_unref(r);
|
||||
if (ret < 0)
|
||||
spa_bt_transport_set_state(transport, SPA_BT_TRANSPORT_STATE_ERROR);
|
||||
else {
|
||||
|
|
@ -3479,7 +3444,7 @@ finish:
|
|||
static int do_transport_acquire(struct spa_bt_transport *transport)
|
||||
{
|
||||
struct spa_bt_monitor *monitor = transport->monitor;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
dbus_bool_t ret;
|
||||
struct spa_bt_transport *t_linked;
|
||||
|
||||
|
|
@ -3506,8 +3471,6 @@ static int do_transport_acquire(struct spa_bt_transport *transport)
|
|||
return -ENOMEM;
|
||||
|
||||
ret = dbus_connection_send_with_reply(monitor->conn, m, &transport->acquire_call, -1);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (!ret || transport->acquire_call == NULL)
|
||||
return -EIO;
|
||||
|
||||
|
|
@ -3573,10 +3536,9 @@ static int transport_acquire(void *data, bool optional)
|
|||
static int do_transport_release(struct spa_bt_transport *transport)
|
||||
{
|
||||
struct spa_bt_monitor *monitor = transport->monitor;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
struct spa_bt_transport *t_linked;
|
||||
bool is_idle = (transport->state == SPA_BT_TRANSPORT_STATE_IDLE);
|
||||
DBusMessage *r;
|
||||
DBusError err;
|
||||
bool linked = false;
|
||||
|
||||
|
|
@ -3627,8 +3589,6 @@ static int do_transport_release(struct spa_bt_transport *transport)
|
|||
|
||||
dbus_error_init(&err);
|
||||
r = dbus_connection_send_with_reply_and_block(monitor->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (r == NULL) {
|
||||
if (is_idle) {
|
||||
/* XXX: The fd always needs to be closed. However, Release()
|
||||
|
|
@ -3645,7 +3605,6 @@ static int do_transport_release(struct spa_bt_transport *transport)
|
|||
dbus_error_free(&err);
|
||||
} else {
|
||||
spa_log_info(monitor->log, "Transport %s released", transport->path);
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -3749,7 +3708,7 @@ static bool media_codec_switch_process_current(struct spa_bt_media_codec_switch
|
|||
char *local_endpoint = NULL;
|
||||
int res, config_size;
|
||||
dbus_bool_t dbus_ret;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
DBusMessageIter iter, d;
|
||||
int i;
|
||||
bool sink;
|
||||
|
|
@ -3849,16 +3808,12 @@ static bool media_codec_switch_process_current(struct spa_bt_media_codec_switch
|
|||
|
||||
spa_assert(sw->pending == NULL);
|
||||
dbus_ret = dbus_connection_send_with_reply(sw->device->monitor->conn, m, &sw->pending, -1);
|
||||
|
||||
if (!dbus_ret || sw->pending == NULL) {
|
||||
spa_log_error(sw->device->monitor->log, "media codec switch %p: dbus call failure, try next", sw);
|
||||
dbus_message_unref(m);
|
||||
goto next;
|
||||
}
|
||||
|
||||
dbus_ret = dbus_pending_call_set_notify(sw->pending, media_codec_switch_reply, sw, NULL);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (!dbus_ret) {
|
||||
spa_log_error(sw->device->monitor->log, "media codec switch %p: dbus set notify failure", sw);
|
||||
goto next;
|
||||
|
|
@ -3957,18 +3912,14 @@ static void media_codec_switch_reply(DBusPendingCall *pending, void *user_data)
|
|||
{
|
||||
struct spa_bt_media_codec_switch *sw = user_data;
|
||||
struct spa_bt_device *device = sw->device;
|
||||
DBusMessage *r;
|
||||
|
||||
spa_assert(sw->pending == pending);
|
||||
r = steal_reply_and_unref(&sw->pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&sw->pending);
|
||||
|
||||
spa_bt_device_update_last_bluez_action_time(device);
|
||||
|
||||
if (!media_codec_switch_goto_active(sw)) {
|
||||
if (r != NULL)
|
||||
dbus_message_unref(r);
|
||||
if (!media_codec_switch_goto_active(sw))
|
||||
return;
|
||||
}
|
||||
|
||||
if (r == NULL) {
|
||||
spa_log_error(sw->device->monitor->log,
|
||||
|
|
@ -3981,12 +3932,9 @@ static void media_codec_switch_reply(DBusPendingCall *pending, void *user_data)
|
|||
spa_log_debug(sw->device->monitor->log,
|
||||
"media codec switch %p: failed (%s), trying next",
|
||||
sw, dbus_message_get_error_name(r));
|
||||
dbus_message_unref(r);
|
||||
goto next;
|
||||
}
|
||||
|
||||
dbus_message_unref(r);
|
||||
|
||||
/* Success */
|
||||
spa_log_info(sw->device->monitor->log, "media codec switch %p: success", sw);
|
||||
spa_bt_device_emit_codec_switched(sw->device, 0);
|
||||
|
|
@ -4218,7 +4166,7 @@ static DBusHandlerResult endpoint_set_configuration(DBusConnection *conn,
|
|||
struct spa_bt_monitor *monitor = userdata;
|
||||
const char *transport_path, *endpoint;
|
||||
DBusMessageIter it[2];
|
||||
DBusMessage *r;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
struct spa_bt_transport *transport;
|
||||
const struct media_codec *codec;
|
||||
int profile;
|
||||
|
|
@ -4327,8 +4275,6 @@ static DBusHandlerResult endpoint_set_configuration(DBusConnection *conn,
|
|||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
|
|
@ -4336,7 +4282,7 @@ static DBusHandlerResult endpoint_clear_configuration(DBusConnection *conn, DBus
|
|||
{
|
||||
struct spa_bt_monitor *monitor = userdata;
|
||||
DBusError err;
|
||||
DBusMessage *r;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
const char *transport_path;
|
||||
struct spa_bt_transport *transport;
|
||||
|
||||
|
|
@ -4369,24 +4315,13 @@ static DBusHandlerResult endpoint_clear_configuration(DBusConnection *conn, DBus
|
|||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
static DBusHandlerResult endpoint_release(DBusConnection *conn, DBusMessage *m, void *userdata)
|
||||
{
|
||||
DBusMessage *r;
|
||||
|
||||
r = dbus_message_new_error(m,
|
||||
BLUEZ_MEDIA_ENDPOINT_INTERFACE ".Error.NotImplemented",
|
||||
"Method not implemented");
|
||||
if (r == NULL)
|
||||
if (!reply_with_error(conn, m, BLUEZ_MEDIA_ENDPOINT_INTERFACE ".Error.NotImplemented", "Method not implemented"))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
if (!dbus_connection_send(conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
|
@ -4395,7 +4330,6 @@ static DBusHandlerResult endpoint_handler(DBusConnection *c, DBusMessage *m, voi
|
|||
{
|
||||
struct spa_bt_monitor *monitor = userdata;
|
||||
const char *path, *interface, *member;
|
||||
DBusMessage *r;
|
||||
DBusHandlerResult res;
|
||||
|
||||
path = dbus_message_get_path(m);
|
||||
|
|
@ -4406,6 +4340,7 @@ static DBusHandlerResult endpoint_handler(DBusConnection *c, DBusMessage *m, voi
|
|||
|
||||
if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||
const char *xml = ENDPOINT_INTROSPECT_XML;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if ((r = dbus_message_new_method_return(m)) == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
|
@ -4414,7 +4349,6 @@ static DBusHandlerResult endpoint_handler(DBusConnection *c, DBusMessage *m, voi
|
|||
if (!dbus_connection_send(monitor->conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
res = DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
else if (dbus_message_is_method_call(m, BLUEZ_MEDIA_ENDPOINT_INTERFACE, "SetConfiguration"))
|
||||
|
|
@ -4437,26 +4371,22 @@ static void bluez_register_endpoint_legacy_reply(DBusPendingCall *pending, void
|
|||
{
|
||||
struct spa_bt_adapter *adapter = user_data;
|
||||
struct spa_bt_monitor *monitor = adapter->monitor;
|
||||
DBusMessage *r;
|
||||
|
||||
r = steal_reply_and_unref(&pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_is_error(r, DBUS_ERROR_UNKNOWN_METHOD)) {
|
||||
spa_log_warn(monitor->log, "BlueZ D-Bus ObjectManager not available");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(monitor->log, "RegisterEndpoint() failed: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
adapter->legacy_endpoints_registered = true;
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static void append_basic_variant_dict_entry(DBusMessageIter *dict, const char* key, int variant_type_int, const char* variant_type_str, void* variant) {
|
||||
|
|
@ -4490,7 +4420,7 @@ static int bluez_register_endpoint_legacy(struct spa_bt_adapter *adapter,
|
|||
struct spa_bt_monitor *monitor = adapter->monitor;
|
||||
const char *path = adapter->path;
|
||||
char *object_path = NULL;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
DBusMessageIter object_it, dict_it;
|
||||
DBusPendingCall *call;
|
||||
uint8_t caps[A2DP_MAX_CAPS_SIZE];
|
||||
|
|
@ -4530,7 +4460,6 @@ static int bluez_register_endpoint_legacy(struct spa_bt_adapter *adapter,
|
|||
|
||||
dbus_connection_send_with_reply(monitor->conn, m, &call, -1);
|
||||
dbus_pending_call_set_notify(call, bluez_register_endpoint_legacy_reply, adapter, NULL);
|
||||
dbus_message_unref(m);
|
||||
|
||||
free(object_path);
|
||||
|
||||
|
|
@ -4636,7 +4565,6 @@ static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage *
|
|||
const struct media_codec * const * const media_codecs = monitor->media_codecs;
|
||||
const char *path, *interface, *member;
|
||||
char *endpoint;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter iter, array;
|
||||
DBusHandlerResult res;
|
||||
int i;
|
||||
|
|
@ -4649,6 +4577,7 @@ static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage *
|
|||
|
||||
if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||
const char *xml = OBJECT_MANAGER_INTROSPECT_XML;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if ((r = dbus_message_new_method_return(m)) == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
|
@ -4657,10 +4586,11 @@ static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage *
|
|||
if (!dbus_connection_send(monitor->conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
dbus_message_unref(r);
|
||||
res = DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
else if (dbus_message_is_method_call(m, "org.freedesktop.DBus.ObjectManager", "GetManagedObjects")) {
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if ((r = dbus_message_new_method_return(m)) == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
|
||||
|
|
@ -4735,10 +4665,9 @@ static void bluez_register_application_a2dp_reply(DBusPendingCall *pending, void
|
|||
{
|
||||
struct spa_bt_adapter *adapter = user_data;
|
||||
struct spa_bt_monitor *monitor = adapter->monitor;
|
||||
DBusMessage *r;
|
||||
bool fallback = true;
|
||||
|
||||
r = steal_reply_and_unref(&pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
|
|
@ -4757,8 +4686,6 @@ static void bluez_register_application_a2dp_reply(DBusPendingCall *pending, void
|
|||
adapter->a2dp_application_registered = true;
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
|
||||
if (fallback)
|
||||
adapter_register_endpoints_legacy(adapter);
|
||||
}
|
||||
|
|
@ -4767,22 +4694,18 @@ static void bluez_register_application_bap_reply(DBusPendingCall *pending, void
|
|||
{
|
||||
struct spa_bt_adapter *adapter = user_data;
|
||||
struct spa_bt_monitor *monitor = adapter->monitor;
|
||||
DBusMessage *r;
|
||||
|
||||
r = steal_reply_and_unref(&pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(monitor->log, "RegisterApplication() failed: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
adapter->bap_application_registered = true;
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static int register_media_endpoint(struct spa_bt_monitor *monitor,
|
||||
|
|
@ -4907,7 +4830,7 @@ static int adapter_register_application(struct spa_bt_adapter *a, bool bap)
|
|||
const char *object_manager_path = bap ? BAP_OBJECT_MANAGER_PATH : A2DP_OBJECT_MANAGER_PATH;
|
||||
struct spa_bt_monitor *monitor = a->monitor;
|
||||
const char *ep_type_name = (bap ? "LE Audio" : "A2DP");
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
DBusMessageIter i, d;
|
||||
DBusPendingCall *call;
|
||||
|
||||
|
|
@ -4947,7 +4870,6 @@ static int adapter_register_application(struct spa_bt_adapter *a, bool bap)
|
|||
dbus_pending_call_set_notify(call,
|
||||
bap ? bluez_register_application_bap_reply : bluez_register_application_a2dp_reply,
|
||||
a, NULL);
|
||||
dbus_message_unref(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -5180,29 +5102,28 @@ static void interfaces_removed(struct spa_bt_monitor *monitor, DBusMessageIter *
|
|||
static void get_managed_objects_reply(DBusPendingCall *pending, void *user_data)
|
||||
{
|
||||
struct spa_bt_monitor *monitor = user_data;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter it[6];
|
||||
|
||||
spa_assert(monitor->get_managed_objects_call == pending);
|
||||
r = steal_reply_and_unref(&monitor->get_managed_objects_call);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&monitor->get_managed_objects_call);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_is_error(r, DBUS_ERROR_UNKNOWN_METHOD)) {
|
||||
spa_log_warn(monitor->log, "BlueZ D-Bus ObjectManager not available");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(monitor->log, "GetManagedObjects() failed: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_init(r, &it[0]) ||
|
||||
!spa_streq(dbus_message_get_signature(r), "a{oa{sa{sv}}}")) {
|
||||
spa_log_error(monitor->log, "Invalid reply signature for GetManagedObjects()");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&it[0], &it[1]);
|
||||
|
|
@ -5218,10 +5139,6 @@ static void get_managed_objects_reply(DBusPendingCall *pending, void *user_data)
|
|||
reselect_backend(monitor, false);
|
||||
|
||||
monitor->objects_listed = true;
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
return;
|
||||
}
|
||||
|
||||
static void get_managed_objects(struct spa_bt_monitor *monitor)
|
||||
|
|
@ -5229,7 +5146,7 @@ static void get_managed_objects(struct spa_bt_monitor *monitor)
|
|||
if (monitor->objects_listed || monitor->get_managed_objects_call)
|
||||
return;
|
||||
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
DBusPendingCall *call;
|
||||
|
||||
m = dbus_message_new_method_call(BLUEZ_SERVICE,
|
||||
|
|
@ -5241,7 +5158,6 @@ static void get_managed_objects(struct spa_bt_monitor *monitor)
|
|||
|
||||
dbus_connection_send_with_reply(monitor->conn, m, &call, -1);
|
||||
dbus_pending_call_set_notify(call, get_managed_objects_reply, monitor, NULL);
|
||||
dbus_message_unref(m);
|
||||
|
||||
monitor->get_managed_objects_call = call;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef SPA_BLUEZ5_DBUS_HELPERS_H
|
||||
#define SPA_BLUEZ5_DBUS_HELPERS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include <spa/utils/cleanup.h>
|
||||
|
|
@ -29,4 +31,17 @@ static inline DBusMessage *steal_reply_and_unref(DBusPendingCall **pp)
|
|||
return reply;
|
||||
}
|
||||
|
||||
SPA_DEFINE_AUTOPTR_CLEANUP(DBusMessage, DBusMessage, {
|
||||
spa_clear_ptr(*thing, dbus_message_unref);
|
||||
})
|
||||
|
||||
static inline bool reply_with_error(DBusConnection *conn,
|
||||
DBusMessage *reply_to,
|
||||
const char *error_name, const char *error_message)
|
||||
{
|
||||
spa_autoptr(DBusMessage) reply = dbus_message_new_error(reply_to, error_name, error_message);
|
||||
|
||||
return reply && dbus_connection_send(conn, reply, NULL);
|
||||
}
|
||||
|
||||
#endif /* SPA_BLUEZ5_DBUS_HELPERS_H */
|
||||
|
|
|
|||
|
|
@ -46,27 +46,22 @@ static bool mm_dbus_connection_send_with_reply(struct impl *this, DBusMessage *m
|
|||
spa_assert(*pending_return == NULL);
|
||||
|
||||
DBusPendingCall *pending_call;
|
||||
bool ret = dbus_connection_send_with_reply(this->conn, m, &pending_call, -1);
|
||||
if (!ret) {
|
||||
if (!dbus_connection_send_with_reply(this->conn, m, &pending_call, -1)) {
|
||||
spa_log_debug(this->log, "dbus call failure");
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
spa_assert(pending_call);
|
||||
|
||||
ret = dbus_pending_call_set_notify(pending_call, function, user_data, NULL);
|
||||
if (!ret) {
|
||||
if (!dbus_pending_call_set_notify(pending_call, function, user_data, NULL)) {
|
||||
spa_log_debug(this->log, "dbus set notify failure");
|
||||
cancel_and_unref(&pending_call);
|
||||
goto out;
|
||||
return false;
|
||||
}
|
||||
|
||||
*pending_return = pending_call;
|
||||
|
||||
out:
|
||||
dbus_message_unref(m);
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int mm_state_to_clcc(struct impl *this, MMCallState state)
|
||||
|
|
@ -119,28 +114,27 @@ static void mm_get_call_properties_reply(DBusPendingCall *pending, void *user_da
|
|||
{
|
||||
struct call *call = user_data;
|
||||
struct impl *this = call->this;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter arg_i, element_i;
|
||||
MMCallDirection direction;
|
||||
MMCallState state;
|
||||
|
||||
spa_assert(call->pending == pending);
|
||||
r = steal_reply_and_unref(&call->pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&call->pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_is_error(r, DBUS_ERROR_UNKNOWN_METHOD)) {
|
||||
spa_log_warn(this->log, "ModemManager D-Bus Call not available");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(this->log, "GetAll() failed: %s", dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_init(r, &arg_i) || !spa_streq(dbus_message_get_signature(r), "a{sv}")) {
|
||||
spa_log_error(this->log, "Invalid arguments in GetAll() reply");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
spa_log_debug(this->log, "Call path: %s", call->path);
|
||||
|
|
@ -184,9 +178,6 @@ static void mm_get_call_properties_reply(DBusPendingCall *pending, void *user_da
|
|||
|
||||
dbus_message_iter_next(&element_i);
|
||||
}
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static DBusHandlerResult mm_parse_voice_properties(struct impl *this, DBusMessageIter *props_i)
|
||||
|
|
@ -417,23 +408,22 @@ next:
|
|||
static void mm_get_managed_objects_reply(DBusPendingCall *pending, void *user_data)
|
||||
{
|
||||
struct impl *this = user_data;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter i, array_i;
|
||||
|
||||
spa_assert(this->pending == pending);
|
||||
r = steal_reply_and_unref(&this->pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&this->pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(this->log, "Failed to get a list of endpoints from ModemManager: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_init(r, &i) || !spa_streq(dbus_message_get_signature(r), "a{oa{sa{sv}}}")) {
|
||||
spa_log_error(this->log, "Invalid arguments in GetManagedObjects() reply");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&i, &array_i);
|
||||
|
|
@ -444,9 +434,6 @@ static void mm_get_managed_objects_reply(DBusPendingCall *pending, void *user_da
|
|||
mm_parse_interfaces(this, &dict_i);
|
||||
dbus_message_iter_next(&array_i);
|
||||
}
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static void call_free(struct call *call)
|
||||
|
|
@ -609,6 +596,7 @@ static DBusHandlerResult mm_filter_cb(DBusConnection *bus, DBusMessage *m, void
|
|||
const char *path;
|
||||
struct call *call_object;
|
||||
const char *mm_call_interface = MM_DBUS_INTERFACE_CALL;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
|
||||
if (!spa_streq(this->modem.path, dbus_message_get_path(m)))
|
||||
goto finish;
|
||||
|
|
@ -771,12 +759,11 @@ static void mm_get_call_simple_reply(DBusPendingCall *pending, void *data)
|
|||
struct impl *this = dbus_cmd_data->this;
|
||||
struct call *call = dbus_cmd_data->call;
|
||||
void *user_data = dbus_cmd_data->user_data;
|
||||
DBusMessage *r;
|
||||
|
||||
free(data);
|
||||
|
||||
spa_assert(call->pending == pending);
|
||||
r = steal_reply_and_unref(&call->pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&call->pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
|
|
@ -801,12 +788,11 @@ static void mm_get_call_create_reply(DBusPendingCall *pending, void *data)
|
|||
struct dbus_cmd_data *dbus_cmd_data = data;
|
||||
struct impl *this = dbus_cmd_data->this;
|
||||
void *user_data = dbus_cmd_data->user_data;
|
||||
DBusMessage *r;
|
||||
|
||||
free(data);
|
||||
|
||||
spa_assert(this->voice_pending == pending);
|
||||
r = steal_reply_and_unref(&this->voice_pending);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&this->voice_pending);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
|
|
@ -831,7 +817,7 @@ bool mm_answer_call(void *modemmanager, void *user_data, enum cmee_error *error)
|
|||
struct impl *this = modemmanager;
|
||||
struct call *call_object, *call_tmp;
|
||||
struct dbus_cmd_data *data;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
|
||||
call_object = NULL;
|
||||
spa_list_for_each(call_tmp, &this->call_list, link) {
|
||||
|
|
@ -877,8 +863,8 @@ bool mm_hangup_call(void *modemmanager, void *user_data, enum cmee_error *error)
|
|||
{
|
||||
struct impl *this = modemmanager;
|
||||
struct call *call_object, *call_tmp;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
struct dbus_cmd_data *data;
|
||||
DBusMessage *m;
|
||||
|
||||
call_object = NULL;
|
||||
spa_list_for_each(call_tmp, &this->call_list, link) {
|
||||
|
|
@ -954,7 +940,7 @@ bool mm_do_call(void *modemmanager, const char* number, void *user_data, enum cm
|
|||
{
|
||||
struct impl *this = modemmanager;
|
||||
struct dbus_cmd_data *data;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
DBusMessageIter iter, dict;
|
||||
|
||||
for (size_t i = 0; number[i]; i++) {
|
||||
|
|
@ -1000,7 +986,7 @@ bool mm_send_dtmf(void *modemmanager, const char *dtmf, void *user_data, enum cm
|
|||
struct impl *this = modemmanager;
|
||||
struct call *call_object, *call_tmp;
|
||||
struct dbus_cmd_data *data;
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
|
||||
call_object = NULL;
|
||||
spa_list_for_each(call_tmp, &this->call_list, link) {
|
||||
|
|
@ -1084,7 +1070,6 @@ struct spa_list *mm_get_calls(void *modemmanager)
|
|||
void *mm_register(struct spa_log *log, void *dbus_connection, const struct spa_dict *info,
|
||||
const struct mm_ops *ops, void *user_data)
|
||||
{
|
||||
struct impl *this;
|
||||
const char *modem_device_str = NULL;
|
||||
bool modem_device_found = false;
|
||||
|
||||
|
|
@ -1102,7 +1087,7 @@ void *mm_register(struct spa_log *log, void *dbus_connection, const struct spa_d
|
|||
return NULL;
|
||||
}
|
||||
|
||||
this = calloc(1, sizeof(struct impl));
|
||||
spa_autofree struct impl *this = calloc(1, sizeof(*this));
|
||||
if (this == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1114,27 +1099,24 @@ void *mm_register(struct spa_log *log, void *dbus_connection, const struct spa_d
|
|||
this->allowed_modem_device = strdup(modem_device_str);
|
||||
spa_list_init(&this->call_list);
|
||||
|
||||
if (add_filters(this) < 0) {
|
||||
goto fail;
|
||||
}
|
||||
if (add_filters(this) < 0)
|
||||
return NULL;
|
||||
|
||||
DBusMessage *m = dbus_message_new_method_call(MM_DBUS_SERVICE, "/org/freedesktop/ModemManager1",
|
||||
DBUS_INTERFACE_OBJECTMANAGER, "GetManagedObjects");
|
||||
spa_autoptr(DBusMessage) m = dbus_message_new_method_call(MM_DBUS_SERVICE,
|
||||
"/org/freedesktop/ModemManager1",
|
||||
DBUS_INTERFACE_OBJECTMANAGER,
|
||||
"GetManagedObjects");
|
||||
if (m == NULL)
|
||||
goto fail;
|
||||
return NULL;
|
||||
|
||||
dbus_message_set_auto_start(m, false);
|
||||
|
||||
if (!mm_dbus_connection_send_with_reply(this, m, &this->pending, mm_get_managed_objects_reply, this)) {
|
||||
spa_log_error(this->log, "dbus call failure");
|
||||
goto fail;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
fail:
|
||||
free(this);
|
||||
return NULL;
|
||||
return spa_steal_ptr(this);
|
||||
}
|
||||
|
||||
void mm_unregister(void *data)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <spa/utils/string.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "dbus-helpers.h"
|
||||
#include "player.h"
|
||||
|
||||
#define PLAYER_OBJECT_PATH_BASE "/media_player"
|
||||
|
|
@ -167,18 +168,18 @@ static DBusMessage *properties_set(struct impl *impl, DBusMessage *m)
|
|||
static DBusMessage *introspect(struct impl *impl, DBusMessage *m)
|
||||
{
|
||||
const char *xml = PLAYER_INTROSPECT_XML;
|
||||
DBusMessage *r;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
if ((r = dbus_message_new_method_return(m)) == NULL)
|
||||
return NULL;
|
||||
if (!dbus_message_append_args(r, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID))
|
||||
return NULL;
|
||||
return r;
|
||||
return spa_steal_ptr(r);
|
||||
}
|
||||
|
||||
static DBusHandlerResult player_handler(DBusConnection *c, DBusMessage *m, void *userdata)
|
||||
{
|
||||
struct impl *impl = userdata;
|
||||
DBusMessage *r;
|
||||
spa_autoptr(DBusMessage) r = NULL;
|
||||
|
||||
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) {
|
||||
r = introspect(impl, m);
|
||||
|
|
@ -194,20 +195,16 @@ static DBusHandlerResult player_handler(DBusConnection *c, DBusMessage *m, void
|
|||
|
||||
if (r == NULL)
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
if (!dbus_connection_send(impl->conn, r, NULL)) {
|
||||
dbus_message_unref(r);
|
||||
if (!dbus_connection_send(impl->conn, r, NULL))
|
||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||
}
|
||||
dbus_message_unref(r);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
static int send_update_signal(struct impl *impl)
|
||||
{
|
||||
DBusMessage *m;
|
||||
spa_autoptr(DBusMessage) m = NULL;
|
||||
const char *iface = PLAYER_INTERFACE;
|
||||
DBusMessageIter i, a;
|
||||
int res = 0;
|
||||
|
||||
m = dbus_message_new_signal(impl->path, DBUS_INTERFACE_PROPERTIES, "PropertiesChanged");
|
||||
if (m == NULL)
|
||||
|
|
@ -223,11 +220,9 @@ static int send_update_signal(struct impl *impl)
|
|||
dbus_message_iter_close_container(&i, &a);
|
||||
|
||||
if (!dbus_connection_send(impl->conn, m, NULL))
|
||||
res = -EIO;
|
||||
return -EIO;
|
||||
|
||||
dbus_message_unref(m);
|
||||
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void update_properties(struct impl *impl, bool send_signal)
|
||||
|
|
@ -332,8 +327,7 @@ int spa_bt_player_register(struct spa_bt_player *player, const char *adapter_pat
|
|||
|
||||
DBusError err;
|
||||
DBusMessageIter i;
|
||||
DBusMessage *m, *r;
|
||||
int res = 0;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
|
||||
spa_log_debug(impl->log, "RegisterPlayer() for dummy AVRCP player %s for %s",
|
||||
impl->path, adapter_path);
|
||||
|
|
@ -349,8 +343,6 @@ int spa_bt_player_register(struct spa_bt_player *player, const char *adapter_pat
|
|||
|
||||
dbus_error_init(&err);
|
||||
r = dbus_connection_send_with_reply_and_block(impl->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (r == NULL) {
|
||||
spa_log_error(impl->log, "RegisterPlayer() failed (%s)", err.message);
|
||||
dbus_error_free(&err);
|
||||
|
|
@ -359,12 +351,10 @@ int spa_bt_player_register(struct spa_bt_player *player, const char *adapter_pat
|
|||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(impl->log, "RegisterPlayer() failed");
|
||||
res = -EIO;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
dbus_message_unref(r);
|
||||
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int spa_bt_player_unregister(struct spa_bt_player *player, const char *adapter_path)
|
||||
|
|
@ -373,8 +363,7 @@ int spa_bt_player_unregister(struct spa_bt_player *player, const char *adapter_p
|
|||
|
||||
DBusError err;
|
||||
DBusMessageIter i;
|
||||
DBusMessage *m, *r;
|
||||
int res = 0;
|
||||
spa_autoptr(DBusMessage) m = NULL, r = NULL;
|
||||
|
||||
spa_log_debug(impl->log, "UnregisterPlayer() for dummy AVRCP player %s for %s",
|
||||
impl->path, adapter_path);
|
||||
|
|
@ -389,8 +378,6 @@ int spa_bt_player_unregister(struct spa_bt_player *player, const char *adapter_p
|
|||
|
||||
dbus_error_init(&err);
|
||||
r = dbus_connection_send_with_reply_and_block(impl->conn, m, -1, &err);
|
||||
dbus_message_unref(m);
|
||||
|
||||
if (r == NULL) {
|
||||
spa_log_error(impl->log, "UnregisterPlayer() failed (%s)", err.message);
|
||||
dbus_error_free(&err);
|
||||
|
|
@ -399,10 +386,8 @@ int spa_bt_player_unregister(struct spa_bt_player *player, const char *adapter_p
|
|||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(impl->log, "UnregisterPlayer() failed");
|
||||
res = -EIO;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
dbus_message_unref(r);
|
||||
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,40 +43,36 @@ static DBusHandlerResult upower_parse_percentage(struct impl *this, DBusMessageI
|
|||
static void upower_get_percentage_properties_reply(DBusPendingCall *pending, void *user_data)
|
||||
{
|
||||
struct impl *backend = user_data;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter i, variant_i;
|
||||
|
||||
spa_assert(backend->pending_get_call == pending);
|
||||
r = steal_reply_and_unref(&backend->pending_get_call);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&backend->pending_get_call);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(backend->log, "Failed to get percentage from UPower: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_init(r, &i) || !spa_streq(dbus_message_get_signature(r), "v")) {
|
||||
spa_log_error(backend->log, "Invalid arguments in Get() reply");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&i, &variant_i);
|
||||
upower_parse_percentage(backend, &variant_i);
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static int update_battery_percentage(struct impl *this)
|
||||
{
|
||||
cancel_and_unref(&this->pending_get_call);
|
||||
|
||||
DBusMessage *m = dbus_message_new_method_call(UPOWER_SERVICE,
|
||||
UPOWER_DISPLAY_DEVICE_OBJECT,
|
||||
DBUS_INTERFACE_PROPERTIES,
|
||||
"Get");
|
||||
spa_autoptr(DBusMessage) m = dbus_message_new_method_call(UPOWER_SERVICE,
|
||||
UPOWER_DISPLAY_DEVICE_OBJECT,
|
||||
DBUS_INTERFACE_PROPERTIES,
|
||||
"Get");
|
||||
if (!m)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
@ -89,8 +85,6 @@ static int update_battery_percentage(struct impl *this)
|
|||
dbus_connection_send_with_reply(this->conn, m, &this->pending_get_call, -1);
|
||||
dbus_pending_call_set_notify(this->pending_get_call, upower_get_percentage_properties_reply, this, NULL);
|
||||
|
||||
dbus_message_unref(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue