[svn r339] GObject's dispose methods organization, and reviewed clean-up actions. trunk
authorrosfran
Thu Feb 08 20:57:31 2007 +0000 (2007-02-08)
branchtrunk
changeset 33760bfeabc0af6
parent 336 3e34d1a2e403
child 338 6d9f4e8468b3
[svn r339] GObject's dispose methods organization, and reviewed clean-up actions.
gmyth/src/gmyth_livetv.c
gmyth/src/gmyth_livetv.h
gmyth/src/gmyth_socket.c
gmyth/src/gmyth_stringlist.c
gmyth/src/gmyth_util.c
     1.1 --- a/gmyth/src/gmyth_livetv.c	Thu Feb 08 14:32:29 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_livetv.c	Thu Feb 08 20:57:31 2007 +0000
     1.3 @@ -71,7 +71,8 @@
     1.4  	livetv->local_hostname = NULL;
     1.5  	livetv->file_transfer = NULL;
     1.6  	livetv->setup_done = FALSE;
     1.7 -
     1.8 +	
     1.9 +	livetv->socket = NULL;
    1.10  	livetv->recorder = NULL;
    1.11  	livetv->tvchain = NULL;
    1.12  	livetv->proginfo = NULL;
    1.13 @@ -88,12 +89,17 @@
    1.14  		g_object_unref (livetv->monitor);
    1.15  		livetv->monitor = NULL;
    1.16  	}
    1.17 -
    1.18 +	
    1.19  	if ( livetv->recorder != NULL ) {
    1.20  		g_object_unref (livetv->recorder);
    1.21  		livetv->recorder = NULL;
    1.22  	}
    1.23  
    1.24 +	if ( livetv->socket != NULL ) {
    1.25 +		g_object_unref (livetv->socket);
    1.26 +		livetv->socket = NULL;
    1.27 +	}
    1.28 +	
    1.29  	if ( livetv->tvchain != NULL ) {
    1.30  		g_object_unref (livetv->tvchain);
    1.31  		livetv->tvchain = NULL;
    1.32 @@ -119,7 +125,6 @@
    1.33  		g_object_unref (livetv->uri);
    1.34  		livetv->uri = NULL;
    1.35  	}
    1.36 -
    1.37  	
    1.38  	G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
    1.39  }
    1.40 @@ -278,15 +283,16 @@
    1.41  			GMythBackendInfo *backend_info )
    1.42  {
    1.43  	gboolean res = TRUE;
    1.44 -
    1.45 -	GMythSocket *socket = gmyth_socket_new ();
    1.46 +	
    1.47 +	if ( NULL == livetv->socket )
    1.48 +		livetv->socket = gmyth_socket_new ();
    1.49  	
    1.50  	livetv->backend_info = backend_info;
    1.51  	
    1.52 -	g_static_mutex_lock( &lock );
    1.53 +	//g_static_mutex_lock( &lock );
    1.54  
    1.55  	/* FIME: Implement this at gmyth_socket */
    1.56 -	res = gmyth_socket_connect_to_backend (socket, livetv->backend_info->hostname,
    1.57 +	res = gmyth_socket_connect_to_backend (livetv->socket, livetv->backend_info->hostname,
    1.58  			livetv->backend_info->port, TRUE);
    1.59  	if (!res) {
    1.60  		g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);	
    1.61 @@ -303,17 +309,17 @@
    1.62  		goto error;
    1.63  	}
    1.64  	
    1.65 -	if ( gmyth_remote_util_get_free_recorder_count (socket) <= 0 ) {
    1.66 +	if ( gmyth_remote_util_get_free_recorder_count (livetv->socket) <= 0 ) {
    1.67  		gmyth_debug ("No free remote encoder available.");
    1.68  		res = FALSE;
    1.69  		goto error;
    1.70  	}
    1.71  
    1.72  	/* Gets the recorder num */
    1.73 -	livetv->recorder = remote_request_next_free_recorder (socket, -1);
    1.74 -	gmyth_socket_close_connection (socket);
    1.75 +	livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1);
    1.76 +	//gmyth_socket_close_connection (socket);
    1.77  
    1.78 -	if ( livetv->recorder == NULL ) {
    1.79 +	if ( NULL == livetv->recorder ) {
    1.80  		g_warning ("[%s] None remote encoder available", __FUNCTION__);
    1.81  		res = FALSE;
    1.82  		goto error;
    1.83 @@ -458,7 +464,7 @@
    1.84  	
    1.85  	livetv->uri = (GMythURI*)gmyth_backend_info_get_uri( backend_info );
    1.86  	
    1.87 -	g_static_mutex_unlock( &lock );
    1.88 +	//g_static_mutex_unlock( &lock );
    1.89  
    1.90  	if ( !gmyth_livetv_monitor_handler_start( livetv ) )
    1.91  	{
     2.1 --- a/gmyth/src/gmyth_livetv.h	Thu Feb 08 14:32:29 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_livetv.h	Thu Feb 08 20:57:31 2007 +0000
     2.3 @@ -61,6 +61,8 @@
     2.4  {
     2.5  	GObject 						parent;
     2.6  	
     2.7 +	GMythSocket					*socket;
     2.8 +	
     2.9  	GString 				 		*local_hostname;
    2.10  	
    2.11  	GMythBackendInfo 		*backend_info;
     3.1 --- a/gmyth/src/gmyth_socket.c	Thu Feb 08 14:32:29 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_socket.c	Thu Feb 08 20:57:31 2007 +0000
     3.3 @@ -71,7 +71,7 @@
     3.4  
     3.5  static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
     3.6  
     3.7 -static GStaticRWLock rwlock = G_STATIC_RW_LOCK_INIT;
     3.8 +/*static GStaticRWLock rwlock = G_STATIC_RW_LOCK_INIT;*/
     3.9  
    3.10  static gchar* local_hostname = NULL;
    3.11  
    3.12 @@ -553,6 +553,8 @@
    3.13  
    3.14      gmyth_socket->sd_io_ch = g_io_channel_unix_new (gmyth_socket->sd);
    3.15      
    3.16 +    g_io_channel_set_close_on_unref (gmyth_socket->sd_io_ch, TRUE);
    3.17 +    
    3.18      //GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch);
    3.19  		/* unset the nonblock flag */
    3.20  		//flags &= ~G_IO_FLAG_NONBLOCK;
    3.21 @@ -927,7 +929,7 @@
    3.22  
    3.23      /* verify if the input (read) buffer is ready to receive data */
    3.24  
    3.25 -    g_static_mutex_lock( &mutex );
    3.26 +    //g_static_mutex_lock( &mutex );
    3.27      //g_static_rw_lock_reader_lock (&rwlock);
    3.28      
    3.29      //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE);
    3.30 @@ -936,8 +938,11 @@
    3.31   		{
    3.32   			gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port );
    3.33   		}
    3.34 - 			
    3.35 -    io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error);
    3.36 + 		
    3.37 + 		if ( gmyth_socket->sd_io_ch->is_readable )
    3.38 +    	io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error);
    3.39 +    else
    3.40 +    	return g_string_new("");
    3.41  
    3.42      /* verify if the input (read) buffer is ready to receive data */
    3.43      io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch);
    3.44 @@ -981,12 +986,16 @@
    3.45  		    bytes_read = 0;
    3.46  				if ( !( gmyth_socket != NULL && gmyth_socket->sd_io_ch != NULL) )
    3.47  					return NULL;
    3.48 -		    io_status = g_io_channel_read_chars( gmyth_socket->sd_io_ch, buffer, len, &bytes_read, &error);
    3.49 +		 		if ( gmyth_socket->sd_io_ch->is_readable )
    3.50 +		    	io_status = g_io_channel_read_chars( gmyth_socket->sd_io_ch, buffer, len, &bytes_read, &error);
    3.51 +		    else
    3.52 +		    	return g_string_new("");
    3.53 +		    	
    3.54  		    buffer[bytes_read] = '\0';
    3.55  			}
    3.56      }
    3.57  
    3.58 -    g_static_mutex_unlock( &mutex );
    3.59 +    //g_static_mutex_unlock( &mutex );
    3.60      //g_static_rw_lock_reader_unlock (&rwlock);
    3.61  
    3.62      gmyth_debug ("Response received from backend: {%s}\n", buffer);
     4.1 --- a/gmyth/src/gmyth_stringlist.c	Thu Feb 08 14:32:29 2007 +0000
     4.2 +++ b/gmyth/src/gmyth_stringlist.c	Thu Feb 08 20:57:31 2007 +0000
     4.3 @@ -66,6 +66,8 @@
     4.4  
     4.5  	if (gmyth_string_list->glist)
     4.6  		gmyth_string_list_clear_all(gmyth_string_list);
     4.7 +		
     4.8 +	g_list_free( gmyth_string_list->glist );
     4.9  
    4.10  	G_OBJECT_CLASS (gmyth_string_list_parent_class)->dispose (object);
    4.11  }
    4.12 @@ -88,6 +90,7 @@
    4.13  gmyth_string_list_new ()
    4.14  {
    4.15      GMythStringList *gmyth_string_list = GMYTH_STRING_LIST (g_object_new (GMYTH_STRING_LIST_TYPE, NULL));
    4.16 +    
    4.17      return gmyth_string_list;
    4.18  }
    4.19  
    4.20 @@ -384,7 +387,8 @@
    4.21  gint
    4.22  gmyth_string_list_length ( GMythStringList *strlist )
    4.23  {
    4.24 -	g_return_val_if_fail( strlist != NULL && strlist->glist != NULL, 0 );
    4.25 +	if ( strlist != NULL && strlist->glist != NULL )
    4.26 +		return 0;
    4.27  
    4.28  	return g_list_length (strlist->glist);
    4.29  }
     5.1 --- a/gmyth/src/gmyth_util.c	Thu Feb 08 14:32:29 2007 +0000
     5.2 +++ b/gmyth/src/gmyth_util.c	Thu Feb 08 20:57:31 2007 +0000
     5.3 @@ -331,7 +331,7 @@
     5.4  	GTimeVal *time = g_new0( GTimeVal, 1 );
     5.5  	struct tm* tm_time = NULL;
     5.6  	time_t time_micros;
     5.7 -	gint result;
     5.8 +	gchar* result;
     5.9  
    5.10  	gmyth_debug( "[%s] time_str = %s. [%s]", time_str, time_str != NULL ? 
    5.11  					time_str : "[time string is NULL!]", time_str );