From 66d48b0ac25c85de354f26782a377d0ad91bd322 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 10 Jul 2007 13:34:57 +0000 Subject: Code cleanup. --- audio/gateway.c | 4 +++- audio/headset.c | 2 +- audio/headset.h | 10 +++++----- audio/ipc.h | 17 +++++++++-------- audio/pcm_bluetooth.c | 16 +++++++++------- audio/unix.c | 45 +++++++++++++++++++++++++++++++++------------ audio/unix.h | 1 + 7 files changed, 61 insertions(+), 34 deletions(-) diff --git a/audio/gateway.c b/audio/gateway.c index afdcbe01..3b84462d 100644 --- a/audio/gateway.c +++ b/audio/gateway.c @@ -314,7 +314,8 @@ static void auth_cb(DBusPendingCall *call, void *data) send_cancel_auth(device); } dbus_error_free(&err); - headset_close_rfcomm(device); + + headset_set_state(device, HEADSET_STATE_DISCONNECTED); } else { char hs_address[18]; @@ -407,6 +408,7 @@ static gboolean gateway_io_cb(GIOChannel *chan, GIOCondition cond, void *data) dbus_pending_call_set_notify(pending, auth_cb, device, NULL); dbus_pending_call_unref(pending); dbus_message_unref(auth); + headset_set_state(device, HEADSET_STATE_CONNECT_IN_PROGRESS); return TRUE; diff --git a/audio/headset.c b/audio/headset.c index ca24e93b..edb323ee 100644 --- a/audio/headset.c +++ b/audio/headset.c @@ -206,7 +206,7 @@ static gboolean rfcomm_io_cb(GIOChannel *chan, GIOCondition cond, err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf) - 1, &bytes_read); if (err != G_IO_ERROR_NONE) - goto failed; + error("Ignoring error %d", err); free_space = sizeof(hs->buf) - hs->data_start - hs->data_length - 1; diff --git a/audio/headset.h b/audio/headset.h index c858d206..d3fd86d9 100644 --- a/audio/headset.h +++ b/audio/headset.h @@ -40,11 +40,11 @@ typedef enum { } headset_event_t; typedef enum { - HEADSET_STATE_DISCONNECTED = 0, - HEADSET_STATE_CONNECT_IN_PROGRESS, - HEADSET_STATE_CONNECTED, - HEADSET_STATE_PLAY_IN_PROGRESS, - HEADSET_STATE_PLAYING, + HEADSET_STATE_DISCONNECTED = STATE_DISCONNECTED, + HEADSET_STATE_CONNECT_IN_PROGRESS = STATE_CONNECTING, + HEADSET_STATE_CONNECTED = STATE_CONNECTED, + HEADSET_STATE_PLAY_IN_PROGRESS = STATE_STREAM_STARTING, + HEADSET_STATE_PLAYING = STATE_STREAMING, } headset_state_t; typedef enum { diff --git a/audio/ipc.h b/audio/ipc.h index d340d15e..e56dca24 100644 --- a/audio/ipc.h +++ b/audio/ipc.h @@ -40,8 +40,8 @@ /* Packet types */ #define PKT_TYPE_CFG_REQ 0 #define PKT_TYPE_CFG_RSP 1 -#define PKT_TYPE_STATUS_REQ 2 -#define PKT_TYPE_STATUS_RSP 3 +#define PKT_TYPE_STATE_REQ 2 +#define PKT_TYPE_STATE_RSP 3 #define PKT_TYPE_CTL_REQ 4 #define PKT_TYPE_CTL_RSP 5 #define PKT_TYPE_CTL_NTFY 6 @@ -75,13 +75,14 @@ struct ipc_data_cfg { } __attribute__ ((packed)); /* Device status */ -#define STATUS_DISCONNECTED 0 -#define STATUS_CONNECTING 1 -#define STATUS_CONNECTED 2 -#define STATUS_STREAMING 3 +#define STATE_DISCONNECTED 0 +#define STATE_CONNECTING 1 +#define STATE_CONNECTED 2 +#define STATE_STREAM_STARTING 3 +#define STATE_STREAMING 4 -struct ipc_data_status { - uint8_t status; /* Stream status */ +struct ipc_data_state { + uint8_t state; /* Stream state */ } __attribute__ ((packed)); #define CTL_MODE_PLAYBACK 0 diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c index 71daab4f..92d0383c 100644 --- a/audio/pcm_bluetooth.c +++ b/audio/pcm_bluetooth.c @@ -86,25 +86,27 @@ static snd_pcm_sframes_t bluetooth_pointer(snd_pcm_ioplug_t *io) static void bluetooth_exit(struct bluetooth_data *data) { - int ret, len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_status); + int ret, len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_state); struct ipc_packet *pkt; - struct ipc_data_status *status; + struct ipc_data_state *state; DBG("Sending PKT_TYPE_STATUS_REQ..."); - if ((pkt = malloc(len)) == 0) + if ((pkt = malloc(len)) == NULL) goto done; memset(pkt, 0, len); - pkt->type = PKT_TYPE_STATUS_REQ; + pkt->type = PKT_TYPE_STATE_REQ; pkt->role = PKT_ROLE_NONE; pkt->error = PKT_ERROR_NONE; - status = (struct ipc_data_status *) pkt->data; - status->status = STATUS_DISCONNECTED; + state = (struct ipc_data_state *) pkt->data; + state->state = STATE_DISCONNECTED; if ((ret = send(data->sock, pkt, len, 0)) < 0) - DBG("OK"); + DBG("Error %s (%d)", strerror(errno), errno); + + free(pkt); done: if (data == NULL) return; diff --git a/audio/unix.c b/audio/unix.c index 0f6c53aa..fbda7ed9 100644 --- a/audio/unix.c +++ b/audio/unix.c @@ -97,18 +97,18 @@ static void ctl_event(int clisk, struct ipc_packet *pkt) { } -static void status_event(int clisk, struct ipc_packet *pkt) +static void state_event(int clisk, struct ipc_packet *pkt) { - struct ipc_data_status *status = (struct ipc_data_status *) pkt->data; + struct ipc_data_state *state = (struct ipc_data_state *) pkt->data; struct device *device; - if (status->status == STATUS_DISCONNECTED) { - if (!(device = manager_default_device())) - return; + if (!(device = manager_default_device())) + return; - if (device->headset) - headset_set_state(device, HEADSET_STATE_DISCONNECTED); - } + if (device->headset) + headset_set_state(device, state->state); + + unix_send_status(clisk, pkt); g_free(pkt); } @@ -152,9 +152,9 @@ static gboolean unix_event(GIOChannel *chan, GIOCondition cond, gpointer data) info("Package PKT_TYPE_CFG_REQ:%u", pkt->role); cfg_event(clisk, pkt); break; - case PKT_TYPE_STATUS_REQ: - info("Package PKT_TYPE_STATUS_REQ"); - status_event(clisk, pkt); + case PKT_TYPE_STATE_REQ: + info("Package PKT_TYPE_STATE_REQ"); + state_event(clisk, pkt); break; case PKT_TYPE_CTL_REQ: info("Package PKT_TYPE_CTL_REQ"); @@ -239,6 +239,27 @@ int unix_send_cfg(int sock, struct ipc_packet *pkt) } g_free(pkt); - close(sock); + return 0; +} + +int unix_send_status(int sock, struct ipc_packet *pkt) +{ + struct ipc_data_state *state = (struct ipc_data_state *) pkt->data; + int len; + + info("status=%u", state->state); + + pkt->type = PKT_TYPE_CFG_RSP; + pkt->length = sizeof(struct ipc_data_state); + pkt->error = PKT_ERROR_NONE; + + len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_state); + len = send(sock, pkt, len, 0); + if (len < 0) + info("Error %s(%d)", strerror(errno), errno); + + info("%d bytes sent", len); + + g_free(pkt); return 0; } diff --git a/audio/unix.h b/audio/unix.h index 15da23ab..32cf4af9 100644 --- a/audio/unix.h +++ b/audio/unix.h @@ -27,3 +27,4 @@ int unix_init(void); void unix_exit(void); int unix_send_cfg(int sock, struct ipc_packet *pkt); +int unix_send_status(int sock, struct ipc_packet *pkt); -- cgit