[svn r217] Added signals to program changed messages coming from backend (MythTV).
1.1 --- a/gmyth/src/gmyth_file_transfer.c Tue Dec 12 18:18:36 2006 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Tue Dec 12 18:19:35 2006 +0000
1.3 @@ -36,7 +36,14 @@
1.4 #endif
1.5
1.6 #include "gmyth_file_transfer.h"
1.7 -
1.8 +#include "gmyth_livetv.h"
1.9 +#include "gmyth_util.h"
1.10 +#include "gmyth_socket.h"
1.11 +#include "gmyth_stringlist.h"
1.12 +#include "gmyth_debug.h"
1.13 +#include "gmyth_uri.h"
1.14 +#include "gmyth_marshal.h"
1.15 +
1.16 #include <unistd.h>
1.17 #include <glib.h>
1.18
1.19 @@ -48,12 +55,6 @@
1.20 #include <stdlib.h>
1.21 #include <assert.h>
1.22
1.23 -#include "gmyth_livetv.h"
1.24 -#include "gmyth_util.h"
1.25 -#include "gmyth_socket.h"
1.26 -#include "gmyth_stringlist.h"
1.27 -#include "gmyth_debug.h"
1.28 -
1.29 #define GMYTHTV_QUERY_HEADER "QUERY_FILETRANSFER "
1.30
1.31 /* default values to the file transfer parameters */
1.32 @@ -85,7 +86,15 @@
1.33 GMYTH_RINGBUFFER_TYPE
1.34 };
1.35
1.36 -//static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT;
1.37 +#define GMYTH_FILE_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferPrivate))
1.38 +
1.39 +struct _GMythFileTransferPrivate {
1.40 +
1.41 + GMythLiveTV *livetv;
1.42 +
1.43 + gboolean do_next_program_chain;
1.44 +
1.45 +};
1.46
1.47 static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass);
1.48 static void gmyth_file_transfer_init (GMythFileTransfer *object);
1.49 @@ -93,6 +102,9 @@
1.50 static void gmyth_file_transfer_dispose (GObject *object);
1.51 static void gmyth_file_transfer_finalize (GObject *object);
1.52
1.53 +static void gmyth_file_transfer_program_info_changed( GMythFileTransfer *transfer,
1.54 + gint msg_code, gpointer livetv_transfer );
1.55 +
1.56 static gboolean gmyth_connect_to_backend (GMythFileTransfer *transfer);
1.57
1.58 void gmyth_file_transfer_close( GMythFileTransfer *transfer );
1.59 @@ -107,11 +119,31 @@
1.60 gmyth_file_transfer_class_init (GMythFileTransferClass *klass)
1.61 {
1.62 GObjectClass *gobject_class;
1.63 + GMythFileTransferClass *gtransfer_class;
1.64
1.65 gobject_class = (GObjectClass *) klass;
1.66 + gtransfer_class = (GMythFileTransferClass *) gobject_class;
1.67
1.68 gobject_class->dispose = gmyth_file_transfer_dispose;
1.69 gobject_class->finalize = gmyth_file_transfer_finalize;
1.70 +
1.71 + g_type_class_add_private (gobject_class, sizeof (GMythFileTransferPrivate));
1.72 +
1.73 + gtransfer_class->program_info_changed_handler_signal_id =
1.74 + g_signal_new ("program-info-changed",
1.75 + G_TYPE_FROM_CLASS (gtransfer_class),
1.76 + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1.77 + 0,
1.78 + NULL,
1.79 + NULL,
1.80 + gmyth_marshal_VOID__INT_POINTER,
1.81 + G_TYPE_NONE,
1.82 + 2,
1.83 + G_TYPE_INT,
1.84 + G_TYPE_POINTER);
1.85 +
1.86 + gtransfer_class->program_info_changed_handler = gmyth_file_transfer_program_info_changed;
1.87 +
1.88 }
1.89
1.90 static void
1.91 @@ -121,6 +153,11 @@
1.92
1.93 transfer->readposition = 0;
1.94 transfer->filesize = GMYTHTV_FILE_SIZE;
1.95 +
1.96 + transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.97 +
1.98 + transfer->priv->do_next_program_chain = FALSE;
1.99 + transfer->priv->livetv = NULL;
1.100
1.101 transfer->control_sock = NULL;
1.102 transfer->sock = NULL;
1.103 @@ -514,7 +551,8 @@
1.104 bytes_sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error
1.105 gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
1.106
1.107 - if ( bytes_sent != 0 ) {
1.108 + if ( bytes_sent != 0 )
1.109 + {
1.110 gchar *data_buffer = g_new0 (gchar, bytes_sent);
1.111 while ( 0 != bytes_sent) {
1.112 io_status = g_io_channel_read_chars( io_channel, data_buffer + total_read,
1.113 @@ -550,12 +588,59 @@
1.114 g_error_free (error);
1.115 }
1.116
1.117 - if ( total_read >= 0 )
1.118 + if ( total_read > 0 )
1.119 transfer->readposition += total_read;
1.120 + else
1.121 + {
1.122 + transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.123 +
1.124 + if ( transfer->priv != NULL && transfer->priv->livetv != NULL )
1.125 + {
1.126 +
1.127 + total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN;
1.128 +
1.129 + if ( max_tries <= 0 && transfer->priv->do_next_program_chain )
1.130 + {
1.131 +
1.132 + if ( !gmyth_livetv_next_program_chain( transfer->priv->livetv ) )
1.133 + {
1.134 + gmyth_debug( "Cannot change to the next program chain!" );
1.135 + }
1.136 + else
1.137 + {
1.138 + gmyth_debug( "OK!!! MOVED to the next program chain [%s]!",
1.139 + (gmyth_tvchain_get_id( transfer->priv->livetv->tvchain ))->str );
1.140 + }
1.141 + }
1.142 +
1.143 + } /* if */
1.144 +
1.145 + } /* if */
1.146
1.147 return total_read;
1.148 }
1.149
1.150 +static void
1.151 +gmyth_file_transfer_program_info_changed( GMythFileTransfer *transfer,
1.152 + gint msg_code, gpointer livetv_transfer )
1.153 +{
1.154 + GMythLiveTV *livetv = (GMythLiveTV*)livetv_transfer;
1.155 +
1.156 + gmyth_debug( "Program info changed! ( file transfer orig. = %p, ptr. = %p )", transfer, livetv_transfer );
1.157 +
1.158 + if ( transfer == livetv->file_transfer )
1.159 + {
1.160 + gmyth_debug( "YES, the requested program info movement on the LiveTV transfer is authentical!" );
1.161 + }
1.162 +
1.163 + transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.164 +
1.165 + transfer->priv->livetv = livetv;
1.166 + transfer->priv->do_next_program_chain = TRUE;
1.167 +
1.168 + //g_object_unref( transfer );
1.169 +}
1.170 +
1.171 gboolean
1.172 gmyth_file_transfer_settimeout( GMythFileTransfer *transfer, gboolean fast )
1.173 {
2.1 --- a/gmyth/src/gmyth_file_transfer.h Tue Dec 12 18:18:36 2006 +0000
2.2 +++ b/gmyth/src/gmyth_file_transfer.h Tue Dec 12 18:19:35 2006 +0000
2.3 @@ -35,7 +35,6 @@
2.4
2.5 #include "gmyth_socket.h"
2.6 #include "gmyth_uri.h"
2.7 -#include "gmyth_livetv.h"
2.8 #include "gmyth_backendinfo.h"
2.9
2.10 #include <stdio.h>
2.11 @@ -54,43 +53,52 @@
2.12 #define IS_GMYTH_FILE_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TRANSFER_TYPE))
2.13 #define GMYTH_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass))
2.14
2.15 -#define GMYTHTV_FILE_TRANSFER_READ_ERROR -314
2.16 +#define GMYTHTV_FILE_TRANSFER_READ_ERROR -314
2.17 +#define GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN -315
2.18
2.19 typedef struct _GMythFileTransfer GMythFileTransfer;
2.20 typedef struct _GMythFileTransferClass GMythFileTransferClass;
2.21 +typedef struct _GMythFileTransferPrivate GMythFileTransferPrivate;
2.22
2.23 struct _GMythFileTransferClass
2.24 {
2.25 GObjectClass parent_class;
2.26
2.27 /* callbacks */
2.28 - /* no one for now */
2.29 + guint program_info_changed_handler_signal_id;
2.30 +
2.31 + /* signal default handlers */
2.32 + void (*program_info_changed_handler) ( GMythFileTransfer *transfer,
2.33 + gint msg_code, gpointer livetv_transfer );
2.34 };
2.35
2.36 struct _GMythFileTransfer
2.37 {
2.38 - GObject parent;
2.39 -
2.40 + GObject parent;
2.41 +
2.42 /* Myth URI structure */
2.43 - gchar* filename;
2.44 + gchar *filename;
2.45 GMythBackendInfo *backend_info;
2.46
2.47 /* MythTV version number */
2.48 - gint mythtv_version;
2.49 + gint mythtv_version;
2.50
2.51 /* socket descriptors */
2.52 - GMythSocket *control_sock;
2.53 - GMythSocket *sock;
2.54 + GMythSocket *control_sock;
2.55 + GMythSocket *sock;
2.56
2.57 - gint64 readposition;
2.58 - guint64 filesize;
2.59 - gint file_id;
2.60 + gint64 readposition;
2.61 + guint64 filesize;
2.62 + gint file_id;
2.63 +
2.64 + GMythFileTransferPrivate *priv;
2.65 +
2.66 };
2.67
2.68 -GType gmyth_file_transfer_get_type (void);
2.69 +GType gmyth_file_transfer_get_type (void);
2.70 GMythFileTransfer *gmyth_file_transfer_new (const GMythBackendInfo *backend_info);
2.71 -gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer,
2.72 - const gchar* filename);
2.73 +gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer,
2.74 + const gchar* filename);
2.75 void gmyth_file_transfer_close (GMythFileTransfer *transfer);
2.76 gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer);
2.77 gint gmyth_file_transfer_read (GMythFileTransfer *transfer,
3.1 --- a/gmyth/src/gmyth_livetv.c Tue Dec 12 18:18:36 2006 +0000
3.2 +++ b/gmyth/src/gmyth_livetv.c Tue Dec 12 18:19:35 2006 +0000
3.3 @@ -31,12 +31,17 @@
3.4
3.5 #include "gmyth_livetv.h"
3.6
3.7 +#ifdef HAVE_CONFIG_H
3.8 +#include "config.h"
3.9 +#endif
3.10 +
3.11 #include "gmyth_remote_util.h"
3.12 #include "gmyth_tvchain.h"
3.13 #include "gmyth_socket.h"
3.14 #include "gmyth_debug.h"
3.15
3.16 #include "gmyth_file_transfer.h"
3.17 +#include "gmyth_monitor_handler.h"
3.18
3.19 static void gmyth_livetv_class_init (GMythLiveTVClass *klass);
3.20 static void gmyth_livetv_init (GMythLiveTV *object);
3.21 @@ -65,9 +70,10 @@
3.22 static void
3.23 gmyth_livetv_init (GMythLiveTV *livetv)
3.24 {
3.25 - livetv->backend_hostname = NULL;
3.26 - livetv->backend_port = 0;
3.27 + livetv->backend_info = NULL;
3.28 livetv->local_hostname = NULL;
3.29 + livetv->file_transfer = NULL;
3.30 + livetv->setup_done = FALSE;
3.31
3.32 livetv->recorder = NULL;
3.33 livetv->tvchain = NULL;
3.34 @@ -90,6 +96,11 @@
3.35
3.36 gmyth_debug ("[%s] Finalizing livetv", __FUNCTION__);
3.37
3.38 + if ( livetv->monitor != NULL ) {
3.39 + g_object_unref (livetv->monitor);
3.40 + livetv->monitor = NULL;
3.41 + }
3.42 +
3.43 if ( livetv->recorder != NULL ) {
3.44 g_object_unref (livetv->recorder);
3.45 livetv->recorder = NULL;
3.46 @@ -104,6 +115,16 @@
3.47 g_object_unref (livetv->proginfo);
3.48 livetv->proginfo = NULL;
3.49 }
3.50 +
3.51 + if ( livetv->file_transfer != NULL ) {
3.52 + g_object_unref (livetv->file_transfer);
3.53 + livetv->file_transfer = NULL;
3.54 + }
3.55 +
3.56 + if ( livetv->backend_info != NULL ) {
3.57 + g_object_unref (livetv->backend_info);
3.58 + livetv->backend_info = NULL;
3.59 + }
3.60
3.61 G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object );
3.62 }
3.63 @@ -118,22 +139,58 @@
3.64
3.65 static void
3.66 gmyth_livetv_monitor_signal_handler( GMythMonitorHandler *monitor, gint msg_code,
3.67 - gchar* message )
3.68 + gchar* message, gpointer livetv )
3.69 {
3.70 + GMythLiveTV *live_tv = (GMythLiveTV*) livetv;
3.71 +
3.72 gmyth_debug( "LIVETV Signal handler ( msg = %s, code = %d )\n", message, msg_code );
3.73 +
3.74 + if ( NULL == live_tv )
3.75 + return;
3.76 +
3.77 + switch ( msg_code )
3.78 + {
3.79 +
3.80 + case GMYTH_BACKEND_PROGRAM_INFO_CHANGED:
3.81 + {
3.82 + gmyth_debug( "LIVETV Program Changed event received [ msg = %s ]\n", message );
3.83 + /*
3.84 + if ( !gmyth_livetv_next_program_chain( live_tv ) )
3.85 + {
3.86 + gmyth_debug( "Cannot change to the next program chain!" );
3.87 + }
3.88 + else
3.89 + {
3.90 + */
3.91 + gmyth_debug( "OK!!! MOVED to the next program chain [%s]!",
3.92 + (gmyth_tvchain_get_id( live_tv->tvchain ))->str );
3.93 + /* advertises the FileTransfer about the program info changed */
3.94 + g_signal_emit ( live_tv->file_transfer,
3.95 + GMYTH_FILE_TRANSFER_GET_CLASS (live_tv->file_transfer)->program_info_changed_handler_signal_id,
3.96 + 0, /* details */
3.97 + msg_code, live_tv );
3.98 + /*}*/
3.99 + break;
3.100 + }
3.101 + default:
3.102 + break;
3.103 +
3.104 + }
3.105 +
3.106 }
3.107
3.108 gboolean
3.109 gmyth_livetv_setup ( GMythLiveTV *livetv, GMythBackendInfo *backend_info )
3.110 {
3.111 gboolean res = TRUE;
3.112 - char *hostname;
3.113
3.114 GMythSocket *socket = gmyth_socket_new ();
3.115 +
3.116 + livetv->backend_info = backend_info;
3.117
3.118 // FIME: Implement this at gmyth_socket
3.119 - res = gmyth_socket_connect_to_backend (socket, backend_info->hostname,
3.120 - backend_info->port, TRUE);
3.121 + res = gmyth_socket_connect_to_backend (socket, livetv->backend_info->hostname,
3.122 + livetv->backend_info->port, TRUE);
3.123 if (!res) {
3.124 g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);
3.125 res = FALSE;
3.126 @@ -144,7 +201,8 @@
3.127
3.128 livetv->monitor = gmyth_monitor_handler_new ( );
3.129
3.130 - res = gmyth_monitor_handler_open (livetv->monitor, backend_info->hostname, backend_info->port );
3.131 + res = gmyth_monitor_handler_open (livetv->monitor, livetv->backend_info->hostname,
3.132 + livetv->backend_info->port );
3.133
3.134 if ( res == TRUE )
3.135 {
3.136 @@ -157,7 +215,7 @@
3.137 gmyth_debug("MythTV Monitor event socket connected and listening!");
3.138 g_signal_connect (G_OBJECT (livetv->monitor), "backend-events-handler",
3.139 (GCallback)gmyth_livetv_monitor_signal_handler,
3.140 - NULL);
3.141 + livetv);
3.142 }
3.143 else
3.144 {
3.145 @@ -166,10 +224,6 @@
3.146 }
3.147 }
3.148
3.149 - hostname = gmyth_backend_info_get_hostname(backend_info);
3.150 - livetv->backend_hostname = g_string_new (hostname);
3.151 - livetv->backend_port = gmyth_backend_info_get_port (backend_info);
3.152 -
3.153 livetv->local_hostname = gmyth_socket_get_local_hostname ( );
3.154
3.155 if ( livetv->local_hostname == NULL ) {
3.156 @@ -189,7 +243,7 @@
3.157
3.158 // Creates livetv chain handler
3.159 livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) );
3.160 - gmyth_tvchain_initialize ( livetv->tvchain, backend_info );
3.161 + gmyth_tvchain_initialize ( livetv->tvchain, livetv->backend_info );
3.162
3.163 if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) {
3.164 res = FALSE;
3.165 @@ -244,15 +298,13 @@
3.166 } else {
3.167 gmyth_debug ("[%s] GMythLiveTV: All requests to backend to start TV were OK.\n", __FUNCTION__ );
3.168 }
3.169 -
3.170 +
3.171 + livetv->setup_done = TRUE;
3.172 +
3.173 return res;
3.174
3.175 error:
3.176 g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
3.177 - if ( livetv->backend_hostname != NULL ) {
3.178 - g_string_free( livetv->backend_hostname, TRUE );
3.179 - res = FALSE;
3.180 - }
3.181
3.182 if ( livetv->local_hostname != NULL ) {
3.183 g_string_free( livetv->local_hostname, TRUE );
3.184 @@ -283,7 +335,14 @@
3.185 {
3.186 gboolean res = TRUE;
3.187
3.188 - // Reload all TV chain from Mysql database.
3.189 + if ( !livetv->setup_done )
3.190 + {
3.191 + gmyth_debug ( "Call the setup function first!" );
3.192 + res= FALSE;
3.193 + goto error;
3.194 + }
3.195 +
3.196 + /* Reload all TV chain from Mysql database. */
3.197 gmyth_tvchain_reload_all (livetv->tvchain);
3.198
3.199 if ( livetv->tvchain == NULL ) {
3.200 @@ -305,10 +364,6 @@
3.201
3.202 error:
3.203 g_print( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
3.204 - if ( livetv->backend_hostname != NULL ) {
3.205 - g_string_free( livetv->backend_hostname, TRUE );
3.206 - res = FALSE;
3.207 - }
3.208
3.209 if ( livetv->local_hostname != NULL ) {
3.210 g_string_free( livetv->local_hostname, TRUE );
3.211 @@ -334,7 +389,57 @@
3.212
3.213 }
3.214
3.215 -// FIXME: How to proceed differently between livetv and recorded content
3.216 +GMythFileTransfer *
3.217 +gmyth_livetv_create_file_transfer( GMythLiveTV *livetv )
3.218 +{
3.219 + GMythURI* uri = NULL;
3.220 +
3.221 + if ( NULL == livetv || NULL == livetv->proginfo )
3.222 + goto done;
3.223 +
3.224 + if ( !livetv->setup_done )
3.225 + {
3.226 + gmyth_debug( "Error: You must do the LiveTV setup, just before generating the FileTransfer from LiveTV source!" );
3.227 + goto done;
3.228 + }
3.229 +
3.230 + gmyth_debug( "URI path = %s.\n", livetv->proginfo->pathname->str );
3.231 +
3.232 + livetv->file_transfer = gmyth_file_transfer_new( livetv->backend_info );
3.233 +
3.234 + if ( NULL == livetv->file_transfer )
3.235 + {
3.236 + gmyth_debug( "Error: couldn't create the FileTransfer from LiveTV source!" );
3.237 + goto done;
3.238 + }
3.239 +
3.240 + uri = gmyth_uri_new_with_value( livetv->proginfo->pathname->str );
3.241 + if ( NULL == uri )
3.242 + {
3.243 + gmyth_debug( "Couldn't parse the URI to start LiveTV! [uri = %s]", livetv->proginfo->pathname->str );
3.244 + }
3.245 +
3.246 + if ( !gmyth_file_transfer_open( livetv->file_transfer, uri != NULL ? gmyth_uri_get_path(uri) :
3.247 + livetv->proginfo->pathname->str ) )
3.248 + {
3.249 + gmyth_debug( "Error: couldn't open the FileTransfer from LiveTV source!" );
3.250 + g_object_unref( livetv->file_transfer );
3.251 + livetv->file_transfer = NULL;
3.252 + goto done;
3.253 + }
3.254 +
3.255 +done:
3.256 + if ( uri != NULL )
3.257 + {
3.258 + g_object_unref( uri );
3.259 + uri = NULL;
3.260 + }
3.261 +
3.262 + return livetv->file_transfer;
3.263 +
3.264 +}
3.265 +
3.266 +/* FIXME: How to proceed differently between livetv and recorded content */
3.267 void
3.268 gmyth_livetv_stop_playing (GMythLiveTV *livetv)
3.269 {
4.1 --- a/gmyth/src/gmyth_livetv.h Tue Dec 12 18:18:36 2006 +0000
4.2 +++ b/gmyth/src/gmyth_livetv.h Tue Dec 12 18:19:35 2006 +0000
4.3 @@ -31,7 +31,12 @@
4.4 #include <glib.h>
4.5 #include <glib-object.h>
4.6
4.7 -#include "gmyth.h"
4.8 +#include "gmyth_recorder.h"
4.9 +#include "gmyth_tvchain.h"
4.10 +#include "gmyth_monitor_handler.h"
4.11 +#include "gmyth_file_transfer.h"
4.12 +#include "gmyth_programinfo.h"
4.13 +#include "gmyth_backendinfo.h"
4.14
4.15 G_BEGIN_DECLS
4.16
4.17 @@ -54,36 +59,39 @@
4.18
4.19 struct _GMythLiveTV
4.20 {
4.21 - GObject parent;
4.22 + GObject parent;
4.23 +
4.24 + GString *local_hostname;
4.25 +
4.26 + GMythBackendInfo *backend_info;
4.27
4.28 - // Backend connection related variables
4.29 - GString *backend_hostname;
4.30 - gint backend_port;
4.31 - GString *local_hostname;
4.32 -
4.33 - GMythRecorder *recorder;
4.34 - GMythTVChain *tvchain;
4.35 - GMythProgramInfo *proginfo;
4.36 + GMythRecorder *recorder;
4.37 + GMythTVChain *tvchain;
4.38 + GMythProgramInfo *proginfo;
4.39 +
4.40 + GMythFileTransfer *file_transfer;
4.41
4.42 GMythMonitorHandler *monitor;
4.43
4.44 - gboolean is_livetv;
4.45 + gboolean is_livetv;
4.46 + gboolean setup_done;
4.47
4.48 };
4.49
4.50 GType gmyth_livetv_get_type (void);
4.51
4.52 -GMythLiveTV* gmyth_livetv_new ();
4.53 +GMythLiveTV* gmyth_livetv_new ();
4.54
4.55 void gmyth_livetv_start_playing (GMythLiveTV *livetv);
4.56 void gmyth_livetv_stop_playing (GMythLiveTV *livetv);
4.57
4.58 -gboolean gmyth_livetv_is_recording ( GMythLiveTV *livetv );
4.59 -
4.60 +gboolean gmyth_livetv_is_recording ( GMythLiveTV *livetv );
4.61
4.62 gboolean gmyth_livetv_setup (GMythLiveTV *livetv, GMythBackendInfo *backend_info);
4.63 gboolean gmyth_livetv_next_program_chain ( GMythLiveTV *livetv );
4.64
4.65 +GMythFileTransfer *gmyth_livetv_create_file_transfer( GMythLiveTV *livetv );
4.66 +
4.67 G_END_DECLS
4.68
4.69 #endif /*GMYTH_LIVETV_H_*/
5.1 --- a/gmyth/src/gmyth_monitor_handler.c Tue Dec 12 18:18:36 2006 +0000
5.2 +++ b/gmyth/src/gmyth_monitor_handler.c Tue Dec 12 18:19:35 2006 +0000
5.3 @@ -37,7 +37,6 @@
5.4
5.5 #include <unistd.h>
5.6 #include <glib.h>
5.7 -
5.8 #include <arpa/inet.h>
5.9 #include <sys/types.h>
5.10 #include <sys/socket.h>
5.11 @@ -46,15 +45,11 @@
5.12 #include <stdlib.h>
5.13 #include <assert.h>
5.14
5.15 -#include "gmyth_uri.h"
5.16 -#include "gmyth_livetv.h"
5.17 -#include "gmyth_util.h"
5.18 -#include "gmyth_socket.h"
5.19 -#include "gmyth_stringlist.h"
5.20 -#include "gmyth_debug.h"
5.21 #include "gmyth_marshal.h"
5.22 -// FIXME: this include cannot be in the first line
5.23 +
5.24 #include "gmyth_monitor_handler.h"
5.25 +
5.26 +#include "gmyth.h"
5.27
5.28 #define GMYTHTV_QUERY_HEADER "QUERY_FILETRANSFER "
5.29
5.30 @@ -79,16 +74,13 @@
5.31
5.32 GThreadPool *monitor_th = NULL;
5.33
5.34 -enum gmyth_monitor_handler_msg_types {
5.35 - GMYTH_BACKEND_NO_MESSAGE = 0,
5.36 - GMYTH_BACKEND_PROGRAM_INFO_CHANGED,
5.37 - GMYTH_BACKEND_STOP_LIVETV
5.38 -};
5.39 -
5.40 //static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
5.41 //static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition,
5.42 // gpointer data );
5.43 //static void myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret );
5.44 +static void
5.45 +gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message,
5.46 + gpointer live_tv );
5.47
5.48 static void gmyth_monitor_handler_listener (GMythMonitorHandler *monitor,
5.49 gpointer user_data);
5.50 @@ -126,13 +118,16 @@
5.51 G_TYPE_FROM_CLASS (gmonitor_class),
5.52 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
5.53 0,
5.54 - NULL,
5.55 - NULL,
5.56 - gmyth_marshal_VOID__INT_STRING,
5.57 - G_TYPE_NONE,
5.58 - 2,
5.59 - G_TYPE_INT,
5.60 - G_TYPE_STRING);
5.61 + NULL,
5.62 + NULL,
5.63 + gmyth_marshal_VOID__INT_STRING_POINTER,
5.64 + G_TYPE_NONE,
5.65 + 3,
5.66 + G_TYPE_INT,
5.67 + G_TYPE_STRING,
5.68 + G_TYPE_POINTER);
5.69 +
5.70 + gmonitor_class->backend_events_handler = gmyth_monitor_handler_default_listener;
5.71
5.72 }
5.73
5.74 @@ -194,7 +189,6 @@
5.75 if ( monitor_th != NULL )
5.76 {
5.77 g_thread_pool_free( monitor_th, TRUE, FALSE );
5.78 - //g_object_unref( monitor_th );
5.79 monitor_th = NULL;
5.80 }
5.81
5.82 @@ -211,11 +205,11 @@
5.83
5.84 // fixme: do we need the card_id????
5.85 GMythMonitorHandler*
5.86 -gmyth_monitor_handler_new (void)
5.87 +gmyth_monitor_handler_new ( void )
5.88 {
5.89 - GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER ( g_object_new (
5.90 - GMYTH_MONITOR_HANDLER_TYPE, FALSE ));
5.91 -
5.92 + GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER ( g_object_new ( GMYTH_MONITOR_HANDLER_TYPE,
5.93 + FALSE ) );
5.94 +
5.95 return monitor;
5.96 }
5.97
5.98 @@ -252,53 +246,53 @@
5.99 gmyth_monitor_handler_is_backend_message( GMythMonitorHandler *monitor,
5.100 GMythStringList* strlist, gchar **back_msg_action )
5.101 {
5.102 - gint msg_type = GMYTH_BACKEND_NO_MESSAGE;
5.103 - GString *back_msg = NULL;
5.104 -
5.105 - back_msg = gmyth_string_list_get_string( strlist, 0 );
5.106 - if ( back_msg != NULL && back_msg->str != NULL &&
5.107 - strstr( back_msg->str, "BACKEND" ) != NULL )
5.108 - {
5.109 - if ( monitor->backend_msgs != NULL )
5.110 - {
5.111 - *back_msg_action = gmyth_string_list_get_char_array( strlist, 1 );
5.112 -
5.113 - if ( back_msg_action != NULL )
5.114 - {
5.115 -
5.116 - if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
5.117 - g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) ||
5.118 - g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
5.119 - {
5.120 - msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
5.121 - }
5.122 -
5.123 - //g_hash_table_insert ( monitor->backend_msgs,
5.124 - // &(monitor->actual_index), *back_msg_action );
5.125 -
5.126 - } // if
5.127 -
5.128 - } // if
5.129 - }
5.130 -
5.131 - if ( back_msg != NULL )
5.132 - {
5.133 - g_string_free( back_msg, TRUE );
5.134 - back_msg = NULL;
5.135 - }
5.136 -
5.137 - return msg_type;
5.138 + gint msg_type = GMYTH_BACKEND_NO_MESSAGE;
5.139 + GString *back_msg = NULL;
5.140 +
5.141 + back_msg = gmyth_string_list_get_string( strlist, 0 );
5.142 + if ( back_msg != NULL && back_msg->str != NULL &&
5.143 + strstr( back_msg->str, "BACKEND" ) != NULL )
5.144 + {
5.145 + if ( monitor->backend_msgs != NULL )
5.146 + {
5.147 + *back_msg_action = gmyth_string_list_get_char_array( strlist, 1 );
5.148 +
5.149 + if ( back_msg_action != NULL )
5.150 + {
5.151 +
5.152 + if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
5.153 + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) ||
5.154 + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
5.155 + {
5.156 + msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
5.157 + }
5.158 +
5.159 + //g_hash_table_insert ( monitor->backend_msgs,
5.160 + // &(monitor->actual_index), *back_msg_action );
5.161 +
5.162 + } // if
5.163 +
5.164 + } // if
5.165 + }
5.166 +
5.167 + if ( back_msg != NULL )
5.168 + {
5.169 + g_string_free( back_msg, TRUE );
5.170 + back_msg = NULL;
5.171 + }
5.172 +
5.173 + return msg_type;
5.174
5.175 }
5.176
5.177 -/*
5.178 static void
5.179 -gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gpointer message )
5.180 +gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message,
5.181 + gpointer live_tv )
5.182 {
5.183 //assert( message!= NULL );
5.184 - gmyth_debug( "DEFAULT Signal handler ( msg = %s, code = %d )\n", (gchar*)message, msg_code );
5.185 + gmyth_debug( "DEFAULT Signal handler ( msg = %s, code = %d, file_transfer ptr. = %p )\n",
5.186 + message, msg_code, live_tv );
5.187 }
5.188 -*/
5.189
5.190 static void
5.191 gmyth_monitor_handler_print( GString *str, gpointer ptr )
5.192 @@ -372,7 +366,7 @@
5.193 g_signal_emit ( monitor,
5.194 GMYTH_MONITOR_HANDLER_GET_CLASS (monitor)->backend_events_handler_signal_id,
5.195 0, /* details */
5.196 - msg_type, back_msg_action );
5.197 + msg_type, back_msg_action, NULL );
5.198
5.199 if (back_msg_action!= NULL)
5.200 g_free( back_msg_action );
6.1 --- a/gmyth/src/gmyth_monitor_handler.h Tue Dec 12 18:18:36 2006 +0000
6.2 +++ b/gmyth/src/gmyth_monitor_handler.h Tue Dec 12 18:19:35 2006 +0000
6.3 @@ -32,7 +32,6 @@
6.4
6.5 #include <glib-object.h>
6.6 #include <glib.h>
6.7 -
6.8 #include <stdio.h>
6.9 #include <stdlib.h>
6.10 #include <string.h>
6.11 @@ -40,11 +39,9 @@
6.12 #include <netdb.h>
6.13 #include <sys/socket.h>
6.14 #include <unistd.h>
6.15 -
6.16 +
6.17 #include "gmyth_socket.h"
6.18 #include "gmyth_uri.h"
6.19 -#include "gmyth_livetv.h"
6.20 -
6.21
6.22 G_BEGIN_DECLS
6.23
6.24 @@ -57,6 +54,12 @@
6.25
6.26 #define GMYTHTV_MONITOR_HANDLER_READ_ERROR -314
6.27
6.28 +enum {
6.29 + GMYTH_BACKEND_NO_MESSAGE = 0,
6.30 + GMYTH_BACKEND_PROGRAM_INFO_CHANGED,
6.31 + GMYTH_BACKEND_STOP_LIVETV
6.32 +};
6.33 +
6.34 typedef struct _GMythMonitorHandler GMythMonitorHandler;
6.35 typedef struct _GMythMonitorHandlerClass GMythMonitorHandlerClass;
6.36
6.37 @@ -68,7 +71,7 @@
6.38 guint backend_events_handler_signal_id;
6.39
6.40 /* signal default handlers */
6.41 - void (*backend_events_handler) (GMythMonitorHandler *monitor, gint msg_code, gchar* message );
6.42 + void (*backend_events_handler) (GMythMonitorHandler *monitor, gint msg_code, gchar* message, gpointer livetv );
6.43 };
6.44
6.45 struct _GMythMonitorHandler
6.46 @@ -80,19 +83,20 @@
6.47
6.48 /* socket descriptors */
6.49 GMythSocket *event_sock;
6.50 -
6.51 +
6.52 gchar *hostname;
6.53 gint port;
6.54
6.55 gint64 actual_index;
6.56
6.57 /* stores the messages coming from the backend */
6.58 - GHashTable *backend_msgs;
6.59 + GHashTable *backend_msgs;
6.60 +
6.61 };
6.62
6.63 GType gmyth_monitor_handler_get_type (void);
6.64
6.65 -GMythMonitorHandler* gmyth_monitor_handler_new (void);
6.66 +GMythMonitorHandler* gmyth_monitor_handler_new ( void );
6.67
6.68 gboolean gmyth_monitor_handler_open (GMythMonitorHandler *monitor, gchar *hostname, gint port);
6.69