# HG changeset patch
# User rosfran
# Date 1165947575 0
# Node ID 001205bb0f408996c8da3f833274b6eb733cc0bf
# Parent  633c6c9784d3f21b917573501ca04770ea6d6504
[svn r217] Added signals to program changed messages coming from backend (MythTV).

diff -r 633c6c9784d3 -r 001205bb0f40 gmyth/src/gmyth_file_transfer.c
--- a/gmyth/src/gmyth_file_transfer.c	Tue Dec 12 18:18:36 2006 +0000
+++ b/gmyth/src/gmyth_file_transfer.c	Tue Dec 12 18:19:35 2006 +0000
@@ -36,7 +36,14 @@
 #endif
 
 #include "gmyth_file_transfer.h"
- 
+#include "gmyth_livetv.h"
+#include "gmyth_util.h"
+#include "gmyth_socket.h"
+#include "gmyth_stringlist.h"
+#include "gmyth_debug.h"
+#include "gmyth_uri.h"
+#include "gmyth_marshal.h"
+
 #include <unistd.h>
 #include <glib.h>
 
@@ -48,12 +55,6 @@
 #include <stdlib.h>
 #include <assert.h>
 
-#include "gmyth_livetv.h"
-#include "gmyth_util.h"
-#include "gmyth_socket.h"
-#include "gmyth_stringlist.h"
-#include "gmyth_debug.h"
-
 #define GMYTHTV_QUERY_HEADER		"QUERY_FILETRANSFER "
 
 /* default values to the file transfer parameters */
@@ -85,7 +86,15 @@
   GMYTH_RINGBUFFER_TYPE
 };
 
-//static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT;
+#define GMYTH_FILE_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferPrivate))
+
+struct _GMythFileTransferPrivate {
+	
+	GMythLiveTV *livetv;
+	
+	gboolean do_next_program_chain;
+	
+};
 
 static void gmyth_file_transfer_class_init          (GMythFileTransferClass *klass);
 static void gmyth_file_transfer_init                (GMythFileTransfer *object);
@@ -93,6 +102,9 @@
 static void gmyth_file_transfer_dispose  (GObject *object);
 static void gmyth_file_transfer_finalize (GObject *object);
 
+static void gmyth_file_transfer_program_info_changed( GMythFileTransfer *transfer, 
+										gint msg_code, gpointer livetv_transfer );
+
 static gboolean gmyth_connect_to_backend (GMythFileTransfer *transfer);
 
 void gmyth_file_transfer_close( GMythFileTransfer *transfer );
@@ -107,11 +119,31 @@
 gmyth_file_transfer_class_init (GMythFileTransferClass *klass)
 {
   GObjectClass *gobject_class;
+  GMythFileTransferClass *gtransfer_class;
 
   gobject_class = (GObjectClass *) klass;
+  gtransfer_class = (GMythFileTransferClass *) gobject_class;
 
   gobject_class->dispose  = gmyth_file_transfer_dispose;
   gobject_class->finalize = gmyth_file_transfer_finalize;
+  
+  g_type_class_add_private (gobject_class, sizeof (GMythFileTransferPrivate));
+  
+	gtransfer_class->program_info_changed_handler_signal_id = 
+		  g_signal_new ("program-info-changed",
+		                 G_TYPE_FROM_CLASS (gtransfer_class),
+		                 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+		                 0,
+										 NULL,
+										 NULL,
+										 gmyth_marshal_VOID__INT_POINTER,
+										 G_TYPE_NONE,
+										 2,
+										 G_TYPE_INT,
+										 G_TYPE_POINTER);
+										 
+	gtransfer_class->program_info_changed_handler = gmyth_file_transfer_program_info_changed; 
+
 }
 
 static void
@@ -121,6 +153,11 @@
 
   transfer->readposition = 0;
   transfer->filesize = GMYTHTV_FILE_SIZE;
+  
+  transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);	
+  
+  transfer->priv->do_next_program_chain = FALSE;
+  transfer->priv->livetv = NULL;
 
   transfer->control_sock = NULL;
   transfer->sock = NULL;
@@ -514,7 +551,8 @@
 	    bytes_sent = gmyth_string_list_get_int( strlist,  0 ); // -1 on backend error
 	    gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
 
