From a174a47811f2168d63f6f021d3ed2f156bff9951 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 24 Sep 2015 11:39:38 +0200 Subject: amr: Kill more duplication and let the code work one of the modes --- openbsc/src/libbsc/bsc_vty.c | 59 +++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 34 deletions(-) (limited to 'openbsc') diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c index d94062412..f8ef833d2 100644 --- a/openbsc/src/libbsc/bsc_vty.c +++ b/openbsc/src/libbsc/bsc_vty.c @@ -479,6 +479,21 @@ static void config_write_bts_model(struct vty *vty, struct gsm_bts *bts) config_write_trx_single(vty, trx); } +static void write_amr_modes(struct vty *vty, const char *prefix, + const char *name, struct amr_mode *modes, int num) +{ + int i; + + vty_out(vty, " %s threshold %s", prefix, name); + for (i = 0; i < num - 1; i++) + vty_out(vty, " %d", modes[i].threshold); + vty_out(vty, "%s", VTY_NEWLINE); + vty_out(vty, " %s hysteresis %s", prefix, name); + for (i = 0; i < num - 1; i++) + vty_out(vty, " %d", modes[i].hysteresis); + vty_out(vty, "%s", VTY_NEWLINE); +} + static void config_write_bts_amr(struct vty *vty, struct gsm_bts *bts, struct amr_multirate_conf *mr, int full) { @@ -503,26 +518,8 @@ static void config_write_bts_amr(struct vty *vty, struct gsm_bts *bts, if (num > 4) num = 4; if (num > 1) { - vty_out(vty, " %s threshold ms", prefix); - for (i = 0; i < num - 1; i++) { - vty_out(vty, " %d", mr->ms_mode[i].threshold); - } - vty_out(vty, "%s", VTY_NEWLINE); - vty_out(vty, " %s hysteresis ms", prefix); - for (i = 0; i < num - 1; i++) { - vty_out(vty, " %d", mr->ms_mode[i].hysteresis); - } - vty_out(vty, "%s", VTY_NEWLINE); - vty_out(vty, " %s threshold bts", prefix); - for (i = 0; i < num - 1; i++) { - vty_out(vty, " %d", mr->bts_mode[i].threshold); - } - vty_out(vty, "%s", VTY_NEWLINE); - vty_out(vty, " %s hysteresis bts", prefix); - for (i = 0; i < num - 1; i++) { - vty_out(vty, " %d", mr->bts_mode[i].hysteresis); - } - vty_out(vty, "%s", VTY_NEWLINE); + write_amr_modes(vty, prefix, "ms", mr->ms_mode, num); + write_amr_modes(vty, prefix, "bts", mr->bts_mode, num); } vty_out(vty, " %s start-mode ", prefix); if (mr_conf->icmi) { @@ -2953,30 +2950,24 @@ static void get_amr_th_from_arg(struct vty *vty, int argc, const char *argv[], i { struct gsm_bts *bts = vty->index; struct amr_multirate_conf *mr = (full) ? &bts->mr_full: &bts->mr_half; + struct amr_mode *modes; int i; - if (argv[0][0]=='m') { - for (i = 0; i < argc - 1; i++) - mr->ms_mode[i].threshold = atoi(argv[i + 1]); - } else { - for (i = 0; i < argc - 1; i++) - mr->bts_mode[i].threshold = atoi(argv[i + 1]); - } + modes = argv[0][0]=='m' ? mr->ms_mode : mr->bts_mode; + for (i = 0; i < argc - 1; i++) + modes[i].threshold = atoi(argv[i + 1]); } static void get_amr_hy_from_arg(struct vty *vty, int argc, const char *argv[], int full) { struct gsm_bts *bts = vty->index; struct amr_multirate_conf *mr = (full) ? &bts->mr_full: &bts->mr_half; + struct amr_mode *modes; int i; - if (argv[0][0]=='m') { - for (i = 0; i < argc - 1; i++) - mr->ms_mode[i].hysteresis = atoi(argv[i + 1]); - } else { - for (i = 0; i < argc - 1; i++) - mr->bts_mode[i].hysteresis = atoi(argv[i + 1]); - } + modes = argv[0][0]=='m' ? mr->ms_mode : mr->bts_mode; + for (i = 0; i < argc - 1; i++) + modes[i].hysteresis = atoi(argv[i + 1]); } static void get_amr_start_from_arg(struct vty *vty, const char *argv[], int full) -- cgit v1.2.3