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 client_task *ct;
27 static struct stdin_task sit;
28 static struct stdout_task sot;
30 static void supervisor_post_select(__a_unused struct sched *s, struct task *t)
32 if (ct->task.error < 0) {
33 t->error = ct->task.error;
36 if (ct->status == CL_SENDING) {
37 stdin_set_defaults(&sit);
38 register_task(&sit.task);
39 t->error = -E_TASK_STARTED;
42 if (ct->status == CL_RECEIVING) {
43 stdout_set_defaults(&sot);
44 register_task(&sot.task);
45 t->error = -E_TASK_STARTED;
50 static struct task svt = {
51 .post_select = supervisor_post_select,
52 .status = "supervisor task"
55 static int client_loglevel = LL_ERROR; /* loglevel */
56 INIT_STDERR_LOGGING(client_loglevel);
59 * The client program to connect to para_server.
61 * \param argc Usual argument count.
62 * \param argv Usual argument vector.
64 * It registers two tasks: The client task that communicates with para_server
65 * and the supervisor task that minitors whether the client task intends to
66 * read from stdin or write to stdout.
68 * Once it has been determined whether the client command corresponds to a
69 * stdin command (addmood, addimg, ..), either the stdin task or the stdout
70 * task is set up to replace the supervisor task.
72 * \return EXIT_SUCCESS or EXIT_FAILURE
74 * \sa client_open(), stdin.c, stdout.c, para_client(1), para_server(1)
76 int main(int argc, char *argv[])
80 static struct sched s;
82 init_random_seed_or_die();
83 s.default_timeout.tv_sec = 1;
84 s.default_timeout.tv_usec = 0;
86 * We add buffer tree nodes for stdin and stdout even though
87 * only one of them will be needed. This simplifies the code
88 * a bit wrt. to the buffer tree setup.
90 sit.btrn = btr_new_node(&(struct btr_node_description)
91 EMBRACE(.name = "stdin"));
92 ret = client_open(argc, argv, &ct, &client_loglevel, sit.btrn, NULL);
95 sot.btrn = btr_new_node(&(struct btr_node_description)
96 EMBRACE(.name = "stdout", .parent = ct->btrn));
101 btr_free_node(sit.btrn);
102 btr_free_node(sot.btrn);
104 /* can not use PARA_LOG here because ct is NULL */
105 fprintf(stderr, "%s\n", para_strerror(-ret));