-      	if ( bytes_sent != 0 ) {
+      	if ( bytes_sent != 0 ) 
+      	{
             gchar *data_buffer = g_new0 (gchar, bytes_sent);    
      	    while ( 0 != bytes_sent) { 
                 io_status = g_io_channel_read_chars( io_channel, data_buffer + total_read, 
@@ -550,12 +588,59 @@
     g_error_free (error);
   }
   
-  if ( total_read >= 0 )
+  if ( total_read > 0 )
   	transfer->readposition += total_read;
+  else
+  {
+		transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
+		
+		if ( transfer->priv != NULL && transfer->priv->livetv != NULL )
+		{
+		
+			total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN;	
+		
+	  	if ( max_tries <= 0 && transfer->priv->do_next_program_chain )
+	  	{
+	  		
+				if ( !gmyth_livetv_next_program_chain( transfer->priv->livetv ) )
+				{
+					gmyth_debug( "Cannot change to the next program chain!" );
+				}
+				else
+				{
+					gmyth_debug( "OK!!! MOVED to the next program chain [%s]!", 
+											(gmyth_tvchain_get_id( transfer->priv->livetv->tvchain ))->str );
+				}
+	  	}
+	  	
+		} /* if */
+		
+  } /* if */
   	
   return total_read;
 }
 
+static void 
+gmyth_file_transfer_program_info_changed( GMythFileTransfer *transfer, 
+										gint msg_code, gpointer livetv_transfer )
+{
+	GMythLiveTV *livetv = (GMythLiveTV*)livetv_transfer;
+	
+	gmyth_debug( "Program info changed! ( file transfer orig. = %p, ptr. = %p )", transfer, livetv_transfer );
+	
+	if ( transfer == livetv->file_transfer )
+	{
+		gmyth_debug( "YES, the requested program info movement on the LiveTV transfer is authentical!" );
+	}
+	
+	transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);	
+	
+	transfer->priv->livetv = livetv;	
+	transfer->priv->do_next_program_chain = TRUE;
+	
+	//g_object_unref( transfer );
+}
+
 gboolean 
 gmyth_file_transfer_settimeout( GMythFileTransfer *transfer, gboolean fast )
 {
diff -r 633c6c9784d3 -r 001205bb0f40 gmyth/src/gmyth_file_transfer.h
--- a/gmyth/src/gmyth_file_transfer.h	Tue Dec 12 18:18:36 2006 +0000
+++ b/gmyth/src/gmyth_file_transfer.h	Tue Dec 12 18:19:35 2006 +0000
@@ -35,7 +35,6 @@
 
 #include "gmyth_socket.h"
 #include "gmyth_uri.h"
-#include "gmyth_livetv.h"
 #include "gmyth_backendinfo.h"
 
 #include <stdio.h>
@@ -54,43 +53,52 @@
 #define IS_GMYTH_FILE_TRANSFER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TRANSFER_TYPE))
 #define GMYTH_FILE_TRANSFER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass))
 
-#define GMYTHTV_FILE_TRANSFER_READ_ERROR	-314
+#define GMYTHTV_FILE_TRANSFER_READ_ERROR					-314
+#define GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN			-315
 
 typedef struct _GMythFileTransfer         GMythFileTransfer;
 typedef struct _GMythFileTransferClass    GMythFileTransferClass;
+typedef struct _GMythFileTransferPrivate  GMythFileTransferPrivate;
 
 struct _GMythFileTransferClass
 {
 	GObjectClass parent_class;
 
 	/* callbacks */
-	/* no one for now */
+	guint program_info_changed_handler_signal_id;
+
+  /* signal default handlers */
+  void (*program_info_changed_handler) ( GMythFileTransfer *transfer, 
+										gint msg_code, gpointer livetv_transfer );
 };
 
 struct _GMythFileTransfer
 {
-	GObject parent;
-
+	GObject 					parent;
+	
 	/* Myth URI structure */
-	gchar* filename;
+	gchar 					 *filename;
 	GMythBackendInfo *backend_info;
 	
 	/* MythTV version number */	
-	gint mythtv_version;
+	gint 							mythtv_version;
 
 	/* socket descriptors */
-	GMythSocket *control_sock;
-	GMythSocket *sock;
+	GMythSocket 			*control_sock;
+	GMythSocket 			*sock;
 
-	gint64 readposition;
-	guint64 filesize;
-	gint file_id;
+	gint64 						readposition;
+	guint64 					filesize;
+	gint 							file_id;
+	
+	GMythFileTransferPrivate 	*priv;
+
 };
 
-GType          		gmyth_file_transfer_get_type        (void);
+GType          			gmyth_file_transfer_get_type        (void);
 GMythFileTransfer  *gmyth_file_transfer_new             (const GMythBackendInfo *backend_info);
-gboolean 			gmyth_file_transfer_open            (GMythFileTransfer *transfer, 
-                                					     const gchar* filename);
+gboolean 						gmyth_file_transfer_open            (GMythFileTransfer *transfer, 
+                                					     						const gchar* filename);
 void                gmyth_file_transfer_close           (GMythFileTransfer *transfer);
 gboolean            gmyth_file_transfer_is_open         (GMythFileTransfer *transfer);
 gint                gmyth_file_transfer_read            (GMythFileTransfer *transfer, 
diff -r 633c6c9784d3 -r 001205bb0f40 gmyth/src/gmyth_livetv.c
--- a/gmyth/src/gmyth_livetv.c	Tue Dec 12 18:18:36 2006 +0000
+++ b/gmyth/src/gmyth_livetv.c	Tue Dec 12 18:19:35 2006 +0000
@@ -31,12 +31,17 @@
 
 #include "gmyth_livetv.h"
  
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "gmyth_remote_util.h"
 #include "gmyth_tvchain.h"
 #include "gmyth_socket.h"
 #include "gmyth_debug.h"
 
 #include "gmyth_file_transfer.h"
+#include "gmyth_monitor_handler.h"
 
 static void gmyth_livetv_class_init          (GMythLiveTVClass *klass);
 static void gmyth_livetv_init                (GMythLiveTV *object);
@@ -65,9 +70,10 @@
 static void
 gmyth_livetv_init (GMythLiveTV *livetv)
 {
-	livetv->backend_hostname = NULL;
-	livetv->backend_port = 0;
+	livetv->backend_info = NULL;
 	livetv->local_hostname = NULL;
+	livetv->file_transfer = NULL;
+	livetv->setup_done = FALSE;
 
 	livetv->recorder = NULL;
 	livetv->tvchain = NULL;
@@ -90,6 +96,11 @@
 
 	gmyth_debug ("[%s] Finalizing livetv", __FUNCTION__);
 
+	if ( livetv->monitor != NULL ) {
+		g_object_unref (livetv->monitor);
+		livetv->monitor = NULL;
+	}
+
 	if ( livetv->recorder != NULL ) {
 		g_object_unref (livetv->recorder);
 		livetv->recorder = NULL;
@@ -104,6 +115,16 @@
 		g_object_unref (livetv->proginfo);
 		livetv->proginfo = NULL;
 	}
+	
+	if ( livetv->file_transfer != NULL ) {
+		g_object_unref (livetv->file_transfer);
+		livetv->file_transfer = NULL;
+	}
+	
+	if ( livetv->backend_info != NULL ) {
+		g_object_unref (livetv->backend_info);
+		livetv->backend_info = NULL;
+	}
 
 	G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object );
 }
@@ -118,22 +139,58 @@
 
 static void
 gmyth_livetv_monitor_signal_handler( GMythMonitorHandler *monitor, gint msg_code, 
-							gchar* message )
+							gchar* message, gpointer livetv )
 {
+	GMythLiveTV *live_tv = (GMythLiveTV*) livetv;
+	
 	gmyth_debug( "LIVETV Signal handler ( msg = %s, code = %d )\n", message, msg_code );
+	
+	if ( NULL == live_tv )
+		return;		
+	
+	switch ( msg_code ) 
+	{
+		
+		case GMYTH_BACKEND_PROGRAM_INFO_CHANGED:
+		{
+			gmyth_debug( "LIVETV Program Changed event received [ msg = %s ]\n", message );
+			/*
+			if ( !gmyth_livetv_next_program_chain( live_tv ) )
+			{
+				gmyth_debug( "Cannot change to the next program chain!" );
+			}
+			else
+			{
+			*/
+			gmyth_debug( "OK!!! MOVED to the next program chain [%s]!", 
+									(gmyth_tvchain_get_id( live_tv->tvchain ))->str );
+			/* advertises the FileTransfer about the program info changed */
+			g_signal_emit ( live_tv->file_transfer,
+             GMYTH_FILE_TRANSFER_GET_CLASS (live_tv->file_transfer)->program_info_changed_handler_signal_id,
+             0, /* details */
+             msg_code, live_tv );
+			/*}*/
+			break;
+		}
+		default:
+			break;
+		
+	}
+	
 }
 
 gboolean
 gmyth_livetv_setup ( GMythLiveTV *livetv, GMythBackendInfo *backend_info )
 {
 	gboolean res = TRUE;
-	char *hostname;
 
 	GMythSocket *socket = gmyth_socket_new ();
+	
+	livetv->backend_info = backend_info;
 
 	// FIME: Implement this at gmyth_socket
-	res = gmyth_socket_connect_to_backend (socket, backend_info->hostname,
-			backend_info->port, TRUE);
+	res = gmyth_socket_connect_to_backend (socket, livetv->backend_info->hostname,
+			livetv->backend_info->port, TRUE);
 	if (!res) {
 		g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);	
 		res = FALSE;
@@ -144,7 +201,8 @@
 	
   livetv->monitor = gmyth_monitor_handler_new ( );
   
-  res = gmyth_monitor_handler_open (livetv->monitor, backend_info->hostname, backend_info->port );
+  res = gmyth_monitor_handler_open (livetv->monitor, livetv->backend_info->hostname, 
+  				livetv->backend_info->port );
   
   if ( res == TRUE )
   {
@@ -157,7 +215,7 @@
   		gmyth_debug("MythTV Monitor event socket connected and listening!");
   		g_signal_connect (G_OBJECT (livetv->monitor), "backend-events-handler",
                   (GCallback)gmyth_livetv_monitor_signal_handler,
-                  NULL);
+                  livetv);
   	}
   	else
   	{
@@ -166,10 +224,6 @@
   	}
   }
 
