struct timeval clock_diff_barrier;
/** Number of the audio format as announced by para_server. */
int current_audio_format_num;
+ /* The status task btrn is the child of the client task. */
+ struct btr_node *btrn;
};
/** The array of status items sent by para_server. */
{
if (!stat_task->ct)
return;
+ btr_free_node(stat_task->ct->btrn);
client_close(stat_task->ct);
stat_task->ct = NULL;
clear_and_dump_items();
sched_min_delay(s);
}
-/* restart the client task if necessary */
static void status_pre_select(struct sched *s, struct task *t)
+{
+ struct status_task *st = container_of(t, struct status_task, task);
+ int ret;
+
+ ret = btr_node_status(st->btrn, 0, BTR_NT_LEAF);
+ sched_request_barrier(&st->restart_barrier, s);
+}
+
+/* restart the client task if necessary */
+static void status_post_select(struct sched *s, struct task *t)
{
struct status_task *st = container_of(t, struct status_task, task);
if (!st->ct)
goto out;
if (st->ct->task.error >= 0) {
- st->ct->task.error = -E_AUDIOD_OFF;
+ kill_btrn(st->ct->btrn, &st->ct->task, -E_AUDIOD_OFF);
goto out;
}
if (st->ct->task.error != -E_TASK_UNREGISTERED)
goto out;
}
if (st->ct) {
+ char *buf;
+ size_t sz;
int ret;
if (st->ct->task.error < 0) {
if (st->ct->task.error != -E_TASK_UNREGISTERED)
}
if (st->ct->status != CL_RECEIVING)
goto out;
- ret = for_each_stat_item(st->ct->buf, st->ct->loaded,
- update_item);
+ ret = btr_node_status(st->btrn, 0, BTR_NT_LEAF);
+ if (ret <= 0)
+ goto out;
+ sz = btr_next_buffer(st->btrn, &buf);
+ ret = for_each_stat_item(buf, sz, update_item);
if (ret < 0) {
- st->ct->task.error = ret;
+ kill_btrn(st->ct->btrn, &st->ct->task, ret);
goto out;
}
- if (st->ct->loaded != ret) {
+ if (sz != ret)
st->last_status_read = *now;
- st->ct->loaded = ret;
- } else {
+ else {
struct timeval diff;
tv_diff(now, &st->last_status_read, &diff);
if (diff.tv_sec > 61)
- st->ct->task.error = -E_STATUS_TIMEOUT;
+ kill_btrn(st->ct->btrn, &st->ct->task,
+ -E_STATUS_TIMEOUT);
}
+ btr_consume(st->btrn, sz - ret);
goto out;
}
if (tv_diff(now, &st->restart_barrier, NULL) < 0)
int argc = 5;
PARA_INFO_LOG("clock diff count: %d\n", st->clock_diff_count);
st->clock_diff_count--;
- client_open(argc, argv, &st->ct, NULL);
+ client_open(argc, argv, &st->ct, NULL, NULL, st->btrn);
set_stat_task_restart_barrier(2);
sched_min_delay(s);
} else {
char *argv[] = {"audiod", "--", "stat", "-p", NULL};
int argc = 4;
- client_open(argc, argv, &st->ct, NULL);
+ client_open(argc, argv, &st->ct, NULL, NULL, st->btrn);
set_stat_task_restart_barrier(5);
sched_min_delay(s);
}
{
memset(st, 0, sizeof(struct status_task));
st->task.pre_select = status_pre_select;
+ st->task.post_select = status_post_select;
st->sa_time_diff_sign = 1;
st->clock_diff_count = conf.clock_diff_count_arg;
st->current_audio_format_num = -1;
- sprintf(st->task.status, "status task");
+ sprintf(st->task.status, "stat");
+ st->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "stat"));
}
static void set_initial_status(void)