[PATCH] osmocom-bb[master]: mobile: Create "ms" singleton for struct osmocom_ms

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

Holger Freyther gerrit-no-reply at lists.osmocom.org
Wed Nov 15 06:30:17 UTC 2017


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

mobile: Create "ms" singleton for struct osmocom_ms

Make the MS the script is associated with accessible to lua. Provide
access to IMSI and IMEI. The IMSI might not be available at the given
time and just return an empty string.

Change-Id: Ia3ace33d6ba4e904b1ff8e271a02d67777334a58
---
M src/host/layer23/src/mobile/script_lua.c
1 file changed, 46 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/40/4840/1

diff --git a/src/host/layer23/src/mobile/script_lua.c b/src/host/layer23/src/mobile/script_lua.c
index 953fb36..53f1c57 100644
--- a/src/host/layer23/src/mobile/script_lua.c
+++ b/src/host/layer23/src/mobile/script_lua.c
@@ -164,8 +164,42 @@
 	{ NULL, NULL },
 };
 
+static int lua_osmo_ms(lua_State *L)
+{
+	lua_pushlightuserdata(L, get_primitive(L)->ms);
+	luaL_getmetatable(L, "MS");
+	lua_setmetatable(L, -2);
+
+	return 1;
+}
+
+static int lua_ms_imei(lua_State *L)
+{
+	struct osmocom_ms *ms = get_primitive(L)->ms;
+
+	luaL_argcheck(L, lua_isuserdata(L, -1), 1, "No userdata");
+	lua_pushstring(L, ms->settings.imei);
+	return 1;
+}
+static int lua_ms_imsi(lua_State *L)
+{
+	struct osmocom_ms *ms = get_primitive(L)->ms;
+
+	luaL_argcheck(L, lua_isuserdata(L, -1), 1, "No userdata");
+	lua_pushstring(L, ms->subscr.imsi);
+	return 1;
+}
+
+static const struct luaL_Reg ms_funcs[] = {
+	{ "imsi", lua_ms_imsi },
+	{ "imei", lua_ms_imei },
+	{ NULL, NULL },
+};
+
+
 static const struct luaL_Reg osmo_funcs[] = {
 	{ "timeout",	lua_osmo_timeout },
+	{ "ms",	lua_osmo_ms },
 	{ NULL, NULL },
 };
 
@@ -194,6 +228,16 @@
 	lua_pop(L, 1);
 }
 
+static void create_meta_table(lua_State *L, const char *name, const luaL_Reg *regs)
+{
+	luaL_newmetatable(L, name);
+	lua_pushliteral(L, "__index");
+	lua_pushvalue(L, -2);
+	lua_rawset(L, -3);
+	luaL_setfuncs(L, regs, 0);
+	lua_pop(L, 1);
+}
+
 static void add_runtime(lua_State *L, struct mobile_prim_intf *intf)
 {
 	add_globals(L);
@@ -204,13 +248,8 @@
 	lua_setglobal(L, "osmo");
 
 	/* Create metatables so we can GC objects... */
-	luaL_newmetatable(L, "Timer");
-	lua_pushliteral(L, "__index");
-	lua_pushvalue(L, -2);
-	lua_rawset(L, -3);
-	luaL_setfuncs(L, timer_funcs, 0);
-	lua_pop(L, 1);
-
+	create_meta_table(L, "Timer", timer_funcs);
+	create_meta_table(L, "MS", ms_funcs);
 
 	/* Remember the primitive pointer... store it in the registry */
 	lua_pushlightuserdata(L, lua_prim_key);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia3ace33d6ba4e904b1ff8e271a02d67777334a58
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <holger at freyther.de>



More information about the gerrit-log mailing list