-	hostname = gmyth_backend_info_get_hostname(backend_info);
-	livetv->backend_hostname = g_string_new (hostname);
-	livetv->backend_port = gmyth_backend_info_get_port (backend_info);
-
 	livetv->local_hostname  = gmyth_socket_get_local_hostname ( );
 
 	if ( livetv->local_hostname == NULL ) {
@@ -189,7 +243,7 @@
 
 	// Creates livetv chain handler
 	livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
-	gmyth_tvchain_initialize ( livetv->tvchain, backend_info );
+	gmyth_tvchain_initialize ( livetv->tvchain, livetv->backend_info );
 
 	if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) {
 		res = FALSE;
@@ -244,15 +298,13 @@
 	} else {
 		gmyth_debug ("[%s] GMythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ );
 	}
-
+	
+	livetv->setup_done = TRUE;
+	
 	return res;
 
 error:
 	g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
-	if ( livetv->backend_hostname != NULL ) {
-		g_string_free( livetv->backend_hostname, TRUE );
-		res = FALSE;
-	}
 
 	if ( livetv->local_hostname != NULL ) {
 		g_string_free( livetv->local_hostname, TRUE );
@@ -283,7 +335,14 @@
 {
 	gboolean res = TRUE;
 	
-	// Reload all TV chain from Mysql database.
+	if ( !livetv->setup_done )
+	{
+		gmyth_debug ( "Call the setup function first!" );
+		res= FALSE;
+		goto error;		
+	}
+	
+	/* Reload all TV chain from Mysql database. */
 	gmyth_tvchain_reload_all (livetv->tvchain);
 
 	if ( livetv->tvchain == NULL ) {
@@ -305,10 +364,6 @@
 
 error:
 	g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
-	if ( livetv->backend_hostname != NULL ) {
-		g_string_free( livetv->backend_hostname, TRUE );
-		res = FALSE;
-	}
 
 	if ( livetv->local_hostname != NULL ) {
 		g_string_free( livetv->local_hostname, TRUE );
@@ -334,7 +389,57 @@
 
 }
 
-// FIXME: How to proceed differently between livetv and recorded content
+GMythFileTransfer *
+gmyth_livetv_create_file_transfer( GMythLiveTV *livetv )
+{
+	GMythURI* uri = NULL;
+	
+	if ( NULL == livetv || NULL == livetv->proginfo )
+		goto done;
+	
+	if ( !livetv->setup_done )
+	{
+		gmyth_debug( "Error: You must do the LiveTV setup, just before generating the FileTransfer from LiveTV source!" );
+		goto done;
+	}	
+
+  gmyth_debug( "URI path = %s.\n", livetv->proginfo->pathname->str ); 
+
+	livetv->file_transfer = gmyth_file_transfer_new( livetv->backend_info );
+
+  if ( NULL == livetv->file_transfer ) 
+  {
+  	gmyth_debug( "Error: couldn't create the FileTransfer from LiveTV source!" );
+    goto done;
+  }
+  
+  uri = gmyth_uri_new_with_value( livetv->proginfo->pathname->str );
+  if ( NULL == uri )
+  {
+  	gmyth_debug( "Couldn't parse the URI to start LiveTV! [uri = %s]", livetv->proginfo->pathname->str );  	
+  }
+
+	if ( !gmyth_file_transfer_open( livetv->file_transfer, uri != NULL ? gmyth_uri_get_path(uri) : 
+				livetv->proginfo->pathname->str ) )
+	{
+		gmyth_debug( "Error: couldn't open the FileTransfer from LiveTV source!" );
+		g_object_unref( livetv->file_transfer );
+		livetv->file_transfer = NULL;
+		goto done;
+	}
+
+done:
+	if ( uri != NULL )
+	{
+		g_object_unref( uri );
+		uri = NULL;
+	}	
+	
+	return livetv->file_transfer;
+	
+}
+
+/* FIXME: How to proceed differently between livetv and recorded content */
 void
 gmyth_livetv_stop_playing (GMythLiveTV *livetv) 
 {
diff -r 633c6c9784d3 -r 001205bb0f40 gmyth/src/gmyth_livetv.h
--- a/gmyth/src/gmyth_livetv.h	Tue Dec 12 18:18:36 2006 +0000
+++ b/gmyth/src/gmyth_livetv.h	Tue Dec 12 18:19:35 2006 +0000
@@ -31,7 +31,12 @@
 #include <glib.h>
 #include <glib-object.h>
 
-#include "gmyth.h"
+#include "gmyth_recorder.h"
+#include "gmyth_tvchain.h"
+#include "gmyth_monitor_handler.h"
+#include "gmyth_file_transfer.h"
+#include "gmyth_programinfo.h"
+#include "gmyth_backendinfo.h"
 
 G_BEGIN_DECLS
 
@@ -54,36 +59,39 @@
 
 struct _GMythLiveTV
 {
-	GObject parent;
+	GObject 						parent;
+	
+	GString 				 		*local_hostname;
+	
+	GMythBackendInfo 		*backend_info;
 
-	// Backend connection related variables
-	GString *backend_hostname;
-	gint backend_port;
-	GString *local_hostname;
-
-	GMythRecorder *recorder;
-	GMythTVChain *tvchain;
-	GMythProgramInfo *proginfo;
+	GMythRecorder 	 		*recorder;
+	GMythTVChain 				*tvchain;
+	GMythProgramInfo 		*proginfo;
+	
+	GMythFileTransfer 	*file_transfer;
 	
 	GMythMonitorHandler *monitor;
 
-	gboolean is_livetv;
+	gboolean 						is_livetv;
+	gboolean 						setup_done;
 
 };
 
 GType          gmyth_livetv_get_type (void);
 
-GMythLiveTV* gmyth_livetv_new ();
+GMythLiveTV* 	 gmyth_livetv_new ();
 
 void gmyth_livetv_start_playing (GMythLiveTV *livetv);
 void gmyth_livetv_stop_playing (GMythLiveTV *livetv);
 
-gboolean gmyth_livetv_is_recording ( GMythLiveTV *livetv );
-	
+gboolean gmyth_livetv_is_recording ( GMythLiveTV *livetv );	
 
 gboolean gmyth_livetv_setup (GMythLiveTV *livetv, GMythBackendInfo *backend_info);
 gboolean gmyth_livetv_next_program_chain ( GMythLiveTV *livetv );
 
+GMythFileTransfer *gmyth_livetv_create_file_transfer( GMythLiveTV *livetv );
+
 G_END_DECLS
 
 #endif /*GMYTH_LIVETV_H_*/
diff -r 633c6c9784d3 -r 001205bb0f40 gmyth/src/gmyth_monitor_handler.c
--- a/gmyth/src/gmyth_monitor_handler.c	Tue Dec 12 18:18:36 2006 +0000
+++ b/gmyth/src/gmyth_monitor_handler.c	Tue Dec 12 18:19:35 2006 +0000
@@ -37,7 +37,6 @@
 
 #include <unistd.h>
 #include <glib.h>
-
 #include <arpa/inet.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -46,15 +45,11 @@
 #include <stdlib.h>
 #include <assert.h>
 
-#include "gmyth_uri.h"
-#include "gmyth_livetv.h"
-#include "gmyth_util.h"
-#include "gmyth_socket.h"
-#include "gmyth_stringlist.h"
-#include "gmyth_debug.h"
 #include "gmyth_marshal.h"
-// FIXME: this include cannot be in the first line
+
 #include "gmyth_monitor_handler.h"
+
+#include "gmyth.h"
  
 #define GMYTHTV_QUERY_HEADER		"QUERY_FILETRANSFER "
 
@@ -79,16 +74,13 @@
 
 GThreadPool *monitor_th = NULL;
 
-enum gmyth_monitor_handler_msg_types {
-	GMYTH_BACKEND_NO_MESSAGE = 0,
-  GMYTH_BACKEND_PROGRAM_INFO_CHANGED,
-  GMYTH_BACKEND_STOP_LIVETV
-};
-
 //static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
 //static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, 
 //				gpointer data );
 //static void myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret );
+static void
+gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message, 
+			gpointer live_tv );
 
 static void gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, 
 		gpointer user_data);
@@ -126,13 +118,16 @@
 		                 G_TYPE_FROM_CLASS (gmonitor_class),
 		                 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
 		                 0,
-				 NULL,
-				 NULL,
-				 gmyth_marshal_VOID__INT_STRING,
-				 G_TYPE_NONE,
-				 2,
-				 G_TYPE_INT,
-				 G_TYPE_STRING);
+										 NULL,
+										 NULL,
+										 gmyth_marshal_VOID__INT_STRING_POINTER,
+										 G_TYPE_NONE,
+										 3,
+										 G_TYPE_INT,
+										 G_TYPE_STRING,
+										 G_TYPE_POINTER);
+										 
+	gmonitor_class->backend_events_handler = gmyth_monitor_handler_default_listener;
 
 }
 
