[svn r204] Fixed problem with the MonitorHandler thread, removed from FileTransfer.
1.1 --- a/gmyth/src/gmyth_file_transfer.c Wed Dec 06 13:33:22 2006 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Wed Dec 06 13:50:55 2006 +0000
1.3 @@ -121,8 +121,6 @@
1.4 transfer->control_sock = NULL;
1.5 transfer->sock = NULL;
1.6
1.7 - transfer->monitor = NULL;
1.8 -
1.9 }
1.10
1.11 static void
1.12 @@ -141,19 +139,7 @@
1.13 g_object_unref( transfer->sock );
1.14 transfer->sock = NULL;
1.15 }
1.16 -
1.17 - if ( transfer->monitor != NULL )
1.18 - {
1.19 - g_object_unref( transfer->monitor );
1.20 - transfer->monitor = NULL;
1.21 - }
1.22 -
1.23 - if ( transfer->event_sock != NULL )
1.24 - {
1.25 - g_object_unref( transfer->event_sock );
1.26 - transfer->event_sock = NULL;
1.27 - }
1.28 -
1.29 +
1.30 if ( transfer->filename != NULL )
1.31 {
1.32 g_free( transfer->filename );
1.33 @@ -293,22 +279,6 @@
1.34 goto cleanup;
1.35 }
1.36
1.37 - transfer->monitor = gmyth_monitor_handler_new ( );
1.38 -
1.39 - ret = gmyth_monitor_handler_open (transfer->monitor, transfer->backend_info->hostname, transfer->backend_info->port );
1.40 -
1.41 - if ( ret == TRUE )
1.42 - {
1.43 - gmyth_debug("Connect MythTV Monitor event socket! Trying to start the message handler...");
1.44 -
1.45 - ret = gmyth_monitor_handler_start ( transfer->monitor );
1.46 -
1.47 - if (ret)
1.48 - gmyth_debug("MythTV Monitor event socket connected and listening!");
1.49 - else
1.50 - gmyth_debug("Problems when trying to start MythTV Monitor event socket!");
1.51 - }
1.52 -
1.53 cleanup:
1.54
1.55 if ( strlist != NULL )
1.56 @@ -378,11 +348,6 @@
1.57 transfer->control_sock = NULL;
1.58 }
1.59
1.60 - if ( transfer->monitor ) {
1.61 - g_object_unref( transfer->monitor );
1.62 - transfer->monitor = NULL;
1.63 - }
1.64 -
1.65 }
1.66
1.67 gint64
2.1 --- a/gmyth/src/gmyth_file_transfer.h Wed Dec 06 13:33:22 2006 +0000
2.2 +++ b/gmyth/src/gmyth_file_transfer.h Wed Dec 06 13:50:55 2006 +0000
2.3 @@ -37,7 +37,6 @@
2.4 #include "gmyth_uri.h"
2.5 #include "gmyth_livetv.h"
2.6 #include "gmyth_backendinfo.h"
2.7 -#include "gmyth_monitor_handler.h"
2.8
2.9 #include <stdio.h>
2.10 #include <stdlib.h>
2.11 @@ -81,10 +80,7 @@
2.12
2.13 /* socket descriptors */
2.14 GMythSocket *control_sock;
2.15 - GMythSocket *event_sock;
2.16 GMythSocket *sock;
2.17 -
2.18 - GMythMonitorHandler *monitor;
2.19
2.20 gint64 readposition;
2.21 guint64 filesize;
3.1 --- a/gmyth/src/gmyth_livetv.c Wed Dec 06 13:33:22 2006 +0000
3.2 +++ b/gmyth/src/gmyth_livetv.c Wed Dec 06 13:50:55 2006 +0000
3.3 @@ -129,6 +129,27 @@
3.4 }
3.5
3.6 livetv->is_livetv = TRUE;
3.7 +
3.8 + livetv->monitor = gmyth_monitor_handler_new ( );
3.9 +
3.10 + res = gmyth_monitor_handler_open (livetv->monitor, backend_info->hostname, backend_info->port );
3.11 +
3.12 + if ( res == TRUE )
3.13 + {
3.14 + gmyth_debug("Connect MythTV Monitor event socket! Trying to start the message handler...");
3.15 +
3.16 + res = gmyth_monitor_handler_start ( livetv->monitor );
3.17 +
3.18 + if (res)
3.19 + {
3.20 + gmyth_debug("MythTV Monitor event socket connected and listening!");
3.21 + }
3.22 + else
3.23 + {
3.24 + gmyth_debug("Problems when trying to start MythTV Monitor event socket!");
3.25 + goto error;
3.26 + }
3.27 + }
3.28
3.29 hostname = gmyth_backend_info_get_hostname(backend_info);
3.30 livetv->backend_hostname = g_string_new (hostname);
4.1 --- a/gmyth/src/gmyth_livetv.h Wed Dec 06 13:33:22 2006 +0000
4.2 +++ b/gmyth/src/gmyth_livetv.h Wed Dec 06 13:50:55 2006 +0000
4.3 @@ -34,6 +34,7 @@
4.4 #include "gmyth_tvchain.h"
4.5 #include "gmyth_common.h"
4.6 #include "gmyth_backendinfo.h"
4.7 +#include "gmyth_monitor_handler.h"
4.8
4.9 #include "gmyth_file_transfer.h"
4.10
4.11 @@ -68,6 +69,8 @@
4.12 GMythRecorder *recorder;
4.13 GMythTVChain *tvchain;
4.14 GMythProgramInfo *proginfo;
4.15 +
4.16 + GMythMonitorHandler *monitor;
4.17
4.18 gboolean is_livetv;
4.19
5.1 --- a/gmyth/src/gmyth_monitor_handler.c Wed Dec 06 13:33:22 2006 +0000
5.2 +++ b/gmyth/src/gmyth_monitor_handler.c Wed Dec 06 13:50:55 2006 +0000
5.3 @@ -108,11 +108,26 @@
5.4 gmyth_monitor_handler_class_init (GMythMonitorHandlerClass *klass)
5.5 {
5.6 GObjectClass *gobject_class;
5.7 + GMythMonitorHandlerClass *gmonitor_class;
5.8
5.9 gobject_class = (GObjectClass *) klass;
5.10 + gmonitor_class = (GMythMonitorHandlerClass *) gobject_class;
5.11
5.12 gobject_class->dispose = gmyth_monitor_handler_dispose;
5.13 gobject_class->finalize = gmyth_monitor_handler_finalize;
5.14 +
5.15 + gmonitor_class->backend_events_handler_signal_id =
5.16 + g_signal_newv ("backend-events-handler",
5.17 + G_TYPE_FROM_CLASS (gmonitor_class),
5.18 + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
5.19 + NULL /* class closure */,
5.20 + NULL /* accumulator */,
5.21 + NULL /* accu_data */,
5.22 + g_cclosure_marshal_VOID__VOID,
5.23 + G_TYPE_NONE /* return_type */,
5.24 + 0 /* n_params */,
5.25 + NULL /* param_types */);
5.26 +
5.27 }
5.28
5.29 static void
5.30 @@ -253,7 +268,7 @@
5.31 static guint count = 0;
5.32
5.33 GIOChannel *io_channel = gmyth_socket->sd_io_ch;
5.34 - GIOCondition condition = g_io_channel_get_buffer_condition( io_channel );
5.35 + //GIOCondition condition = g_io_channel_get_buffer_condition( io_channel );
5.36
5.37 GMythStringList *strlist = NULL;
5.38
5.39 @@ -271,50 +286,7 @@
5.40 ++count;
5.41
5.42 gmyth_debug ("%d - Listening on Monitor socket...!\n", count);
5.43 - /*
5.44 - condition = g_io_channel_get_buffer_condition( io_channel );
5.45 - //while ( !has_io_access )
5.46 - // g_cond_wait( io_watcher_cond, mutex );
5.47 -
5.48 - //myth_control_acquire_context (TRUE);
5.49 -
5.50 - if (condition & G_IO_HUP) {
5.51 - gmyth_debug ("Read end of pipe died!\n");
5.52 - ret = FALSE;
5.53 - //goto clean_up;
5.54 - }
5.55 -
5.56 - //if ( ( condition & G_IO_IN ) != 0 ) {
5.57 - byte_array = g_byte_array_new();
5.58 - io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
5.59 - guint buffer_size = GMYTHTV_BUFFER_SIZE;
5.60 - do
5.61 - {
5.62 - trash = g_new0( gchar, buffer_size );
5.63
5.64 - io_status = g_io_channel_read_chars( io_channel, trash,
5.65 - buffer_size, &len, &error);
5.66 -
5.67 - gmyth_debug ( "[%s] Received data buffer from IO binary channel... %d bytes gone!\n",
5.68 - __FUNCTION__, len );
5.69 -
5.70 - recv += len;
5.71 -
5.72 - byte_array = g_byte_array_append( byte_array, (const guint8*)trash, len );
5.73 -
5.74 - if ( trash != NULL )
5.75 - g_free( trash );
5.76 -
5.77 - io_cond = g_io_channel_get_buffer_condition( io_channel );
5.78 -
5.79 - } while ( ( io_cond & G_IO_IN ) != 0 );
5.80 -
5.81 - gmyth_debug ("\n\n\n[%s]\tEVENT: Read %d bytes: %s\n\n\n", __FUNCTION__, recv, byte_array != NULL && byte_array->data != NULL ? (gchar*)byte_array->data : "[no event data]" );
5.82 -
5.83 - //}
5.84 - */
5.85 - //io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
5.86 -
5.87 guint buffer_size = GMYTHTV_BUFFER_SIZE;
5.88 do
5.89 {
5.90 @@ -350,15 +322,10 @@
5.91 gmyth_debug ("\n\n\n[%s]\tMONITOR EVENT: Read %d bytes: %s\n\n\n", __FUNCTION__, recv,
5.92 strlist != NULL && strlist->glist != NULL ?
5.93 gmyth_string_list_get_char_array( strlist, 0 ) : "[no event data]" );
5.94 -/*
5.95 - if ( byte_array != NULL ) {
5.96 - g_byte_array_free( byte_array, TRUE );
5.97 - byte_array = NULL;
5.98 - }
5.99 - */
5.100 +
5.101 g_usleep( 300 );
5.102
5.103 - }
5.104 + } /* main GThread while */
5.105
5.106 if ( io_status == G_IO_STATUS_ERROR ) {
5.107 //gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" );
5.108 @@ -377,14 +344,6 @@
5.109 if (strlist!=NULL)
5.110 g_object_unref( strlist );
5.111
5.112 -/*
5.113 - if ( byte_array != NULL ) {
5.114 - g_byte_array_free( byte_array, TRUE );
5.115 - byte_array = NULL;
5.116 - }
5.117 - */
5.118 - //return ret;
5.119 -
5.120 }
5.121
5.122 static gboolean
5.123 @@ -469,9 +428,9 @@
5.124 if (!g_thread_supported () ) g_thread_init (NULL);
5.125
5.126 monitor_th = g_thread_pool_new( (GFunc)gmyth_monitor_handler_listener,
5.127 - monitor->event_sock, 3, FALSE, NULL );
5.128 + monitor->event_sock, 3, TRUE, NULL );
5.129
5.130 - g_thread_pool_push( monitor_th, monitor->event_sock, NULL );
5.131 + //g_thread_pool_push( monitor_th, monitor->event_sock, NULL );
5.132
5.133 //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
5.134 if ( monitor_th != NULL )
6.1 --- a/gmyth/src/gmyth_monitor_handler.h Wed Dec 06 13:33:22 2006 +0000
6.2 +++ b/gmyth/src/gmyth_monitor_handler.h Wed Dec 06 13:50:55 2006 +0000
6.3 @@ -62,8 +62,11 @@
6.4 {
6.5 GObjectClass parent_class;
6.6
6.7 - /* callbacks */
6.8 - /* no one for now */
6.9 + /* callbacks */
6.10 + guint backend_events_handler_signal_id;
6.11 +
6.12 + /* signal default handlers */
6.13 + void (*backend_events_handler) (GMythMonitorHandler *self);
6.14 };
6.15
6.16 struct _GMythMonitorHandler