[svn r199] Fixed problem with COxa. trunk
authorrosfran
Tue Dec 05 21:57:35 2006 +0000 (2006-12-05)
branchtrunk
changeset 198109630cf20ef
parent 197 c57ba96bda15
child 199 4bed4ce6b681
[svn r199] Fixed problem with COxa.
gmyth/src/gmyth_monitor_handler.c
     1.1 --- a/gmyth/src/gmyth_monitor_handler.c	Tue Dec 05 21:56:57 2006 +0000
     1.2 +++ b/gmyth/src/gmyth_monitor_handler.c	Tue Dec 05 21:57:35 2006 +0000
     1.3 @@ -72,7 +72,7 @@
     1.4  
     1.5  GMainContext *io_watcher_context = NULL;
     1.6  
     1.7 -GThread *monitor_th = NULL;
     1.8 +GThreadPool *monitor_th = NULL;
     1.9  
    1.10  enum myth_sock_types {
    1.11    GMYTH_PLAYBACK_TYPE = 0,
    1.12 @@ -82,8 +82,10 @@
    1.13  };
    1.14  
    1.15  //static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
    1.16 -static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, 
    1.17 -				gpointer data );
    1.18 +//static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, 
    1.19 +//				gpointer data );
    1.20 +
    1.21 +static void myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret );
    1.22  
    1.23  static GMutex*				mutex 					 = NULL;
    1.24  
    1.25 @@ -169,8 +171,8 @@
    1.26    
    1.27    if ( monitor_th != NULL )  
    1.28    {
    1.29 -  	g_thread_join( monitor_th );
    1.30 -  	g_object_unref( monitor_th );
    1.31 +  	g_thread_pool_free( monitor_th, TRUE, FALSE );
    1.32 +  	//g_object_unref( monitor_th );
    1.33    	monitor_th = NULL;
    1.34    }
    1.35  
    1.36 @@ -224,37 +226,42 @@
    1.37  
    1.38  }
    1.39  
    1.40 -static gboolean
    1.41 -myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
    1.42 -//myth_control_sock_listener( GIOChannel *io_channel )
    1.43 +static void
    1.44 +//myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
    1.45 +myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret )
    1.46  {
    1.47  
    1.48    GIOStatus io_status;
    1.49    GError *error = NULL;
    1.50    GIOCondition io_cond;
    1.51 -  //GIOCondition condition;
    1.52 +  GIOCondition condition;
    1.53    gchar *trash = NULL;
    1.54    GByteArray *byte_array = NULL;
    1.55    guint recv = 0;
    1.56 -  //gboolean* ret = g_new0( gboolean, 1 );
    1.57 -  gboolean ret = TRUE;
    1.58 +  ret = g_new0( gboolean, 1 );
    1.59 +  *ret = TRUE;
    1.60 +  //gboolean ret = TRUE;
    1.61    gsize len = 0;
    1.62    
    1.63 +  static guint count = 0;  
    1.64 +  
    1.65 +  
    1.66    //GMythMonitorHandler *monitor = (GMythMonitorHandler*)data;
    1.67    
    1.68    //myth_control_acquire_context (TRUE);
    1.69    
    1.70    if ( io_channel == NULL ) {
    1.71    	g_debug ("Monitor socket is NULL!\n");
    1.72 -  	ret = FALSE;
    1.73 +  	*ret = FALSE;
    1.74    	goto clean_up;
    1.75    }
    1.76 -  gmyth_debug ("Listening on Monitor socket...!\n");
    1.77 -  
    1.78 -  //while (TRUE) {
    1.79 +    
    1.80 +  while (TRUE) {
    1.81 +  	++count;
    1.82 +  	
    1.83 +  	gmyth_debug ("%d - Listening on Monitor socket...!\n", count);
    1.84  	  	
    1.85 -	  //condition = g_io_channel_get_buffer_condition( io_channel );
    1.86 -	  
    1.87 +	  condition = g_io_channel_get_buffer_condition( io_channel );	  
    1.88  	  //while ( !has_io_access ) 
    1.89  	  //	g_cond_wait( io_watcher_cond, mutex );
    1.90  	  	
    1.91 @@ -266,7 +273,7 @@
    1.92  	    //goto clean_up;
    1.93  	  }
    1.94  	    
    1.95 -	  if ( ( condition & G_IO_IN ) != 0 ) {
    1.96 +	  //if ( ( condition & G_IO_IN ) != 0 ) {
    1.97  	  	byte_array = g_byte_array_new();
    1.98  	  	io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
    1.99  	  	guint buffer_size = GMYTHTV_BUFFER_SIZE;
   1.100 @@ -290,8 +297,10 @@
   1.101  	      io_cond = g_io_channel_get_buffer_condition( io_channel );
   1.102  	
   1.103  	    } while ( ( io_cond & G_IO_IN ) != 0 );
   1.104 +	    
   1.105  	    gmyth_debug ("\n\n\n[%s]\tEVENT: Read %d bytes: %s\n\n\n", __FUNCTION__, recv, byte_array != NULL && byte_array->data != NULL ? (gchar*)byte_array->data : "[no event data]" );
   1.106 -	  }	  
   1.107 +	    
   1.108 +	  //}	  
   1.109  	  
   1.110  	  if ( byte_array != NULL ) {
   1.111  	  	g_byte_array_free( byte_array, TRUE );
   1.112 @@ -300,10 +309,11 @@
   1.113  	  
   1.114  	  g_usleep( 300 );
   1.115  	  
   1.116 -  //}
   1.117 -  if ( io_status == G_IO_STATUS_ERROR ) {
   1.118 +  }
   1.119 +  
   1.120 +  if ( io_status == G_IO_STATUS_ERROR || error != NULL ) {
   1.121      gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" );
   1.122 -   	ret = FALSE;
   1.123 +   	*ret = FALSE;
   1.124     	goto clean_up;   	
   1.125    }
   1.126    
   1.127 @@ -313,8 +323,13 @@
   1.128    //monitor->actual_index += recv;
   1.129  
   1.130  clean_up:
   1.131 +
   1.132 +  if ( byte_array != NULL ) {
   1.133 +  	g_byte_array_free( byte_array, TRUE );
   1.134 +  	byte_array = NULL;
   1.135 +  }
   1.136    
   1.137 -  return ret;
   1.138 +  //return ret;
   1.139  
   1.140  }
   1.141  
   1.142 @@ -347,16 +362,19 @@
   1.143  myth_control_sock_setup( GIOChannel *channel )
   1.144  {
   1.145  	gboolean *ret = g_new0( gboolean, 1 );
   1.146 +	//guint src_id = 0;
   1.147  	
   1.148  	*ret = TRUE;
   1.149  	
   1.150    io_watcher_context = g_main_context_default();
   1.151 -  //GMainLoop *loop = g_main_loop_new( io_watcher_context, TRUE );
   1.152 +  GMainLoop *loop = g_main_loop_new( io_watcher_context, TRUE );
   1.153  
   1.154    GSource *source;
   1.155  
   1.156    if ( channel != NULL ) {
   1.157      source = g_io_create_watch( channel, G_IO_IN | G_IO_HUP );
   1.158 +    //src_id = g_io_add_watch( channel, G_IO_IN | G_IO_HUP, 
   1.159 +    //					(GSourceFunc)myth_control_sock_listener, NULL );
   1.160    } else {
   1.161    	*ret = FALSE;
   1.162    	goto cleanup;
   1.163 @@ -366,18 +384,24 @@
   1.164  
   1.165    g_source_attach( source, io_watcher_context );
   1.166    
   1.167 -  if (source==NULL) {
   1.168 +  if (NULL == source){
   1.169      gmyth_debug( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
   1.170      *ret = FALSE;
   1.171      goto cleanup;
   1.172    }
   1.173    
   1.174 -  //g_main_loop_run( loop );
   1.175 +  g_main_loop_run( loop );
   1.176    
   1.177  cleanup:
   1.178 -  //if ( source != NULL )
   1.179 -  //  g_source_unref( source );
   1.180 -  
   1.181 +  if ( source != NULL )
   1.182 +    g_source_unref( source );
   1.183 +    
   1.184 +  //if ( io_watcher_context != NULL )
   1.185 +  //  g_main_context_unref( io_watcher_context );
   1.186 +
   1.187 +  //if ( loop != NULL )
   1.188 +  //  g_main_loop_unref( loop );
   1.189 +    
   1.190    return ret;
   1.191    
   1.192  }
   1.193 @@ -388,28 +412,29 @@
   1.194  	gboolean *ret = g_new0( gboolean, 1 ); 
   1.195  	*ret = TRUE;	
   1.196  	
   1.197 -	if (!g_thread_supported ()) g_thread_init (NULL);
   1.198 +	if (!g_thread_supported () ) 	g_thread_init (NULL);
   1.199  	
   1.200 -  monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_setup, 
   1.201 -  					monitor->event_sock->sd_io_ch, TRUE, NULL );
   1.202 +  monitor_th = g_thread_pool_new( (GFunc)myth_control_sock_listener, 
   1.203 +  					monitor->event_sock->sd_io_ch, 3, FALSE, NULL );
   1.204    					
   1.205 -  if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
   1.206 +  //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
   1.207 +  if ( monitor_th != NULL )
   1.208    {
   1.209 -  	gmyth_debug ( "\n[%s]\tERROR! Coudn't start listener on the MONITOR event socket...[thread location = %p]\n", 
   1.210 -  				__FUNCTION__, g_thread_self( ) );  	  	
   1.211 -  } else {
   1.212    	gmyth_debug ( "\n[%s]\tOK! Starting listener on the MONITOR event socket...[thread location = %p]\n", 
   1.213    				__FUNCTION__, g_thread_self( ) );
   1.214 +  	*ret = TRUE;  	  	
   1.215 +  } else {
   1.216 +  	gmyth_debug ( "\n[%s]\tERROR! Coudn't start listener on the MONITOR event socket...[thread location = %p]\n", 
   1.217 +  				__FUNCTION__, g_thread_self( ) );
   1.218 +  	*ret = FALSE;
   1.219    }
   1.220  
   1.221 -cleanup:
   1.222 -  //if ( source != NULL )
   1.223 -  //  g_source_unref( source );
   1.224 +//cleanup:
   1.225      
   1.226    gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n", 
   1.227    			__FUNCTION__, ( *ret == TRUE ? "YES" : "NO" ) );
   1.228      
   1.229 -    return TRUE;
   1.230 +    return *ret;
   1.231  }
   1.232  
   1.233  void