[svn r222] Some fixes to the GTimeVal, non-conformant g_time_val (ISO 8601) functions. trunk
authorrosfran
Fri Dec 15 00:21:57 2006 +0000 (2006-12-15)
branchtrunk
changeset 221b250ee0438a2
parent 220 462a3c81abd6
child 222 803672c406ec
[svn r222] Some fixes to the GTimeVal, non-conformant g_time_val (ISO 8601) functions.
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_file_transfer.h
gmyth/src/gmyth_util.c
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Wed Dec 13 23:44:04 2006 +0000
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Fri Dec 15 00:21:57 2006 +0000
     1.3 @@ -201,7 +201,6 @@
     1.4  static void
     1.5  gmyth_file_transfer_finalize (GObject *object)
     1.6  {
     1.7 -
     1.8    g_signal_handlers_destroy (object);
     1.9  
    1.10    G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->finalize (object);
    1.11 @@ -440,9 +439,8 @@
    1.12  }
    1.13  
    1.14  static gboolean 
    1.15 -myth_control_acquire_context( gboolean do_wait ) 
    1.16 +myth_control_acquire_context( gboolean do_wait )
    1.17  {
    1.18 -	
    1.19  	gboolean ret = TRUE;	
    1.20  	//guint max_iter = 50;
    1.21  	
    1.22 @@ -466,13 +464,11 @@
    1.23    //g_static_mutex_lock( &st_mutex );
    1.24    
    1.25    return ret;
    1.26 -  
    1.27  }
    1.28  
    1.29  static gboolean 
    1.30  myth_control_release_context( ) 
    1.31  {
    1.32 -	
    1.33  	gboolean ret = TRUE;
    1.34      
    1.35    //g_static_mutex_unlock( &st_mutex );
    1.36 @@ -488,7 +484,6 @@
    1.37    //g_mutex_unlock( mutex );  
    1.38   
    1.39    return ret;
    1.40 -  
    1.41  }
    1.42  
    1.43  gint 
     2.1 --- a/gmyth/src/gmyth_file_transfer.h	Wed Dec 13 23:44:04 2006 +0000
     2.2 +++ b/gmyth/src/gmyth_file_transfer.h	Fri Dec 15 00:21:57 2006 +0000
     2.3 @@ -69,7 +69,7 @@
     2.4  
     2.5    /* signal default handlers */
     2.6    void (*program_info_changed_handler) ( GMythFileTransfer *transfer, 
     2.7 -										gint msg_code, gpointer livetv_transfer );
     2.8 +										gint msg_code, gpointer livetv_transfer, gpointer user_data );
     2.9  };
    2.10  
    2.11  struct _GMythFileTransfer
     3.1 --- a/gmyth/src/gmyth_util.c	Wed Dec 13 23:44:04 2006 +0000
     3.2 +++ b/gmyth/src/gmyth_util.c	Fri Dec 15 00:21:57 2006 +0000
     3.3 @@ -88,37 +88,59 @@
     3.4   * @return GString* the converted isoformat string 
     3.5   */
     3.6  static gchar*
     3.7 -gmyth_util_time_to_isoformat_from_time_val_fmt ( const gchar *fmt_string, GTimeVal* time)
     3.8 +gmyth_util_time_to_isoformat_from_time_val_fmt ( const gchar *fmt_string, GTimeVal* time_val )
     3.9  {
    3.10  	
    3.11 -	gchar *result = g_time_val_to_iso8601( time );
    3.12 -	gmyth_debug ("GMythUtil: before transcoding, result is: %s!\n", result);
    3.13 +	gchar *result = NULL;
    3.14 +	struct tm *tm_time = NULL;
    3.15  	
    3.16 -	struct tm* tm_timeval = g_new0( struct tm, 1 );
    3.17 +	gint buffer_len = 0;
    3.18  	
    3.19 -	g_return_val_if_fail( fmt_string != NULL, NULL );
    3.20 +	g_return_val_if_fail( fmt_string != NULL, NULL );	
    3.21 +	g_return_val_if_fail( time_val != NULL, NULL );
    3.22 + 
    3.23 +	time_t time = time_val->tv_sec + (gint)(time_val->tv_usec / G_USEC_PER_SEC);
    3.24  
    3.25 -  if ( NULL == time ) { 
    3.26 -		gmyth_debug ("GMythUtil: time_to_isoformat_from_time converter error (timeval == NULL)!\n");
    3.27 -		return NULL;
    3.28 +	tm_time = g_malloc0( sizeof(struct tm) );
    3.29 +
    3.30 +	g_static_mutex_lock ( &mutex );
    3.31 +	
    3.32 +	if ( NULL == gmtime_r( &time, tm_time ) ) {
    3.33 +		g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
    3.34 +	}	else {
    3.35 +		// we first check the return of strftime to allocate a buffer of the correct size
    3.36 +	  buffer_len = strftime( NULL, SSIZE_MAX, fmt_string, tm_time );
    3.37 +	  if( buffer_len > 0 ){
    3.38 +	    result = g_malloc0( buffer_len + 1 );
    3.39 +	    if( result == NULL ){     
    3.40 +				g_static_mutex_unlock ( &mutex );
    3.41 +				g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
    3.42 +				return NULL;
    3.43 +	    }
    3.44 +	    strftime( result, buffer_len + 1, fmt_string, tm_time );
    3.45 +	    gmyth_debug( "Dateline (ISO result): %s\n", result );
    3.46 +	  }
    3.47 +		
    3.48  	}
    3.49  	
    3.50 -	g_static_mutex_lock ( &mutex );
    3.51 +	/* 
    3.52 +	if ( NULL == asctime_r( tm_time, result ) ) {
    3.53 +		g_static_mutex_unlock ( &mutex );
    3.54 +		g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
    3.55 +    return NULL;
    3.56 +	}
    3.57 +	*/
    3.58  	
    3.59 -	strptime( result, "%Y-%m-%dT%H:%M:%SZ", tm_timeval ); 
    3.60 +	gmyth_debug( "Result (after asctime_r) = %s", result );
    3.61  	
    3.62 -	//g_date_set_time_val( date, time );
    3.63 +	//strptime( result, "%Y-%m-%dT%H:%M:%SZ", tm_time ); 
    3.64  	
    3.65 -	//g_date_strftime( result, 21, fmt_string, date );
    3.66 -	strftime( result, strlen(result), fmt_string, tm_timeval );
    3.67 +	//strftime( result, strlen(result), fmt_string, tm_time );
    3.68  	
    3.69  	g_static_mutex_unlock ( &mutex );
    3.70  	
    3.71  	gmyth_debug( "Result (ISO 8601) = %s", result  );
    3.72  	
    3.73 -	//if ( date != NULL )
    3.74 -	//	g_date_free( date );
    3.75 -	
    3.76  	return result;	
    3.77  		
    3.78  }
    3.79 @@ -135,7 +157,7 @@
    3.80  gchar*
    3.81  gmyth_util_time_to_isoformat_from_time_val ( GTimeVal* time )
    3.82  {
    3.83 -	gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%Y-%m-%d %T", time );
    3.84 +	gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%Y-%m-%dT%T", time );
    3.85  	//result[10] = ' ';
    3.86  	//result[ strlen(result) - 1] = '\0';
    3.87  	
    3.88 @@ -209,6 +231,7 @@
    3.89  gmyth_util_time_to_string_from_time_val (GTimeVal *time_val)
    3.90  {
    3.91  	gchar *result = gmyth_util_time_to_isoformat_from_time_val (time_val);
    3.92 +	result[10] = ' ';
    3.93  
    3.94  	return result;
    3.95  }