62{
65 int debug_flag = 0;
66 bool force = false;
67 bool multithread = false;
68 bool asyncmultithread = false;
71
72 setbuf(stdout, NULL);
73 setbuf(stderr, NULL);
74
75#ifndef OS_WINNT
76 signal(SIGPIPE, SIG_IGN);
77#endif
78
79
81
82
83
84 if (argc < 2)
86
87 for (
int i = 1;
i < argc;
i++) {
88 if (argv[
i][0] ==
'-') {
89 if (argv[
i][1] ==
'v')
91 else if (argv[
i][1] ==
'f')
92 force = true;
93 else if (argv[
i][1] ==
'a')
94 asyncmultithread = true;
95 else if (argv[
i][1] ==
'm')
96 multithread = true;
97 else if (argv[
i][1] ==
'd' &&
i < argc-1)
98 debug_flag = strtoul(argv[++
i], NULL, 0);
99 else if (argv[
i][1] ==
'e' &&
i < argc-1)
101 else if (argv[
i][1] ==
'h' &&
i < argc-1)
103 else
105 }
106 }
107
108 if (debug_flag)
111 debug_flag = 1;
112
113
115
120 fprintf(stderr,"Error: Cannot connect to experiment \'%s\' on host \'%s\', status %d\n",
124 exit(1);
125 }
126
128 printf(
"Connected to experiment \'%s\' on host \'%s\'\n",
exp_name.c_str(),
host_name.c_str());
129
131
134
136 if (multithread)
138 if (asyncmultithread)
140
141 for (
int i=1;
i<argc;
i++) {
142
143 if (argv[
i][0] ==
'-') {
144
145
146
147 if (argv[
i][1] ==
'd')
149 else if (argv[
i][1] ==
'h')
151 if (argv[
i][1] ==
'e')
153
154 continue;
155
156 }
else if (strcmp(argv[
i],
"START") == 0) {
157
158
159
160
162
164 printf("START: Run is already started\n");
167 exit(1);
169 printf("START: Run is paused, please use \"RESUME\"\n");
172 exit(1);
173 }
174
175
176 int old_run_number = 0;
177 int size = sizeof(old_run_number);
180 assert(old_run_number >= 0);
181
182 int new_run_number = old_run_number + 1;
183
185 if (isdigit(argv[
i+1][0])) {
186 new_run_number = atoi(argv[
i+1]);
188 }
189 }
190
192 printf("Starting run %d\n", new_run_number);
193
197
200
201 printf(
"START: cm_transition status %d, message \'%s\'\n",
status,
str);
202 }
203
204 }
else if (strcmp(argv[
i],
"STOP") == 0) {
205
206
207
209
211 printf("Run is already stopped, stopping again.\n");
212 }
213
216
218 printf(
"STOP: cm_transition status %d, message \'%s\'\n",
status,
str);
219
220 }
else if (strcmp(argv[
i],
"PAUSE") == 0) {
221
222
223
225
227 printf("PAUSE: Run is already paused\n");
228 continue;
229 }
230
232 printf("PAUSE: Run is not started\n");
235 exit(1);
236 }
237
240
242 printf(
"PAUSE: cm_transition status %d, message \'%s\'\n",
status,
str);
243
244 }
else if (strcmp(argv[
i],
"RESUME") == 0) {
245
247
249 printf("RESUME: Run is already running\n");
250 continue;
252 printf("RESUME: Run is not paused\n");
255 exit(1);
256 }
257
261 printf(
"RESUME: cm_transition status %d, message \'%s\'\n",
status,
str);
262
263 }
else if (strcmp(argv[
i],
"STARTABORT") == 0) {
264
268 printf(
"STARTABORT: cm_transition status %d, message \'%s\'\n",
status,
str);
269
270 }
else if (strcmp(argv[
i],
"DELAY") == 0) {
271
272 if (argv[
i+1] == NULL) {
273 fprintf(stderr,"Command DELAY requires an argument\n");
275 }
276
277 const char* arg = argv[++
i];
278 int delay = 0;
279
280 if (isdigit(arg[0])) {
281 delay = atoi(arg);
282 } else if (arg[0] == '/') {
283 int size = sizeof(delay);
286 fprintf(stderr,
"DELAY: Cannot read ODB variable \'%s\', status %d\n", arg,
status);
289 exit(1);
290 }
291 }
292
294 printf("DELAY \'%s\' %d sec\n", arg, delay);
295
298
299 }
else if (strcmp(argv[
i],
"IF") == 0) {
300
301 if (argv[
i+1] == NULL) {
302 fprintf(stderr,"Command IF requires an argument\n");
304 }
305
306 const char* arg = argv[++
i];
308
309 if (isdigit(arg[0])) {
311 } else if (arg[0] == '/') {
312 int size =
sizeof(
value);
316 }
318 fprintf(stderr,
"IF: Cannot read ODB variable \'%s\', status %d\n", arg,
status);
321 exit(1);
322 }
323 }
324
326 printf(
"IF \'%s\' value %d\n", arg,
value);
327
331 exit(0);
332 }
333
334 } else {
335
336 fprintf(stderr,
"Unknown command \'%s\'\n", argv[
i]);
338
339 }
340 }
341
342 while (1) {
345 break;
346 printf("waiting for transition to finish!\n");
348 }
349
350
352
354
355 return 0;
356}
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_transition(INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag)
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
INT cm_disconnect_experiment(void)
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
INT cm_transition_cleanup()
INT ss_sleep(INT millisec)
INT cm_set_msg_print(INT system_mask, INT user_mask, int(*func)(const char *))
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
char exp_name[NAME_LENGTH]
char host_name[HOST_NAME_LENGTH]
#define DEFAULT_WATCHDOG_TIMEOUT
int read_state(HNDLE hDB)