[svn r661] Fixed starvation loop when reading an unlimited-size buffer (LiveTV) from the FileTransfer; MonitorHandler is a GThread now. trunk
authorrosfran
Tue May 15 21:39:04 2007 +0100 (2007-05-15)
branchtrunk
changeset 655ad1457d65f74
parent 654 76b9c97faada
child 656 49f79548b1cc
[svn r661] Fixed starvation loop when reading an unlimited-size buffer (LiveTV) from the FileTransfer; MonitorHandler is a GThread now.
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_file_transfer.h
gmyth/src/gmyth_livetv.c
gmyth/src/gmyth_livetv.h
gmyth/src/gmyth_monitor_handler.c
gmyth/src/gmyth_monitor_handler.h
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Tue May 15 20:16:26 2007 +0100
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Tue May 15 21:39:04 2007 +0100
     1.3 @@ -9,28 +9,28 @@
     1.4   * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     1.5   * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
     1.6   *
     1.7 - *//*
     1.8 - * 
     1.9 - * This program is free software; you can redistribute it and/or modify
    1.10 - * it under the terms of the GNU Lesser General Public License as published by
    1.11 - * the Free Software Foundation; either version 2 of the License, or
    1.12 - * (at your option) any later version.
    1.13 - *
    1.14 - * This program is distributed in the hope that it will be useful,
    1.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 - * GNU General Public License for more details.
    1.18 - *
    1.19 - * You should have received a copy of the GNU Lesser General Public License
    1.20 - * along with this program; if not, write to the Free Software
    1.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.22 - *
    1.23 - * GStreamer MythTV plug-in properties:
    1.24 - * - location (backend server hostname/URL) [ex.: myth://192.168.1.73:28722/1000_1092091.nuv]
    1.25 - * - path (qurl - remote file to be opened)
    1.26 - * - port number *   
    1.27 - */
    1.28 - 
    1.29 +          *//*
    1.30 +       * 
    1.31 +       * This program is free software; you can redistribute it and/or modify
    1.32 +       * it under the terms of the GNU Lesser General Public License as published by
    1.33 +       * the Free Software Foundation; either version 2 of the License, or
    1.34 +       * (at your option) any later version.
    1.35 +       *
    1.36 +       * This program is distributed in the hope that it will be useful,
    1.37 +       * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.38 +       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.39 +       * GNU General Public License for more details.
    1.40 +       *
    1.41 +       * You should have received a copy of the GNU Lesser General Public License
    1.42 +       * along with this program; if not, write to the Free Software
    1.43 +       * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.44 +       *
    1.45 +       * GStreamer MythTV plug-in properties:
    1.46 +       * - location (backend server hostname/URL) [ex.: myth://192.168.1.73:28722/1000_1092091.nuv]
    1.47 +       * - path (qurl - remote file to be opened)
    1.48 +       * - port number *   
    1.49 +       */
    1.50 +
    1.51  #ifdef HAVE_CONFIG_H
    1.52  #include "config.h"
    1.53  #endif
    1.54 @@ -61,44 +61,46 @@
    1.55  #define GMYTH_FILE_TRANSFER_GET_PRIVATE(obj) \
    1.56      (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferPrivate))
    1.57  
    1.58 -enum myth_sock_types {
    1.59 -  GMYTH_PLAYBACK_TYPE = 0,
    1.60 -  GMYTH_MONITOR_TYPE,
    1.61 -  GMYTH_FILETRANSFER_TYPE,
    1.62 -  GMYTH_RINGBUFFER_TYPE
    1.63 -};
    1.64 +enum myth_sock_types
    1.65 +    {
    1.66 +        GMYTH_PLAYBACK_TYPE = 0,
    1.67 +        GMYTH_MONITOR_TYPE,
    1.68 +        GMYTH_FILETRANSFER_TYPE,
    1.69 +        GMYTH_RINGBUFFER_TYPE
    1.70 +    };
    1.71  
    1.72 -struct _GMythFileTransferPrivate {
    1.73 -	GMythRecorder  *recorder;
    1.74 -	
    1.75 -	gboolean       do_next_program_chain;
    1.76 -	gboolean       disposed;
    1.77 -    gboolean       livetv_wait;
    1.78 +struct _GMythFileTransferPrivate
    1.79 +    {
    1.80 +        GMythRecorder *recorder;
    1.81  
    1.82 -	/* MythTV version number */	
    1.83 -	gint           mythtv_version;
    1.84 +        gboolean do_next_program_chain;
    1.85 +        gboolean disposed;
    1.86 +        gboolean livetv_wait;
    1.87  
    1.88 -	/* socket descriptors */
    1.89 -	GMythSocket    *control_sock;
    1.90 -	GMythSocket    *sock;
    1.91 -	GMutex         *mutex;
    1.92 -	gint           file_id;
    1.93 -};
    1.94 +        /* MythTV version number */
    1.95 +        gint mythtv_version;
    1.96  
    1.97 -static void gmyth_file_transfer_class_init          (GMythFileTransferClass *klass);
    1.98 -static void gmyth_file_transfer_init                (GMythFileTransfer *object);
    1.99 -static void gmyth_file_transfer_dispose             (GObject *object);
   1.100 -static void gmyth_file_transfer_finalize            (GObject *object);
   1.101 -static void _file_transfer_program_info_changed(GMythFileTransfer *transfer, 
   1.102 -										             gint msg_code, gpointer livetv_recorder);
   1.103 -static gboolean _connect_to_backend                 (GMythFileTransfer *transfer);
   1.104 -static gboolean _control_acquire_context            (GMythFileTransfer *transfer, gboolean do_wait);
   1.105 -static gboolean _control_release_context            (GMythFileTransfer *transfer);
   1.106 +        /* socket descriptors */
   1.107 +        GMythSocket *control_sock;
   1.108 +        GMythSocket *sock;
   1.109 +        GMutex *mutex;
   1.110 +        gint file_id;
   1.111 +    };
   1.112  
   1.113 -G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, GMYTH_FILE_TYPE)
   1.114 +static void gmyth_file_transfer_class_init (GMythFileTransferClass * klass);
   1.115 +static void gmyth_file_transfer_init (GMythFileTransfer * object);
   1.116 +static void gmyth_file_transfer_dispose (GObject * object);
   1.117 +static void gmyth_file_transfer_finalize (GObject * object);
   1.118 +static void _file_transfer_program_info_changed (GMythFileTransfer * transfer,
   1.119 +                                                 gint msg_code,
   1.120 +                                                 gpointer livetv_recorder);
   1.121 +static gboolean _connect_to_backend (GMythFileTransfer * transfer);
   1.122 +static gboolean _control_acquire_context (GMythFileTransfer * transfer,
   1.123 +                                          gboolean do_wait);
   1.124 +static gboolean _control_release_context (GMythFileTransfer * transfer);
   1.125  
   1.126 -static void
   1.127 -gmyth_file_transfer_class_init (GMythFileTransferClass *klass)
   1.128 +G_DEFINE_TYPE (GMythFileTransfer, gmyth_file_transfer, GMYTH_FILE_TYPE)
   1.129 +     static void gmyth_file_transfer_class_init (GMythFileTransferClass * klass)
   1.130  {
   1.131      GObjectClass *gobject_class;
   1.132      GMythFileTransferClass *gtransfer_class;
   1.133 @@ -106,88 +108,89 @@
   1.134      gobject_class = (GObjectClass *) klass;
   1.135      gtransfer_class = (GMythFileTransferClass *) gobject_class;
   1.136  
   1.137 -    gobject_class->dispose  = gmyth_file_transfer_dispose;
   1.138 +    gobject_class->dispose = gmyth_file_transfer_dispose;
   1.139      gobject_class->finalize = gmyth_file_transfer_finalize;
   1.140 -  
   1.141 +
   1.142      g_type_class_add_private (gobject_class, sizeof (GMythFileTransferPrivate));
   1.143 -  
   1.144 -	gtransfer_class->program_info_changed_handler = _file_transfer_program_info_changed;
   1.145 -  
   1.146 -	gtransfer_class->program_info_changed_handler_signal_id = 
   1.147 -		  g_signal_new ("program-info-changed",
   1.148 -		                G_TYPE_FROM_CLASS (gtransfer_class),
   1.149 -		                G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
   1.150 -		                0,
   1.151 -						NULL,
   1.152 -						NULL,
   1.153 - 					    gmyth_marshal_VOID__INT_POINTER,
   1.154 -						G_TYPE_NONE,
   1.155 -						2,
   1.156 -						G_TYPE_INT,
   1.157 -						G_TYPE_POINTER );
   1.158 +
   1.159 +    gtransfer_class->program_info_changed_handler =
   1.160 +        _file_transfer_program_info_changed;
   1.161 +
   1.162 +    gtransfer_class->program_info_changed_handler_signal_id =
   1.163 +        g_signal_new ("program-info-changed",
   1.164 +                      G_TYPE_FROM_CLASS (gtransfer_class),
   1.165 +                      G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE |
   1.166 +                      G_SIGNAL_NO_HOOKS, 0, NULL, NULL,
   1.167 +                      gmyth_marshal_VOID__INT_POINTER, G_TYPE_NONE, 2,
   1.168 +                      G_TYPE_INT, G_TYPE_POINTER);
   1.169  
   1.170  }
   1.171  
   1.172  static void
   1.173 -gmyth_file_transfer_init (GMythFileTransfer *transfer)
   1.174 -{ 
   1.175 -    g_return_if_fail( transfer != NULL );
   1.176 +gmyth_file_transfer_init (GMythFileTransfer * transfer)
   1.177 +{
   1.178 +    g_return_if_fail (transfer != NULL);
   1.179  
   1.180 -    transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);	
   1.181 -    transfer->priv->mutex = g_mutex_new();
   1.182 -  
   1.183 -    g_signal_connect ( G_OBJECT (transfer), "program-info-changed",
   1.184 -        (GCallback)(GMYTH_FILE_TRANSFER_GET_CLASS(transfer)->program_info_changed_handler),
   1.185 -        NULL );
   1.186 +    transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
   1.187 +    transfer->priv->mutex = g_mutex_new ();
   1.188 +
   1.189 +    g_signal_connect (G_OBJECT (transfer), "program-info-changed",
   1.190 +                      (GCallback) (GMYTH_FILE_TRANSFER_GET_CLASS (transfer)->
   1.191 +                                   program_info_changed_handler), NULL);
   1.192  }
   1.193  
   1.194  static void
   1.195 -gmyth_file_transfer_dispose  (GObject *object)
   1.196 -{	
   1.197 +gmyth_file_transfer_dispose (GObject * object)
   1.198 +{
   1.199      GMythFileTransferPrivate *priv;
   1.200 -	GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (object);
   1.201 +    GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (object);
   1.202  
   1.203 -    g_return_if_fail( transfer != NULL );
   1.204 +    g_return_if_fail (transfer != NULL);
   1.205  
   1.206 -    priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);	
   1.207 +    priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
   1.208  
   1.209 -    if (priv->disposed) {
   1.210 +    if (priv->disposed)
   1.211 +    {
   1.212          /* If dispose did already run, return. */
   1.213          return;
   1.214      }
   1.215 -    
   1.216 +
   1.217      /* Make sure dispose does not run twice. */
   1.218      priv->disposed = TRUE;
   1.219 -    
   1.220 -    if (priv->mutex != NULL ) {
   1.221 -        g_mutex_free (priv->mutex );
   1.222 +
   1.223 +    if (priv->mutex != NULL)
   1.224 +    {
   1.225 +        g_mutex_free (priv->mutex);
   1.226          priv->mutex = NULL;
   1.227      }
   1.228  
   1.229 -    if (priv->control_sock != NULL ) {
   1.230 -        g_object_unref (priv->control_sock );
   1.231 +    if (priv->control_sock != NULL)
   1.232 +    {
   1.233 +        g_object_unref (priv->control_sock);
   1.234          priv->control_sock = NULL;
   1.235 -    }  
   1.236 +    }
   1.237  
   1.238 -    if (priv->sock != NULL ) {
   1.239 +    if (priv->sock != NULL)
   1.240 +    {
   1.241          g_object_unref (priv->sock);
   1.242          priv->sock = NULL;
   1.243      }
   1.244  
   1.245 -    if (priv->recorder != NULL ) {
   1.246 -        g_object_unref (priv->recorder );
   1.247 +    if (priv->recorder != NULL)
   1.248 +    {
   1.249 +        g_object_unref (priv->recorder);
   1.250          priv->recorder = NULL;
   1.251      }
   1.252 -    
   1.253 +
   1.254      G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->dispose (object);
   1.255  }
   1.256  
   1.257  static void
   1.258 -gmyth_file_transfer_finalize (GObject *object)
   1.259 +gmyth_file_transfer_finalize (GObject * object)
   1.260  {
   1.261 -  g_signal_handlers_destroy (object);
   1.262 +    g_signal_handlers_destroy (object);
   1.263  
   1.264 -  G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->finalize (object);
   1.265 +    G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->finalize (object);
   1.266  }
   1.267  
   1.268  /** 
   1.269 @@ -198,28 +201,30 @@
   1.270   * 
   1.271   * @return a new instance of the File Transfer. 
   1.272   */
   1.273 -GMythFileTransfer*
   1.274 -gmyth_file_transfer_new (GMythBackendInfo *backend_info)
   1.275 +GMythFileTransfer *
   1.276 +gmyth_file_transfer_new (GMythBackendInfo * backend_info)
   1.277  {
   1.278 -    GMythFileTransfer *transfer = g_object_new (GMYTH_FILE_TRANSFER_TYPE, 
   1.279 -            "backend-info", backend_info, NULL);
   1.280 +    GMythFileTransfer *transfer = g_object_new (GMYTH_FILE_TRANSFER_TYPE,
   1.281 +                                                "backend-info", backend_info,
   1.282 +                                                NULL);
   1.283      //GValue val = {0,};    
   1.284      //backend_info = g_object_ref( backend_info );
   1.285 -    gmyth_debug( "Creating FileTransfer BackendInfo hostname = %s", gmyth_backend_info_get_hostname(backend_info) );
   1.286 +    gmyth_debug ("Creating FileTransfer BackendInfo hostname = %s",
   1.287 +                 gmyth_backend_info_get_hostname (backend_info));
   1.288      //GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri (uri_str);
   1.289      //g_value_init (&val, G_TYPE_OBJECT);
   1.290      //g_value_set_object (&val, backend_info);    
   1.291      //g_object_set (G_OBJECT (transfer), "backend-info", &val, NULL);
   1.292 -  
   1.293 +
   1.294      return transfer;
   1.295  }
   1.296  
   1.297 -gchar*
   1.298 -gmyth_file_transfer_get_file_name (GMythFileTransfer *transfer)
   1.299 +gchar *
   1.300 +gmyth_file_transfer_get_file_name (GMythFileTransfer * transfer)
   1.301  {
   1.302      gchar *filename;
   1.303 -    
   1.304 -    g_object_get( G_OBJECT(transfer), "filename", &filename, NULL );
   1.305 +
   1.306 +    g_object_get (G_OBJECT (transfer), "filename", &filename, NULL);
   1.307  
   1.308      return filename;
   1.309  }
   1.310 @@ -231,16 +236,17 @@
   1.311   * 
   1.312   * @return a new instance of the File Transfer. 
   1.313   */
   1.314 -GMythFileTransfer* 
   1.315 -gmyth_file_transfer_new_with_uri (const gchar* uri_str)
   1.316 +GMythFileTransfer *
   1.317 +gmyth_file_transfer_new_with_uri (const gchar * uri_str)
   1.318  {
   1.319 -    GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
   1.320 -    gmyth_debug( "URI str = %s", uri_str );
   1.321 +    GMythFileTransfer *transfer =
   1.322 +        GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
   1.323 +    gmyth_debug ("URI str = %s", uri_str);
   1.324      //GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri (uri_str);
   1.325 -    GValue val = {0,};
   1.326 +    GValue val = { 0, };
   1.327      g_value_init (&val, G_TYPE_OBJECT);
   1.328      g_value_set_object (&val, gmyth_backend_info_new_with_uri (uri_str));
   1.329 -    g_object_set(G_OBJECT (transfer), "backend-info", &val, NULL);
   1.330 +    g_object_set (G_OBJECT (transfer), "backend-info", &val, NULL);
   1.331  
   1.332      return transfer;
   1.333  }
   1.334 @@ -254,32 +260,37 @@
   1.335   * @return <code>true</code>, if the connection opening had been done successfully. 
   1.336   */
   1.337  gboolean
   1.338 -gmyth_file_transfer_open (GMythFileTransfer *transfer, const gchar* filename)
   1.339 +gmyth_file_transfer_open (GMythFileTransfer * transfer, const gchar * filename)
   1.340  {
   1.341      gboolean ret = TRUE;
   1.342      GMythFileTransferPrivate *priv;
   1.343 -  
   1.344 +
   1.345      g_return_val_if_fail (transfer != NULL, FALSE);
   1.346 -    g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE);
   1.347 +    g_return_val_if_fail (filename != NULL && strlen (filename) > 0, FALSE);
   1.348  
   1.349      priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
   1.350 -    
   1.351 +
   1.352      //if ( )
   1.353 -    gmyth_debug( "Opening the FileTransfer... (%s)", filename );
   1.354 -    
   1.355 -    g_object_set( GMYTH_FILE(transfer), "filename", filename, NULL );
   1.356 +    gmyth_debug ("Opening the FileTransfer... (%s)", filename);
   1.357 +
   1.358 +    g_object_set (GMYTH_FILE (transfer), "filename", filename, NULL);
   1.359  
   1.360      /* configure the control socket */
   1.361 -    if (priv->control_sock == NULL) { 
   1.362 -        if (!_connect_to_backend (transfer)) {
   1.363 +    if (priv->control_sock == NULL)
   1.364 +    {
   1.365 +        if (!_connect_to_backend (transfer))
   1.366 +        {
   1.367              gmyth_debug ("Connection to backend failed (Control Socket).");
   1.368              ret = FALSE;
   1.369          }
   1.370 -    } else {
   1.371 -        gmyth_debug("Remote transfer control socket already created.");
   1.372      }
   1.373 -  
   1.374 -    gmyth_debug ("Got file with size = %lld.\n", gmyth_file_get_filesize(GMYTH_FILE(transfer)));
   1.375 +    else
   1.376 +    {
   1.377 +        gmyth_debug ("Remote transfer control socket already created.");
   1.378 +    }
   1.379 +
   1.380 +    gmyth_debug ("Got file with size = %lld.\n",
   1.381 +                 gmyth_file_get_filesize (GMYTH_FILE (transfer)));
   1.382  
   1.383      return ret;
   1.384  }
   1.385 @@ -292,95 +303,108 @@
   1.386   * @return <code>true</code>, if the connection had been configured successfully. 
   1.387   */
   1.388  static gboolean
   1.389 -_connect_to_backend (GMythFileTransfer *transfer)
   1.390 +_connect_to_backend (GMythFileTransfer * transfer)
   1.391  {
   1.392      GString *base_str = NULL;
   1.393      GString *hostname = NULL;
   1.394 -    GMythStringList *strlist = NULL; 
   1.395 +    GMythStringList *strlist = NULL;
   1.396      gboolean ret = TRUE;
   1.397      GMythFileTransferPrivate *priv;
   1.398      GMythBackendInfo *backend_info;
   1.399  
   1.400 -    g_return_val_if_fail (transfer != NULL, FALSE );
   1.401 -    
   1.402 -    g_object_get( GMYTH_FILE(transfer), "backend-info", &backend_info, NULL );
   1.403 +    g_return_val_if_fail (transfer != NULL, FALSE);
   1.404 +
   1.405 +    g_object_get (GMYTH_FILE (transfer), "backend-info", &backend_info, NULL);
   1.406  
   1.407      priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
   1.408      _control_acquire_context (transfer, TRUE);
   1.409  
   1.410      /* Creates the control socket */
   1.411  
   1.412 -    if (priv->control_sock != NULL) {
   1.413 +    if (priv->control_sock != NULL)
   1.414 +    {
   1.415          g_object_unref (priv->control_sock);
   1.416          priv->control_sock = NULL;
   1.417      }
   1.418  
   1.419      base_str = g_string_new ("");
   1.420 -  
   1.421 -  	priv->control_sock = gmyth_socket_new();
   1.422 +
   1.423 +    priv->control_sock = gmyth_socket_new ();
   1.424      // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version 
   1.425 -	if (!gmyth_socket_connect_to_backend (priv->control_sock,
   1.426 -    	    backend_info->hostname, backend_info->port, TRUE)) {
   1.427 -	
   1.428 -	    g_object_unref (priv->control_sock);
   1.429 -	    priv->control_sock = NULL;
   1.430 -	    return FALSE;
   1.431 +    if (!gmyth_socket_connect_to_backend (priv->control_sock,
   1.432 +                                          backend_info->hostname,
   1.433 +                                          backend_info->port, TRUE))
   1.434 +    {
   1.435 +
   1.436 +        g_object_unref (priv->control_sock);
   1.437 +        priv->control_sock = NULL;
   1.438 +        return FALSE;
   1.439      }
   1.440 -	  
   1.441 +
   1.442      /* Creates the data socket */
   1.443 -    if (priv->sock != NULL) {
   1.444 +    if (priv->sock != NULL)
   1.445 +    {
   1.446          g_object_unref (priv->sock);
   1.447          priv->sock = NULL;
   1.448 -    }  
   1.449 +    }
   1.450  
   1.451      priv->sock = gmyth_socket_new ();
   1.452 -	gmyth_socket_connect (priv->sock, backend_info->hostname, backend_info->port);
   1.453 -	gmyth_debug ("Connecting file transfer... (%s, %d)", backend_info->hostname, backend_info->port);	  
   1.454 -  
   1.455 -	strlist = gmyth_string_list_new();
   1.456 -	hostname = gmyth_socket_get_local_hostname();
   1.457 -	gmyth_debug( "[%s] MythTV version (from backend) = %d.\n", __FUNCTION__, priv->control_sock->mythtv_version );
   1.458 -	if (priv->control_sock->mythtv_version > 26 )
   1.459 -	  	g_string_printf (base_str, "ANN FileTransfer %s 1 -1", hostname->str);
   1.460 -	else
   1.461 -	    g_string_printf (base_str, "ANN FileTransfer %s", hostname->str);
   1.462 -	
   1.463 -    gmyth_string_list_append_string (strlist, base_str );
   1.464 -	gmyth_string_list_append_char_array (strlist, gmyth_file_get_file_name(GMYTH_FILE(transfer)));
   1.465 -	
   1.466 -	gmyth_socket_write_stringlist (priv->sock, strlist );
   1.467 -	gmyth_socket_read_stringlist (priv->sock, strlist );
   1.468 -	    
   1.469 -	/* file identification used in future file transfer requests to backend */
   1.470 -	priv->file_id = gmyth_string_list_get_int (strlist, 1);
   1.471 -	
   1.472 -	/* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
   1.473 -	gmyth_file_set_filesize( GMYTH_FILE(transfer), gmyth_util_decode_long_long (strlist, 2) );
   1.474 -	
   1.475 -	gmyth_debug ( "***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n",
   1.476 -	          priv->file_id, gmyth_file_get_filesize(GMYTH_FILE(transfer)) );
   1.477 -	
   1.478 -	if ( gmyth_file_get_filesize(GMYTH_FILE(transfer)) < 0 ) {
   1.479 -	    gmyth_debug ( "Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", 
   1.480 -                gmyth_file_get_filesize(GMYTH_FILE(transfer)) );
   1.481 -	    g_object_unref (priv->sock);
   1.482 -	    priv->sock = NULL;
   1.483 -	    ret = FALSE;
   1.484 +    gmyth_socket_connect (priv->sock, backend_info->hostname,
   1.485 +                          backend_info->port);
   1.486 +    gmyth_debug ("Connecting file transfer... (%s, %d)", backend_info->hostname,
   1.487 +                 backend_info->port);
   1.488 +
   1.489 +    strlist = gmyth_string_list_new ();
   1.490 +    hostname = gmyth_socket_get_local_hostname ();
   1.491 +    gmyth_debug ("[%s] MythTV version (from backend) = %d.\n", __FUNCTION__,
   1.492 +                 priv->control_sock->mythtv_version);
   1.493 +    if (priv->control_sock->mythtv_version > 26)
   1.494 +        g_string_printf (base_str, "ANN FileTransfer %s 1 -1", hostname->str);
   1.495 +    else
   1.496 +        g_string_printf (base_str, "ANN FileTransfer %s", hostname->str);
   1.497 +
   1.498 +    gmyth_string_list_append_string (strlist, base_str);
   1.499 +    gmyth_string_list_append_char_array (strlist,
   1.500 +                                         gmyth_file_get_file_name (GMYTH_FILE
   1.501 +                                                                   (transfer)));
   1.502 +
   1.503 +    gmyth_socket_write_stringlist (priv->sock, strlist);
   1.504 +    gmyth_socket_read_stringlist (priv->sock, strlist);
   1.505 +
   1.506 +    /* file identification used in future file transfer requests to backend */
   1.507 +    priv->file_id = gmyth_string_list_get_int (strlist, 1);
   1.508 +
   1.509 +    /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
   1.510 +    gmyth_file_set_filesize (GMYTH_FILE (transfer),
   1.511 +                             gmyth_util_decode_long_long (strlist, 2));
   1.512 +
   1.513 +    gmyth_debug ("***** Received: recordernum = %d, filesize = %"
   1.514 +                 G_GUINT64_FORMAT "\n", priv->file_id,
   1.515 +                 gmyth_file_get_filesize (GMYTH_FILE (transfer)));
   1.516 +
   1.517 +    if (gmyth_file_get_filesize (GMYTH_FILE (transfer)) < 0)
   1.518 +    {
   1.519 +        gmyth_debug
   1.520 +            ("Got filesize equals to %llu is lesser than 0 [invalid stream file]\n",
   1.521 +             gmyth_file_get_filesize (GMYTH_FILE (transfer)));
   1.522 +        g_object_unref (priv->sock);
   1.523 +        priv->sock = NULL;
   1.524 +        ret = FALSE;
   1.525      }
   1.526 -  
   1.527 -    _control_release_context( transfer );
   1.528 +
   1.529 +    _control_release_context (transfer);
   1.530  
   1.531      if (strlist != NULL)
   1.532          g_object_unref (strlist);
   1.533 -  
   1.534 +
   1.535      if (base_str != NULL)
   1.536 -      	g_string_free (base_str, TRUE);
   1.537 -  	
   1.538 -    if (hostname != NULL )
   1.539 -  	    g_string_free (hostname, TRUE);
   1.540 +        g_string_free (base_str, TRUE);
   1.541 +
   1.542 +    if (hostname != NULL)
   1.543 +        g_string_free (hostname, TRUE);
   1.544  
   1.545      return ret;
   1.546 -}    
   1.547 +}
   1.548  
   1.549  /** 
   1.550   * Receives a GObject signal coming from a LiveTV instance, all the time a 
   1.551 @@ -391,15 +415,14 @@
   1.552   * @param live_tv A pointer to the LiveTV instance. * 
   1.553   */
   1.554  void
   1.555 -gmyth_file_transfer_emit_program_info_changed_signal ( GMythFileTransfer *transfer, gint msg_code,
   1.556 -			gpointer live_tv_recorder ) 
   1.557 +gmyth_file_transfer_emit_program_info_changed_signal (GMythFileTransfer *
   1.558 +                                                      transfer, gint msg_code,
   1.559 +                                                      gpointer live_tv_recorder)
   1.560  {
   1.561 -  gmyth_debug( "Calling signal handler... [FILE_TRANSFER]" );
   1.562 +    gmyth_debug ("Calling signal handler... [FILE_TRANSFER]");
   1.563  
   1.564 -  g_signal_emit ( transfer,
   1.565 -         GMYTH_FILE_TRANSFER_GET_CLASS (transfer)->program_info_changed_handler_signal_id,
   1.566 -         0, /* details */
   1.567 -         msg_code, live_tv_recorder);
   1.568 +    g_signal_emit (transfer, GMYTH_FILE_TRANSFER_GET_CLASS (transfer)->program_info_changed_handler_signal_id, 0,       /* details */
   1.569 +                   msg_code, live_tv_recorder);
   1.570  
   1.571  }
   1.572  
   1.573 @@ -411,7 +434,7 @@
   1.574   * @return <code>true</code>, if the File Transfer connection is opened. 
   1.575   */
   1.576  gboolean
   1.577 -gmyth_file_transfer_is_open (GMythFileTransfer *transfer)
   1.578 +gmyth_file_transfer_is_open (GMythFileTransfer * transfer)
   1.579  {
   1.580      GMythStringList *strlist;
   1.581      GMythFileTransferPrivate *priv;
   1.582 @@ -425,16 +448,16 @@
   1.583  
   1.584      _control_acquire_context (transfer, TRUE);
   1.585  
   1.586 -    strlist = gmyth_string_list_new();
   1.587 +    strlist = gmyth_string_list_new ();
   1.588      query = g_string_new (GMYTHTV_QUERY_HEADER);
   1.589 -    g_string_append_printf (query, "%d", priv->file_id );
   1.590 +    g_string_append_printf (query, "%d", priv->file_id);
   1.591  
   1.592 -    gmyth_string_list_append_string (strlist, query );
   1.593 +    gmyth_string_list_append_string (strlist, query);
   1.594      gmyth_string_list_append_char_array (strlist, "IS_OPEN");
   1.595  
   1.596 -    gmyth_socket_write_stringlist (priv->control_sock, strlist );
   1.597 -    gmyth_socket_read_stringlist (priv->control_sock, strlist );
   1.598 -    
   1.599 +    gmyth_socket_write_stringlist (priv->control_sock, strlist);
   1.600 +    gmyth_socket_read_stringlist (priv->control_sock, strlist);
   1.601 +
   1.602      _control_release_context (transfer);
   1.603  
   1.604      g_string_free (query, TRUE);
   1.605 @@ -449,7 +472,7 @@
   1.606   * @param transfer The actual File Transfer instance. 
   1.607   */
   1.608  void
   1.609 -gmyth_file_transfer_close (GMythFileTransfer *transfer )
   1.610 +gmyth_file_transfer_close (GMythFileTransfer * transfer)
   1.611  {
   1.612      GMythStringList *strlist;
   1.613      GMythFileTransferPrivate *priv;
   1.614 @@ -471,23 +494,26 @@
   1.615      gmyth_string_list_append_string (strlist, query);
   1.616      gmyth_string_list_append_char_array (strlist, "DONE");
   1.617  
   1.618 -    if (gmyth_socket_sendreceive_stringlist (priv->control_sock, strlist) <= 0 ) {
   1.619 +    if (gmyth_socket_sendreceive_stringlist (priv->control_sock, strlist) <= 0)
   1.620 +    {
   1.621          // fixme: time out???
   1.622 -        gmyth_debug ( "Remote file timeout.\n" );
   1.623 +        gmyth_debug ("Remote file timeout.\n");
   1.624      }
   1.625  
   1.626      g_string_free (query, TRUE);
   1.627      g_object_unref (strlist);
   1.628  
   1.629 -    if (priv->sock) {
   1.630 -        g_object_unref (priv->sock );
   1.631 +    if (priv->sock)
   1.632 +    {
   1.633 +        g_object_unref (priv->sock);
   1.634          priv->sock = NULL;
   1.635      }
   1.636  
   1.637 -    if (priv->control_sock) {
   1.638 -        g_object_unref (priv->control_sock );
   1.639 +    if (priv->control_sock)
   1.640 +    {
   1.641 +        g_object_unref (priv->control_sock);
   1.642          priv->control_sock = NULL;
   1.643 -    } 
   1.644 +    }
   1.645  
   1.646      _control_release_context (transfer);
   1.647  }
   1.648 @@ -502,9 +528,10 @@
   1.649   * @return The actual position on the remote file (after seek has been done). 
   1.650   */
   1.651  gint64
   1.652 -gmyth_file_transfer_seek (GMythFileTransfer *transfer, guint64 pos, gint whence)
   1.653 +gmyth_file_transfer_seek (GMythFileTransfer * transfer, guint64 pos,
   1.654 +                          gint whence)
   1.655  {
   1.656 -    GMythStringList *strlist = gmyth_string_list_new();
   1.657 +    GMythStringList *strlist = gmyth_string_list_new ();
   1.658      GMythFileTransferPrivate *priv;
   1.659      GString *query;
   1.660  
   1.661 @@ -514,7 +541,7 @@
   1.662      g_return_val_if_fail (priv->sock != NULL, -1);
   1.663      g_return_val_if_fail (priv->control_sock != NULL, -1);
   1.664  
   1.665 -    strlist = gmyth_string_list_new();
   1.666 +    strlist = gmyth_string_list_new ();
   1.667      query = g_string_new (GMYTHTV_QUERY_HEADER);
   1.668      g_string_append_printf (query, "%d", priv->file_id);
   1.669  
   1.670 @@ -524,18 +551,21 @@
   1.671      gmyth_string_list_append_char_array (strlist, "SEEK");
   1.672      gmyth_string_list_append_uint64 (strlist, pos);
   1.673  
   1.674 -    gmyth_string_list_append_int (strlist, whence);  
   1.675 +    gmyth_string_list_append_int (strlist, whence);
   1.676  
   1.677 -    if (pos > 0 )
   1.678 +    if (pos > 0)
   1.679          gmyth_string_list_append_uint64 (strlist, pos);
   1.680      else
   1.681 -        gmyth_string_list_append_uint64 (strlist, gmyth_file_get_offset( GMYTH_FILE(transfer) ) );
   1.682 +        gmyth_string_list_append_uint64 (strlist,
   1.683 +                                         gmyth_file_get_offset (GMYTH_FILE
   1.684 +                                                                (transfer)));
   1.685  
   1.686      gmyth_socket_sendreceive_stringlist (priv->control_sock, strlist);
   1.687  
   1.688      gint64 retval = gmyth_string_list_get_int64 (strlist, 0);
   1.689 -    gmyth_file_set_offset( GMYTH_FILE(transfer), retval );
   1.690 -    gmyth_debug ( "Got reading position pointer from the streaming = %lld\n", retval );
   1.691 +    gmyth_file_set_offset (GMYTH_FILE (transfer), retval);
   1.692 +    gmyth_debug ("Got reading position pointer from the streaming = %lld\n",
   1.693 +                 retval);
   1.694  
   1.695      g_object_unref (strlist);
   1.696      g_string_free (query, TRUE);
   1.697 @@ -553,16 +583,16 @@
   1.698   * 
   1.699   * @return <code>true</code>, if the acquire had been got. 
   1.700   */
   1.701 -static gboolean 
   1.702 -_control_acquire_context( GMythFileTransfer *transfer, gboolean do_wait )
   1.703 +static gboolean
   1.704 +_control_acquire_context (GMythFileTransfer * transfer, gboolean do_wait)
   1.705  {
   1.706 -	gboolean ret = TRUE;	
   1.707 +    gboolean ret = TRUE;
   1.708      GMythFileTransferPrivate *priv;
   1.709  
   1.710      g_return_val_if_fail (transfer != NULL, FALSE);
   1.711      priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
   1.712  
   1.713 -	g_mutex_lock (priv->mutex);
   1.714 +    g_mutex_lock (priv->mutex);
   1.715      return ret;
   1.716  }
   1.717  
   1.718 @@ -573,17 +603,17 @@
   1.719   * 
   1.720   * @return <code>true</code>, if the socket read/write permissions had been releaseds. 
   1.721   */
   1.722 -static gboolean 
   1.723 -_control_release_context( GMythFileTransfer *transfer ) 
   1.724 +static gboolean
   1.725 +_control_release_context (GMythFileTransfer * transfer)
   1.726  {
   1.727 -	gboolean ret = TRUE;
   1.728 +    gboolean ret = TRUE;
   1.729      GMythFileTransferPrivate *priv;
   1.730  
   1.731      g_return_val_if_fail (transfer != NULL, FALSE);
   1.732      priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
   1.733 -   
   1.734 -    g_mutex_unlock (priv->mutex );  
   1.735 - 
   1.736 +
   1.737 +    g_mutex_unlock (priv->mutex);
   1.738 +
   1.739      return ret;
   1.740  }
   1.741  
   1.742 @@ -600,8 +630,9 @@
   1.743   * @return The actual block size (in bytes) returned by REQUEST_BLOCK message,
   1.744   * 				or the error code. 
   1.745   */
   1.746 -GMythFileReadResult 
   1.747 -gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, gint size, gboolean read_unlimited)
   1.748 +GMythFileReadResult
   1.749 +gmyth_file_transfer_read (GMythFileTransfer * transfer, GByteArray * data,
   1.750 +                          gint size, gboolean read_unlimited)
   1.751  {
   1.752      gint bytes_sent = 0;
   1.753      gsize bytes_read = 0;
   1.754 @@ -629,41 +660,48 @@
   1.755  
   1.756      priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
   1.757  
   1.758 -    strlist = gmyth_string_list_new();
   1.759 +    strlist = gmyth_string_list_new ();
   1.760  
   1.761      io_channel = priv->sock->sd_io_ch;
   1.762      io_channel_control = priv->control_sock->sd_io_ch;
   1.763  
   1.764 -    io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
   1.765 -    if ( io_status == G_IO_STATUS_NORMAL )
   1.766 -        gmyth_debug ( "[%s] Setting encoding to binary data socket).\n", __FUNCTION__ );
   1.767 +    io_status = g_io_channel_set_encoding (io_channel, NULL, &error);
   1.768 +    if (io_status == G_IO_STATUS_NORMAL)
   1.769 +        gmyth_debug ("[%s] Setting encoding to binary data socket).\n",
   1.770 +                     __FUNCTION__);
   1.771  
   1.772 -    io_cond = g_io_channel_get_buffer_condition( io_channel );  
   1.773 +    io_cond = g_io_channel_get_buffer_condition (io_channel);
   1.774  
   1.775 -    io_cond_control = g_io_channel_get_buffer_condition( io_channel );
   1.776 -    if (priv->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) ) {
   1.777 -        g_printerr( "gmyth_file_transfer_read(): Called with no raw socket.\n" );
   1.778 +    io_cond_control = g_io_channel_get_buffer_condition (io_channel);
   1.779 +    if (priv->sock == NULL || (io_status == G_IO_STATUS_ERROR))
   1.780 +    {
   1.781 +        g_printerr ("gmyth_file_transfer_read(): Called with no raw socket.\n");
   1.782          return GMYTH_FILE_READ_ERROR;
   1.783      }
   1.784  
   1.785 -    if (priv->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) ) {
   1.786 -        g_printerr( "gmyth_file_transfer_read(): Called with no control socket.\n" );
   1.787 +    if (priv->control_sock == NULL || (io_status_control == G_IO_STATUS_ERROR))
   1.788 +    {
   1.789 +        g_printerr
   1.790 +            ("gmyth_file_transfer_read(): Called with no control socket.\n");
   1.791          return GMYTH_FILE_READ_ERROR;
   1.792      }
   1.793  
   1.794      query = g_string_new (GMYTHTV_QUERY_HEADER);
   1.795 -    g_string_append_printf ( query, "%d", priv->file_id );
   1.796 -    gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str );
   1.797 +    g_string_append_printf (query, "%d", priv->file_id);
   1.798 +    gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str);
   1.799  
   1.800 -    _control_acquire_context (transfer, TRUE );
   1.801 +    _control_acquire_context (transfer, TRUE);
   1.802      //Do Read
   1.803 -    gmyth_string_list_append_char_array (strlist, query->str );
   1.804 -    gmyth_string_list_append_char_array (strlist, "REQUEST_BLOCK" );
   1.805 +    gmyth_string_list_append_char_array (strlist, query->str);
   1.806 +    gmyth_string_list_append_char_array (strlist, "REQUEST_BLOCK");
   1.807      gmyth_string_list_append_int (strlist, size - total_read);
   1.808  
   1.809 -    do {
   1.810 +    guint iter_count = 3;
   1.811 +
   1.812 +    do
   1.813 +    {
   1.814          bytes_sent = 0;
   1.815 -        
   1.816 +
   1.817          // Request the block to the backend
   1.818          gmyth_socket_write_stringlist (priv->control_sock, strlist);
   1.819  
   1.820 @@ -673,27 +711,34 @@
   1.821          ret_strlist = gmyth_string_list_new ();
   1.822          // Receives the backand answer    
   1.823          gmyth_socket_read_stringlist (priv->control_sock, ret_strlist);
   1.824 -        
   1.825 -        if (ret_strlist != NULL && gmyth_string_list_length (ret_strlist) > 0) { 
   1.826 -            bytes_sent = gmyth_string_list_get_int (ret_strlist,  0); // -1 on backend error
   1.827 -	        gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
   1.828 -        } 
   1.829  
   1.830 -        if (read_unlimited && (bytes_sent == 0)) {
   1.831 +        if (ret_strlist != NULL && gmyth_string_list_length (ret_strlist) > 0)
   1.832 +        {
   1.833 +            bytes_sent = gmyth_string_list_get_int (ret_strlist, 0);    // -1 on backend error
   1.834 +            gmyth_debug ("[%s] got SENT buffer message = %d\n", __FUNCTION__,
   1.835 +                         bytes_sent);
   1.836 +        }
   1.837 +
   1.838 +        if (read_unlimited && (bytes_sent == 0))
   1.839 +        {
   1.840              g_usleep (300);
   1.841          }
   1.842  
   1.843 -    } while (read_unlimited && (bytes_sent == 0));
   1.844 +	--iter_count;
   1.845  
   1.846 -   	if (bytes_sent > 0) {
   1.847 +    }
   1.848 +    while (read_unlimited && (bytes_sent == 0) && iter_count > 0);
   1.849 +
   1.850 +    if (bytes_sent > 0)
   1.851 +    {
   1.852          gchar *data_buffer = g_new0 (gchar, bytes_sent);
   1.853 -        io_status = g_io_channel_read_chars (io_channel, 
   1.854 +        io_status = g_io_channel_read_chars (io_channel,
   1.855                                               data_buffer,
   1.856                                               (gsize) bytes_sent,
   1.857 -                                             &bytes_read, 
   1.858 -                                             &error);
   1.859 +                                             &bytes_read, &error);
   1.860  
   1.861 -        if (io_status != G_IO_STATUS_NORMAL) {
   1.862 +        if (io_status != G_IO_STATUS_NORMAL)
   1.863 +        {
   1.864              gmyth_debug ("Error on io_channel");
   1.865              g_free (data_buffer);
   1.866              g_object_unref (strlist);
   1.867 @@ -702,100 +747,119 @@
   1.868          }
   1.869  
   1.870          /* append new data to the increasing byte array */
   1.871 -        data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
   1.872 -        gmyth_file_set_offset( GMYTH_FILE(transfer),  
   1.873 -                gmyth_file_get_offset( GMYTH_FILE(transfer) ) + bytes_read );
   1.874 +        data =
   1.875 +            g_byte_array_append (data, (const guint8 *) data_buffer,
   1.876 +                                 bytes_read);
   1.877 +        gmyth_file_set_offset (GMYTH_FILE (transfer),
   1.878 +                               gmyth_file_get_offset (GMYTH_FILE (transfer)) +
   1.879 +                               bytes_read);
   1.880  
   1.881 -        if ( !read_unlimited && ( gmyth_file_get_filesize( GMYTH_FILE(transfer) ) > 0 ) && 
   1.882 -                ( gmyth_file_get_offset( GMYTH_FILE(transfer) ) == gmyth_file_get_filesize( GMYTH_FILE(transfer) ) ) ) {
   1.883 +        if (!read_unlimited
   1.884 +            && (gmyth_file_get_filesize (GMYTH_FILE (transfer)) > 0)
   1.885 +            && (gmyth_file_get_offset (GMYTH_FILE (transfer)) ==
   1.886 +                gmyth_file_get_filesize (GMYTH_FILE (transfer))))
   1.887 +        {
   1.888              retval = GMYTH_FILE_READ_EOF;
   1.889              goto error;
   1.890          }
   1.891 -        
   1.892 +
   1.893          g_free (data_buffer);
   1.894 -    } else { 
   1.895 +    }
   1.896 +    else
   1.897 +    {
   1.898          retval = GMYTH_FILE_READ_ERROR;
   1.899      }
   1.900  
   1.901 -    if (strlist!=NULL)
   1.902 +    if (strlist != NULL)
   1.903      {
   1.904 -	    g_object_unref (strlist);
   1.905 -	    strlist = NULL;
   1.906 +        g_object_unref (strlist);
   1.907 +        strlist = NULL;
   1.908      }
   1.909  
   1.910 -    if (ret_strlist!=NULL)
   1.911 +    if (ret_strlist != NULL)
   1.912      {
   1.913 -	    g_object_unref (ret_strlist);
   1.914 -	    ret_strlist = NULL;
   1.915 +        g_object_unref (ret_strlist);
   1.916 +        ret_strlist = NULL;
   1.917      }
   1.918  
   1.919 -    if (read_unlimited && (bytes_sent == 0)) {
   1.920 -		gmyth_debug( "Trying to move to the next program chain..." );
   1.921 -		if (priv->recorder != NULL &&
   1.922 -			priv->do_next_program_chain)
   1.923 -		{
   1.924 -		    retval = GMYTH_FILE_READ_NEXT_PROG_CHAIN;
   1.925 -	  		GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info (priv->recorder);
   1.926 -	  		
   1.927 -	  		if (prog_info != NULL && prog_info->pathname != NULL && strlen( prog_info->pathname->str ) > 0 &&
   1.928 -	  						g_ascii_strcasecmp( prog_info->pathname->str, 
   1.929 -                                    gmyth_file_get_file_name( GMYTH_FILE(transfer) ) ) != 0 )
   1.930 -	  			ret = gmyth_file_transfer_open (transfer, g_strrstr( prog_info->pathname->str, "/" ) );
   1.931 -	  		
   1.932 -	  		if (prog_info != NULL )
   1.933 -	  			g_object_unref( prog_info );
   1.934 -	  			
   1.935 -			if ( !ret )
   1.936 -				gmyth_debug( "Cannot change to the next program info!" );
   1.937 -			else
   1.938 -				gmyth_debug( "OK!!! MOVED to the next program info [%s]!", 
   1.939 -										gmyth_file_get_file_name( GMYTH_FILE(transfer) ) );						
   1.940 -		}
   1.941 +    if (read_unlimited && (bytes_sent == 0))
   1.942 +    {
   1.943 +        gmyth_debug ("Trying to move to the next program chain...");
   1.944 +        if (priv->recorder != NULL && priv->do_next_program_chain)
   1.945 +        {
   1.946 +            retval = GMYTH_FILE_READ_NEXT_PROG_CHAIN;
   1.947 +            GMythProgramInfo *prog_info =
   1.948 +                gmyth_recorder_get_current_program_info (priv->recorder);
   1.949  
   1.950 -    } /* if */
   1.951 +            if (prog_info != NULL && prog_info->pathname != NULL
   1.952 +                && strlen (prog_info->pathname->str) > 0
   1.953 +                && g_ascii_strcasecmp (prog_info->pathname->str,
   1.954 +                                       gmyth_file_get_file_name (GMYTH_FILE
   1.955 +                                                                 (transfer))) !=
   1.956 +                0)
   1.957 +                ret =
   1.958 +                    gmyth_file_transfer_open (transfer,
   1.959 +                                              g_strrstr (prog_info->pathname->
   1.960 +                                                         str, "/"));
   1.961  
   1.962 -error:    
   1.963 -  
   1.964 +            if (prog_info != NULL)
   1.965 +                g_object_unref (prog_info);
   1.966 +
   1.967 +            if (!ret)
   1.968 +                gmyth_debug ("Cannot change to the next program info!");
   1.969 +            else
   1.970 +                gmyth_debug ("OK!!! MOVED to the next program info [%s]!",
   1.971 +                             gmyth_file_get_file_name (GMYTH_FILE (transfer)));
   1.972 +        }
   1.973 +
   1.974 +    }                           /* if */
   1.975 +
   1.976 +  error:
   1.977 +
   1.978      _control_release_context (transfer);
   1.979      g_string_free (query, TRUE);
   1.980  
   1.981 -    if ( error != NULL ) {
   1.982 -        gmyth_debug ("Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message, 
   1.983 -	        error->code);
   1.984 +    if (error != NULL)
   1.985 +    {
   1.986 +        gmyth_debug ("Cleaning-up ERROR: %s [msg = %s, code = %d]\n",
   1.987 +                     __FUNCTION__, error->message, error->code);
   1.988          g_error_free (error);
   1.989      }
   1.990 -  
   1.991 -    if ( total_read > 0 )
   1.992 -  	    gmyth_file_set_offset( GMYTH_FILE(transfer), 
   1.993 -                gmyth_file_get_offset( GMYTH_FILE(transfer) ) + total_read );  	
   1.994 -  	
   1.995 +
   1.996 +    if (total_read > 0)
   1.997 +        gmyth_file_set_offset (GMYTH_FILE (transfer),
   1.998 +                               gmyth_file_get_offset (GMYTH_FILE (transfer)) +
   1.999 +                               total_read);
  1.1000 +
  1.1001      return retval;
  1.1002  }
  1.1003  
  1.1004 -static void 
  1.1005 -_file_transfer_program_info_changed( GMythFileTransfer *transfer, 
  1.1006 -									gint msg_code, gpointer livetv_recorder )
  1.1007 +static void
  1.1008 +_file_transfer_program_info_changed (GMythFileTransfer * transfer,
  1.1009 +                                     gint msg_code, gpointer livetv_recorder)
  1.1010  {
  1.1011 -	GMythRecorder *recorder;
  1.1012 +    GMythRecorder *recorder;
  1.1013      GMythFileTransferPrivate *priv;
  1.1014  
  1.1015      g_return_if_fail (transfer != NULL);
  1.1016  
  1.1017      priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
  1.1018  
  1.1019 -	recorder = GMYTH_RECORDER( livetv_recorder );
  1.1020 -	gmyth_debug( "Program info changed! ( file transfer orig. = %p, ptr. = [%s] )", transfer, 
  1.1021 -		livetv_recorder != NULL ? "[NOT NULL]" : "[NULL]");
  1.1022 -	
  1.1023 -	if ( NULL != recorder )
  1.1024 -	{
  1.1025 -		gmyth_debug( "YES, the requested program info movement on the LiveTV transfer is authentical!" );
  1.1026 -	}
  1.1027 -	
  1.1028 -	priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);	
  1.1029 -	g_object_ref(recorder);
  1.1030 -	priv->recorder = recorder;
  1.1031 -	priv->do_next_program_chain = TRUE;
  1.1032 +    recorder = GMYTH_RECORDER (livetv_recorder);
  1.1033 +    gmyth_debug
  1.1034 +        ("Program info changed! ( file transfer orig. = %p, ptr. = [%s] )",
  1.1035 +         transfer, livetv_recorder != NULL ? "[NOT NULL]" : "[NULL]");
  1.1036 +
  1.1037 +    if (NULL != recorder)
  1.1038 +    {
  1.1039 +        gmyth_debug
  1.1040 +            ("YES, the requested program info movement on the LiveTV transfer is authentical!");
  1.1041 +    }
  1.1042 +
  1.1043 +    priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
  1.1044 +    g_object_ref (recorder);
  1.1045 +    priv->recorder = recorder;
  1.1046 +    priv->do_next_program_chain = TRUE;
  1.1047  }
  1.1048  
  1.1049  /** 
  1.1050 @@ -807,42 +871,43 @@
  1.1051   * 
  1.1052   * @return <code>true</code>, if the acquire had been got. 
  1.1053   */
  1.1054 -gboolean 
  1.1055 -gmyth_file_transfer_settimeout( GMythFileTransfer *transfer, gboolean fast )
  1.1056 +gboolean
  1.1057 +gmyth_file_transfer_settimeout (GMythFileTransfer * transfer, gboolean fast)
  1.1058  {
  1.1059 -  GMythFileTransferPrivate *priv;
  1.1060 -  GMythStringList *strlist = NULL;
  1.1061 +    GMythFileTransferPrivate *priv;
  1.1062 +    GMythStringList *strlist = NULL;
  1.1063  
  1.1064 -  g_return_val_if_fail (transfer != NULL, FALSE);
  1.1065 +    g_return_val_if_fail (transfer != NULL, FALSE);
  1.1066  
  1.1067 -  priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
  1.1068 +    priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
  1.1069  
  1.1070 -  g_return_val_if_fail (priv->sock != NULL, FALSE);
  1.1071 -  g_return_val_if_fail (priv->control_sock != NULL, FALSE);
  1.1072 -  
  1.1073 -  _control_acquire_context (transfer, TRUE );
  1.1074 +    g_return_val_if_fail (priv->sock != NULL, FALSE);
  1.1075 +    g_return_val_if_fail (priv->control_sock != NULL, FALSE);
  1.1076  
  1.1077 -  strlist = gmyth_string_list_new(); 
  1.1078 -  gmyth_string_list_append_char_array( strlist, GMYTHTV_QUERY_HEADER );
  1.1079 -  gmyth_string_list_append_char_array( strlist, "SET_TIMEOUT" );
  1.1080 -  gmyth_string_list_append_int( strlist, fast ); 
  1.1081 +    _control_acquire_context (transfer, TRUE);
  1.1082  
  1.1083 -  gint strlist_len = gmyth_socket_sendreceive_stringlist (priv->control_sock, 
  1.1084 -  				strlist );
  1.1085 -  
  1.1086 -  if ( strlist_len > 0 )
  1.1087 -  	gmyth_debug( "Yes, timeout was changed: %s.", gmyth_string_list_get_char_array( strlist, 0 ) );
  1.1088 -  else
  1.1089 -  	gmyth_debug( "Timeout cannot be changed!" );
  1.1090 -  	
  1.1091 -  _control_release_context (transfer);
  1.1092 +    strlist = gmyth_string_list_new ();
  1.1093 +    gmyth_string_list_append_char_array (strlist, GMYTHTV_QUERY_HEADER);
  1.1094 +    gmyth_string_list_append_char_array (strlist, "SET_TIMEOUT");
  1.1095 +    gmyth_string_list_append_int (strlist, fast);
  1.1096  
  1.1097 -  gmyth_debug ( "%s setting timeout flag of this file transfer = %s\n", 
  1.1098 -  		strlist_len > 0 ? "Yes," : "NOT", fast ? "FAST" : "NOT FAST" );
  1.1099 +    gint strlist_len = gmyth_socket_sendreceive_stringlist (priv->control_sock,
  1.1100 +                                                            strlist);
  1.1101  
  1.1102 -  g_object_unref (strlist);
  1.1103 +    if (strlist_len > 0)
  1.1104 +        gmyth_debug ("Yes, timeout was changed: %s.",
  1.1105 +                     gmyth_string_list_get_char_array (strlist, 0));
  1.1106 +    else
  1.1107 +        gmyth_debug ("Timeout cannot be changed!");
  1.1108  
  1.1109 -  return TRUE;
  1.1110 +    _control_release_context (transfer);
  1.1111 +
  1.1112 +    gmyth_debug ("%s setting timeout flag of this file transfer = %s\n",
  1.1113 +                 strlist_len > 0 ? "Yes," : "NOT", fast ? "FAST" : "NOT FAST");
  1.1114 +
  1.1115 +    g_object_unref (strlist);
  1.1116 +
  1.1117 +    return TRUE;
  1.1118  }
  1.1119  
  1.1120  /** 
  1.1121 @@ -853,13 +918,13 @@
  1.1122   * @return The actual file size in bytes. 
  1.1123   */
  1.1124  guint64
  1.1125 -gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer)
  1.1126 +gmyth_file_transfer_get_filesize (GMythFileTransfer * transfer)
  1.1127  {
  1.1128      guint64 filesize;
  1.1129 -    
  1.1130 +
  1.1131      g_return_val_if_fail (transfer != NULL, 0);
  1.1132 -    
  1.1133 -    g_object_get( GMYTH_FILE(transfer), "file-size", &filesize, NULL );
  1.1134 +
  1.1135 +    g_object_get (GMYTH_FILE (transfer), "file-size", &filesize, NULL);
  1.1136  
  1.1137      return filesize;
  1.1138  }
     2.1 --- a/gmyth/src/gmyth_file_transfer.h	Tue May 15 20:16:26 2007 +0100
     2.2 +++ b/gmyth/src/gmyth_file_transfer.h	Tue May 15 21:39:04 2007 +0100
     2.3 @@ -9,23 +9,23 @@
     2.4   * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     2.5   * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
     2.6   *
     2.7 - *//*
     2.8 - * 
     2.9 - * This program is free software; you can redistribute it and/or modify
    2.10 - * it under the terms of the GNU Lesser General Public License as published by
    2.11 - * the Free Software Foundation; either version 2 of the License, or
    2.12 - * (at your option) any later version.
    2.13 - *
    2.14 - * This program is distributed in the hope that it will be useful,
    2.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.17 - * GNU General Public License for more details.
    2.18 - *
    2.19 - * You should have received a copy of the GNU Lesser General Public License
    2.20 - * along with this program; if not, write to the Free Software
    2.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.22 - */
    2.23 - 
    2.24 +          *//*
    2.25 +       * 
    2.26 +       * This program is free software; you can redistribute it and/or modify
    2.27 +       * it under the terms of the GNU Lesser General Public License as published by
    2.28 +       * the Free Software Foundation; either version 2 of the License, or
    2.29 +       * (at your option) any later version.
    2.30 +       *
    2.31 +       * This program is distributed in the hope that it will be useful,
    2.32 +       * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.33 +       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.34 +       * GNU General Public License for more details.
    2.35 +       *
    2.36 +       * You should have received a copy of the GNU Lesser General Public License
    2.37 +       * along with this program; if not, write to the Free Software
    2.38 +       * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.39 +       */
    2.40 +
    2.41  #ifndef __GMYTH_FILE_TRANSFER_H__
    2.42  #define __GMYTH_FILE_TRANSFER_H__
    2.43  
    2.44 @@ -45,61 +45,58 @@
    2.45  #include <unistd.h>
    2.46  
    2.47  G_BEGIN_DECLS
    2.48 -
    2.49  #define GMYTH_FILE_TRANSFER_TYPE               (gmyth_file_transfer_get_type ())
    2.50  #define GMYTH_FILE_TRANSFER(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransfer))
    2.51  #define GMYTH_FILE_TRANSFER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass))
    2.52  #define IS_GMYTH_FILE_TRANSFER(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMYTH_FILE_TRANSFER_TYPE))
    2.53  #define IS_GMYTH_FILE_TRANSFER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TRANSFER_TYPE))
    2.54  #define GMYTH_FILE_TRANSFER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass))
    2.55 -
    2.56 -typedef struct _GMythFileTransfer         GMythFileTransfer;
    2.57 -typedef struct _GMythFileTransferClass    GMythFileTransferClass;
    2.58 -typedef struct _GMythFileTransferPrivate  GMythFileTransferPrivate;
    2.59 +typedef struct _GMythFileTransfer GMythFileTransfer;
    2.60 +typedef struct _GMythFileTransferClass GMythFileTransferClass;
    2.61 +typedef struct _GMythFileTransferPrivate GMythFileTransferPrivate;
    2.62  
    2.63  struct _GMythFileTransfer
    2.64 -{
    2.65 -	GMythFile 				 parent;
    2.66 -    GMythFileTransferPrivate *priv;
    2.67 -};
    2.68 +    {
    2.69 +        GMythFile parent;
    2.70 +        GMythFileTransferPrivate *priv;
    2.71 +    };
    2.72  
    2.73  struct _GMythFileTransferClass
    2.74 -{
    2.75 -	GMythFileClass parent_class;
    2.76 +    {
    2.77 +        GMythFileClass parent_class;
    2.78  
    2.79 -	/* callbacks */
    2.80 -	guint program_info_changed_handler_signal_id;
    2.81 +        /* callbacks */
    2.82 +        guint program_info_changed_handler_signal_id;
    2.83  
    2.84 -    /* signal default handlers */
    2.85 -    void (*program_info_changed_handler) ( GMythFileTransfer *transfer, 
    2.86 -										gint msg_code, gpointer livetv_recorder );
    2.87 -};
    2.88 +        /* signal default handlers */
    2.89 +        void (*program_info_changed_handler) (GMythFileTransfer * transfer,
    2.90 +                                              gint msg_code,
    2.91 +                                              gpointer livetv_recorder);
    2.92 +    };
    2.93  
    2.94  
    2.95 -GType               gmyth_file_transfer_get_type        (void);
    2.96 -GMythFileTransfer*  gmyth_file_transfer_new             (GMythBackendInfo *backend_info);
    2.97 -gchar*              gmyth_file_transfer_get_file_name   (GMythFileTransfer *transfer);
    2.98 -gboolean            gmyth_file_transfer_open            (GMythFileTransfer *transfer, 
    2.99 -                                					     const gchar* filename);
   2.100 -void                gmyth_file_transfer_close           (GMythFileTransfer *transfer);
   2.101 -gboolean            gmyth_file_transfer_is_open         (GMythFileTransfer *transfer);
   2.102 +GType gmyth_file_transfer_get_type (void);
   2.103 +GMythFileTransfer *gmyth_file_transfer_new (GMythBackendInfo * backend_info);
   2.104 +gchar *gmyth_file_transfer_get_file_name (GMythFileTransfer * transfer);
   2.105 +gboolean gmyth_file_transfer_open (GMythFileTransfer * transfer,
   2.106 +                                   const gchar * filename);
   2.107 +void gmyth_file_transfer_close (GMythFileTransfer * transfer);
   2.108 +gboolean gmyth_file_transfer_is_open (GMythFileTransfer * transfer);
   2.109  GMythFileReadResult
   2.110 -                    gmyth_file_transfer_read            (GMythFileTransfer *transfer, 
   2.111 -                                                         GByteArray *data, 
   2.112 -                                                         gint size, 
   2.113 -                                                         gboolean read_unlimited);
   2.114 -gint64              gmyth_file_transfer_seek            (GMythFileTransfer *transfer, 
   2.115 -                                                         guint64 pos, 
   2.116 -                                                         gint whence);
   2.117 -gboolean            gmyth_file_transfer_settimeout      (GMythFileTransfer *transfer, 
   2.118 -                                                         gboolean fast);
   2.119 -guint64             gmyth_file_transfer_get_filesize    (GMythFileTransfer *transfer);
   2.120 +gmyth_file_transfer_read (GMythFileTransfer * transfer,
   2.121 +                          GByteArray * data,
   2.122 +                          gint size, gboolean read_unlimited);
   2.123 +gint64 gmyth_file_transfer_seek (GMythFileTransfer * transfer,
   2.124 +                                 guint64 pos, gint whence);
   2.125 +gboolean gmyth_file_transfer_settimeout (GMythFileTransfer * transfer,
   2.126 +                                         gboolean fast);
   2.127 +guint64 gmyth_file_transfer_get_filesize (GMythFileTransfer * transfer);
   2.128  
   2.129 -void                gmyth_file_transfer_emit_program_info_changed_signal ( 
   2.130 -                                                        GMythFileTransfer *transfer, 
   2.131 -														gint msg_code,
   2.132 -														gpointer live_tv_recorder );
   2.133 +void gmyth_file_transfer_emit_program_info_changed_signal (GMythFileTransfer *
   2.134 +                                                           transfer,
   2.135 +                                                           gint msg_code,
   2.136 +                                                           gpointer
   2.137 +                                                           live_tv_recorder);
   2.138  
   2.139  G_END_DECLS
   2.140 -
   2.141  #endif /* __GMYTH_FILE_TRANSFER_H__ */
     3.1 --- a/gmyth/src/gmyth_livetv.c	Tue May 15 20:16:26 2007 +0100
     3.2 +++ b/gmyth/src/gmyth_livetv.c	Tue May 15 21:39:04 2007 +0100
     3.3 @@ -8,28 +8,28 @@
     3.4   * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     3.5   * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
     3.6   *
     3.7 - *//*
     3.8 - * 
     3.9 - * This program is free software; you can redistribute it and/or modify
    3.10 - * it under the terms of the GNU Lesser General Public License as published by
    3.11 - * the Free Software Foundation; either version 2 of the License, or
    3.12 - * (at your option) any later version.
    3.13 - *
    3.14 - * This program is distributed in the hope that it will be useful,
    3.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.17 - * GNU General Public License for more details.
    3.18 - *
    3.19 - * You should have received a copy of the GNU Lesser General Public License
    3.20 - * along with this program; if not, write to the Free Software
    3.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.22 - */
    3.23 -  
    3.24 +          *//*
    3.25 +       * 
    3.26 +       * This program is free software; you can redistribute it and/or modify
    3.27 +       * it under the terms of the GNU Lesser General Public License as published by
    3.28 +       * the Free Software Foundation; either version 2 of the License, or
    3.29 +       * (at your option) any later version.
    3.30 +       *
    3.31 +       * This program is distributed in the hope that it will be useful,
    3.32 +       * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.33 +       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.34 +       * GNU General Public License for more details.
    3.35 +       *
    3.36 +       * You should have received a copy of the GNU Lesser General Public License
    3.37 +       * along with this program; if not, write to the Free Software
    3.38 +       * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.39 +       */
    3.40 +
    3.41  #ifdef HAVE_CONFIG_H
    3.42  #include "config.h"
    3.43  #endif
    3.44  
    3.45 -#include "gmyth_livetv.h" 
    3.46 +#include "gmyth_livetv.h"
    3.47  #include "gmyth_remote_util.h"
    3.48  #include "gmyth_tvchain.h"
    3.49  #include "gmyth_socket.h"
    3.50 @@ -44,122 +44,131 @@
    3.51  #include "gmyth_common.h"
    3.52  #include "gmyth_util.h"
    3.53  
    3.54 -static void gmyth_livetv_class_init          (GMythLiveTVClass *klass);
    3.55 -static void gmyth_livetv_init                (GMythLiveTV *object);
    3.56 +static void gmyth_livetv_class_init (GMythLiveTVClass * klass);
    3.57 +static void gmyth_livetv_init (GMythLiveTV * object);
    3.58  
    3.59 -static void gmyth_livetv_dispose  (GObject *object);
    3.60 -static void gmyth_livetv_finalize (GObject *object);
    3.61 +static void gmyth_livetv_dispose (GObject * object);
    3.62 +static void gmyth_livetv_finalize (GObject * object);
    3.63  
    3.64 -static gint tvchain_curr_index = -1; 
    3.65 +static gint tvchain_curr_index = -1;
    3.66  
    3.67  /*static GStaticMutex lock = G_STATIC_MUTEX_INIT;*/
    3.68  
    3.69  #define GMYTHTV_TRANSFER_MAX_WAITS	    100
    3.70  
    3.71 -G_DEFINE_TYPE(GMythLiveTV, gmyth_livetv, G_TYPE_OBJECT)
    3.72 +G_DEFINE_TYPE (GMythLiveTV, gmyth_livetv, G_TYPE_OBJECT)
    3.73 +     static void gmyth_livetv_class_init (GMythLiveTVClass * klass)
    3.74 +{
    3.75 +    GObjectClass *gobject_class;
    3.76  
    3.77 -static void
    3.78 -gmyth_livetv_class_init (GMythLiveTVClass *klass)
    3.79 -{
    3.80 -	GObjectClass *gobject_class;
    3.81 +    gobject_class = (GObjectClass *) klass;
    3.82  
    3.83 -	gobject_class = (GObjectClass *) klass;
    3.84 -
    3.85 -	gobject_class->dispose  = gmyth_livetv_dispose;
    3.86 -	gobject_class->finalize = gmyth_livetv_finalize;	
    3.87 +    gobject_class->dispose = gmyth_livetv_dispose;
    3.88 +    gobject_class->finalize = gmyth_livetv_finalize;
    3.89  }
    3.90  
    3.91  static void
    3.92 -gmyth_livetv_init (GMythLiveTV *livetv)
    3.93 +gmyth_livetv_init (GMythLiveTV * livetv)
    3.94  {
    3.95      livetv->monitor = NULL;
    3.96 -	livetv->backend_info = NULL;
    3.97 -	livetv->local_hostname = NULL;
    3.98 -	livetv->file = NULL;
    3.99 -	livetv->setup_done = FALSE;
   3.100 -	
   3.101 -	livetv->socket = NULL;
   3.102 -	livetv->recorder = NULL;
   3.103 -	livetv->tvchain = NULL;
   3.104 -	livetv->proginfo = NULL;
   3.105 -	livetv->uri = NULL;
   3.106 -	
   3.107 -	livetv->mutex = g_mutex_new();
   3.108 +    livetv->backend_info = NULL;
   3.109 +    livetv->local_hostname = NULL;
   3.110 +    livetv->file = NULL;
   3.111 +    livetv->setup_done = FALSE;
   3.112 +
   3.113 +    livetv->socket = NULL;
   3.114 +    livetv->recorder = NULL;
   3.115 +    livetv->tvchain = NULL;
   3.116 +    livetv->proginfo = NULL;
   3.117 +    livetv->uri = NULL;
   3.118 +
   3.119 +    livetv->mutex = g_mutex_new ();
   3.120  }
   3.121  
   3.122  static void
   3.123 -gmyth_livetv_dispose  (GObject *object)
   3.124 -{	
   3.125 -	GMythLiveTV *livetv = GMYTH_LIVETV (object);
   3.126 +gmyth_livetv_dispose (GObject * object)
   3.127 +{
   3.128 +    GMythLiveTV *livetv = GMYTH_LIVETV (object);
   3.129  
   3.130 -    if (livetv->disposed) {
   3.131 +    if (livetv->disposed)
   3.132 +    {
   3.133          /* If dispose did already run, return. */
   3.134          return;
   3.135      }
   3.136 -    
   3.137 +
   3.138      /* Make sure dispose does not run twice. */
   3.139      livetv->disposed = TRUE;
   3.140  
   3.141 -	if ( livetv->monitor != NULL ) {
   3.142 -		g_object_unref (livetv->monitor);
   3.143 -		livetv->monitor = NULL;
   3.144 -	}
   3.145 -    
   3.146 -    if ( livetv->file != NULL ) {
   3.147 +    if (livetv->monitor != NULL)
   3.148 +    {
   3.149 +        g_object_unref (livetv->monitor);
   3.150 +        livetv->monitor = NULL;
   3.151 +    }
   3.152 +
   3.153 +    if (livetv->file != NULL)
   3.154 +    {
   3.155          g_object_unref (livetv->file);
   3.156          livetv->file = NULL;
   3.157      }
   3.158 -	
   3.159 -	if ( livetv->recorder != NULL ) {
   3.160 +
   3.161 +    if (livetv->recorder != NULL)
   3.162 +    {
   3.163          //gmyth_recorder_close(livetv->recorder);
   3.164 -		g_object_unref (livetv->recorder);
   3.165 -		livetv->recorder = NULL;
   3.166 -	}
   3.167 +        g_object_unref (livetv->recorder);
   3.168 +        livetv->recorder = NULL;
   3.169 +    }
   3.170  
   3.171 -	if ( livetv->socket != NULL ) {
   3.172 -		g_object_unref (livetv->socket);
   3.173 -		livetv->socket = NULL;
   3.174 -	}
   3.175 -	
   3.176 -	if ( livetv->tvchain != NULL ) {
   3.177 -		g_object_unref (livetv->tvchain);
   3.178 -		livetv->tvchain = NULL;
   3.179 -	}
   3.180 +    if (livetv->socket != NULL)
   3.181 +    {
   3.182 +        g_object_unref (livetv->socket);
   3.183 +        livetv->socket = NULL;
   3.184 +    }
   3.185  
   3.186 -	if ( livetv->proginfo != NULL ) {
   3.187 -		g_object_unref (livetv->proginfo);
   3.188 -		livetv->proginfo = NULL;
   3.189 -	}
   3.190 -	
   3.191 -	if ( livetv->backend_info != NULL ) {
   3.192 -		g_object_unref (livetv->backend_info);
   3.193 -		livetv->backend_info = NULL;
   3.194 -	}
   3.195 -	
   3.196 -	if ( livetv->uri != NULL ) {
   3.197 -		g_object_unref (livetv->uri);
   3.198 -		livetv->uri = NULL;
   3.199 -	}
   3.200 -	
   3.201 -	if ( livetv->mutex != NULL ) {
   3.202 -		g_mutex_free (livetv->mutex);
   3.203 -		livetv->mutex = NULL;
   3.204 -	}
   3.205 -    
   3.206 -    if ( livetv->local_hostname != NULL ) {
   3.207 +    if (livetv->tvchain != NULL)
   3.208 +    {
   3.209 +        g_object_unref (livetv->tvchain);
   3.210 +        livetv->tvchain = NULL;
   3.211 +    }
   3.212 +
   3.213 +    if (livetv->proginfo != NULL)
   3.214 +    {
   3.215 +        g_object_unref (livetv->proginfo);
   3.216 +        livetv->proginfo = NULL;
   3.217 +    }
   3.218 +
   3.219 +    if (livetv->backend_info != NULL)
   3.220 +    {
   3.221 +        g_object_unref (livetv->backend_info);
   3.222 +        livetv->backend_info = NULL;
   3.223 +    }
   3.224 +
   3.225 +    if (livetv->uri != NULL)
   3.226 +    {
   3.227 +        g_object_unref (livetv->uri);
   3.228 +        livetv->uri = NULL;
   3.229 +    }
   3.230 +
   3.231 +    if (livetv->mutex != NULL)
   3.232 +    {
   3.233 +        g_mutex_free (livetv->mutex);
   3.234 +        livetv->mutex = NULL;
   3.235 +    }
   3.236 +
   3.237 +    if (livetv->local_hostname != NULL)
   3.238 +    {
   3.239          g_string_free (livetv->local_hostname, TRUE);
   3.240          livetv->local_hostname = NULL;
   3.241      }
   3.242  
   3.243 -	G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
   3.244 +    G_OBJECT_CLASS (gmyth_livetv_parent_class)->dispose (object);
   3.245  }
   3.246  
   3.247  static void
   3.248 -gmyth_livetv_finalize (GObject *object)
   3.249 +gmyth_livetv_finalize (GObject * object)
   3.250  {
   3.251 -	g_signal_handlers_destroy (object);
   3.252 +    g_signal_handlers_destroy (object);
   3.253  
   3.254 -	G_OBJECT_CLASS ( gmyth_livetv_parent_class )->finalize ( object );
   3.255 +    G_OBJECT_CLASS (gmyth_livetv_parent_class)->finalize (object);
   3.256  }
   3.257  
   3.258  /**
   3.259 @@ -167,15 +176,15 @@
   3.260   * 
   3.261   * @return a newly allocated GMythLiveTV instance
   3.262   */
   3.263 -GMythLiveTV*
   3.264 -gmyth_livetv_new (GMythBackendInfo *backend_info)
   3.265 +GMythLiveTV *
   3.266 +gmyth_livetv_new (GMythBackendInfo * backend_info)
   3.267  {
   3.268 -	GMythLiveTV *livetv = GMYTH_LIVETV ( g_object_new( GMYTH_LIVETV_TYPE, NULL ) );
   3.269 -    
   3.270 -	livetv->backend_info = backend_info;
   3.271 +    GMythLiveTV *livetv = GMYTH_LIVETV (g_object_new (GMYTH_LIVETV_TYPE, NULL));
   3.272 +
   3.273 +    livetv->backend_info = backend_info;
   3.274      g_object_ref (livetv->backend_info);
   3.275  
   3.276 -	return livetv;
   3.277 +    return livetv;
   3.278  }
   3.279  
   3.280  /**
   3.281 @@ -189,83 +198,107 @@
   3.282   * @param user_data pointer to the GMythLiveTV instance
   3.283   */
   3.284  static void
   3.285 -gmyth_livetv_monitor_signal_handler( GMythMonitorHandler *monitor, gint msg_code, 
   3.286 -							gchar* message, gpointer user_data )
   3.287 +gmyth_livetv_monitor_signal_handler (GMythMonitorHandler * monitor,
   3.288 +                                     gint msg_code, gchar * message,
   3.289 +                                     gpointer user_data)
   3.290  {
   3.291 -	GMythLiveTV *live_tv = GMYTH_LIVETV ( user_data );
   3.292 -	
   3.293 -	gmyth_debug( "LIVETV Signal handler ( msg = %s, code = %d, live_tv param = %s, user_data = %s )\n", message, msg_code, live_tv != NULL ? "" : 
   3.294 -					"NULL", user_data != NULL ? "" : "NULL" );
   3.295 -	
   3.296 -	if ( NULL == live_tv || !IS_GMYTH_FILE_TRANSFER( live_tv->file ) )
   3.297 -	{
   3.298 -		gmyth_debug( "LiveTV_obj is equals to NULL!!!" );
   3.299 -		return;
   3.300 -	}		
   3.301 -	
   3.302 -	switch ( msg_code ) 
   3.303 -	{
   3.304 -		
   3.305 -		case GMYTH_BACKEND_PROGRAM_INFO_CHANGED:
   3.306 -		{
   3.307 -			gmyth_debug( "LIVETV Program Changed request received [ msg = %s ]. Watching if the new "\
   3.308 -				"TV Chain ID is the same as the old one...\n", message );
   3.309 -			if ( g_ascii_strcasecmp ( message, (gmyth_tvchain_get_id( live_tv->tvchain ))->str ) != 0 ) {				
   3.310 -				gmyth_debug( "OK!!! MOVED to the next program chain [actual == %s]!", 
   3.311 -										(gmyth_tvchain_get_id( live_tv->tvchain ))->str );
   3.312 -				/* advertises the FileTransfer about the program info changed */
   3.313 -				if ( live_tv->file != NULL )
   3.314 -				{
   3.315 -					gmyth_debug( "Emitting signal to the FileTransfer... [ \"program-info-changed \" ]" );
   3.316 -					
   3.317 -					gmyth_file_transfer_emit_program_info_changed_signal( GMYTH_FILE_TRANSFER(live_tv->file),
   3.318 -		             msg_code, (gpointer)(live_tv->recorder) );
   3.319 -		             
   3.320 -					/* gmyth_livetv_monitor_handler_stop( live_tv ); */
   3.321 -				} else
   3.322 -					gmyth_debug( "LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");				
   3.323 -			}
   3.324 -			break;
   3.325 -		}
   3.326 -		case GMYTH_BACKEND_DONE_RECORDING:
   3.327 -		{
   3.328 -			gmyth_debug( "LIVETV Program Changed request received [ msg = %s ]. Watching if the new "\
   3.329 -				"TV Chain ID is the same as the old one...\n", message );
   3.330 -			if ( g_ascii_strcasecmp ( message, (gmyth_tvchain_get_id( live_tv->tvchain ))->str ) != 0 ) {				
   3.331 -				gmyth_debug( "OK!!! MOVED to the next program chain [actual == %s]!", 
   3.332 -										(gmyth_tvchain_get_id( live_tv->tvchain ))->str );
   3.333 -				/* advertises the FileTransfer about the program info changed */
   3.334 -				if ( live_tv->file != NULL )
   3.335 -				{
   3.336 -					gmyth_debug( "Emitting signal to the FileTransfer... [ \"backend-done-recording\" ]" );
   3.337 -					
   3.338 -					gmyth_file_transfer_emit_program_info_changed_signal( GMYTH_FILE_TRANSFER(live_tv->file),
   3.339 -		             msg_code, (gpointer)(live_tv->recorder) );
   3.340 -		             
   3.341 -				} else
   3.342 -					gmyth_debug( "LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");				
   3.343 -			}
   3.344 -			break;
   3.345 -		}
   3.346 -		case GMYTH_BACKEND_STOP_LIVETV:
   3.347 -		{
   3.348 -			gmyth_debug( "LIVETV Stop LiveTV request received [ msg = %s ]. Going out the "\
   3.349 -				"LiveTV...\n", message );
   3.350 -			/* stops the LiveTV */
   3.351 -			if ( live_tv != NULL )
   3.352 -			{
   3.353 -				gmyth_debug( "Going out the LiveTV... [ \"quit-livetv\" ]" );
   3.354 -				
   3.355 -				g_object_unref( live_tv );
   3.356 -			} else
   3.357 -				gmyth_debug( "LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");				
   3.358 -			
   3.359 -			break;
   3.360 -		}
   3.361 -		default:
   3.362 -			break;		
   3.363 -	} /* switch (Monitor Handler messages) */
   3.364 -	
   3.365 +    GMythLiveTV *live_tv = GMYTH_LIVETV (user_data);
   3.366 +
   3.367 +    gmyth_debug
   3.368 +        ("LIVETV Signal handler ( msg = %s, code = %d, live_tv param = %s, user_data = %s )\n",
   3.369 +         message, msg_code, live_tv != NULL ? "" : "NULL",
   3.370 +         user_data != NULL ? "" : "NULL");
   3.371 +
   3.372 +    if (NULL == live_tv || !IS_GMYTH_FILE_TRANSFER (live_tv->file))
   3.373 +    {
   3.374 +        gmyth_debug ("LiveTV_obj is equals to NULL!!!");
   3.375 +        return;
   3.376 +    }
   3.377 +
   3.378 +    switch (msg_code)
   3.379 +    {
   3.380 +
   3.381 +        case GMYTH_BACKEND_PROGRAM_INFO_CHANGED:
   3.382 +            {
   3.383 +                gmyth_debug
   3.384 +                    ("LIVETV Program Changed request received [ msg = %s ]. Watching if the new "
   3.385 +                     "TV Chain ID is the same as the old one...\n", message);
   3.386 +                if (g_ascii_strcasecmp
   3.387 +                    (message,
   3.388 +                     (gmyth_tvchain_get_id (live_tv->tvchain))->str) != 0)
   3.389 +                {
   3.390 +                    gmyth_debug
   3.391 +                        ("OK!!! MOVED to the next program chain [actual == %s]!",
   3.392 +                         (gmyth_tvchain_get_id (live_tv->tvchain))->str);
   3.393 +                    /* advertises the FileTransfer about the program info changed */
   3.394 +                    if (live_tv->file != NULL)
   3.395 +                    {
   3.396 +                        gmyth_debug
   3.397 +                            ("Emitting signal to the FileTransfer... [ \"program-info-changed \" ]");
   3.398 +
   3.399 +                        gmyth_file_transfer_emit_program_info_changed_signal
   3.400 +                            (GMYTH_FILE_TRANSFER (live_tv->file), msg_code,
   3.401 +                             (gpointer) (live_tv->recorder));
   3.402 +
   3.403 +                        /* gmyth_livetv_monitor_handler_stop( live_tv ); */
   3.404 +                    }
   3.405 +                    else
   3.406 +                        gmyth_debug
   3.407 +                            ("LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");
   3.408 +                }
   3.409 +                break;
   3.410 +            }
   3.411 +        case GMYTH_BACKEND_DONE_RECORDING:
   3.412 +            {
   3.413 +                gmyth_debug
   3.414 +                    ("LIVETV Program Changed request received [ msg = %s ]. Watching if the new "
   3.415 +                     "TV Chain ID is the same as the old one...\n", message);
   3.416 +                if (g_ascii_strcasecmp
   3.417 +                    (message,
   3.418 +                     (gmyth_tvchain_get_id (live_tv->tvchain))->str) != 0)
   3.419 +                {
   3.420 +                    gmyth_debug
   3.421 +                        ("OK!!! MOVED to the next program chain [actual == %s]!",
   3.422 +                         (gmyth_tvchain_get_id (live_tv->tvchain))->str);
   3.423 +                    /* advertises the FileTransfer about the program info changed */
   3.424 +                    if (live_tv->file != NULL)
   3.425 +                    {
   3.426 +                        gmyth_debug
   3.427 +                            ("Emitting signal to the FileTransfer... [ \"backend-done-recording\" ]");
   3.428 +
   3.429 +                        gmyth_file_transfer_emit_program_info_changed_signal
   3.430 +                            (GMYTH_FILE_TRANSFER (live_tv->file), msg_code,
   3.431 +                             (gpointer) (live_tv->recorder));
   3.432 +
   3.433 +                    }
   3.434 +                    else
   3.435 +                        gmyth_debug
   3.436 +                            ("LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");
   3.437 +                }
   3.438 +                break;
   3.439 +            }
   3.440 +        case GMYTH_BACKEND_STOP_LIVETV:
   3.441 +            {
   3.442 +                gmyth_debug
   3.443 +                    ("LIVETV Stop LiveTV request received [ msg = %s ]. Going out the "
   3.444 +                     "LiveTV...\n", message);
   3.445 +                /* stops the LiveTV */
   3.446 +                if (live_tv != NULL)
   3.447 +                {
   3.448 +                    gmyth_debug ("Going out the LiveTV... [ \"quit-livetv\" ]");
   3.449 +
   3.450 +                    g_object_unref (live_tv);
   3.451 +                }
   3.452 +                else
   3.453 +                    gmyth_debug
   3.454 +                        ("LIVETV file_transfer is NULL!!! Cannot move to the next program chain event received.\n");
   3.455 +
   3.456 +                break;
   3.457 +            }
   3.458 +        default:
   3.459 +            break;
   3.460 +    }                           /* switch (Monitor Handler messages) */
   3.461 +
   3.462  }
   3.463  
   3.464  /**
   3.465 @@ -278,44 +311,50 @@
   3.466   * 	   had been concluded succcesfully 
   3.467   */
   3.468  gboolean
   3.469 -gmyth_livetv_monitor_handler_start( GMythLiveTV *livetv )
   3.470 +gmyth_livetv_monitor_handler_start (GMythLiveTV * livetv)
   3.471  {
   3.472 -	gboolean res = TRUE;
   3.473 -	
   3.474 -	if ( livetv->monitor != NULL )
   3.475 -	{
   3.476 -		g_object_unref( livetv->monitor );
   3.477 -		livetv->monitor	= NULL;
   3.478 -	}
   3.479 -	
   3.480 -  livetv->monitor = gmyth_monitor_handler_new ( );
   3.481 -  
   3.482 -  res = gmyth_monitor_handler_open (livetv->monitor, livetv->backend_info->hostname, 
   3.483 -  				livetv->backend_info->port );
   3.484 -  
   3.485 -  if ( res == TRUE )
   3.486 -  {
   3.487 -  	gmyth_debug("Connect MythTV Monitor event socket! Trying to start the message handler...");
   3.488 -  	
   3.489 -  	res = gmyth_monitor_handler_start ( livetv->monitor );
   3.490 -  	
   3.491 -  	if (res)
   3.492 -  	{
   3.493 -  		gmyth_debug("MythTV Monitor event socket connected and listening!");
   3.494 -  		g_signal_connect ( G_OBJECT (livetv->monitor), "backend-events-handler",
   3.495 -                  (GCallback)gmyth_livetv_monitor_signal_handler,
   3.496 -                  livetv );
   3.497 -  	}
   3.498 -  	else
   3.499 -  	{
   3.500 -  		gmyth_debug("Problems when trying to start MythTV Monitor event socket!");
   3.501 -  		goto error;  		
   3.502 -  	}
   3.503 -  }
   3.504 -  
   3.505 -error:
   3.506 -	return res;
   3.507 -  
   3.508 +    gboolean res = TRUE;
   3.509 +
   3.510 +    if (livetv->monitor != NULL)
   3.511 +    {
   3.512 +        g_object_unref (livetv->monitor);
   3.513 +        livetv->monitor = NULL;
   3.514 +    }
   3.515 +
   3.516 +    livetv->monitor = gmyth_monitor_handler_new ();
   3.517 +
   3.518 +    res =
   3.519 +        gmyth_monitor_handler_open (livetv->monitor,
   3.520 +                                    livetv->backend_info->hostname,
   3.521 +                                    livetv->backend_info->port);
   3.522 +
   3.523 +    if (res == TRUE)
   3.524 +    {
   3.525 +        gmyth_debug
   3.526 +            ("Connect MythTV Monitor event socket! Trying to start the message handler...");
   3.527 +
   3.528 +        res = gmyth_monitor_handler_start (livetv->monitor);
   3.529 +
   3.530 +        if (res)
   3.531 +        {
   3.532 +            gmyth_debug
   3.533 +                ("MythTV Monitor event socket connected and listening!");
   3.534 +            g_signal_connect (G_OBJECT (livetv->monitor),
   3.535 +                              "backend-events-handler",
   3.536 +                              (GCallback) gmyth_livetv_monitor_signal_handler,
   3.537 +                              livetv);
   3.538 +        }
   3.539 +        else
   3.540 +        {
   3.541 +            gmyth_debug
   3.542 +                ("Problems when trying to start MythTV Monitor event socket!");
   3.543 +            goto error;
   3.544 +        }
   3.545 +    }
   3.546 +
   3.547 +  error:
   3.548 +    return res;
   3.549 +
   3.550  }
   3.551  
   3.552  /**
   3.553 @@ -328,27 +367,25 @@
   3.554   * 	   had been concluded succcesfully 
   3.555   */
   3.556  void
   3.557 -gmyth_livetv_monitor_handler_stop( GMythLiveTV *livetv )
   3.558 +gmyth_livetv_monitor_handler_stop (GMythLiveTV * livetv)
   3.559  {
   3.560 -	
   3.561 -  if ( livetv->monitor != NULL )
   3.562 -  {
   3.563 -  	g_object_unref( livetv->monitor );
   3.564 -  	livetv->monitor = NULL;
   3.565 -  } 
   3.566 -  
   3.567 +
   3.568 +    if (livetv->monitor != NULL)
   3.569 +    {
   3.570 +        g_object_unref (livetv->monitor);
   3.571 +        livetv->monitor = NULL;
   3.572 +    }
   3.573 +
   3.574  }
   3.575  
   3.576  #if 0
   3.577 -static gchar*
   3.578 -gmyth_livetv_create_remote_url( GMythLiveTV *livetv )
   3.579 +static gchar *
   3.580 +gmyth_livetv_create_remote_url (GMythLiveTV * livetv)
   3.581  {
   3.582 -	gchar *uri = g_strdup("");
   3.583 -	gmyth_backend_info_get_remote_h
   3.584 -	
   3.585 -	//gmyth_backend(livetv->backend_info)
   3.586 -	
   3.587 -	return uri;
   3.588 +    gchar *uri = g_strdup ("");
   3.589 +    gmyth_backend_info_get_remote_h
   3.590 +        //gmyth_backend(livetv->backend_info)
   3.591 +        return uri;
   3.592  }
   3.593  #endif
   3.594  
   3.595 @@ -365,238 +402,280 @@
   3.596   * 				had been concluded succcesfully 
   3.597   */
   3.598  static gboolean
   3.599 -gmyth_livetv_setup_recorder_channel_name (GMythLiveTV *livetv, gchar* channel)
   3.600 +gmyth_livetv_setup_recorder_channel_name (GMythLiveTV * livetv, gchar * channel)
   3.601  {
   3.602 -	gboolean res = TRUE;
   3.603 -    
   3.604 +    gboolean res = TRUE;
   3.605 +
   3.606      g_return_val_if_fail (livetv != NULL, FALSE);
   3.607 -    
   3.608 -	if ( NULL == livetv->socket ) {
   3.609 -		livetv->socket = gmyth_socket_new ();
   3.610 -		
   3.611 -		/* FIME: Implement this at gmyth_socket */
   3.612 -		res = gmyth_socket_connect_to_backend (livetv->socket, livetv->backend_info->hostname,
   3.613 -				livetv->backend_info->port, TRUE);
   3.614 -		if (!res) {
   3.615 -			gmyth_debug ("[%s] LiveTV can not connect to backend", __FUNCTION__);	
   3.616 -			res = FALSE;
   3.617 -			goto error;
   3.618 -		}
   3.619 -	}
   3.620 -	
   3.621 -	g_mutex_lock( livetv->mutex );
   3.622 -	
   3.623 -	livetv->is_livetv = TRUE;
   3.624 -	
   3.625 -	livetv->local_hostname  = gmyth_socket_get_local_hostname ();
   3.626  
   3.627 -	if ( livetv->local_hostname == NULL ) {
   3.628 -		res = FALSE;
   3.629 -		goto error;
   3.630 -	}
   3.631 -	
   3.632 -	if  ( livetv->recorder != NULL )
   3.633 -	{
   3.634 -		g_object_unref( livetv->recorder );
   3.635 -		livetv->recorder= NULL;
   3.636 -	} 
   3.637 -	
   3.638 -	if ( gmyth_remote_util_get_free_recorder_count (livetv->socket) <= 0 ) {
   3.639 -		gmyth_debug ("No free remote encoder available.");
   3.640 -		res = FALSE;
   3.641 -		goto error;
   3.642 -	}
   3.643 +    if (NULL == livetv->socket)
   3.644 +    {
   3.645 +        livetv->socket = gmyth_socket_new ();
   3.646  
   3.647 -	/* Gets the recorder num */
   3.648 -	livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1);
   3.649 -	gmyth_socket_close_connection (livetv->socket);
   3.650 +        /* FIME: Implement this at gmyth_socket */
   3.651 +        res =
   3.652 +            gmyth_socket_connect_to_backend (livetv->socket,
   3.653 +                                             livetv->backend_info->hostname,
   3.654 +                                             livetv->backend_info->port, TRUE);
   3.655 +        if (!res)
   3.656 +        {
   3.657 +            gmyth_debug ("[%s] LiveTV can not connect to backend",
   3.658 +                         __FUNCTION__);
   3.659 +            res = FALSE;
   3.660 +            goto error;
   3.661 +        }
   3.662 +    }
   3.663  
   3.664 -	if ( NULL == livetv->recorder ) {
   3.665 -		gmyth_debug ("[%s] None remote encoder available", __FUNCTION__);
   3.666 -		res = FALSE;
   3.667 -		goto error;
   3.668 -	}
   3.669 -	
   3.670 -	/* Init remote encoder. Opens its control socket. */
   3.671 -	res = gmyth_recorder_setup(livetv->recorder);
   3.672 -	if ( !res ) {
   3.673 -		gmyth_debug ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
   3.674 -		res = FALSE;
   3.675 -		goto error;
   3.676 -	}
   3.677 -    
   3.678 -	/* Creates livetv chain handler */
   3.679 -	livetv->tvchain = gmyth_tvchain_new();
   3.680 -	gmyth_tvchain_initialize ( livetv->tvchain, livetv->backend_info );
   3.681 +    g_mutex_lock (livetv->mutex);
   3.682  
   3.683 -	if ( livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL ) {
   3.684 -		res = FALSE;
   3.685 -		goto error;
   3.686 -	}
   3.687 -	
   3.688 -	// Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
   3.689 -	res = gmyth_recorder_spawntv ( livetv->recorder,
   3.690 -			gmyth_tvchain_get_id(livetv->tvchain) );
   3.691 -	if (!res) {
   3.692 -		gmyth_debug ("[%s] Fail while spawn tv\n", __FUNCTION__);
   3.693 -		res = FALSE;
   3.694 -		goto error;
   3.695 -	}
   3.696 -	
   3.697 -  if ( res == TRUE ) {
   3.698 -    /* loop finished, set the max tries variable to zero again... */
   3.699 -    gint wait_to_transfer = 0;
   3.700 +    livetv->is_livetv = TRUE;
   3.701  
   3.702 -    while (wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
   3.703 -        (gmyth_recorder_is_recording (livetv->recorder) == FALSE))
   3.704 -      g_usleep (300);
   3.705 +    livetv->local_hostname = gmyth_socket_get_local_hostname ();
   3.706  
   3.707 -		if ( channel != NULL ) 
   3.708 -		{
   3.709 -			/* Pauses remote encoder. */
   3.710 -			res = gmyth_recorder_pause_recording(livetv->recorder);
   3.711 -			if ( !res ) {
   3.712 -				gmyth_debug ("[%s] Fail while pausing remote encoder\n", __FUNCTION__);
   3.713 -				res = FALSE;
   3.714 -				goto error;
   3.715 -			}
   3.716 -	
   3.717 -    	  	if ( gmyth_recorder_check_channel_name( livetv->recorder, channel ) )
   3.718 -    	  	{
   3.719 -    		  	if ( gmyth_recorder_set_channel_name( livetv->recorder, channel ) )
   3.720 -    		  	{
   3.721 -    		  		gmyth_debug( "Channel changed!!! [%s].\n", channel );
   3.722 -    		  	}
   3.723 -    	  	}
   3.724 -	
   3.725 -		} /* if - changes the channel number */
   3.726 -    /* sleep (5); */                  /* FIXME: this is evil (tpm) */
   3.727 -  }
   3.728 -  
   3.729 -  /* DEBUG message */  
   3.730 -	GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( livetv->recorder );
   3.731 -	
   3.732 -	if ( NULL == prog_info )
   3.733 -	{
   3.734 -		gmyth_debug( "ProgramInfo is equals to NULL!!!" );
   3.735 -		
   3.736 +    if (livetv->local_hostname == NULL)
   3.737 +    {
   3.738 +        res = FALSE;
   3.739 +        goto error;
   3.740 +    }
   3.741 +
   3.742 +    if (livetv->recorder != NULL)
   3.743 +    {
   3.744 +        g_object_unref (livetv->recorder);
   3.745 +        livetv->recorder = NULL;
   3.746 +    }
   3.747 +
   3.748 +    if (gmyth_remote_util_get_free_recorder_count (livetv->socket) <= 0)
   3.749 +    {
   3.750 +        gmyth_debug ("No free remote encoder available.");
   3.751 +        res = FALSE;
   3.752 +        goto error;
   3.753 +    }
   3.754 +
   3.755 +    /* Gets the recorder num */
   3.756 +    livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1);
   3.757 +    gmyth_socket_close_connection (livetv->socket);
   3.758 +
   3.759 +    if (NULL == livetv->recorder)
   3.760 +    {
   3.761 +        gmyth_debug ("[%s] None remote encoder available", __FUNCTION__);
   3.762 +        res = FALSE;
   3.763 +        goto error;
   3.764 +    }
   3.765 +
   3.766 +    /* Init remote encoder. Opens its control socket. */
   3.767 +    res = gmyth_recorder_setup (livetv->recorder);
   3.768 +    if (!res)
   3.769 +    {
   3.770 +        gmyth_debug ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
   3.771 +        res = FALSE;
   3.772 +        goto error;
   3.773 +    }
   3.774 +
   3.775 +    /* Creates livetv chain handler */
   3.776 +    livetv->tvchain = gmyth_tvchain_new ();
   3.777 +    gmyth_tvchain_initialize (livetv->tvchain, livetv->backend_info);
   3.778 +
   3.779 +    if (livetv->tvchain == NULL || livetv->tvchain->tvchain_id == NULL)
   3.780 +    {
   3.781 +        res = FALSE;
   3.782 +        goto error;
   3.783 +    }
   3.784 +
   3.785 +    // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
   3.786 +    res = gmyth_recorder_spawntv (livetv->recorder,
   3.787 +                                  gmyth_tvchain_get_id (livetv->tvchain));
   3.788 +    if (!res)
   3.789 +    {
   3.790 +        gmyth_debug ("[%s] Fail while spawn tv\n", __FUNCTION__);
   3.791 +        res = FALSE;
   3.792 +        goto error;
   3.793 +    }
   3.794 +
   3.795 +    if (res == TRUE)
   3.796 +    {
   3.797 +        /* loop finished, set the max tries variable to zero again... */
   3.798 +        gint wait_to_transfer = 0;
   3.799 +
   3.800 +        while (wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
   3.801 +               (gmyth_recorder_is_recording (livetv->recorder) == FALSE))
   3.802 +            g_usleep (300);
   3.803 +
   3.804 +        if (channel != NULL)
   3.805 +        {
   3.806 +            /* Pauses remote encoder. */
   3.807 +            res = gmyth_recorder_pause_recording (livetv->recorder);
   3.808 +            if (!res)
   3.809 +            {
   3.810 +                gmyth_debug ("[%s] Fail while pausing remote encoder\n",
   3.811 +                             __FUNCTION__);
   3.812 +                res = FALSE;
   3.813 +                goto error;
   3.814 +            }
   3.815 +
   3.816 +            if (gmyth_recorder_check_channel_name (livetv->recorder, channel))
   3.817 +            {
   3.818 +                if (gmyth_recorder_set_channel_name (livetv->recorder, channel))
   3.819 +                {
   3.820 +                    gmyth_debug ("Channel changed!!! [%s].\n", channel);
   3.821 +                }
   3.822 +            }
   3.823 +
   3.824 +        }                       /* if - changes the channel number */
   3.825 +        /* sleep (5); *//* FIXME: this is evil (tpm) */
   3.826 +    }
   3.827 +
   3.828 +    /* DEBUG message */
   3.829 +    GMythProgramInfo *prog_info =
   3.830 +        gmyth_recorder_get_current_program_info (livetv->recorder);
   3.831 +
   3.832 +    if (NULL == prog_info)
   3.833 +    {
   3.834 +        gmyth_debug ("ProgramInfo is equals to NULL!!!");
   3.835 +
   3.836          gint i;
   3.837          gchar *channame = NULL;
   3.838 -    
   3.839 -        gmyth_debug( "Problem getting current proginfo!\n" );
   3.840 -    
   3.841 +
   3.842 +        gmyth_debug ("Problem getting current proginfo!\n");
   3.843 +
   3.844          /*
   3.845           * mythbackend must not be tuned in to a channel, so keep
   3.846           * changing channels until we find a valid one, or until
   3.847           * we decide to give up.
   3.848           */
   3.849 -        for (i=1; i<1000; i++) {
   3.850 -    		if ( channame != NULL )
   3.851 -    			g_free(channame);
   3.852 -            channame = g_strdup_printf( "%d", i );            
   3.853 -            if (gmyth_recorder_set_channel_name(livetv->recorder, channame) < 0) {
   3.854 +        for (i = 1; i < 1000; i++)
   3.855 +        {
   3.856 +            if (channame != NULL)
   3.857 +                g_free (channame);
   3.858 +            channame = g_strdup_printf ("%d", i);
   3.859 +            if (gmyth_recorder_set_channel_name (livetv->recorder, channame) <
   3.860 +                0)
   3.861 +            {
   3.862                  continue;
   3.863              }
   3.864 -            prog_info = gmyth_recorder_get_next_program_info(livetv->recorder, BROWSE_DIRECTION_UP);
   3.865 -            gmyth_program_info_print( prog_info );
   3.866 +            prog_info =
   3.867 +                gmyth_recorder_get_next_program_info (livetv->recorder,
   3.868 +                                                      BROWSE_DIRECTION_UP);
   3.869 +            gmyth_program_info_print (prog_info);
   3.870              if (prog_info != NULL)
   3.871                  break;
   3.872          }
   3.873  
   3.874 -	} /* if - Program Info */
   3.875 -	
   3.876 -	/* prints program info data text */ 
   3.877 -	gmyth_debug( "New ProgramInfo...\n" );
   3.878 -	gmyth_program_info_print( prog_info );
   3.879 +    }                           /* if - Program Info */
   3.880  
   3.881 -	/* check if the program chain could be obtained from the MythTV protocol message */
   3.882 -	if ( prog_info != NULL )
   3.883 -	{
   3.884 -	    gmyth_backend_info_set_username( livetv->tvchain->backend_info, "mythtv" );
   3.885 -	    gmyth_backend_info_set_password( livetv->tvchain->backend_info, "mythtv" );
   3.886 -	    gmyth_backend_info_set_db_name( livetv->tvchain->backend_info, "mythconverg" );
   3.887 -        GList* prog_list = gmyth_tvchain_get_program_info_from_channel( livetv->tvchain, channel );
   3.888 +    /* prints program info data text */
   3.889 +    gmyth_debug ("New ProgramInfo...\n");
   3.890 +    gmyth_program_info_print (prog_info);
   3.891 +
   3.892 +    /* check if the program chain could be obtained from the MythTV protocol message */
   3.893 +    if (prog_info != NULL)
   3.894 +    {
   3.895 +        gmyth_backend_info_set_username (livetv->tvchain->backend_info,
   3.896 +                                         "mythtv");
   3.897 +        gmyth_backend_info_set_password (livetv->tvchain->backend_info,
   3.898 +                                         "mythtv");
   3.899 +        gmyth_backend_info_set_db_name (livetv->tvchain->backend_info,
   3.900 +                                        "mythconverg");
   3.901 +        GList *prog_list =
   3.902 +            gmyth_tvchain_get_program_info_from_channel (livetv->tvchain,
   3.903 +                                                         channel);
   3.904          GMythProgramInfo *ch_prog = NULL;
   3.905 -	    if ( prog_list != NULL && g_list_length(prog_list) > 0 )
   3.906 -	    {
   3.907 -          ch_prog = (GMythProgramInfo*)g_list_nth_data( prog_list, 0 );
   3.908 -          gmyth_debug( "Channel program info (from a list with size = %d)!", g_list_length(prog_list) );
   3.909 -          gmyth_program_info_print( ch_prog );
   3.910 -	    }
   3.911 -	    
   3.912 -	    gmyth_debug( "Program Info: %s\n", gmyth_program_info_to_string( prog_info ) );
   3.913 -		livetv->proginfo = prog_info;
   3.914 -		/* testing change channel */
   3.915 -		//gmyth_recorder_spawntv_no_tvchain( livetv->recorder );
   3.916 -	} else {
   3.917 -		
   3.918 -		/* check for the program info in the TV program chain could be obtained 
   3.919 -		   from the MythTV MySQL database */
   3.920 +        if (prog_list != NULL && g_list_length (prog_list) > 0)
   3.921 +        {
   3.922 +            ch_prog = (GMythProgramInfo *) g_list_nth_data (prog_list, 0);
   3.923 +            gmyth_debug ("Channel program info (from a list with size = %d)!",
   3.924 +                         g_list_length (prog_list));
   3.925 +            gmyth_program_info_print (ch_prog);
   3.926 +        }
   3.927  
   3.928 -		/* Reload all TV chain from Mysql database. */
   3.929 -		gmyth_tvchain_reload_all (livetv->tvchain);
   3.930 -	
   3.931 -		if ( livetv->tvchain == NULL ) {
   3.932 -			res = FALSE;
   3.933 -			goto error;
   3.934 -		}
   3.935 -		
   3.936 -		/* Get program info from database using chanid and starttime */
   3.937 -		livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, tvchain_curr_index++ );
   3.938 -		if ( livetv->proginfo == NULL ) {
   3.939 -			gmyth_debug ("LiveTV not successfully started.\n");
   3.940 -			res = FALSE;
   3.941 -			goto error;
   3.942 -		} else {
   3.943 -			res = TRUE;
   3.944 -			gmyth_debug ("GMythLiveTV: All requests to backend to start TV were OK. [%s]\n", livetv->proginfo->pathname->str );
   3.945 -		}
   3.946 -		
   3.947 -	}
   3.948 -	
   3.949 -	livetv->uri = (GMythURI*)gmyth_backend_info_get_uri( livetv->backend_info );
   3.950 -	
   3.951 -	g_mutex_unlock( livetv->mutex );
   3.952 +        gmyth_debug ("Program Info: %s\n",
   3.953 +                     gmyth_program_info_to_string (prog_info));
   3.954 +        livetv->proginfo = prog_info;
   3.955 +        /* testing change channel */
   3.956 +        //gmyth_recorder_spawntv_no_tvchain( livetv->recorder );
   3.957 +    }
   3.958 +    else
   3.959 +    {
   3.960  
   3.961 -	if ( !gmyth_livetv_monitor_handler_start( livetv ) )
   3.962 -	{
   3.963 -		res = FALSE;
   3.964 -		gmyth_debug( "LiveTV MONITOR handler error on setup!" );
   3.965 -		goto error;
   3.966 -	}
   3.967 -	
   3.968 -	livetv->setup_done = TRUE;
   3.969 -	
   3.970 -	return res;
   3.971 +        /* check for the program info in the TV program chain could be obtained 
   3.972 +           from the MythTV MySQL database */
   3.973  
   3.974 -error:
   3.975 -	gmyth_debug( "[%s] ERROR running LiveTV setup.\n", __FUNCTION__ );
   3.976 +        /* Reload all TV chain from Mysql database. */
   3.977 +        gmyth_tvchain_reload_all (livetv->tvchain);
   3.978 +
   3.979 +        if (livetv->tvchain == NULL)
   3.980 +        {
   3.981 +            res = FALSE;
   3.982 +            goto error;
   3.983 +        }
   3.984 +
   3.985 +        /* Get program info from database using chanid and starttime */
   3.986 +        livetv->proginfo =
   3.987 +            gmyth_tvchain_get_program_at (livetv->tvchain,
   3.988 +                                          tvchain_curr_index++);
   3.989 +        if (livetv->proginfo == NULL)
   3.990 +        {
   3.991 +            gmyth_debug ("LiveTV not successfully started.\n");
   3.992 +            res = FALSE;
   3.993 +            goto error;
   3.994 +        }
   3.995 +        else
   3.996 +        {
   3.997 +            res = TRUE;
   3.998 +            gmyth_debug
   3.999 +                ("GMythLiveTV: All requests to backend to start TV were OK. [%s]\n",
  3.1000 +                 livetv->proginfo->pathname->str);
  3.1001 +        }
  3.1002 +
  3.1003 +    }
  3.1004 +
  3.1005 +    livetv->uri =
  3.1006 +        (GMythURI *) gmyth_backend_info_get_uri (livetv->backend_info);
  3.1007 +
  3.1008 +    g_mutex_unlock (livetv->mutex);
  3.1009 +
  3.1010 +    if (!gmyth_livetv_monitor_handler_start (livetv))
  3.1011 +    {
  3.1012 +        res = FALSE;
  3.1013 +        gmyth_debug ("LiveTV MONITOR handler error on setup!");
  3.1014 +        goto error;
  3.1015 +    }
  3.1016 +
  3.1017 +    livetv->setup_done = TRUE;
  3.1018 +
  3.1019 +    return res;
  3.1020 +
  3.1021 +  error:
  3.1022 +    gmyth_debug ("[%s] ERROR running LiveTV setup.\n", __FUNCTION__);
  3.1023  
  3.1024      res = FALSE;
  3.1025  
  3.1026 -    g_string_free( livetv->local_hostname, TRUE );
  3.1027 +    g_string_free (livetv->local_hostname, TRUE);
  3.1028  
  3.1029 -	if ( livetv->recorder != NULL ) {
  3.1030 -		g_object_unref (livetv->recorder);
  3.1031 -		livetv->recorder = NULL;
  3.1032 -	}
  3.1033 +    if (livetv->recorder != NULL)
  3.1034 +    {
  3.1035 +        g_object_unref (livetv->recorder);
  3.1036 +        livetv->recorder = NULL;
  3.1037 +    }
  3.1038  
  3.1039 -	if ( livetv->tvchain != NULL ) {
  3.1040 -		g_object_unref (livetv->tvchain);
  3.1041 -		livetv->tvchain = NULL;
  3.1042 -	}
  3.1043 +    if (livetv->tvchain != NULL)
  3.1044 +    {
  3.1045 +        g_object_unref (livetv->tvchain);
  3.1046 +        livetv->tvchain = NULL;
  3.1047 +    }
  3.1048  
  3.1049 -	if ( livetv->proginfo != NULL ) {
  3.1050 -		g_object_unref (livetv->proginfo);
  3.1051 -		livetv->proginfo = NULL;
  3.1052 -	}
  3.1053 +    if (livetv->proginfo != NULL)
  3.1054 +    {
  3.1055 +        g_object_unref (livetv->proginfo);
  3.1056 +        livetv->proginfo = NULL;
  3.1057 +    }
  3.1058  
  3.1059 -	if ( livetv->monitor != NULL ) {
  3.1060 -		g_object_unref (livetv->monitor);
  3.1061 -		livetv->monitor = NULL;
  3.1062 -	}
  3.1063 +    if (livetv->monitor != NULL)
  3.1064 +    {
  3.1065 +        g_object_unref (livetv->monitor);
  3.1066 +        livetv->monitor = NULL;
  3.1067 +    }
  3.1068  
  3.1069 -	return res;
  3.1070 +    return res;
  3.1071  
  3.1072  }
  3.1073  
  3.1074 @@ -613,10 +692,12 @@
  3.1075   * 				had been concluded succcesfully 
  3.1076   */
  3.1077  static gboolean
  3.1078 -gmyth_livetv_setup_recorder ( GMythLiveTV *livetv, gint channel)
  3.1079 +gmyth_livetv_setup_recorder (GMythLiveTV * livetv, gint channel)
  3.1080  {
  3.1081 -	return gmyth_livetv_setup_recorder_channel_name ( livetv, ( channel != -1 ) ? 
  3.1082 -				g_strdup_printf( "%d", channel ) : NULL );
  3.1083 +    return gmyth_livetv_setup_recorder_channel_name (livetv, (channel != -1) ?
  3.1084 +                                                     g_strdup_printf ("%d",
  3.1085 +                                                                      channel) :
  3.1086 +                                                     NULL);
  3.1087  }
  3.1088  
  3.1089  /**
  3.1090 @@ -632,9 +713,9 @@
  3.1091   * 				had been concluded succcesfully 
  3.1092   */
  3.1093  gboolean
  3.1094 -gmyth_livetv_channel_setup ( GMythLiveTV *livetv, gint channel )
  3.1095 +gmyth_livetv_channel_setup (GMythLiveTV * livetv, gint channel)
  3.1096  {
  3.1097 -	return gmyth_livetv_setup_recorder ( livetv, channel );
  3.1098 +    return gmyth_livetv_setup_recorder (livetv, channel);
  3.1099  }
  3.1100  
  3.1101  /**
  3.1102 @@ -650,9 +731,9 @@
  3.1103   * 				had been concluded succcesfully 
  3.1104   */
  3.1105  gboolean
  3.1106 -gmyth_livetv_channel_name_setup ( GMythLiveTV *livetv, gchar* channel )
  3.1107 +gmyth_livetv_channel_name_setup (GMythLiveTV * livetv, gchar * channel)
  3.1108  {
  3.1109 -	return gmyth_livetv_setup_recorder_channel_name ( livetv, channel );
  3.1110 +    return gmyth_livetv_setup_recorder_channel_name (livetv, channel);
  3.1111  }
  3.1112  
  3.1113  /**
  3.1114 @@ -667,9 +748,9 @@
  3.1115   * 				had been concluded succcesfully 
  3.1116   */
  3.1117  gboolean
  3.1118 -gmyth_livetv_setup ( GMythLiveTV *livetv )
  3.1119 +gmyth_livetv_setup (GMythLiveTV * livetv)
  3.1120  {
  3.1121 -	return gmyth_livetv_setup_recorder ( livetv, -1 );
  3.1122 +    return gmyth_livetv_setup_recorder (livetv, -1);
  3.1123  }
  3.1124  
  3.1125  /**
  3.1126 @@ -680,67 +761,81 @@
  3.1127   * @return <code>true</code> if the next program info could be got 
  3.1128   */
  3.1129  gboolean
  3.1130 -gmyth_livetv_next_program_chain ( GMythLiveTV *livetv )
  3.1131 +gmyth_livetv_next_program_chain (GMythLiveTV * livetv)
  3.1132  {
  3.1133 -	gboolean res = TRUE;
  3.1134 -	GMythProgramInfo *prog_info = NULL;
  3.1135 -	
  3.1136 -	if ( !livetv->setup_done )
  3.1137 -	{
  3.1138 -		gmyth_debug ( "Call the setup function first!" );
  3.1139 -		goto error;		
  3.1140 -	}
  3.1141 -	
  3.1142 -	gmyth_debug( "Current ProgramInfo...\n" );
  3.1143 -	prog_info = gmyth_recorder_get_current_program_info( livetv->recorder );
  3.1144 -	
  3.1145 -	if ( prog_info != NULL )
  3.1146 -	{
  3.1147 -		livetv->proginfo = prog_info;
  3.1148 -	} else {
  3.1149 -		gmyth_debug( "ProgramInfo equals to NULL!!! Getting the next program info..." );
  3.1150 -		prog_info = gmyth_recorder_get_next_program_info( livetv->recorder, BROWSE_DIRECTION_RIGHT );
  3.1151 -		livetv->proginfo = prog_info;		
  3.1152 -	}
  3.1153 -	/* prints program info data text */ 
  3.1154 -	gmyth_program_info_print( prog_info );
  3.1155 +    gboolean res = TRUE;
  3.1156 +    GMythProgramInfo *prog_info = NULL;
  3.1157  
  3.1158 -	if ( prog_info != NULL ) {		
  3.1159 -		res = TRUE;
  3.1160 -		livetv->proginfo = prog_info;
  3.1161 -		gmyth_debug ("GMythLiveTV: All requests to backend to start TV were OK, program info changed.");
  3.1162 -	} else {
  3.1163 -		gmyth_debug ("[%s] LiveTV not successfully started on the next program chain.\n", __FUNCTION__ );
  3.1164 -		goto error;
  3.1165 -	}
  3.1166 -	
  3.1167 -	livetv->setup_done = TRUE;
  3.1168 +    if (!livetv->setup_done)
  3.1169 +    {
  3.1170 +        gmyth_debug ("Call the setup function first!");
  3.1171 +        goto error;
  3.1172 +    }
  3.1173  
  3.1174 -	return res;
  3.1175 +    gmyth_debug ("Current ProgramInfo...\n");
  3.1176 +    prog_info = gmyth_recorder_get_current_program_info (livetv->recorder);
  3.1177  
  3.1178 -error:
  3.1179 -	gmyth_debug( "ERROR running LiveTV setup.\n" );
  3.1180 +    if (prog_info != NULL)
  3.1181 +    {
  3.1182 +        livetv->proginfo = prog_info;
  3.1183 +    }
  3.1184 +    else
  3.1185 +    {
  3.1186 +        gmyth_debug
  3.1187 +            ("ProgramInfo equals to NULL!!! Getting the next program info...");
  3.1188 +        prog_info =
  3.1189 +            gmyth_recorder_get_next_program_info (livetv->recorder,
  3.1190 +                                                  BROWSE_DIRECTION_RIGHT);
  3.1191 +        livetv->proginfo = prog_info;
  3.1192 +    }
  3.1193 +    /* prints program info data text */
  3.1194 +    gmyth_program_info_print (prog_info);
  3.1195 +
  3.1196 +    if (prog_info != NULL)
  3.1197 +    {
  3.1198 +        res = TRUE;
  3.1199 +        livetv->proginfo = prog_info;
  3.1200 +        gmyth_debug
  3.1201 +            ("GMythLiveTV: All requests to backend to start TV were OK, program info changed.");
  3.1202 +    }
  3.1203 +    else
  3.1204 +    {
  3.1205 +        gmyth_debug
  3.1206 +            ("[%s] LiveTV not successfully started on the next program chain.\n",
  3.1207 +             __FUNCTION__);
  3.1208 +        goto error;
  3.1209 +    }
  3.1210 +
  3.1211 +    livetv->setup_done = TRUE;
  3.1212 +
  3.1213 +    return res;
  3.1214 +
  3.1215 +  error:
  3.1216 +    gmyth_debug ("ERROR running LiveTV setup.\n");
  3.1217  
  3.1218      res = FALSE;
  3.1219 -    
  3.1220 -    g_string_free( livetv->local_hostname, TRUE );
  3.1221  
  3.1222 -	if ( livetv->recorder != NULL ) {
  3.1223 -		g_object_unref (livetv->recorder);
  3.1224 -		livetv->recorder = NULL;
  3.1225 -	}
  3.1226 +    g_string_free (livetv->local_hostname, TRUE);
  3.1227  
  3.1228 -	if ( livetv->tvchain != NULL ) {
  3.1229 -		g_object_unref (livetv->tvchain);
  3.1230 -		livetv->tvchain = NULL;
  3.1231 -	}
  3.1232 +    if (livetv->recorder != NULL)
  3.1233 +    {
  3.1234 +        g_object_unref (livetv->recorder);
  3.1235 +        livetv->recorder = NULL;
  3.1236 +    }
  3.1237  
  3.1238 -	if ( livetv->proginfo != NULL ) {
  3.1239 -		g_object_unref (livetv->proginfo);
  3.1240 -		livetv->proginfo = NULL;
  3.1241 -	}
  3.1242 +    if (livetv->tvchain != NULL)
  3.1243 +    {
  3.1244 +        g_object_unref (livetv->tvchain);
  3.1245 +        livetv->tvchain = NULL;
  3.1246 +    }
  3.1247  
  3.1248 -	return res;
  3.1249 +    if (livetv->proginfo != NULL)
  3.1250 +    {
  3.1251 +        g_object_unref (livetv->proginfo);
  3.1252 +        livetv->proginfo = NULL;
  3.1253 +    }
  3.1254 +
  3.1255 +    return res;
  3.1256  }
  3.1257  
  3.1258  /**
  3.1259 @@ -753,78 +848,91 @@
  3.1260   * 		data got from the actual program info.
  3.1261   */
  3.1262  GMythFile *
  3.1263 -gmyth_livetv_create_file_transfer( GMythLiveTV *livetv )
  3.1264 +gmyth_livetv_create_file_transfer (GMythLiveTV * livetv)
  3.1265  {
  3.1266 -	//GMythURI* uri = NULL;
  3.1267 -	
  3.1268 -    if ( NULL == livetv )
  3.1269 -		goto done;
  3.1270 -	
  3.1271 -	if ( !livetv->setup_done )
  3.1272 -	{
  3.1273 -		gmyth_debug( "Error: You must do the LiveTV setup, just before generating the FileTransfer from LiveTV source!" );
  3.1274 -		goto done;
  3.1275 -	}
  3.1276 -	
  3.1277 -	if ( livetv->proginfo != NULL )
  3.1278 -  	gmyth_debug( "URI path (from program info) = %s.\n", livetv->proginfo->pathname->str );
  3.1279 -  else
  3.1280 -  	gmyth_debug( "URI path (from URI) = %s.\n", livetv->uri->uri->str );
  3.1281 -  
  3.1282 -    g_mutex_lock( livetv->mutex );
  3.1283 -  
  3.1284 -    if ( livetv->file != NULL )
  3.1285 +    //GMythURI* uri = NULL;
  3.1286 +
  3.1287 +    if (NULL == livetv)
  3.1288 +        goto done;
  3.1289 +
  3.1290 +    if (!livetv->setup_done)
  3.1291      {
  3.1292 -        /*gmyth_file_transfer_close( livetv->file );*/
  3.1293 -        g_object_unref( livetv->file );
  3.1294 +        gmyth_debug
  3.1295 +            ("Error: You must do the LiveTV setup, just before generating the FileTransfer from LiveTV source!");
  3.1296 +        goto done;
  3.1297 +    }
  3.1298 +
  3.1299 +    if (livetv->proginfo != NULL)
  3.1300 +        gmyth_debug ("URI path (from program info) = %s.\n",
  3.1301 +                     livetv->proginfo->pathname->str);
  3.1302 +    else
  3.1303 +        gmyth_debug ("URI path (from URI) = %s.\n", livetv->uri->uri->str);
  3.1304 +
  3.1305 +    g_mutex_lock (livetv->mutex);
  3.1306 +
  3.1307 +    if (livetv->file != NULL)
  3.1308 +    {
  3.1309 +        /*gmyth_file_transfer_close( livetv->file ); */
  3.1310 +        g_object_unref (livetv->file);
  3.1311          livetv->file = NULL;
  3.1312 -    }  	
  3.1313 +    }
  3.1314  
  3.1315 -    if ( livetv->uri != NULL )  
  3.1316 +    if (livetv->uri != NULL)
  3.1317      {
  3.1318 -        gmyth_debug( "URI is not NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str );
  3.1319 -        livetv->uri->path = g_string_erase(livetv->uri->path, 0, -1);
  3.1320 -        livetv->uri->path = g_string_new( g_strrstr( livetv->proginfo->pathname->str, "/" ) );
  3.1321 -    } else {
  3.1322 -        gmyth_debug( "URI is NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str );
  3.1323 -      	livetv->uri = gmyth_uri_new_with_value( livetv->proginfo->pathname->str );
  3.1324 +        gmyth_debug
  3.1325 +            ("URI is not NULL, creating from the ProgramInfo pathname... (%s)",
  3.1326 +             livetv->proginfo->pathname->str);
  3.1327 +        livetv->uri->path = g_string_erase (livetv->uri->path, 0, -1);
  3.1328 +        livetv->uri->path =
  3.1329 +            g_string_new (g_strrstr (livetv->proginfo->pathname->str, "/"));
  3.1330      }
  3.1331 -  	
  3.1332 -    if ( NULL == livetv->uri )
  3.1333 -    {  	
  3.1334 -        gmyth_debug( "Couldn't parse the URI to start LiveTV! [ uri = %s ]", livetv->proginfo->pathname->str );
  3.1335 -        goto done;  	
  3.1336 -    }
  3.1337 -  
  3.1338 -    if ( gmyth_uri_is_local_file( livetv->uri ) ) 
  3.1339 -        livetv->file = GMYTH_FILE( gmyth_file_local_new( livetv->backend_info ) );
  3.1340      else
  3.1341      {
  3.1342 -        livetv->file = GMYTH_FILE( gmyth_file_transfer_new( livetv->backend_info ) );
  3.1343 +        gmyth_debug
  3.1344 +            ("URI is NULL, creating from the ProgramInfo pathname... (%s)",
  3.1345 +             livetv->proginfo->pathname->str);
  3.1346 +        livetv->uri =
  3.1347 +            gmyth_uri_new_with_value (livetv->proginfo->pathname->str);
  3.1348 +    }
  3.1349 +
  3.1350 +    if (NULL == livetv->uri)
  3.1351 +    {
  3.1352 +        gmyth_debug ("Couldn't parse the URI to start LiveTV! [ uri = %s ]",
  3.1353 +                     livetv->proginfo->pathname->str);
  3.1354 +        goto done;
  3.1355 +    }
  3.1356 +
  3.1357 +    if (gmyth_uri_is_local_file (livetv->uri))
  3.1358 +        livetv->file = GMYTH_FILE (gmyth_file_local_new (livetv->backend_info));
  3.1359 +    else
  3.1360 +    {
  3.1361 +        livetv->file =
  3.1362 +            GMYTH_FILE (gmyth_file_transfer_new (livetv->backend_info));
  3.1363          //gmyth_file_transfer_settimeout( GMYTH_FILE_TRANSFER(livetv->file), TRUE );
  3.1364      }
  3.1365  
  3.1366 -    if ( NULL == livetv->file ) 
  3.1367 +    if (NULL == livetv->file)
  3.1368      {
  3.1369 -        gmyth_debug( "Error: couldn't create the FileTransfer from LiveTV source!" );
  3.1370 +        gmyth_debug
  3.1371 +            ("Error: couldn't create the FileTransfer from LiveTV source!");
  3.1372          goto done;
  3.1373      }
  3.1374 -  
  3.1375 -    g_object_ref( livetv->file );
  3.1376  
  3.1377 -    g_mutex_unlock( livetv->mutex );
  3.1378 +    g_object_ref (livetv->file);
  3.1379  
  3.1380 -done:
  3.1381 -	/*
  3.1382 -	if ( uri != NULL )
  3.1383 -	{
  3.1384 -		g_object_unref( uri );
  3.1385 -		uri = NULL;
  3.1386 -	}
  3.1387 -	*/	
  3.1388 -	
  3.1389 -	return livetv->file;
  3.1390 -	
  3.1391 +    g_mutex_unlock (livetv->mutex);
  3.1392 +
  3.1393 +  done:
  3.1394 +    /*
  3.1395 +       if ( uri != NULL )
  3.1396 +       {
  3.1397 +       g_object_unref( uri );
  3.1398 +       uri = NULL;
  3.1399 +       }
  3.1400 +     */
  3.1401 +
  3.1402 +    return livetv->file;
  3.1403 +
  3.1404  }
  3.1405  
  3.1406  /**
  3.1407 @@ -833,31 +941,37 @@
  3.1408   * @param live_tv the GMythLiveTV instance
  3.1409   */
  3.1410  void
  3.1411 -gmyth_livetv_stop_playing (GMythLiveTV *livetv) 
  3.1412 +gmyth_livetv_stop_playing (GMythLiveTV * livetv)
  3.1413  {
  3.1414      gmyth_debug ("Stopping the LiveTV...\n");
  3.1415  
  3.1416 -	if (livetv->is_livetv) {
  3.1417 -		if ( !gmyth_recorder_stop_livetv (livetv->recorder) ) {
  3.1418 -			gmyth_debug ("[%s] Error while stoping remote encoder", __FUNCTION__);	
  3.1419 -		}
  3.1420 -		
  3.1421 -		if ( !gmyth_recorder_finish_recording(livetv->recorder) ) {
  3.1422 -			gmyth_debug ("[%s] Error while finishing recording on remote encoder", __FUNCTION__);	
  3.1423 -		}
  3.1424 -	}
  3.1425 +    if (livetv->is_livetv)
  3.1426 +    {
  3.1427 +        if (!gmyth_recorder_stop_livetv (livetv->recorder))
  3.1428 +        {
  3.1429 +            gmyth_debug ("[%s] Error while stoping remote encoder",
  3.1430 +                         __FUNCTION__);
  3.1431 +        }
  3.1432 +
  3.1433 +        if (!gmyth_recorder_finish_recording (livetv->recorder))
  3.1434 +        {
  3.1435 +            gmyth_debug
  3.1436 +                ("[%s] Error while finishing recording on remote encoder",
  3.1437 +                 __FUNCTION__);
  3.1438 +        }
  3.1439 +    }
  3.1440  }
  3.1441  
  3.1442  gboolean
  3.1443 -gmyth_livetv_is_playing (GMythLiveTV *livetv)
  3.1444 +gmyth_livetv_is_playing (GMythLiveTV * livetv)
  3.1445  {
  3.1446 -	return TRUE;
  3.1447 +    return TRUE;
  3.1448  }
  3.1449  
  3.1450  void
  3.1451 -gmyth_livetv_start_playing (GMythLiveTV *livetv)
  3.1452 +gmyth_livetv_start_playing (GMythLiveTV * livetv)
  3.1453  {
  3.1454  
  3.1455 -	// TODO
  3.1456 +    // TODO
  3.1457  
  3.1458  }
     4.1 --- a/gmyth/src/gmyth_livetv.h	Tue May 15 20:16:26 2007 +0100
     4.2 +++ b/gmyth/src/gmyth_livetv.h	Tue May 15 21:39:04 2007 +0100
     4.3 @@ -8,22 +8,22 @@
     4.4   * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     4.5   * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
     4.6   *
     4.7 - *//*
     4.8 - * 
     4.9 - * This program is free software; you can redistribute it and/or modify
    4.10 - * it under the terms of the GNU Lesser General Public License as published by
    4.11 - * the Free Software Foundation; either version 2 of the License, or
    4.12 - * (at your option) any later version.
    4.13 - *
    4.14 - * This program is distributed in the hope that it will be useful,
    4.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.17 - * GNU General Public License for more details.
    4.18 - *
    4.19 - * You should have received a copy of the GNU Lesser General Public License
    4.20 - * along with this program; if not, write to the Free Software
    4.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.22 - */
    4.23 +          *//*
    4.24 +       * 
    4.25 +       * This program is free software; you can redistribute it and/or modify
    4.26 +       * it under the terms of the GNU Lesser General Public License as published by
    4.27 +       * the Free Software Foundation; either version 2 of the License, or
    4.28 +       * (at your option) any later version.
    4.29 +       *
    4.30 +       * This program is distributed in the hope that it will be useful,
    4.31 +       * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.32 +       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.33 +       * GNU General Public License for more details.
    4.34 +       *
    4.35 +       * You should have received a copy of the GNU Lesser General Public License
    4.36 +       * along with this program; if not, write to the Free Software
    4.37 +       * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.38 +       */
    4.39  
    4.40  #ifndef GMYTH_LIVETV_H_
    4.41  #define GMYTH_LIVETV_H_
    4.42 @@ -39,67 +39,65 @@
    4.43  #include "gmyth_backendinfo.h"
    4.44  
    4.45  G_BEGIN_DECLS
    4.46 -
    4.47  #define GMYTH_LIVETV_TYPE               (gmyth_livetv_get_type ())
    4.48  #define GMYTH_LIVETV(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_LIVETV_TYPE, GMythLiveTV))
    4.49  #define GMYTH_LIVETV_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_LIVETV_TYPE, GMythLiveTVClass))
    4.50  #define IS_GMYTH_LIVETV(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMYTH_LIVETV_TYPE))
    4.51  #define IS_GMYTH_LIVETV_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_LIVETV_TYPE))
    4.52  #define GMYTH_LIVETV_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_LIVETV_TYPE, GMythLiveTVClass))
    4.53 -
    4.54 -typedef struct _GMythLiveTV         GMythLiveTV;
    4.55 -typedef struct _GMythLiveTVClass    GMythLiveTVClass;
    4.56 +typedef struct _GMythLiveTV GMythLiveTV;
    4.57 +typedef struct _GMythLiveTVClass GMythLiveTVClass;
    4.58  
    4.59  struct _GMythLiveTVClass
    4.60 -{
    4.61 -    GObjectClass parent_class;
    4.62 +    {
    4.63 +        GObjectClass parent_class;
    4.64  
    4.65 -    /* callbacks */
    4.66 -};
    4.67 +        /* callbacks */
    4.68 +    };
    4.69  
    4.70  struct _GMythLiveTV
    4.71 -{
    4.72 -	GObject					parent;
    4.73 -	
    4.74 -	GMythSocket				*socket;
    4.75 -	
    4.76 -    GString				 	*local_hostname;
    4.77 -	
    4.78 -	GMythBackendInfo        *backend_info;
    4.79 +    {
    4.80 +        GObject parent;
    4.81  
    4.82 -	GMythRecorder 	 		*recorder;
    4.83 -	GMythTVChain 			*tvchain;
    4.84 -	GMythProgramInfo 		*proginfo;
    4.85 -	
    4.86 -	GMythFile               *file;
    4.87 -	
    4.88 -	GMythMonitorHandler     *monitor;
    4.89 -	GMythURI				*uri;
    4.90 +        GMythSocket *socket;
    4.91  
    4.92 -	gboolean 				is_livetv;
    4.93 -	gboolean 				setup_done;
    4.94 -	
    4.95 -	GMutex 					*mutex;	
    4.96 -    gboolean                disposed;
    4.97 -};
    4.98 +        GString *local_hostname;
    4.99  
   4.100 -GType           gmyth_livetv_get_type (void);
   4.101 +        GMythBackendInfo *backend_info;
   4.102  
   4.103 -GMythLiveTV*    gmyth_livetv_new (GMythBackendInfo *backend_info);
   4.104 +        GMythRecorder *recorder;
   4.105 +        GMythTVChain *tvchain;
   4.106 +        GMythProgramInfo *proginfo;
   4.107  
   4.108 -void            gmyth_livetv_start_playing (GMythLiveTV *livetv);
   4.109 -void            gmyth_livetv_stop_playing (GMythLiveTV *livetv);
   4.110 +        GMythFile *file;
   4.111  
   4.112 -gboolean        gmyth_livetv_setup (GMythLiveTV *livetv);
   4.113 -gboolean        gmyth_livetv_channel_setup ( GMythLiveTV *livetv, gint channel);
   4.114 -gboolean        gmyth_livetv_channel_name_setup ( GMythLiveTV *livetv, gchar* channel);
   4.115 -gboolean        gmyth_livetv_next_program_chain ( GMythLiveTV *livetv );
   4.116 +        GMythMonitorHandler *monitor;
   4.117 +        GMythURI *uri;
   4.118  
   4.119 -GMythFile*      gmyth_livetv_create_file_transfer( GMythLiveTV *livetv );
   4.120 +        gboolean is_livetv;
   4.121 +        gboolean setup_done;
   4.122  
   4.123 -gboolean        gmyth_livetv_monitor_handler_start( GMythLiveTV *livetv );
   4.124 -void            gmyth_livetv_monitor_handler_stop( GMythLiveTV *livetv );
   4.125 +        GMutex *mutex;
   4.126 +        gboolean disposed;
   4.127 +    };
   4.128 +
   4.129 +GType gmyth_livetv_get_type (void);
   4.130 +
   4.131 +GMythLiveTV *gmyth_livetv_new (GMythBackendInfo * backend_info);
   4.132 +
   4.133 +void gmyth_livetv_start_playing (GMythLiveTV * livetv);
   4.134 +void gmyth_livetv_stop_playing (GMythLiveTV * livetv);
   4.135 +
   4.136 +gboolean gmyth_livetv_setup (GMythLiveTV * livetv);
   4.137 +gboolean gmyth_livetv_channel_setup (GMythLiveTV * livetv, gint channel);
   4.138 +gboolean gmyth_livetv_channel_name_setup (GMythLiveTV * livetv,
   4.139 +                                          gchar * channel);
   4.140 +gboolean gmyth_livetv_next_program_chain (GMythLiveTV * livetv);
   4.141 +
   4.142 +GMythFile *gmyth_livetv_create_file_transfer (GMythLiveTV * livetv);
   4.143 +
   4.144 +gboolean gmyth_livetv_monitor_handler_start (GMythLiveTV * livetv);
   4.145 +void gmyth_livetv_monitor_handler_stop (GMythLiveTV * livetv);
   4.146  
   4.147  G_END_DECLS
   4.148 -
   4.149 -#endif /*GMYTH_LIVETV_H_*/
   4.150 +#endif /*GMYTH_LIVETV_H_ */
     5.1 --- a/gmyth/src/gmyth_monitor_handler.c	Tue May 15 20:16:26 2007 +0100
     5.2 +++ b/gmyth/src/gmyth_monitor_handler.c	Tue May 15 21:39:04 2007 +0100
     5.3 @@ -9,27 +9,27 @@
     5.4   * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     5.5   * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
     5.6   *
     5.7 - *//*
     5.8 - * 
     5.9 - * This program is free software; you can redistribute it and/or modify
    5.10 - * it under the terms of the GNU Lesser General Public License as published by
    5.11 - * the Free Software Foundation; either version 2 of the License, or
    5.12 - * (at your option) any later version.
    5.13 - *
    5.14 - * This program is distributed in the hope that it will be useful,
    5.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.17 - * GNU General Public License for more details.
    5.18 - *
    5.19 - * You should have received a copy of the GNU Lesser General Public License
    5.20 - * along with this program; if not, write to the Free Software
    5.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.22 - *
    5.23 - * GStreamer MythTV plug-in properties:
    5.24 - * - location (backend server hostname/URL) [ex.: myth://192.168.1.73:28722/1000_1092091.nuv]
    5.25 - * - path (qurl - remote file to be opened)
    5.26 - * - port number *   
    5.27 - */
    5.28 +          *//*
    5.29 +       * 
    5.30 +       * This program is free software; you can redistribute it and/or modify
    5.31 +       * it under the terms of the GNU Lesser General Public License as published by
    5.32 +       * the Free Software Foundation; either version 2 of the License, or
    5.33 +       * (at your option) any later version.
    5.34 +       *
    5.35 +       * This program is distributed in the hope that it will be useful,
    5.36 +       * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.37 +       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.38 +       * GNU General Public License for more details.
    5.39 +       *
    5.40 +       * You should have received a copy of the GNU Lesser General Public License
    5.41 +       * along with this program; if not, write to the Free Software
    5.42 +       * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.43 +       *
    5.44 +       * GStreamer MythTV plug-in properties:
    5.45 +       * - location (backend server hostname/URL) [ex.: myth://192.168.1.73:28722/1000_1092091.nuv]
    5.46 +       * - path (qurl - remote file to be opened)
    5.47 +       * - port number *   
    5.48 +       */
    5.49  
    5.50  #ifdef HAVE_CONFIG_H
    5.51  #include "config.h"
    5.52 @@ -49,7 +49,7 @@
    5.53  
    5.54  #include "gmyth_monitor_handler.h"
    5.55  #include "gmyth_debug.h"
    5.56 - 
    5.57 +
    5.58  #define GMYTHTV_QUERY_HEADER		"QUERY_FILETRANSFER "
    5.59  
    5.60  #define GMYTHTV_VERSION							30
    5.61 @@ -69,133 +69,135 @@
    5.62  #define GMYTHTV_ENABLE_DEBUG				1
    5.63  #endif
    5.64  
    5.65 -gboolean gmyth_monitor_handler_listener( GIOChannel *io_channel, 
    5.66 -						GIOCondition io_cond, gpointer data );
    5.67 +gpointer gmyth_monitor_handler_listener (gpointer data);
    5.68  
    5.69 -static void gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message );
    5.70 +static void gmyth_monitor_handler_default_listener (GMythMonitorHandler *
    5.71 +                                                    monitor, gint msg_code,
    5.72 +                                                    gchar * message);
    5.73  
    5.74 -static void gmyth_monitor_handler_class_init          (GMythMonitorHandlerClass *klass);
    5.75 -static void gmyth_monitor_handler_init                (GMythMonitorHandler *object);
    5.76 +static void gmyth_monitor_handler_class_init (GMythMonitorHandlerClass * klass);
    5.77 +static void gmyth_monitor_handler_init (GMythMonitorHandler * object);
    5.78  
    5.79 -static void gmyth_monitor_handler_dispose  (GObject *object);
    5.80 -static void gmyth_monitor_handler_finalize (GObject *object);
    5.81 +static void gmyth_monitor_handler_dispose (GObject * object);
    5.82 +static void gmyth_monitor_handler_finalize (GObject * object);
    5.83  
    5.84 -static gboolean gmyth_connect_to_backend_monitor (GMythMonitorHandler *monitor);
    5.85 +static gboolean gmyth_connect_to_backend_monitor (GMythMonitorHandler *
    5.86 +                                                  monitor);
    5.87  
    5.88 -static gboolean gmyth_monitor_handler_setup( GMythMonitorHandler *monitor,
    5.89 -                                             GIOChannel *channel );
    5.90 +static gboolean gmyth_monitor_handler_setup (GMythMonitorHandler * monitor,
    5.91 +                                             GIOChannel * channel);
    5.92  
    5.93 -void gmyth_monitor_handler_close( GMythMonitorHandler *monitor );
    5.94 +void gmyth_monitor_handler_close (GMythMonitorHandler * monitor);
    5.95  
    5.96 -G_DEFINE_TYPE(GMythMonitorHandler, gmyth_monitor_handler, G_TYPE_OBJECT)
    5.97 +G_DEFINE_TYPE (GMythMonitorHandler, gmyth_monitor_handler, G_TYPE_OBJECT)
    5.98 +     static void
    5.99 +         gmyth_monitor_handler_class_init (GMythMonitorHandlerClass * klass)
   5.100 +{
   5.101 +    GObjectClass *gobject_class;
   5.102 +    GMythMonitorHandlerClass *gmonitor_class;
   5.103  
   5.104 -static void
   5.105 -gmyth_monitor_handler_class_init (GMythMonitorHandlerClass *klass)
   5.106 -{
   5.107 -  GObjectClass *gobject_class;
   5.108 -  GMythMonitorHandlerClass *gmonitor_class;
   5.109 +    gobject_class = (GObjectClass *) klass;
   5.110 +    gmonitor_class = (GMythMonitorHandlerClass *) gobject_class;
   5.111  
   5.112 -  gobject_class = (GObjectClass *) klass;
   5.113 -  gmonitor_class = (GMythMonitorHandlerClass *) gobject_class;
   5.114 +    gobject_class->dispose = gmyth_monitor_handler_dispose;
   5.115 +    gobject_class->finalize = gmyth_monitor_handler_finalize;
   5.116  
   5.117 -  gobject_class->dispose  = gmyth_monitor_handler_dispose;
   5.118 -  gobject_class->finalize = gmyth_monitor_handler_finalize;
   5.119 -  
   5.120 -	gmonitor_class->backend_events_handler_signal_id = 
   5.121 -		  g_signal_new ("backend-events-handler",
   5.122 -		                 G_TYPE_FROM_CLASS (gmonitor_class),
   5.123 -		                 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
   5.124 -		                 0,
   5.125 -										 NULL,
   5.126 -										 NULL,
   5.127 -										 gmyth_marshal_VOID__INT_STRING,
   5.128 -										 G_TYPE_NONE,
   5.129 -										 2,
   5.130 -										 G_TYPE_INT,
   5.131 -										 G_TYPE_STRING);
   5.132 -										 
   5.133 -	gmonitor_class->backend_events_handler = gmyth_monitor_handler_default_listener;
   5.134 +    gmonitor_class->backend_events_handler_signal_id =
   5.135 +        g_signal_new ("backend-events-handler",
   5.136 +                      G_TYPE_FROM_CLASS (gmonitor_class),
   5.137 +                      G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE |
   5.138 +                      G_SIGNAL_NO_HOOKS, 0, NULL, NULL,
   5.139 +                      gmyth_marshal_VOID__INT_STRING, G_TYPE_NONE, 2,
   5.140 +                      G_TYPE_INT, G_TYPE_STRING);
   5.141 +
   5.142 +    gmonitor_class->backend_events_handler =
   5.143 +        gmyth_monitor_handler_default_listener;
   5.144  
   5.145  }
   5.146  
   5.147  static void
   5.148 -gmyth_monitor_handler_init (GMythMonitorHandler *monitor)
   5.149 -{ 
   5.150 -  g_return_if_fail( monitor != NULL );
   5.151 +gmyth_monitor_handler_init (GMythMonitorHandler * monitor)
   5.152 +{
   5.153 +    g_return_if_fail (monitor != NULL);
   5.154  
   5.155 -  monitor->event_sock = NULL;
   5.156 -  monitor->hostname = NULL;
   5.157 -  monitor->port = 0;
   5.158 -  monitor->actual_index = 0;
   5.159 -  
   5.160 -  monitor->allow_msgs_listener = FALSE;
   5.161 -  
   5.162 -  /* monitor->backend_msgs = g_hash_table_new( g_int_hash, g_int_equal ); */
   5.163 -    
   5.164 -  /* it is used for signalizing the event socket consumer thread */
   5.165 -  monitor->mutex = g_mutex_new();
   5.166 -  
   5.167 -  monitor->sid_io_watch = -1;
   5.168 -  
   5.169 -  monitor->gmyth_monitor_handler_listener = gmyth_monitor_handler_listener;
   5.170 +    monitor->event_sock = NULL;
   5.171 +    monitor->hostname = NULL;
   5.172 +    monitor->port = 0;
   5.173 +    monitor->actual_index = 0;
   5.174 +
   5.175 +    monitor->allow_msgs_listener = FALSE;
   5.176 +
   5.177 +    /* monitor->backend_msgs = g_hash_table_new( g_int_hash, g_int_equal ); */
   5.178 +
   5.179 +    /* it is used for signalizing the event socket consumer thread */
   5.180 +    monitor->mutex = g_mutex_new ();
   5.181 +
   5.182 +    monitor->th = NULL;
   5.183 +
   5.184 +    monitor->gmyth_monitor_handler_listener = gmyth_monitor_handler_listener;
   5.185  }
   5.186  
   5.187  static void
   5.188 -gmyth_monitor_handler_dispose  (GObject *object)
   5.189 +gmyth_monitor_handler_dispose (GObject * object)
   5.190  {
   5.191 -	GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER (object);
   5.192 -    gmyth_monitor_handler_close(monitor);
   5.193 +    GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER (object);
   5.194 +    gmyth_monitor_handler_close (monitor);
   5.195  
   5.196 -	monitor->allow_msgs_listener = FALSE;
   5.197 +    monitor->allow_msgs_listener = FALSE;
   5.198  
   5.199 -	if (monitor->sid_io_watch != -1)
   5.200 -	{
   5.201 -        g_source_remove (monitor->sid_io_watch);
   5.202 -	}
   5.203 +    if (monitor->th != NULL)
   5.204 +    {
   5.205 +    	gboolean *ret = (gboolean*)g_thread_join( monitor->th );
   5.206 +	if ( *ret == FALSE )
   5.207 +		gmyth_debug ( "Error closing GThread listener socket!" );
   5.208 +	else
   5.209 +		gmyth_debug ( "Closed GThread listener socket." );
   5.210 +	//g_object_unref( monitor->th );
   5.211 +    }
   5.212  
   5.213      /* mutex to control access to the event socket consumer thread */
   5.214 -    if ( monitor->mutex != NULL )
   5.215 +    if (monitor->mutex != NULL)
   5.216      {
   5.217          //g_mutex_unlock( monitor->mutex );
   5.218 -        g_mutex_free( monitor->mutex );
   5.219 +        g_mutex_free (monitor->mutex);
   5.220          monitor->mutex = NULL;
   5.221      }
   5.222 -    
   5.223 -    if ( monitor->event_sock != NULL )  
   5.224 +
   5.225 +    if (monitor->event_sock != NULL)
   5.226      {
   5.227 -  	    g_object_unref( monitor->event_sock );
   5.228 -  	    monitor->event_sock = NULL;
   5.229 +        g_object_unref (monitor->event_sock);
   5.230 +        monitor->event_sock = NULL;
   5.231      }
   5.232  
   5.233 -    if ( monitor->hostname != NULL )  
   5.234 +    if (monitor->hostname != NULL)
   5.235      {
   5.236 -  	    g_free( monitor->hostname );
   5.237 -  	    monitor->hostname = NULL;
   5.238 +        g_free (monitor->hostname);
   5.239 +        monitor->hostname = NULL;
   5.240      }
   5.241  
   5.242 -    if ( monitor->backend_msgs != NULL )
   5.243 +    if (monitor->backend_msgs != NULL)
   5.244      {
   5.245 -  	    g_hash_table_destroy ( monitor->backend_msgs );
   5.246 -  	    monitor->backend_msgs = NULL;
   5.247 +        g_hash_table_destroy (monitor->backend_msgs);
   5.248 +        monitor->backend_msgs = NULL;
   5.249      }
   5.250 - 
   5.251 +
   5.252      /*
   5.253 -    if ( io_watcher_cond != NULL )  
   5.254 -    {
   5.255 -        g_cond_free( io_watcher_cond );
   5.256 -        io_watcher_cond = NULL;
   5.257 -    }
   5.258 -    */
   5.259 -  
   5.260 +       if ( io_watcher_cond != NULL )  
   5.261 +       {
   5.262 +       g_cond_free( io_watcher_cond );
   5.263 +       io_watcher_cond = NULL;
   5.264 +       }
   5.265 +     */
   5.266 +
   5.267      G_OBJECT_CLASS (gmyth_monitor_handler_parent_class)->dispose (object);
   5.268  }
   5.269  
   5.270  static void
   5.271 -gmyth_monitor_handler_finalize (GObject *object)
   5.272 +gmyth_monitor_handler_finalize (GObject * object)
   5.273  {
   5.274 -  g_signal_handlers_destroy (object);
   5.275 +    g_signal_handlers_destroy (object);
   5.276  
   5.277 -  G_OBJECT_CLASS (gmyth_monitor_handler_parent_class)->finalize (object);
   5.278 +    G_OBJECT_CLASS (gmyth_monitor_handler_parent_class)->finalize (object);
   5.279  }
   5.280  
   5.281  /** 
   5.282 @@ -203,13 +205,14 @@
   5.283   * 
   5.284   * @return a new instance of the Monitor Handler. 
   5.285   */
   5.286 -GMythMonitorHandler*
   5.287 -gmyth_monitor_handler_new ( void )
   5.288 +GMythMonitorHandler *
   5.289 +gmyth_monitor_handler_new (void)
   5.290  {
   5.291 -  GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER ( 
   5.292 -  					g_object_new ( GMYTH_MONITOR_HANDLER_TYPE, FALSE ) );
   5.293 +    GMythMonitorHandler *monitor =
   5.294 +        GMYTH_MONITOR_HANDLER (g_object_new
   5.295 +                               (GMYTH_MONITOR_HANDLER_TYPE, FALSE));
   5.296  
   5.297 -  return monitor;
   5.298 +    return monitor;
   5.299  }
   5.300  
   5.301  /** 
   5.302 @@ -220,16 +223,16 @@
   5.303   * 
   5.304   * @return <code>true</code>, if the access to IO Watcher was acquired. 
   5.305   */
   5.306 -static gboolean 
   5.307 -myth_control_acquire_context( GMythMonitorHandler *monitor, gboolean do_wait ) 
   5.308 +static gboolean
   5.309 +myth_control_acquire_context (GMythMonitorHandler * monitor, gboolean do_wait)
   5.310  {
   5.311 -	
   5.312 -    gboolean ret = TRUE;	
   5.313 -  	
   5.314 -    g_mutex_lock( monitor->mutex );
   5.315 -  
   5.316 +
   5.317 +    gboolean ret = TRUE;
   5.318 +
   5.319 +    g_mutex_lock (monitor->mutex);
   5.320 +
   5.321      return ret;
   5.322 -  
   5.323 +
   5.324  }
   5.325  
   5.326  /** 
   5.327 @@ -239,36 +242,36 @@
   5.328   * 
   5.329   * @return <code>true</code>, if the access to IO Watcher was released. 
   5.330   */
   5.331 -static gboolean 
   5.332 -myth_control_release_context( GMythMonitorHandler *monitor ) 
   5.333 +static gboolean
   5.334 +myth_control_release_context (GMythMonitorHandler * monitor)
   5.335  {
   5.336 -	
   5.337 -	gboolean ret = TRUE;
   5.338 -    
   5.339 -    g_mutex_unlock( monitor->mutex );
   5.340 -  
   5.341 +
   5.342 +    gboolean ret = TRUE;
   5.343 +
   5.344 +    g_mutex_unlock (monitor->mutex);
   5.345 +
   5.346      return ret;
   5.347  }
   5.348  
   5.349  void
   5.350 -gmyth_monitor_handler_close (GMythMonitorHandler *monitor)
   5.351 +gmyth_monitor_handler_close (GMythMonitorHandler * monitor)
   5.352  {
   5.353 -	monitor->allow_msgs_listener = FALSE;
   5.354 +    monitor->allow_msgs_listener = FALSE;
   5.355  
   5.356 -#if 0	
   5.357 -	if ( monitor->monitor_th != NULL ) 
   5.358 -  {
   5.359 -  	g_thread_pool_free( monitor->monitor_th, TRUE, FALSE );
   5.360 -  	//g_thread_exit( monitor->monitor_th );
   5.361 -  	/*if ( monitor->monitor_th != NULL )
   5.362 -  		g_object_unref( monitor->monitor_th );*/
   5.363 -  	monitor->monitor_th = NULL;
   5.364 -  }
   5.365 -	
   5.366 -  if ( monitor->event_sock != NULL )  
   5.367 -  {
   5.368 -  	gmyth_socket_close_connection( monitor->event_sock );  	
   5.369 -  }
   5.370 +#if 0
   5.371 +    if (monitor->monitor_th != NULL)
   5.372 +    {
   5.373 +        g_thread_pool_free (monitor->monitor_th, TRUE, FALSE);
   5.374 +        //g_thread_exit( monitor->monitor_th );
   5.375 +        /*if ( monitor->monitor_th != NULL )
   5.376 +           g_object_unref( monitor->monitor_th ); */
   5.377 +        monitor->monitor_th = NULL;
   5.378 +    }
   5.379 +
   5.380 +    if (monitor->event_sock != NULL)
   5.381 +    {
   5.382 +        gmyth_socket_close_connection (monitor->event_sock);
   5.383 +    }
   5.384  #endif
   5.385  
   5.386  }
   5.387 @@ -284,34 +287,50 @@
   5.388   * @return <code>true</code>, if the connection was successfully opened.
   5.389   */
   5.390  gboolean
   5.391 -gmyth_monitor_handler_open (GMythMonitorHandler *monitor, const gchar *hostname, gint port)
   5.392 +gmyth_monitor_handler_open (GMythMonitorHandler * monitor,
   5.393 +                            const gchar * hostname, gint port)
   5.394  {
   5.395 -  gboolean ret = TRUE;
   5.396 -  
   5.397 -  g_return_val_if_fail( hostname != NULL, FALSE );
   5.398 +    gboolean ret = TRUE;
   5.399  
   5.400 -  if (monitor->hostname != NULL) {
   5.401 -    g_free (monitor->hostname);
   5.402 -    monitor->hostname = NULL;
   5.403 -  }
   5.404 +    g_return_val_if_fail (hostname != NULL, FALSE);
   5.405  
   5.406 -  monitor->hostname = g_strdup (hostname);
   5.407 -  monitor->port = port;
   5.408 +    if (monitor->hostname != NULL)
   5.409 +    {
   5.410 +        g_free (monitor->hostname);
   5.411 +        monitor->hostname = NULL;
   5.412 +    }
   5.413  
   5.414 -  gmyth_debug ("Monitor event socket --- hostname: %s, port %d\n", monitor->hostname, monitor->port);
   5.415 -  
   5.416 -  /* configure the event socket */
   5.417 -  if ( NULL == monitor->event_sock) { 
   5.418 -      if (!gmyth_connect_to_backend_monitor (monitor)) {
   5.419 -          gmyth_debug( "Connection to backend failed (Event Socket)." );
   5.420 -          ret = FALSE;
   5.421 -      }
   5.422 -      else {
   5.423 -          gmyth_debug("Remote monitor event socket already created.\n");
   5.424 -      }
   5.425 -  }
   5.426 +    monitor->hostname = g_strdup (hostname);
   5.427 +    monitor->port = port;
   5.428  
   5.429 -  return ret;
   5.430 +    gmyth_debug ("Monitor event socket --- hostname: %s, port %d\n",
   5.431 +                 monitor->hostname, monitor->port);
   5.432 +
   5.433 +    if ( NULL != monitor->event_sock)
   5.434 +    {
   5.435 +    	g_object_unref( monitor->event_sock );
   5.436 +  	monitor->event_sock = NULL;
   5.437 +    }
   5.438 +
   5.439 +    /* configure the event socket */
   5.440 +    if (NULL == monitor->event_sock)
   5.441 +    {
   5.442 +        if (!gmyth_connect_to_backend_monitor (monitor))
   5.443 +        {
   5.444 +            gmyth_debug ("Connection to backend failed (Event Socket)!");
   5.445 +            ret = FALSE;
   5.446 +        }
   5.447 +        else
   5.448 +	{
   5.449 +	    gmyth_debug ( "Remote monitor event socket had been succesfully created. (io_fd == %d)\n", 
   5.450 +	    	g_io_channel_unix_get_fd( monitor->event_sock->sd_io_ch ) );
   5.451 +	}
   5.452 +    } else
   5.453 +    {
   5.454 +    	gmyth_debug ("ASSERT ERROR: Remote monitor event socket is not NULL at the setup...\n");
   5.455 +    }
   5.456 +
   5.457 +    return ret;
   5.458  
   5.459  }
   5.460  
   5.461 @@ -326,178 +345,213 @@
   5.462   * @return The backend status message code ID.
   5.463   */
   5.464  static gint
   5.465 -gmyth_monitor_handler_is_backend_message( GMythMonitorHandler *monitor,
   5.466 -                        GMythStringList* strlist, gchar **back_msg_action )
   5.467 +gmyth_monitor_handler_is_backend_message (GMythMonitorHandler * monitor,
   5.468 +                                          GMythStringList * strlist,
   5.469 +                                          gchar ** back_msg_action)
   5.470  {
   5.471 -	gint msg_type = GMYTH_BACKEND_NO_MESSAGE;
   5.472 -	GString *back_msg = NULL;
   5.473 -	
   5.474 -	if ( gmyth_string_list_length(strlist) > 0 )
   5.475 -	{
   5.476 -		
   5.477 -		back_msg = gmyth_string_list_get_string( strlist, 0 );
   5.478 -		if ( back_msg != NULL && back_msg->str != NULL &&
   5.479 -		                                strstr( back_msg->str, "BACKEND" ) != NULL )
   5.480 -		{
   5.481 -			gmyth_debug( "MONITOR HANDLER - Received backend message = %s", back_msg->str );
   5.482 -	  	    *back_msg_action = gmyth_string_list_get_char_array( strlist, 1 );
   5.483 -	  	
   5.484 -	  	if ( back_msg_action != NULL )
   5.485 -	  	{	        	
   5.486 -	  	
   5.487 -	    	if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
   5.488 -	    			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) || 
   5.489 -	    			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "SCHEDULE_CHANGE" ) ||
   5.490 -	    			g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
   5.491 -	    	{
   5.492 -	    		gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_PROGRAM_INFO_CHANGED, msg = %s", *back_msg_action );
   5.493 -	    		msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
   5.494 -	    	} else if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "DONE_RECORDING" ) ) {
   5.495 -	    		gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_DONE_RECORDING, msg = %s", *back_msg_action );
   5.496 -	    		msg_type = GMYTH_BACKEND_DONE_RECORDING;
   5.497 -	    	} else if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "QUIT" ) ) {
   5.498 -	    		gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_STOP_LIVETV, msg = %s", *back_msg_action );
   5.499 -	    		msg_type = GMYTH_BACKEND_STOP_LIVETV;	    		
   5.500 -	  		}	    	
   5.501 -	
   5.502 -	      /* g_hash_table_insert ( monitor->backend_msgs,
   5.503 -	                             &(monitor->actual_index), *back_msg_action ); */
   5.504 -		    
   5.505 -		  } /*  if  */
   5.506 -		  
   5.507 -		} /* if */
   5.508 -		
   5.509 -		if ( back_msg != NULL )
   5.510 -		{
   5.511 -			g_string_free( back_msg, TRUE );
   5.512 -			back_msg = NULL;        	
   5.513 -		}
   5.514 -		
   5.515 -	} /* if - Does Monitor got any message from backend? */
   5.516 -	else {
   5.517 -		*back_msg_action = g_strdup("");
   5.518 -	}
   5.519 -	
   5.520 -	return msg_type;
   5.521 +    gint msg_type = GMYTH_BACKEND_NO_MESSAGE;
   5.522 +    GString *back_msg = NULL;
   5.523 +
   5.524 +    if (gmyth_string_list_length (strlist) > 0)
   5.525 +    {
   5.526 +
   5.527 +        back_msg = gmyth_string_list_get_string (strlist, 0);
   5.528 +        if (back_msg != NULL && back_msg->str != NULL &&
   5.529 +            strstr (back_msg->str, "BACKEND") != NULL)
   5.530 +        {
   5.531 +            gmyth_debug ("MONITOR HANDLER - Received backend message = %s",
   5.532 +                         back_msg->str);
   5.533 +            *back_msg_action = gmyth_string_list_get_char_array (strlist, 1);
   5.534 +
   5.535 +            if (back_msg_action != NULL)
   5.536 +            {
   5.537 +
   5.538 +                if (g_strstr_len
   5.539 +                    (*back_msg_action, strlen (*back_msg_action),
   5.540 +                     "LIVETV_CHAIN")
   5.541 +                    || g_strstr_len (*back_msg_action,
   5.542 +                                     strlen (*back_msg_action),
   5.543 +                                     "RECORDING_LIST_CHANGE")
   5.544 +                    || g_strstr_len (*back_msg_action,
   5.545 +                                     strlen (*back_msg_action),
   5.546 +                                     "SCHEDULE_CHANGE")
   5.547 +                    || g_strstr_len (*back_msg_action,
   5.548 +                                     strlen (*back_msg_action), "LIVETV_WATCH"))
   5.549 +                {
   5.550 +                    gmyth_debug
   5.551 +                        ("MONITOR: message type == GMYTH_BACKEND_PROGRAM_INFO_CHANGED, msg = %s",
   5.552 +                         *back_msg_action);
   5.553 +                    msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
   5.554 +                }
   5.555 +                else if (g_strstr_len
   5.556 +                         (*back_msg_action, strlen (*back_msg_action),
   5.557 +                          "DONE_RECORDING"))
   5.558 +                {
   5.559 +                    gmyth_debug
   5.560 +                        ("MONITOR: message type == GMYTH_BACKEND_DONE_RECORDING, msg = %s",
   5.561 +                         *back_msg_action);
   5.562 +                    msg_type = GMYTH_BACKEND_DONE_RECORDING;
   5.563 +                }
   5.564 +                else if (g_strstr_len
   5.565 +                         (*back_msg_action, strlen (*back_msg_action), "QUIT"))
   5.566 +                {
   5.567 +                    gmyth_debug
   5.568 +                        ("MONITOR: message type == GMYTH_BACKEND_STOP_LIVETV, msg = %s",
   5.569 +                         *back_msg_action);
   5.570 +                    msg_type = GMYTH_BACKEND_STOP_LIVETV;
   5.571 +                }
   5.572 +
   5.573 +                /* g_hash_table_insert ( monitor->backend_msgs,
   5.574 +                   &(monitor->actual_index), *back_msg_action ); */
   5.575 +
   5.576 +            } /*  if  */
   5.577 +
   5.578 +        } /* if */
   5.579 +
   5.580 +        if (back_msg != NULL)
   5.581 +        {
   5.582 +            g_string_free (back_msg, TRUE);
   5.583 +            back_msg = NULL;
   5.584 +        }
   5.585 +
   5.586 +    }                           /* if - Does Monitor got any message from backend? */
   5.587 +    else
   5.588 +    {
   5.589 +        *back_msg_action = g_strdup ("");
   5.590 +    }
   5.591 +
   5.592 +    return msg_type;
   5.593  
   5.594  }
   5.595  
   5.596  static void
   5.597 -gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message )
   5.598 +gmyth_monitor_handler_default_listener (GMythMonitorHandler * monitor,
   5.599 +                                        gint msg_code, gchar * message)
   5.600  {
   5.601 -	//assert( message!= NULL );  
   5.602 -	gmyth_debug( "DEFAULT Signal handler ( msg = %s, code = %d )\n", 
   5.603 -				message, msg_code );
   5.604 +    //assert( message!= NULL );  
   5.605 +    gmyth_debug ("DEFAULT Signal handler ( msg = %s, code = %d )\n",
   5.606 +                 message, msg_code);
   5.607  }
   5.608  
   5.609  static void
   5.610 -gmyth_monitor_handler_print( GString *str, gpointer ptr )
   5.611 +gmyth_monitor_handler_print (GString * str, gpointer ptr)
   5.612  {
   5.613 -	gmyth_debug( "Backend message event: %s --- ", str->str );
   5.614 +    gmyth_debug ("Backend message event: %s --- ", str->str);
   5.615  }
   5.616  
   5.617  /** 
   5.618   * Opens connection the the Monitor socket on MythTV backend server,
   5.619   * where all status messages are notified to the client.
   5.620   * 
   5.621 - * @param io_channel The GIOChannel instance to the Monitor connection.
   5.622 - * @param io_cond The GIOCondition describing the actual status of the IO Channel.
   5.623   * @param data Pointer to the GMythMonitorHandler.
   5.624   * 
   5.625 - * @return <code>true</code>, if the data was successfully read.
   5.626 + * @return Pointer to a gboolean <code>true</code> value, if the data was 
   5.627 + * 	successfully read.
   5.628   */
   5.629 -gboolean
   5.630 -gmyth_monitor_handler_listener( GIOChannel *io_channel, GIOCondition io_cond, gpointer data )
   5.631 +gpointer
   5.632 +gmyth_monitor_handler_listener (gpointer data)
   5.633  {
   5.634 -	GMythMonitorHandler *monitor = (GMythMonitorHandler*)data; 
   5.635 -  guint recv = 0;
   5.636 -  gboolean ret = TRUE;
   5.637 -  gsize len = 0;
   5.638 -  
   5.639 -  static guint count = 0;
   5.640 +    GMythMonitorHandler *monitor = (GMythMonitorHandler *) data;
   5.641 +    guint recv = 0;
   5.642 +    gboolean *ret = g_new0( gboolean, 1 );
   5.643 +    gsize len = 0;
   5.644 +    GIOChannel *io_channel = monitor->event_sock->sd_io_ch;
   5.645 +    GIOCondition io_cond = g_io_channel_get_buffer_condition( io_channel );
   5.646 +    static guint count = 0;
   5.647  
   5.648 -  myth_control_acquire_context ( monitor, TRUE );
   5.649 -  
   5.650 -  if ( ( io_cond & G_IO_HUP ) != 0 ) {
   5.651 -  	ret = FALSE;
   5.652 -  	goto clean_up;
   5.653 -  }
   5.654 -  
   5.655 -  //GIOChannel *io_channel = monitor->event_sock->sd_io_ch;
   5.656 -  //GIOCondition condition = g_io_channel_get_buffer_condition( io_channel );
   5.657 -  
   5.658 -  GMythStringList *strlist = NULL;
   5.659 -  
   5.660 -  if ( NULL == io_channel ) {
   5.661 -  	gmyth_debug ("Monitor socket is NULL! (GIOChannel)");
   5.662 -  	ret = FALSE;
   5.663 -  	goto clean_up;
   5.664 -  }
   5.665 -    
   5.666 -  if (monitor->allow_msgs_listener) {
   5.667 -  	++count;
   5.668 -  	
   5.669 -  	gmyth_debug ("%d - Listening on Monitor socket...!\n", count);
   5.670 -	
   5.671 -    do 
   5.672 +    *ret = TRUE;
   5.673 +
   5.674 +    gmyth_debug ( "Entering MONITOR handler listener..." );
   5.675 +
   5.676 +    myth_control_acquire_context (monitor, TRUE);
   5.677 +
   5.678 +    if ((io_cond & G_IO_HUP) != 0)
   5.679      {
   5.680 -    	
   5.681 -    	gint bytes_sent = 0;
   5.682 -    	
   5.683 -    	strlist = gmyth_string_list_new();
   5.684 -    	
   5.685 -    	if ( monitor->event_sock != NULL )
   5.686 -    	{
   5.687 -    		
   5.688 -	      len = gmyth_socket_read_stringlist( monitor->event_sock, strlist );
   5.689 -	      
   5.690 -		    if ( ( len > 0 ) && strlist != NULL && gmyth_string_list_length( strlist ) > 0 ) 
   5.691 -		    { 
   5.692 -			    bytes_sent = gmyth_string_list_get_int( strlist,  0 ); // -1 on backend error
   5.693 -	
   5.694 -		      gmyth_debug ( "[%s] MONITOR: received data buffer from IO event channel... %d strings gone!\n", 
   5.695 -		      		__FUNCTION__, len );
   5.696 -		      		
   5.697 -		      recv += len;
   5.698 -		      
   5.699 -		      /* debug purpose: prints out all the string list elements */
   5.700 -		      g_list_foreach( strlist->glist, (GFunc)gmyth_monitor_handler_print, NULL );
   5.701 -		      
   5.702 -		      gchar *back_msg_action = g_new0( gchar, 1 );
   5.703 -		      gint msg_type = gmyth_monitor_handler_is_backend_message( monitor, strlist, 
   5.704 -		      		&back_msg_action );
   5.705 -		      		
   5.706 -		      if (monitor!=NULL)		      
   5.707 -		        g_signal_emit ( monitor,
   5.708 -		               GMYTH_MONITOR_HANDLER_GET_CLASS (monitor)->backend_events_handler_signal_id,
   5.709 -		               0, /* details */
   5.710 -		               msg_type, back_msg_action );
   5.711 -	               
   5.712 -	        if (back_msg_action!= NULL)
   5.713 -	        	g_free( back_msg_action );
   5.714 -		      
   5.715 -		    }
   5.716 -		    
   5.717 -    	}
   5.718 -	    
   5.719 -	    if (strlist!=NULL)
   5.720 -	    {
   5.721 -	    	g_object_unref( strlist );
   5.722 -	    	strlist = NULL;
   5.723 -	    }
   5.724 +        *ret = FALSE;
   5.725 +        goto clean_up;
   5.726 +    }
   5.727  
   5.728 -      io_cond = g_io_channel_get_buffer_condition (io_channel);
   5.729 +    GMythStringList *strlist = NULL;
   5.730  
   5.731 -    } while ( recv <= 0 && ( ( io_cond & G_IO_HUP ) == 0 ) );
   5.732 -    
   5.733 -    gmyth_debug ("\tMONITOR EVENT: Read %d bytes\n", recv );
   5.734 +    if (NULL == io_channel)
   5.735 +    {
   5.736 +        gmyth_debug ("Monitor socket is NULL! (GIOChannel)");
   5.737 +        *ret = FALSE;
   5.738 +        goto clean_up;
   5.739 +    }
   5.740  
   5.741 -  } /* main GThread while */
   5.742 -  
   5.743 -clean_up:
   5.744 -  myth_control_release_context (monitor);
   5.745 -  	
   5.746 - 	return ret;
   5.747 +    while (monitor->allow_msgs_listener)
   5.748 +    {
   5.749 +        ++count;
   5.750 +
   5.751 +        gmyth_debug ("%d - Listening on Monitor socket...!\n", count);
   5.752 +
   5.753 +        do
   5.754 +        {
   5.755 +
   5.756 +            gint bytes_sent = 0;
   5.757 +
   5.758 +            strlist = gmyth_string_list_new ();
   5.759 +
   5.760 +            if (monitor->event_sock != NULL)
   5.761 +            {
   5.762 +
   5.763 +                len =
   5.764 +                    gmyth_socket_read_stringlist (monitor->event_sock, strlist);
   5.765 +
   5.766 +                if ((len > 0) && strlist != NULL
   5.767 +                    && gmyth_string_list_length (strlist) > 0)
   5.768 +                {
   5.769 +                    bytes_sent = gmyth_string_list_get_int (strlist, 0);        // -1 on backend error
   5.770 +
   5.771 +                    gmyth_debug
   5.772 +                        ("[%s] MONITOR: received data buffer from IO event channel... %d strings gone!\n",
   5.773 +                         __FUNCTION__, len);
   5.774 +
   5.775 +                    recv += len;
   5.776 +
   5.777 +                    /* debug purpose: prints out all the string list elements */
   5.778 +                    g_list_foreach (strlist->glist,
   5.779 +                                    (GFunc) gmyth_monitor_handler_print, NULL);
   5.780 +
   5.781 +                    gchar *back_msg_action = g_new0 (gchar, 1);
   5.782 +                    gint msg_type =
   5.783 +                        gmyth_monitor_handler_is_backend_message (monitor,
   5.784 +                                                                  strlist,
   5.785 +                                                                  &back_msg_action);
   5.786 +
   5.787 +                    if (monitor != NULL)
   5.788 +                        g_signal_emit (monitor, GMYTH_MONITOR_HANDLER_GET_CLASS (monitor)->backend_events_handler_signal_id, 0, /* details */
   5.789 +                                       msg_type, back_msg_action);
   5.790 +
   5.791 +                    if (back_msg_action != NULL)
   5.792 +                        g_free (back_msg_action);
   5.793 +
   5.794 +                }
   5.795 +
   5.796 +            }
   5.797 +
   5.798 +            if (strlist != NULL)
   5.799 +            {
   5.800 +                g_object_unref (strlist);
   5.801 +                strlist = NULL;
   5.802 +            }
   5.803 +
   5.804 +            io_cond = g_io_channel_get_buffer_condition (io_channel);
   5.805 +
   5.806 +        }
   5.807 +        while (recv <= 0 && ((io_cond & G_IO_HUP) == 0));
   5.808 +
   5.809 +        gmyth_debug ("\tMONITOR EVENT: Read %d bytes\n", recv);
   5.810 +
   5.811 +    } /* main GThread while */
   5.812 +
   5.813 +  clean_up:
   5.814 +    myth_control_release_context (monitor);
   5.815 +
   5.816 +    g_thread_exit( ret );
   5.817 +
   5.818 +    return (gpointer)ret;
   5.819  
   5.820  }
   5.821  
   5.822 @@ -510,23 +564,24 @@
   5.823   * @return <code>true</code>, if the socket was successfully opened.
   5.824   */
   5.825  static gboolean
   5.826 -gmyth_connect_to_backend_monitor (GMythMonitorHandler *monitor)
   5.827 +gmyth_connect_to_backend_monitor (GMythMonitorHandler * monitor)
   5.828  {
   5.829 -  gboolean ret = TRUE;
   5.830 +    gboolean ret = TRUE;
   5.831  
   5.832 -  monitor->event_sock = gmyth_socket_new();
   5.833 +    monitor->event_sock = gmyth_socket_new ();
   5.834  
   5.835 -  /* Connects the socket, send Mythtv ANN Monitor and verify Mythtv protocol version */ 
   5.836 -  if (!gmyth_socket_connect_to_backend_events ( monitor->event_sock,
   5.837 -          monitor->hostname, monitor->port, FALSE ) ) 
   5.838 -  {
   5.839 -    g_object_unref (monitor->event_sock);
   5.840 -    monitor->event_sock = NULL;
   5.841 -    ret = FALSE;
   5.842 -  }
   5.843 -  
   5.844 -  return ret;
   5.845 -}    
   5.846 +    /* Connects the socket, send Mythtv ANN Monitor and verify Mythtv protocol version */
   5.847 +    if (!gmyth_socket_connect_to_backend_events (monitor->event_sock,
   5.848 +                                                 monitor->hostname,
   5.849 +                                                 monitor->port, FALSE))
   5.850 +    {
   5.851 +        g_object_unref (monitor->event_sock);
   5.852 +        monitor->event_sock = NULL;
   5.853 +        ret = FALSE;
   5.854 +    }
   5.855 +
   5.856 +    return ret;
   5.857 +}
   5.858  
   5.859  /** 
   5.860   * Opens connection the the Monitor socket on MythTV backend server,
   5.861 @@ -539,33 +594,37 @@
   5.862   * 				 GMythMonitorHandler could be configured.
   5.863   */
   5.864  static gboolean
   5.865 -gmyth_monitor_handler_setup( GMythMonitorHandler *monitor, GIOChannel *channel )
   5.866 +gmyth_monitor_handler_setup (GMythMonitorHandler * monitor,
   5.867 +                             GIOChannel * channel)
   5.868  {
   5.869 -	gboolean ret = TRUE;
   5.870 -	
   5.871 -  if ( channel != NULL ) {
   5.872 -  	
   5.873 -  	monitor->allow_msgs_listener = TRUE;
   5.874 -    
   5.875 -    monitor->sid_io_watch = -1;
   5.876 -  	
   5.877 -    monitor->sid_io_watch = g_io_add_watch (channel, G_IO_IN | G_IO_HUP, 
   5.878 -    					(GIOFunc)gmyth_monitor_handler_listener, monitor );
   5.879 -  } else {
   5.880 -  	ret = FALSE;
   5.881 -  	goto cleanup;
   5.882 -  }
   5.883 +    gboolean ret = TRUE;
   5.884  
   5.885 -  if (monitor->sid_io_watch < 0){
   5.886 -    gmyth_debug( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
   5.887 -    ret = FALSE;
   5.888 -    goto cleanup;
   5.889 -  }
   5.890 -  
   5.891 -cleanup:
   5.892 -    
   5.893 -  return ret;
   5.894 -  
   5.895 +    if (channel != NULL)
   5.896 +    {
   5.897 +        monitor->allow_msgs_listener = TRUE;
   5.898 +
   5.899 +        monitor->th = g_thread_create ( (GThreadFunc)gmyth_monitor_handler_listener,
   5.900 +                                       monitor, TRUE, NULL );
   5.901 +	gmyth_debug( "MONITOR GThread created!" );
   5.902 +    }
   5.903 +    else
   5.904 +    {
   5.905 +        ret = FALSE;
   5.906 +        goto cleanup;
   5.907 +    }
   5.908 +
   5.909 +    if (NULL == monitor->th)
   5.910 +    {
   5.911 +        gmyth_debug
   5.912 +            ("[%s] Error adding GThread listener function to the IO control channel!\n",
   5.913 +             __FUNCTION__);
   5.914 +        ret = FALSE;
   5.915 +        goto cleanup;
   5.916 +    }
   5.917 +
   5.918 +  cleanup:
   5.919 +
   5.920 +    return ret;
   5.921  }
   5.922  
   5.923  /** 
   5.924 @@ -575,24 +634,35 @@
   5.925   * 
   5.926   * @return <code>true</code>, if the MonitorHandler was started.
   5.927   */
   5.928 -gboolean 
   5.929 -gmyth_monitor_handler_start (GMythMonitorHandler *monitor)
   5.930 +gboolean
   5.931 +gmyth_monitor_handler_start (GMythMonitorHandler * monitor)
   5.932  {
   5.933      gboolean ret = TRUE;
   5.934 -	
   5.935 -    ret = gmyth_monitor_handler_setup( monitor, monitor->event_sock->sd_io_ch ); 
   5.936 -    if ( ret ) {
   5.937 -  	    gmyth_debug ( "\n[%s]\tOK! Starting listener on the MONITOR event socket...[thread location = %p]\n", 
   5.938 -  				__FUNCTION__, g_thread_self( ) );
   5.939 -  	    ret = TRUE;  	  	
   5.940 -    } else {
   5.941 -  	    gmyth_debug ( "\n[%s]\tERROR! Coudn't start listener on the MONITOR event socket...[thread location = %p]\n", 
   5.942 -  				__FUNCTION__, g_thread_self( ) );
   5.943 -  	    ret = FALSE;
   5.944 +
   5.945 +    if ( !( ret = g_thread_supported ()) ) 
   5.946 +    {
   5.947 +    	gmyth_debug( "Thread system wasn't initialized, starting NOW!!!" );
   5.948 +    	g_thread_init (NULL);
   5.949      }
   5.950  
   5.951 -    gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n", 
   5.952 -  			__FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) );
   5.953 -    
   5.954 +    ret = gmyth_monitor_handler_setup (monitor, monitor->event_sock->sd_io_ch);
   5.955 +    if (ret)
   5.956 +    {
   5.957 +        gmyth_debug
   5.958 +            ("\n[%s]\tOK! Starting listener on the MONITOR event socket...[thread location = %p]\n",
   5.959 +             __FUNCTION__, g_thread_self ());
   5.960 +    }
   5.961 +    else
   5.962 +    {
   5.963 +        gmyth_debug
   5.964 +            ("\n[%s]\tERROR! Coudn't start listener on the MONITOR event socket...[thread location = %p]\n",
   5.965 +             __FUNCTION__, g_thread_self ());
   5.966 +        ret = FALSE;
   5.967 +    }
   5.968 +
   5.969 +    gmyth_debug
   5.970 +        ("[%s] Watch listener function over the IO control channel? %s!!!\n",
   5.971 +         __FUNCTION__, (ret == TRUE ? "YES" : "NO"));
   5.972 +
   5.973      return ret;
   5.974  }
     6.1 --- a/gmyth/src/gmyth_monitor_handler.h	Tue May 15 20:16:26 2007 +0100
     6.2 +++ b/gmyth/src/gmyth_monitor_handler.h	Tue May 15 21:39:04 2007 +0100
     6.3 @@ -10,23 +10,23 @@
     6.4   * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
     6.5   * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
     6.6   *
     6.7 - *//*
     6.8 - * 
     6.9 - * This program is free software; you can redistribute it and/or modify
    6.10 - * it under the terms of the GNU Lesser General Public License as published by
    6.11 - * the Free Software Foundation; either version 2 of the License, or
    6.12 - * (at your option) any later version.
    6.13 - *
    6.14 - * This program is distributed in the hope that it will be useful,
    6.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.17 - * GNU General Public License for more details.
    6.18 - *
    6.19 - * You should have received a copy of the GNU Lesser General Public License
    6.20 - * along with this program; if not, write to the Free Software
    6.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.22 - */
    6.23 - 
    6.24 +          *//*
    6.25 +       * 
    6.26 +       * This program is free software; you can redistribute it and/or modify
    6.27 +       * it under the terms of the GNU Lesser General Public License as published by
    6.28 +       * the Free Software Foundation; either version 2 of the License, or
    6.29 +       * (at your option) any later version.
    6.30 +       *
    6.31 +       * This program is distributed in the hope that it will be useful,
    6.32 +       * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.33 +       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.34 +       * GNU General Public License for more details.
    6.35 +       *
    6.36 +       * You should have received a copy of the GNU Lesser General Public License
    6.37 +       * along with this program; if not, write to the Free Software
    6.38 +       * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.39 +       */
    6.40 +
    6.41  #ifndef __GMYTH_MONITOR_HANDLER_H__
    6.42  #define __GMYTH_MONITOR_HANDLER_H__
    6.43  
    6.44 @@ -44,76 +44,74 @@
    6.45  #include "gmyth_uri.h"
    6.46  
    6.47  G_BEGIN_DECLS
    6.48 -
    6.49  #define GMYTH_MONITOR_HANDLER_TYPE               (gmyth_monitor_handler_get_type ())
    6.50  #define GMYTH_MONITOR_HANDLER(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_MONITOR_HANDLER_TYPE, GMythMonitorHandler))
    6.51  #define GMYTH_MONITOR_HANDLER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_MONITOR_HANDLER_TYPE, GMythMonitorHandlerClass))
    6.52  #define IS_GMYTH_MONITOR_HANDLER(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMYTH_MONITOR_HANDLER_TYPE))
    6.53  #define IS_GMYTH_MONITOR_HANDLER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_MONITOR_HANDLER_TYPE))
    6.54  #define GMYTH_MONITOR_HANDLER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_MONITOR_HANDLER_TYPE, GMythMonitorHandlerClass))
    6.55 +#define GMYTHTV_MONITOR_HANDLER_READ_ERROR	-314
    6.56 +    enum
    6.57 +    {
    6.58 +        GMYTH_BACKEND_NO_MESSAGE = 0,
    6.59 +        GMYTH_BACKEND_PROGRAM_INFO_CHANGED,
    6.60 +        GMYTH_BACKEND_DONE_RECORDING,
    6.61 +        GMYTH_BACKEND_STOP_LIVETV
    6.62 +    };
    6.63  
    6.64 -#define GMYTHTV_MONITOR_HANDLER_READ_ERROR	-314
    6.65 -
    6.66 -enum {
    6.67 -	GMYTH_BACKEND_NO_MESSAGE = 0,
    6.68 -  GMYTH_BACKEND_PROGRAM_INFO_CHANGED,
    6.69 -  GMYTH_BACKEND_DONE_RECORDING,
    6.70 -  GMYTH_BACKEND_STOP_LIVETV
    6.71 -};
    6.72 -
    6.73 -typedef struct _GMythMonitorHandler         GMythMonitorHandler;
    6.74 -typedef struct _GMythMonitorHandlerClass    GMythMonitorHandlerClass;
    6.75 +typedef struct _GMythMonitorHandler GMythMonitorHandler;
    6.76 +typedef struct _GMythMonitorHandlerClass GMythMonitorHandlerClass;
    6.77  
    6.78  struct _GMythMonitorHandlerClass
    6.79 -{
    6.80 -	GObjectClass parent_class;
    6.81 +    {
    6.82 +        GObjectClass parent_class;
    6.83  
    6.84 -	/* callbacks */	
    6.85 -	guint backend_events_handler_signal_id;
    6.86 +        /* callbacks */
    6.87 +        guint backend_events_handler_signal_id;
    6.88  
    6.89 -  /* signal default handlers */
    6.90 -  void (*backend_events_handler) (GMythMonitorHandler *monitor, gint msg_code, gchar* message );
    6.91 -};
    6.92 +        /* signal default handlers */
    6.93 +        void (*backend_events_handler) (GMythMonitorHandler * monitor,
    6.94 +                                        gint msg_code, gchar * message);
    6.95 +    };
    6.96  
    6.97  struct _GMythMonitorHandler
    6.98 -{
    6.99 -	GObject parent;
   6.100 +    {
   6.101 +        GObject parent;
   6.102  
   6.103 -	/* MythTV version number */	
   6.104 -	gint mythtv_version;
   6.105 +        /* MythTV version number */
   6.106 +        gint mythtv_version;
   6.107  
   6.108 -	/* socket descriptors */
   6.109 -	GMythSocket *event_sock;
   6.110 +        /* socket descriptors */
   6.111 +        GMythSocket *event_sock;
   6.112 +
   6.113 +        gpointer (*gmyth_monitor_handler_listener) (gpointer data);
   6.114 +
   6.115 +        gchar *hostname;
   6.116 +        gint port;
   6.117 +
   6.118 +        gint64 actual_index;
   6.119 +
   6.120 +        gboolean allow_msgs_listener;
   6.121 +
   6.122 +        /* stores the messages coming from the backend */
   6.123 +        GHashTable *backend_msgs;
   6.124 +
   6.125 +        GMutex *mutex;
   6.126  	
   6.127 -	gboolean (*gmyth_monitor_handler_listener) ( GIOChannel *io_channel, 
   6.128 -						GIOCondition io_cond, gpointer data );
   6.129 -	
   6.130 -	gchar *hostname;
   6.131 -	gint port;
   6.132 -	
   6.133 -	gint64 actual_index;
   6.134 -	
   6.135 -	gboolean allow_msgs_listener;
   6.136 -	
   6.137 -	/* stores the messages coming from the backend */
   6.138 -	GHashTable *backend_msgs;	
   6.139 -	
   6.140 -	GMutex	*mutex;
   6.141 -	
   6.142 -	guint sid_io_watch;
   6.143 +	GThread *th;
   6.144  
   6.145 -};
   6.146 +    };
   6.147  
   6.148 -GType          gmyth_monitor_handler_get_type        (void);
   6.149 +GType gmyth_monitor_handler_get_type (void);
   6.150  
   6.151 -GMythMonitorHandler* gmyth_monitor_handler_new ( void );
   6.152 +GMythMonitorHandler *gmyth_monitor_handler_new (void);
   6.153  
   6.154 -gboolean gmyth_monitor_handler_open (GMythMonitorHandler *monitor, const gchar *hostname, gint port);
   6.155 +gboolean gmyth_monitor_handler_open (GMythMonitorHandler * monitor,
   6.156 +                                     const gchar * hostname, gint port);
   6.157  
   6.158 -gboolean gmyth_monitor_handler_start (GMythMonitorHandler *monitor);
   6.159 +gboolean gmyth_monitor_handler_start (GMythMonitorHandler * monitor);
   6.160  
   6.161 -void gmyth_monitor_handler_close (GMythMonitorHandler *monitor);
   6.162 +void gmyth_monitor_handler_close (GMythMonitorHandler * monitor);
   6.163  
   6.164  G_END_DECLS
   6.165 -
   6.166  #endif /* __GMYTH_MONITOR_HANDLER_H__ */