# HG changeset patch # User renatofilho # Date 1193687795 0 # Node ID 7fd8198b93aa69670f2ae2afe183a429b2b47f98 # Parent 007c65343f3125223e9e8cfdc0ff37c3e07e734d [svn r883] implemented error propagation diff -r 007c65343f31 -r 7fd8198b93aa gmyth-dbus/debian/changelog --- a/gmyth-dbus/debian/changelog Fri Oct 26 23:03:22 2007 +0100 +++ b/gmyth-dbus/debian/changelog Mon Oct 29 19:56:35 2007 +0000 @@ -1,3 +1,9 @@ +gmyth-dbus (0.1.1) unstable; urgency=low + + * Implemented error propagation; + + -- Hallyson Melo Fri, 29 Oct 2006 14:00:16 -0300 + gmyth-dbus (0.1) unstable; urgency=low * Initial Package. diff -r 007c65343f31 -r 7fd8198b93aa gmyth-dbus/src/gmyth-dbus-server.c --- a/gmyth-dbus/src/gmyth-dbus-server.c Fri Oct 26 23:03:22 2007 +0100 +++ b/gmyth-dbus/src/gmyth-dbus-server.c Mon Oct 29 19:56:35 2007 +0000 @@ -26,15 +26,31 @@ #endif +#include #include #include - #include "gmyth-dbus-common.h" #include "gmyth-dbus-server.h" #define MYTH_DEFAULT_DB "mythconverg" +enum +{ + GMYTH_DBUS_ERROR_MYTHTV, + GMYTH_DBUS_ERROR_CONNECTION, + GMYTH_DBUS_ERROR_EPG, + GMYTH_DBUS_ERROR_SCHEDULE +}; + +#define GMYTH_DBUS_ERROR gmyth_dbus_error_quark () + +GQuark +gmyth_dbus_error_quark (void) +{ + return g_quark_from_static_string ("gmyth-dbus-error-quark"); +} + typedef struct _GMythDbusServerPrivate GMythDbusServerPrivate; struct _GMythDbusServerPrivate @@ -83,10 +99,11 @@ gint channel_id, const gchar *start_time, const gchar *end_time, - GPtrArray **program_list); + GPtrArray **program_list, + GError **error); static gboolean gmyth_dbus_server_get_schedule_list (GObject *obj, - GPtrArray **schedule_list); - + GPtrArray **schedule_list, + GError **error); static gboolean gmyth_dbus_server_connected (GObject *obj, gboolean *status, GError **error); @@ -168,13 +185,20 @@ } static gboolean -gmyth_dbus_server_connect_epg (GMythDbusServer *server) +gmyth_dbus_server_connect_epg (GMythDbusServer *server, GError **error) { GMythDbusServerPrivate *priv; priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server); if (!priv->connected) + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_CONNECTION, + _("Not connected")); + return FALSE; + } if (!priv->myth_epg) { @@ -183,6 +207,12 @@ { g_object_unref (priv->myth_epg); priv->myth_epg = NULL; + + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_EPG, + _("Fail to connect with EPG")); + return FALSE; } } @@ -191,13 +221,21 @@ } static gboolean -gmyth_dbus_server_connect_scheduler (GMythDbusServer *server) +gmyth_dbus_server_connect_scheduler (GMythDbusServer *server, + GError **error) { GMythDbusServerPrivate *priv; priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server); if (!priv->connected) + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_CONNECTION, + _("Not connected")); + return FALSE; + } if (!priv->myth_scheduler) { @@ -207,6 +245,12 @@ { g_object_unref (priv->myth_scheduler); priv->myth_scheduler = NULL; + + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_SCHEDULE, + _("Fail to connect with Schedule")); + return FALSE; } } @@ -230,7 +274,7 @@ priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj); - if (priv->myth_backend) + if (priv->connected) { gmyth_dbus_server_disconnect (obj, NULL); } @@ -249,10 +293,14 @@ } else { - g_debug ("FAIL TO CONNECT"); g_object_unref (priv->myth_backend); priv->myth_backend = NULL; *result = FALSE; + + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_CONNECTION, + _("Fail to connect with backend")); } priv->connected = *result; @@ -329,6 +377,16 @@ socket = gmyth_backend_info_get_connected_socket (priv->myth_backend); + if (!socket) + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("MythTv not avaliable")); + return FALSE; + + } + details = NULL; gmyth_util_get_backend_details (socket, &details); @@ -341,6 +399,13 @@ ret = TRUE; } + else + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("Fail to get MythTv details")); + } g_object_unref (socket); @@ -375,8 +440,10 @@ g_return_val_if_fail (priv->myth_backend != NULL, FALSE); - if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error)) + { return FALSE; + } ch_type = GMYTH_DBUS_CHANNEL_G_TYPE; @@ -391,6 +458,13 @@ *info = g_value_get_boxed (&v); return TRUE; } + else + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_EPG, + _("no channel info avaliable")); + } return FALSE; } @@ -411,7 +485,7 @@ priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj); g_return_val_if_fail (priv->myth_backend != NULL, FALSE); - if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error)) return FALSE; @@ -460,7 +534,8 @@ gint channel_id, const gchar *start_time, const gchar *end_time, - GPtrArray **programs) + GPtrArray **programs, + GError **error) { GList *list; GList *walk; @@ -474,7 +549,7 @@ priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj); g_return_val_if_fail (priv->myth_backend, FALSE); - if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error)) return FALSE; g_time_val_from_iso8601 (start_time, &start_time_val); @@ -574,7 +649,7 @@ g_return_val_if_fail (priv->myth_backend, FALSE); - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error)) return FALSE; record_type = GMYTH_DBUS_RECORD_G_TYPE; @@ -597,6 +672,14 @@ return TRUE; } + else + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_EPG, + _("no record info avaliable")); + + } return FALSE; } @@ -617,7 +700,7 @@ priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj); g_return_val_if_fail (priv->myth_backend != NULL, FALSE); - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error)) return FALSE; @@ -652,7 +735,8 @@ static gboolean gmyth_dbus_server_get_schedule_list (GObject *obj, - GPtrArray **schedules) + GPtrArray **schedules, + GError **error) { GList *list; GList *walk; @@ -664,7 +748,7 @@ priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj); g_return_val_if_fail (priv->myth_backend, FALSE); - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error)) return FALSE; @@ -733,12 +817,25 @@ g_return_val_if_fail (priv->myth_backend, FALSE); if (!gmyth_util_file_exists (priv->myth_backend, uri)) + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("File not exists")); + goto fail; + } file_transfer = gmyth_file_transfer_new (priv->myth_backend); if (!gmyth_file_transfer_open (file_transfer, uri)) + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("Fail to open file")); goto fail; + } filesize = gmyth_file_transfer_get_filesize (file_transfer); if (filesize <= 0) @@ -747,13 +844,27 @@ *image = g_byte_array_new (); result = gmyth_file_transfer_read (file_transfer, *image, filesize, FALSE); if (result == GMYTH_FILE_READ_ERROR) + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("Fail to read file")); + goto fail; + } gmyth_file_transfer_close (file_transfer); g_object_unref (file_transfer); if (filesize > (*image)->len) + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("Empty file")); + goto fail; + } return TRUE; @@ -785,12 +896,23 @@ *icon = NULL; if (channel == NULL) + { + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("Invalid channel")); + return FALSE; + } if (!gmyth_epg_channel_has_icon(priv->myth_epg, channel)) { gmyth_channel_info_free (channel); - g_debug("Channel does not have icon available"); + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("Channel does not have icon available")); + return FALSE; } @@ -802,7 +924,11 @@ &icon_length)) { gmyth_channel_info_free (channel); - g_warning("Could not get channel icon for channel id = %u", channel_id); + g_set_error (error, + GMYTH_DBUS_ERROR, + GMYTH_DBUS_ERROR_MYTHTV, + _("Could not get channel icon for channel id = %u"), + channel_id); return FALSE; } @@ -828,7 +954,7 @@ priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj); g_return_val_if_fail (priv->myth_backend, FALSE); - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error)) return FALSE; ret = gmyth_scheduler_stop_recording (priv->myth_scheduler, @@ -893,7 +1019,7 @@ g_return_val_if_fail (priv->myth_backend, FALSE); - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error)) return FALSE; @@ -980,7 +1106,7 @@ g_return_val_if_fail (priv->myth_backend, FALSE); - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error)) return FALSE; g_time_val_from_iso8601 (start_time, &start_vtime); @@ -1020,7 +1146,7 @@ g_return_val_if_fail (priv->myth_backend, FALSE); - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj))) + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error)) return FALSE; return gmyth_scheduler_delete_schedule (priv->myth_scheduler, schedule_id);