[grilo-plugins] lua-factory: Protect against broken sources
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] lua-factory: Protect against broken sources
- Date: Wed, 19 Mar 2014 11:31:46 +0000 (UTC)
commit 3ceffa5fbdb974769ba6f6fa47183bef64ea7396
Author: Bastien Nocera <hadess hadess net>
Date: Tue Mar 18 10:47:10 2014 +0100
lua-factory: Protect against broken sources
If no fetches are pending and grl.callback() was not called,
throw a warning, and clean up after the source to avoid
inconsistent states in front-ends.
https://bugzilla.gnome.org/show_bug.cgi?id=725209
src/lua-factory/grl-lua-common.h | 2 ++
src/lua-factory/grl-lua-library.c | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-common.h b/src/lua-factory/grl-lua-common.h
index 8ed1c57..e951b94 100644
--- a/src/lua-factory/grl-lua-common.h
+++ b/src/lua-factory/grl-lua-common.h
@@ -64,6 +64,8 @@ typedef struct _OperationSpec {
GrlMedia *media;
gpointer user_data;
guint error_code;
+ guint pending_ops;
+ gboolean callback_done;
} OperationSpec;
void grl_lua_library_save_operation_data (lua_State *L, OperationSpec *os);
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index a47eb85..943ccc4 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -303,6 +303,7 @@ grl_util_fetch_done (GObject *source_object,
gchar *data = NULL;
guint i = 0;
GError *err = NULL;
+ OperationSpec *os;
FetchOperation *fo = (FetchOperation *) user_data;
lua_State *L = fo->L;
@@ -329,6 +330,8 @@ grl_util_fetch_done (GObject *source_object,
}
grl_lua_library_set_current_operation (L, fo->operation_id);
+ os = grl_lua_library_get_current_operation (L);
+ os->pending_ops--;
lua_getglobal (L, fo->lua_cb);
@@ -607,6 +610,7 @@ grl_l_fetch (lua_State *L)
os = grl_lua_library_get_current_operation (L);
g_return_val_if_fail (os != NULL, 0);
+ os->pending_ops++;
num_urls = (lua_isstring (L, 1)) ? 1 : luaL_len (L, 1);
urls = g_new0 (gchar *, num_urls);
@@ -728,6 +732,7 @@ grl_l_callback (lua_State *L)
if (count == 0) {
g_list_free (os->keys);
g_object_unref (os->options);
+ os->callback_done = TRUE;
grl_lua_library_remove_operation_data (L, os->operation_id);
g_slice_free (OperationSpec, os);
}
@@ -972,6 +977,25 @@ grl_lua_library_set_current_operation (lua_State *L, guint operation_id)
{
OperationSpec *os;
+ /* Verify that either grl.callback was called, or that there
+ * are pending operations */
+ os = grl_lua_library_get_current_operation (L);
+ if (os) {
+ if (os->pending_ops == 0 && !os->callback_done) {
+ g_warning ("Source '%s' is broken, as there are no pending operations "
+ "and grl.callback() was not called", grl_source_get_id (os->source));
+ switch (os->op_type) {
+ case LUA_RESOLVE:
+ os->cb.resolve (os->source, os->operation_id, NULL, os->user_data, NULL);
+ break;
+
+ default:
+ os->cb.result (os->source, os->operation_id, NULL,
+ 0, os->user_data, NULL);
+ }
+ }
+ }
+
if (operation_id > 0)
os = grl_lua_library_load_operation_data (L, operation_id);
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]