[svn r362] Some fixes in the GIOWatcher clean-ups, and changed the API version number.
1.1 --- a/gmyth/configure.ac Tue Feb 13 23:22:07 2007 +0000
1.2 +++ b/gmyth/configure.ac Wed Feb 14 21:28:49 2007 +0000
1.3 @@ -10,7 +10,7 @@
1.4
1.5 dnl when going to/from release please set the nano (fourth number) right !
1.6 dnl releases only do Wall, SVN and prerelease does Werror too
1.7 -AS_VERSION(gmyth, GMYTH, 0, 1, 0, 3, GMYTH_SVN="no", GMYTH_SVN="yes")
1.8 +AS_VERSION(gmyth, GMYTH, 0, 1, 0, 8, GMYTH_SVN="no", GMYTH_SVN="yes")
1.9 GMYTH_MAJORMINOR=$GMYTH_MAJOR_VERSION.$GMYTH_MINOR_VERSION
1.10 AC_SUBST(GMYTH_MAJORMINOR)
1.11
2.1 --- a/gmyth/src/gmyth_monitor_handler.c Tue Feb 13 23:22:07 2007 +0000
2.2 +++ b/gmyth/src/gmyth_monitor_handler.c Wed Feb 14 21:28:49 2007 +0000
2.3 @@ -137,14 +137,14 @@
2.4 monitor->port = 0;
2.5 monitor->actual_index = 0;
2.6
2.7 - monitor->allow_msgs_listener = TRUE;
2.8 + monitor->allow_msgs_listener = FALSE;
2.9
2.10 - //monitor->backend_msgs = g_hash_table_new( g_int_hash, g_int_equal );
2.11 + /* monitor->backend_msgs = g_hash_table_new( g_int_hash, g_int_equal ); */
2.12
2.13 /* it is used for signalizing the event socket consumer thread */
2.14 - //io_watcher_cond = g_cond_new();
2.15 + monitor->mutex = g_mutex_new();
2.16
2.17 - monitor->monitor_th = NULL;
2.18 + monitor->sid_io_watch = -1;
2.19
2.20 monitor->gmyth_monitor_handler_listener = gmyth_monitor_handler_listener;
2.21 }
2.22 @@ -153,28 +153,35 @@
2.23 gmyth_monitor_handler_dispose (GObject *object)
2.24 {
2.25 GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER (object);
2.26 + GSource* source = NULL;
2.27 + GMainContext* context = g_main_context_default();
2.28
2.29 gmyth_monitor_handler_close(monitor);
2.30
2.31 monitor->allow_msgs_listener = FALSE;
2.32 -
2.33 - /*
2.34 - if ( monitor->mutex != NULL )
2.35 +
2.36 + if ( context != NULL && monitor->sid_io_watch != -1 )
2.37 + {
2.38 + g_main_context_acquire( context );
2.39 +
2.40 + source = g_main_context_find_source_by_id( g_main_context_default(),
2.41 + monitor->sid_io_watch );
2.42 +
2.43 + if ( source != NULL )
2.44 + {
2.45 + g_source_destroy( source );
2.46 + }
2.47 +
2.48 + g_main_context_release( context );
2.49 +
2.50 + }
2.51 +
2.52 + if ( monitor->mutex != NULL )
2.53 {
2.54 - g_mutex_unlock( monitor->mutex );
2.55 + //g_mutex_unlock( monitor->mutex );
2.56 g_mutex_free( monitor->mutex );
2.57 monitor->mutex = NULL;
2.58 }
2.59 - */
2.60 -
2.61 - if ( monitor->monitor_th != NULL )
2.62 - {
2.63 - g_thread_pool_free( monitor->monitor_th, TRUE, FALSE );
2.64 - //g_thread_exit( monitor->monitor_th );
2.65 - //if ( monitor->monitor_th != NULL )
2.66 - // g_object_unref( monitor->monitor_th );
2.67 - monitor->monitor_th = NULL;
2.68 - }
2.69
2.70 if ( monitor->event_sock != NULL )
2.71 {
2.72 @@ -182,7 +189,7 @@
2.73 /*gmyth_socket_close_connection( monitor->event_sock );*/
2.74 monitor->event_sock = NULL;
2.75 }
2.76 -
2.77 +
2.78 if ( monitor->hostname != NULL )
2.79 {
2.80 g_free( monitor->hostname );
2.81 @@ -248,7 +255,7 @@
2.82 ret = FALSE;
2.83 */
2.84
2.85 - //g_mutex_lock( monitor->mutex );
2.86 + g_mutex_lock( monitor->mutex );
2.87
2.88 return ret;
2.89
2.90 @@ -260,7 +267,7 @@
2.91
2.92 gboolean ret = TRUE;
2.93
2.94 - //g_mutex_unlock( monitor->mutex );
2.95 + g_mutex_unlock( monitor->mutex );
2.96
2.97 //g_main_context_release( io_watcher_context );
2.98
2.99 @@ -360,13 +367,14 @@
2.100 } else if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "DONE_RECORDING" ) ) {
2.101 gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_DONE_RECORDING, msg = %s", *back_msg_action );
2.102 msg_type = GMYTH_BACKEND_DONE_RECORDING;
2.103 - }
2.104 + }
2.105
2.106 //g_hash_table_insert ( monitor->backend_msgs,
2.107 // &(monitor->actual_index), *back_msg_action );
2.108
2.109 - } // if
2.110 - }
2.111 + } /* if */
2.112 +
2.113 + } /* if */
2.114
2.115 if ( back_msg != NULL )
2.116 {
2.117 @@ -397,12 +405,8 @@
2.118 gmyth_debug( "Backend message event: %s --- ", str->str );
2.119 }
2.120
2.121 -//static void
2.122 -//gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data)
2.123 gboolean
2.124 gmyth_monitor_handler_listener( GIOChannel *io_channel, GIOCondition io_cond, gpointer data )
2.125 -//gboolean* gmyth_monitor_handler_listener( GMythMonitorHandler *monitor )
2.126 -//void gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data)
2.127 {
2.128 GMythMonitorHandler *monitor = (GMythMonitorHandler*)data;
2.129 GIOStatus io_status;
2.130 @@ -494,8 +498,6 @@
2.131
2.132 gmyth_debug ("\tMONITOR EVENT: Read %d bytes\n", recv );
2.133
2.134 - //g_usleep( 300 );
2.135 -
2.136 } /* main GThread while */
2.137
2.138 myth_control_release_context (monitor);
2.139 @@ -536,46 +538,27 @@
2.140 gmyth_monitor_handler_setup( GMythMonitorHandler *monitor, GIOChannel *channel )
2.141 {
2.142 gboolean *ret = g_new0( gboolean, 1 );
2.143 - guint src_id = 0;
2.144
2.145 *ret = TRUE;
2.146
2.147 - //io_watcher_context = g_main_context_default();
2.148 - //GMainLoop *loop = g_main_loop_new( io_watcher_context, TRUE );
2.149 -
2.150 - //GSource *source;
2.151 -
2.152 if ( channel != NULL ) {
2.153 - //source = g_io_create_watch( channel, G_IO_IN | G_IO_HUP );
2.154 - src_id = g_io_add_watch( channel, G_IO_IN | G_IO_HUP,
2.155 +
2.156 + monitor->allow_msgs_listener = TRUE;
2.157 +
2.158 + monitor->sid_io_watch = g_io_add_watch( channel, G_IO_IN | G_IO_HUP,
2.159 (GIOFunc)gmyth_monitor_handler_listener, monitor );
2.160 } else {
2.161 *ret = FALSE;
2.162 goto cleanup;
2.163 }
2.164
2.165 - //g_source_set_callback ( source, (GSourceFunc)gmyth_monitor_handler_listener, NULL, NULL );
2.166 -
2.167 - //g_source_attach( source, io_watcher_context );
2.168 -
2.169 - //if (NULL == source){
2.170 - if (src_id < 0){
2.171 + if (monitor->sid_io_watch < 0){
2.172 gmyth_debug( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
2.173 *ret = FALSE;
2.174 goto cleanup;
2.175 }
2.176
2.177 - //g_main_loop_run( loop );
2.178 -
2.179 cleanup:
2.180 - //if ( source != NULL )
2.181 - // g_source_unref( source );
2.182 -
2.183 - //if ( io_watcher_context != NULL )
2.184 - // g_main_context_unref( io_watcher_context );
2.185 -
2.186 - //if ( loop != NULL )
2.187 - // g_main_loop_unref( loop );
2.188
2.189 return ret;
2.190
2.191 @@ -587,20 +570,6 @@
2.192 gboolean *ret = g_new0( gboolean, 1 );
2.193 *ret = TRUE;
2.194
2.195 - /*if (!g_thread_supported () ) g_thread_init (NULL);*/
2.196 - /*
2.197 - monitor->monitor_th = g_thread_pool_new( (GThreadFunc)gmyth_monitor_handler_listener,
2.198 - monitor, TRUE, NULL );
2.199 - */
2.200 -
2.201 - /*
2.202 -
2.203 - monitor->monitor_th = g_thread_pool_new( (GFunc)gmyth_monitor_handler_listener,
2.204 - monitor, 3, TRUE, NULL );
2.205 - g_thread_pool_push( monitor->monitor_th, monitor, NULL );
2.206 - */
2.207 - //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
2.208 - //if ( monitor->monitor_th != NULL )
2.209 ret = gmyth_monitor_handler_setup( monitor, monitor->event_sock->sd_io_ch );
2.210 if ( *ret )
2.211 {
2.212 @@ -613,8 +582,6 @@
2.213 *ret = FALSE;
2.214 }
2.215
2.216 -//cleanup:
2.217 -
2.218 gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n",
2.219 __FUNCTION__, ( *ret == TRUE ? "YES" : "NO" ) );
2.220
3.1 --- a/gmyth/src/gmyth_monitor_handler.h Tue Feb 13 23:22:07 2007 +0000
3.2 +++ b/gmyth/src/gmyth_monitor_handler.h Wed Feb 14 21:28:49 2007 +0000
3.3 @@ -85,10 +85,6 @@
3.4 /* socket descriptors */
3.5 GMythSocket *event_sock;
3.6
3.7 - GThreadPool *monitor_th;
3.8 -
3.9 - //gboolean* (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor );
3.10 - //void (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor, gpointer user_data );
3.11 gboolean (*gmyth_monitor_handler_listener) ( GIOChannel *io_channel,
3.12 GIOCondition io_cond, gpointer data );
3.13
3.14 @@ -102,7 +98,9 @@
3.15 /* stores the messages coming from the backend */
3.16 GHashTable *backend_msgs;
3.17
3.18 - //GMutex *mutex;
3.19 + GMutex *mutex;
3.20 +
3.21 + guint sid_io_watch;
3.22
3.23 };
3.24