[PATCH] openbsc[master]: move to libxsc: global vty gsm_network pointer

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

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Fri Oct 21 00:01:11 UTC 2016


Review at  https://gerrit.osmocom.org/1133

move to libxsc: global vty gsm_network pointer

Move gsmnet_from_vty() and the bsc_gsmnet global to xsc_vty.c.

Rename bsc_gsmnet to vty_global_gsm_network and make it static to xsc_vty.c, to
clearly mark the global variable for VTY use only.

Introduce xsc_vty_init() to set vty_global_gsm_network.

Change-Id: I26c5c47de08f899b896813d09612d5cb2f8e42d6
---
M openbsc/include/openbsc/xsc.h
M openbsc/src/libbsc/bsc_vty.c
M openbsc/src/libxsc/xsc_vty.c
3 files changed, 32 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/33/1133/1

diff --git a/openbsc/include/openbsc/xsc.h b/openbsc/include/openbsc/xsc.h
index 172d6e6..a2f43eb 100644
--- a/openbsc/include/openbsc/xsc.h
+++ b/openbsc/include/openbsc/xsc.h
@@ -7,6 +7,8 @@
 
 typedef int (*mncc_recv_cb_t)(struct gsm_network *, struct msgb *);
 
+struct vty;
+
 #define MAX_A5_KEY_LEN	(128/8)
 
 struct gsm_encr {
@@ -19,3 +21,6 @@
 				     uint16_t country_code,
 				     uint16_t network_code,
 				     mncc_recv_cb_t mncc_recv);
+
+int xsc_vty_init(struct gsm_network *network);
+struct gsm_network *gsmnet_from_vty(struct vty *v);
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index cb0b1d8..020fba3 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -131,21 +131,6 @@
 	1,
 };
 
-extern struct gsm_network *bsc_gsmnet;
-
-struct gsm_network *gsmnet_from_vty(struct vty *v)
-{
-	/* In case we read from the config file, the vty->priv cannot
-	 * point to a struct telnet_connection, and thus conn->priv
-	 * will not point to the gsm_network structure */
-#if 0
-	struct telnet_connection *conn = v->priv;
-	return (struct gsm_network *) conn->priv;
-#else
-	return bsc_gsmnet;
-#endif
-}
-
 static int dummy_config_write(struct vty *v)
 {
 	return CMD_SUCCESS;
@@ -3939,7 +3924,7 @@
 	uint8_t buf[88];
 	int rc;
 
-	bts = gsm_bts_num(bsc_gsmnet, bts_nr);
+	bts = gsm_bts_num(gsmnet_from_vty(vty), bts_nr);
 	if (!bts) {
 		vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
 		return CMD_WARNING;
@@ -3990,7 +3975,7 @@
 	int ts_nr = atoi(argv[2]);
 	int activate;
 
-	bts = gsm_bts_num(bsc_gsmnet, bts_nr);
+	bts = gsm_bts_num(gsmnet_from_vty(vty), bts_nr);
 	if (!bts) {
 		vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE);
 		return CMD_WARNING;
@@ -4052,6 +4037,7 @@
 					   "BTS Vendor/Type\n",
 					   "\n", "", 0);
 
+	xsc_vty_init(network);
 
 	install_element_ve(&show_net_cmd);
 	install_element_ve(&show_bts_cmd);
diff --git a/openbsc/src/libxsc/xsc_vty.c b/openbsc/src/libxsc/xsc_vty.c
index 141179b..0de4a9d 100644
--- a/openbsc/src/libxsc/xsc_vty.c
+++ b/openbsc/src/libxsc/xsc_vty.c
@@ -1,6 +1,7 @@
 /* Code used by both libbsc and libmsc (xsc means "BSC or MSC").
  *
  * (C) 2016 by sysmocom s.m.f.c. <info at sysmocom.de>
+ * (C) 2008-2010 by Harald Welte <laforge at gnumonks.org>
  * All Rights Reserved
  *
  * This program is free software; you can redistribute it and/or modify
@@ -17,3 +18,26 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
+
+#include <openbsc/gsm_data.h>
+
+static struct gsm_network *vty_global_gsm_network = NULL;
+
+/* initialize VTY elements used in both BSC and MSC */
+int xsc_vty_init(struct gsm_network *network)
+{
+	OSMO_ASSERT(vty_global_gsm_network == NULL);
+	vty_global_gsm_network = network;
+}
+
+struct gsm_network *gsmnet_from_vty(struct vty *v)
+{
+	/* It can't hurt to force callers to continue to pass the vty instance
+	 * to this function, in case we'd like to retrieve the global
+	 * gsm_network instance from the vty at some point in the future. But
+	 * until then, just return the global pointer, which should have been
+	 * initialized by xsc_vty_init().
+	 */
+	OSMO_ASSERT(vty_global_gsm_network);
+	return vty_global_gsm_network;
+}

-- 
To view, visit https://gerrit.osmocom.org/1133
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I26c5c47de08f899b896813d09612d5cb2f8e42d6
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list