Change in osmo-remsim[master]: remsim-client: Avoid using 'ci' global variable

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/.

laforge gerrit-no-reply at lists.osmocom.org
Tue Dec 17 00:19:37 UTC 2019


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-remsim/+/16625 )


Change subject: remsim-client: Avoid using 'ci' global variable
......................................................................

remsim-client: Avoid using 'ci' global variable

Rather, pass it around between functions and attach it to other state.

Also, make it a talloc contxt so other objects can be allocated off it.

Change-Id: I25f592581382238d5640c1f6326dec745f8d1d40
---
M src/client/client.h
M src/client/simtrace2-remsim_client.c
2 files changed, 16 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-remsim refs/changes/25/16625/1

diff --git a/src/client/client.h b/src/client/client.h
index 96a454f..f36e2e3 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -11,6 +11,8 @@
 
 /* main.c */
 
+struct cardem_inst;
+
 struct bankd_client {
 	/* connection to the remsim-server (control) */
 	struct rspro_server_conn srv_conn;
@@ -21,4 +23,6 @@
 	struct app_comp_id peer_comp_id;
 
 	struct bank_slot bankd_slot;
+
+	struct cardem_inst *cardem;
 };
diff --git a/src/client/simtrace2-remsim_client.c b/src/client/simtrace2-remsim_client.c
index 1af3274..190eb90 100644
--- a/src/client/simtrace2-remsim_client.c
+++ b/src/client/simtrace2-remsim_client.c
@@ -679,17 +679,13 @@
 	.slot_nr = 0,
 };
 
-struct cardem_inst _ci = {
-	.slot = &_slot,
-};
-
-struct cardem_inst *ci = &_ci;
+static struct cardem_inst *g_ci;
 
 static void signal_handler(int signal)
 {
 	switch (signal) {
 	case SIGINT:
-		cardem_request_card_insert(ci, false);
+		cardem_request_card_insert(g_ci, false);
 		exit(0);
 		break;
 	default:
@@ -714,9 +710,9 @@
 	ac.sw[1] = card2modem->data.buf[card2modem->data.size - 1];
 	printf("SIMtrace <= SW=0x%02x%02x, len_rx=%d\n", ac.sw[0], ac.sw[1], card2modem->data.size - 2);
 	if (card2modem->data.size > 2) { // send PB and data to modem
-		cardem_request_pb_and_tx(ci, ac.hdr.ins, card2modem->data.buf, card2modem->data.size - 2);
+		cardem_request_pb_and_tx(bc->cardem, ac.hdr.ins, card2modem->data.buf, card2modem->data.size - 2);
 	}
-	cardem_request_sw_tx(ci, ac.sw); // send SW to modem
+	cardem_request_sw_tx(bc->cardem, ac.sw); // send SW to modem
 
 	return 0;
 }
@@ -730,7 +726,7 @@
 	OSMO_ASSERT(RsproPDUchoice_PR_setAtrReq == pdu->msg.present);
 
 	/* FIXME: is this permitted at any time by the SIMtrace2 cardemfirmware? */
-	rc = cardem_request_set_atr(ci, pdu->msg.choice.setAtrReq.atr.buf,
+	rc = cardem_request_set_atr(bc->cardem, pdu->msg.choice.setAtrReq.atr.buf,
 				    pdu->msg.choice.setAtrReq.atr.size);
 	if (rc == 0)
 		resp = rspro_gen_SetAtrRes(ResultCode_ok);
@@ -998,7 +994,7 @@
 }
 
 
-static void main_body(struct client_config *cfg)
+static void main_body(struct cardem_inst *ci, struct client_config *cfg)
 {
 	struct st_transport *transp = ci->slot->transp;
 	struct usb_interface_match _ifm, *ifm = &_ifm;
@@ -1125,7 +1121,10 @@
 	msgb_talloc_ctx_init(g_tall_ctx, 0);
 	osmo_init_logging2(g_tall_ctx, &log_info);
 
-	cfg = client_config_init(g_tall_ctx);
+	g_ci = talloc_zero(g_tall_ctx, struct cardem_inst);
+	g_ci->slot = &_slot;
+
+	cfg = client_config_init(g_ci);
 	handle_options(cfg, argc, argv);
 
 	if (cfg->usb.vendor_id < 0 || cfg->usb.product_id < 0) {
@@ -1153,6 +1152,7 @@
 	// initialize remote SIM client
 
 	g_client = talloc_zero(g_tall_ctx, struct bankd_client);
+	g_client->cardem = g_ci;
 
 	if (cfg->client_id != -1) {
 		g_client->srv_conn.clslot = talloc_zero(g_client, ClientSlot_t);
@@ -1199,7 +1199,7 @@
 
 	// connect to SIMtrace2 cardem
 	do {
-		main_body(cfg);
+		main_body(g_ci, cfg);
 		sleep(1);
 	} while (cfg->keep_running);
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-remsim/+/16625
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-remsim
Gerrit-Branch: master
Gerrit-Change-Id: I25f592581382238d5640c1f6326dec745f8d1d40
Gerrit-Change-Number: 16625
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191217/8466c4da/attachment.htm>


More information about the gerrit-log mailing list