[svn r572] Fixed add scheduling call. Now we query the station information before adding the schedule, and handle the mysqlquery auto-increment. Added the function gmyth_uri_to_string(). Added the function gmyth_query_process_statement_with_increment()
1.1 --- a/gmyth/src/gmyth_query.c Wed Apr 18 16:21:38 2007 +0100
1.2 +++ b/gmyth/src/gmyth_query.c Wed Apr 18 22:01:21 2007 +0100
1.3 @@ -233,4 +233,25 @@
1.4 return mysql_store_result (gmyth_query->conn);
1.5 }
1.6
1.7 +MYSQL_RES*
1.8 +gmyth_query_process_statement_with_increment (GMythQuery *gmyth_query, char *stmt_str, gulong *id)
1.9 +{
1.10 + assert(gmyth_query);
1.11 +
1.12 + gmyth_debug ("[%s] Running mysql query %s", __FUNCTION__, stmt_str);
1.13
1.14 + if (gmyth_query == NULL)
1.15 + return NULL;
1.16 +
1.17 + /* the statement failed */
1.18 + if (mysql_query (gmyth_query->conn, stmt_str) != 0) {
1.19 + gmyth_query_print_error (gmyth_query->conn, "Could not execute statement");
1.20 + return NULL;
1.21 + }
1.22 +
1.23 + *id = (my_ulonglong) mysql_insert_id (gmyth_query->conn);
1.24 +
1.25 + /* the statement succeeded; determine whether it returned data */
1.26 + return mysql_store_result (gmyth_query->conn);
1.27 +}
1.28 +
2.1 --- a/gmyth/src/gmyth_query.h Wed Apr 18 16:21:38 2007 +0100
2.2 +++ b/gmyth/src/gmyth_query.h Wed Apr 18 22:01:21 2007 +0100
2.3 @@ -73,6 +73,8 @@
2.4 GMythQuery* gmyth_query_new (void);
2.5 MYSQL_RES * gmyth_query_process_statement (GMythQuery *gmyth_query,
2.6 gchar *stmt_str);
2.7 +MYSQL_RES*
2.8 +gmyth_query_process_statement_with_increment (GMythQuery *gmyth_query, char *stmt_str, gulong *id);
2.9
2.10 gboolean gmyth_query_connect (GMythQuery *gmyth_query,
2.11 GMythBackendInfo *backend_info);
3.1 --- a/gmyth/src/gmyth_scheduler.c Wed Apr 18 16:21:38 2007 +0100
3.2 +++ b/gmyth/src/gmyth_scheduler.c Wed Apr 18 22:01:21 2007 +0100
3.3 @@ -47,7 +47,7 @@
3.4 static void gmyth_scheduler_finalize (GObject *object);
3.5
3.6 static gint get_record_id_from_database (GMythScheduler *scheduler);
3.7 -static void update_backend (GMythScheduler *scheduler, gint record_id);
3.8 +static gboolean update_backend (GMythScheduler *scheduler, gint record_id);
3.9
3.10 G_DEFINE_TYPE(GMythScheduler, gmyth_scheduler, G_TYPE_OBJECT)
3.11
3.12 @@ -326,6 +326,23 @@
3.13 return (*recorded_list == NULL) ? 0 : g_list_length (*recorded_list);
3.14 }
3.15
3.16 +static void
3.17 +_set_value (GMythQuery *myth_query, char* field, gchar* value, gint rec_id)
3.18 +{
3.19 + gchar* query = g_strdup_printf ("UPDATE record SET recordid = %d, %s = \"%s\" WHERE recordid = %d;", rec_id, field, value, rec_id);
3.20 +
3.21 + gmyth_query_process_statement (myth_query, query);
3.22 + g_free (query);
3.23 +}
3.24 +
3.25 +static void
3.26 +_set_int_value (GMythQuery *myth_query, char* field, gint value, gint rec_id)
3.27 +{
3.28 + gchar *str_value = g_strdup_printf ("%d", value);
3.29 + _set_value (myth_query, field, str_value, rec_id);
3.30 + g_free (str_value);
3.31 +}
3.32 +
3.33 /** Requests the Mysql database in the backend to add a new schedule.
3.34 *
3.35 * @param scheduler the GMythScheduler instance.
3.36 @@ -338,11 +355,10 @@
3.37 gmyth_scheduler_add_schedule (GMythScheduler *scheduler,
3.38 ScheduleInfo *schedule_info)
3.39 {
3.40 - //GTimeVal *start_tm;
3.41 - //GTimeVal *end_tm;
3.42 -
3.43 MYSQL_RES *msql_res;
3.44 - GString *query_str = g_string_new ("");
3.45 + gchar *query_str = "INSERT record (recordid) VALUE (0);";
3.46 + gchar *station = NULL;
3.47 + gulong rec_id;
3.48
3.49 assert(scheduler);
3.50
3.51 @@ -350,60 +366,67 @@
3.52 g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
3.53 return FALSE;
3.54 }
3.55 -
3.56 - //TODO: verify if this funtion realy does what it should do!
3.57 - g_string_printf (query_str, "REPLACE INTO record "
3.58 - "(recordid, type, chanid, starttime, "
3.59 - "startdate, endtime, enddate, title,"
3.60 - "profile, recpriority, maxnewest, inactive, "
3.61 - "maxepisodes, autoexpire, startoffset, endoffset, "
3.62 - "recgroup, dupmethod, dupin, station, "
3.63 - "autocommflag, findday, findtime, findid, "
3.64 - "search, autotranscode, transcoder, tsdefault, "
3.65 - "autouserjob1, autouserjob2, autouserjob3, autouserjob4) "
3.66 - " values ( %d, 1, %d, \"%s\"," //recordid, type, chanid, starttime
3.67 - " \"%s\", \"%s\", \"%s\", \"%s\"," //startdate, endtime, enddate, title
3.68 - "DEFAULT, 0, 0, 0, " //profile, recpriority, maxnewest, inactive
3.69 - "0, 1, 0, 0, " //maxepisodes, autoexpire, startoffset, endoffset
3.70 - "DEFAULT, 6, 15, %d, " //recgroup, dupmethod, dupin, station
3.71 - "1, %d, \"%s\", %d, " //autocommflag, findday, findtime, findid
3.72 - "5, 0, 29, 1, " //search, autotranscode, transcoder, tsdefault
3.73 - "0, 0, 0, 0 );", //autouserjob1, autouserjob2, autouserjob3, autouserjob4
3.74 - schedule_info->record_id, /* record id */
3.75 - schedule_info->channel_id, /* channel id */
3.76 - gmyth_util_time_to_string_only_time( schedule_info->start_time ), /* start time */
3.77 - gmyth_util_time_to_string_only_date( schedule_info->start_time ), /* start date */
3.78 - gmyth_util_time_to_string_only_time( schedule_info->end_time ), /* end time */
3.79 - gmyth_util_time_to_string_only_date( schedule_info->end_time ), /* end date */
3.80 - schedule_info->title->str, /* title */
3.81 - schedule_info->channel_id,/* station */
3.82 - (gmyth_util_time_val_to_date( schedule_info->start_time ))->tm_wday, //findday
3.83 - gmyth_util_time_to_string_only_time( schedule_info->start_time ), //findtime
3.84 - (gint)(schedule_info->start_time->tv_sec/60/60/24 + 719528)//findid
3.85 - );
3.86 +
3.87 + msql_res = gmyth_query_process_statement_with_increment (scheduler->msqlquery, query_str, &rec_id);
3.88 + mysql_free_result (msql_res);
3.89
3.90 - gmyth_debug ( "Sending query to MySQL = %s.", query_str->str );
3.91 + // Retrieves the station info
3.92 + query_str = g_strdup_printf ("SELECT callsign FROM channel WHERE chanid = \"%d\";", schedule_info->channel_id);
3.93 + msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str);
3.94 + if (msql_res == NULL) {
3.95 + g_warning ("[%s] msql query returned NULL MYSQL_RES", __FUNCTION__);
3.96 + return FALSE;
3.97 + } else {
3.98 + MYSQL_ROW row;
3.99 + if ((row = mysql_fetch_row (msql_res)) != NULL) {
3.100 + station = g_strdup (row[0]);
3.101 + }
3.102 + }
3.103 + mysql_free_result (msql_res);
3.104 + g_free (query_str);
3.105
3.106 - msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
3.107 -
3.108 - /* FIXME: currently no way to detect db error in UPDATE, REPLACES!
3.109 - if (msql_res == NULL) {
3.110 - g_warning ("DB retrieval of recording list failed");
3.111 - return -1;
3.112 - }*/
3.113 -
3.114 - /* TODO: verify record_id = -1 semantics */
3.115 - if (schedule_info->record_id <= 0)
3.116 - schedule_info->record_id = get_record_id_from_database(scheduler);
3.117 -
3.118 + // _set_value (field, value, id);
3.119 + _set_int_value (scheduler->msqlquery, "chanid", schedule_info->channel_id, rec_id);
3.120 + _set_value (scheduler->msqlquery, "station", station, rec_id);
3.121 + _set_value (scheduler->msqlquery, "title", schedule_info->title->str, rec_id);
3.122 + /// subtitle, description
3.123 + _set_value (scheduler->msqlquery, "starttime", gmyth_util_time_to_string_only_time( schedule_info->start_time), rec_id);
3.124 + _set_value (scheduler->msqlquery, "startdate", gmyth_util_time_to_string_only_date( schedule_info->start_time), rec_id);
3.125 + _set_value (scheduler->msqlquery, "endtime", gmyth_util_time_to_string_only_time( schedule_info->end_time), rec_id);
3.126 + _set_value (scheduler->msqlquery, "enddate", gmyth_util_time_to_string_only_date( schedule_info->end_time), rec_id);
3.127 + /// category, series id, program id
3.128 + //_set_value (scheduler->msqlquery, "findday", (gmyth_util_time_val_to_date( schedule_info->start_time ))->tm_wday, rec_id);
3.129 + //_set_value (scheduler->msqlquery, "findtime", gmyth_util_time_to_string_only_time( schedule_info->start_time), rec_id);
3.130 + //_set_int_value (scheduler->msqlquery, "findid", (gint)(schedule_info->start_time->tv_sec/60/60/24 + 719528), rec_id);
3.131 + _set_value (scheduler->msqlquery, "parentid", "0", rec_id);
3.132 + _set_value (scheduler->msqlquery, "search", "0", rec_id);
3.133 + _set_value (scheduler->msqlquery, "type", "1", rec_id);
3.134 + _set_value (scheduler->msqlquery, "recpriority", "0", rec_id);
3.135 + _set_value (scheduler->msqlquery, "startoffset", "0", rec_id);
3.136 + _set_value (scheduler->msqlquery, "endoffset", "0", rec_id);
3.137 + _set_value (scheduler->msqlquery, "dupmethod", "6", rec_id); // ?
3.138 + _set_value (scheduler->msqlquery, "dupin", "15", rec_id); // ?
3.139 +
3.140 + _set_value (scheduler->msqlquery, "prefinput", "0", rec_id);
3.141 + _set_value (scheduler->msqlquery, "inactive", "0", rec_id);
3.142 + _set_value (scheduler->msqlquery, "profile", "Default", rec_id);
3.143 + _set_value (scheduler->msqlquery, "recgroup", "Default", rec_id);
3.144 + _set_value (scheduler->msqlquery, "storagegroup", "Default", rec_id);
3.145 + _set_value (scheduler->msqlquery, "playgroup", "Default", rec_id);
3.146 + _set_value (scheduler->msqlquery, "autoexpire", "1", rec_id);
3.147 + _set_value (scheduler->msqlquery, "maxepisodes", "0", rec_id);
3.148 + _set_value (scheduler->msqlquery, "maxnewest", "0", rec_id);
3.149 + _set_value (scheduler->msqlquery, "autocommflag", "1", rec_id);
3.150 + _set_value (scheduler->msqlquery, "autotranscode", "0", rec_id);
3.151 + _set_value (scheduler->msqlquery, "transcoder", "0", rec_id);
3.152 +
3.153 + _set_value (scheduler->msqlquery, "autouserjob1", "0", rec_id);
3.154 + _set_value (scheduler->msqlquery, "autouserjob2", "0", rec_id);
3.155 + _set_value (scheduler->msqlquery, "autouserjob3", "0", rec_id);
3.156 + _set_value (scheduler->msqlquery, "autouserjob4", "0", rec_id);
3.157 +
3.158 /* Notify the backend of changes */
3.159 - update_backend(scheduler, schedule_info->record_id);
3.160 -
3.161 - /* free allocated memory */
3.162 - mysql_free_result (msql_res);
3.163 - g_string_free(query_str, TRUE);
3.164 -
3.165 - return 1;
3.166 + return update_backend(scheduler, rec_id);
3.167 }
3.168
3.169 /** Requests the Mysql database in the backend to remove an existing schedule.
3.170 @@ -432,12 +455,12 @@
3.171
3.172 msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
3.173
3.174 - update_backend(scheduler, record_id);// Notify the backend of the changes
3.175
3.176 mysql_free_result (msql_res);
3.177 g_string_free(query_str, TRUE);
3.178 -
3.179 - return TRUE;
3.180 +
3.181 + // Notify the backend of the changes
3.182 + return update_backend(scheduler, record_id);
3.183 }
3.184
3.185 /** Requests the Mysql database in the backend to remove an existing recorded item.
3.186 @@ -468,13 +491,12 @@
3.187 // FIXME: Mythtv implementation runs also: DELETE FROM oldfind WHERE recordid = x
3.188
3.189 msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
3.190 -
3.191 - update_backend(scheduler, record_id);// Notify the backend of the changes
3.192
3.193 mysql_free_result (msql_res);
3.194 g_string_free(query_str, TRUE);
3.195 -
3.196 - return TRUE;
3.197 +
3.198 + // Notify the backend of the changes
3.199 + return update_backend(scheduler, record_id);
3.200 }
3.201
3.202 /** Retrieves an existing recorded item information from database. The information
3.203 @@ -604,12 +626,13 @@
3.204 *
3.205 * @param record_id the id of the modified recording.
3.206 */
3.207 -static void
3.208 +static gboolean
3.209 update_backend(GMythScheduler *scheduler, gint record_id)//fixme: put void and discovery record_id inside
3.210 {
3.211 GMythSocket *socket;
3.212 GMythStringList *strlist = gmyth_string_list_new ();
3.213 GString *datastr = g_string_new ("RESCHEDULE_RECORDINGS ");
3.214 + gboolean ret = FALSE;
3.215
3.216 g_string_append_printf (datastr, "%d", record_id);
3.217 gmyth_string_list_append_string (strlist, datastr);
3.218 @@ -617,13 +640,15 @@
3.219 socket = gmyth_socket_new ();
3.220 if (gmyth_socket_connect_to_backend (socket, scheduler->backend_info->hostname,
3.221 scheduler->backend_info->port, TRUE)) {
3.222 - gmyth_socket_sendreceive_stringlist (socket, strlist);
3.223 + ret = (gmyth_socket_sendreceive_stringlist (socket, strlist) > 0);
3.224 } else {
3.225 g_warning ("[%s] Connection to backend failed!", __FUNCTION__);
3.226 }
3.227
3.228 g_string_free(datastr, TRUE);
3.229 g_object_unref(strlist);
3.230 +
3.231 + return ret;
3.232 }
3.233
3.234 void
4.1 --- a/gmyth/src/gmyth_uri.c Wed Apr 18 16:21:38 2007 +0100
4.2 +++ b/gmyth/src/gmyth_uri.c Wed Apr 18 22:01:21 2007 +0100
4.3 @@ -519,3 +519,12 @@
4.4 return ret;
4.5
4.6 }
4.7 +
4.8 +char*
4.9 +gmyth_uri_to_string (const GMythURI* uri)
4.10 +{
4.11 + g_return_val_if_fail (uri != NULL, NULL);
4.12 + g_return_val_if_fail (uri->uri != NULL, NULL);
4.13 +
4.14 + return g_strdup (uri->uri->str);
4.15 +}
5.1 --- a/gmyth/src/gmyth_uri.h Wed Apr 18 16:21:38 2007 +0100
5.2 +++ b/gmyth/src/gmyth_uri.h Wed Apr 18 22:01:21 2007 +0100
5.3 @@ -110,6 +110,9 @@
5.4 gint gmyth_uri_get_channel_num( GMythURI* uri );
5.5 gchar* gmyth_uri_get_channel_name( GMythURI* uri );
5.6
5.7 +char* gmyth_uri_to_string (const GMythURI* uri);
5.8 +
5.9 +
5.10 gboolean gmyth_uri_is_local_file( const GMythURI* uri );
5.11
5.12 #define gmyth_uri_get_host(urip) ( urip->host != NULL ? urip->host->str : "" )