void cmd_reverse(char **args) { if (!prof_win_exists(echo_win)) { prof_win_create(echo_win, handle_reverse); } prof_win_focus(echo_win); if (args[0] != NULL) { handle_reverse(echo_win, args[0]); } }
static void trains_server(void) { register_as("trains"); struct trainsrv_state state; trainsrv_state_init(&state); train_alert_start(switch_historical_get_current(&state.switch_history), true); // TODO: we should block the creating task from continuing until init is done for (;;) { int tid = -1; struct trains_request req; receive(&tid, &req, sizeof(req)); /* printf("Trains server got message! %d"EOL, req.type); */ switch (req.type) { case QUERY_ACTIVE: { int active_trains[MAX_ACTIVE_TRAINS]; int num_active_trains = handle_query_active(&state, active_trains); reply(tid, &active_trains, num_active_trains * sizeof(active_trains[0])); break; } case QUERY_SPATIALS: { struct train_state ts = handle_query_spatials(&state, req.train_number); reply(tid, &ts, sizeof(ts)); break; } case QUERY_ARRIVAL: { int ticks = handle_query_arrival(&state, req.train_number, req.distance); reply(tid, &ticks, sizeof(ticks)); break; } case QUERY_ERROR: { int error = handle_query_error(&state, req.train_number); reply(tid, &error, sizeof(error)); break; } case SEND_SENSORS: handle_sensors(&state, req.sensors); reply(tid, NULL, 0); break; case SET_SPEED: handle_set_speed(&state, req.train_number, req.speed); reply(tid, NULL, 0); break; case REVERSE: handle_reverse(&state, req.train_number); reply(tid, NULL, 0); break; case REVERSE_UNSAFE: handle_reverse_unsafe(&state, req.train_number); reply(tid, NULL, 0); break; case SWITCH_SWITCH: handle_switch(&state, req.switch_number, req.direction); reply(tid, NULL, 0); break; case SWITCH_GET: { struct switch_state switches = switch_historical_get_current(&state.switch_history); reply(tid, &switches, sizeof(switches)); break; } case GET_STOPPING_DISTANCE: { struct internal_train_state *ts = get_train_state(&state, req.train_number); int distance = ts->est_stopping_distances[train_speed_index(ts, 1)]; reply(tid, &distance, sizeof(distance)); break; } case SET_STOPPING_DISTANCE: { struct internal_train_state *ts = get_train_state(&state, req.train_number); ts->est_stopping_distances[train_speed_index(ts, 1)] = req.stopping_distance; reply(tid, NULL, 0); break; } case GET_LAST_KNOWN_SENSOR: { struct internal_train_state *ts = get_train_state(&state, req.train_number); int last_sensor_hit = sensor_historical_get_current(&ts->sensor_history); reply(tid, &last_sensor_hit, sizeof(last_sensor_hit)); break; } default: nameserver_dump_names(); WTF("UNKNOWN TRAINS REQ %d FROM %d"EOL, req.type, tid); break; } } }