[svn r953] Added several functions to handle with schedule exceptions trunk
authormelunko
Fri Mar 14 13:13:18 2008 +0000 (2008-03-14)
branchtrunk
changeset 944ec1d5934d8e8
parent 943 17c89e61d1c3
child 945 457f25eb3569
[svn r953] Added several functions to handle with schedule exceptions
gmyth/gmyth/gmyth_remote_util.c
gmyth/gmyth/gmyth_scheduler.c
gmyth/gmyth/gmyth_scheduler.h
     1.1 --- a/gmyth/gmyth/gmyth_remote_util.c	Fri Mar 14 12:45:05 2008 +0000
     1.2 +++ b/gmyth/gmyth/gmyth_remote_util.c	Fri Mar 14 13:13:18 2008 +0000
     1.3 @@ -158,7 +158,6 @@
     1.4  	    gint recorder_num = (gint) g_ascii_strtoull (row[0], NULL, 10);
     1.5              GString *hostname = g_string_new (binfo->hostname);
     1.6  
     1.7 -	    g_debug ("XXXXXXXXXXXX Recorded found: %d", recorder_num);
     1.8              recorder = gmyth_recorder_new (recorder_num, hostname, binfo->port);
     1.9  	    if (gmyth_recorder_setup (recorder)) {
    1.10  		*list = g_list_append(*list, recorder);
     2.1 --- a/gmyth/gmyth/gmyth_scheduler.c	Fri Mar 14 12:45:05 2008 +0000
     2.2 +++ b/gmyth/gmyth/gmyth_scheduler.c	Fri Mar 14 13:13:18 2008 +0000
     2.3 @@ -273,7 +273,6 @@
     2.4  		                     GList ** schedule_list,
     2.5  				     gchar *filter)
     2.6  {
     2.7 -	
     2.8      ScheduleInfo   *schedule;
     2.9      MYSQL_RES      *msql_res;
    2.10      GString        *query_str = g_string_new("");
    2.11 @@ -965,6 +964,133 @@
    2.12      return res;
    2.13  }
    2.14  
    2.15 +gboolean
    2.16 +gmyth_scheduler_is_exception (GMythScheduler *scheduler, ScheduleInfo *sch_info, 
    2.17 +                              gint *recordid, gint *parentid)
    2.18 +{
    2.19 +    MYSQL_RES *msql_res;
    2.20 +    gboolean ret = FALSE;
    2.21 +    gchar *query_str;
    2.22 +    gchar *start_time, *start_date;
    2.23 +    gchar *end_time, *end_date;
    2.24 +
    2.25 +    g_return_val_if_fail (scheduler != NULL, FALSE);
    2.26 +    g_return_val_if_fail (sch_info != NULL, FALSE);
    2.27 +
    2.28 +    if (scheduler->msqlquery == NULL) {
    2.29 +        g_warning("[%s] Scheduler db connection not initialized", __FUNCTION__);
    2.30 +        return FALSE;
    2.31 +    }
    2.32 +
    2.33 +    start_time = gmyth_util_time_to_string_only_time (sch_info->start_time);
    2.34 +    start_date = gmyth_util_time_to_string_only_date (sch_info->start_time);
    2.35 +
    2.36 +    end_time = gmyth_util_time_to_string_only_time (sch_info->end_time);
    2.37 +    end_date = gmyth_util_time_to_string_only_date (sch_info->end_time);
    2.38 +
    2.39 +    query_str = g_strdup_printf ("SELECT recordid,parentid FROM record WHERE type=8 and "
    2.40 +                                 "chanid=\"%d\" and starttime=\"%s\" and startdate=\"%s\" and "
    2.41 +                                 "endtime=\"%s\" and enddate=\"%s\";", sch_info->channel_id,
    2.42 +                                 start_time, start_date, end_time, end_date);
    2.43 +
    2.44 +    msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str);
    2.45 +
    2.46 +    if (msql_res == NULL) {
    2.47 +        g_warning("DB retrieval of exception schedule info failed");
    2.48 +        goto clean_me;
    2.49 +    } else {
    2.50 +        MYSQL_ROW row = mysql_fetch_row(msql_res);
    2.51 +        if (row) {
    2.52 +            *recordid = g_ascii_strtoull (row[0], NULL, 10);
    2.53 +            *parentid = g_ascii_strtoull (row[1], NULL, 10);
    2.54 +
    2.55 +            ret = TRUE;
    2.56 +        }
    2.57 +
    2.58 +        mysql_free_result(msql_res);
    2.59 +    }
    2.60 +	
    2.61 +clean_me:
    2.62 +    g_free (start_time);
    2.63 +    g_free (start_date);
    2.64 +    g_free (end_time);
    2.65 +    g_free (end_date);
    2.66 +    g_free (query_str);
    2.67 +
    2.68 +    return ret;
    2.69 +}
    2.70 +
    2.71 +gboolean
    2.72 +gmyth_scheduler_remove_all_exceptions (GMythScheduler *scheduler, gint parentid)
    2.73 +{
    2.74 +    MYSQL_RES *msql_res;
    2.75 +    gboolean ret = FALSE;
    2.76 +    gchar *list_query;
    2.77 +
    2.78 +    g_return_val_if_fail (scheduler != NULL, FALSE);
    2.79 +
    2.80 +    if (scheduler->msqlquery == NULL) {
    2.81 +        g_warning("[%s] Scheduler db connection not initialized", __FUNCTION__);
    2.82 +        return FALSE;
    2.83 +    }
    2.84 +
    2.85 +    list_query = g_strdup_printf ("SELECT recordid FROM record WHERE parentid=%d;",
    2.86 +                                 parentid);
    2.87 +
    2.88 +    msql_res = gmyth_query_process_statement(scheduler->msqlquery, list_query);
    2.89 +
    2.90 +    if (msql_res == NULL) {
    2.91 +        g_warning("DB retrieval of schedule list failed");
    2.92 +        goto clean_me;
    2.93 +    } else {
    2.94 +        MYSQL_ROW row;
    2.95 +
    2.96 +        while ((row = mysql_fetch_row(msql_res)) != NULL) {
    2.97 +
    2.98 +            gint recordid = g_ascii_strtoull (row[0], NULL, 10);
    2.99 +            ret = gmyth_scheduler_remove_exception (scheduler, recordid);
   2.100 +            if (!ret) {
   2.101 +                g_warning ("Fail to remove schedule exception");
   2.102 +                break;
   2.103 +            }
   2.104 +        }
   2.105 +
   2.106 +        mysql_free_result(msql_res);
   2.107 +    }
   2.108 +
   2.109 +clean_me:
   2.110 +    g_free (list_query);
   2.111 +
   2.112 +    return ret;
   2.113 +}
   2.114 +
   2.115 +gboolean
   2.116 +gmyth_scheduler_remove_exception (GMythScheduler *scheduler, gint scheduleid)
   2.117 +{
   2.118 +    MYSQL_RES *msql_res;
   2.119 +    gchar *query_str = NULL;
   2.120 +
   2.121 +    g_return_val_if_fail (scheduler != NULL, FALSE);
   2.122 +
   2.123 +    if (scheduler->msqlquery == NULL) {
   2.124 +        g_warning("[%s] Scheduler db connection not initialized",
   2.125 +                  __FUNCTION__);
   2.126 +        return FALSE;
   2.127 +    }
   2.128 +
   2.129 +    query_str = g_strdup_printf ("DELETE FROM record WHERE recordid=%d", scheduleid);
   2.130 +
   2.131 +    msql_res = gmyth_query_process_statement(scheduler->msqlquery,
   2.132 +                                             query_str);
   2.133 +
   2.134 +    mysql_free_result(msql_res);
   2.135 +    g_free (query_str);
   2.136 +
   2.137 +    // Notify the backend of the changes
   2.138 +    return update_backend(scheduler, scheduleid);
   2.139 +}
   2.140 +
   2.141 +
   2.142  /** Requests the Mysql database in the backend to remove an existing recorded item.
   2.143   * 
   2.144   * @param scheduler the GMythScheduler instance.
     3.1 --- a/gmyth/gmyth/gmyth_scheduler.h	Fri Mar 14 12:45:05 2008 +0000
     3.2 +++ b/gmyth/gmyth/gmyth_scheduler.h	Fri Mar 14 13:13:18 2008 +0000
     3.3 @@ -167,9 +167,19 @@
     3.4  gboolean            gmyth_scheduler_add_schedule_full       (GMythScheduler * scheduler,
     3.5                                                               ScheduleInfo * schedule_info,
     3.6                                                               GMythScheduleType type);
     3.7 +
     3.8 +/* Schedule exception handling. When one program is not part of an "all schedule programs */
     3.9  gboolean            gmyth_scheduler_add_exception           (GMythScheduler *scheduler,
    3.10                                                               gint schedule_id,
    3.11                                                               ScheduleInfo *exception_info);
    3.12 +gboolean            gmyth_scheduler_is_exception            (GMythScheduler *scheduler, 
    3.13 +		                                             ScheduleInfo *sch_info,
    3.14 +                                                             gint *recordid, gint *parentid);
    3.15 +gboolean            gmyth_scheduler_remove_all_exceptions   (GMythScheduler *scheduler, 
    3.16 +		                                             gint parentid);
    3.17 +gboolean             gmyth_scheduler_remove_exception        (GMythScheduler *scheduler, 
    3.18 +		                                             gint scheduleid);
    3.19 +
    3.20  gboolean            gmyth_scheduler_delete_schedule         (GMythScheduler * scheduler,
    3.21                                                               gint record_id);
    3.22  gint                gmyth_scheduler_delete_recorded         (GMythScheduler * scheduler,