Max has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/13163 )

Change subject: MCS: move Mode enum outside of class definition
......................................................................

MCS: move Mode enum outside of class definition

Move Mode (EDGE/GPRS) definition and related functions outside of
GprsCodingScheme class. This allows us to use standard libosmocore
value_string functions.

Change-Id: I3baaac7f1ca3f5b88917a23c1679d63847455f47
---
M src/coding_scheme.c
M src/coding_scheme.h
M src/gprs_coding_scheme.cpp
M src/gprs_coding_scheme.h
M src/gprs_ms.cpp
M src/gprs_ms.h
M src/pcu_vty_functions.cpp
M src/tbf.cpp
M tests/edge/EdgeTest.cpp
9 files changed, 50 insertions(+), 51 deletions(-)

Approvals:
  osmith: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/coding_scheme.c b/src/coding_scheme.c
index 93278e7..135ddd2 100644
--- a/src/coding_scheme.c
+++ b/src/coding_scheme.c
@@ -85,3 +85,14 @@
        OSMO_ASSERT(ht < NUM_HEADER_TYPES);
        return hdr_type_info[ht].data_block_header_bits;
 }
+
+const struct value_string mode_names[] = {
+       { GPRS, "GPRS" },
+       { EGPRS_GMSK, "EGPRS_GMSK-only"},
+       { EGPRS, "EGPRS"},
+       { 0, NULL }
+};
+
+const char *mode_name(enum mcs_kind val) {
+       return get_value_string(mode_names, val);
+}
diff --git a/src/coding_scheme.h b/src/coding_scheme.h
index 1e8ca78..f69a76e 100644
--- a/src/coding_scheme.h
+++ b/src/coding_scheme.h
@@ -49,3 +49,11 @@
 uint8_t num_data_header_bits_UL(enum HeaderType ht);
 uint8_t num_data_header_bits_DL(enum HeaderType ht);
 uint8_t num_data_block_header_bits(enum HeaderType ht);
+
+enum mcs_kind {
+       GPRS,
+       EGPRS_GMSK,
+       EGPRS,
+};
+
+const char *mode_name(enum mcs_kind val);
diff --git a/src/gprs_coding_scheme.cpp b/src/gprs_coding_scheme.cpp
index 53b3b07..1a89b77 100644
--- a/src/gprs_coding_scheme.cpp
+++ b/src/gprs_coding_scheme.cpp
@@ -198,7 +198,7 @@
        return mcs_info[m_scheme].data_hdr;
 }

-void GprsCodingScheme::inc(Mode mode)
+void GprsCodingScheme::inc(enum mcs_kind mode)
 {
        if (!isCompatible(mode))
                /* This should not happen. TODO: Use assert? */
@@ -212,7 +212,7 @@
        m_scheme = new_cs;
 }

-void GprsCodingScheme::dec(Mode mode)
+void GprsCodingScheme::dec(enum mcs_kind mode)
 {
        if (!isCompatible(mode))
                /* This should not happen. TODO: Use assert? */
@@ -254,16 +254,6 @@
        m_scheme = CodingScheme(m_scheme - 1);
 }

