[svn r233] Improved GObject' signals emition, following some tips from Kapeta. trunk
authorrosfran
Tue Dec 19 23:28:32 2006 +0000 (2006-12-19)
branchtrunk
changeset 23200b55a87f1ba
parent 231 94387b7ed946
child 233 1cf29cf20fb3
[svn r233] Improved GObject' signals emition, following some tips from Kapeta.
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_file_transfer.h
gmyth/src/gmyth_livetv.c
gmyth/src/gmyth_marshal.list
gmyth/src/gmyth_monitor_handler.c
gmyth/src/gmyth_monitor_handler.h
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Tue Dec 19 21:29:51 2006 +0000
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Tue Dec 19 23:28:32 2006 +0000
     1.3 @@ -103,7 +103,7 @@
     1.4  static void gmyth_file_transfer_finalize (GObject *object);
     1.5  
     1.6  static void gmyth_file_transfer_program_info_changed( GMythFileTransfer *transfer, 
     1.7 -										gint msg_code, gpointer livetv_transfer, gpointer user_data );
     1.8 +										gint msg_code, gpointer livetv_transfer );
     1.9  
    1.10  static gboolean gmyth_connect_to_backend (GMythFileTransfer *transfer);
    1.11  
    1.12 @@ -631,9 +631,9 @@
    1.13  
    1.14  static void 
    1.15  gmyth_file_transfer_program_info_changed( GMythFileTransfer *transfer, 
    1.16 -										gint msg_code, gpointer livetv_transfer, gpointer user_data )
    1.17 +										gint msg_code, gpointer livetv_transfer )
    1.18  {
    1.19 -	GMythLiveTV *livetv = (GMythLiveTV*)user_data;
    1.20 +	GMythLiveTV *livetv = (GMythLiveTV*)livetv_transfer;
    1.21  	
    1.22  	gmyth_debug( "Program info changed! ( file transfer orig. = %p, ptr. = [%s], user data = [%s] )", transfer, 
    1.23  		livetv_transfer != NULL ? "[NOT NULL]" : "[NULL]", livetv != NULL ? "[NOT NULL]" : "[NULL]" );
     2.1 --- a/gmyth/src/gmyth_file_transfer.h	Tue Dec 19 21:29:51 2006 +0000
     2.2 +++ b/gmyth/src/gmyth_file_transfer.h	Tue Dec 19 23:28:32 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, gpointer user_data );
     2.8 +										gint msg_code, gpointer livetv_transfer );
     2.9  };
    2.10  
    2.11  struct _GMythFileTransfer
     3.1 --- a/gmyth/src/gmyth_livetv.c	Tue Dec 19 21:29:51 2006 +0000
     3.2 +++ b/gmyth/src/gmyth_livetv.c	Tue Dec 19 23:28:32 2006 +0000
     3.3 @@ -138,15 +138,19 @@
     3.4  
     3.5  static void
     3.6  gmyth_livetv_monitor_signal_handler( GMythMonitorHandler *monitor, gint msg_code, 
     3.7 -							gchar* message, gpointer livetv, gpointer user_data )
     3.8 +							gchar* message, gpointer user_data )
     3.9  {
    3.10  	GMythLiveTV *live_tv = (GMythLiveTV*) user_data;
    3.11 +	g_object_ref( live_tv );
    3.12  	
    3.13 -	gmyth_debug( "LIVETV Signal handler ( msg = %s, code = %d, livetv param = %s, user_data = %s )\n", message, msg_code, livetv != NULL ? "" : 
    3.14 +	gmyth_debug( "LIVETV Signal handler ( msg = %s, code = %d, live_tv param = %s, user_data = %s )\n", message, msg_code, live_tv != NULL ? "" : 
    3.15  					"NULL", user_data != NULL ? "" : "NULL" );
    3.16  	
    3.17 -	if ( NULL == live_tv && user_data == NULL )
    3.18 -		return;		
    3.19 +	if ( NULL == live_tv )
    3.20 +	{
    3.21 +		gmyth_debug( "LiveTV_obj is equals to NULL!!!" );
    3.22 +		return;
    3.23 +	}		
    3.24  	
    3.25  	switch ( msg_code ) 
    3.26  	{
    3.27 @@ -159,10 +163,10 @@
    3.28  			/* advertises the FileTransfer about the program info changed */
    3.29  			if ( live_tv->file_transfer != NULL )
    3.30  			{
    3.31 -				g_signal_emit ( live_tv->file_transfer,
    3.32 -	             GMYTH_FILE_TRANSFER_GET_CLASS (live_tv->file_transfer)->program_info_changed_handler_signal_id,
    3.33 +				g_signal_emit_by_name ( G_OBJECT(live_tv->file_transfer),
    3.34 +	             "program-info-changed",
    3.35  	             0, /* details */
    3.36 -	             msg_code, live_tv, live_tv );
    3.37 +	             msg_code, live_tv );
    3.38  	             
    3.39  	      gmyth_livetv_monitor_handler_stop( live_tv );	      
    3.40  			} else
    3.41 @@ -328,6 +332,7 @@
    3.42  	if ( !gmyth_livetv_monitor_handler_start( livetv ) )
    3.43  	{
    3.44  		res = FALSE;
    3.45 +		gmyth_debug("LiveTV MONITOR handler error on setup!");
    3.46  		goto error;		
    3.47  	}
    3.48  	
     4.1 --- a/gmyth/src/gmyth_marshal.list	Tue Dec 19 21:29:51 2006 +0000
     4.2 +++ b/gmyth/src/gmyth_marshal.list	Tue Dec 19 23:28:32 2006 +0000
     4.3 @@ -1,2 +1,2 @@
     4.4 -VOID:INT,STRING,POINTER
     4.5 +VOID:INT,STRING
     4.6  VOID:INT,POINTER
     5.1 --- a/gmyth/src/gmyth_monitor_handler.c	Tue Dec 19 21:29:51 2006 +0000
     5.2 +++ b/gmyth/src/gmyth_monitor_handler.c	Tue Dec 19 23:28:32 2006 +0000
     5.3 @@ -78,10 +78,11 @@
     5.4  //static gboolean gmyth_monitor_handler_listener( GIOChannel *io_channel, 
     5.5  //						GIOCondition condition, gpointer data );
     5.6  
     5.7 -gboolean* gmyth_monitor_handler_listener( GMythMonitorHandler *monitor );
     5.8 +//gboolean* gmyth_monitor_handler_listener( GMythMonitorHandler *monitor );
     5.9  
    5.10 -static void gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message,
    5.11 -			gpointer live_tv, gpointer user_data );
    5.12 +void gmyth_monitor_handler_listener( GMythMonitorHandler *monitor, gpointer user_data );
    5.13 +
    5.14 +static void gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message );
    5.15  
    5.16  static GMutex*				mutex 					 = NULL;
    5.17  
    5.18 @@ -118,12 +119,11 @@
    5.19  		                 0,
    5.20  										 NULL,
    5.21  										 NULL,
    5.22 -										 gmyth_marshal_VOID__INT_STRING_POINTER,
    5.23 +										 gmyth_marshal_VOID__INT_STRING,
    5.24  										 G_TYPE_NONE,
    5.25 -										 3,
    5.26 +										 2,
    5.27  										 G_TYPE_INT,
    5.28 -										 G_TYPE_STRING,
    5.29 -										 G_TYPE_POINTER);
    5.30 +										 G_TYPE_STRING);
    5.31  										 
    5.32  	gmonitor_class->backend_events_handler = gmyth_monitor_handler_default_listener;
    5.33  
    5.34 @@ -160,10 +160,12 @@
    5.35  	
    5.36  	if ( monitor->monitor_th != NULL )  
    5.37    {
    5.38 -  	//g_thread_exit( monitor->monitor_th, TRUE, FALSE );
    5.39 +  	g_thread_pool_free( monitor->monitor_th, TRUE, FALSE );
    5.40 +  	/*
    5.41    	g_thread_exit( monitor->monitor_th );
    5.42    	if ( monitor->monitor_th != NULL )
    5.43    		g_object_unref( monitor->monitor_th );
    5.44 +  	*/
    5.45    	monitor->monitor_th = NULL;
    5.46    }
    5.47  	
    5.48 @@ -179,7 +181,7 @@
    5.49    	monitor->hostname = NULL;
    5.50    }
    5.51  
    5.52 -  if ( monitor->backend_msgs != NULL )  
    5.53 +  if ( monitor->backend_msgs != NULL )
    5.54    {
    5.55    	g_hash_table_destroy ( monitor->backend_msgs );
    5.56    	monitor->backend_msgs = NULL;
    5.57 @@ -321,7 +323,8 @@
    5.58  	    	if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
    5.59  	    			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) ||
    5.60  	    			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
    5.61 -	    	{		        	
    5.62 +	    	{
    5.63 +	    		gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_PROGRAM_INFO_CHANGED, msg = %s", *back_msg_action );
    5.64  	    		msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
    5.65  	    	}  	
    5.66  	
    5.67 @@ -344,12 +347,11 @@
    5.68  }
    5.69  
    5.70  static void
    5.71 -gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message,
    5.72 -			gpointer live_tv, gpointer user_data )
    5.73 +gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message )
    5.74  {
    5.75  	//assert( message!= NULL );  
    5.76 -	gmyth_debug( "DEFAULT Signal handler ( msg = %s, code = %d, file_transfer ptr. = %p )\n", 
    5.77 -				message, msg_code, live_tv );
    5.78 +	gmyth_debug( "DEFAULT Signal handler ( msg = %s, code = %d )\n", 
    5.79 +				message, msg_code );
    5.80  }
    5.81  
    5.82  static void
    5.83 @@ -362,8 +364,9 @@
    5.84  //gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data)
    5.85  //static gboolean
    5.86  //gmyth_monitor_handler_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
    5.87 -gboolean*
    5.88 -gmyth_monitor_handler_listener( GMythMonitorHandler *monitor )
    5.89 +//gboolean* gmyth_monitor_handler_listener( GMythMonitorHandler *monitor )
    5.90 +void
    5.91 +gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data)
    5.92  {
    5.93  	//GMythMonitorHandler *monitor = (GMythMonitorHandler*)data; 
    5.94    GIOStatus io_status;
    5.95 @@ -427,7 +430,7 @@
    5.96  	        g_signal_emit ( monitor,
    5.97  	               GMYTH_MONITOR_HANDLER_GET_CLASS (monitor)->backend_events_handler_signal_id,
    5.98  	               0, /* details */
    5.99 -	               msg_type, back_msg_action, NULL );
   5.100 +	               msg_type, back_msg_action );
   5.101  	               
   5.102  	        if (back_msg_action!= NULL)
   5.103  	        	g_free( back_msg_action );
   5.104 @@ -463,7 +466,7 @@
   5.105    if (strlist!=NULL)
   5.106    	g_object_unref( strlist );
   5.107    	
   5.108 - 	return ret;
   5.109 + 	return;
   5.110  
   5.111  }
   5.112  
   5.113 @@ -542,11 +545,13 @@
   5.114  	*ret = TRUE;	
   5.115  	
   5.116  	/*if (!g_thread_supported () ) 	g_thread_init (NULL);*/
   5.117 -	
   5.118 -  monitor->monitor_th = g_thread_create( (GThreadFunc)gmyth_monitor_handler_listener, 
   5.119 +	/*
   5.120 +  monitor->monitor_th = g_thread_pool_new( (GThreadFunc)gmyth_monitor_handler_listener, 
   5.121    					monitor, TRUE, NULL );
   5.122 -  					
   5.123 -  //g_thread_pool_push( monitor_th, monitor, NULL ); 
   5.124 + */				
   5.125 +  monitor->monitor_th = g_thread_pool_new( (GFunc)gmyth_monitor_handler_listener, 
   5.126 +  					monitor, 3, TRUE, NULL );
   5.127 +  g_thread_pool_push( monitor->monitor_th, monitor, NULL ); 
   5.128    					
   5.129    //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
   5.130    if ( monitor->monitor_th != NULL )
     6.1 --- a/gmyth/src/gmyth_monitor_handler.h	Tue Dec 19 21:29:51 2006 +0000
     6.2 +++ b/gmyth/src/gmyth_monitor_handler.h	Tue Dec 19 23:28:32 2006 +0000
     6.3 @@ -71,8 +71,7 @@
     6.4  	guint backend_events_handler_signal_id;
     6.5  
     6.6    /* signal default handlers */
     6.7 -  void (*backend_events_handler) (GMythMonitorHandler *monitor, gint msg_code, gchar* message, 
     6.8 -  					gpointer livetv, gpointer user_data );
     6.9 +  void (*backend_events_handler) (GMythMonitorHandler *monitor, gint msg_code, gchar* message );
    6.10  };
    6.11  
    6.12  struct _GMythMonitorHandler
    6.13 @@ -85,9 +84,10 @@
    6.14  	/* socket descriptors */
    6.15  	GMythSocket *event_sock;
    6.16  	
    6.17 -	GThread *monitor_th;
    6.18 +	GThreadPool *monitor_th;
    6.19  	
    6.20 -	gboolean* (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor );
    6.21 +	// gboolean* (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor );
    6.22 +	void (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor, gpointer user_data );
    6.23  	
    6.24  	gchar *hostname;
    6.25  	gint port;