Exemple #1
0
/*!
 * \brief Parses configuration string for the switch
 * Parses a configuration string for switch settings and updates
 * the configuration structure.
 * \param settings the configuration string in the following form:
\verbatim
 *              <id>=<switch>[,<id>=<switch>]...
\endverbatim
 * \return 1 on success, -1 otherwise
 */
int conf_parse_switch(char *settings)
{
	/* make a copy since we are modifying it */
	int len = strlen(settings);
	if (len==0) return 1;
	char *strc = (char *)pkg_malloc(len+1);
	if (strc == NULL) {
		PKG_MEM_ERROR;
		return -1;
	}
	memcpy(strc, settings, len+1);
	remove_spaces(strc);

	char *set_p = strc;
	char *token = NULL;
	while ((token = strsep(&set_p, ","))) {  /* iterate through list of settings */
		char *id_str = strsep(&token, "=");
		int id = conf_str2id(id_str);
		if (id < 0) {
			LM_ERR("cannot parse id '%s'.\n", id_str);
			pkg_free(strc);
			return -1;
		}

		/* got all data for one setting -> update configuration now */
		if (update_switch(id, token) < 0) {
			LM_ERR("cannot update switch.\n");
			pkg_free(strc);
			return -1;
		}
	}

	pkg_free(strc);
	return 1;
}
Exemple #2
0
static void ensure_uncurved(struct trainsrv_state *state, int sw) {
	struct switch_state switches = \
		switch_historical_get_current(&state->switch_history);
	if (switch_get(&switches, sw) == CURVED) {
		tc_switch_switch(sw, STRAIGHT);
		tc_deactivate_switch();
		update_switch(state, sw, STRAIGHT);
	}
}
Exemple #3
0
static void handle_switch(struct trainsrv_state *state, int sw, enum sw_direction dir) {
	tc_switch_switch(sw, dir);
	tc_deactivate_switch();
	// On the middle switches, curved curved == BAD BAD. Prevent this
	// configuration by automatically rewriting it to curved straight, which
	// is probably what you want.
	if (sw == 153 && dir == CURVED) ensure_uncurved(state, 154);
	if (sw == 154 && dir == CURVED) ensure_uncurved(state, 153);
	if (sw == 155 && dir == CURVED) ensure_uncurved(state, 156);
	if (sw == 156 && dir == CURVED) ensure_uncurved(state, 155);
	update_switch(state, sw, dir);
}