[svn r141] Fixes the gmyth_uri* calls, starts a Monitor listener thread.
1.1 --- a/gmyth/src/gmyth_backendinfo.c Wed Nov 29 19:06:58 2006 +0000
1.2 +++ b/gmyth/src/gmyth_backendinfo.c Wed Nov 29 19:27:41 2006 +0000
1.3 @@ -119,7 +119,7 @@
1.4 GMythBackendInfo *backend_info =
1.5 GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
1.6
1.7 - GMythURI* uri = gmyth_uri_new( uri_str );
1.8 + GMythURI* uri = gmyth_uri_new_with_value( uri_str );
1.9
1.10 gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri ) );
1.11 gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( uri ) );
2.1 --- a/gmyth/src/gmyth_file_transfer.c Wed Nov 29 19:06:58 2006 +0000
2.2 +++ b/gmyth/src/gmyth_file_transfer.c Wed Nov 29 19:27:41 2006 +0000
2.3 @@ -75,6 +75,8 @@
2.4 #define GMYTHTV_ENABLE_DEBUG 1
2.5 #endif
2.6
2.7 +GThread *monitor_th = NULL;
2.8 +
2.9 enum myth_sock_types {
2.10 GMYTH_PLAYBACK_TYPE = 0,
2.11 GMYTH_MONITOR_TYPE,
2.12 @@ -82,10 +84,10 @@
2.13 GMYTH_RINGBUFFER_TYPE
2.14 };
2.15
2.16 -//static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
2.17 +static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT;
2.18
2.19 -//static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
2.20 -static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data );
2.21 +static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
2.22 +/* static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ); */
2.23
2.24 static GMutex* mutex = NULL;
2.25
2.26 @@ -175,7 +177,7 @@
2.27 {
2.28 gboolean ret = TRUE;
2.29
2.30 - transfer->uri = gmyth_uri_new ( uri_str->str );
2.31 + transfer->uri = gmyth_uri_new_with_value ( uri_str->str );
2.32 transfer->hostname = g_string_new( gmyth_uri_get_host(transfer->uri) );
2.33 transfer->port = gmyth_uri_get_port( transfer->uri );
2.34
2.35 @@ -196,114 +198,126 @@
2.36
2.37 }
2.38
2.39 -static gboolean
2.40 -myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
2.41 -//myth_control_sock_listener( GIOChannel *io_channel )
2.42 +static gboolean*
2.43 +//myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
2.44 +myth_control_sock_listener( GIOChannel *io_channel )
2.45 {
2.46
2.47 GIOStatus io_status;
2.48 GError *error = NULL;
2.49 GIOCondition io_cond;
2.50 - //GIOCondition condition;
2.51 + GIOCondition condition;
2.52 gchar *trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE*10 );
2.53 guint recv = 0;
2.54 - //gboolean* ret = g_new0( gboolean, 1 );
2.55 - gboolean ret = TRUE;
2.56 + gboolean* ret = g_new0( gboolean, 1 );
2.57 + //gboolean ret = TRUE;
2.58 + gsize len = 0;
2.59
2.60 - //*ret = TRUE;
2.61 + *ret = TRUE;
2.62 + //myth_control_acquire_context (TRUE);
2.63
2.64 if ( io_channel == NULL ) {
2.65 - ret = FALSE;
2.66 + g_debug ("Monitor socket is NULL!\n");
2.67 + *ret = FALSE;
2.68 goto clean_up;
2.69 }
2.70 gmyth_debug ("Listening on Monitor socket...!\n");
2.71 -
2.72 - //condition = g_io_channel_get_buffer_condition( io_channel );
2.73
2.74 - myth_control_acquire_context (TRUE);
2.75 -
2.76 - //while ( !has_io_access )
2.77 - // g_cond_wait( io_watcher_cond, mutex );
2.78 -
2.79 - //myth_control_acquire_context (TRUE);
2.80 -
2.81 - gsize len = 0;
2.82 - if (condition & G_IO_HUP) {
2.83 - gmyth_debug ("Read end of pipe died!\n");
2.84 - ret = FALSE;
2.85 - goto clean_up;
2.86 - }
2.87 -
2.88 - if ( ( condition & G_IO_IN ) != 0 ) {
2.89 - io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
2.90 - do
2.91 - {
2.92 - //trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE );
2.93 -
2.94 - io_status = g_io_channel_read_chars( io_channel, trash + recv,
2.95 - GMYTHTV_BUFFER_SIZE, &len, &error);
2.96 -
2.97 - gmyth_debug ( "[%s] Received data buffer from IO binary channel... %d bytes gone!\n",
2.98 - __FUNCTION__, len );
2.99 -
2.100 - recv += len;
2.101 -
2.102 - //msg = g_strconcat( msg, g_strdup(trash), NULL );
2.103 -
2.104 - //if ( trash != NULL )
2.105 - // g_free( trash );
2.106 -
2.107 - io_cond = g_io_channel_get_buffer_condition( io_channel );
2.108 -
2.109 - } while ( ( io_cond & G_IO_IN ) != 0 && ( io_status != G_IO_STATUS_ERROR ) );
2.110 + while (TRUE) {
2.111 +
2.112 + condition = g_io_channel_get_buffer_condition( io_channel );
2.113 +
2.114 + //myth_control_acquire_context (TRUE);
2.115 +
2.116 + //while ( !has_io_access )
2.117 + // g_cond_wait( io_watcher_cond, mutex );
2.118 +
2.119 + //myth_control_acquire_context (TRUE);
2.120 +
2.121 + if (condition & G_IO_HUP) {
2.122 + gmyth_debug ("Read end of pipe died!\n");
2.123 + *ret = FALSE;
2.124 + goto clean_up;
2.125 + }
2.126 +
2.127 + if ( ( condition & G_IO_IN ) != 0 ) {
2.128 + io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
2.129 + do
2.130 + {
2.131 + //trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE );
2.132 +
2.133 + io_status = g_io_channel_read_chars( io_channel, trash + recv,
2.134 + GMYTHTV_BUFFER_SIZE, &len, &error);
2.135 +
2.136 + gmyth_debug ( "[%s] Received data buffer from IO binary channel... %d bytes gone!\n",
2.137 + __FUNCTION__, len );
2.138 +
2.139 + recv += len;
2.140 +
2.141 + //msg = g_strconcat( msg, g_strdup(trash), NULL );
2.142 +
2.143 + //if ( trash != NULL )
2.144 + // g_free( trash );
2.145 +
2.146 + io_cond = g_io_channel_get_buffer_condition( io_channel );
2.147 +
2.148 + } while ( ( io_cond & G_IO_IN ) != 0 && ( io_status != G_IO_STATUS_ERROR ) );
2.149 + }
2.150 +
2.151 + g_usleep( 300 );
2.152 +
2.153 }
2.154 //ret = g_io_channel_read_chars ( source, &msg, &len, NULL, &err);
2.155 if ( io_status == G_IO_STATUS_ERROR ) {
2.156 gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" );
2.157 - ret = FALSE;
2.158 + *ret = FALSE;
2.159 }
2.160 gmyth_debug ("\n[%s]\tEVENT: Read %d bytes: %s\n\n", __FUNCTION__, len, trash != NULL ? trash : "[no event data]" );
2.161
2.162 //g_cond_signal( io_watcher_cond );
2.163
2.164 +clean_up:
2.165 //myth_control_release_context( );
2.166 -clean_up:
2.167 +
2.168 return ret;
2.169
2.170 }
2.171
2.172 static gboolean
2.173 -gmyth_connect_to_backend_monitor (GMythFileTransfer *transfer)
2.174 +gmyth_connect_to_backend_monitor (GMythFileTransfer *transfer, GString *hostname )
2.175 {
2.176 gboolean ret = TRUE;
2.177 GString *base_str = g_string_new( "" );
2.178 - guint source_id = 0;
2.179 + //guint source_id = 0;
2.180
2.181 transfer->event_sock = gmyth_socket_new();
2.182
2.183 gmyth_socket_connect ( transfer->event_sock, transfer->hostname->str, transfer->port);
2.184 - g_string_printf( base_str, "ANN Monitor %s %d", transfer->hostname->str, TRUE );
2.185 + g_string_printf( base_str, "ANN Monitor %s %d", hostname->str, TRUE );
2.186
2.187 gmyth_socket_send_command( transfer->event_sock, base_str );
2.188 GString *resp = gmyth_socket_receive_response( transfer->event_sock );
2.189 gmyth_debug ( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
2.190 - //g_thread_create( (GThreadFunc)myth_control_sock_listener, transfer->event_sock->sd_io_ch, TRUE, NULL );
2.191 + monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_listener, transfer->event_sock->sd_io_ch, FALSE, NULL );
2.192 + /*
2.193 io_watcher_context = g_main_context_default();
2.194 - //GMainLoop *loop = g_main_loop_new( NULL, TRUE );
2.195 + GMainLoop *loop = g_main_loop_new( NULL, TRUE );
2.196
2.197 - //GSource *source;
2.198 + GSource *source;
2.199
2.200 if ( transfer->event_sock->sd_io_ch != NULL ) {
2.201 - source_id = g_io_add_watch( transfer->event_sock->sd_io_ch, G_IO_IN, (GIOFunc)myth_control_sock_listener, NULL );
2.202 + source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN );
2.203 //transfer->event_sock->sd_io_ch
2.204 } else {
2.205 ret = FALSE;
2.206 goto cleanup;
2.207 }
2.208
2.209 - //g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL );
2.210 + g_source_set_callback ( source, (GIOFunc)myth_control_sock_listener, NULL, NULL );
2.211
2.212 - //g_source_attach( source, io_watcher_context );
2.213 + g_source_attach( source, io_watcher_context );
2.214 +
2.215 + */
2.216
2.217 /*
2.218 if (source==NULL) {
2.219 @@ -316,8 +330,10 @@
2.220 //g_main_loop_run( loop );
2.221
2.222 cleanup:
2.223 - //if ( source != NULL )
2.224 - // g_source_unref( source );
2.225 + /*
2.226 + if ( source != NULL )
2.227 + g_source_unref( source );
2.228 + */
2.229
2.230 gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n",
2.231 __FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) );
2.232 @@ -386,7 +402,7 @@
2.233 return FALSE;
2.234 }
2.235
2.236 - gmyth_connect_to_backend_monitor( transfer );
2.237 + //gmyth_connect_to_backend_monitor( transfer, hostname );
2.238
2.239 if ( strlist != NULL )
2.240 g_object_unref( strlist );
2.241 @@ -500,7 +516,7 @@
2.242 {
2.243
2.244 gboolean ret = TRUE;
2.245 - guint max_iter = 50;
2.246 + //guint max_iter = 50;
2.247
2.248 //g_mutex_lock( mutex );
2.249
2.250 @@ -510,14 +526,16 @@
2.251 //has_io_access = FALSE;
2.252
2.253 //myth_control_acquire_context (FALSE);
2.254 -
2.255 - g_mutex_lock( mutex );
2.256 -
2.257 +
2.258 + /*
2.259 if ( do_wait ) {
2.260 while ( --max_iter > 0 && !g_main_context_wait( io_watcher_context, io_watcher_cond, mutex ) )
2.261 ret = FALSE;
2.262 } else if ( !g_main_context_acquire( io_watcher_context ) )
2.263 ret = FALSE;
2.264 + */
2.265 +
2.266 + //g_static_mutex_lock( &st_mutex );
2.267
2.268 return ret;
2.269
2.270 @@ -528,17 +546,18 @@
2.271 {
2.272
2.273 gboolean ret = TRUE;
2.274 -
2.275 - g_main_context_release( io_watcher_context );
2.276 +
2.277 + //g_static_mutex_unlock( &st_mutex );
2.278
2.279 - g_mutex_unlock( mutex );
2.280 + //g_main_context_release( io_watcher_context );
2.281 +
2.282 + //g_main_context_wakeup( io_watcher_context );
2.283
2.284 //has_io_access = TRUE;
2.285
2.286 //g_cond_broadcast( io_watcher_cond );
2.287
2.288 - //g_mutex_unlock( mutex );
2.289 -
2.290 + //g_mutex_unlock( mutex );
2.291
2.292 return ret;
2.293
2.294 @@ -593,6 +612,8 @@
2.295 g_string_append_printf ( query, "%d", transfer->file_id );
2.296 gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str );
2.297
2.298 + myth_control_acquire_context( TRUE );
2.299 +
2.300 while (total_read == 0) {
2.301
2.302 strlist = gmyth_string_list_new();
2.303 @@ -631,6 +652,8 @@
2.304 }
2.305 }
2.306 }
2.307 +
2.308 + myth_control_release_context( );
2.309
2.310 g_object_unref( strlist );
2.311 g_string_free (query, TRUE);