038fc0134e52adcc041fa52c152a321b9818b58e
2 * Copyright (C) 1997-2011 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file client.c the client program used to connect to para_server */
16 #include "client.cmdline.h"
21 #include "buffer_tree.h"
26 static struct sched sched
;
27 static struct client_task
*ct
;
28 static struct stdin_task sit
;
29 static struct stdout_task sot
;
31 static void supervisor_post_select(struct sched
*s
, struct task
*t
)
33 if (ct
->task
.error
< 0) {
34 t
->error
= ct
->task
.error
;
37 if (ct
->status
== CL_SENDING
) {
38 stdin_set_defaults(&sit
);
39 register_task(s
, &sit
.task
);
40 t
->error
= -E_TASK_STARTED
;
43 if (ct
->status
== CL_RECEIVING
) {
44 stdout_set_defaults(&sot
);
45 register_task(s
, &sot
.task
);
46 t
->error
= -E_TASK_STARTED
;
51 static struct task svt
= {
52 .post_select
= supervisor_post_select
,
53 .status
= "supervisor task"
56 static int client_loglevel
= LL_ERROR
; /* loglevel */
57 INIT_STDERR_LOGGING(client_loglevel
);
60 * The client program to connect to para_server.
62 * \param argc Usual argument count.
63 * \param argv Usual argument vector.
65 * It registers two tasks: The client task that communicates with para_server
66 * and the supervisor task that minitors whether the client task intends to
67 * read from stdin or write to stdout.
69 * Once it has been determined whether the client command corresponds to a
70 * stdin command (addmood, addimg, ..), either the stdin task or the stdout
71 * task is set up to replace the supervisor task.
73 * \return EXIT_SUCCESS or EXIT_FAILURE
75 * \sa client_open(), stdin.c, stdout.c, para_client(1), para_server(1)
77 int main(int argc
, char *argv
[])
81 static struct sched s
;
83 init_random_seed_or_die();
84 s
.default_timeout
.tv_sec
= 1;
85 s
.default_timeout
.tv_usec
= 0;
88 * We add buffer tree nodes for stdin and stdout even though
89 * only one of them will be needed. This simplifies the code
90 * a bit wrt. to the buffer tree setup.
92 sit
.btrn
= btr_new_node(&(struct btr_node_description
)
93 EMBRACE(.name
= "stdin"));
94 ret
= client_open(argc
, argv
, &ct
, &client_loglevel
, sit
.btrn
, NULL
, &sched
);
97 sot
.btrn
= btr_new_node(&(struct btr_node_description
)
98 EMBRACE(.name
= "stdout", .parent
= ct
->btrn
));
99 register_task(&sched
, &svt
);
100 ret
= schedule(&sched
);
103 btr_free_node(sit
.btrn
);
104 btr_free_node(sot
.btrn
);
106 /* can not use PARA_LOG here because ct is NULL */
107 fprintf(stderr
, "%s\n", para_strerror(-ret
));