tbf: Move enable_egprs() to constructor

Whether the TBF is GPRS or EGPRS is known at allocation time since it
comes from the information known in the MS object used to create it.
Hence, no need to delay calling it to later steps such as setup().

So far it was probably left in setup() due to the constrains about
requiring the subclass to be constructed (use of window() virtual API).

Change-Id: I2e9d2a98c666a930333d52fb6c0463d7593c2615
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 2f832a5..05d83f9 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -575,9 +575,6 @@
 {
 	int rc;
 
-	if (ms_mode(m_ms) != GPRS)
-		enable_egprs();
-
 	/* select algorithm */
 	rc = the_pcu->alloc_algorithm(bts, this, single_slot, use_trx);
 	/* if no resource */
diff --git a/src/tbf.h b/src/tbf.h
index b033590..3f58cd2 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -254,13 +254,13 @@
 
 protected:
 	void merge_and_clear_ms(GprsMs *old_ms);
+	void enable_egprs(void);
 
 	gprs_llc_queue *llc_queue();
 	const gprs_llc_queue *llc_queue() const;
 
 	struct GprsMs *m_ms;
 private:
-	void enable_egprs();
 	bool m_egprs_enabled;
 	struct osmo_timer_list Tarr[T_MAX];
 	uint8_t Narr[N_MAX];
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index cdd703c..628d593 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -183,6 +183,11 @@
 	state_fsm.dl_tbf = this;
 	state_fi = osmo_fsm_inst_alloc(&tbf_dl_fsm, this, &state_fsm, LOGL_INFO, NULL);
 	OSMO_ASSERT(state_fi);
+
+	/* This has to be called in child constructor because enable_egprs()
+	 * uses the window() virtual function which is dependent on subclass. */
+	if (ms_mode(m_ms) != GPRS)
+		enable_egprs();
 }
 
 /**
diff --git a/src/tbf_ul.cpp b/src/tbf_ul.cpp
index a6c4ee3..16ef304 100644
--- a/src/tbf_ul.cpp
+++ b/src/tbf_ul.cpp
@@ -189,6 +189,11 @@
 	OSMO_ASSERT(m_ul_egprs_ctrs);
 	m_ul_gprs_ctrs = rate_ctr_group_alloc(this, &tbf_ul_gprs_ctrg_desc, m_ctrs->idx);
 	OSMO_ASSERT(m_ul_gprs_ctrs);
+
+	/* This has to be called in child constructor because enable_egprs()
+	 * uses the window() virtual function which is dependent on subclass. */
+	if (ms_mode(m_ms) != GPRS)
+		enable_egprs();
 }
 
 /*
diff --git a/tests/tbf/TbfTest.err b/tests/tbf/TbfTest.err
index 79c89b1..e17a6a8 100644
--- a/tests/tbf/TbfTest.err
+++ b/tests/tbf/TbfTest.err
@@ -9771,15 +9771,15 @@
 DL_ASS_TBF{NONE}: Allocated
 UL_TBF{NEW}: Allocated
 UL_ACK_TBF{NONE}: Allocated
-TBF(UL:TFI-0-0--1:STATE-NEW:GPRS:TLLI-0xffeeddd3) Setting Control TS PDCH(bts=0,trx=0,ts=7)
-MS(TLLI-0xffeeddd3:TA-7:MSCLS-11-11) Attaching UL TBF: TBF(UL:TFI-0-0--1:STATE-NEW:GPRS:TLLI-0xffeeddd3)
+TBF(UL:TFI-0-0--1:STATE-NEW:EGPRS:TLLI-0xffeeddd3) Setting Control TS PDCH(bts=0,trx=0,ts=7)
+MS(TLLI-0xffeeddd3:TA-7:MSCLS-11-11) Attaching UL TBF: TBF(UL:TFI-0-0--1:STATE-NEW:EGPRS:TLLI-0xffeeddd3)
 MS(TLLI-0xffeeddd3:TA-7:MSCLS-11-11:UL): + tbf: now used by 2 (rcv_resource_request,tbf)
-UL_TBF(UL:TFI-0-0--1:STATE-NEW:GPRS:TLLI-0xffeeddd3){NEW}: Received Event ASSIGN_ADD_PACCH
-TBF(UL:TFI-0-0--1:STATE-NEW:GPRS:TLLI-0xffeeddd3) set ass. type PACCH [prev CCCH:0, PACCH:0]
-UL_TBF(UL:TFI-0-0--1:STATE-NEW:GPRS:TLLI-0xffeeddd3){NEW}: state_chg to ASSIGN
-TBF(UL:TFI-0-0--1:STATE-ASSIGN:GPRS:TLLI-0xffeeddd3) Starting timer X2001 [assignment (PACCH)] with 2 sec. 0 microsec
-UL_ASS_TBF(UL:TFI-0-0--1:STATE-NEW:GPRS:TLLI-0xffeeddd3){NONE}: Received Event SCHED_ASS_REJ
-UL_ASS_TBF(UL:TFI-0-0--1:STATE-NEW:GPRS:TLLI-0xffeeddd3){NONE}: state_chg to SEND_ASS_REJ
+UL_TBF(UL:TFI-0-0--1:STATE-NEW:EGPRS:TLLI-0xffeeddd3){NEW}: Received Event ASSIGN_ADD_PACCH
+TBF(UL:TFI-0-0--1:STATE-NEW:EGPRS:TLLI-0xffeeddd3) set ass. type PACCH [prev CCCH:0, PACCH:0]
+UL_TBF(UL:TFI-0-0--1:STATE-NEW:EGPRS:TLLI-0xffeeddd3){NEW}: state_chg to ASSIGN
+TBF(UL:TFI-0-0--1:STATE-ASSIGN:EGPRS:TLLI-0xffeeddd3) Starting timer X2001 [assignment (PACCH)] with 2 sec. 0 microsec
+UL_ASS_TBF(UL:TFI-0-0--1:STATE-NEW:EGPRS:TLLI-0xffeeddd3){NONE}: Received Event SCHED_ASS_REJ
+UL_ASS_TBF(UL:TFI-0-0--1:STATE-NEW:EGPRS:TLLI-0xffeeddd3){NONE}: state_chg to SEND_ASS_REJ
 MS(TLLI-0xffeeddd3:TA-7:MSCLS-11-11:UL): - rcv_resource_request: now used by 1 (tbf)
 PDCH(bts=0,trx=0,ts=7) Expiring FN=82 but previous FN=2654231 is still reserved!
 PDCH(bts=0,trx=0,ts=7) Timeout for registered POLL (FN=2654231, reason=UL_ASS): TBF(UL:TFI-0-0-6:STATE-ASSIGN:EGPRS:TLLI-0xffeeddd2)
@@ -9798,7 +9798,7 @@
 UL_ASS_TBF(UL:TFI-0-0-0:STATE-NEW:EGPRS:TLLI-0xffeeddcc){SEND_ASS}: state_chg to WAIT_ACK
 PDCH(bts=0,trx=0,ts=7) FN=2654218 Scheduling control message at RTS for TBF(UL:TFI-0-0-0:STATE-ASSIGN:EGPRS:TLLI-0xffeeddcc)
 MS(TLLI-0xffeeddd3:TA-7:MSCLS-11-11:UL) Destroying MS object
-MS(TLLI-0xffeeddd3:TA-7:MSCLS-11-11:UL) Detaching TBF: TBF(UL:TFI-0-0--1:STATE-ASSIGN:GPRS:TLLI-0xffeeddd3)
+MS(TLLI-0xffeeddd3:TA-7:MSCLS-11-11:UL) Detaching TBF: TBF(UL:TFI-0-0--1:STATE-ASSIGN:EGPRS:TLLI-0xffeeddd3)
 MS(TLLI-0xffeeddd3:TA-7:MSCLS-11-11): - tbf: now used by 0 (-)
 MS(TLLI-0xffeeddd2:TA-7:MSCLS-11-11:UL) Destroying MS object
 MS(TLLI-0xffeeddd2:TA-7:MSCLS-11-11:UL) Detaching TBF: TBF(UL:TFI-0-0-6:STATE-ASSIGN:EGPRS:TLLI-0xffeeddd2)