task_register() conversion: client task
authorAndre Noll <maan@systemlinux.org>
Mon, 30 Dec 2013 23:54:26 +0000 (23:54 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 May 2014 13:39:00 +0000 (15:39 +0200)
audiod.c
client.c
client.h
client_common.c

index afdb97f7a9ea4b135378954d974e44b234ef4633..948204dc8829a78c3a4595d5a03dde48733d0462 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -1081,6 +1081,7 @@ static void close_stat_pipe(void)
        if (!stat_task->ct)
                return;
        client_close(stat_task->ct);
+       task_reap(&stat_task->ct->task);
        stat_task->ct = NULL;
        clear_and_dump_items();
        stat_task->length_seconds = 0;
@@ -1231,8 +1232,8 @@ static int status_post_select(struct sched *s, struct task *t)
        if (audiod_status == AUDIOD_OFF) {
                if (!st->ct)
                        goto out;
-               if (st->ct->task.error >= 0) {
-                       task_notify(&st->ct->task, E_AUDIOD_OFF);
+               if (st->ct->task->error >= 0) {
+                       task_notify(st->ct->task, E_AUDIOD_OFF);
                        goto out;
                }
                close_stat_pipe();
@@ -1255,14 +1256,14 @@ static int status_post_select(struct sched *s, struct task *t)
                        struct timeval diff;
                        tv_diff(now, &st->last_status_read, &diff);
                        if (diff.tv_sec > 61)
-                               task_notify(&st->ct->task, E_STATUS_TIMEOUT);
+                               task_notify(st->ct->task, E_STATUS_TIMEOUT);
                        goto out;
                }
                btr_merge(st->btrn, st->min_iqs);
                sz = btr_next_buffer(st->btrn, &buf);
                ret = for_each_stat_item(buf, sz, update_item);
                if (ret < 0) {
-                       task_notify(&st->ct->task, -ret);
+                       task_notify(st->ct->task, -ret);
                        goto out;
                }
                if (sz != ret) {
index d3ad23a4267d18d18ff3490d9d25b88cc6b5a945..88b1e93a024f7028709614be0b2e763d1091697d 100644 (file)
--- a/client.c
+++ b/client.c
@@ -537,8 +537,8 @@ static int supervisor_post_select(struct sched *s, struct task *t)
 {
        struct supervisor_task *svt = task_context(t);
 
-       if (ct->task.error < 0)
-               return ct->task.error;
+       if (ct->task->error < 0)
+               return ct->task->error;
        if (!svt->stdout_task_started && ct->status == CL_EXECUTING) {
                stdout_task_register(&sot, s);
                svt->stdout_task_started = true;
@@ -606,8 +606,8 @@ int main(int argc, char *argv[])
        }, &sched);
 
        ret = schedule(&sched);
-       if (ret >= 0 && ct->task.error < 0) {
-               switch(ct->task.error) {
+       if (ret >= 0 && ct->task->error < 0) {
+               switch (ct->task->error) {
                /* these are not errors */
                case -E_SERVER_CMD_SUCCESS:
                case -E_EOF:
index e304f0923693b5913a5224c4be8327a0fa6795f1..0a0c55cba0077cecaeb665b86542dc5a038e7d7d 100644 (file)
--- a/client.h
+++ b/client.h
@@ -47,7 +47,7 @@ struct client_task {
        /** Paraslash user name. */
        char *user;
        /** The client task structure. */
-       struct task task;
+       struct task *task;
        /** List of features supported by the server. */
        char **features;
 };
index 8212abb1d611dcff88889fa70629fcdc9f6eb5cf..df279129411b9cfaca3d7529654e59509b11029b 100644 (file)
@@ -70,7 +70,7 @@ void client_close(struct client_task *ct)
 static void client_pre_select(struct sched *s, struct task *t)
 {
        int ret;
-       struct client_task *ct = container_of(t, struct client_task, task);
+       struct client_task *ct = task_context(t);
 
        if (ct->scc.fd < 0)
                return;
@@ -283,7 +283,7 @@ static int send_sb_command(struct client_task *ct)
  */
 static int client_post_select(struct sched *s, struct task *t)
 {
-       struct client_task *ct = container_of(t, struct client_task, task);
+       struct client_task *ct = task_context(t);
        int ret = 0;
        size_t n;
        char buf[CLIENT_BUFSIZE];
@@ -496,11 +496,13 @@ int client_connect(struct client_task *ct, struct sched *s,
                EMBRACE(.name = "client recv", .parent = NULL, .child = child));
        ct->btrn[1] = btr_new_node(&(struct btr_node_description)
                EMBRACE(.name = "client send", .parent = parent, .child = NULL));
-       ct->task.pre_select = client_pre_select;
-       ct->task.post_select = client_post_select;
-       ct->task.error = 0;
-       sprintf(ct->task.status, "client");
-       register_task(s, &ct->task);
+
+       ct->task = task_register(&(struct task_info) {
+               .name = "client",
+               .pre_select = client_pre_select,
+               .post_select = client_post_select,
+               .context = ct,
+       }, s);
        return 1;
 err_out:
        close(ct->scc.fd);