[svn r338] Moved cleaning code from the _finalize methods in GObject, to the _dispose methods.
1.1 --- a/gmyth/src/gmyth_file_transfer.c Thu Feb 08 14:30:36 2007 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Thu Feb 08 14:32:29 2007 +0000
1.3 @@ -172,7 +172,7 @@
1.4
1.5 static void
1.6 gmyth_file_transfer_dispose (GObject *object)
1.7 -{
1.8 +{
1.9 GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (object);
1.10
1.11 if ( transfer->mutex != NULL )
1.12 @@ -192,8 +192,22 @@
1.13 g_object_unref( transfer->sock );
1.14 transfer->sock = NULL;
1.15 }
1.16 +
1.17 + if ( transfer->priv->livetv != NULL )
1.18 + {
1.19 + g_object_unref( transfer->priv->livetv );
1.20 + transfer->priv->livetv = NULL;
1.21 + }
1.22 +
1.23 + /*
1.24 + if ( transfer->priv != NULL )
1.25 + {
1.26 + g_object_unref( transfer->priv );
1.27 + transfer->priv = NULL;
1.28 + }
1.29 + */
1.30
1.31 - if ( transfer->filename != NULL )
1.32 + if ( transfer->filename != NULL )
1.33 {
1.34 g_free( transfer->filename );
1.35 transfer->filename = NULL;
2.1 --- a/gmyth/src/gmyth_livetv.c Thu Feb 08 14:30:36 2007 +0000
2.2 +++ b/gmyth/src/gmyth_livetv.c Thu Feb 08 14:32:29 2007 +0000
2.3 @@ -81,19 +81,9 @@
2.4
2.5 static void
2.6 gmyth_livetv_dispose (GObject *object)
2.7 -{
2.8 - G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
2.9 -}
2.10 -
2.11 -static void
2.12 -gmyth_livetv_finalize (GObject *object)
2.13 -{
2.14 - g_signal_handlers_destroy (object);
2.15 -
2.16 +{
2.17 GMythLiveTV *livetv = GMYTH_LIVETV (object);
2.18
2.19 - gmyth_debug ("Finalizing livetv");
2.20 -
2.21 if ( livetv->monitor != NULL ) {
2.22 g_object_unref (livetv->monitor);
2.23 livetv->monitor = NULL;
2.24 @@ -130,6 +120,15 @@
2.25 livetv->uri = NULL;
2.26 }
2.27
2.28 +
2.29 + G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
2.30 +}
2.31 +
2.32 +static void
2.33 +gmyth_livetv_finalize (GObject *object)
2.34 +{
2.35 + g_signal_handlers_destroy (object);
2.36 +
2.37 G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object );
2.38 }
2.39
3.1 --- a/gmyth/src/gmyth_monitor_handler.c Thu Feb 08 14:30:36 2007 +0000
3.2 +++ b/gmyth/src/gmyth_monitor_handler.c Thu Feb 08 14:32:29 2007 +0000
3.3 @@ -157,14 +157,15 @@
3.4 static void
3.5 gmyth_monitor_handler_dispose (GObject *object)
3.6 {
3.7 -
3.8 GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER (object);
3.9 -
3.10 +
3.11 + gmyth_monitor_handler_close(monitor);
3.12 +
3.13 monitor->allow_msgs_listener = FALSE;
3.14
3.15 if ( monitor->monitor_th != NULL )
3.16 {
3.17 - g_thread_pool_free( monitor->monitor_th, TRUE, TRUE );
3.18 + g_thread_pool_free( monitor->monitor_th, TRUE, FALSE );
3.19 //g_thread_exit( monitor->monitor_th );
3.20 /*if ( monitor->monitor_th != NULL )
3.21 g_object_unref( monitor->monitor_th );*/
3.22 @@ -173,7 +174,7 @@
3.23
3.24 if ( monitor->event_sock != NULL )
3.25 {
3.26 - /* g_object_unref( monitor->event_sock ); */
3.27 + g_object_unref( monitor->event_sock );
3.28 gmyth_socket_close_connection( monitor->event_sock );
3.29 monitor->event_sock = NULL;
3.30 }
3.31 @@ -274,6 +275,26 @@
3.32
3.33 }
3.34
3.35 +void
3.36 +gmyth_monitor_handler_close (GMythMonitorHandler *monitor)
3.37 +{
3.38 + monitor->allow_msgs_listener = FALSE;
3.39 +
3.40 + if ( monitor->monitor_th != NULL )
3.41 + {
3.42 + g_thread_pool_free( monitor->monitor_th, TRUE, FALSE );
3.43 + //g_thread_exit( monitor->monitor_th );
3.44 + /*if ( monitor->monitor_th != NULL )
3.45 + g_object_unref( monitor->monitor_th );*/
3.46 + monitor->monitor_th = NULL;
3.47 + }
3.48 +
3.49 + if ( monitor->event_sock != NULL )
3.50 + {
3.51 + gmyth_socket_close_connection( monitor->event_sock );
3.52 + }
3.53 +}
3.54 +
3.55 gboolean
3.56 gmyth_monitor_handler_open (GMythMonitorHandler *monitor, const gchar *hostname, gint port)
3.57 {
3.58 @@ -577,20 +598,3 @@
3.59
3.60 return *ret;
3.61 }
3.62 -
3.63 -void
3.64 -gmyth_monitor_handler_close( GMythMonitorHandler *monitor )
3.65 -{
3.66 -
3.67 - if (monitor->event_sock) {
3.68 - g_object_unref( monitor->event_sock );
3.69 - monitor->event_sock = NULL;
3.70 - }
3.71 -
3.72 - if (monitor->hostname) {
3.73 - g_free( monitor->hostname );
3.74 - monitor->hostname = NULL;
3.75 - }
3.76 -
3.77 -}
3.78 -
4.1 --- a/gmyth/src/gmyth_recorder.c Thu Feb 08 14:30:36 2007 +0000
4.2 +++ b/gmyth/src/gmyth_recorder.c Thu Feb 08 14:32:29 2007 +0000
4.3 @@ -68,7 +68,14 @@
4.4 static void
4.5 gmyth_recorder_dispose (GObject *object)
4.6 {
4.7 - // GMythRecorder *gmyth_remote_encoder = GMYTH_RECORDER(object);
4.8 + GMythRecorder *recorder = GMYTH_RECORDER(object);
4.9 +
4.10 + gmyth_recorder_close(recorder);
4.11 +
4.12 + if ( recorder->myth_socket != NULL ) {
4.13 + g_object_unref (recorder->myth_socket);
4.14 + recorder->myth_socket = NULL;
4.15 + }
4.16
4.17 G_OBJECT_CLASS (gmyth_recorder_parent_class)->dispose (object);
4.18 }
4.19 @@ -79,15 +86,14 @@
4.20 {
4.21 g_signal_handlers_destroy (object);
4.22
4.23 - GMythRecorder *recorder = GMYTH_RECORDER(object);
4.24 + G_OBJECT_CLASS (gmyth_recorder_parent_class)->finalize (object);
4.25 +}
4.26
4.27 - gmyth_debug ("[%s] Closing control socket", __FUNCTION__);
4.28 - /*gmyth_socket_close_connection(recorder->myth_socket);*/
4.29 -
4.30 - if ( recorder->myth_socket != NULL )
4.31 - g_object_unref (recorder->myth_socket);
4.32 -
4.33 - G_OBJECT_CLASS (gmyth_recorder_parent_class)->finalize (object);
4.34 +void
4.35 +gmyth_recorder_close (GMythRecorder *recorder)
4.36 +{
4.37 + if (recorder->myth_socket != NULL)
4.38 + gmyth_socket_close_connection(recorder->myth_socket);
4.39 }
4.40
4.41 /** Creates a new instance of GMythRecorder.
5.1 --- a/gmyth/src/gmyth_recorder.h Thu Feb 08 14:30:36 2007 +0000
5.2 +++ b/gmyth/src/gmyth_recorder.h Thu Feb 08 14:32:29 2007 +0000
5.3 @@ -94,6 +94,8 @@
5.4 GMythRecorder* gmyth_recorder_new (int num,
5.5 GString *hostname,
5.6 gshort port);
5.7 +
5.8 +void gmyth_recorder_close (GMythRecorder *recorder);
5.9
5.10 gboolean gmyth_recorder_setup (GMythRecorder *recorder);
5.11 gboolean gmyth_recorder_spawntv (GMythRecorder *recorder,
6.1 --- a/gmyth/src/gmyth_socket.c Thu Feb 08 14:30:36 2007 +0000
6.2 +++ b/gmyth/src/gmyth_socket.c Thu Feb 08 14:32:29 2007 +0000
6.3 @@ -71,6 +71,8 @@
6.4
6.5 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
6.6
6.7 +static GStaticRWLock rwlock = G_STATIC_RW_LOCK_INIT;
6.8 +
6.9 static gchar* local_hostname = NULL;
6.10
6.11 static void gmyth_socket_class_init (GMythSocketClass *klass);
6.12 @@ -338,8 +340,8 @@
6.13 /* disconnect socket */
6.14 gmyth_socket_close_connection (gmyth_socket);
6.15
6.16 - g_free (gmyth_socket->hostname);
6.17 - gmyth_socket->hostname = NULL;
6.18 + //g_free (gmyth_socket->hostname);
6.19 + //gmyth_socket->hostname = NULL;
6.20
6.21 g_free (local_hostname);
6.22
6.23 @@ -717,7 +719,7 @@
6.24 hostname = gmyth_socket_get_local_hostname();
6.25 if (hostname == NULL) {
6.26 g_debug ("Hostname not available, setting to n800frontend\n");
6.27 - hostname = g_strdup ("n800frontend");
6.28 + hostname = g_string_new ("n800frontend");
6.29 }
6.30
6.31 g_string_printf(base_str, "ANN %s %s %u",
6.32 @@ -794,14 +796,15 @@
6.33 void
6.34 gmyth_socket_close_connection (GMythSocket *gmyth_socket)
6.35 {
6.36 - if ( gmyth_socket->sd != -1 ) {
6.37 - close (gmyth_socket->sd);
6.38 - gmyth_socket->sd = -1;
6.39 - }
6.40 + //if ( gmyth_socket->sd != -1 ) {
6.41 + // close (gmyth_socket->sd);
6.42 + //gmyth_socket->sd = -1;
6.43 + //}
6.44
6.45 if (gmyth_socket->sd_io_ch != NULL) {
6.46 - g_io_channel_unref (gmyth_socket->sd_io_ch);
6.47 - gmyth_socket->sd_io_ch = NULL;
6.48 + g_io_channel_shutdown (gmyth_socket->sd_io_ch, TRUE, NULL);
6.49 + //g_io_channel_unref (gmyth_socket->sd_io_ch);
6.50 + //gmyth_socket->sd_io_ch = NULL;
6.51 }
6.52 }
6.53
6.54 @@ -916,20 +919,31 @@
6.55
6.56 gsize bytes_read = 0;
6.57 gint len = 0;
6.58 +
6.59 + if ( !( gmyth_socket != NULL) )
6.60 + return NULL;
6.61 +
6.62 GIOCondition io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch);
6.63
6.64 - g_return_val_if_fail( gmyth_socket != NULL, NULL );
6.65 -
6.66 /* verify if the input (read) buffer is ready to receive data */
6.67
6.68 - //g_static_mutex_lock( &mutex );
6.69 -
6.70 + g_static_mutex_lock( &mutex );
6.71 + //g_static_rw_lock_reader_lock (&rwlock);
6.72 +
6.73 //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE);
6.74 buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' ');
6.75 + if ( NULL == gmyth_socket->sd_io_ch )
6.76 + {
6.77 + gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port );
6.78 + }
6.79 +
6.80 io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error);
6.81
6.82 /* verify if the input (read) buffer is ready to receive data */
6.83 io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch);
6.84 +
6.85 + //if ( ( io_cond & G_IO_IN ) == 0 )
6.86 + // return NULL;
6.87
6.88 gmyth_debug ( "[%s] Bytes read = %d\n", __FUNCTION__, bytes_read );
6.89
6.90 @@ -943,7 +957,7 @@
6.91 /* verify if the input (read) buffer is ready to receive data */
6.92 io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
6.93
6.94 - //if ( ( io_cond & G_IO_IN ) != 0 ) {
6.95 + if ( ( io_cond & G_IO_IN ) != 0 ) {
6.96 //gchar *buffer_aux = NULL;
6.97
6.98 /* removes trailing whitespace */
6.99 @@ -965,12 +979,15 @@
6.100 buffer = g_new0 (gchar, len+1);
6.101
6.102 bytes_read = 0;
6.103 + if ( !( gmyth_socket != NULL && gmyth_socket->sd_io_ch != NULL) )
6.104 + return NULL;
6.105 io_status = g_io_channel_read_chars( gmyth_socket->sd_io_ch, buffer, len, &bytes_read, &error);
6.106 buffer[bytes_read] = '\0';
6.107 - //}
6.108 - }
6.109 + }
6.110 + }
6.111
6.112 - //g_static_mutex_unlock( &mutex );
6.113 + g_static_mutex_unlock( &mutex );
6.114 + //g_static_rw_lock_reader_unlock (&rwlock);
6.115
6.116 gmyth_debug ("Response received from backend: {%s}\n", buffer);
6.117
6.118 @@ -1004,6 +1021,7 @@
6.119 gchar *str_array = NULL;
6.120
6.121 g_static_mutex_lock( &mutex );
6.122 + //g_static_rw_lock_writer_lock (&rwlock);
6.123
6.124 ptr_array = g_ptr_array_sized_new (g_list_length(str_list->glist));
6.125
6.126 @@ -1021,6 +1039,7 @@
6.127 str_array = g_strjoinv (MYTH_SEPARATOR, (gchar **) (ptr_array->pdata));
6.128
6.129 g_static_mutex_unlock( &mutex );
6.130 + //g_static_rw_lock_writer_unlock (&rwlock);
6.131
6.132 gmyth_debug ( "[%s] Sending socket request: %s\n", __FUNCTION__, str_array );
6.133