-const char *GprsCodingScheme::modeName(Mode mode)
-{
-       switch (mode) {
-       case GPRS:       return "GPRS";
-       case EGPRS_GMSK: return "EGPRS_GMSK-only";
-       case EGPRS:      return "EGPRS";
-       default:         return "???";
-       }
-}
-
 bool GprsCodingScheme::isFamilyCompatible(GprsCodingScheme o) const
 {
        if (*this == o)
diff --git a/src/gprs_coding_scheme.h b/src/gprs_coding_scheme.h
index 055c166..6f965d6 100644
--- a/src/gprs_coding_scheme.h
+++ b/src/gprs_coding_scheme.h
@@ -34,12 +34,6 @@
 #define EGPRS_ARQ1            0x0
 #define EGPRS_ARQ2            0x1

-       enum Mode {
-               GPRS,
-               EGPRS_GMSK,
-               EGPRS,
-       };
-
        GprsCodingScheme(CodingScheme s = UNKNOWN);

        operator bool() const {return m_scheme != UNKNOWN;}
@@ -54,12 +48,12 @@
        bool isGprs()   const {return CS1 <= m_scheme && m_scheme <= CS4;}
        bool isEgprs()  const {return m_scheme >= MCS1;}
        bool isEgprsGmsk()  const {return isEgprs() && m_scheme <= MCS4;}
-       bool isCompatible(Mode mode) const;
+       bool isCompatible(enum mcs_kind mode) const;
        bool isCompatible(GprsCodingScheme o) const;
        bool isFamilyCompatible(GprsCodingScheme o) const;

-       void inc(Mode mode);
-       void dec(Mode mode);
+       void inc(enum mcs_kind mode);
+       void dec(enum mcs_kind mode);
        void inc();
        void dec();
        void decToSingleBlock(bool *needStuffing);
@@ -81,7 +75,6 @@
        static GprsCodingScheme getGprsByNum(unsigned num);
        static GprsCodingScheme getEgprsByNum(unsigned num);

-       static const char *modeName(Mode mode);
        static CodingScheme get_retx_mcs(const GprsCodingScheme mcs,
                                const GprsCodingScheme retx_mcs,
                                const unsigned arq_type);
@@ -102,7 +95,7 @@
        return 0;
 }