@@ -194,7 +189,6 @@
   if ( monitor_th != NULL )  
   {
   	g_thread_pool_free( monitor_th, TRUE, FALSE );
-  	//g_object_unref( monitor_th );
   	monitor_th = NULL;
   }
 
@@ -211,11 +205,11 @@
 
 // fixme: do we need the card_id????
 GMythMonitorHandler*
-gmyth_monitor_handler_new (void)
+gmyth_monitor_handler_new ( void )
 {
-  GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER ( g_object_new (
-				GMYTH_MONITOR_HANDLER_TYPE, FALSE ));
-
+  GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER ( g_object_new ( GMYTH_MONITOR_HANDLER_TYPE, 
+  					FALSE ) );
+				
   return monitor;
 }
 
@@ -252,53 +246,53 @@
 gmyth_monitor_handler_is_backend_message( GMythMonitorHandler *monitor,
                         GMythStringList* strlist, gchar **back_msg_action )
 {
-        gint msg_type = GMYTH_BACKEND_NO_MESSAGE;
-        GString *back_msg = NULL;
-
-        back_msg = gmyth_string_list_get_string( strlist, 0 );
-        if ( back_msg != NULL && back_msg->str != NULL &&
-                                        strstr( back_msg->str, "BACKEND" ) != NULL )
-        {
-	        if ( monitor->backend_msgs != NULL ) 
-	        {
-	        	*back_msg_action = gmyth_string_list_get_char_array( strlist, 1 );	        	
-	        	
-	        	if ( back_msg_action != NULL )
-	        	{	        	
-	        	
-		        	if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
-		        			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) ||
-		        			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
-		        	{		        	
-		        		msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
-		        	}  	
-		
-		          //g_hash_table_insert ( monitor->backend_msgs,
-		          //                       &(monitor->actual_index), *back_msg_action );
-		                                  
-	        	} // if
-	          
-	        } // if
-        }
-        
-        if ( back_msg != NULL )
-        {
-        	g_string_free( back_msg, TRUE );
-        	back_msg = NULL;        	
-        }
-
-        return msg_type;
+	gint msg_type = GMYTH_BACKEND_NO_MESSAGE;
+	GString *back_msg = NULL;
+	
+	back_msg = gmyth_string_list_get_string( strlist, 0 );
+	if ( back_msg != NULL && back_msg->str != NULL &&
+	                                strstr( back_msg->str, "BACKEND" ) != NULL )
+	{
+	  if ( monitor->backend_msgs != NULL )
+	  {
+	  	*back_msg_action = gmyth_string_list_get_char_array( strlist, 1 );	        	
+	  	
+	  	if ( back_msg_action != NULL )
+	  	{	        	
+	  	
+	    	if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
+	    			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) ||
+	    			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
+	    	{		        	
+	    		msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
+	    	}  	
+	
+	      //g_hash_table_insert ( monitor->backend_msgs,
+	      //                       &(monitor->actual_index), *back_msg_action );
+	                              
+	  	} // if
+	    
+	  } // if
+	}
+	
+	if ( back_msg != NULL )
+	{
+		g_string_free( back_msg, TRUE );
+		back_msg = NULL;        	
+	}
+	
+	return msg_type;
 
 }
 
