author | viric@llimona |
Sun, 25 Mar 2007 04:55:18 +0200 | |
changeset 23 | 96fcebb68510 |
parent 22 | afdc8410633f |
child 27 | 886bdb2f4632 |
permissions | -rw-r--r-- |
1 | 1 |
#include <assert.h> |
9 | 2 |
#include <stdio.h> |
1 | 3 |
#include "msg.h" |
3 | 4 |
#include "main.h" |
1 | 5 |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
6 |
static void c_end_of_job(int errorlevel); |
8 | 7 |
|
3 | 8 |
void c_new_job(const char *command) |
9 |
{ |
|
10 |
struct msg m; |
|
11 |
||
12 |
m.type = NEWJOB; |
|
13 |
||
8 | 14 |
/* global */ |
18 | 15 |
m.u.newjob.command_size = strlen(command) + 1; /* add null */ |
3 | 16 |
|
18 | 17 |
/* Send the message */ |
18 |
send_msg(server_socket, &m); |
|
19 |
||
20 |
/* Send the command */ |
|
21 |
send_bytes(server_socket, command, m.u.newjob.command_size); |
|
3 | 22 |
} |
23 |
||
22 | 24 |
void c_wait_server_commands(const char *my_command, int store_output) |
3 | 25 |
{ |
26 |
struct msg m; |
|
27 |
int res; |
|
28 |
||
29 |
while (1) |
|
30 |
{ |
|
9 | 31 |
res = recv(server_socket, &m, sizeof(m), 0); |
3 | 32 |
if(res == -1) |
9 | 33 |
{ |
3 | 34 |
perror("read"); |
9 | 35 |
exit(-1); |
36 |
} |
|
3 | 37 |
|
38 |
if (res == 0) |
|
39 |
break; |
|
9 | 40 |
if (res != sizeof(m)) |
41 |
{ |
|
42 |
fprintf(stderr, "c: recv() message size wrong: %i instead of %i\n", |
|
43 |
res, (int) sizeof(m)); |
|
44 |
} |
|
3 | 45 |
assert(res == sizeof(m)); |
4 | 46 |
msgdump(&m); |
3 | 47 |
if (m.type == NEWJOB_OK) |
48 |
; |
|
8 | 49 |
if (m.type == RUNJOB) |
5 | 50 |
{ |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
51 |
int errorlevel; |
22 | 52 |
/* This will send RUNJOB_OK */ |
53 |
errorlevel = run_job(my_command, store_output); |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
54 |
c_end_of_job(errorlevel); |
8 | 55 |
break; |
5 | 56 |
} |
57 |
} |
|
58 |
} |
|
59 |
||
60 |
void c_wait_server_lines() |
|
61 |
{ |
|
62 |
struct msg m; |
|
63 |
int res; |
|
64 |
||
65 |
while (1) |
|
66 |
{ |
|
21 | 67 |
res = recv_msg(server_socket, &m); |
5 | 68 |
if(res == -1) |
22 | 69 |
{ |
5 | 70 |
perror("read"); |
22 | 71 |
exit(-1); |
72 |
} |
|
5 | 73 |
|
74 |
if (res == 0) |
|
75 |
break; |
|
76 |
assert(res == sizeof(m)); |
|
77 |
if (m.type == LIST_LINE) |
|
78 |
{ |
|
21 | 79 |
char * buffer; |
80 |
buffer = (char *) malloc(m.u.line_size); |
|
81 |
recv_bytes(server_socket, buffer, m.u.line_size); |
|
82 |
printf("%s", buffer); |
|
83 |
free(buffer); |
|
5 | 84 |
} |
3 | 85 |
} |
86 |
} |
|
87 |
||
8 | 88 |
void c_list_jobs() |
3 | 89 |
{ |
90 |
struct msg m; |
|
91 |
int res; |
|
92 |
||
93 |
m.type = LIST; |
|
94 |
||
9 | 95 |
res = send(server_socket, &m, sizeof(m), 0); |
3 | 96 |
if(res == -1) |
9 | 97 |
perror("send"); |
3 | 98 |
} |
99 |
||
22 | 100 |
void c_send_runjob_ok(int store_output, const char *ofname) |
101 |
{ |
|
102 |
struct msg m; |
|
103 |
int res; |
|
104 |
||
105 |
/* Prepare the message */ |
|
106 |
m.type = RUNJOB_OK; |
|
107 |
m.u.runjob_ok.store_output = store_output; |
|
108 |
if (store_output) |
|
109 |
m.u.runjob_ok.ofilename_size = strlen(ofname) + 1; |
|
110 |
else |
|
111 |
m.u.runjob_ok.ofilename_size = 0; |
|
112 |
||
113 |
send_msg(server_socket, &m); |
|
114 |
||
115 |
/* Send the filename */ |
|
116 |
if (store_output) |
|
117 |
send_bytes(server_socket, ofname, m.u.runjob_ok.ofilename_size); |
|
118 |
} |
|
119 |
||
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
120 |
static void c_end_of_job(int errorlevel) |
8 | 121 |
{ |
122 |
struct msg m; |
|
123 |
int res; |
|
124 |
||
125 |
m.type = ENDJOB; |
|
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
18
diff
changeset
|
126 |
m.u.errorlevel = errorlevel; |
8 | 127 |
|
9 | 128 |
res = send(server_socket, &m, sizeof(m),0); |
8 | 129 |
if(res == -1) |
9 | 130 |
perror("send"); |
8 | 131 |
} |
132 |
||
3 | 133 |
int c_shutdown_server() |
1 | 134 |
{ |
2 | 135 |
struct msg m; |
136 |
int res; |
|
1 | 137 |
|
2 | 138 |
m.type = KILL; |
9 | 139 |
res = send(server_socket, &m, sizeof(m), 0); |
2 | 140 |
assert(res != -1); |
1 | 141 |
} |
20
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
142 |
|
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
143 |
int c_clear_finished() |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
144 |
{ |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
145 |
struct msg m; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
146 |
int res; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
147 |
|
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
148 |
m.type = CLEAR_FINISHED; |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
149 |
res = send(server_socket, &m, sizeof(m), 0); |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
150 |
assert(res != -1); |
d85b4c0745fa
"-c" added, for clearing the finished tasks' list.
viric@llimona
parents:
19
diff
changeset
|
151 |
} |