[svn r442] added backend_info to constructor trunk
authorleo_sobral
Fri Mar 23 13:47:31 2007 +0000 (2007-03-23)
branchtrunk
changeset 43784d70ba2ac65
parent 436 7304e78d6307
child 438 2ca84b85d2dd
[svn r442] added backend_info to constructor
gmyth/src/gmyth_livetv.c
     1.1 --- a/gmyth/src/gmyth_livetv.c	Fri Mar 23 13:43:28 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_livetv.c	Fri Mar 23 13:47:31 2007 +0000
     1.3 @@ -69,6 +69,7 @@
     1.4  static void
     1.5  gmyth_livetv_init (GMythLiveTV *livetv)
     1.6  {
     1.7 +    livetv->monitor = NULL;
     1.8  	livetv->backend_info = NULL;
     1.9  	livetv->local_hostname = NULL;
    1.10  	livetv->file_transfer = NULL;
    1.11 @@ -80,8 +81,7 @@
    1.12  	livetv->proginfo = NULL;
    1.13  	livetv->uri = NULL;
    1.14  	
    1.15 -	livetv->mutex = NULL;
    1.16 -
    1.17 +	livetv->mutex = g_mutex_new();
    1.18  }
    1.19  
    1.20  static void
    1.21 @@ -89,13 +89,20 @@
    1.22  {	
    1.23  	GMythLiveTV *livetv = GMYTH_LIVETV (object);
    1.24  
    1.25 +    if (livetv->disposed) {
    1.26 +        /* If dispose did already run, return. */
    1.27 +        return;
    1.28 +    }
    1.29 +    
    1.30 +    /* Make sure dispose does not run twice. */
    1.31 +    livetv->disposed = TRUE;
    1.32 +
    1.33  	if ( livetv->monitor != NULL ) {
    1.34  		g_object_unref (livetv->monitor);
    1.35  		livetv->monitor = NULL;
    1.36  	}
    1.37  	
    1.38  	if ( livetv->recorder != NULL ) {
    1.39 -		//gmyth_livetv_stop_playing( 
    1.40  		g_object_unref (livetv->recorder);
    1.41  		livetv->recorder = NULL;
    1.42  	}
    1.43 @@ -115,7 +122,7 @@
    1.44  		livetv->proginfo = NULL;
    1.45  	}
    1.46  	
    1.47 -	if ( livetv->file_transfer != NULL && G_IS_OBJECT(livetv->file_transfer) ) {
    1.48 +	if ( livetv->file_transfer != NULL ) {
    1.49  		g_object_unref (livetv->file_transfer);
    1.50  		livetv->file_transfer = NULL;
    1.51  	}
    1.52 @@ -125,18 +132,18 @@
    1.53  		livetv->backend_info = NULL;
    1.54  	}
    1.55  	
    1.56 -	if ( livetv->uri != NULL )
    1.57 -	{
    1.58 +	if ( livetv->uri != NULL ) {
    1.59  		g_object_unref (livetv->uri);
    1.60  		livetv->uri = NULL;
    1.61  	}
    1.62  	
    1.63 -	if ( livetv->mutex != NULL )
    1.64 -	{
    1.65 +	if ( livetv->mutex != NULL ) {
    1.66  		g_mutex_free (livetv->mutex);
    1.67  		livetv->mutex = NULL;
    1.68  	}
    1.69 -	
    1.70 +
    1.71 +    g_string_free (livetv->local_hostname, TRUE);
    1.72 +
    1.73  	G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
    1.74  }
    1.75  
    1.76 @@ -154,12 +161,13 @@
    1.77   * @return a newly allocated GMythLiveTV instance
    1.78   */
    1.79  GMythLiveTV*
    1.80 -gmyth_livetv_new ()
    1.81 +gmyth_livetv_new (GMythBackendInfo *backend_info)
    1.82  {
    1.83  	GMythLiveTV *livetv = GMYTH_LIVETV ( g_object_new( GMYTH_LIVETV_TYPE, NULL ) );
    1.84 -	
    1.85 -	livetv->mutex = g_mutex_new();
    1.86 -	
    1.87 +    
    1.88 +	livetv->backend_info = backend_info;
    1.89 +    g_object_ref (livetv->backend_info);
    1.90 +
    1.91  	return livetv;
    1.92  }
    1.93  
    1.94 @@ -178,7 +186,6 @@
    1.95  							gchar* message, gpointer user_data )
    1.96  {
    1.97  	GMythLiveTV *live_tv = GMYTH_LIVETV ( user_data );
    1.98 -	//g_object_ref( live_tv );
    1.99  	
   1.100  	gmyth_debug( "LIVETV Signal handler ( msg = %s, code = %d, live_tv param = %s, user_data = %s )\n", message, msg_code, live_tv != NULL ? "" : 
   1.101  					"NULL", user_data != NULL ? "" : "NULL" );
   1.102 @@ -242,7 +249,7 @@
   1.103  			{
   1.104  				gmyth_debug( "Going out the LiveTV... [ \"quit-livetv\" ]" );
   1.105  				
   1.106 -				g_object_unref( live_tv );				
   1.107 +				g_object_unref( live_tv );
   1.108  			} else
   1.109  				gmyth_debug( "LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");				
   1.110  			
   1.111 @@ -351,13 +358,12 @@
   1.112   * 				had been concluded succcesfully 
   1.113   */
   1.114  static gboolean
   1.115 -gmyth_livetv_setup_recorder_channel_name ( GMythLiveTV *livetv, gchar* channel, 
   1.116 -			GMythBackendInfo *backend_info )
   1.117 +gmyth_livetv_setup_recorder_channel_name (GMythLiveTV *livetv, gchar* channel)
   1.118  {
   1.119  	gboolean res = TRUE;
   1.120 -	
   1.121 -	livetv->backend_info = backend_info;
   1.122 -		
   1.123 +    
   1.124 +    g_return_val_if_fail (livetv != NULL, FALSE);
   1.125 +    
   1.126  	if ( NULL == livetv->socket ) {
   1.127  		livetv->socket = gmyth_socket_new ();
   1.128  		
   1.129 @@ -536,7 +542,7 @@
   1.130  		
   1.131  	}
   1.132  	
   1.133 -	livetv->uri = (GMythURI*)gmyth_backend_info_get_uri( backend_info );
   1.134 +	livetv->uri = (GMythURI*)gmyth_backend_info_get_uri( livetv->backend_info );
   1.135  	
   1.136  	g_mutex_unlock( livetv->mutex );
   1.137  
   1.138 @@ -554,11 +560,9 @@
   1.139  error:
   1.140  	g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
   1.141  
   1.142 -	if ( livetv->local_hostname != NULL ) {
   1.143 -		g_string_free( livetv->local_hostname, TRUE );
   1.144 -		livetv->local_hostname = NULL;
   1.145 -		res = FALSE;
   1.146 -	}
   1.147 +    res = FALSE;
   1.148 +
   1.149 +    g_string_free( livetv->local_hostname, TRUE );
   1.150  
   1.151  	if ( livetv->recorder != NULL ) {
   1.152  		g_object_unref (livetv->recorder);
   1.153 @@ -597,10 +601,10 @@
   1.154   * 				had been concluded succcesfully 
   1.155   */
   1.156  static gboolean
   1.157 -gmyth_livetv_setup_recorder ( GMythLiveTV *livetv, gint channel, GMythBackendInfo *backend_info )
   1.158 +gmyth_livetv_setup_recorder ( GMythLiveTV *livetv, gint channel)
   1.159  {
   1.160  	return gmyth_livetv_setup_recorder_channel_name ( livetv, ( channel != -1 ) ? 
   1.161 -				g_strdup_printf( "%d", channel ) : NULL, backend_info );
   1.162 +				g_strdup_printf( "%d", channel ) : NULL );
   1.163  }
   1.164  
   1.165  /**
   1.166 @@ -616,9 +620,9 @@
   1.167   * 				had been concluded succcesfully 
   1.168   */
   1.169  gboolean
   1.170 -gmyth_livetv_channel_setup ( GMythLiveTV *livetv, gint channel, GMythBackendInfo *backend_info )
   1.171 +gmyth_livetv_channel_setup ( GMythLiveTV *livetv, gint channel )
   1.172  {
   1.173 -	return gmyth_livetv_setup_recorder ( livetv, channel, backend_info );
   1.174 +	return gmyth_livetv_setup_recorder ( livetv, channel );
   1.175  }
   1.176  
   1.177  /**
   1.178 @@ -634,9 +638,9 @@
   1.179   * 				had been concluded succcesfully 
   1.180   */
   1.181  gboolean
   1.182 -gmyth_livetv_channel_name_setup ( GMythLiveTV *livetv, gchar* channel, GMythBackendInfo *backend_info )
   1.183 +gmyth_livetv_channel_name_setup ( GMythLiveTV *livetv, gchar* channel )
   1.184  {
   1.185 -	return gmyth_livetv_setup_recorder_channel_name ( livetv, channel, backend_info );
   1.186 +	return gmyth_livetv_setup_recorder_channel_name ( livetv, channel );
   1.187  }
   1.188  
   1.189  /**
   1.190 @@ -651,9 +655,9 @@
   1.191   * 				had been concluded succcesfully 
   1.192   */
   1.193  gboolean
   1.194 -gmyth_livetv_setup ( GMythLiveTV *livetv, GMythBackendInfo *backend_info )
   1.195 +gmyth_livetv_setup ( GMythLiveTV *livetv )
   1.196  {
   1.197 -	return gmyth_livetv_setup_recorder ( livetv, -1, backend_info );
   1.198 +	return gmyth_livetv_setup_recorder ( livetv, -1 );
   1.199  }
   1.200  
   1.201  /**
   1.202 @@ -672,7 +676,6 @@
   1.203  	if ( !livetv->setup_done )
   1.204  	{
   1.205  		gmyth_debug ( "Call the setup function first!" );
   1.206 -		res= FALSE;
   1.207  		goto error;		
   1.208  	}
   1.209  	
   1.210 @@ -683,7 +686,7 @@
   1.211  	{
   1.212  		livetv->proginfo = prog_info;
   1.213  	} else {
   1.214 -		gmyth_debug( "ProgramInfo is equals to NULL!!! Getting the next program info..." );
   1.215 +		gmyth_debug( "ProgramInfo equals to NULL!!! Getting the next program info..." );
   1.216  		prog_info = gmyth_recorder_get_next_program_info( livetv->recorder, BROWSE_DIRECTION_RIGHT );
   1.217  		livetv->proginfo = prog_info;		
   1.218  	}
   1.219 @@ -698,7 +701,6 @@
   1.220  		gmyth_debug ("GMythLiveTV: All requests to backend to start TV were OK, program info changed.");
   1.221  	} else {
   1.222  		g_warning ("[%s] LiveTV not successfully started on the next program chain.\n", __FUNCTION__ );
   1.223 -		res = FALSE;
   1.224  		goto error;
   1.225  	}
   1.226  	
   1.227 @@ -709,10 +711,9 @@
   1.228  error:
   1.229  	g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
   1.230  
   1.231 -	if ( livetv->local_hostname != NULL ) {
   1.232 -		g_string_free( livetv->local_hostname, FALSE );
   1.233 -		res = FALSE;
   1.234 -	}
   1.235 +    res = FALSE;
   1.236 +    
   1.237 +    g_string_free( livetv->local_hostname, TRUE );
   1.238  
   1.239  	if ( livetv->recorder != NULL ) {
   1.240  		g_object_unref (livetv->recorder);
   1.241 @@ -730,7 +731,6 @@
   1.242  	}
   1.243  
   1.244  	return res;
   1.245 -
   1.246  }
   1.247  
   1.248  /**
   1.249 @@ -798,7 +798,7 @@
   1.250    	gmyth_debug( "Couldn't parse the URI to start LiveTV! [ uri = %s ]", livetv->proginfo->pathname->str );
   1.251    	goto done;  	
   1.252    }
   1.253 -  
   1.254 + 
   1.255  	livetv->file_transfer = gmyth_file_transfer_new( livetv->backend_info );
   1.256  
   1.257    if ( NULL == livetv->file_transfer ) 
   1.258 @@ -807,6 +807,8 @@
   1.259      goto done;
   1.260    }
   1.261    
   1.262 +    g_object_ref( livetv->file_transfer );
   1.263 +
   1.264    /* gmyth_file_transfer_settimeout( livetv->file_transfer, TRUE ); */
   1.265  	
   1.266    g_mutex_unlock( livetv->mutex );