-/*
 static void
-gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gpointer message )
+gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message,
+			gpointer live_tv )
 {
 	//assert( message!= NULL );  
-	gmyth_debug( "DEFAULT Signal handler ( msg = %s, code = %d )\n", (gchar*)message, msg_code );
+	gmyth_debug( "DEFAULT Signal handler ( msg = %s, code = %d, file_transfer ptr. = %p )\n", 
+				message, msg_code, live_tv );
 }
-*/
 
 static void
 gmyth_monitor_handler_print( GString *str, gpointer ptr )
@@ -372,7 +366,7 @@
         g_signal_emit ( monitor,
                GMYTH_MONITOR_HANDLER_GET_CLASS (monitor)->backend_events_handler_signal_id,
                0, /* details */
-               msg_type, back_msg_action );
+               msg_type, back_msg_action, NULL );
                
         if (back_msg_action!= NULL)
         	g_free( back_msg_action );
diff -r 633c6c9784d3 -r 001205bb0f40 gmyth/src/gmyth_monitor_handler.h
--- a/gmyth/src/gmyth_monitor_handler.h	Tue Dec 12 18:18:36 2006 +0000
+++ b/gmyth/src/gmyth_monitor_handler.h	Tue Dec 12 18:19:35 2006 +0000
@@ -32,7 +32,6 @@
 
 #include <glib-object.h>
 #include <glib.h>
