/** * Handle start of output. */ static iks *prompt_component_handle_output_start(struct rayo_actor *prompt, struct rayo_message *msg, void *data) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s) output start\n", RAYO_JID(prompt), prompt_component_state_to_string(PROMPT_COMPONENT(prompt)->state)); switch (PROMPT_COMPONENT(prompt)->state) { case PCS_START_OUTPUT: PROMPT_COMPONENT(prompt)->output_jid = switch_core_strdup(RAYO_POOL(prompt), msg->from_jid); PROMPT_COMPONENT(prompt)->state = PCS_OUTPUT; /* send ref to client */ rayo_component_send_start(RAYO_COMPONENT(prompt), PROMPT_COMPONENT(prompt)->iq); break; case PCS_START_OUTPUT_BARGE: PROMPT_COMPONENT(prompt)->output_jid = switch_core_strdup(RAYO_POOL(prompt), msg->from_jid); PROMPT_COMPONENT(prompt)->state = PCS_START_INPUT_OUTPUT; /* start input without timers and with barge events */ start_input(PROMPT_COMPONENT(prompt), 0, 1); break; case PCS_OUTPUT: case PCS_START_INPUT_OUTPUT: case PCS_START_INPUT: case PCS_START_INPUT_TIMERS: case PCS_INPUT_OUTPUT: case PCS_STOP_OUTPUT: case PCS_INPUT: case PCS_DONE_STOP_OUTPUT: case PCS_DONE: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, unexpected start output event\n", RAYO_JID(prompt)); break; } return NULL; }
/** * Handle completion event */ static iks *prompt_component_handle_output_complete(struct rayo_actor *prompt, struct rayo_message *msg, void *data) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s) output complete\n", RAYO_JID(prompt), prompt_component_state_to_string(PROMPT_COMPONENT(prompt)->state)); switch (PROMPT_COMPONENT(prompt)->state) { case PCS_OUTPUT: PROMPT_COMPONENT(prompt)->state = PCS_START_INPUT; /* start input with timers enabled and barge events disabled */ start_input(PROMPT_COMPONENT(prompt), 1, 0); iks_delete(PROMPT_COMPONENT(prompt)->iq); break; case PCS_START_INPUT_OUTPUT: /* output finished before input started */ PROMPT_COMPONENT(prompt)->state = PCS_START_INPUT_TIMERS; break; case PCS_INPUT_OUTPUT: PROMPT_COMPONENT(prompt)->state = PCS_INPUT; start_input_timers(PROMPT_COMPONENT(prompt)); break; case PCS_STOP_OUTPUT: PROMPT_COMPONENT(prompt)->state = PCS_INPUT; start_input_timers(PROMPT_COMPONENT(prompt)); break; case PCS_DONE_STOP_OUTPUT: if (PROMPT_COMPONENT(prompt)->complete) { rayo_component_send_complete_event(RAYO_COMPONENT(prompt), PROMPT_COMPONENT(prompt)->complete); } break; case PCS_INPUT: case PCS_START_OUTPUT: case PCS_START_OUTPUT_BARGE: case PCS_START_INPUT: case PCS_START_INPUT_TIMERS: case PCS_DONE: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, unexpected start output error event\n", RAYO_JID(prompt)); break; } return NULL; }
int main(int argc, char *argv[]) { int rc; gamut_opts opts; signal(SIGPIPE, SIG_IGN); memset(&opts, 0, sizeof(opts)); /* Use line buffering for stdout */ setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); rc = parse_opts(argc, argv, &opts); if(rc < 0) { s_log(G_EMERG, "Error parsing options.\n"); exit(EXIT_FAILURE); } else if(!rc) { usage(argv[0]); exit(EXIT_FAILURE); } /* * In this order, perform these steps (if necessary) * 1. Redirect to a log file * 2. Restore benchmark data from a file * 3. Run the benchmarks * 4. Save the new benchmark data * 5. Quit after benchmarks * 6. Run calibration (if no benchmark data) * 7. Run a trace file and exit * 8. Accept commands from stdin */ /* * 1. Redirect to a log file */ if(redirect_stdout) { redirect_output(); } /* * 2. Restore benchmark data from a file */ if(load_benchmarks) { s_log(G_NOTICE, "Loading benchmark data ... "); load_benchmark_data(); s_log(G_NOTICE, "done.\n"); } /* * 3. Run the benchmarks */ if(run_benchmarks) { s_log(G_NOTICE, "Running %u calibration trials.\n", DEF_BMARK_TRIALS); benchmark_delays(DEF_BMARK_TRIALS); } /* * 4. Save the new benchmark data */ if(save_benchmarks) { s_log(G_NOTICE, "Saving benchmark data ... "); save_benchmark_data(); s_log(G_NOTICE, "done.\n"); /* * 5. Quit after benchmarks */ if(quit_benchmarks) exit(EXIT_SUCCESS); } /* * 6. Run calibration (if no benchmark data is available yet) */ if(!load_benchmarks && !run_benchmarks) { s_log(G_NOTICE, "Calibrating node attributes ... "); benchmark_delays(1); s_log(G_NOTICE, "done.\n"); } init_opts(&opts); start_reaper(&opts); start_input(&opts); execute_gamut(&opts); stop_input(&opts); killall_workers(&opts); stop_reaper(&opts); return 0; }