# HG changeset patch # User melunko # Date 1205500398 0 # Node ID ec1d5934d8e819d6976f9192f527b32737d77c91 # Parent 17c89e61d1c31fbbafa9eff0a3d7892bf82b74e5 [svn r953] Added several functions to handle with schedule exceptions diff -r 17c89e61d1c3 -r ec1d5934d8e8 gmyth/gmyth/gmyth_remote_util.c --- a/gmyth/gmyth/gmyth_remote_util.c Fri Mar 14 12:45:05 2008 +0000 +++ b/gmyth/gmyth/gmyth_remote_util.c Fri Mar 14 13:13:18 2008 +0000 @@ -158,7 +158,6 @@ gint recorder_num = (gint) g_ascii_strtoull (row[0], NULL, 10); GString *hostname = g_string_new (binfo->hostname); - g_debug ("XXXXXXXXXXXX Recorded found: %d", recorder_num); recorder = gmyth_recorder_new (recorder_num, hostname, binfo->port); if (gmyth_recorder_setup (recorder)) { *list = g_list_append(*list, recorder); diff -r 17c89e61d1c3 -r ec1d5934d8e8 gmyth/gmyth/gmyth_scheduler.c --- a/gmyth/gmyth/gmyth_scheduler.c Fri Mar 14 12:45:05 2008 +0000 +++ b/gmyth/gmyth/gmyth_scheduler.c Fri Mar 14 13:13:18 2008 +0000 @@ -273,7 +273,6 @@ GList ** schedule_list, gchar *filter) { - ScheduleInfo *schedule; MYSQL_RES *msql_res; GString *query_str = g_string_new(""); @@ -965,6 +964,133 @@ return res; } +gboolean +gmyth_scheduler_is_exception (GMythScheduler *scheduler, ScheduleInfo *sch_info, + gint *recordid, gint *parentid) +{ + MYSQL_RES *msql_res; + gboolean ret = FALSE; + gchar *query_str; + gchar *start_time, *start_date; + gchar *end_time, *end_date; + + g_return_val_if_fail (scheduler != NULL, FALSE); + g_return_val_if_fail (sch_info != NULL, FALSE); + + if (scheduler->msqlquery == NULL) { + g_warning("[%s] Scheduler db connection not initialized", __FUNCTION__); + return FALSE; + } + + start_time = gmyth_util_time_to_string_only_time (sch_info->start_time); + start_date = gmyth_util_time_to_string_only_date (sch_info->start_time); + + end_time = gmyth_util_time_to_string_only_time (sch_info->end_time); + end_date = gmyth_util_time_to_string_only_date (sch_info->end_time); + + query_str = g_strdup_printf ("SELECT recordid,parentid FROM record WHERE type=8 and " + "chanid=\"%d\" and starttime=\"%s\" and startdate=\"%s\" and " + "endtime=\"%s\" and enddate=\"%s\";", sch_info->channel_id, + start_time, start_date, end_time, end_date); + + msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str); + + if (msql_res == NULL) { + g_warning("DB retrieval of exception schedule info failed"); + goto clean_me; + } else { + MYSQL_ROW row = mysql_fetch_row(msql_res); + if (row) { + *recordid = g_ascii_strtoull (row[0], NULL, 10); + *parentid = g_ascii_strtoull (row[1], NULL, 10); + + ret = TRUE; + } + + mysql_free_result(msql_res); + } + +clean_me: + g_free (start_time); + g_free (start_date); + g_free (end_time); + g_free (end_date); + g_free (query_str); + + return ret; +} + +gboolean +gmyth_scheduler_remove_all_exceptions (GMythScheduler *scheduler, gint parentid) +{ + MYSQL_RES *msql_res; + gboolean ret = FALSE; + gchar *list_query; + + g_return_val_if_fail (scheduler != NULL, FALSE); + + if (scheduler->msqlquery == NULL) { + g_warning("[%s] Scheduler db connection not initialized", __FUNCTION__); + return FALSE; + } + + list_query = g_strdup_printf ("SELECT recordid FROM record WHERE parentid=%d;", + parentid); + + msql_res = gmyth_query_process_statement(scheduler->msqlquery, list_query); + + if (msql_res == NULL) { + g_warning("DB retrieval of schedule list failed"); + goto clean_me; + } else { + MYSQL_ROW row; + + while ((row = mysql_fetch_row(msql_res)) != NULL) { + + gint recordid = g_ascii_strtoull (row[0], NULL, 10); + ret = gmyth_scheduler_remove_exception (scheduler, recordid); + if (!ret) { + g_warning ("Fail to remove schedule exception"); + break; + } + } + + mysql_free_result(msql_res); + } + +clean_me: + g_free (list_query); + + return ret; +} + +gboolean +gmyth_scheduler_remove_exception (GMythScheduler *scheduler, gint scheduleid) +{ + MYSQL_RES *msql_res; + gchar *query_str = NULL; + + g_return_val_if_fail (scheduler != NULL, FALSE); + + if (scheduler->msqlquery == NULL) { + g_warning("[%s] Scheduler db connection not initialized", + __FUNCTION__); + return FALSE; + } + + query_str = g_strdup_printf ("DELETE FROM record WHERE recordid=%d", scheduleid); + + msql_res = gmyth_query_process_statement(scheduler->msqlquery, + query_str); + + mysql_free_result(msql_res); + g_free (query_str); + + // Notify the backend of the changes + return update_backend(scheduler, scheduleid); +} + + /** Requests the Mysql database in the backend to remove an existing recorded item. * * @param scheduler the GMythScheduler instance. diff -r 17c89e61d1c3 -r ec1d5934d8e8 gmyth/gmyth/gmyth_scheduler.h --- a/gmyth/gmyth/gmyth_scheduler.h Fri Mar 14 12:45:05 2008 +0000 +++ b/gmyth/gmyth/gmyth_scheduler.h Fri Mar 14 13:13:18 2008 +0000 @@ -167,9 +167,19 @@ gboolean gmyth_scheduler_add_schedule_full (GMythScheduler * scheduler, ScheduleInfo * schedule_info, GMythScheduleType type); + +/* Schedule exception handling. When one program is not part of an "all schedule programs */ gboolean gmyth_scheduler_add_exception (GMythScheduler *scheduler, gint schedule_id, ScheduleInfo *exception_info); +gboolean gmyth_scheduler_is_exception (GMythScheduler *scheduler, + ScheduleInfo *sch_info, + gint *recordid, gint *parentid); +gboolean gmyth_scheduler_remove_all_exceptions (GMythScheduler *scheduler, + gint parentid); +gboolean gmyth_scheduler_remove_exception (GMythScheduler *scheduler, + gint scheduleid); + gboolean gmyth_scheduler_delete_schedule (GMythScheduler * scheduler, gint record_id); gint gmyth_scheduler_delete_recorded (GMythScheduler * scheduler,