summaryrefslogtreecommitdiffstats
path: root/audio/unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio/unix.c')
-rw-r--r--audio/unix.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/audio/unix.c b/audio/unix.c
index 8cd1affc..f2bf2271 100644
--- a/audio/unix.c
+++ b/audio/unix.c
@@ -39,8 +39,8 @@
#include "logging.h"
#include "dbus.h"
-#include "ipc.h"
#include "unix.h"
+#include "manager.h"
static int unix_sock = -1;
@@ -48,8 +48,8 @@ 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;
+ struct ipc_packet *pkt;
+ struct ipc_data_cfg *cfg;
int sk, len;
debug("chan %p cond %td data %p", chan, cond, data);
@@ -67,29 +67,28 @@ static gboolean unix_event(GIOChannel *chan, GIOCondition cond, gpointer data)
memset(&addr, 0, sizeof(addr));
addrlen = sizeof(addr);
- len = recvfrom(sk, &pkt, sizeof(pkt), 0, (struct sockaddr *) &addr, &addrlen);
+ len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_cfg);
+ pkt = g_malloc0(len);
+ len = recvfrom(sk, pkt, len, 0, (struct sockaddr *) &addr, &addrlen);
debug("path %s len %d", addr.sun_path + 1, len);
- switch (pkt.type) {
+ switch (pkt->type) {
case PKT_TYPE_CFG_REQ:
- info("Package PKT_TYPE_CFG_REQ:%u", pkt.role);
- struct ipc_data_cfg *cfg_ptr;
-
- cfg.fd = -1;
- cfg.fd_opt = CFG_FD_OPT_READWRITE;
- cfg.encoding = 0;
- cfg.bitpool = 0;
- cfg.channels = 1;
- cfg.pkt_len = 48;
- cfg.sample_size = 2;
- cfg.rate = 8000;
-
- cfg_ptr = (struct ipc_data_cfg *) &pkt.data;
- pkt.type = PKT_TYPE_CFG_RSP;
- cfg_ptr[0] = cfg;
- pkt.length = sizeof(struct ipc_data_cfg);
- len = send(sk, &pkt, sizeof(struct ipc_packet) + sizeof(struct ipc_data_cfg), 0);
+ info("Package PKT_TYPE_CFG_REQ:%u", pkt->role);
+
+ cfg = (struct ipc_data_cfg *) pkt->data;
+
+ if (manager_get_device(pkt->role, cfg) < 0)
+ cfg->fd = -1;
+
+ pkt->type = PKT_TYPE_CFG_RSP;
+ pkt->length = sizeof(struct ipc_data_cfg);
+ pkt->error = PKT_ERROR_NONE;
+ len = sendto(sk, pkt, len, 0, (struct sockaddr *) &addr, addrlen);
+ if (len < 0)
+ info("Error %s(%d)", strerror(errno), errno);
+ info("%d bytes sent", len);
break;
case PKT_TYPE_STATUS_REQ:
info("Package PKT_TYPE_STATUS_REQ");
@@ -98,6 +97,8 @@ static gboolean unix_event(GIOChannel *chan, GIOCondition cond, gpointer data)
info("Package PKT_TYPE_CTL_REQ");
break;
}
+
+ g_free(pkt);
return TRUE;
}