# HG changeset patch # User rosfran # Date 1170945149 0 # Node ID 3e34d1a2e4030d6b8b9946ce78a64b0c0a6b1537 # Parent aedcbbf818b7b611c2bf681b20185c3c3258990e [svn r338] Moved cleaning code from the _finalize methods in GObject, to the _dispose methods. diff -r aedcbbf818b7 -r 3e34d1a2e403 gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Thu Feb 08 14:30:36 2007 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Thu Feb 08 14:32:29 2007 +0000 @@ -172,7 +172,7 @@ static void gmyth_file_transfer_dispose (GObject *object) -{ +{ GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (object); if ( transfer->mutex != NULL ) @@ -192,8 +192,22 @@ g_object_unref( transfer->sock ); transfer->sock = NULL; } + + if ( transfer->priv->livetv != NULL ) + { + g_object_unref( transfer->priv->livetv ); + transfer->priv->livetv = NULL; + } + + /* + if ( transfer->priv != NULL ) + { + g_object_unref( transfer->priv ); + transfer->priv = NULL; + } + */ - if ( transfer->filename != NULL ) + if ( transfer->filename != NULL ) { g_free( transfer->filename ); transfer->filename = NULL; diff -r aedcbbf818b7 -r 3e34d1a2e403 gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Thu Feb 08 14:30:36 2007 +0000 +++ b/gmyth/src/gmyth_livetv.c Thu Feb 08 14:32:29 2007 +0000 @@ -81,19 +81,9 @@ static void gmyth_livetv_dispose (GObject *object) -{ - G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object); -} - -static void -gmyth_livetv_finalize (GObject *object) -{ - g_signal_handlers_destroy (object); - +{ GMythLiveTV *livetv = GMYTH_LIVETV (object); - gmyth_debug ("Finalizing livetv"); - if ( livetv->monitor != NULL ) { g_object_unref (livetv->monitor); livetv->monitor = NULL; @@ -130,6 +120,15 @@ livetv->uri = NULL; } + + G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object); +} + +static void +gmyth_livetv_finalize (GObject *object) +{ + g_signal_handlers_destroy (object); + G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object ); } diff -r aedcbbf818b7 -r 3e34d1a2e403 gmyth/src/gmyth_monitor_handler.c --- a/gmyth/src/gmyth_monitor_handler.c Thu Feb 08 14:30:36 2007 +0000 +++ b/gmyth/src/gmyth_monitor_handler.c Thu Feb 08 14:32:29 2007 +0000 @@ -157,14 +157,15 @@ static void gmyth_monitor_handler_dispose (GObject *object) { - GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER (object); - + + gmyth_monitor_handler_close(monitor); + monitor->allow_msgs_listener = FALSE; if ( monitor->monitor_th != NULL ) { - g_thread_pool_free( monitor->monitor_th, TRUE, TRUE ); + g_thread_pool_free( monitor->monitor_th, TRUE, FALSE ); //g_thread_exit( monitor->monitor_th ); /*if ( monitor->monitor_th != NULL ) g_object_unref( monitor->monitor_th );*/ @@ -173,7 +174,7 @@ if ( monitor->event_sock != NULL ) { - /* g_object_unref( monitor->event_sock ); */ + g_object_unref( monitor->event_sock ); gmyth_socket_close_connection( monitor->event_sock ); monitor->event_sock = NULL; } @@ -274,6 +275,26 @@ } +void +gmyth_monitor_handler_close (GMythMonitorHandler *monitor) +{ + monitor->allow_msgs_listener = FALSE; + + if ( monitor->monitor_th != NULL ) + { + g_thread_pool_free( monitor->monitor_th, TRUE, FALSE ); + //g_thread_exit( monitor->monitor_th ); + /*if ( monitor->monitor_th != NULL ) + g_object_unref( monitor->monitor_th );*/ + monitor->monitor_th = NULL; + } + + if ( monitor->event_sock != NULL ) + { + gmyth_socket_close_connection( monitor->event_sock ); + } +} + gboolean gmyth_monitor_handler_open (GMythMonitorHandler *monitor, const gchar *hostname, gint port) { @@ -577,20 +598,3 @@ return *ret; } - -void -gmyth_monitor_handler_close( GMythMonitorHandler *monitor ) -{ - - if (monitor->event_sock) { - g_object_unref( monitor->event_sock ); - monitor->event_sock = NULL; - } - - if (monitor->hostname) { - g_free( monitor->hostname ); - monitor->hostname = NULL; - } - -} - diff -r aedcbbf818b7 -r 3e34d1a2e403 gmyth/src/gmyth_recorder.c --- a/gmyth/src/gmyth_recorder.c Thu Feb 08 14:30:36 2007 +0000 +++ b/gmyth/src/gmyth_recorder.c Thu Feb 08 14:32:29 2007 +0000 @@ -68,7 +68,14 @@ static void gmyth_recorder_dispose (GObject *object) { - // GMythRecorder *gmyth_remote_encoder = GMYTH_RECORDER(object); + GMythRecorder *recorder = GMYTH_RECORDER(object); + + gmyth_recorder_close(recorder); + + if ( recorder->myth_socket != NULL ) { + g_object_unref (recorder->myth_socket); + recorder->myth_socket = NULL; + } G_OBJECT_CLASS (gmyth_recorder_parent_class)->dispose (object); } @@ -79,15 +86,14 @@ { g_signal_handlers_destroy (object); - GMythRecorder *recorder = GMYTH_RECORDER(object); + G_OBJECT_CLASS (gmyth_recorder_parent_class)->finalize (object); +} - gmyth_debug ("[%s] Closing control socket", __FUNCTION__); - /*gmyth_socket_close_connection(recorder->myth_socket);*/ - - if ( recorder->myth_socket != NULL ) - g_object_unref (recorder->myth_socket); - - G_OBJECT_CLASS (gmyth_recorder_parent_class)->finalize (object); +void +gmyth_recorder_close (GMythRecorder *recorder) +{ + if (recorder->myth_socket != NULL) + gmyth_socket_close_connection(recorder->myth_socket); } /** Creates a new instance of GMythRecorder. diff -r aedcbbf818b7 -r 3e34d1a2e403 gmyth/src/gmyth_recorder.h --- a/gmyth/src/gmyth_recorder.h Thu Feb 08 14:30:36 2007 +0000 +++ b/gmyth/src/gmyth_recorder.h Thu Feb 08 14:32:29 2007 +0000 @@ -94,6 +94,8 @@ GMythRecorder* gmyth_recorder_new (int num, GString *hostname, gshort port); + +void gmyth_recorder_close (GMythRecorder *recorder); gboolean gmyth_recorder_setup (GMythRecorder *recorder); gboolean gmyth_recorder_spawntv (GMythRecorder *recorder, diff -r aedcbbf818b7 -r 3e34d1a2e403 gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Thu Feb 08 14:30:36 2007 +0000 +++ b/gmyth/src/gmyth_socket.c Thu Feb 08 14:32:29 2007 +0000 @@ -71,6 +71,8 @@ static GStaticMutex mutex = G_STATIC_MUTEX_INIT; +static GStaticRWLock rwlock = G_STATIC_RW_LOCK_INIT; + static gchar* local_hostname = NULL; static void gmyth_socket_class_init (GMythSocketClass *klass); @@ -338,8 +340,8 @@ /* disconnect socket */ gmyth_socket_close_connection (gmyth_socket); - g_free (gmyth_socket->hostname); - gmyth_socket->hostname = NULL; + //g_free (gmyth_socket->hostname); + //gmyth_socket->hostname = NULL; g_free (local_hostname); @@ -717,7 +719,7 @@ hostname = gmyth_socket_get_local_hostname(); if (hostname == NULL) { g_debug ("Hostname not available, setting to n800frontend\n"); - hostname = g_strdup ("n800frontend"); + hostname = g_string_new ("n800frontend"); } g_string_printf(base_str, "ANN %s %s %u", @@ -794,14 +796,15 @@ void gmyth_socket_close_connection (GMythSocket *gmyth_socket) { - if ( gmyth_socket->sd != -1 ) { - close (gmyth_socket->sd); - gmyth_socket->sd = -1; - } + //if ( gmyth_socket->sd != -1 ) { + // close (gmyth_socket->sd); + //gmyth_socket->sd = -1; + //} if (gmyth_socket->sd_io_ch != NULL) { - g_io_channel_unref (gmyth_socket->sd_io_ch); - gmyth_socket->sd_io_ch = NULL; + g_io_channel_shutdown (gmyth_socket->sd_io_ch, TRUE, NULL); + //g_io_channel_unref (gmyth_socket->sd_io_ch); + //gmyth_socket->sd_io_ch = NULL; } } @@ -916,20 +919,31 @@ gsize bytes_read = 0; gint len = 0; + + if ( !( gmyth_socket != NULL) ) + return NULL; + GIOCondition io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch); - g_return_val_if_fail( gmyth_socket != NULL, NULL ); - /* verify if the input (read) buffer is ready to receive data */ - //g_static_mutex_lock( &mutex ); - + g_static_mutex_lock( &mutex ); + //g_static_rw_lock_reader_lock (&rwlock); + //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE); buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' '); + if ( NULL == gmyth_socket->sd_io_ch ) + { + gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port ); + } + io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error); /* verify if the input (read) buffer is ready to receive data */ io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch); + + //if ( ( io_cond & G_IO_IN ) == 0 ) + // return NULL; gmyth_debug ( "[%s] Bytes read = %d\n", __FUNCTION__, bytes_read ); @@ -943,7 +957,7 @@ /* verify if the input (read) buffer is ready to receive data */ io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch ); - //if ( ( io_cond & G_IO_IN ) != 0 ) { + if ( ( io_cond & G_IO_IN ) != 0 ) { //gchar *buffer_aux = NULL; /* removes trailing whitespace */ @@ -965,12 +979,15 @@ buffer = g_new0 (gchar, len+1); bytes_read = 0; + if ( !( gmyth_socket != NULL && gmyth_socket->sd_io_ch != NULL) ) + return NULL; io_status = g_io_channel_read_chars( gmyth_socket->sd_io_ch, buffer, len, &bytes_read, &error); buffer[bytes_read] = '\0'; - //} - } + } + } - //g_static_mutex_unlock( &mutex ); + g_static_mutex_unlock( &mutex ); + //g_static_rw_lock_reader_unlock (&rwlock); gmyth_debug ("Response received from backend: {%s}\n", buffer); @@ -1004,6 +1021,7 @@ gchar *str_array = NULL; g_static_mutex_lock( &mutex ); + //g_static_rw_lock_writer_lock (&rwlock); ptr_array = g_ptr_array_sized_new (g_list_length(str_list->glist)); @@ -1021,6 +1039,7 @@ str_array = g_strjoinv (MYTH_SEPARATOR, (gchar **) (ptr_array->pdata)); g_static_mutex_unlock( &mutex ); + //g_static_rw_lock_writer_unlock (&rwlock); gmyth_debug ( "[%s] Sending socket request: %s\n", __FUNCTION__, str_array );