[svn r358] Fixes on the GMythProgramInfo attributes, changes all references from GStaticMutex to GMutex. trunk
authorrosfran
Tue Feb 13 22:33:08 2007 +0000 (2007-02-13)
branchtrunk
changeset 3565486e606498b
parent 355 f7b40eb795c2
child 357 194c44ef8da4
[svn r358] Fixes on the GMythProgramInfo attributes, changes all references from GStaticMutex to GMutex.
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_livetv.c
gmyth/src/gmyth_programinfo.c
gmyth/src/gmyth_programinfo.h
gmyth/src/gmyth_recorder.c
gmyth/src/gmyth_recorder.h
gmyth/src/gmyth_socket.c
gmyth/src/gmyth_socket.h
gmyth/src/gmyth_stringlist.c
gmyth/src/gmyth_uri.c
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Mon Feb 12 17:56:41 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Tue Feb 13 22:33:08 2007 +0000
     1.3 @@ -253,12 +253,14 @@
     1.4    
     1.5    g_return_val_if_fail (transfer != NULL, FALSE);
     1.6    g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE);
     1.7 +  /*
     1.8    
     1.9    if (transfer->filename != NULL)
    1.10    {
    1.11      g_free (transfer->filename);
    1.12      transfer->filename = NULL;
    1.13    }
    1.14 +  */
    1.15  
    1.16    transfer->filename = g_strdup( filename );
    1.17    
    1.18 @@ -268,6 +270,7 @@
    1.19        gmyth_debug ("Connection to backend failed (Control Socket).\n");
    1.20        ret = FALSE;
    1.21      }
    1.22 +  
    1.23    } else {
    1.24      g_warning("Remote transfer control socket already created.\n");
    1.25    }
    1.26 @@ -291,70 +294,85 @@
    1.27    base_str = g_string_new ("");
    1.28  
    1.29    /* Creates the control socket */
    1.30 +  
    1.31    if (transfer->control_sock != NULL) {
    1.32      g_object_unref (transfer->control_sock);
    1.33      transfer->control_sock = NULL;
    1.34    }
    1.35 +  
    1.36 +  //if ( NULL == transfer->control_sock )
    1.37 +  //{
    1.38 +  	transfer->control_sock = gmyth_socket_new();
    1.39  
    1.40 -  transfer->control_sock = gmyth_socket_new();
    1.41 -
    1.42 -  // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version 
    1.43 -  if (!gmyth_socket_connect_to_backend (transfer->control_sock,
    1.44 -        transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) {
    1.45 -
    1.46 -    g_object_unref (transfer->control_sock);
    1.47 -    transfer->control_sock = NULL;
    1.48 -    return FALSE;
    1.49 -  }
    1.50 +	  // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version 
    1.51 +	  if (!gmyth_socket_connect_to_backend (transfer->control_sock,
    1.52 +	        transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) {
    1.53 +	
    1.54 +	    g_object_unref (transfer->control_sock);
    1.55 +	    transfer->control_sock = NULL;
    1.56 +	    return FALSE;
    1.57 +	  }
    1.58 +	  
    1.59 +  //}
    1.60      
    1.61    /* Creates the data socket */
    1.62    if (transfer->sock != NULL) {
    1.63      g_object_unref (transfer->sock);
    1.64      transfer->sock = NULL;
    1.65 -  }
    1.66 -
    1.67 -  transfer->sock = gmyth_socket_new ();
    1.68 -  gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port);
    1.69 -  gmyth_debug("Connecting file transfer... (%s, %d)", transfer->backend_info->hostname, transfer->backend_info->port);
    1.70 -
    1.71 -  strlist = gmyth_string_list_new();
    1.72 -  hostname = gmyth_socket_get_local_hostname();
    1.73 -  gmyth_debug( "[%s] MythTV version (from backend) = %d.\n", __FUNCTION__, transfer->control_sock->mythtv_version );
    1.74 -  if ( transfer->control_sock->mythtv_version > 26 )
    1.75 -  	g_string_printf( base_str, "ANN FileTransfer %s 1 -1", hostname->str);
    1.76 -  else
    1.77 -  	g_string_printf( base_str, "ANN FileTransfer %s", hostname->str);
    1.78 -
    1.79 -  gmyth_string_list_append_string (strlist, base_str );
    1.80 -  gmyth_string_list_append_char_array (strlist, transfer->filename);
    1.81 -
    1.82 -  gmyth_socket_write_stringlist (transfer->sock, strlist );
    1.83 -  gmyth_socket_read_stringlist (transfer->sock, strlist );
    1.84 -    
    1.85 -  /* file identification used in future file transfer requests to backend */
    1.86 -  transfer->file_id = gmyth_string_list_get_int( strlist, 1 );
    1.87 -
    1.88 -  /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
    1.89 -  transfer->filesize = gmyth_util_decode_long_long( strlist, 2 );
    1.90 -
    1.91 -  gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__,
    1.92 -          transfer->file_id, transfer->filesize );
    1.93 -
    1.94 -  if (transfer->filesize < 0 ) {
    1.95 -      gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, transfer->filesize );
    1.96 -      g_object_unref (transfer->sock);
    1.97 -      transfer->sock = NULL;
    1.98 -      ret = FALSE;
    1.99 -      goto cleanup;
   1.100 -  }
   1.101 +  }  
   1.102 +  
   1.103 +  //if ( NULL == transfer->sock ) {	
   1.104 +	  transfer->sock = gmyth_socket_new ();
   1.105 +	  gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port);
   1.106 +	  gmyth_debug("Connecting file transfer... (%s, %d)", transfer->backend_info->hostname, transfer->backend_info->port);	  
   1.107 +  //}
   1.108 +  
   1.109 +  if ( transfer->control_sock != NULL )
   1.110 +  {
   1.111 +	
   1.112 +	  strlist = gmyth_string_list_new();
   1.113 +	  hostname = gmyth_socket_get_local_hostname();
   1.114 +	  gmyth_debug( "[%s] MythTV version (from backend) = %d.\n", __FUNCTION__, transfer->control_sock->mythtv_version );
   1.115 +	  if ( transfer->control_sock->mythtv_version > 26 )
   1.116 +	  	g_string_printf( base_str, "ANN FileTransfer %s 1 -1", hostname->str);
   1.117 +	  else
   1.118 +	  	g_string_printf( base_str, "ANN FileTransfer %s", hostname->str);
   1.119 +	
   1.120 +	  gmyth_string_list_append_string (strlist, base_str );
   1.121 +	  gmyth_string_list_append_char_array (strlist, transfer->filename);
   1.122 +	
   1.123 +	  gmyth_socket_write_stringlist (transfer->sock, strlist );
   1.124 +	  gmyth_socket_read_stringlist (transfer->sock, strlist );
   1.125 +	    
   1.126 +	  /* file identification used in future file transfer requests to backend */
   1.127 +	  transfer->file_id = gmyth_string_list_get_int( strlist, 1 );
   1.128 +	
   1.129 +	  /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
   1.130 +	  transfer->filesize = gmyth_util_decode_long_long( strlist, 2 );
   1.131 +	
   1.132 +	  gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__,
   1.133 +	          transfer->file_id, transfer->filesize );
   1.134 +	
   1.135 +	  if (transfer->filesize < 0 ) {
   1.136 +	      gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, transfer->filesize );
   1.137 +	      g_object_unref (transfer->sock);
   1.138 +	      transfer->sock = NULL;
   1.139 +	      ret = FALSE;
   1.140 +	      goto cleanup;
   1.141 +	  }
   1.142 +	  
   1.143 +  } /* if - Control Socket is not equals to NULL? */
   1.144    
   1.145  cleanup:
   1.146  
   1.147    if ( strlist != NULL )
   1.148      g_object_unref( strlist );
   1.149 -
   1.150 -  g_string_free (base_str, TRUE);
   1.151 -  g_string_free (hostname, TRUE);
   1.152 +  
   1.153 +  if ( base_str != NULL )
   1.154 +  	g_string_free (base_str, TRUE);
   1.155 +  	
   1.156 +  if ( hostname != NULL )
   1.157 +  	g_string_free (hostname, TRUE);
   1.158  
   1.159    return ret;
   1.160  }    
   1.161 @@ -633,24 +651,27 @@
   1.162  					transfer->priv->do_next_program_chain )
   1.163  		{
   1.164  		
   1.165 -			total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN;	
   1.166 +			  total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN;	
   1.167  		
   1.168 -	  		g_mutex_lock( transfer->mutex );
   1.169 +	  		//g_mutex_lock( transfer->mutex );
   1.170  	  		
   1.171 -	  		ret = gmyth_livetv_next_program_chain( transfer->priv->livetv );
   1.172 +	  		//ret = gmyth_livetv_next_program_chain( transfer->priv->livetv );
   1.173 +	  		GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info( transfer->priv->livetv->recorder );
   1.174  	  		
   1.175 -	  		if ( transfer->priv->livetv->proginfo != NULL && 
   1.176 -	  						transfer->priv->livetv->proginfo->pathname != NULL &&
   1.177 -	  						g_ascii_strcasecmp( transfer->priv->livetv->proginfo->pathname->str, transfer->filename ) != 0 )	  						
   1.178 -	  			ret = gmyth_file_transfer_open ( transfer, transfer->priv->livetv->proginfo->pathname->str );
   1.179 +	  		if ( prog_info != NULL && prog_info->pathname != NULL && strlen( prog_info->pathname->str ) > 0 &&
   1.180 +	  						g_ascii_strcasecmp( prog_info->pathname->str, transfer->filename ) != 0 )
   1.181 +	  			ret = gmyth_file_transfer_open ( transfer, g_strrstr( prog_info->pathname->str, "/" ) );
   1.182  	  		
   1.183 -	  		g_mutex_unlock( transfer->mutex );
   1.184 +	  		if ( prog_info != NULL )
   1.185 +	  			g_object_unref( prog_info );
   1.186 +	  			
   1.187 +	  		//g_mutex_unlock( transfer->mutex );
   1.188    		
   1.189  			if ( !ret )
   1.190 -				gmyth_debug( "Cannot change to the next program chain!" );
   1.191 +				gmyth_debug( "Cannot change to the next program info!" );
   1.192  			else
   1.193 -				gmyth_debug( "OK!!! MOVED to the next program chain [%s]!", 
   1.194 -										(gmyth_tvchain_get_id( transfer->priv->livetv->tvchain ))->str );						
   1.195 +				gmyth_debug( "OK!!! MOVED to the next program info [%s]!", 
   1.196 +										transfer->filename );						
   1.197  		}
   1.198  
   1.199  	} /* if */
     2.1 --- a/gmyth/src/gmyth_livetv.c	Mon Feb 12 17:56:41 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_livetv.c	Tue Feb 13 22:33:08 2007 +0000
     2.3 @@ -175,9 +175,11 @@
     2.4  				if ( live_tv->file_transfer != NULL )
     2.5  				{
     2.6  					gmyth_debug( "Emitting signal to the FileTransfer... [ \"program-info-changed \" ]" );
     2.7 +					/*
     2.8  					GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( live_tv->recorder );
     2.9  					if ( prog_info != NULL )
    2.10  						live_tv->proginfo = prog_info;
    2.11 +					*/
    2.12  					
    2.13  					gmyth_file_transfer_emit_program_info_changed_signal( live_tv->file_transfer,
    2.14  		             msg_code, (gpointer)live_tv );
    2.15 @@ -198,9 +200,11 @@
    2.16  				if ( live_tv->file_transfer != NULL )
    2.17  				{
    2.18  					gmyth_debug( "Emitting signal to the FileTransfer... [ \"backend-done-recording\" ]" );
    2.19 +					/*
    2.20  					GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( live_tv->recorder );
    2.21  					if ( prog_info != NULL )
    2.22  						live_tv->proginfo = prog_info;
    2.23 +						*/
    2.24  					
    2.25  					gmyth_file_transfer_emit_program_info_changed_signal( live_tv->file_transfer,
    2.26  		             msg_code, (gpointer)live_tv );
    2.27 @@ -292,7 +296,7 @@
    2.28  	
    2.29  	livetv->backend_info = backend_info;
    2.30  		
    2.31 -	//if ( NULL == livetv->socket ) {
    2.32 +	if ( NULL == livetv->socket ) {
    2.33  		livetv->socket = gmyth_socket_new ();
    2.34  		
    2.35  		/* FIME: Implement this at gmyth_socket */
    2.36 @@ -303,7 +307,7 @@
    2.37  			res = FALSE;
    2.38  			goto error;
    2.39  		}
    2.40 -	//}
    2.41 +	}
    2.42  	
    2.43  	g_static_mutex_lock( &lock );
    2.44  	
    2.45 @@ -316,12 +320,23 @@
    2.46  		goto error;
    2.47  	}
    2.48  	
    2.49 +	if  ( livetv->recorder != NULL )
    2.50 +	{
    2.51 +		g_object_unref( livetv->recorder );
    2.52 +		livetv->recorder= NULL;
    2.53 +	} 
    2.54 +	
    2.55  	if ( gmyth_remote_util_get_free_recorder_count (livetv->socket) <= 0 ) {
    2.56 -		gmyth_debug ("No free remote encoder available.");
    2.57 -		res = FALSE;
    2.58 -		goto error;
    2.59 +		gmyth_debug ("No free remote encoder available. Trying to close the actual recording...");
    2.60 +		
    2.61 +		//res = FALSE;
    2.62 +		//goto error;
    2.63 +		if ( livetv->recorder != NULL ) {
    2.64 +			g_object_unref( livetv->recorder );
    2.65 +			livetv->recorder = NULL;
    2.66 +		}			
    2.67  	}
    2.68 -
    2.69 +	
    2.70  	/* Gets the recorder num */
    2.71  	livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1);
    2.72  	gmyth_socket_close_connection (livetv->socket);
    2.73 @@ -490,7 +505,8 @@
    2.74  	g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
    2.75  
    2.76  	if ( livetv->local_hostname != NULL ) {
    2.77 -		g_string_free( livetv->local_hostname, FALSE );
    2.78 +		g_string_free( livetv->local_hostname, TRUE );
    2.79 +		livetv->local_hostname = NULL;
    2.80  		res = FALSE;
    2.81  	}
    2.82  
    2.83 @@ -695,6 +711,10 @@
    2.84  		if ( !gmyth_recorder_stop_livetv (livetv->recorder) ) {
    2.85  			g_warning ("[%s] Error while stoping remote encoder", __FUNCTION__);	
    2.86  		}
    2.87 +		
    2.88 +		if ( !gmyth_recorder_finish_recording(livetv->recorder) ) {
    2.89 +			g_warning ("[%s] Error while finishing recording on remote encoder", __FUNCTION__);	
    2.90 +		}
    2.91  	}
    2.92  }
    2.93  
     3.1 --- a/gmyth/src/gmyth_programinfo.c	Mon Feb 12 17:56:41 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_programinfo.c	Tue Feb 13 22:33:08 2007 +0000
     3.3 @@ -47,6 +47,8 @@
     3.4  
     3.5  G_DEFINE_TYPE(GMythProgramInfo, gmyth_program_info, G_TYPE_OBJECT)
     3.6      
     3.7 +static const gchar* gmyth_program_info_non_null_value( const GString *str );
     3.8 +
     3.9  static void
    3.10  gmyth_program_info_class_init (GMythProgramInfoClass *klass)
    3.11  {
    3.12 @@ -309,25 +311,25 @@
    3.13      gmyth_string_list_append_string (slist, prog->chansign); /* 6 */
    3.14      gmyth_string_list_append_string (slist, prog->channame); /* 7 */
    3.15      gmyth_string_list_append_string (slist, prog->pathname); /* 8 */
    3.16 -    gmyth_string_list_append_int (slist, 0); /* 9 */
    3.17 +    gmyth_string_list_append_int64 (slist, 0); /* 9 */
    3.18  
    3.19      // fixme
    3.20      //gmyth_string_list_append_int64 (slist, 100/*prog->filesize*/); /* 9 */
    3.21      //gmyth_string_list_append_int (slist, 0); /* 10 */
    3.22  
    3.23      if (prog->startts)
    3.24 -        gmyth_string_list_append_int64 (slist, prog->startts->tv_sec);  /* 10 */ //DATETIME_TO_LIST(startts)
    3.25 +        gmyth_string_list_append_int (slist, prog->startts->tv_sec);  /* 11 */ //DATETIME_TO_LIST(startts)
    3.26      else
    3.27 -	gmyth_string_list_append_int64 (slist, 0);
    3.28 +	gmyth_string_list_append_int (slist, 0);
    3.29      
    3.30      if (prog->endts)
    3.31 -        gmyth_string_list_append_int64 (slist, prog->endts->tv_sec);  /* 12 */ //DATETIME_TO_LIST(endts)
    3.32 +        gmyth_string_list_append_int (slist, prog->endts->tv_sec);  /* 12 */ //DATETIME_TO_LIST(endts)
    3.33      else
    3.34 -	gmyth_string_list_append_int64 (slist, 0);
    3.35 +	gmyth_string_list_append_int (slist, 0);
    3.36  
    3.37 -    gmyth_string_list_append_int (slist, prog->duplicate); /* 14 */
    3.38 -    gmyth_string_list_append_int (slist, prog->shareable); /* 15 */
    3.39 -    gmyth_string_list_append_int (slist, prog->findid); /* 16 */
    3.40 +    gmyth_string_list_append_int (slist, prog->duplicate); /* 13 */
    3.41 +    gmyth_string_list_append_int (slist, prog->shareable); /* 14 */
    3.42 +    gmyth_string_list_append_int (slist, prog->findid); /* 15 */
    3.43      gmyth_string_list_append_string (slist, prog->hostname); /* 16 */
    3.44      gmyth_string_list_append_int (slist, prog->sourceid); /* 17 */
    3.45      gmyth_string_list_append_int (slist, prog->cardid); /* 18 */
    3.46 @@ -338,8 +340,8 @@
    3.47      gmyth_string_list_append_int (slist, 0 /*prog->rectype*/); /* 23 */
    3.48      gmyth_string_list_append_int (slist, 0 /*prog->dupin*/); /* 24 */
    3.49      gmyth_string_list_append_int (slist, 0 /*prog->dupmethod*/); /* 25 */
    3.50 -    gmyth_string_list_append_int64 (slist, prog->recstartts != NULL ? prog->recstartts->tv_sec : 0);  /* 26 */ //DATETIME_TO_LIST(recstartts)
    3.51 -    gmyth_string_list_append_int64 (slist, prog->recendts != NULL ? prog->recendts->tv_sec : 0);  /* 27 */ //DATETIME_TO_LIST(recendts)
    3.52 +    gmyth_string_list_append_int (slist, prog->recstartts != NULL ? prog->recstartts->tv_sec : 0);  /* 26 */ //DATETIME_TO_LIST(recstartts)
    3.53 +    gmyth_string_list_append_int (slist, prog->recendts != NULL ? prog->recendts->tv_sec : 0);  /* 27 */ //DATETIME_TO_LIST(recendts)
    3.54      gmyth_string_list_append_int (slist, prog->repeat); /* 28 */
    3.55      gmyth_string_list_append_int (slist, prog->programflags); /* 29 */
    3.56      gmyth_string_list_append_char_array (slist, "Default"); /* 30 */ //prog->(recgroup != "") ? recgroup : "Default")
    3.57 @@ -348,9 +350,9 @@
    3.58      gmyth_string_list_append_string (slist, prog->seriesid); /* 33 */
    3.59      gmyth_string_list_append_string (slist, prog->programid); /* 34 */
    3.60      gmyth_string_list_append_char_array (slist, ""); /* 35 */
    3.61 -    gmyth_string_list_append_int64 (slist, prog->lastmodified != NULL ? prog->lastmodified->tv_sec : 0);  /* 36 */ //DATETIME_TO_LIST(lastmodified)
    3.62 +    gmyth_string_list_append_int (slist, prog->lastmodified != NULL ? prog->lastmodified->tv_sec : 0);  /* 36 */ //DATETIME_TO_LIST(lastmodified)
    3.63      gmyth_string_list_append_int (slist, 0);  /* 37 */ //FLOAT_TO_LIST(stars)
    3.64 -    gmyth_string_list_append_int64 (slist, prog->originalAirDate != NULL ? prog->originalAirDate->tv_sec : 0);  /* 38 */ //DATETIME_TO_LIST(QDateTime(originalAirDate))
    3.65 +    gmyth_string_list_append_int (slist, prog->originalAirDate != NULL ? prog->originalAirDate->tv_sec : 0);  /* 38 */ //DATETIME_TO_LIST(QDateTime(originalAirDate))
    3.66      gmyth_string_list_append_int (slist, prog->hasAirDate); /* 39 */
    3.67      gmyth_string_list_append_char_array (slist, "Default");  /* 40 */ //prog->(playgroup != "") ? playgroup : "Default")
    3.68      gmyth_string_list_append_int (slist, prog->recpriority2); /* 41 */
    3.69 @@ -416,11 +418,23 @@
    3.70      prog->channame = gmyth_string_list_get_string (slist, 5);
    3.71      prog->chanstr = gmyth_string_list_get_string (slist, 6);    
    3.72      prog->chansign = gmyth_string_list_get_string (slist, 7);    
    3.73 -    prog->pathname = gmyth_string_list_get_string (slist, 8);    
    3.74 +    prog->pathname = gmyth_string_list_get_string (slist, 8);
    3.75 +    
    3.76 +    prog->filesize = gmyth_string_list_get_int64 (slist, 9);
    3.77 +    
    3.78 +    gmyth_debug( "Prog info: [ %s, %s, %s, %s, %s, %s, %s, %s, %s, %d ]\n", 
    3.79 +    			gmyth_program_info_non_null_value( prog->title ), 
    3.80 +    			gmyth_program_info_non_null_value( prog->subtitle ), 
    3.81 +    			gmyth_program_info_non_null_value( prog->description ), 
    3.82 +    			gmyth_program_info_non_null_value( prog->category ), 
    3.83 +    			gmyth_program_info_non_null_value( prog->chanid ), 
    3.84 +    			gmyth_program_info_non_null_value( prog->channame ), 
    3.85 +    			gmyth_program_info_non_null_value( prog->chanstr ), 
    3.86 +    			gmyth_program_info_non_null_value( prog->chansign ), 
    3.87 +    			gmyth_program_info_non_null_value( prog->pathname ), 
    3.88 +    			gmyth_string_list_get_int (slist, 11) );    
    3.89      //gmyth_string_list_get_int (slist, 9);
    3.90      
    3.91 -    prog->filesize = gmyth_string_list_get_int64 (slist, 9);
    3.92 -
    3.93      prog->startts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
    3.94      					(time_t)gmyth_string_list_get_int (slist, 11) ))->str ); //DATETIME_TO_LIST(startts)
    3.95      prog->endts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
    3.96 @@ -457,7 +471,61 @@
    3.97      					(time_t)gmyth_string_list_get_int (slist, 38) ))->str ); //DATETIME_TO_LIST(QDateTime(originalAirDate))
    3.98      prog->hasAirDate = gmyth_string_list_get_int (slist, 39);
    3.99      prog->playgroup = gmyth_string_list_get_string (slist, 40); //prog->(playgroup != "") ? playgroup : "Default")
   3.100 -    //prog->recpriority2 = gmyth_string_list_get_int (slist, 41);
   3.101 +    prog->recpriority2 = gmyth_string_list_get_int (slist, 41);
   3.102     
   3.103      return prog;
   3.104  }
   3.105 +
   3.106 +static const gchar*
   3.107 +gmyth_program_info_non_null_value( const GString *str )
   3.108 +{
   3.109 +	return ( str != NULL && str->str != NULL && strlen( str->str ) > 0 ? str->str : " " );
   3.110 +}
   3.111 +
   3.112 +const gchar*
   3.113 +gmyth_program_info_to_string( const GMythProgramInfo* prog )
   3.114 +{
   3.115 +	 return g_strdup_printf( "Title: %s, Subtitle: %s, Description: %s, Category: %s, Channel ID: %s, "\
   3.116 +	 		"Channel Name: %s, Chan str: %s, Channel Sign: %s, Path Name: %s, File Size: %lld, \n"\
   3.117 +	 		"Start TS: %s, End TS: %s, Duplicate: %d, Shareable: %d, Find ID: %d, Hostname: %s, "\
   3.118 +	 		"Source ID: %d, Vard ID: %d, Input ID: %d, Rec Priority: %d, Reactivate: %d, \n"\
   3.119 +	 		"Record ID: %d, Rec Start TS: %s, Rec End TS: %s, Repeat: %d, Program Flags: %d, "\
   3.120 +	 		"Rec Group: %s, Channel Comm Free: %d, Channel Output Filters: %s, Series ID: %s, \n"\
   3.121 +	 		"Program ID: %s, Last Modified Date: %s, Original Air Date: %s, Has Air Date: %d, "
   3.122 +	 		"Play Group: %s.\n", 
   3.123 +	 	gmyth_program_info_non_null_value( prog->title ), 
   3.124 +    gmyth_program_info_non_null_value( prog->subtitle ),    
   3.125 +    gmyth_program_info_non_null_value( prog->description ),
   3.126 +    gmyth_program_info_non_null_value( prog->category ),
   3.127 +		gmyth_program_info_non_null_value( prog->chanid ),
   3.128 +    gmyth_program_info_non_null_value( prog->channame ),
   3.129 +    gmyth_program_info_non_null_value( prog->chanstr ),    
   3.130 +    gmyth_program_info_non_null_value( prog->chansign ),    
   3.131 +    gmyth_program_info_non_null_value( prog->pathname ),
   3.132 +    prog->filesize,
   3.133 +    gmyth_util_time_to_string_from_time_val( prog->startts), 
   3.134 +    gmyth_util_time_to_string_from_time_val( prog->endts), 
   3.135 +    prog->duplicate,
   3.136 +    prog->shareable,
   3.137 +    prog->findid,
   3.138 +    gmyth_program_info_non_null_value( prog->hostname ),
   3.139 +    prog->sourceid,
   3.140 +    prog->cardid,
   3.141 +    prog->inputid,
   3.142 +    prog->recpriority,
   3.143 +    prog->reactivate,
   3.144 +    prog->recordid,
   3.145 +    gmyth_util_time_to_string_from_time_val(prog->recstartts),
   3.146 +    gmyth_util_time_to_string_from_time_val(prog->recendts),
   3.147 +    prog->repeat,
   3.148 +    prog->programflags,
   3.149 +    gmyth_program_info_non_null_value( prog->recgroup ),
   3.150 +    prog->chancommfree,
   3.151 +    gmyth_program_info_non_null_value( prog->chanOutputFilters ),
   3.152 +    gmyth_program_info_non_null_value( prog->seriesid ),
   3.153 +    gmyth_program_info_non_null_value( prog->programid ),
   3.154 +    gmyth_util_time_to_string_from_time_val(prog->lastmodified),
   3.155 +    gmyth_util_time_to_string_from_time_val(prog->originalAirDate),
   3.156 +    prog->hasAirDate,
   3.157 +    gmyth_program_info_non_null_value(prog->playgroup) );
   3.158 +}
     4.1 --- a/gmyth/src/gmyth_programinfo.h	Mon Feb 12 17:56:41 2007 +0000
     4.2 +++ b/gmyth/src/gmyth_programinfo.h	Tue Feb 13 22:33:08 2007 +0000
     4.3 @@ -156,6 +156,8 @@
     4.4  GMythStringList* 		gmyth_program_info_to_string_list (GMythProgramInfo *prog, GMythStringList *slist);
     4.5  GMythProgramInfo* 	gmyth_program_info_from_string_list (GMythStringList *slist);
     4.6  
     4.7 +const gchar*				gmyth_program_info_to_string( const GMythProgramInfo* prog );
     4.8 +
     4.9  G_END_DECLS
    4.10  
    4.11  #endif /*_GMYTH_PROGRAMINFO_H*/
     5.1 --- a/gmyth/src/gmyth_recorder.c	Mon Feb 12 17:56:41 2007 +0000
     5.2 +++ b/gmyth/src/gmyth_recorder.c	Tue Feb 13 22:33:08 2007 +0000
     5.3 @@ -70,7 +70,7 @@
     5.4  {
     5.5    GMythRecorder *recorder = GMYTH_RECORDER(object);
     5.6    
     5.7 -  //gmyth_recorder_close(recorder);
     5.8 +  gmyth_recorder_close(recorder);
     5.9    
    5.10  	if ( recorder->myth_socket != NULL ) {
    5.11  		g_object_unref (recorder->myth_socket);
    5.12 @@ -92,8 +92,7 @@
    5.13  void
    5.14  gmyth_recorder_close  (GMythRecorder *recorder)
    5.15  {
    5.16 -	if (recorder->myth_socket != NULL)
    5.17 -  	gmyth_socket_close_connection(recorder->myth_socket);
    5.18 +  gmyth_recorder_finish_recording( recorder );
    5.19  }
    5.20  
    5.21  /** Creates a new instance of GMythRecorder.
    5.22 @@ -731,9 +730,8 @@
    5.23  	          program_info->programid = gmyth_string_list_get_string (str_list, 13);
    5.24  	  }
    5.25  	  
    5.26 -	  if ( ( program_info->chanid != NULL && strlen( program_info->chanid->str ) > 0  ) &&
    5.27 -	  	( program_info->channame != NULL && strlen( program_info->channame->str ) > 0 ) &&
    5.28 -	  	( program_info->title != NULL && strlen( program_info->title->str ) > 0 ) ) 
    5.29 +	  if ( /*( program_info->chanid != NULL && strlen( program_info->chanid->str ) > 0  ) &&*/
    5.30 +	  	( program_info->pathname != NULL && strlen( program_info->pathname->str ) > 0 ) ) 
    5.31  	  {
    5.32  	  		gmyth_debug( "OK!!! Got the next program info..." );
    5.33  	  } else {
    5.34 @@ -825,3 +823,41 @@
    5.35    return ret;
    5.36  
    5.37  }
    5.38 +
    5.39 +gboolean
    5.40 +gmyth_recorder_finish_recording ( GMythRecorder *recorder )
    5.41 +{
    5.42 +  gboolean ret = TRUE;
    5.43 +  
    5.44 +  g_return_val_if_fail( recorder != NULL, FALSE );
    5.45 +
    5.46 +  GMythStringList *str_list = gmyth_string_list_new ();
    5.47 +  GString *message = g_string_new ("");
    5.48 +
    5.49 +  g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER, recorder->recorder_num);
    5.50 +  gmyth_string_list_append_string (str_list, message);
    5.51 +  gmyth_string_list_append_string (str_list, g_string_new ("FINISH_RECORDING"));
    5.52 +
    5.53 +  gmyth_socket_sendreceive_stringlist ( recorder->myth_socket, str_list );
    5.54 +
    5.55 +  if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 )
    5.56 +  {
    5.57 +    GString *str = NULL;
    5.58 +    if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp( str->str, "ok" )!= 0 ) 
    5.59 +    {
    5.60 +      gint is_rec = gmyth_string_list_get_int( str_list, 0 );
    5.61 +      if ( is_rec != 0 )
    5.62 +        ret = TRUE;
    5.63 +      else
    5.64 +        ret = FALSE;
    5.65 +    }
    5.66 +  }
    5.67 +  gmyth_debug( "%s, stream is %s being recorded!\n", ret ? "YES" : "NO", ret ? "" : "NOT" );
    5.68 +  //g_static_mutex_unlock (&mutex);
    5.69 +
    5.70 +  if ( str_list != NULL )
    5.71 +    g_object_unref (str_list);
    5.72 +
    5.73 +  return ret;
    5.74 +
    5.75 +}
     6.1 --- a/gmyth/src/gmyth_recorder.h	Mon Feb 12 17:56:41 2007 +0000
     6.2 +++ b/gmyth/src/gmyth_recorder.h	Tue Feb 13 22:33:08 2007 +0000
     6.3 @@ -133,6 +133,8 @@
     6.4  
     6.5  gboolean gmyth_recorder_is_recording ( GMythRecorder *recorder );
     6.6  
     6.7 +gboolean 	gmyth_recorder_finish_recording ( GMythRecorder *recorder );
     6.8 +
     6.9  G_END_DECLS
    6.10  
    6.11  #endif /* __GMYTH_REMOTE_ENCODER_H__ */
     7.1 --- a/gmyth/src/gmyth_socket.c	Mon Feb 12 17:56:41 2007 +0000
     7.2 +++ b/gmyth/src/gmyth_socket.c	Tue Feb 13 22:33:08 2007 +0000
     7.3 @@ -69,7 +69,7 @@
     7.4  // FIXME: put this in the right place
     7.5  #define  MYTHTV_VERSION_DEFAULT			31
     7.6  
     7.7 -static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
     7.8 +/* static GStaticMutex mutex = G_STATIC_MUTEX_INIT; */
     7.9  
    7.10  /*static GStaticRWLock rwlock = G_STATIC_RW_LOCK_INIT;*/
    7.11  
    7.12 @@ -282,7 +282,7 @@
    7.13      	return str;
    7.14      }
    7.15      
    7.16 -    g_static_mutex_lock( &mutex );    	
    7.17 +    g_mutex_lock( gmyth_socket->mutex );    	
    7.18  
    7.19      addr_info0 = addr_info_data;
    7.20  
    7.21 @@ -323,7 +323,7 @@
    7.22      	}
    7.23      }
    7.24  
    7.25 -    g_static_mutex_unlock (&mutex);
    7.26 +    g_mutex_unlock (gmyth_socket->mutex);
    7.27      
    7.28      if ( str != NULL && str->str != NULL )
    7.29      	local_hostname = g_strdup( str->str );
    7.30 @@ -340,14 +340,18 @@
    7.31      /* disconnect socket */
    7.32      gmyth_socket_close_connection (gmyth_socket);
    7.33      
    7.34 -    /*
    7.35      g_free (gmyth_socket->hostname);
    7.36      gmyth_socket->hostname = NULL;
    7.37 -    */
    7.38      
    7.39      g_free (local_hostname);
    7.40      
    7.41      local_hostname = NULL;
    7.42 +    
    7.43 +    if ( gmyth_socket->mutex != NULL )
    7.44 +    {
    7.45 +    	g_mutex_free( gmyth_socket->mutex );
    7.46 +    	gmyth_socket->mutex = NULL; 
    7.47 +    }
    7.48  
    7.49      G_OBJECT_CLASS (gmyth_socket_parent_class)->dispose (object);
    7.50  }
    7.51 @@ -370,6 +374,8 @@
    7.52      GMythSocket *gmyth_socket = GMYTH_SOCKET (g_object_new(GMYTH_SOCKET_TYPE, NULL));
    7.53  
    7.54      gmyth_socket->mythtv_version = MYTHTV_VERSION_DEFAULT;
    7.55 +    
    7.56 +    gmyth_socket->mutex = g_mutex_new();
    7.57  
    7.58      return gmyth_socket;
    7.59  }
    7.60 @@ -663,7 +669,7 @@
    7.61  		goto done;
    7.62      }
    7.63  
    7.64 -    g_static_mutex_lock( &mutex );
    7.65 +    g_mutex_lock( gmyth_socket->mutex );
    7.66      gmyth_debug ("Sending command to backend: %s\n", command->str);
    7.67  
    7.68      buffer = g_strnfill( BUFLEN, ' ' );
    7.69 @@ -693,7 +699,7 @@
    7.70  		ret = TRUE;
    7.71      }
    7.72  
    7.73 -    g_static_mutex_unlock( &mutex );
    7.74 +    g_mutex_unlock( gmyth_socket->mutex );
    7.75  done:
    7.76      if ( error != NULL ) {
    7.77  		g_printerr( "[%s] Error found reading data from IO channel: (%d, %s)\n", __FUNCTION__, error->code, error->message );
    7.78 @@ -949,11 +955,11 @@
    7.79  
    7.80      /* verify if the input (read) buffer is ready to receive data */
    7.81  
    7.82 -    //g_static_mutex_lock( &mutex );
    7.83 +    g_mutex_lock( gmyth_socket->mutex );
    7.84      //g_static_rw_lock_reader_lock (&rwlock);
    7.85      
    7.86 -    buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE);
    7.87 -    //buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' ');
    7.88 +    //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE);
    7.89 +    buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' ');
    7.90   		if ( NULL == gmyth_socket->sd_io_ch )
    7.91   		{
    7.92   			gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port );
    7.93 @@ -981,7 +987,7 @@
    7.94  		g_debug ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__);
    7.95  		str = NULL;
    7.96  		//return NULL;
    7.97 -    } else {
    7.98 +    } else if ( buffer != NULL && strlen(buffer) > 0 ) {
    7.99  
   7.100  		//io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error );
   7.101  		/* verify if the input (read) buffer is ready to receive data */
   7.102 @@ -1020,7 +1026,7 @@
   7.103  			//}
   7.104      }
   7.105  
   7.106 -    //g_static_mutex_unlock( &mutex );
   7.107 +    g_mutex_unlock( gmyth_socket->mutex );
   7.108      //g_static_rw_lock_reader_unlock (&rwlock);
   7.109  
   7.110      gmyth_debug ("Response received from backend: {%s}\n", buffer);
   7.111 @@ -1054,7 +1060,7 @@
   7.112      GPtrArray *ptr_array = NULL;
   7.113      gchar *str_array = NULL;
   7.114  
   7.115 -    g_static_mutex_lock( &mutex );
   7.116 +    g_mutex_lock( gmyth_socket->mutex );
   7.117      //g_static_rw_lock_writer_lock (&rwlock);
   7.118  
   7.119      ptr_array = g_ptr_array_sized_new (g_list_length(str_list->glist));
   7.120 @@ -1072,7 +1078,7 @@
   7.121  
   7.122      str_array = g_strjoinv (MYTH_SEPARATOR, (gchar **) (ptr_array->pdata));
   7.123  
   7.124 -    g_static_mutex_unlock( &mutex );
   7.125 +    g_mutex_unlock( gmyth_socket->mutex );
   7.126      //g_static_rw_lock_writer_unlock (&rwlock);
   7.127  
   7.128      gmyth_debug ( "[%s] Sending socket request: %s\n", __FUNCTION__, str_array );
   7.129 @@ -1106,15 +1112,17 @@
   7.130      if ( response != NULL && response->str != NULL && response->len > 0 )
   7.131      {
   7.132      	  
   7.133 -	    g_static_mutex_lock( &mutex );    
   7.134 +	    g_mutex_lock( gmyth_socket->mutex );    
   7.135  	
   7.136  	    gmyth_string_list_clear_all (str_list);	
   7.137  	    str_array = g_strsplit (response->str, MYTH_SEPARATOR, -1);
   7.138  	
   7.139 -	    for (i=0; i< g_strv_length (str_array); i++) {
   7.140 -		gmyth_string_list_append_char_array (str_list, str_array[i] );
   7.141 +	    for ( i=0; i< g_strv_length (str_array); i++ ) {
   7.142 +	    	//if ( str_array[i] != NULL && strlen( str_array[i] ) > 0 )
   7.143 +				gmyth_string_list_append_char_array ( str_list, str_array[i] );
   7.144  	    }
   7.145 -	    g_static_mutex_unlock( &mutex );
   7.146 +	    
   7.147 +	    g_mutex_unlock( gmyth_socket->mutex );
   7.148  	    
   7.149      }
   7.150  
     8.1 --- a/gmyth/src/gmyth_socket.h	Mon Feb 12 17:56:41 2007 +0000
     8.2 +++ b/gmyth/src/gmyth_socket.h	Tue Feb 13 22:33:08 2007 +0000
     8.3 @@ -66,15 +66,17 @@
     8.4  
     8.5  struct _GMythSocket
     8.6  {
     8.7 -	GObject parent;
     8.8 +	GObject 		parent;
     8.9 +	
    8.10 +	GMutex 			*mutex;
    8.11  
    8.12  	/* socket descriptor */
    8.13 -	gint sd;
    8.14 -	GIOChannel *sd_io_ch;
    8.15 +	gint 				sd;
    8.16 +	GIOChannel 	*sd_io_ch;
    8.17  
    8.18 -	gchar *hostname;
    8.19 -	gint port;
    8.20 -	gint mythtv_version;
    8.21 +	gchar 			*hostname;
    8.22 +	gint 				port;
    8.23 +	gint 				mythtv_version;
    8.24  };
    8.25  
    8.26  /* used when no protocol version number was negotiated */
     9.1 --- a/gmyth/src/gmyth_stringlist.c	Mon Feb 12 17:56:41 2007 +0000
     9.2 +++ b/gmyth/src/gmyth_stringlist.c	Tue Feb 13 22:33:08 2007 +0000
     9.3 @@ -91,7 +91,7 @@
     9.4  gmyth_string_list_new ()
     9.5  {
     9.6      GMythStringList *gmyth_string_list = GMYTH_STRING_LIST (g_object_new (GMYTH_STRING_LIST_TYPE, NULL));
     9.7 -    
     9.8 +
     9.9      return gmyth_string_list;
    9.10  }
    9.11  
    9.12 @@ -202,7 +202,8 @@
    9.13  	
    9.14  	tmp_str = g_string_new (value);
    9.15  
    9.16 -	g_return_val_if_fail( tmp_str != NULL, NULL );
    9.17 +	if ( NULL == tmp_str )
    9.18 +		return NULL;		
    9.19  
    9.20  	gmyth_string_list_append_string (strlist, tmp_str);
    9.21  
    9.22 @@ -242,7 +243,8 @@
    9.23  
    9.24  	tmp_str = (GString *) g_list_nth_data (strlist->glist, index);
    9.25  
    9.26 -	g_return_val_if_fail( tmp_str != NULL && tmp_str->str != NULL, 0 );
    9.27 +	if ( NULL == tmp_str || NULL == tmp_str->str || strlen( tmp_str->str ) <= 0 )
    9.28 +		return 0;
    9.29  	
    9.30  	return (gint) ( /* 0x00000000ffffffffL &  (gint64)*/g_ascii_strtoull ( tmp_str->str, NULL, 10 ) );
    9.31  }
    10.1 --- a/gmyth/src/gmyth_uri.c	Mon Feb 12 17:56:41 2007 +0000
    10.2 +++ b/gmyth/src/gmyth_uri.c	Tue Feb 13 22:33:08 2007 +0000
    10.3 @@ -374,7 +374,7 @@
    10.4  		
    10.5  		/* gmyth_debug( "Channel tuple is [ %s, %s ]", chan_key_value[0], chan_key_value[1] ); */
    10.6  
    10.7 -		if ( chan_key_value[1] != NULL )
    10.8 +		if ( chan_key_value[1] != NULL && strlen( chan_key_value[1] ) > 0 )
    10.9  		{
   10.10  			channel = g_strdup( chan_key_value[1] ); 
   10.11  		}