[grilo-plugins] lua-factory: change grl.get_media_keys() into the static table
- From: Victor Toso de Carvalho <victortoso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] lua-factory: change grl.get_media_keys() into the static table
- Date: Sat, 30 Jan 2016 11:24:23 +0000 (UTC)
commit 3e409b7727f803e2be4427c7544c679373a7d926
Author: George Sedov <radist morse gmail com>
Date: Fri Nov 27 14:36:01 2015 +0300
lua-factory: change grl.get_media_keys() into the static table
It's part of the work aimed at removing the OperationSpec from the
global scope.
grl_l_media_get_keys was replaced by grl_lua_library_push_grl_media
Although the GrlMedia is now a parameter for the lua source, Grilo
expects that the same GrlMedia object will be returned in the callback
for the Resolve operation [0]; For that reason we still keep track of
GrlMedia and merge it with the resulting GrlMedia from Lua source.
[0] see https://bugzilla.gnome.org/show_bug.cgi?id=760382#c3
https://bugzilla.gnome.org/show_bug.cgi?id=753141
Acked-by: Victor Toso <me victortoso com>
src/lua-factory/grl-lua-common.h | 1 +
src/lua-factory/grl-lua-factory.c | 9 ++----
src/lua-factory/grl-lua-library.c | 47 +++++++++++++++++++++++++++---------
3 files changed, 39 insertions(+), 18 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-common.h b/src/lua-factory/grl-lua-common.h
index 79f8fd3..4a369dc 100644
--- a/src/lua-factory/grl-lua-common.h
+++ b/src/lua-factory/grl-lua-common.h
@@ -90,6 +90,7 @@ OperationSpec * grl_lua_library_get_current_operation (lua_State *L);
void grl_lua_library_save_goa_data (lua_State *L, gpointer goa_object);
gpointer grl_lua_library_load_goa_data (lua_State *L);
+void grl_lua_library_push_grl_media (lua_State *L, GrlMedia *media);
void grl_lua_library_push_grl_options (lua_State *L, guint operation_id, GrlOperationOptions *options, GList
*keys);
#endif /* _GRL_LUA_LIBRARY_COMMON_H_ */
diff --git a/src/lua-factory/grl-lua-factory.c b/src/lua-factory/grl-lua-factory.c
index 8954671..13cccc5 100644
--- a/src/lua-factory/grl-lua-factory.c
+++ b/src/lua-factory/grl-lua-factory.c
@@ -1521,16 +1521,12 @@ grl_lua_factory_source_browse (GrlSource *source,
GrlLuaFactorySource *lua_source = GRL_LUA_FACTORY_SOURCE (source);
lua_State *L = lua_source->priv->l_st;
OperationSpec *os = NULL;
- const gchar *media_id = NULL;
GRL_DEBUG ("grl_lua_factory_source_browse");
- media_id = bs->container ? grl_media_get_id (bs->container) : NULL;
-
os = g_slice_new0 (OperationSpec);
os->source = bs->source;
os->operation_id = bs->operation_id;
- os->media = bs->container;
os->cb.result = bs->callback;
os->user_data = bs->user_data;
os->error_code = GRL_CORE_ERROR_BROWSE_FAILED;
@@ -1540,7 +1536,7 @@ grl_lua_factory_source_browse (GrlSource *source,
grl_lua_library_set_current_operation (L, os->operation_id);
lua_getglobal (L, LUA_SOURCE_OPERATION[LUA_BROWSE]);
- lua_pushstring (L, media_id);
+ grl_lua_library_push_grl_media (L, bs->container);
grl_lua_library_push_grl_options (L, bs->operation_id, bs->options, bs->keys);
if (lua_pcall (L, 2, 0, 0)) {
@@ -1614,9 +1610,10 @@ grl_lua_factory_source_resolve (GrlSource *source,
grl_lua_library_set_current_operation (L, os->operation_id);
lua_getglobal (L, LUA_SOURCE_OPERATION[LUA_RESOLVE]);
+ grl_lua_library_push_grl_media (L, rs->media);
grl_lua_library_push_grl_options (L, rs->operation_id, rs->options, rs->keys);
- if (lua_pcall (L, 1, 0, 0)) {
+ if (lua_pcall (L, 2, 0, 0)) {
GRL_WARNING ("%s '%s'", "calling resolve function fail:",
lua_tolstring (L, -1, NULL));
lua_pop (L, 1);
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index 84ec452..390b003 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -809,24 +809,48 @@ fail:
}
/**
-* grl.get_media_keys
+* grl_lua_library_push_grl_media.
*
-* @return: table with all keys/values of media (may be empty);
+* Pushes the GrlMedia on top of the lua stack as a key-value table
+*
+* @L: LuaState where the data is stored.
+* @media: GrlMedia to be put.
+* @return: Nothing.
*/
-static gint
-grl_l_media_get_keys (lua_State *L)
+void
+grl_lua_library_push_grl_media (lua_State *L,
+ GrlMedia *media)
{
- OperationSpec *os;
GrlRegistry *registry;
GList *it;
GList *list_keys;
+ const gchar *media_type = NULL;
- os = grl_lua_library_get_current_operation (L);
- g_return_val_if_fail (os != NULL, 0);
+ if (media == NULL) {
+ lua_pushnil (L);
+ return;
+ }
registry = grl_registry_get_default ();
lua_newtable (L);
- list_keys = grl_data_get_keys (GRL_DATA (os->media));
+
+ if (grl_media_is_audio (media)) {
+ media_type = "audio";
+ } else if (grl_media_is_video (media)) {
+ media_type = "video";
+ } else if (grl_media_is_image (media)) {
+ media_type = "image";
+ } else if (grl_media_is_container (media)) {
+ media_type = "container";
+ }
+
+ if (media_type) {
+ lua_pushstring (L, "type");
+ lua_pushstring (L, media_type);
+ lua_settable (L, -3);
+ }
+
+ list_keys = grl_data_get_keys (GRL_DATA (media));
for (it = list_keys; it != NULL; it = it->next) {
GrlKeyID key_id;
gchar *key_name;
@@ -844,7 +868,7 @@ grl_l_media_get_keys (lua_State *L)
}
lua_pushstring (L, key_name);
- if (push_grl_media_key (L, os->media, key_id))
+ if (push_grl_media_key (L, media, key_id))
lua_settable (L, -3);
else
lua_pop (L, 1);
@@ -852,7 +876,6 @@ grl_l_media_get_keys (lua_State *L)
g_free (key_name);
}
g_list_free (list_keys);
- return 1;
}
/**
@@ -968,7 +991,8 @@ grl_l_callback (lua_State *L)
return 0;
}
- media = (os->op_type == LUA_RESOLVE) ? os->media : NULL;
+ media = os->media;
+
if (nparam > 0) {
media = grl_util_build_media (L, media);
count = (lua_isinteger (L, 2)) ? lua_tointeger (L, 2) : 0;
@@ -1329,7 +1353,6 @@ gint
luaopen_grilo (lua_State *L)
{
static const luaL_Reg library_fn[] = {
- {"get_media_keys", &grl_l_media_get_keys},
{"callback", &grl_l_callback},
{"fetch", &grl_l_fetch},
{"debug", &grl_l_debug},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]