Пример #1
0
void HSS::set_key_id() {

	query = "select key_id from ue_data where imsi = " + to_string(ue_data.imsi) + " and msisdn = " + to_string(ue_data.msisdn);
	db_client.perform_query(query.c_str());
	query_res = mysql_fetch_row(db_client.result);
	handle_query_error();
	res_row = query_res[0];	
	ue_data.key_id = stoull(res_row);
}
Пример #2
0
void HSS::set_autn_tokens() {
	int i;

	curr_time = time(0);
	local_time = localtime(&curr_time);
	curr_sec = local_time->tm_sec;
	query = "select * from ue_autn where autn like '%" + to_string(curr_sec) + "'";
	db_client.perform_query(query.c_str());
	num_fields = mysql_num_fields(db_client.result);
	query_res = mysql_fetch_row(db_client.result);
	handle_query_error();
	for (i = 0; i < num_fields; i++) {
		res_row = query_res[i];
		if (i == 0) {
			ue_data.autn_num = stoull(res_row);
		}
		else {
			ue_data.rand_num = stoull(res_row);
		}
	}
}
Пример #3
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;
		}
	}
}