[svn r215] Use the GTimeVal GLib date/time structure, instead of using the time_t from libc.
1.1 --- a/gmyth/src/gmyth_common.h Fri Dec 08 23:16:15 2006 +0000
1.2 +++ b/gmyth/src/gmyth_common.h Tue Dec 12 17:59:47 2006 +0000
1.3 @@ -58,13 +58,13 @@
1.4 GString *chanid;
1.5
1.6 /** The program start time. */
1.7 - time_t startts;
1.8 + GTimeVal* startts;
1.9 /** The program end time. */
1.10 - time_t endts;
1.11 + GTimeVal* endts;
1.12 /** The recording schedule start time. */
1.13 - time_t recstartts;
1.14 + GTimeVal* recstartts;
1.15 /** The recording schedule end time */
1.16 - time_t recendts;
1.17 + GTimeVal* recendts;
1.18
1.19 /** The program title. */
1.20 GString *title;
1.21 @@ -97,9 +97,9 @@
1.22 double stars;
1.23 int repeat;
1.24
1.25 - time_t originalAirDate;
1.26 - time_t lastmodified;
1.27 - time_t lastInUseTime;
1.28 + GTimeVal* originalAirDate;
1.29 + GTimeVal* lastmodified;
1.30 + GTimeVal* lastInUseTime;
1.31
1.32 gboolean hasAirDate;
1.33
2.1 --- a/gmyth/src/gmyth_epg.c Fri Dec 08 23:16:15 2006 +0000
2.2 +++ b/gmyth/src/gmyth_epg.c Tue Dec 12 17:59:47 2006 +0000
2.3 @@ -161,7 +161,7 @@
2.4 while ((row = mysql_fetch_row (msql_res)) != NULL){
2.5
2.6 channel_info = g_new0(GMythChannelInfo, 1);
2.7 - channel_info->channel_ID = atoi (row[0]);
2.8 + channel_info->channel_ID = g_ascii_strtoull (row[0], NULL, 10);
2.9 channel_info->channel_name = g_string_new (row[1]);
2.10
2.11 #if 0
2.12 @@ -189,8 +189,8 @@
2.13 gmyth_epg_get_program_list (GMythEPG *gmyth_epg, GList **proglist,
2.14 const gint chan_num, time_t starttime, time_t endtime)
2.15 {
2.16 - GString *startts = gmyth_util_time_to_string(starttime);
2.17 - GString *endts = gmyth_util_time_to_string(endtime);
2.18 + gchar *startts = gmyth_util_time_to_string_from_time_val(starttime);
2.19 + gchar *endts = gmyth_util_time_to_string_from_time_val(endtime);
2.20 MYSQL_ROW row;
2.21 GString *querystr;
2.22
2.23 @@ -219,7 +219,7 @@
2.24 " AND program.endtime >= '%s' "
2.25 " AND program.starttime <= '%s' "
2.26 " AND program.manualid = 0 ",
2.27 - chan_num, startts->str, endts->str);
2.28 + chan_num, startts, endts);
2.29
2.30 if (!g_strrstr(querystr->str, " GROUP BY "))
2.31 querystr = g_string_append(querystr,
2.32 @@ -243,8 +243,8 @@
2.33 GMythProgramInfo *p = g_new0 (GMythProgramInfo, 1);
2.34 p->chanid = g_string_new (row[0]);
2.35
2.36 - p->startts = gmyth_util_string_to_time (g_string_new (row[1]));
2.37 - p->endts = gmyth_util_string_to_time (g_string_new (row[2]));
2.38 + p->startts = gmyth_util_string_to_time_val (row[1]);
2.39 + p->endts = gmyth_util_string_to_time_val (row[2]);
2.40
2.41 p->recstartts = p->startts;
2.42 p->recendts = p->endts;
2.43 @@ -257,19 +257,19 @@
2.44 p->chanstr = g_string_new (row[7]);
2.45 p->chansign = g_string_new (row[8]);
2.46 p->channame = g_string_new (row[9]);
2.47 - p->repeat = atoi(row[10]);
2.48 - p->chancommfree = atoi(row[11]);
2.49 + p->repeat = g_ascii_strtoull(row[10], NULL, 10);
2.50 + p->chancommfree = g_ascii_strtoull(row[11], NULL, 10);
2.51 p->chanOutputFilters = g_string_new (row[12]);
2.52 p->seriesid = g_string_new (row[13]);
2.53 p->programid = g_string_new (row[14]);
2.54 p->year = g_string_new (row[15]);
2.55 - p->stars = atof(row[16]);
2.56 + p->stars = g_ascii_strtod(row[16], NULL);
2.57
2.58 if (!row[17] || !strcmp(row[17], "")) {
2.59 p->originalAirDate = 0;
2.60 p->hasAirDate = FALSE;
2.61 } else {
2.62 - p->originalAirDate = gmyth_util_string_to_time (g_string_new (row[17]));
2.63 + p->originalAirDate = gmyth_util_string_to_time_val (row[17]);
2.64 p->hasAirDate = TRUE;
2.65 }
2.66
3.1 --- a/gmyth/src/gmyth_marshal.list Fri Dec 08 23:16:15 2006 +0000
3.2 +++ b/gmyth/src/gmyth_marshal.list Tue Dec 12 17:59:47 2006 +0000
3.3 @@ -1,1 +1,2 @@
3.4 -VOID:INT,STRING
3.5 +VOID:INT,STRING,POINTER
3.6 +VOID:INT,POINTER
4.1 --- a/gmyth/src/gmyth_query.h Fri Dec 08 23:16:15 2006 +0000
4.2 +++ b/gmyth/src/gmyth_query.h Tue Dec 12 17:59:47 2006 +0000
4.3 @@ -74,7 +74,7 @@
4.4
4.5 GMythQuery* gmyth_query_new ( );
4.6 MYSQL_RES * gmyth_query_process_statement
4.7 - (GMythQuery *gmyth_query, char *stmt_str);
4.8 + (GMythQuery *gmyth_query, gchar *stmt_str);
4.9
4.10 gboolean gmyth_query_connect (GMythQuery *gmyth_query, GMythBackendInfo *backend_info);
4.11 gboolean gmyth_query_disconnect (GMythQuery *gmyth_query);
5.1 --- a/gmyth/src/gmyth_scheduler.c Fri Dec 08 23:16:15 2006 +0000
5.2 +++ b/gmyth/src/gmyth_scheduler.c Tue Dec 12 17:59:47 2006 +0000
5.3 @@ -30,10 +30,11 @@
5.4 #include "config.h"
5.5 #endif
5.6
5.7 -#include "gmyth_scheduler.h"
5.8 -
5.9 #include <assert.h>
5.10
5.11 +#include <glib/gprintf.h>
5.12 +
5.13 +#include "gmyth_scheduler.h"
5.14 #include "gmyth_util.h"
5.15 #include "gmyth_query.h"
5.16 #include "gmyth_socket.h"
5.17 @@ -191,7 +192,7 @@
5.18 ScheduleInfo *schedule;
5.19 MYSQL_RES *msql_res;
5.20 GString *query_str = g_string_new ("");
5.21 - GString *date_time = g_string_new ("");
5.22 + gchar *date_time = NULL;
5.23
5.24 assert(scheduler);
5.25
5.26 @@ -220,14 +221,14 @@
5.27 schedule->channel_id = g_ascii_strtoull (row[2], NULL, 10);
5.28
5.29 /* generate a time_t from a time and a date db field */
5.30 - g_string_printf (date_time, "%s %s", row[4], row[3]);
5.31 + g_sprintf (date_time, "%sT%s", row[4], row[3]);
5.32
5.33 - schedule->start_time = gmyth_util_string_to_time (date_time);
5.34 + schedule->start_time = gmyth_util_string_to_time_val (date_time);
5.35
5.36 /* generate a time_t from a time and a date db field */
5.37 - g_string_printf (date_time, "%s %s", row[6], row[5]);
5.38 + g_sprintf (date_time, "%sT%s", row[6], row[5]);
5.39
5.40 - schedule->end_time = gmyth_util_string_to_time (date_time);
5.41 + schedule->end_time = gmyth_util_string_to_time_val (date_time);
5.42
5.43 schedule->title = g_string_new (row[7]);
5.44 schedule->subtitle = g_string_new (row[8]);
5.45 @@ -240,7 +241,7 @@
5.46
5.47 mysql_free_result (msql_res);
5.48 g_string_free(query_str, TRUE);
5.49 - g_string_free(date_time, TRUE);
5.50 + g_free(date_time);
5.51
5.52 return (*schedule_list == NULL) ? 0 : g_list_length (*schedule_list);
5.53 }
5.54 @@ -257,7 +258,7 @@
5.55 RecordedInfo *record;
5.56 MYSQL_RES *msql_res;
5.57 GString *query_str = g_string_new ("");
5.58 - GString *date_time = g_string_new ("");
5.59 + gchar *date_time = NULL;
5.60
5.61 assert(scheduler);
5.62
5.63 @@ -290,17 +291,17 @@
5.64 * we are not using the date field */
5.65 /* generate a time_t from a time and a date db field */
5.66 /* g_string_printf (date_time, "%s %s", row[4], row[3]); */
5.67 - g_string_printf (date_time, "%s", row[3]);
5.68 + g_sprintf (date_time, "%s", row[3]);
5.69
5.70 - record->start_time = gmyth_util_string_to_time (date_time);
5.71 + record->start_time = gmyth_util_string_to_time_val (date_time);
5.72
5.73 /* the db field time already contains the date. therefore
5.74 * we are not using the date field */
5.75 /* generate a time_t from a time and a date db field */
5.76 /* g_string_printf (date_time, "%s %s", row[6], row[5]); */
5.77 - g_string_printf (date_time, "%s", row[5]);
5.78 + g_sprintf (date_time, "%s", row[5]);
5.79
5.80 - record->end_time = gmyth_util_string_to_time (date_time);
5.81 + record->end_time = gmyth_util_string_to_time_val (date_time);
5.82
5.83 record->title = g_string_new (row[7]);
5.84 record->subtitle = g_string_new (row[8]);
5.85 @@ -315,7 +316,7 @@
5.86
5.87 mysql_free_result (msql_res);
5.88 g_string_free(query_str, TRUE);
5.89 - g_string_free(date_time, TRUE);
5.90 + g_free(date_time);
5.91
5.92 return (*recorded_list == NULL) ? 0 : g_list_length (*recorded_list);
5.93 }
5.94 @@ -332,30 +333,21 @@
5.95 gmyth_scheduler_add_schedule (GMythScheduler *scheduler,
5.96 ScheduleInfo *schedule_info)
5.97 {
5.98 - struct tm start_tm;
5.99 - struct tm end_tm;
5.100 + //GTimeVal *start_tm;
5.101 + //GTimeVal *end_tm;
5.102
5.103 MYSQL_RES *msql_res;
5.104 GString *query_str = g_string_new ("");
5.105 -
5.106 +
5.107 + gchar *date_time = NULL;
5.108 +
5.109 assert(scheduler);
5.110
5.111 if (scheduler->msqlquery == NULL) {
5.112 g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
5.113 - return 0;
5.114 + return FALSE;
5.115 }
5.116
5.117 - /* manipulating time */
5.118 - if(localtime_r(&schedule_info->start_time, &start_tm) == NULL) {
5.119 - g_warning ("localtime_r error in libgmyth scheduler!\n");
5.120 - return FALSE;
5.121 - }
5.122 -
5.123 - if(localtime_r(&schedule_info->end_time, &end_tm) == NULL) {
5.124 - g_warning ("localtime_r error in libgmyth scheduler!\n");
5.125 - return FALSE;
5.126 - }
5.127 -
5.128 //TODO: verify if this funtion realy does what it should do!
5.129 g_string_printf (query_str, "REPLACE INTO record "
5.130 "(recordid, type, chanid, starttime, "
5.131 @@ -366,26 +358,25 @@
5.132 "autocommflag, findday, findtime, findid, "
5.133 "search, autotranscode, transcoder, tsdefault, "
5.134 "autouserjob1, autouserjob2, autouserjob3, autouserjob4) "
5.135 - " values ( %d, 1, %d, \"%02d:%02d:00\"," //recordid, type, chanid, starttime
5.136 - " \"%d-%02d-%02d\", \"%02d:%02d:00\", \"%04d-%02d-%02d\", \"%s\","
5.137 + " values ( %d, 1, %d, \"%s\"," //recordid, type, chanid, starttime
5.138 + " \"%s\", \"%s\", \"%s\", \"%s\","
5.139 //startdate, endtime, enddate, title
5.140 "DEFAULT, 0, 0, 0, " //profile, recpriority, maxnewest, inactive
5.141 "0, 1, 0, 0, " //maxepisodes, autoexpire, startoffset, endoffset
5.142 "DEFAULT, 6, 15, %d, " //recgroup, dupmethod, dupin, station
5.143 - "1, %d, \"%02d:%02d:00\", %d, " //autocommflag, findday, findtime, findid
5.144 + "1, %d, \"%s\", %d, " //autocommflag, findday, findtime, findid
5.145 "5, 0, 29, 1, " //search, autotranscode, transcoder, tsdefault
5.146 "0, 0, 0, 0 );", //autouserjob1, autouserjob2, autouserjob3, autouserjob4
5.147 schedule_info->record_id, schedule_info->channel_id,
5.148 - start_tm.tm_hour, start_tm.tm_min,
5.149 - start_tm.tm_year+1900, start_tm.tm_mon+1,
5.150 - start_tm.tm_mday,
5.151 - end_tm.tm_hour, end_tm.tm_min,
5.152 - end_tm.tm_year+1900, end_tm.tm_mon+1,
5.153 - end_tm.tm_mday, schedule_info->title->str, //title
5.154 + gmyth_util_time_to_string_only_time( schedule_info->start_time ),
5.155 + gmyth_util_time_to_string_only_date( schedule_info->start_time ),
5.156 + gmyth_util_time_to_string_only_time( schedule_info->end_time ),
5.157 + gmyth_util_time_to_string_only_date( schedule_info->end_time ),
5.158 + schedule_info->title->str, //title
5.159 schedule_info->channel_id,//station
5.160 - start_tm.tm_wday+1, //findday
5.161 - start_tm.tm_hour, start_tm.tm_min, //findtime
5.162 - (gint)(schedule_info->start_time/60/60/24 + 719528)//findid
5.163 + g_date_get_weekday( gmyth_util_time_val_to_date( schedule_info->start_time ) ), //findday
5.164 + gmyth_util_time_to_string_only_time( schedule_info->start_time ), //findtime
5.165 + (gint)(schedule_info->start_time->tv_sec/60/60/24 + 719528)//findid
5.166 );
5.167
5.168 msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
5.169 @@ -495,12 +486,12 @@
5.170 */
5.171 GMythProgramInfo*
5.172 gmyth_scheduler_get_recorded (GMythScheduler *scheduler,
5.173 - GString *channel, time_t starttime)
5.174 + GString *channel, GTimeVal* starttime)
5.175 {
5.176 MYSQL_RES *msql_res;
5.177 GMythProgramInfo *proginfo = NULL;
5.178 GString *query_str = g_string_new("");
5.179 - GString *time_str = gmyth_util_time_to_string (starttime);
5.180 + gchar *time_str = gmyth_util_time_to_string_from_time_val (starttime);
5.181
5.182 assert(scheduler);
5.183
5.184 @@ -521,7 +512,7 @@
5.185 "ON recorded.chanid = channel.chanid "
5.186 "WHERE recorded.chanid = \"%s\" "
5.187 "AND starttime = \"%s\" ;",
5.188 - channel->str, time_str->str);
5.189 + channel->str, time_str);
5.190
5.191 msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
5.192
5.193 @@ -533,10 +524,10 @@
5.194 proginfo = g_new0 (GMythProgramInfo, 1);
5.195
5.196 proginfo->chanid = g_string_new (msql_row[0]);
5.197 - proginfo->startts = gmyth_util_string_to_time (g_string_new (msql_row[23]));
5.198 - proginfo->endts = gmyth_util_string_to_time (g_string_new (msql_row[24]));
5.199 - proginfo->recstartts = gmyth_util_string_to_time (g_string_new (msql_row[1]));
5.200 - proginfo->recendts = gmyth_util_string_to_time (g_string_new (msql_row[2]));
5.201 + proginfo->startts = gmyth_util_string_to_time_val (msql_row[23]);
5.202 + proginfo->endts = gmyth_util_string_to_time_val (msql_row[24]);
5.203 + proginfo->recstartts = gmyth_util_string_to_time_val (msql_row[1]);
5.204 + proginfo->recendts = gmyth_util_string_to_time_val (msql_row[2]);
5.205 proginfo->title = g_string_new (msql_row[3]);
5.206 proginfo->subtitle = g_string_new (msql_row[4]);
5.207 proginfo->description = g_string_new (msql_row[5]);
5.208 @@ -550,7 +541,7 @@
5.209 proginfo->programid = g_string_new (msql_row[12]);
5.210 proginfo->filesize = g_ascii_strtoull (msql_row[13], NULL, 10);
5.211
5.212 - proginfo->lastmodified = gmyth_util_string_to_time (g_string_new (msql_row[14]));
5.213 + proginfo->lastmodified = gmyth_util_string_to_time_val (msql_row[14]);
5.214
5.215 proginfo->stars = g_ascii_strtod (msql_row[15], NULL);
5.216 proginfo->repeat = g_ascii_strtoull (msql_row[16], NULL, 10);
5.217 @@ -559,7 +550,7 @@
5.218 proginfo->originalAirDate = 0;
5.219 proginfo->hasAirDate = FALSE;
5.220 } else {
5.221 - proginfo->originalAirDate = gmyth_util_string_to_time (g_string_new (msql_row[17]));
5.222 + proginfo->originalAirDate = gmyth_util_string_to_time_val (msql_row[17]);
5.223 proginfo->hasAirDate = TRUE;
5.224 }
5.225
5.226 @@ -582,7 +573,7 @@
5.227
5.228 mysql_free_result (msql_res);
5.229 g_string_free(query_str, TRUE);
5.230 - g_string_free(time_str, TRUE);
5.231 + g_free(time_str);
5.232
5.233 return proginfo;
5.234 }
6.1 --- a/gmyth/src/gmyth_scheduler.h Fri Dec 08 23:16:15 2006 +0000
6.2 +++ b/gmyth/src/gmyth_scheduler.h Tue Dec 12 17:59:47 2006 +0000
6.3 @@ -102,8 +102,8 @@
6.4 gint program_id;
6.5 gint channel_id;
6.6
6.7 - time_t start_time;
6.8 - time_t end_time;
6.9 + GTimeVal* start_time;
6.10 + GTimeVal* end_time;
6.11
6.12 GString *title;
6.13 GString *subtitle;
6.14 @@ -117,8 +117,8 @@
6.15 guint program_id;
6.16 guint channel_id;
6.17
6.18 - time_t start_time;
6.19 - time_t end_time;
6.20 + GTimeVal* start_time;
6.21 + GTimeVal* end_time;
6.22
6.23 GString *title;
6.24 GString *subtitle;
6.25 @@ -144,7 +144,7 @@
6.26 GList **rec_list);
6.27
6.28 GMythProgramInfo* gmyth_scheduler_get_recorded (GMythScheduler *scheduler,
6.29 - GString *channel, time_t starttime);
6.30 + GString *channel, GTimeVal* starttime);
6.31
6.32 gint gmyth_scheduler_add_schedule(GMythScheduler *scheduler,
6.33 ScheduleInfo *schedule_info);
7.1 --- a/gmyth/src/gmyth_tvchain.c Fri Dec 08 23:16:15 2006 +0000
7.2 +++ b/gmyth/src/gmyth_tvchain.c Tue Dec 12 17:59:47 2006 +0000
7.3 @@ -71,7 +71,7 @@
7.4 tvchain->tvchain_id = NULL;
7.5
7.6 tvchain->cur_chanid = g_string_new ("");
7.7 - tvchain->cur_startts = 0;
7.8 + tvchain->cur_startts = NULL;
7.9 }
7.10
7.11 static void
7.12 @@ -130,19 +130,20 @@
7.13 hostname = gmyth_backend_info_get_hostname (backend_info);
7.14
7.15 if (tvchain->tvchain_id == NULL) {
7.16 - GString *isodate;
7.17 - time_t cur_time;
7.18 + gchar *isodate = NULL;
7.19 + GTimeVal *cur_time = g_new0( GTimeVal, 1 );
7.20
7.21 - time(&cur_time);
7.22 - isodate = gmyth_util_time_to_isoformat (cur_time);
7.23 + g_get_current_time(cur_time);
7.24 + isodate = gmyth_util_time_to_isoformat_from_time_val (cur_time);
7.25
7.26 - tvchain->tvchain_id = g_string_sized_new (7 + strlen (hostname) + isodate->len);
7.27 + tvchain->tvchain_id = g_string_sized_new (7 + strlen (hostname) + strlen(isodate));
7.28 g_string_printf(tvchain->tvchain_id,
7.29 - "live-%s-%s", hostname, isodate->str);
7.30 + "live-%s-%s", hostname, isodate);
7.31
7.32 gmyth_debug ("[%s] tv_chain_id: %s", __FUNCTION__, tvchain->tvchain_id->str);
7.33
7.34 - g_string_free(isodate, TRUE);
7.35 + if (isodate)
7.36 + g_free(isodate);
7.37 } else {
7.38 g_warning ("[%s] TVchain already initialized", __FUNCTION__);
7.39 }
7.40 @@ -214,8 +215,8 @@
7.41 while ((msql_row = mysql_fetch_row (msql_res)) != NULL) {
7.42 struct LiveTVChainEntry *entry = g_new0 (struct LiveTVChainEntry, 1);
7.43 entry->chanid = g_string_new (msql_row[0]);
7.44 - entry->starttime = gmyth_util_string_to_time (g_string_new ((gchar*)msql_row[1]));
7.45 - entry->endtime = gmyth_util_string_to_time (g_string_new (msql_row[2]));
7.46 + entry->starttime = gmyth_util_string_to_time_val ((gchar*)msql_row[1]);
7.47 + entry->endtime = gmyth_util_string_to_time_val (msql_row[2]);
7.48 entry->discontinuity = atoi (msql_row[3]) != 0;
7.49 entry->hostprefix = g_string_new (msql_row[5]);
7.50 entry->cardtype = g_string_new (msql_row[6]);
7.51 @@ -275,10 +276,10 @@
7.52 * @param chanid The channel id.
7.53 * @param startts The program start time.
7.54 */
7.55 -int
7.56 -gmyth_tvchain_program_is_at (GMythTVChain *tvchain, GString *chanid, time_t startts)
7.57 +gint
7.58 +gmyth_tvchain_program_is_at (GMythTVChain *tvchain, GString *chanid, GTimeVal* startts)
7.59 {
7.60 - int count = 0;
7.61 + gint count = 0;
7.62 struct LiveTVChainEntry *entry;
7.63 GList *tmp_list = tvchain->tvchain_list;
7.64 guint list_size = g_list_length (tvchain->tvchain_list);
7.65 @@ -288,8 +289,8 @@
7.66 for (; tmp_list && ( count < list_size ); tmp_list = tvchain->tvchain_list->next, count++)
7.67 {
7.68 entry = (struct LiveTVChainEntry*) tmp_list->data;
7.69 - if (!g_strncasecmp (entry->chanid->str, chanid->str, chanid->len)
7.70 - && entry->starttime == startts)
7.71 + if ( !g_strncasecmp (entry->chanid->str, chanid->str, chanid->len)
7.72 + && entry->starttime == startts )
7.73 {
7.74 g_static_mutex_unlock( &mutex );
7.75 return count;
7.76 @@ -307,7 +308,7 @@
7.77 * @return The program info structure.
7.78 */
7.79 GMythProgramInfo*
7.80 -gmyth_tvchain_get_program_at (GMythTVChain *tvchain, int index)
7.81 +gmyth_tvchain_get_program_at (GMythTVChain *tvchain, gint index)
7.82 {
7.83 struct LiveTVChainEntry *entry;
7.84
7.85 @@ -326,7 +327,7 @@
7.86 * @return The LiveTVchainEntry structure.
7.87 */
7.88 struct LiveTVChainEntry*
7.89 -gmyth_tvchain_get_entry_at (GMythTVChain *tvchain, int index)
7.90 +gmyth_tvchain_get_entry_at (GMythTVChain *tvchain, gint index)
7.91 {
7.92 struct LiveTVChainEntry* chain_entry = NULL;
7.93
7.94 @@ -334,8 +335,8 @@
7.95
7.96 g_static_mutex_lock( &mutex );
7.97
7.98 - int size = g_list_length (tvchain->tvchain_list);
7.99 - int new_index = (index < 0 || index >= size) ? size - 1 : index;
7.100 + gint size = g_list_length (tvchain->tvchain_list);
7.101 + gint new_index = (index < 0 || index >= size) ? size - 1 : index;
7.102
7.103 if (new_index >= 0)
7.104 chain_entry = (struct LiveTVChainEntry*) g_list_nth_data (tvchain->tvchain_list, new_index);
7.105 @@ -380,7 +381,7 @@
7.106 if (proginfo) {
7.107 proginfo->pathname = g_string_prepend (proginfo->pathname, entry->hostprefix->str);
7.108 } else {
7.109 - g_warning ("tvchain_entry_to_program(%s, %ld) failed!", entry->chanid->str, entry->starttime);
7.110 + g_warning ("tvchain_entry_to_program( chan id = %s, starttime = %ld) failed!", entry->chanid->str, entry->starttime);
7.111 }
7.112
7.113 return proginfo;
8.1 --- a/gmyth/src/gmyth_tvchain.h Fri Dec 08 23:16:15 2006 +0000
8.2 +++ b/gmyth/src/gmyth_tvchain.h Tue Dec 12 17:59:47 2006 +0000
8.3 @@ -53,8 +53,8 @@
8.4 {
8.5 GString *chanid;
8.6
8.7 - time_t starttime;
8.8 - time_t endtime;
8.9 + GTimeVal* starttime;
8.10 + GTimeVal* endtime;
8.11
8.12 gboolean discontinuity; // if true, can't play smooth from last entry
8.13 GString *hostprefix;
8.14 @@ -79,9 +79,9 @@
8.15 GString *tvchain_id;
8.16 GList *tvchain_list;
8.17
8.18 - time_t cur_startts;
8.19 + GTimeVal* cur_startts;
8.20 GString *cur_chanid;
8.21 - int cur_pos;
8.22 + gint cur_pos;
8.23
8.24 GMythBackendInfo *backend_info;
8.25 };
8.26 @@ -93,8 +93,8 @@
8.27 GMythBackendInfo *backend_info);
8.28 gboolean gmyth_tvchain_reload_all (GMythTVChain *tvchain);
8.29 GString* gmyth_tvchain_get_id (GMythTVChain *tvchain);
8.30 -int gmyth_tvchain_program_is_at (GMythTVChain *tvchain,
8.31 - GString *chanid, time_t startts);
8.32 +gint gmyth_tvchain_program_is_at (GMythTVChain *tvchain,
8.33 + GString *chanid, GTimeVal* startts);
8.34
8.35 struct LiveTVChainEntry* gmyth_tvchain_get_entry_at (GMythTVChain *tvchain,
8.36 gint index);
9.1 --- a/gmyth/src/gmyth_util.c Fri Dec 08 23:16:15 2006 +0000
9.2 +++ b/gmyth/src/gmyth_util.c Tue Dec 12 17:59:47 2006 +0000
9.3 @@ -29,17 +29,17 @@
9.4 #include "config.h"
9.5 #endif
9.6
9.7 -#include "gmyth_util.h"
9.8 +#define _XOPEN_SOURCE
9.9 +#define _XOPEN_SOURCE_EXTENDED
9.10
9.11 #include <glib.h>
9.12 #include <glib/gprintf.h>
9.13 +#include <time.h>
9.14 +#include <sys/time.h>
9.15
9.16 -#include "gmyth_backendinfo.h"
9.17 -#include "gmyth_socket.h"
9.18 -#include "gmyth_programinfo.h"
9.19 -#include "gmyth_common.h"
9.20 -#include "gmyth_debug.h"
9.21 +#include "gmyth.h"
9.22
9.23 +static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
9.24
9.25 /** Converts a time_t struct in a GString at ISO standard format
9.26 * (e.g. 2006-07-20T09:56:41).
9.27 @@ -56,7 +56,10 @@
9.28 struct tm tm_time;
9.29 GString *result;
9.30
9.31 + g_static_mutex_lock ( &mutex );
9.32 +
9.33 if (localtime_r(&time_value, &tm_time) == NULL) {
9.34 + g_static_mutex_unlock ( &mutex );
9.35 g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
9.36 return NULL;
9.37 }
9.38 @@ -65,8 +68,114 @@
9.39 g_string_printf(result, "%04d-%02d-%02dT%02d:%02d:%02d",
9.40 tm_time.tm_year + 1900, tm_time.tm_mon + 1, tm_time.tm_mday,
9.41 tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
9.42 +
9.43 + gmyth_debug( "Result (ISO 8601) = %s", result->str );
9.44 +
9.45 + g_static_mutex_unlock ( &mutex );
9.46
9.47 return result;
9.48 +
9.49 +
9.50 +}
9.51 +
9.52 +/** Converts a time_t struct in a GString at ISO standard format
9.53 + * (e.g. 2006-07-20T09:56:41).
9.54 + *
9.55 + * The returned GString memory should be deallocated from
9.56 + * the calling function.
9.57 + *
9.58 + * @param time_value the GTimeValue to be converted
9.59 + * @return GString* the converted isoformat string
9.60 + */
9.61 +static gchar*
9.62 +gmyth_util_time_to_isoformat_from_time_val_fmt ( const gchar *fmt_string, GTimeVal* time)
9.63 +{
9.64 +
9.65 + gchar *result = g_time_val_to_iso8601( time );
9.66 + gmyth_debug ("GMythUtil: before transcoding, result is: %s!\n", result);
9.67 +
9.68 + struct tm* tm_timeval = g_new0( struct tm, 1 );
9.69 +
9.70 + g_return_val_if_fail( fmt_string != NULL, NULL );
9.71 +
9.72 + if ( NULL == time ) {
9.73 + gmyth_debug ("GMythUtil: time_to_isoformat_from_time converter error (timeval == NULL)!\n");
9.74 + return NULL;
9.75 + }
9.76 +
9.77 + g_static_mutex_lock ( &mutex );
9.78 +
9.79 + strptime( result, "%Y-%m-%dT%H:%M:%SZ", tm_timeval );
9.80 +
9.81 + //g_date_set_time_val( date, time );
9.82 +
9.83 + //g_date_strftime( result, 21, fmt_string, date );
9.84 + strftime( result, strlen(result), fmt_string, tm_timeval );
9.85 +
9.86 + g_static_mutex_unlock ( &mutex );
9.87 +
9.88 + gmyth_debug( "Result (ISO 8601) = %s", result );
9.89 +
9.90 + //if ( date != NULL )
9.91 + // g_date_free( date );
9.92 +
9.93 + return result;
9.94 +
9.95 +}
9.96 +
9.97 +/** Converts a time_t struct in a GString at ISO standard format
9.98 + * (e.g. 2006-07-20T09:56:41).
9.99 + *
9.100 + * The returned GString memory should be deallocated from
9.101 + * the calling function.
9.102 + *
9.103 + * @param time_value the GTimeValue to be converted
9.104 + * @return GString* the converted isoformat string
9.105 + */
9.106 +gchar*
9.107 +gmyth_util_time_to_isoformat_from_time_val ( GTimeVal* time )
9.108 +{
9.109 + gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%Y-%m-%d %T", time );
9.110 + //result[10] = ' ';
9.111 + //result[ strlen(result) - 1] = '\0';
9.112 +
9.113 + return result;
9.114 +}
9.115 +
9.116 +/** Converts a time_t struct in a GString at ISO standard format
9.117 + * (e.g. 2006-07-20T09:56:41).
9.118 + *
9.119 + * The returned GString memory should be deallocated from
9.120 + * the calling function.
9.121 + *
9.122 + * @param time_value the GTimeValue to be converted
9.123 + * @return GString* the converted isoformat string
9.124 + */
9.125 +gchar*
9.126 +gmyth_util_time_to_string_only_date ( GTimeVal* time )
9.127 +{
9.128 + gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%y-%m-%d", time );
9.129 + result[10] = ' ';
9.130 + result[ strlen(result) - 1] = '\0';
9.131 + return result;
9.132 +}
9.133 +
9.134 +/** Converts a time_t struct in a GString at ISO standard format
9.135 + * (e.g. 2006-07-20T09:56:41).
9.136 + *
9.137 + * The returned GString memory should be deallocated from
9.138 + * the calling function.
9.139 + *
9.140 + * @param time_value the GTimeValue to be converted
9.141 + * @return GString* the converted isoformat string
9.142 + */
9.143 +gchar*
9.144 +gmyth_util_time_to_string_only_time ( GTimeVal* time )
9.145 +{
9.146 + gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%T", time );
9.147 + result[10] = ' ';
9.148 + result[ strlen(result) - 1] = '\0';
9.149 + return result;
9.150 }
9.151
9.152 /** Converts a time_t struct in a GString to the following
9.153 @@ -87,6 +196,23 @@
9.154 return result;
9.155 }
9.156
9.157 +/** Converts a time_t struct in a GString to the following
9.158 + * format (e.g. 2006-07-20 09:56:41).
9.159 + *
9.160 + * The returned GString memory should be deallocated from
9.161 + * the calling function.
9.162 + *
9.163 + * @param time_value the time value to be converted
9.164 + * @return GString* the converted string
9.165 + */
9.166 +gchar*
9.167 +gmyth_util_time_to_string_from_time_val (GTimeVal *time_val)
9.168 +{
9.169 + gchar *result = gmyth_util_time_to_isoformat_from_time_val (time_val);
9.170 +
9.171 + return result;
9.172 +}
9.173 +
9.174 /** Converts a GString in the following format
9.175 * (e.g. 2006-07-20 09:56:41) to a time_t struct.
9.176 *
9.177 @@ -96,27 +222,106 @@
9.178 time_t
9.179 gmyth_util_string_to_time (GString* time_str)
9.180 {
9.181 - int year, month, day, hour, min, sec;
9.182 + gint year, month, day, hour, min, sec;
9.183 + GDate *date = g_date_new();
9.184
9.185 -#if 0
9.186 - gmyth_debug( "[%s] time_str = %s.\n", __FUNCTION__, time_str != NULL ? time_str->str : "[time string is NULL!]" );
9.187 -#endif
9.188 + gmyth_debug( "[%s] time_str = %s. [%s]\n", __FUNCTION__, time_str != NULL ?
9.189 + time_str->str : "[time string is NULL!]", g_strdelimit( time_str->str, " ", 'T' ) );
9.190
9.191 - if (sscanf (time_str->str, "%04d-%02d-%02d %02d:%02d:%02d",
9.192 - &year, &month, &day, &hour, &min, &sec) < 3) { /* At least date */
9.193 +
9.194 + //if (sscanf (time_str->str, "%04d-%02d-%02d %02d:%02d:%02d",
9.195 + // &year, &month, &day, &hour, &min, &sec) < 3) {
9.196 + //g_date_set_parse( date, time_str->str );
9.197 + if ( NULL == date ) {
9.198 g_warning ("GMythUtil: isoformat_to_time converter error!\n");
9.199 return 0;
9.200 - } else {
9.201 - struct tm* tm_time = g_new0( struct tm, 1 );
9.202 + }
9.203 +
9.204 + g_static_mutex_lock ( &mutex );
9.205 + //GDate *date = g_date_new_dmy( day, month - 1, year - 1900 );
9.206 +
9.207 + struct tm* tm_time = g_malloc0( sizeof(struct tm) );
9.208 +/*
9.209 tm_time->tm_year = year - 1900;
9.210 tm_time->tm_mon = month - 1;
9.211 tm_time->tm_mday = day;
9.212 tm_time->tm_hour = hour;
9.213 tm_time->tm_min = min;
9.214 tm_time->tm_sec = sec;
9.215 -
9.216 - return mktime (tm_time);
9.217 + */
9.218 +
9.219 + GTimeVal *time = g_new0( GTimeVal, 1 );
9.220 +
9.221 + if ( !g_time_val_from_iso8601( g_strdelimit( time_str->str, " ", 'T' ), time ) )
9.222 + {
9.223 + gmyth_debug( "ERROR! Problems converting to GTimeVal == %s\n", g_time_val_to_iso8601( time ) );
9.224 + }
9.225 +
9.226 + gmyth_debug( "Converted to GTimeVal == %s\n", g_time_val_to_iso8601( time ) );
9.227 +
9.228 + g_date_set_time_val( date, time );
9.229 +
9.230 + g_date_to_struct_tm( date, tm_time );
9.231 +
9.232 + g_static_mutex_unlock ( &mutex );
9.233 +
9.234 + return mktime( tm_time );
9.235 +}
9.236 +
9.237 +/** Converts a GString in the following format
9.238 + * (e.g. 2006-07-20 09:56:41) to a time_t struct.
9.239 + *
9.240 + * @param time_str the string to be converted
9.241 + * @return time_t the time converted value
9.242 + */
9.243 +GDate *
9.244 +gmyth_util_time_val_to_date (GTimeVal* time)
9.245 +{
9.246 + GDate *date = g_date_new();
9.247 +
9.248 + if ( NULL == date ) {
9.249 + g_warning ("GMythUtil: GDate *gmyth_util_time_val_to_date (GTimeVal* time) - converter error!\n");
9.250 + return 0;
9.251 }
9.252 +
9.253 + g_date_set_time_val( date, time );
9.254 +
9.255 + gmyth_debug( "Converted from GTimeVal == %s to GDate\n", g_time_val_to_iso8601( time ) );
9.256 +
9.257 + return date;
9.258 +}
9.259 +
9.260 +/** Converts a GString in the following format
9.261 + * (e.g. 2006-07-20 09:56:41) to a time_t struct.
9.262 + *
9.263 + * @param time_str the string to be converted
9.264 + * @return time_t the time converted value
9.265 + */
9.266 +GTimeVal*
9.267 +gmyth_util_string_to_time_val (gchar* time_str)
9.268 +{
9.269 + GTimeVal *time = g_new0( GTimeVal, 1 );
9.270 +
9.271 + gmyth_debug( "[%s] time_str = %s. [%s]\n", __FUNCTION__, time_str != NULL ?
9.272 + time_str : "[time string is NULL!]", g_strdelimit( time_str, " ", 'T' ) );
9.273 +
9.274 + if ( NULL == time ) {
9.275 + g_warning ("GMythUtil: isoformat_to_time converter error!\n");
9.276 + return NULL;
9.277 + }
9.278 +
9.279 + g_static_mutex_lock ( &mutex );
9.280 +
9.281 + if ( !g_time_val_from_iso8601( g_strdelimit( time_str, " ", 'T' ), time ) )
9.282 + {
9.283 + gmyth_debug( "ERROR! Problems converting to GTimeVal == %s\n", g_strdelimit( time_str, " ", 'T' ) );
9.284 + }
9.285 +
9.286 + gmyth_debug( "Converted to GTimeVal == %s\n", g_time_val_to_iso8601( time ) );
9.287 +
9.288 + g_static_mutex_unlock ( &mutex );
9.289 +
9.290 + return time;
9.291 }
9.292
9.293 /** Decodes a long long variable from the string list
9.294 @@ -150,7 +355,7 @@
9.295 }
9.296
9.297 gboolean
9.298 -gmyth_util_file_exists (GMythBackendInfo *backend_info, const char* filename)
9.299 +gmyth_util_file_exists (GMythBackendInfo *backend_info, const gchar* filename)
9.300 {
9.301 GMythSocket *socket;
9.302 gboolean res;
10.1 --- a/gmyth/src/gmyth_util.h Fri Dec 08 23:16:15 2006 +0000
10.2 +++ b/gmyth/src/gmyth_util.h Tue Dec 12 17:59:47 2006 +0000
10.3 @@ -36,13 +36,25 @@
10.4
10.5 G_BEGIN_DECLS
10.6
10.7 -GString * gmyth_util_time_to_isoformat(time_t time_value);
10.8 -GString * gmyth_util_time_to_string (time_t time_value);
10.9 +GString *gmyth_util_time_to_isoformat(time_t time_value);
10.10 +GString *gmyth_util_time_to_string (time_t time_value);
10.11 time_t gmyth_util_string_to_time (GString* time_str);
10.12 -gint64 gmyth_util_decode_long_long (GMythStringList *strlist,
10.13 +gint64 gmyth_util_decode_long_long (GMythStringList *strlist,
10.14 guint offset);
10.15 +
10.16 +GTimeVal *gmyth_util_string_to_time_val (gchar* time_str);
10.17
10.18 -gboolean gmyth_util_file_exists (GMythBackendInfo *backend_info, const char* filename);
10.19 +gchar *gmyth_util_time_to_isoformat_from_time_val(GTimeVal *time);
10.20 +
10.21 +gchar *gmyth_util_time_to_string_only_date ( GTimeVal* time );
10.22 +
10.23 +gchar *gmyth_util_time_to_string_only_time ( GTimeVal* time );
10.24 +
10.25 +gchar *gmyth_util_time_to_string_from_time_val (GTimeVal *time_val);
10.26 +
10.27 +GDate *gmyth_util_time_val_to_date (GTimeVal* time);
10.28 +
10.29 +gboolean gmyth_util_file_exists (GMythBackendInfo *backend_info, const gchar* filename);
10.30
10.31 G_END_DECLS
10.32