- FOR_EACH_SLOT(i) {
- struct slot_info *s = &slot[i];
- struct audio_format_info *a;
- struct receiver_node *rn = s->receiver_node;
- if (s->format < 0 || !rn || rn->eof)
- continue;
- a = &afi[s->format];
- ret = a->receiver->post_select(rn, select_ret, rfds, wfds);
- if (ret <= 0) {
- if (ret)
- PARA_ERROR_LOG("%s post select failed: %s (slot %d)\n",
- a->receiver->name, PARA_STRERROR(-ret), i);
- else
- PARA_INFO_LOG("eof in slot %d\n", i);
- rn->eof = 1;
- }
- if (ret < 0 && s->fci)
- s->fci->error = ret;
+static void command_pre_select(struct sched *s, struct task *t)
+{
+ struct command_task *ct = t->private_data;
+ para_fd_set(ct->fd, &s->rfds, &s->max_fileno);
+
+}
+
+static void command_post_select(struct sched *s, struct task *t)
+{
+ int ret;
+ struct command_task *ct = t->private_data;
+
+ if (audiod_status != AUDIOD_OFF)
+ audiod_status_dump();
+ t->ret = 1; /* always successful */
+ if (!FD_ISSET(ct->fd, &s->rfds))
+ return;
+ ret = handle_connect();
+ if (ret < 0)
+ PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
+}
+
+void init_command_task(struct command_task *ct)
+{
+ ct->task.pre_select = command_pre_select;
+ ct->task.post_select = command_post_select;
+ ct->task.private_data = ct;
+ ct->task.flags = 0;
+ sprintf(ct->task.status, "command task");
+}
+
+static void status_pre_select(struct sched *s, struct task *t)
+{
+ struct status_task *st = t->private_data;
+ t->ret = 1;
+ if (st->fd >= 0 && audiod_status == AUDIOD_OFF)
+ close_stat_pipe();
+ if (st->fd < 0 && audiod_status != AUDIOD_OFF) {
+ st->fd = open_stat_pipe();
+ st->loaded = 0;
+ st->buf[0] = '\0';
+ }
+ if (st->fd >= 0 && audiod_status != AUDIOD_OFF)
+ para_fd_set(st->fd, &s->rfds, &s->max_fileno);
+}
+
+static void status_post_select(struct sched *s, struct task *t)
+{
+ struct status_task *st = t->private_data;
+ int ret;
+
+ t->ret = 1;
+ if (st->fd < 0 || !FD_ISSET(st->fd, &s->rfds))
+ return;
+ ret = read(st->fd, st->buf + st->loaded,
+ STRINGSIZE - 1 - st->loaded);
+ if (ret <= 0) {
+ close_stat_pipe();
+ /* avoid busy loop if server is down */
+ while (sleep(1) > 0)
+ ; /* try again*/
+ } else {
+ st->buf[ret + st->loaded] = '\0';
+ st->loaded = for_each_line(st->buf, ret + st->loaded,
+ &check_stat_line);