- 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -40,11 +39,9 @@
 #include <netdb.h>
 #include <sys/socket.h>
 #include <unistd.h>
- 
+
 #include "gmyth_socket.h"
 #include "gmyth_uri.h"
-#include "gmyth_livetv.h"
-
 
 G_BEGIN_DECLS
 
@@ -57,6 +54,12 @@
 
 #define GMYTHTV_MONITOR_HANDLER_READ_ERROR	-314
 
+enum {
+	GMYTH_BACKEND_NO_MESSAGE = 0,
+  GMYTH_BACKEND_PROGRAM_INFO_CHANGED,
+  GMYTH_BACKEND_STOP_LIVETV
+};
+
 typedef struct _GMythMonitorHandler         GMythMonitorHandler;
 typedef struct _GMythMonitorHandlerClass    GMythMonitorHandlerClass;
 
@@ -68,7 +71,7 @@
 	guint backend_events_handler_signal_id;
 
   /* signal default handlers */
-  void (*backend_events_handler) (GMythMonitorHandler *monitor, gint msg_code, gchar* message );
+  void (*backend_events_handler) (GMythMonitorHandler *monitor, gint msg_code, gchar* message, gpointer livetv );
 };
 
 struct _GMythMonitorHandler
@@ -80,19 +83,20 @@
 
 	/* socket descriptors */
 	GMythSocket *event_sock;
-
+	
 	gchar *hostname;
 	gint port;
 	
 	gint64 actual_index;
 	
 	/* stores the messages coming from the backend */
-	GHashTable *backend_msgs;
+	GHashTable *backend_msgs;	
+
 };
 
 GType          gmyth_monitor_handler_get_type        (void);
 
-GMythMonitorHandler* gmyth_monitor_handler_new (void);
+GMythMonitorHandler* gmyth_monitor_handler_new ( void );
 
 gboolean gmyth_monitor_handler_open (GMythMonitorHandler *monitor, gchar *hostname, gint port);