# HG changeset patch # User rosfran # Date 1164828461 0 # Node ID 2d912dd5b845fd612d34414db55f65f947b9fdc1 # Parent 92baff6356c7ebecb6c413a80784c68e7f5bc939 [svn r141] Fixes the gmyth_uri* calls, starts a Monitor listener thread. diff -r 92baff6356c7 -r 2d912dd5b845 gmyth/src/gmyth_backendinfo.c --- a/gmyth/src/gmyth_backendinfo.c Wed Nov 29 19:06:58 2006 +0000 +++ b/gmyth/src/gmyth_backendinfo.c Wed Nov 29 19:27:41 2006 +0000 @@ -119,7 +119,7 @@ GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL)); - GMythURI* uri = gmyth_uri_new( uri_str ); + GMythURI* uri = gmyth_uri_new_with_value( uri_str ); gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri ) ); gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( uri ) ); diff -r 92baff6356c7 -r 2d912dd5b845 gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Wed Nov 29 19:06:58 2006 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Wed Nov 29 19:27:41 2006 +0000 @@ -75,6 +75,8 @@ #define GMYTHTV_ENABLE_DEBUG 1 #endif +GThread *monitor_th = NULL; + enum myth_sock_types { GMYTH_PLAYBACK_TYPE = 0, GMYTH_MONITOR_TYPE, @@ -82,10 +84,10 @@ GMYTH_RINGBUFFER_TYPE }; -//static GStaticMutex mutex = G_STATIC_MUTEX_INIT; +static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT; -//static gboolean* myth_control_sock_listener( GIOChannel *io_channel ); -static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ); +static gboolean* myth_control_sock_listener( GIOChannel *io_channel ); +/* static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ); */ static GMutex* mutex = NULL; @@ -175,7 +177,7 @@ { gboolean ret = TRUE; - transfer->uri = gmyth_uri_new ( uri_str->str ); + transfer->uri = gmyth_uri_new_with_value ( uri_str->str ); transfer->hostname = g_string_new( gmyth_uri_get_host(transfer->uri) ); transfer->port = gmyth_uri_get_port( transfer->uri ); @@ -196,114 +198,126 @@ } -static gboolean -myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ) -//myth_control_sock_listener( GIOChannel *io_channel ) +static gboolean* +//myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ) +myth_control_sock_listener( GIOChannel *io_channel ) { GIOStatus io_status; GError *error = NULL; GIOCondition io_cond; - //GIOCondition condition; + GIOCondition condition; gchar *trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE*10 ); guint recv = 0; - //gboolean* ret = g_new0( gboolean, 1 ); - gboolean ret = TRUE; + gboolean* ret = g_new0( gboolean, 1 ); + //gboolean ret = TRUE; + gsize len = 0; - //*ret = TRUE; + *ret = TRUE; + //myth_control_acquire_context (TRUE); if ( io_channel == NULL ) { - ret = FALSE; + g_debug ("Monitor socket is NULL!\n"); + *ret = FALSE; goto clean_up; } gmyth_debug ("Listening on Monitor socket...!\n"); - - //condition = g_io_channel_get_buffer_condition( io_channel ); - myth_control_acquire_context (TRUE); - - //while ( !has_io_access ) - // g_cond_wait( io_watcher_cond, mutex ); - - //myth_control_acquire_context (TRUE); - - gsize len = 0; - if (condition & G_IO_HUP) { - gmyth_debug ("Read end of pipe died!\n"); - ret = FALSE; - goto clean_up; - } - - if ( ( condition & G_IO_IN ) != 0 ) { - io_status = g_io_channel_set_encoding( io_channel, NULL, &error ); - do - { - //trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE ); - - io_status = g_io_channel_read_chars( io_channel, trash + recv, - GMYTHTV_BUFFER_SIZE, &len, &error); - - gmyth_debug ( "[%s] Received data buffer from IO binary channel... %d bytes gone!\n", - __FUNCTION__, len ); - - recv += len; - - //msg = g_strconcat( msg, g_strdup(trash), NULL ); - - //if ( trash != NULL ) - // g_free( trash ); - - io_cond = g_io_channel_get_buffer_condition( io_channel ); - - } while ( ( io_cond & G_IO_IN ) != 0 && ( io_status != G_IO_STATUS_ERROR ) ); + while (TRUE) { + + condition = g_io_channel_get_buffer_condition( io_channel ); + + //myth_control_acquire_context (TRUE); + + //while ( !has_io_access ) + // g_cond_wait( io_watcher_cond, mutex ); + + //myth_control_acquire_context (TRUE); + + if (condition & G_IO_HUP) { + gmyth_debug ("Read end of pipe died!\n"); + *ret = FALSE; + goto clean_up; + } + + if ( ( condition & G_IO_IN ) != 0 ) { + io_status = g_io_channel_set_encoding( io_channel, NULL, &error ); + do + { + //trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE ); + + io_status = g_io_channel_read_chars( io_channel, trash + recv, + GMYTHTV_BUFFER_SIZE, &len, &error); + + gmyth_debug ( "[%s] Received data buffer from IO binary channel... %d bytes gone!\n", + __FUNCTION__, len ); + + recv += len; + + //msg = g_strconcat( msg, g_strdup(trash), NULL ); + + //if ( trash != NULL ) + // g_free( trash ); + + io_cond = g_io_channel_get_buffer_condition( io_channel ); + + } while ( ( io_cond & G_IO_IN ) != 0 && ( io_status != G_IO_STATUS_ERROR ) ); + } + + g_usleep( 300 ); + } //ret = g_io_channel_read_chars ( source, &msg, &len, NULL, &err); if ( io_status == G_IO_STATUS_ERROR ) { gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" ); - ret = FALSE; + *ret = FALSE; } gmyth_debug ("\n[%s]\tEVENT: Read %d bytes: %s\n\n", __FUNCTION__, len, trash != NULL ? trash : "[no event data]" ); //g_cond_signal( io_watcher_cond ); +clean_up: //myth_control_release_context( ); -clean_up: + return ret; } static gboolean -gmyth_connect_to_backend_monitor (GMythFileTransfer *transfer) +gmyth_connect_to_backend_monitor (GMythFileTransfer *transfer, GString *hostname ) { gboolean ret = TRUE; GString *base_str = g_string_new( "" ); - guint source_id = 0; + //guint source_id = 0; transfer->event_sock = gmyth_socket_new(); gmyth_socket_connect ( transfer->event_sock, transfer->hostname->str, transfer->port); - g_string_printf( base_str, "ANN Monitor %s %d", transfer->hostname->str, TRUE ); + g_string_printf( base_str, "ANN Monitor %s %d", hostname->str, TRUE ); gmyth_socket_send_command( transfer->event_sock, base_str ); GString *resp = gmyth_socket_receive_response( transfer->event_sock ); gmyth_debug ( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str ); - //g_thread_create( (GThreadFunc)myth_control_sock_listener, transfer->event_sock->sd_io_ch, TRUE, NULL ); + monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_listener, transfer->event_sock->sd_io_ch, FALSE, NULL ); + /* io_watcher_context = g_main_context_default(); - //GMainLoop *loop = g_main_loop_new( NULL, TRUE ); + GMainLoop *loop = g_main_loop_new( NULL, TRUE ); - //GSource *source; + GSource *source; if ( transfer->event_sock->sd_io_ch != NULL ) { - source_id = g_io_add_watch( transfer->event_sock->sd_io_ch, G_IO_IN, (GIOFunc)myth_control_sock_listener, NULL ); + source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN ); //transfer->event_sock->sd_io_ch } else { ret = FALSE; goto cleanup; } - //g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL ); + g_source_set_callback ( source, (GIOFunc)myth_control_sock_listener, NULL, NULL ); - //g_source_attach( source, io_watcher_context ); + g_source_attach( source, io_watcher_context ); + + */ /* if (source==NULL) { @@ -316,8 +330,10 @@ //g_main_loop_run( loop ); cleanup: - //if ( source != NULL ) - // g_source_unref( source ); + /* + if ( source != NULL ) + g_source_unref( source ); + */ gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n", __FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) ); @@ -386,7 +402,7 @@ return FALSE; } - gmyth_connect_to_backend_monitor( transfer ); + //gmyth_connect_to_backend_monitor( transfer, hostname ); if ( strlist != NULL ) g_object_unref( strlist ); @@ -500,7 +516,7 @@ { gboolean ret = TRUE; - guint max_iter = 50; + //guint max_iter = 50; //g_mutex_lock( mutex ); @@ -510,14 +526,16 @@ //has_io_access = FALSE; //myth_control_acquire_context (FALSE); - - g_mutex_lock( mutex ); - + + /* if ( do_wait ) { while ( --max_iter > 0 && !g_main_context_wait( io_watcher_context, io_watcher_cond, mutex ) ) ret = FALSE; } else if ( !g_main_context_acquire( io_watcher_context ) ) ret = FALSE; + */ + + //g_static_mutex_lock( &st_mutex ); return ret; @@ -528,17 +546,18 @@ { gboolean ret = TRUE; - - g_main_context_release( io_watcher_context ); + + //g_static_mutex_unlock( &st_mutex ); - g_mutex_unlock( mutex ); + //g_main_context_release( io_watcher_context ); + + //g_main_context_wakeup( io_watcher_context ); //has_io_access = TRUE; //g_cond_broadcast( io_watcher_cond ); - //g_mutex_unlock( mutex ); - + //g_mutex_unlock( mutex ); return ret; @@ -593,6 +612,8 @@ g_string_append_printf ( query, "%d", transfer->file_id ); gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str ); + myth_control_acquire_context( TRUE ); + while (total_read == 0) { strlist = gmyth_string_list_new(); @@ -631,6 +652,8 @@ } } } + + myth_control_release_context( ); g_object_unref( strlist ); g_string_free (query, TRUE);