lua/api: simplify & improve session_item_configure
This commit is contained in:
@@ -1040,8 +1040,6 @@ session_item_configure (lua_State *L)
|
|||||||
g_auto (GVariantBuilder) b =
|
g_auto (GVariantBuilder) b =
|
||||||
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
|
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
|
||||||
GVariant *config = NULL;
|
GVariant *config = NULL;
|
||||||
gboolean is_key = TRUE;
|
|
||||||
const gchar *key = NULL;
|
|
||||||
|
|
||||||
/* validate arguments */
|
/* validate arguments */
|
||||||
luaL_checktype (L, 2, LUA_TTABLE);
|
luaL_checktype (L, 2, LUA_TTABLE);
|
||||||
@@ -1049,48 +1047,24 @@ session_item_configure (lua_State *L)
|
|||||||
/* build the configuration */
|
/* build the configuration */
|
||||||
lua_pushnil (L);
|
lua_pushnil (L);
|
||||||
while (lua_next (L, 2)) {
|
while (lua_next (L, 2)) {
|
||||||
if (is_key) {
|
const gchar *key = NULL;
|
||||||
is_key = FALSE;
|
GVariant *var = NULL;
|
||||||
key = lua_tostring (L, -1);
|
|
||||||
} else {
|
switch (lua_type (L, -1)) {
|
||||||
is_key = TRUE;
|
case LUA_TUSERDATA: {
|
||||||
switch (lua_type (L, -1)) {
|
GValue *v = lua_touserdata (L, -1);
|
||||||
case LUA_TBOOLEAN:
|
gpointer p = g_value_peek_pointer (v);
|
||||||
g_variant_builder_add (&b, "{sv}", key,
|
var = g_variant_new_uint64 ((guint64) p);
|
||||||
g_variant_new_boolean (lua_toboolean (L, -1)));
|
break;
|
||||||
break;
|
|
||||||
case LUA_TNUMBER:
|
|
||||||
g_variant_builder_add (&b, "{sv}", key,
|
|
||||||
g_variant_new_int64 (lua_tointeger (L, -1)));
|
|
||||||
break;
|
|
||||||
case LUA_TSTRING:
|
|
||||||
g_variant_builder_add (&b, "{sv}", key,
|
|
||||||
g_variant_new_string (lua_tostring (L, -1)));
|
|
||||||
break;
|
|
||||||
case LUA_TUSERDATA: {
|
|
||||||
GValue *v = lua_touserdata (L, -1);
|
|
||||||
gpointer p = NULL;
|
|
||||||
if (G_VALUE_HOLDS_OBJECT (v)) {
|
|
||||||
p = g_value_get_object (v);
|
|
||||||
} else if (G_VALUE_HOLDS_BOXED (v)) {
|
|
||||||
p = g_value_get_boxed (v);
|
|
||||||
} else if (G_VALUE_HOLDS_POINTER (v)) {
|
|
||||||
p = g_value_get_pointer (v);
|
|
||||||
} else {
|
|
||||||
luaL_error (L, "Key '%s' does not hold a valid pointer", key);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_variant_builder_add (&b, "{sv}", key,
|
|
||||||
g_variant_new_uint64 ((guint64)p));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
luaL_error (L, "Key '%s' with value type '%s' is not supported", key,
|
|
||||||
lua_typename(L, lua_type(L, -1)));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
var = wplua_lua_to_gvariant (L, -1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
lua_pop (L, 1);
|
|
||||||
|
key = luaL_tolstring (L, -2, NULL);
|
||||||
|
g_variant_builder_add (&b, "{sv}", key, var);
|
||||||
|
lua_pop (L, 2);
|
||||||
}
|
}
|
||||||
config = g_variant_builder_end (&b);
|
config = g_variant_builder_end (&b);
|
||||||
|
|
||||||
|
@@ -32,12 +32,12 @@ function addEndpoint (node, session_name, endpoint_type, priority)
|
|||||||
session_items.endpoints[id] = SessionItem ( endpoint_type )
|
session_items.endpoints[id] = SessionItem ( endpoint_type )
|
||||||
|
|
||||||
-- configure endpoint
|
-- configure endpoint
|
||||||
if not session_items.endpoints[id]:configure ({
|
if not session_items.endpoints[id]:configure {
|
||||||
"node", node,
|
["node"] = node,
|
||||||
"name", name,
|
["name"] = name,
|
||||||
"media-class", media_class,
|
["media-class"] = media_class,
|
||||||
"priority", priority,
|
["priority"] = priority,
|
||||||
}) then
|
} then
|
||||||
Log.warning(node, "failed to configure endpoint");
|
Log.warning(node, "failed to configure endpoint");
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -56,9 +56,9 @@ function addEndpoint (node, session_name, endpoint_type, priority)
|
|||||||
local monitor = SessionItem ( "si-monitor-endpoint" )
|
local monitor = SessionItem ( "si-monitor-endpoint" )
|
||||||
|
|
||||||
-- configure monitor
|
-- configure monitor
|
||||||
if not monitor:configure ({
|
if not monitor:configure {
|
||||||
"adapter", session_items.endpoints[id]
|
["adapter"] = session_items.endpoints[id]
|
||||||
}) then
|
} then
|
||||||
Log.warning(monitor, "failed to configure monitor " .. name);
|
Log.warning(monitor, "failed to configure monitor " .. name);
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user