-inline bool GprsCodingScheme::isCompatible(Mode mode) const
+inline bool GprsCodingScheme::isCompatible(enum mcs_kind mode) const
 {
        switch (mode) {
        case GPRS: return isGprs();
diff --git a/src/gprs_ms.cpp b/src/gprs_ms.cpp
index 3c28319..e64bee4 100644
--- a/src/gprs_ms.cpp
+++ b/src/gprs_ms.cpp
@@ -110,7 +110,7 @@
        m_reserved_ul_slots(0),
        m_current_trx(NULL),
        m_codel_state(NULL),
-       m_mode(GprsCodingScheme::GPRS),
+       m_mode(GPRS),
        m_dl_ctrl_msg(0)
 {
        int codel_interval = LLC_CODEL_USE_DEFAULT;
@@ -213,7 +213,7 @@
        unref();
 }

-void GprsMs::set_mode(GprsCodingScheme::Mode mode)
+void GprsMs::set_mode(enum mcs_kind mode)
 {
        m_mode = mode;

@@ -221,7 +221,7 @@
                return;

        switch (m_mode) {
-       case GprsCodingScheme::GPRS:
+       case GPRS:
                if (!m_current_cs_ul.isGprs()) {
                        m_current_cs_ul = GprsCodingScheme::getGprsByNum(
                                m_bts->bts_data()->initial_cs_ul);
@@ -236,8 +236,8 @@
                }
                break;

-       case GprsCodingScheme::EGPRS_GMSK:
-       case GprsCodingScheme::EGPRS:
+       case EGPRS_GMSK:
+       case EGPRS:
                if (!m_current_cs_ul.isEgprs()) {
                        m_current_cs_ul = GprsCodingScheme::getEgprsByNum(
                                m_bts->bts_data()->initial_mcs_ul);
diff --git a/src/gprs_ms.h b/src/gprs_ms.h
index 0a9efb8..ad8ca1d 100644
--- a/src/gprs_ms.h
+++ b/src/gprs_ms.h
@@ -74,8 +74,8 @@
        bool check_tlli(uint32_t tlli);

        void reset();
-       GprsCodingScheme::Mode mode() const;
-       void set_mode(GprsCodingScheme::Mode mode);
+       enum mcs_kind mode() const;
+       void set_mode(enum mcs_kind mode);

        const char *imsi() const;
        void set_imsi(const char *imsi);
@@ -181,7 +181,7 @@
        gprs_rlcmac_trx *m_current_trx;

        struct gprs_codel *m_codel_state;
-       GprsCodingScheme::Mode m_mode;
+       enum mcs_kind m_mode;

        unsigned m_dl_ctrl_msg;
 };
@@ -237,7 +237,7 @@
        return m_current_cs_ul;
 }

-inline GprsCodingScheme::Mode GprsMs::mode() const
+inline enum mcs_kind GprsMs::mode() const
 {
        return m_mode;
 }
diff --git a/src/pcu_vty_functions.cpp b/src/pcu_vty_functions.cpp
index 47a0559..c93935d 100644
--- a/src/pcu_vty_functions.cpp
+++ b/src/pcu_vty_functions.cpp
@@ -79,7 +79,7 @@
                        ul_tbf->window_size(), win->v_q(), win->v_r());
                vty_out(vty, "%s", VTY_NEWLINE);
                vty_out(vty, " TBF Statistics:%s", VTY_NEWLINE);
-               if(GprsCodingScheme::GPRS == tbf->ms()->mode()) {
+               if(GPRS == tbf->ms()->mode()) {
                        vty_out_rate_ctr_group(vty, " ", 
ul_tbf->m_ul_gprs_ctrs);
                } else {
                        vty_out_rate_ctr_group(vty, " ", 
ul_tbf->m_ul_egprs_ctrs);
@@ -92,7 +92,7 @@
                        win->window_stalled() ? " STALLED" : "");
                vty_out(vty, "%s", VTY_NEWLINE);
                vty_out_rate_ctr_group(vty, " ", tbf->m_ctrs);
-               if(GprsCodingScheme::GPRS == tbf->ms()->mode()) {
+               if(GPRS == tbf->ms()->mode()) {
                        vty_out_rate_ctr_group(vty, " ", 
dl_tbf->m_dl_gprs_ctrs);
                } else {
                        vty_out_rate_ctr_group(vty, " ", 
dl_tbf->m_dl_egprs_ctrs);
@@ -153,8 +153,7 @@
                VTY_NEWLINE);
        vty_out(vty, "  Coding scheme downlink: %s%s", 
mcs_name(ms->current_cs_dl()),
                VTY_NEWLINE);
-       vty_out(vty, "  Mode:                   %s%s",
-               GprsCodingScheme::modeName(ms->mode()), VTY_NEWLINE);
+       vty_out(vty, "  Mode:                   %s%s", mode_name(ms->mode()), 
VTY_NEWLINE);
        vty_out(vty, "  MS class:               %d%s", ms->ms_class(), 
VTY_NEWLINE);
        vty_out(vty, "  EGPRS MS class:         %d%s", ms->egprs_ms_class(), 
VTY_NEWLINE);
        vty_out(vty, "  PACCH:                  ");
diff --git a/src/tbf.cpp b/src/tbf.cpp
index ffe8b82..3d9b5c4 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -897,7 +897,7 @@

        bts = tbf->bts->bts_data();

-       if (ms->mode() == GprsCodingScheme::EGPRS)
+       if (ms->mode() == EGPRS)
                ms_class = egprs_ms_class;

        tbf->m_created_ts = time(NULL);
@@ -954,11 +954,11 @@
 {
        if (GprsCodingScheme::getEgprsByNum(bts->max_mcs_ul).isEgprsGmsk() &&
                GprsCodingScheme::getEgprsByNum(bts->max_mcs_dl).isEgprsGmsk() 
&&
-               ms->mode() != GprsCodingScheme::EGPRS)
+               ms->mode() != EGPRS)
        {
-               ms->set_mode(GprsCodingScheme::EGPRS_GMSK);
+               ms->set_mode(EGPRS_GMSK);
        } else {
-               ms->set_mode(GprsCodingScheme::EGPRS);
+               ms->set_mode(EGPRS);
        }
 }

@@ -992,8 +992,7 @@
        if (egprs_ms_class > 0 && bts->egprs_enabled) {
                tbf->enable_egprs();
                setup_egprs_mode(bts, ms);
-               LOGPTBF(tbf, LOGL_INFO, "Enabled EGPRS, mode %s\n",
-                       GprsCodingScheme::modeName(ms->mode()));
+               LOGPTBF(tbf, LOGL_INFO, "Enabled EGPRS, mode %s\n", 
mode_name(ms->mode()));
        }

        rc = setup_tbf(tbf, ms, use_trx, ms_class, egprs_ms_class, single_slot);
@@ -1085,8 +1084,7 @@
        if (egprs_ms_class > 0 && bts->egprs_enabled) {
                tbf->enable_egprs();
                setup_egprs_mode(bts, ms);
-               LOGPTBF(tbf, LOGL_INFO, "Enabled EGPRS, mode %s\n",
-                       GprsCodingScheme::modeName(ms->mode()));
+               LOGPTBF(tbf, LOGL_INFO, "Enabled EGPRS, mode %s\n", 
mode_name(ms->mode()));
        }

        rc = setup_tbf(tbf, ms, use_trx, ms_class, 0, single_slot);
diff --git a/tests/edge/EdgeTest.cpp b/tests/edge/EdgeTest.cpp
index 41a1115..b902806 100644
--- a/tests/edge/EdgeTest.cpp
+++ b/tests/edge/EdgeTest.cpp
@@ -48,7 +48,7 @@
 int16_t spoof_mnc = 0, spoof_mcc = 0;
 bool spoof_mnc_3_digits = false;

-static void check_coding_scheme(GprsCodingScheme& cs, GprsCodingScheme::Mode 
mode)
+static void check_coding_scheme(GprsCodingScheme& cs, enum mcs_kind mode)
 {
        volatile unsigned expected_size;
        bool need_padding;
@@ -148,9 +148,9 @@
        OSMO_ASSERT(!cs);
        OSMO_ASSERT(CodingScheme(cs) == UNKNOWN);
        OSMO_ASSERT(cs == GprsCodingScheme(UNKNOWN));
-       OSMO_ASSERT(!cs.isCompatible(GprsCodingScheme::GPRS));
-       OSMO_ASSERT(!cs.isCompatible(GprsCodingScheme::EGPRS_GMSK));
-       OSMO_ASSERT(!cs.isCompatible(GprsCodingScheme::EGPRS));
+       OSMO_ASSERT(!cs.isCompatible(GPRS));
+       OSMO_ASSERT(!cs.isCompatible(EGPRS_GMSK));
+       OSMO_ASSERT(!cs.isCompatible(EGPRS));

        last_size_UL = 0;
        last_size_DL = 0;
@@ -170,7 +170,7 @@
                /* Check header types */
                OSMO_ASSERT(current_cs.headerTypeData() == HEADER_GPRS_DATA);

-               check_coding_scheme(current_cs, GprsCodingScheme::GPRS);
+               check_coding_scheme(current_cs, GPRS);
        }
        OSMO_ASSERT(i == 4);

@@ -190,8 +190,8 @@
                last_size_DL = current_cs.maxBytesDL();

                if (egprs_schemes[i].is_gmsk)
-                       check_coding_scheme(current_cs, 
GprsCodingScheme::EGPRS_GMSK);
-               check_coding_scheme(current_cs, GprsCodingScheme::EGPRS);
+                       check_coding_scheme(current_cs, EGPRS_GMSK);
+               check_coding_scheme(current_cs, EGPRS);
        }
        OSMO_ASSERT(i == 9);


--
To view, visit https://gerrit.osmocom.org/13163
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3baaac7f1ca3f5b88917a23c1679d63847455f47
Gerrit-Change-Number: 13163
Gerrit-PatchSet: 7
Gerrit-Owner: Max <msur...@sysmocom.de>
Gerrit-Reviewer: André Boddenberg <dr.bl...@gmail.com>
Gerrit-Reviewer: Daniel Willmann <dwillm...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de>
Gerrit-Reviewer: osmith <osm...@sysmocom.de>

Reply via email to