After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 725188 - Lua-Factory: extend fetch operation
Lua-Factory: extend fetch operation
Status: RESOLVED FIXED
Product: grilo
Classification: Other
Component: plugins
git master
Other Linux
: Normal enhancement
: ---
Assigned To: grilo-maint
grilo-maint
Depends on:
Blocks:
 
 
Reported: 2014-02-26 02:37 UTC by Victor Toso
Modified: 2014-02-26 09:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Multiple urls to fetch as an array in grl.fetch (4.95 KB, patch)
2014-02-26 02:43 UTC, Victor Toso
needs-work Details | Review

Description Victor Toso 2014-02-26 02:37:23 UTC
Currently, the lua-source is able to fetch a single url doing:

grl.fetch("url", "callback_fn")

Sometimes is necessary to have multiples fetchs before dealing with the data in the callback_fn.

Extend the grl.fetch from single url to an array of urls.
Comment 1 Victor Toso 2014-02-26 02:43:16 UTC
Created attachment 270344 [details] [review]
Multiple urls to fetch as an array in grl.fetch

The result of grl.fetch an array of urls is a array of data, where first data element corresponds to the first url element and so on.
Comment 2 Bastien Nocera 2014-02-26 08:36:03 UTC
Review of attachment 270344 [details] [review]:

Looks good overall.

::: src/lua-factory/grl-lua-library.c
@@ +215,3 @@
+  for (i = 0; i < fo->num_urls; i++)
+    if (fo->data[i] == NULL)
+      goto fetch_op_cleanup;

that doesn't tell me much about what's supposed to happen after "fetch_op_cleanup".

@@ +482,3 @@
 
+  num_urls = (lua_isstring (L, 1)) ? 1 : luaL_len (L, 1);
+  urls = g_malloc0 (sizeof (gchar *) * num_urls);

use g_new0 instead of g_malloc0

@@ +540,3 @@
 
+  /* shared data between urls */
+  data = g_malloc0 (sizeof(gchar *) * num_urls);

Ditto.
Comment 3 Bastien Nocera 2014-02-26 08:59:25 UTC
Review of attachment 270344 [details] [review]:

::: src/lua-factory/grl-lua-library.c
@@ +219,3 @@
   lua_getglobal (L, fo->lua_cb);
+
+  if (fo->num_urls == 1) {

Not quite good enough.

If I want to avoid having to check whether the results are a table or a string in my code, I'd probably always pass a table with a single, or multiple URLs and expect the result to always be a table which I can iterate over.

You'll need to add a member to the FetchOperation struct to remember whether the input is a table or not.
Comment 4 Bastien Nocera 2014-02-26 09:31:05 UTC
Fixed the niggles mentioned in the review and pushed.