Change in osmo-msc[master]: SMS: remove code duplication in transaction init

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Thu Jan 17 12:17:53 UTC 2019


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

Change subject: SMS: remove code duplication in transaction init
......................................................................

SMS: remove code duplication in transaction init

Move code which allocates transaction for SMS and initializes
corresponding FSM into separate function (shared by MT and MO code
paths) to avoid code duplication and simplify further modifications.

Change-Id: I3563e11bebb58e656592df2ff7db96f41deaf735
---
M src/libmsc/gsm_04_11.c
1 file changed, 28 insertions(+), 25 deletions(-)

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



diff --git a/src/libmsc/gsm_04_11.c b/src/libmsc/gsm_04_11.c
index 8ef26a7..4dc07bd 100644
--- a/src/libmsc/gsm_04_11.c
+++ b/src/libmsc/gsm_04_11.c
@@ -1007,6 +1007,27 @@
 	return rc;
 }
 
+static struct gsm_trans *gsm411_trans_init(struct gsm_network *net, struct vlr_subscr *vsub, struct ran_conn *conn,
+					   uint8_t tid)
+{
+	/* Allocate a new transaction */
+	struct gsm_trans *trans = trans_alloc(net, vsub, GSM48_PDISC_SMS, tid, new_callref++);
+	if (!trans) {
+		LOGP(DLSMS, LOGL_ERROR, "No memory for transaction\n");
+		return NULL;
+	}
+
+	/* Init both SMC and SMR state machines */
+	gsm411_smc_init(&trans->sms.smc_inst, 0, 1, gsm411_mn_recv, gsm411_mm_send);
+	gsm411_smr_init(&trans->sms.smr_inst, 0, 1, gsm411_rl_recv, gsm411_mn_send);
+
+	/* Associate transaction with connection */
+	if (conn)
+		trans->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_SMS);
+
+	return trans;
+}
+
 static struct gsm_trans *gsm411_alloc_mt_trans(struct gsm_network *net,
 					       struct vlr_subscr *vsub)
 {
@@ -1023,24 +1044,15 @@
 		return NULL;
 	}
 
-	/* Allocate a new transaction */
-	trans = trans_alloc(net, vsub, GSM48_PDISC_SMS, tid, new_callref++);
-	if (!trans) {
-		LOGP(DLSMS, LOGL_ERROR, "No memory for trans\n");
-		return NULL;
-	}
-
-	/* Init both SMC and SMR state machines */
-	gsm411_smc_init(&trans->sms.smc_inst, 0, 1,
-		gsm411_mn_recv, gsm411_mm_send);
-	gsm411_smr_init(&trans->sms.smr_inst, 0, 1,
-		gsm411_rl_recv, gsm411_mn_send);
-
 	/* Attempt to find an existing connection */
 	conn = connection_for_subscr(vsub);
+
+	/* Allocate a new transaction */
+	trans = gsm411_trans_init(net, vsub, conn, tid);
+	if (!trans)
+		return NULL;
+
 	if (conn) {
-		/* Associate transaction with connection */
-		trans->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_SMS);
 		/* Generate unique RP Message Reference */
 		trans->sms.sm_rp_mr = conn->next_rp_ref++;
 	}
@@ -1192,21 +1204,12 @@
 	}
 
 	if (!trans) {
-		DEBUGP(DLSMS, " -> (new transaction)\n");
-		trans = trans_alloc(conn->network, conn->vsub,
-				    GSM48_PDISC_SMS,
-				    transaction_id, new_callref++);
+		trans = gsm411_trans_init(conn->network, conn->vsub, conn, transaction_id);
 		if (!trans) {
-			DEBUGP(DLSMS, " -> No memory for trans\n");
 			/* FIXME: send some error message */
 			return -ENOMEM;
 		}
-		gsm411_smc_init(&trans->sms.smc_inst, 0, 1,
-			gsm411_mn_recv, gsm411_mm_send);
-		gsm411_smr_init(&trans->sms.smr_inst, 0, 1,
-			gsm411_rl_recv, gsm411_mn_send);
 
-		trans->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_SMS);
 		trans->dlci = OMSC_LINKID_CB(msg); /* DLCI as received from BSC */
 
 		new_trans = 1;

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

Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3563e11bebb58e656592df2ff7db96f41deaf735
Gerrit-Change-Number: 12578
Gerrit-PatchSet: 2
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190117/28f8c953/attachment.htm>


More information about the gerrit-log mailing list