30 int size =
sizeof(
state);
38 fprintf(stderr,
"Usage: mtransition [-v] [-d debug_flag] [-f] [-h Hostname] [-e Experiment] commands...\n");
39 fprintf(stderr,
"Options:\n");
40 fprintf(stderr,
" -v - report activity\n");
41 fprintf(stderr,
" -d debug_flag - passed through cm_transition(debug_flag): 0=normal, 1=printf, 2=cm_msg(MINFO)\n");
42 fprintf(stderr,
" -f - force new state regardless of current state\n");
43 fprintf(stderr,
" -m - multithread transition\n");
44 fprintf(stderr,
" -a - async multithread transition\n");
45 fprintf(stderr,
" -h Hostname - connect to mserver on remote host\n");
46 fprintf(stderr,
" -e Experiment - connect to non-default experiment\n");
47 fprintf(stderr,
"Commands:\n");
48 fprintf(stderr,
" START [runno] - start a new run\n");
49 fprintf(stderr,
" STOP - stop the run\n");
50 fprintf(stderr,
" PAUSE - pause the run\n");
51 fprintf(stderr,
" RESUME - resume the run\n");
52 fprintf(stderr,
" STARTABORT - cleanup after failed START\n");
53 fprintf(stderr,
" DELAY 100 - sleep for 100 seconds\n");
54 fprintf(stderr,
" DELAY \"/logger/Auto restart delay\" - sleep for time specified in ODB variable\n");
55 fprintf(stderr,
" IF \"/logger/Auto restart\" - continue only if ODB variable is set to TRUE\n");
61int main(
int argc,
char *argv[])
67 bool multithread =
false;
68 bool asyncmultithread =
false;
76 signal(SIGPIPE, SIG_IGN);
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')
93 else if (argv[
i][1] ==
'a')
94 asyncmultithread =
true;
95 else if (argv[
i][1] ==
'm')
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)
120 fprintf(stderr,
"Error: Cannot connect to experiment \'%s\' on host \'%s\', status %d\n",
128 printf(
"Connected to experiment \'%s\' on host \'%s\'\n",
exp_name.c_str(),
host_name.c_str());
138 if (asyncmultithread)
141 for (
int i=1;
i<argc;
i++) {
143 if (argv[
i][0] ==
'-') {
147 if (argv[
i][1] ==
'd')
149 else if (argv[
i][1] ==
'h')
151 if (argv[
i][1] ==
'e')
156 }
else if (strcmp(argv[
i],
"START") == 0) {
164 printf(
"START: Run is already started\n");
169 printf(
"START: Run is paused, please use \"RESUME\"\n");
176 int old_run_number = 0;
177 int size =
sizeof(old_run_number);
180 assert(old_run_number >= 0);
182 int new_run_number = old_run_number + 1;
185 if (isdigit(argv[
i+1][0])) {
186 new_run_number = atoi(argv[
i+1]);
192 printf(
"Starting run %d\n", new_run_number);
201 printf(
"START: cm_transition status %d, message \'%s\'\n",
status,
str);
204 }
else if (strcmp(argv[
i],
"STOP") == 0) {
211 printf(
"Run is already stopped, stopping again.\n");
218 printf(
"STOP: cm_transition status %d, message \'%s\'\n",
status,
str);
220 }
else if (strcmp(argv[
i],
"PAUSE") == 0) {
227 printf(
"PAUSE: Run is already paused\n");
232 printf(
"PAUSE: Run is not started\n");
242 printf(
"PAUSE: cm_transition status %d, message \'%s\'\n",
status,
str);
244 }
else if (strcmp(argv[
i],
"RESUME") == 0) {
249 printf(
"RESUME: Run is already running\n");
252 printf(
"RESUME: Run is not paused\n");
261 printf(
"RESUME: cm_transition status %d, message \'%s\'\n",
status,
str);
263 }
else if (strcmp(argv[
i],
"STARTABORT") == 0) {
268 printf(
"STARTABORT: cm_transition status %d, message \'%s\'\n",
status,
str);
270 }
else if (strcmp(argv[
i],
"DELAY") == 0) {
272 if (argv[
i+1] == NULL) {
273 fprintf(stderr,
"Command DELAY requires an argument\n");
277 const char* arg = argv[++
i];
280 if (isdigit(arg[0])) {
282 }
else if (arg[0] ==
'/') {
283 int size =
sizeof(delay);
286 fprintf(stderr,
"DELAY: Cannot read ODB variable \'%s\', status %d\n", arg,
status);
294 printf(
"DELAY \'%s\' %d sec\n", arg, delay);
299 }
else if (strcmp(argv[
i],
"IF") == 0) {
301 if (argv[
i+1] == NULL) {
302 fprintf(stderr,
"Command IF requires an argument\n");
306 const char* arg = argv[++
i];
309 if (isdigit(arg[0])) {
311 }
else if (arg[0] ==
'/') {
312 int size =
sizeof(
value);
318 fprintf(stderr,
"IF: Cannot read ODB variable \'%s\', status %d\n", arg,
status);
326 printf(
"IF \'%s\' value %d\n", arg,
value);
336 fprintf(stderr,
"Unknown command \'%s\'\n", argv[
i]);
346 printf(
"waiting for transition to finish!\n");
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)