summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-06-02 14:34:58 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-06-02 14:34:58 +0000
commitb6029c0ffd7facd5f41bd665c84043d08961847d (patch)
tree76de65ffbf222a3f080a5e79c301639761b5ab99 /audio
parent08e3720b8860a0aef687e841533bd30ee22cc534 (diff)
Make audio service to use libgdbus functions.
Diffstat (limited to 'audio')
-rw-r--r--audio/control.c22
-rw-r--r--audio/device.c53
-rw-r--r--audio/headset.c303
-rw-r--r--audio/manager.c189
-rw-r--r--audio/sink.c69
5 files changed, 302 insertions, 334 deletions
diff --git a/audio/control.c b/audio/control.c
index b10fb1dd..c9663a26 100644
--- a/audio/control.c
+++ b/audio/control.c
@@ -920,7 +920,7 @@ void avrcp_exit(void)
connection = NULL;
}
-static DBusHandlerResult control_is_connected(DBusConnection *conn,
+static DBusMessage *control_is_connected(DBusConnection *conn,
DBusMessage *msg,
void *data)
{
@@ -931,24 +931,22 @@ static DBusHandlerResult control_is_connected(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
connected = (control->session != NULL);
dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &connected,
DBUS_TYPE_INVALID);
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusMethodVTable control_methods[] = {
- { "IsConnected", control_is_connected, "", "b" },
+static GDBusMethodTable control_methods[] = {
+ { "IsConnected", "", "b", control_is_connected },
{ NULL, NULL, NULL, NULL }
};
-static DBusSignalVTable control_signals[] = {
+static GDBusSignalTable control_signals[] = {
{ "Connected", "" },
{ "Disconnected", "" },
{ NULL, NULL }
@@ -956,10 +954,10 @@ static DBusSignalVTable control_signals[] = {
struct control *control_init(struct audio_device *dev)
{
- if (!dbus_connection_register_interface(dev->conn, dev->path,
- AUDIO_CONTROL_INTERFACE,
- control_methods,
- control_signals, NULL))
+ if (!g_dbus_register_interface(dev->conn, dev->path,
+ AUDIO_CONTROL_INTERFACE,
+ control_methods, control_signals, NULL,
+ dev, NULL))
return NULL;
return g_new0(struct control, 1);
diff --git a/audio/device.c b/audio/device.c
index 6b8c5318..c9608b96 100644
--- a/audio/device.c
+++ b/audio/device.c
@@ -54,7 +54,7 @@
#include "headset.h"
#include "sink.h"
-static DBusHandlerResult device_get_address(DBusConnection *conn,
+static DBusMessage *device_get_address(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct audio_device *device = data;
@@ -63,14 +63,14 @@ static DBusHandlerResult device_get_address(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
ba2str(&device->dst, address);
dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr,
DBUS_TYPE_INVALID);
- return send_message_and_unref(conn, reply);
+ return reply;
}
static char *get_dev_name(DBusConnection *conn, const bdaddr_t *src,
@@ -87,7 +87,7 @@ static char *get_dev_name(DBusConnection *conn, const bdaddr_t *src,
return textfile_caseget(filename, address);
}
-static DBusHandlerResult device_get_name(DBusConnection *conn,
+static DBusMessage *device_get_name(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct audio_device *dev = data;
@@ -96,15 +96,15 @@ static DBusHandlerResult device_get_name(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
dbus_message_append_args(reply, DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID);
- return send_message_and_unref(conn, reply);
+ return reply;
}
-static DBusHandlerResult device_get_adapter(DBusConnection *conn,
+static DBusMessage *device_get_adapter(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct audio_device *device = data;
@@ -113,18 +113,18 @@ static DBusHandlerResult device_get_adapter(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
ba2str(&device->src, address);
dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr,
DBUS_TYPE_INVALID);
- return send_message_and_unref(conn, reply);
+ return reply;
}
-static DBusHandlerResult device_get_connected(DBusConnection *conn,
+static DBusMessage *device_get_connected(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessageIter iter, array_iter;
@@ -134,7 +134,7 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
dbus_message_iter_init_append(reply, &iter);
@@ -151,15 +151,15 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn,
dbus_message_iter_close_container(&iter, &array_iter);
- return send_message_and_unref(conn, reply);
+ return reply;
}
-static DBusMethodVTable device_methods[] = {
- { "GetAddress", device_get_address, "", "s" },
- { "GetName", device_get_name, "", "s" },
- { "GetAdapter", device_get_adapter, "", "s" },
- { "GetConnectedInterfaces", device_get_connected, "", "as" },
- { NULL, NULL, NULL, NULL }
+static GDBusMethodTable device_methods[] = {
+ { "GetAddress", "", "s", device_get_address },
+ { "GetName", "", "s", device_get_name },
+ { "GetAdapter", "", "s", device_get_adapter },
+ { "GetConnectedInterfaces", "", "as", device_get_connected },
+ { }
};
static void device_free(struct audio_device *dev)
@@ -183,7 +183,7 @@ static void device_free(struct audio_device *dev)
g_free(dev);
}
-static void device_unregister(DBusConnection *conn, void *data)
+static void device_unregister(void *data)
{
struct audio_device *device = data;
@@ -216,18 +216,13 @@ struct audio_device *device_register(DBusConnection *conn,
return NULL;
}
- if (!dbus_connection_create_object_path(conn, path, dev,
- device_unregister)) {
- error("D-Bus failed to register %s path", path);
- device_free(dev);
- return NULL;
- }
-
- if (!dbus_connection_register_interface(conn, path,
- AUDIO_DEVICE_INTERFACE, device_methods, NULL, NULL)) {
+ if (!g_dbus_register_interface(conn, path,
+ AUDIO_DEVICE_INTERFACE,
+ device_methods, NULL, NULL,
+ dev, device_unregister)) {
error("Failed to register %s interface to %s",
AUDIO_DEVICE_INTERFACE, path);
- dbus_connection_destroy_object_path(conn, path);
+ device_free(dev);
return NULL;
}
diff --git a/audio/headset.c b/audio/headset.c
index 69b89a77..1cdaf746 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -887,7 +887,7 @@ static int rfcomm_connect(struct audio_device *dev, headset_stream_cb_t cb,
return 0;
}
-static DBusHandlerResult hs_stop(DBusConnection *conn, DBusMessage *msg,
+static DBusMessage *hs_stop(DBusConnection *conn, DBusMessage *msg,
void *data)
{
struct audio_device *device = data;
@@ -895,19 +895,20 @@ static DBusHandlerResult hs_stop(DBusConnection *conn, DBusMessage *msg,
DBusMessage *reply = NULL;
if (hs->state < HEADSET_STATE_PLAY_IN_PROGRESS)
- return error_not_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
headset_set_state(device, HEADSET_STATE_CONNECTED);
- send_message_and_unref(conn, reply);
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_is_playing(DBusConnection *conn, DBusMessage *msg,
+static DBusMessage *hs_is_playing(DBusConnection *conn, DBusMessage *msg,
void *data)
{
struct audio_device *device = data;
@@ -917,19 +918,17 @@ static DBusHandlerResult hs_is_playing(DBusConnection *conn, DBusMessage *msg,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
playing = (hs->state == HEADSET_STATE_PLAYING);
dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &playing,
DBUS_TYPE_INVALID);
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_disconnect(DBusConnection *conn, DBusMessage *msg,
+static DBusMessage *hs_disconnect(DBusConnection *conn, DBusMessage *msg,
void *data)
{
struct audio_device *device = data;
@@ -939,21 +938,21 @@ static DBusHandlerResult hs_disconnect(DBusConnection *conn, DBusMessage *msg,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
if (hs->state == HEADSET_STATE_DISCONNECTED)
- return error_not_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
headset_set_state(device, HEADSET_STATE_DISCONNECTED);
ba2str(&device->dst, hs_address);
info("Disconnected from %s, %s", hs_address, device->path);
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_is_connected(DBusConnection *conn,
+static DBusMessage *hs_is_connected(DBusConnection *conn,
DBusMessage *msg,
void *data)
{
@@ -963,19 +962,17 @@ static DBusHandlerResult hs_is_connected(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
connected = (device->headset->state >= HEADSET_STATE_CONNECTED);
dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &connected,
DBUS_TYPE_INVALID);
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_connect(DBusConnection *conn, DBusMessage *msg,
+static DBusMessage *hs_connect(DBusConnection *conn, DBusMessage *msg,
void *data)
{
struct audio_device *device = data;
@@ -983,19 +980,24 @@ static DBusHandlerResult hs_connect(DBusConnection *conn, DBusMessage *msg,
int err;
if (hs->state == HEADSET_STATE_CONNECT_IN_PROGRESS)
- return error_in_progress(conn, msg, "Connect in progress");
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".InProgress",
+ "Connect in Progress");
else if (hs->state > HEADSET_STATE_CONNECT_IN_PROGRESS)
- return error_already_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".AlreadyConnected",
+ "Already Connected");
err = rfcomm_connect(device, NULL, NULL, NULL);
if (err < 0)
- return error_connection_attempt_failed(conn, msg, -err);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".ConnectAttemptFailed",
+ "Connect Attempt Failed");
hs->auto_dc = FALSE;
hs->pending->msg = dbus_message_ref(msg);
- return DBUS_HANDLER_RESULT_HANDLED;
+ return NULL;
}
static gboolean ring_timer_cb(gpointer data)
@@ -1022,7 +1024,7 @@ static gboolean ring_timer_cb(gpointer data)
return TRUE;
}
-static DBusHandlerResult hs_ring(DBusConnection *conn, DBusMessage *msg,
+static DBusMessage *hs_ring(DBusConnection *conn, DBusMessage *msg,
void *data)
{
struct audio_device *device = data;
@@ -1031,11 +1033,13 @@ static DBusHandlerResult hs_ring(DBusConnection *conn, DBusMessage *msg,
int err;
if (hs->state < HEADSET_STATE_CONNECTED)
- return error_not_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
if (hs->ring_timer) {
debug("IndicateCall received when already indicating");
@@ -1045,7 +1049,8 @@ static DBusHandlerResult hs_ring(DBusConnection *conn, DBusMessage *msg,
err = headset_send(hs, "\r\nRING\r\n");
if (err < 0) {
dbus_message_unref(reply);
- return error_failed_errno(conn, msg, -err);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", strerror(-err));
}
if (hs->cli_active && hs->ph_number) {
@@ -1053,32 +1058,34 @@ static DBusHandlerResult hs_ring(DBusConnection *conn, DBusMessage *msg,
hs->ph_number, hs->type);
if (err < 0) {
dbus_message_unref(reply);
- return error_failed_errno(conn, msg, -err);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".Failed", "%s",
+ strerror(-err));
}
}
hs->ring_timer = g_timeout_add(RING_INTERVAL, ring_timer_cb, device);
done:
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_cancel_ringing(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *hs_cancel_ringing(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
struct audio_device *device = data;
struct headset *hs = device->headset;
DBusMessage *reply = NULL;
if (hs->state < HEADSET_STATE_CONNECTED)
- return error_not_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
if (!hs->ring_timer) {
debug("Got CancelRinging method call but ringing is not in progress");
@@ -1095,17 +1102,17 @@ done:
err = headset_send(hs, "\r\n+CIEV:3,0\r\n");
if (err < 0) {
dbus_message_unref(reply);
- return error_failed_errno(conn, msg, -err);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".Failed", "%s",
+ strerror(-err));
}
}
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_play(DBusConnection *conn, DBusMessage *msg,
- void *data)
+static DBusMessage *hs_play(DBusConnection *conn, DBusMessage *msg,
+ void *data)
{
struct audio_device *device = data;
struct headset *hs = device->headset;
@@ -1114,17 +1121,24 @@ static DBusHandlerResult hs_play(DBusConnection *conn, DBusMessage *msg,
if (sco_hci) {
error("Refusing Headset.Play() because SCO HCI routing "
"is enabled");
- return error_not_available(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAvailable",
+ "Operation not Available");
}
switch (hs->state) {
case HEADSET_STATE_DISCONNECTED:
case HEADSET_STATE_CONNECT_IN_PROGRESS:
- return error_not_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
case HEADSET_STATE_PLAY_IN_PROGRESS:
- return error_in_progress(conn, msg, "Play in progress");
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".InProgress",
+ "Play in Progress");
case HEADSET_STATE_PLAYING:
- return error_already_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".AlreadyConnected",
+ "Device Already Connected");
case HEADSET_STATE_CONNECTED:
default:
break;
@@ -1132,16 +1146,17 @@ static DBusHandlerResult hs_play(DBusConnection *conn, DBusMessage *msg,
err = sco_connect(device, NULL, NULL, NULL);
if (err < 0)
- return error_failed(conn, msg, strerror(-err));
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", strerror(-err));
hs->pending->msg = dbus_message_ref(msg);
- return DBUS_HANDLER_RESULT_HANDLED;
+ return NULL;
}
-static DBusHandlerResult hs_get_speaker_gain(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *hs_get_speaker_gain(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
struct audio_device *device = data;
struct headset *hs = device->headset;
@@ -1149,25 +1164,24 @@ static DBusHandlerResult hs_get_speaker_gain(DBusConnection *conn,
dbus_uint16_t gain;
if (hs->state < HEADSET_STATE_CONNECTED || hs->sp_gain < 0)
- return error_not_available(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAvailable",
+ "Operation not Available");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
gain = (dbus_uint16_t) hs->sp_gain;
dbus_message_append_args(reply, DBUS_TYPE_UINT16, &gain,
DBUS_TYPE_INVALID);
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_get_mic_gain(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *hs_get_mic_gain(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
struct audio_device *device = data;
struct headset *hs = device->headset;
@@ -1175,53 +1189,48 @@ static DBusHandlerResult hs_get_mic_gain(DBusConnection *conn,
dbus_uint16_t gain;
if (hs->state < HEADSET_STATE_CONNECTED || hs->mic_gain < 0)
- return error_not_available(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAvailable",
+ "Operation not Available");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
gain = (dbus_uint16_t) hs->mic_gain;
dbus_message_append_args(reply, DBUS_TYPE_UINT16, &gain,
DBUS_TYPE_INVALID);
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_set_gain(DBusConnection *conn,
- DBusMessage *msg,
- void *data, char type)
+static DBusMessage *hs_set_gain(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data, char type)
{
struct audio_device *device = data;
struct headset *hs = device->headset;
DBusMessage *reply;
- DBusError derr;
dbus_uint16_t gain;
int err;
if (hs->state < HEADSET_STATE_CONNECTED)
- return error_not_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
- dbus_error_init(&derr);
- dbus_message_get_args(msg, &derr, DBUS_TYPE_UINT16, &gain,
- DBUS_TYPE_INVALID);
-
- if (dbus_error_is_set(&derr)) {
- error_invalid_arguments(conn, msg, derr.message);
- dbus_error_free(&derr);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT16, &gain,
+ DBUS_TYPE_INVALID))
+ return NULL;
if (gain > 15)
- return error_invalid_arguments(conn, msg,
- "Must be less than or equal to 15");
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".InvalidArgument",
+ "Must be less than or equal to 15");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
if (hs->state != HEADSET_STATE_PLAYING)
goto done;
@@ -1229,7 +1238,8 @@ static DBusHandlerResult hs_set_gain(DBusConnection *conn,
err = headset_send(hs, "\r\n+VG%c=%u\r\n", type, gain);
if (err < 0) {
dbus_message_unref(reply);
- return error_failed(conn, msg, "Unable to send to headset");
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", strerror(-err));
}
done:
@@ -1249,55 +1259,50 @@ done:
DBUS_TYPE_INVALID);
}
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hs_set_speaker_gain(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *hs_set_speaker_gain(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
return hs_set_gain(conn, msg, data, HEADSET_GAIN_SPEAKER);
}
-static DBusHandlerResult hs_set_mic_gain(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *hs_set_mic_gain(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
return hs_set_gain(conn, msg, data, HEADSET_GAIN_MICROPHONE);
}
-static DBusHandlerResult hf_setup_call(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *hf_setup_call(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
struct audio_device *device = data;
struct headset *hs = device->headset;
DBusMessage *reply;
- DBusError derr;
const char *value;
int err;
if (!hs->hfp_active)
- return error_not_supported(device->conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotSuppported",
+ "Not Supported");
if (hs->state < HEADSET_STATE_CONNECTED)
- return error_not_connected(conn, msg);
-
- dbus_error_init(&derr);
- dbus_message_get_args(msg, &derr, DBUS_TYPE_STRING, &value,
- DBUS_TYPE_INVALID);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
- if (dbus_error_is_set(&derr)) {
- error_invalid_arguments(conn, msg, derr.message);
- dbus_error_free(&derr);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &value,
+ DBUS_TYPE_INVALID))
+ return NULL;
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
if (!strncmp(value, "incoming", 8))
err = headset_send(hs, "\r\n+CIEV:3,1\r\n");
@@ -1310,74 +1315,70 @@ static DBusHandlerResult hf_setup_call(DBusConnection *conn,
if (err < 0) {
dbus_message_unref(reply);
- return error_failed_errno(conn, msg, -err);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", strerror(-err));
}
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusHandlerResult hf_identify_call(DBusConnection *conn,
+static DBusMessage *hf_identify_call(DBusConnection *conn,
DBusMessage *msg,
void *data)
{
struct audio_device *device = data;
struct headset *hs = device->headset;
DBusMessage *reply;
- DBusError derr;
const char *number;
dbus_int32_t type;
if (!hs->hfp_active && !hs->cli_active)
- return error_not_supported(device->conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotSuppported",
+ "Not Supported");
if (hs->state < HEADSET_STATE_CONNECTED)
- return error_not_connected(conn, msg);
-
- dbus_error_init(&derr);
- dbus_message_get_args(msg, &derr, DBUS_TYPE_STRING, &number,
- DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
- if (dbus_error_is_set(&derr)) {
- error_invalid_arguments(conn, msg, derr.message);
- dbus_error_free(&derr);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
+ DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID))
+ return NULL;
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
g_free(hs->ph_number);
hs->ph_number = g_strdup(number);
hs->type = type;
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusMethodVTable headset_methods[] = {
- { "Connect", hs_connect, "", "" },
- { "Disconnect", hs_disconnect, "", "" },
- { "IsConnected", hs_is_connected, "", "b" },
- { "IndicateCall", hs_ring, "", "" },
- { "CancelCall", hs_cancel_ringing, "", "" },
- { "Play", hs_play, "", "" },
- { "Stop", hs_stop, "", "" },
- { "IsPlaying", hs_is_playing, "", "b" },
- { "GetSpeakerGain", hs_get_speaker_gain, "", "q" },
- { "GetMicrophoneGain", hs_get_mic_gain, "", "q" },
- { "SetSpeakerGain", hs_set_speaker_gain, "q", "" },
- { "SetMicrophoneGain", hs_set_mic_gain, "q", "" },
- { "SetupCall", hf_setup_call, "s", "" },
- { "IdentifyCall", hf_identify_call, "si", "" },
+static GDBusMethodTable headset_methods[] = {
+ { "Connect", "", "", hs_connect,
+ G_DBUS_METHOD_FLAG_ASYNC },
+ { "Disconnect", "", "", hs_disconnect },
+ { "IsConnected", "", "b", hs_is_connected },
+ { "IndicateCall", "", "", hs_ring },
+ { "CancelCall", "", "", hs_cancel_ringing },
+ { "Play", "", "", hs_play,
+ G_DBUS_METHOD_FLAG_ASYNC },
+ { "Stop", "", "", hs_stop },
+ { "IsPlaying", "", "b", hs_is_playing },
+ { "GetSpeakerGain", "", "q", hs_get_speaker_gain },
+ { "GetMicrophoneGain", "", "q", hs_get_mic_gain },
+ { "SetSpeakerGain", "q", "", hs_set_speaker_gain },
+ { "SetMicrophoneGain", "q", "", hs_set_mic_gain },
+ { "SetupCall", "s", "", hf_setup_call },
+ { "IdentifyCall", "si", "", hf_identify_call },
{ NULL, NULL, NULL, NULL }
};
-static DBusSignalVTable headset_signals[] = {
+static GDBusSignalTable headset_signals[] = {
{ "Connected", "" },
{ "Disconnected", "" },
{ "AnswerRequested", "" },
@@ -1486,10 +1487,10 @@ struct headset *headset_init(struct audio_device *dev, sdp_record_t *record,
headset_set_channel(hs, record, svc);
register_iface:
- if (!dbus_connection_register_interface(dev->conn, dev->path,
- AUDIO_HEADSET_INTERFACE,
- headset_methods,
- headset_signals, NULL)) {
+ if (!g_dbus_register_interface(dev->conn, dev->path,
+ AUDIO_HEADSET_INTERFACE,
+ headset_methods, headset_signals, NULL,
+ dev, NULL)) {
g_free(hs);
return NULL;
}
diff --git a/audio/manager.c b/audio/manager.c
index f6d26abd..2c3e4257 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -120,7 +120,7 @@ static struct enabled_interfaces enabled = {
.control = TRUE,
};
-static DBusHandlerResult get_records(uuid_t *uuid, struct audio_sdp_data *data);
+static DBusMessage *get_records(uuid_t *uuid, struct audio_sdp_data *data);
static struct audio_device *create_device(const bdaddr_t *bda)
{
@@ -430,7 +430,7 @@ static void get_records_cb(sdp_list_t *recs, int err, gpointer user_data)
get_records(&uuid, data);
}
-static DBusHandlerResult get_records(uuid_t *uuid, struct audio_sdp_data *data)
+static DBusMessage *get_records(uuid_t *uuid, struct audio_sdp_data *data)
{
struct audio_device *device = data->device;
int err;
@@ -448,10 +448,10 @@ static DBusHandlerResult get_records(uuid_t *uuid, struct audio_sdp_data *data)
return DBUS_HANDLER_RESULT_HANDLED;
}
-static DBusHandlerResult resolve_services(DBusMessage *msg,
- struct audio_device *device,
- create_dev_cb_t cb,
- void *user_data)
+static DBusMessage *resolve_services(DBusMessage *msg,
+ struct audio_device *device,
+ create_dev_cb_t cb,
+ void *user_data)
{
struct audio_sdp_data *sdp_data;
uuid_t uuid;
@@ -568,9 +568,9 @@ gboolean manager_create_device(bdaddr_t *bda, create_dev_cb_t cb,
return TRUE;
}
-static DBusHandlerResult am_create_device(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *am_create_device(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
const char *address, *path;
bdaddr_t bda;
@@ -601,15 +601,15 @@ static DBusHandlerResult am_create_device(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
dbus_message_append_args(reply, DBUS_TYPE_STRING, &path,
DBUS_TYPE_INVALID);
- return send_message_and_unref(conn, reply);
+ return reply;
}
-static DBusHandlerResult am_list_devices(DBusConnection *conn,
+static DBusMessage *am_list_devices(DBusConnection *conn,
DBusMessage *msg,
void *data)
{
@@ -619,7 +619,6 @@ static DBusHandlerResult am_list_devices(DBusConnection *conn,
GSList *l;
gboolean hs_only = FALSE;
-
dbus_error_init(&derr);
if (dbus_message_is_method_call(msg, AUDIO_MANAGER_INTERFACE,
@@ -630,7 +629,7 @@ static DBusHandlerResult am_list_devices(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
dbus_message_iter_init_append(reply, &iter);
@@ -649,7 +648,7 @@ static DBusHandlerResult am_list_devices(DBusConnection *conn,
dbus_message_iter_close_container(&iter, &array_iter);
- return send_message_and_unref(connection, reply);
+ return reply;
}
static gint device_path_cmp(gconstpointer a, gconstpointer b)
@@ -660,36 +659,28 @@ static gint device_path_cmp(gconstpointer a, gconstpointer b)
return strcmp(device->path, path);
}
-static DBusHandlerResult am_remove_device(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *am_remove_device(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
- DBusError derr;
DBusMessage *reply;
GSList *match;
const char *path;
struct audio_device *device;
- dbus_error_init(&derr);
- if (!dbus_message_get_args(msg, &derr,
+ if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_STRING, &path,
- DBUS_TYPE_INVALID)) {
- error_invalid_arguments(connection, msg, derr.message);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
- if (dbus_error_is_set(&derr)) {
- error_invalid_arguments(connection, msg, derr.message);
- dbus_error_free(&derr);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ DBUS_TYPE_INVALID))
+ return NULL;
match = g_slist_find_custom(devices, path, device_path_cmp);
if (!match)
- return error_device_does_not_exist(connection, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
+ "Device does not exists");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
device = match->data;
device_remove_stored(device);
@@ -737,99 +728,88 @@ static DBusHandlerResult am_remove_device(DBusConnection *conn,
DBUS_TYPE_STRING, &path,
DBUS_TYPE_INVALID);
- return send_message_and_unref(connection, reply);
+ return reply;
}
-static DBusHandlerResult am_find_by_addr(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *am_find_by_addr(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
const char *address;
DBusMessage *reply;
- DBusError derr;
struct audio_device *device;
bdaddr_t bda;
- dbus_error_init(&derr);
- dbus_message_get_args(msg, &derr,
+ if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&derr)) {
- error_invalid_arguments(connection, msg, derr.message);
- dbus_error_free(&derr);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ DBUS_TYPE_INVALID))
+ return NULL;
str2ba(address, &bda);
device = manager_find_device(&bda, NULL, FALSE);
if (!device)
- return error_device_does_not_exist(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
+ "Device does not exists");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
dbus_message_append_args(reply, DBUS_TYPE_STRING, &device->path,
DBUS_TYPE_INVALID);
- return send_message_and_unref(conn, reply);
+ return reply;
}
-static DBusHandlerResult am_default_device(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *am_default_device(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
DBusMessage *reply;
if (!default_dev)
- return error_device_does_not_exist(connection, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
+ "Device does not exists");
if (default_dev->headset == NULL &&
dbus_message_is_method_call(msg, AUDIO_MANAGER_INTERFACE,
"DefaultHeadset"))
- return error_device_does_not_exist(connection, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
+ "Device does not exists");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
dbus_message_append_args(reply, DBUS_TYPE_STRING, &default_dev->path,
DBUS_TYPE_INVALID);
- return send_message_and_unref(connection, reply);
+ return reply;
}
-static DBusHandlerResult am_change_default_device(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *am_change_default_device(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
- DBusError derr;
DBusMessage *reply;
GSList *match;
const char *path;
struct audio_device *device;
- dbus_error_init(&derr);
- if (!dbus_message_get_args(msg, &derr,
+ if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_STRING, &path,
- DBUS_TYPE_INVALID)) {
- error_invalid_arguments(connection, msg, derr.message);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
- if (dbus_error_is_set(&derr)) {
- error_invalid_arguments(connection, msg, derr.message);
- dbus_error_free(&derr);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ DBUS_TYPE_INVALID))
+ return NULL;
match = g_slist_find_custom(devices, path, device_path_cmp);
if (!match)
- return error_device_does_not_exist(connection, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
+ "Device does not exists");
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
device = match->data;
@@ -847,47 +827,40 @@ static DBusHandlerResult am_change_default_device(DBusConnection *conn,
DBUS_TYPE_STRING, &device->path,
DBUS_TYPE_INVALID);
else
- return error_device_does_not_exist(connection, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
+ "Device does not exists");
default_dev = device;
device_store(device, TRUE);
- return send_message_and_unref(connection, reply);
+
+ return reply;
}
-static DBusMethodVTable manager_methods[] = {
- { "CreateDevice", am_create_device,
- "s", "s" },
- { "RemoveDevice", am_remove_device,
- "s", "" },
- { "ListDevices", am_list_devices,
- "", "as" },
- { "DefaultDevice", am_default_device,
- "", "s" },
- { "ChangeDefaultDevice", am_change_default_device,
- "s", "" },
- { "CreateHeadset", am_create_device,
- "s", "s" },
- { "RemoveHeadset", am_remove_device,
- "s", "" },
- { "ListHeadsets", am_list_devices,
- "", "as" },
- { "FindDeviceByAddress", am_find_by_addr,
- "s", "s" },
- { "DefaultHeadset", am_default_device,
- "", "s" },
- { "ChangeDefaultHeadset", am_change_default_device,
- "s", "" },
- { NULL, NULL, NULL, NULL },
+static GDBusMethodTable manager_methods[] = {
+ { "CreateDevice", "s", "s", am_create_device,
+ G_DBUS_METHOD_FLAG_ASYNC },
+ { "RemoveDevice", "s", "", am_remove_device },
+ { "ListDevices", "", "as", am_list_devices },
+ { "DefaultDevice", "", "s", am_default_device },
+ { "ChangeDefaultDevice", "s", "", am_change_default_device },
+ { "CreateHeadset", "s", "s", am_create_device,
+ G_DBUS_METHOD_FLAG_ASYNC },
+ { "RemoveHeadset", "s", "", am_remove_device },
+ { "ListHeadsets", "", "as", am_list_devices },
+ { "FindDeviceByAddress", "s", "s", am_find_by_addr },
+ { "DefaultHeadset", "", "s", am_default_device },
+ { "ChangeDefaultHeadset", "s", "", am_change_default_device },
+ { }
};
-static DBusSignalVTable manager_signals[] = {
+static GDBusSignalTable manager_signals[] = {
{ "DeviceCreated", "s" },
{ "DeviceRemoved", "s" },
{ "HeadsetCreated", "s" },
{ "HeadsetRemoved", "s" },
{ "DefaultDeviceChanged", "s" },
{ "DefaultHeadsetChanged", "s" },
- { NULL, NULL }
+ { }
};
static void parse_stored_devices(char *key, char *value, void *data)
@@ -992,7 +965,7 @@ static void register_stored(void)
closedir(dir);
}
-static void manager_unregister(DBusConnection *conn, void *data)
+static void manager_unregister(void *data)
{
info("Unregistered manager path");
@@ -1501,12 +1474,6 @@ int audio_manager_init(DBusConnection *conn, GKeyFile *config)
g_strfreev(list);
proceed:
- if (!dbus_connection_create_object_path(conn, AUDIO_MANAGER_PATH,
- NULL, manager_unregister)) {
- error("D-Bus failed to register %s path", AUDIO_MANAGER_PATH);
- goto failed;
- }
-
if (enabled.headset) {
if (headset_server_init(conn, config) < 0)
goto failed;
@@ -1525,10 +1492,10 @@ proceed:
if (enabled.control && avrcp_init(conn, config) < 0)
goto failed;
- if (!dbus_connection_register_interface(conn, AUDIO_MANAGER_PATH,
- AUDIO_MANAGER_INTERFACE,
- manager_methods,
- manager_signals, NULL)) {
+ if (!g_dbus_register_interface(conn, AUDIO_MANAGER_PATH,
+ AUDIO_MANAGER_INTERFACE,
+ manager_methods, manager_signals,
+ NULL, NULL, manager_unregister)) {
error("Failed to register %s interface to %s",
AUDIO_MANAGER_INTERFACE, AUDIO_MANAGER_PATH);
goto failed;
diff --git a/audio/sink.c b/audio/sink.c
index 7f33cf13..9027cd74 100644
--- a/audio/sink.c
+++ b/audio/sink.c
@@ -379,8 +379,8 @@ failed:
error_failed(pending->conn, pending->msg, "Stream setup failed");
}
-static DBusHandlerResult sink_connect(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static DBusMessage *sink_connect(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
struct audio_device *dev = data;
struct sink *sink = dev->sink;
@@ -390,14 +390,17 @@ static DBusHandlerResult sink_connect(DBusConnection *conn,
sink->session = avdtp_get(&dev->src, &dev->dst);
if (!sink->session)
- return error_failed(conn, msg, "Unable to get a session");
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "Unable to get a session");
if (sink->connect || sink->disconnect)
- return error_in_progress(conn, msg, "Device connection"
- "already in progress");
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", strerror(EBUSY));
if (sink->state >= AVDTP_STATE_OPEN)
- return error_already_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".AlreadyConnected",
+ "Device Already Connected");
pending = g_new0(struct pending_request, 1);
pending->conn = dbus_connection_ref(conn);
@@ -408,11 +411,11 @@ static DBusHandlerResult sink_connect(DBusConnection *conn,
debug("stream creation in progress");
- return DBUS_HANDLER_RESULT_HANDLED;
+ return NULL;
}
-static DBusHandlerResult sink_disconnect(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static DBusMessage *sink_disconnect(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
struct audio_device *device = data;
struct sink *sink = device->sink;
@@ -420,35 +423,39 @@ static DBusHandlerResult sink_disconnect(DBusConnection *conn,
int err;
if (!sink->session)
- return error_not_connected(conn, msg);
+ return g_dbus_create_error(msg, ERROR_INTERFACE
+ ".NotConnected",
+ "Device not Connected");
if (sink->connect || sink->disconnect)
- return error_failed(conn, msg, strerror(EBUSY));
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", strerror(EBUSY));
if (sink->state < AVDTP_STATE_OPEN) {
DBusMessage *reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
avdtp_unref(sink->session);
sink->session = NULL;
- return send_message_and_unref(conn, reply);
+ return reply;
}
err = avdtp_close(sink->session, sink->stream);
if (err < 0)
- return error_failed(conn, msg, strerror(-err));
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", strerror(-err));
pending = g_new0(struct pending_request, 1);
pending->conn = dbus_connection_ref(conn);
pending->msg = dbus_message_ref(msg);
sink->disconnect = pending;
- return DBUS_HANDLER_RESULT_HANDLED;
+ return NULL;
}
-static DBusHandlerResult sink_is_connected(DBusConnection *conn,
- DBusMessage *msg,
- void *data)
+static DBusMessage *sink_is_connected(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
{
struct audio_device *device = data;
struct sink *sink = device->sink;
@@ -457,26 +464,26 @@ static DBusHandlerResult sink_is_connected(DBusConnection *conn,
reply = dbus_message_new_method_return(msg);
if (!reply)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return NULL;
connected = (sink->state >= AVDTP_STATE_CONFIGURED);
dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &connected,
DBUS_TYPE_INVALID);
- send_message_and_unref(conn, reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return reply;
}
-static DBusMethodVTable sink_methods[] = {
- { "Connect", sink_connect, "", "" },
- { "Disconnect", sink_disconnect, "", "" },
- { "IsConnected", sink_is_connected, "", "b" },
+static GDBusMethodTable sink_methods[] = {
+ { "Connect", "", "", sink_connect,
+ G_DBUS_METHOD_FLAG_ASYNC },
+ { "Disconnect", "", "", sink_disconnect,
+ G_DBUS_METHOD_FLAG_ASYNC },
+ { "IsConnected", "", "b", sink_is_connected },
{ NULL, NULL, NULL, NULL }
};
-static DBusSignalVTable sink_signals[] = {
+static GDBusSignalTable sink_signals[] = {
{ "Connected", "" },
{ "Disconnected", "" },
{ "Playing", "" },
@@ -486,10 +493,10 @@ static DBusSignalVTable sink_signals[] = {
struct sink *sink_init(struct audio_device *dev)
{
- if (!dbus_connection_register_interface(dev->conn, dev->path,
- AUDIO_SINK_INTERFACE,
- sink_methods,
- sink_signals, NULL))
+ if (!g_dbus_register_interface(dev->conn, dev->path,
+ AUDIO_SINK_INTERFACE,
+ sink_methods, sink_signals, NULL,
+ dev, NULL))
return NULL;
return g_new0(struct sink, 1);