# HG changeset patch # User rosfran # Date 1175540756 -3600 # Node ID 5e1afa4a66e80a78f41014fdc99b4d03ced18a26 # Parent d220053366be301d488ca13821e5f68250161331 [svn r484] Added gmyth_util_get_channel_list to the gmyth_util.h; removes static_mutex locking/unlocking from the gmyth_util. diff -r d220053366be -r 5e1afa4a66e8 gmyth/src/gmyth_recorder.c --- a/gmyth/src/gmyth_recorder.c Mon Apr 02 18:00:39 2007 +0100 +++ b/gmyth/src/gmyth_recorder.c Mon Apr 02 20:05:56 2007 +0100 @@ -102,9 +102,12 @@ void gmyth_recorder_close(GMythRecorder *recorder) { - gmyth_recorder_stop_playing(recorder); - gmyth_recorder_finish_recording(recorder); - gmyth_recorder_free_tuner(recorder); + if ( recorder != NULL && recorder->recorder_num != -1 ) + { + gmyth_recorder_stop_playing(recorder); + gmyth_recorder_finish_recording(recorder); + gmyth_recorder_free_tuner(recorder); + } } /** Creates a new instance of GMythRecorder. diff -r d220053366be -r 5e1afa4a66e8 gmyth/src/gmyth_util.c --- a/gmyth/src/gmyth_util.c Mon Apr 02 18:00:39 2007 +0100 +++ b/gmyth/src/gmyth_util.c Mon Apr 02 20:05:56 2007 +0100 @@ -55,8 +55,6 @@ #endif -static GStaticMutex mutex = G_STATIC_MUTEX_INIT; - /** Converts a time_t struct in a GString at ISO standard format * (e.g. 2006-07-20T09:56:41). * @@ -72,11 +70,8 @@ struct tm tm_time; GString *result; - g_static_mutex_lock ( &mutex ); - if (localtime_r(&time_value, &tm_time) == NULL) { - g_static_mutex_unlock ( &mutex ); - g_warning ("gmyth_util_time_to_isoformat convertion error!\n"); + gmyth_debug("gmyth_util_time_to_isoformat convertion error!\n"); return NULL; } @@ -87,8 +82,6 @@ gmyth_debug( "Result (ISO 8601) = %s", result->str ); - g_static_mutex_unlock ( &mutex ); - return result; } @@ -118,18 +111,15 @@ tm_time = g_malloc0( sizeof(struct tm) ); - g_static_mutex_lock ( &mutex ); - if ( NULL == localtime_r( &time, tm_time ) ) { - g_warning ("gmyth_util_time_to_isoformat convertion error!\n"); + gmyth_debug ("gmyth_util_time_to_isoformat convertion error!\n"); } else { /* we first check the return of strftime to allocate a buffer of the correct size */ buffer_len = strftime( NULL, SSIZE_MAX, fmt_string, tm_time ); if ( buffer_len > 0 ) { result = g_malloc0( buffer_len + 1 ); if( result == NULL ) { - g_static_mutex_unlock ( &mutex ); - g_warning ("gmyth_util_time_to_isoformat convertion error!\n"); + gmyth_debug ("gmyth_util_time_to_isoformat convertion error!\n"); return NULL; } strftime( result, buffer_len + 1, fmt_string, tm_time ); @@ -145,8 +135,6 @@ g_free (tm_time); - g_static_mutex_unlock ( &mutex ); - gmyth_debug( "Result (ISO 8601) = %s", result ); return result; @@ -276,12 +264,10 @@ if ( sscanf (time_str->str, "%04d-%02d-%02d %02d:%02d:%02d", &year, &month, &day, &hour, &min, &sec) < 3 ) { - g_warning ("GMythUtil: isoformat_to_time converter error!\n"); + gmyth_debug ("GMythUtil: isoformat_to_time converter error!\n"); return 0; } - g_static_mutex_lock ( &mutex ); - struct tm* tm_time = g_malloc0( sizeof(struct tm) ); tm_time->tm_year = year - 1900; tm_time->tm_mon = month - 1; @@ -290,8 +276,6 @@ tm_time->tm_min = min; tm_time->tm_sec = sec; - g_static_mutex_unlock ( &mutex ); - return mktime( tm_time ); } @@ -308,12 +292,12 @@ time_t time_micros = time->tv_sec;// + (gint)( time->tv_usec / G_USEC_PER_SEC ); if ( NULL == date ) { - g_warning ( "GMythUtil: GDate *gmyth_util_time_val_to_date (GTimeVal* time) - converter error!\n" ); + gmyth_debug ( "GMythUtil: GDate *gmyth_util_time_val_to_date (GTimeVal* time) - converter error!\n" ); return NULL; } if ( NULL == localtime_r( &time_micros, date ) ) { - g_warning ( "gmyth_util_time_to_isoformat convertion error!\n" ); + gmyth_debug ( "gmyth_util_time_to_isoformat convertion error!\n" ); return NULL; } @@ -341,12 +325,10 @@ if ( NULL == time_str ) { - g_warning ("GMythUtil: isoformat_to_time converter error!\n"); + gmyth_debug ("GMythUtil: isoformat_to_time converter error!\n"); return NULL; } - g_static_mutex_lock ( &mutex ); - tm_time = g_malloc0( sizeof(struct tm) ); /* we first check the return of strftime to allocate a buffer of the correct size */ @@ -360,7 +342,6 @@ if ( NULL == result) { result = strptime( time_str, "%Y-%m-%dT%H:%M", tm_time ); if ( NULL == result ) { - g_static_mutex_unlock ( &mutex ); gmyth_debug( "Dateline (ISO result): %s", result ); g_free(tm_time); return NULL; @@ -376,7 +357,6 @@ gmyth_debug( "After mktime call... = %s", asctime(tm_time) ); - g_static_mutex_unlock ( &mutex ); g_free (tm_time); return time; @@ -561,6 +541,38 @@ return basename; } + +/** + * Gets the channel list. + * + * @param backend_info The GMythBackendInfo instance. + * + * @return a pointer to a GList with all the channels. + */ +GList * +gmyth_util_get_channel_list (GMythBackendInfo *backend_info) +{ + GMythRecorder *recorder; + GList *channel_list = NULL; + gboolean res = FALSE; + + gmyth_debug ("Gets channel list."); + + g_return_val_if_fail (backend_info != NULL, FALSE); + + recorder = gmyth_recorder_new ( -1, g_string_new( gmyth_backend_info_get_hostname( backend_info ) ), + gmyth_backend_info_get_port( backend_info ) ); + res = gmyth_recorder_setup (recorder); + + if (res == TRUE) { + channel_list = gmyth_recorder_get_channel_list( recorder ); + } + + g_object_unref (recorder); + + return channel_list; +} + #if !GLIB_CHECK_VERSION (2, 10, 0) /* Hacked from glib 2.10 */ diff -r d220053366be -r 5e1afa4a66e8 gmyth/src/gmyth_util.h --- a/gmyth/src/gmyth_util.h Mon Apr 02 18:00:39 2007 +0100 +++ b/gmyth/src/gmyth_util.h Mon Apr 02 20:05:56 2007 +0100 @@ -68,6 +68,8 @@ gchar* gmyth_util_create_filename( const gint chan_id, const GTimeVal* start_time ); +GList * gmyth_util_get_channel_list (GMythBackendInfo *backend_info); + G_END_DECLS #endif /*GMYTH_UTIL_H_*/