diff options
author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2007-06-29 23:19:36 +0000 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2007-06-29 23:19:36 +0000 |
commit | df235d1f395b10654024979180c778777bd50c71 (patch) | |
tree | d12a132c9921e5e50a661a73b752b01f71034b28 /audio/unix.c | |
parent | b57f22a505f7c46662bfd5900df38dd68099df2c (diff) |
Handle state machine in a better way and add disconnect code for plugin.
Diffstat (limited to 'audio/unix.c')
-rw-r--r-- | audio/unix.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/audio/unix.c b/audio/unix.c index a4b8f2c4..0f6c53aa 100644 --- a/audio/unix.c +++ b/audio/unix.c @@ -75,13 +75,49 @@ static int unix_sendmsg_fd(int sock, int fd, struct ipc_packet *pkt) return sendmsg(sock, &msgh, MSG_NOSIGNAL); } -static gboolean unix_event(GIOChannel *chan, GIOCondition cond, gpointer data) +static void cfg_event(int clisk, struct ipc_packet *pkt) +{ + struct ipc_data_cfg *cfg = (struct ipc_data_cfg *) pkt->data; + struct device *device; + + memset(cfg, 0, sizeof(struct ipc_data_cfg)); + + if ((device = manager_default_device())) { + if (device->headset) + headset_get_config(device, clisk, pkt); + } + else + cfg->fd = -1; + + if (cfg->fd != 0) + unix_send_cfg(clisk, pkt); +} + +static void ctl_event(int clisk, struct ipc_packet *pkt) +{ +} + +static void status_event(int clisk, struct ipc_packet *pkt) { + struct ipc_data_status *status = (struct ipc_data_status *) pkt->data; struct device *device; + + if (status->status == STATUS_DISCONNECTED) { + if (!(device = manager_default_device())) + return; + + if (device->headset) + headset_set_state(device, HEADSET_STATE_DISCONNECTED); + } + + g_free(pkt); +} + +static gboolean unix_event(GIOChannel *chan, GIOCondition cond, gpointer data) +{ struct sockaddr_un addr; socklen_t addrlen; struct ipc_packet *pkt; - struct ipc_data_cfg *cfg; int sk, clisk, len; debug("chan %p cond %td data %p", chan, cond, data); @@ -114,23 +150,15 @@ static gboolean unix_event(GIOChannel *chan, GIOCondition cond, gpointer data) switch (pkt->type) { case PKT_TYPE_CFG_REQ: info("Package PKT_TYPE_CFG_REQ:%u", pkt->role); - - cfg = (struct ipc_data_cfg *) pkt->data; - - memset(cfg, 0, sizeof(struct ipc_data_cfg)); - if ((device = manager_default_device())) { - if (device->headset) - headset_get_config(device, clisk, pkt); - } - - if (cfg->fd != 0) - unix_send_cfg(clisk, pkt); + cfg_event(clisk, pkt); break; case PKT_TYPE_STATUS_REQ: info("Package PKT_TYPE_STATUS_REQ"); + status_event(clisk, pkt); break; case PKT_TYPE_CTL_REQ: info("Package PKT_TYPE_CTL_REQ"); + ctl_event(clisk, pkt); break; } |