[svn r178] API adding to allow Monitor events' socket listening. trunk
authorrosfran
Sat Dec 02 03:46:17 2006 +0000 (2006-12-02)
branchtrunk
changeset 17785b47c66a241
parent 176 94a7f5399f79
child 178 b3904bc4ac6d
[svn r178] API adding to allow Monitor events' socket listening.
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_file_transfer.h
gmyth/src/gmyth_socket.c
gmyth/src/gmyth_socket.h
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Sat Dec 02 03:41:47 2006 +0000
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Sat Dec 02 03:46:17 2006 +0000
     1.3 @@ -33,6 +33,7 @@
     1.4   */
     1.5  
     1.6  #include "gmyth_file_transfer.h"
     1.7 +#include "gmyth_uri.h"
     1.8  #include "gmyth_livetv.h"
     1.9  #include "gmyth_util.h"
    1.10  #include "gmyth_socket.h"
    1.11 @@ -57,7 +58,7 @@
    1.12  #define GMYTHTV_RETRIES							-1
    1.13  #define GMYTHTV_FILE_SIZE						0
    1.14  
    1.15 -#define GMYTHTV_BUFFER_SIZE					128*1024
    1.16 +#define GMYTHTV_BUFFER_SIZE					8*1024
    1.17  
    1.18  #define GMYTHTV_VERSION							30
    1.19  
    1.20 @@ -74,8 +75,6 @@
    1.21  #define GMYTHTV_ENABLE_DEBUG				1
    1.22  #endif
    1.23  
    1.24 -GThread *monitor_th = NULL;
    1.25 -
    1.26  enum myth_sock_types {
    1.27    GMYTH_PLAYBACK_TYPE = 0,
    1.28    GMYTH_MONITOR_TYPE,
    1.29 @@ -83,6 +82,7 @@
    1.30    GMYTH_RINGBUFFER_TYPE
    1.31  };
    1.32  
    1.33 +//static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT;
    1.34  
    1.35  static GMutex*				mutex 					 = NULL;
    1.36  
    1.37 @@ -120,9 +120,12 @@
    1.38  { 
    1.39    g_return_if_fail( transfer != NULL );
    1.40  
    1.41 +  //transfer->card_id = num;
    1.42 +  //transfer->rec_id = -1;
    1.43 +  //transfer->recordernum = num;
    1.44 +
    1.45    transfer->readposition = 0;
    1.46    transfer->filesize = GMYTHTV_FILE_SIZE;
    1.47 -  transfer->filename = NULL;
    1.48    //transfer->timeoutisfast = FALSE;
    1.49  
    1.50    //transfer->userreadahead = GMYTHTV_USER_READ_AHEAD;
    1.51 @@ -130,8 +133,8 @@
    1.52  
    1.53    transfer->control_sock = NULL;
    1.54    transfer->sock = NULL;
    1.55 -
    1.56 -  transfer->backend_info = NULL;
    1.57 +  
    1.58 +  transfer->monitor = NULL;
    1.59    
    1.60    /* it is used for signalizing the event socket consumer thread */
    1.61    io_watcher_cond = g_cond_new();
    1.62 @@ -156,49 +159,54 @@
    1.63  
    1.64  // fixme: do we need the card_id????
    1.65  GMythFileTransfer*
    1.66 -gmyth_file_transfer_new (GMythBackendInfo *backend_info)
    1.67 +gmyth_file_transfer_new ( const GMythBackendInfo *backend_info)
    1.68  {
    1.69    GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
    1.70 +  
    1.71 +  transfer->backend_info = (GMythBackendInfo *)backend_info;
    1.72  
    1.73 -  if (backend_info != NULL) {
    1.74 -    g_object_ref (backend_info);
    1.75 -    transfer->backend_info = backend_info;
    1.76 -  }
    1.77 +  return transfer;
    1.78 +}
    1.79 +
    1.80 +GMythFileTransfer* 
    1.81 +gmyth_file_transfer_new_with_uri ( const gchar* uri_str )
    1.82 +{
    1.83 +  GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
    1.84 +  
    1.85 +  transfer->uri = gmyth_uri_new_with_value (uri_str);
    1.86  
    1.87    return transfer;
    1.88  }
    1.89  
    1.90  gboolean
    1.91 -gmyth_file_transfer_open (GMythFileTransfer *transfer, const char *filename)
    1.92 +gmyth_file_transfer_open ( GMythFileTransfer *transfer )
    1.93  {
    1.94    gboolean ret = TRUE;
    1.95 -
    1.96 -  g_assert (transfer);
    1.97 -  g_return_val_if_fail (transfer->backend_info != NULL, FALSE);
    1.98 -  g_return_val_if_fail (filename != NULL, FALSE);
    1.99 -      
   1.100 -  // FIXME: Verify if file_transfer has already been opened
   1.101 -  if (transfer->filename != NULL) {
   1.102 -    g_warning ("[%s] File transfer already opened!", __FUNCTION__);
   1.103 -    return FALSE;
   1.104 +  
   1.105 +  g_return_val_if_fail( transfer != NULL, FALSE );
   1.106 +  
   1.107 +  if ( transfer->backend_info != NULL )
   1.108 +  {
   1.109 +	  transfer->hostname = g_string_new ( gmyth_backend_info_get_hostname(transfer->backend_info) );
   1.110 +	  transfer->port = gmyth_backend_info_get_port (transfer->backend_info);
   1.111 +  } else {
   1.112 +	  gmyth_debug ("[%s] URI: %s\n", __FUNCTION__, transfer->uri->uri->str);
   1.113 +	  transfer->hostname = g_string_new ( gmyth_uri_get_host(transfer->uri) );
   1.114 +	  transfer->port = gmyth_uri_get_port (transfer->uri);
   1.115    }
   1.116  
   1.117 -  transfer->filename = g_strdup (filename);
   1.118 -
   1.119 -  gmyth_debug ("[%s] File name: %s\n", __FUNCTION__, filename);
   1.120 -  gmyth_debug ("hostname: %s, port %d\n", transfer->backend_info->hostname, 
   1.121 -      transfer->backend_info->port);
   1.122 +  gmyth_debug ("hostname: %s, port %d\n", transfer->hostname->str, transfer->port);
   1.123    
   1.124    /* configure the control socket */
   1.125    if (transfer->control_sock == NULL) { 
   1.126      if (!gmyth_connect_to_backend (transfer)) {
   1.127 -      g_printerr( "Connection to backend failed (Control Socket).\n" );
   1.128 +      gmyth_debug( "Connection to backend failed (Control Socket).\n" );
   1.129        ret = FALSE;
   1.130      }
   1.131    } else {
   1.132      g_warning("Remote transfer control socket already created.\n");
   1.133    }
   1.134 -
   1.135 +  
   1.136    return ret;
   1.137  
   1.138  }
   1.139 @@ -207,15 +215,18 @@
   1.140  gmyth_connect_to_backend (GMythFileTransfer *transfer)
   1.141  {
   1.142    GString *base_str = NULL;
   1.143 +  GString *hostname = NULL;
   1.144    GMythStringList *strlist = NULL; 
   1.145 -  GString *hostname = NULL;
   1.146 +  gchar *path_dir = NULL;
   1.147    gboolean ret = TRUE;
   1.148  
   1.149    g_return_val_if_fail (transfer != NULL, FALSE );
   1.150 -  g_return_val_if_fail (transfer->filename != NULL, FALSE );
   1.151 -  g_return_val_if_fail (transfer->backend_info != NULL, FALSE);
   1.152 +  g_return_val_if_fail (transfer->hostname != NULL, FALSE);
   1.153 +  g_return_val_if_fail (transfer->port > 0, FALSE);
   1.154  
   1.155    base_str = g_string_new ("");
   1.156 +  path_dir = ( transfer->uri != NULL ? gmyth_uri_get_path (transfer->uri) : 
   1.157 +  				gmyth_backend_info_get_path( transfer->backend_info ) );
   1.158  
   1.159    /* Creates the control socket */
   1.160    if (transfer->control_sock != NULL) {
   1.161 @@ -227,7 +238,7 @@
   1.162  
   1.163    // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version 
   1.164    if (!gmyth_socket_connect_to_backend (transfer->control_sock,
   1.165 -          transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) {
   1.166 +          transfer->hostname->str, transfer->port, TRUE)) {
   1.167  
   1.168      g_object_unref (transfer->control_sock);
   1.169      transfer->control_sock = NULL;
   1.170 @@ -241,7 +252,7 @@
   1.171    }
   1.172  
   1.173    transfer->sock = gmyth_socket_new ();
   1.174 -  gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port);
   1.175 +  gmyth_socket_connect (transfer->sock, transfer->hostname->str, transfer->port);
   1.176  
   1.177    strlist = gmyth_string_list_new();
   1.178    hostname = gmyth_socket_get_local_hostname();
   1.179 @@ -252,7 +263,7 @@
   1.180    	g_string_printf( base_str, "ANN FileTransfer %s", hostname->str);
   1.181  
   1.182    gmyth_string_list_append_string (strlist, base_str );
   1.183 -  gmyth_string_list_append_char_array (strlist, transfer->filename );
   1.184 +  gmyth_string_list_append_char_array (strlist, path_dir );
   1.185  
   1.186    gmyth_socket_write_stringlist (transfer->sock, strlist );
   1.187    gmyth_socket_read_stringlist (transfer->sock, strlist );
   1.188 @@ -274,7 +285,22 @@
   1.189        goto cleanup;
   1.190    }
   1.191    
   1.192 -  //gmyth_connect_to_backend_monitor( transfer, hostname );
   1.193 +  transfer->monitor = gmyth_monitor_handler_new ( );
   1.194 +  
   1.195 +  ret = gmyth_monitor_handler_open ( transfer->monitor, transfer->hostname->str, transfer->port );
   1.196 +  
   1.197 +  if ( ret == TRUE )
   1.198 +  {
   1.199 +  	gmyth_debug("Connect MythTV Monitor event socket! Trying to start the message handler...");
   1.200 +  	
   1.201 +  	ret = gmyth_monitor_handler_start ( transfer->monitor );
   1.202 +  	
   1.203 +  	if (ret)
   1.204 +  		gmyth_debug("MythTV Monitor event socket connected and listening!");
   1.205 +  	else
   1.206 +  		gmyth_debug("Problems when trying to start MythTV Monitor event socket!");
   1.207 +  }
   1.208 +  
   1.209  cleanup:
   1.210  
   1.211    if ( strlist != NULL )
   1.212 @@ -343,7 +369,12 @@
   1.213      g_object_unref( transfer->control_sock );
   1.214      transfer->control_sock = NULL;
   1.215    } 
   1.216 -
   1.217 +  
   1.218 +  if ( transfer->monitor ) {
   1.219 +    g_object_unref( transfer->monitor );
   1.220 +    transfer->monitor = NULL;
   1.221 +  }
   1.222 +  
   1.223  }
   1.224  
   1.225  gint64
   1.226 @@ -439,7 +470,7 @@
   1.227  gint 
   1.228  gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, gint size, gboolean read_unlimited)
   1.229  {
   1.230 -  gsize bytes_sent = 0;
   1.231 +  gint bytes_sent = 0;
   1.232    gsize bytes_read = 0;
   1.233    gsize total_read = 0;
   1.234    
   1.235 @@ -468,13 +499,13 @@
   1.236    io_cond_control = g_io_channel_get_buffer_condition( io_channel );
   1.237    if ( transfer->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) ) {
   1.238      g_printerr( "gmyth_file_transfer_read(): Called with no raw socket.\n" );
   1.239 -    exit(0); // fixme remove this
   1.240 +    //exit(0); // fixme remove this
   1.241      return -1;
   1.242    }
   1.243  
   1.244    if ( transfer->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) ) {
   1.245      g_printerr( "gmyth_file_transfer_read(): Called with no control socket.\n" );
   1.246 -    exit(0); // fixme remove this
   1.247 +    //exit(0); // fixme remove this
   1.248      return -1;
   1.249    }
   1.250  
   1.251 @@ -482,9 +513,12 @@
   1.252    g_string_append_printf ( query, "%d", transfer->file_id );
   1.253    gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str );
   1.254    
   1.255 +  /* send requests to the maximum number of REQUEST_BLOCK messages */
   1.256 +  guint max_tries = 4;
   1.257 +  
   1.258    myth_control_acquire_context( TRUE );
   1.259    
   1.260 -  while (total_read == 0) {
   1.261 +  while (total_read == 0 && --max_tries > 0) {
   1.262      GMythStringList *strlist = gmyth_string_list_new();
   1.263  
   1.264      gmyth_string_list_append_char_array( strlist, query->str );
   1.265 @@ -511,11 +545,18 @@
   1.266                  bytes_sent -= bytes_read;
   1.267  	        
   1.268  	            /* append new data to the increasing byte array */
   1.269 -		    	data = g_byte_array_append (data, data_buffer, bytes_read);
   1.270 +		    		data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
   1.271  		        gmyth_debug ("Total file transfer data read: %d\n", total_read);
   1.272  	        }
   1.273              g_free (data_buffer);
   1.274 -	    }
   1.275 +	    } else {
   1.276 +	    	
   1.277 +      }
   1.278 +    } else {
   1.279 +    	total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
   1.280 +    	g_object_unref (strlist);
   1.281 +    	strlist = NULL; 
   1.282 +    	break;
   1.283      }
   1.284      g_object_unref (strlist);
   1.285      strlist = NULL;
   1.286 @@ -530,7 +571,9 @@
   1.287      g_error_free (error);
   1.288    }
   1.289    
   1.290 -  transfer->readposition += total_read;
   1.291 +  if ( total_read >= 0 )
   1.292 +  	transfer->readposition += total_read;
   1.293 +  	
   1.294    return total_read;
   1.295  }
   1.296  
     2.1 --- a/gmyth/src/gmyth_file_transfer.h	Sat Dec 02 03:41:47 2006 +0000
     2.2 +++ b/gmyth/src/gmyth_file_transfer.h	Sat Dec 02 03:46:17 2006 +0000
     2.3 @@ -37,6 +37,7 @@
     2.4  #include "gmyth_uri.h"
     2.5  #include "gmyth_livetv.h"
     2.6  #include "gmyth_backendinfo.h"
     2.7 +#include "gmyth_monitor_handler.h"
     2.8  
     2.9  #include <stdio.h>
    2.10  #include <stdlib.h>
    2.11 @@ -72,7 +73,9 @@
    2.12  	GObject parent;
    2.13  
    2.14  	/* Myth URI structure */
    2.15 -	//const GMythURI *uri;
    2.16 +	GMythURI *uri;
    2.17 +	GString* hostname;
    2.18 +	gint port;
    2.19  	gchar* filename;
    2.20  	GMythBackendInfo *backend_info;
    2.21  	
    2.22 @@ -83,27 +86,34 @@
    2.23  	GMythSocket *control_sock;
    2.24  	GMythSocket *event_sock;
    2.25  	GMythSocket *sock;
    2.26 +	
    2.27 +	GMythMonitorHandler *monitor;
    2.28  
    2.29  	gint64 readposition;
    2.30  	guint64 filesize;
    2.31 -	//gboolean timeoutisfast;
    2.32 -	//gboolean userreadahead;
    2.33 -	//gint retries;
    2.34  
    2.35  	gint file_id;
    2.36  };
    2.37  
    2.38  GType          gmyth_file_transfer_get_type        (void);
    2.39  
    2.40 -GMythFileTransfer* gmyth_file_transfer_new ( GMythBackendInfo *backend_info );
    2.41 +GMythFileTransfer* gmyth_file_transfer_new ( const GMythBackendInfo *backend_info );
    2.42  
    2.43 -gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer, const gchar* filename);
    2.44 +GMythFileTransfer* gmyth_file_transfer_new_with_uri ( const gchar* uri_str );
    2.45 +
    2.46 +gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer);
    2.47 +
    2.48  void gmyth_file_transfer_close (GMythFileTransfer *transfer);
    2.49  
    2.50  gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer);
    2.51 -gint gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, gint size, gboolean read_unlimited);
    2.52 +
    2.53 +gint gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, 
    2.54 +							gint size, gboolean read_unlimited);
    2.55 +							
    2.56  gint64 gmyth_file_transfer_seek(GMythFileTransfer *transfer, guint64 pos, gint whence);
    2.57 +
    2.58  gboolean gmyth_file_transfer_settimeout( GMythFileTransfer *transfer, gboolean fast);
    2.59 +
    2.60  guint64 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer);
    2.61  
    2.62  #define G_END_DECLS
     3.1 --- a/gmyth/src/gmyth_socket.c	Sat Dec 02 03:41:47 2006 +0000
     3.2 +++ b/gmyth/src/gmyth_socket.c	Sat Dec 02 03:46:17 2006 +0000
     3.3 @@ -73,6 +73,8 @@
     3.4  
     3.5  static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
     3.6  
     3.7 +static gchar* local_hostname = NULL;
     3.8 +
     3.9  static void gmyth_socket_class_init          (GMythSocketClass *klass);
    3.10  static void gmyth_socket_init                (GMythSocket *object);
    3.11  
    3.12 @@ -95,6 +97,9 @@
    3.13  static void
    3.14  gmyth_socket_init (GMythSocket *gmyth_socket)
    3.15  {
    3.16 +	
    3.17 +	/* gmyth_socket->local_hostname = NULL; */
    3.18 +	
    3.19  }
    3.20  
    3.21  /** Gets the some important address translation info, from the client socket
    3.22 @@ -113,7 +118,7 @@
    3.23      hints = g_new0 (struct addrinfo, 1);
    3.24      hints->ai_family = AF_INET;
    3.25      hints->ai_socktype = SOCK_STREAM;
    3.26 -    hints->ai_flags = AI_NUMERICHOST;
    3.27 +    /* hints->ai_flags = AI_NUMERICHOST; */
    3.28      
    3.29      if ( port != -1 )	
    3.30          portStr = g_strdup_printf ("%d", port);
    3.31 @@ -157,7 +162,7 @@
    3.32  	struct ifaddrs *ifaddr = g_new0( struct ifaddrs, 1 );	
    3.33  	struct ifaddrs *i = g_new0( struct ifaddrs, 1 );
    3.34  
    3.35 -	gchar addr[NI_MAXHOST+1];
    3.36 +	gchar *addr = g_new0( gchar, NI_MAXHOST+1 );
    3.37  	gchar *ifname;
    3.38  	gint ifIdx;
    3.39  	
    3.40 @@ -180,7 +185,14 @@
    3.41  			if ( current_connections == NULL || ( current_connections != NULL && 
    3.42  					g_list_find_custom( current_connections, (gchar *)addr, 
    3.43  						(GCompareFunc)gmyth_socket_find_match_address_uri ) == NULL ) )
    3.44 -				local_addrs = g_list_append (local_addrs, addr);
    3.45 +			{
    3.46 +				local_addrs = g_list_append( local_addrs, g_strdup( addr ) );				
    3.47 +			}
    3.48 +			
    3.49 +			if ( addr != NULL ) {
    3.50 +				g_free( addr );
    3.51 +				addr = g_new0( gchar, NI_MAXHOST+1 );
    3.52 +			}
    3.53  
    3.54  		}
    3.55  	} /* iterates over network interfaces */
    3.56 @@ -290,6 +302,9 @@
    3.57  gmyth_socket_get_local_hostname  ()
    3.58  {
    3.59      GString *str = NULL;
    3.60 +    
    3.61 +    if ( local_hostname != NULL )
    3.62 +    	return g_string_new( local_hostname );
    3.63  
    3.64      gchar localhostname[1024];
    3.65      gchar *localaddr = NULL; 
    3.66 @@ -338,7 +353,10 @@
    3.67      }
    3.68  
    3.69      g_static_mutex_unlock (&mutex);
    3.70 -
    3.71 +    
    3.72 +    if ( str != NULL && str->str != NULL )
    3.73 +    	local_hostname = g_strdup( str->str );
    3.74 +    
    3.75      return str;
    3.76  }
    3.77  
    3.78 @@ -678,12 +696,14 @@
    3.79   * @param gmyth_socket the GMythSocket instance.
    3.80   * @param hostname_backend The backend hostname or IP address.
    3.81   * @param port The backend port to connect.
    3.82 - * @param blocking_client A flag to choose between blocking and non-blocking 
    3.83 - * backend connection.
    3.84 + * @param blocking_client A flag to choose between blocking and non-blocking
    3.85 + * @param with_events	Sets the connection flag to receive events.
    3.86 + * 										backend connection. 
    3.87   */
    3.88 -gboolean
    3.89 -gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
    3.90 -	const gchar *hostname_backend, int port, gboolean blocking_client)
    3.91 +static gboolean
    3.92 +gmyth_socket_connect_to_backend_and_events (GMythSocket *gmyth_socket, 
    3.93 +	const gchar *hostname_backend, gint port, gboolean blocking_client,
    3.94 +	gboolean with_events)
    3.95  {
    3.96      if (!gmyth_socket_connect (gmyth_socket, hostname_backend, port)) {
    3.97  		g_warning ("[%s] Could not open socket to backend machine [%s]\n", __FUNCTION__,
    3.98 @@ -699,14 +719,14 @@
    3.99  
   3.100  	hostname = gmyth_socket_get_local_hostname();
   3.101  
   3.102 -	g_string_printf(base_str, "ANN %s %s 0", 
   3.103 +	g_string_printf(base_str, "ANN %s %s %u", 
   3.104  		(blocking_client ? "Playback" : "Monitor"),
   3.105 -		hostname->str);
   3.106 +		hostname->str, with_events);
   3.107  
   3.108  	gmyth_debug ("[%s] Connection command sent to backend: %s", __FUNCTION__, base_str->str);
   3.109  
   3.110  	gmyth_socket_send_command (gmyth_socket, base_str);
   3.111 -	result = gmyth_socket_receive_response(gmyth_socket);
   3.112 +	result = gmyth_socket_receive_response (gmyth_socket);
   3.113  
   3.114  	if (result != NULL) {
   3.115  	    gmyth_debug ("[%s] Response received from backend: %s", __FUNCTION__, result->str);
   3.116 @@ -723,6 +743,51 @@
   3.117      }
   3.118  }
   3.119  
   3.120 +/** Starts Mythtv protocol level connection. Checks Mythtv protocol version
   3.121 + * supported by the backend and send the "ANN" command.
   3.122 + * 
   3.123 + * @param gmyth_socket the GMythSocket instance.
   3.124 + * @param hostname_backend The backend hostname or IP address.
   3.125 + * @param port The backend port to connect.
   3.126 + * @param blocking_client A flag to choose between blocking and non-blocking 
   3.127 + */
   3.128 +gboolean
   3.129 +gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
   3.130 +	const gchar *hostname_backend, gint port, gboolean blocking_client)
   3.131 +{
   3.132 +    if (!gmyth_socket_connect_to_backend_and_events ( gmyth_socket, hostname_backend, port,
   3.133 +    		blocking_client, FALSE) ) {
   3.134 +		gmyth_debug ("[%s] Could not open socket to backend machine [%s]\n", __FUNCTION__,
   3.135 +					hostname_backend );
   3.136 +		return FALSE;
   3.137 +    }
   3.138 +    
   3.139 +    return TRUE;
   3.140 +
   3.141 +}
   3.142 +
   3.143 +/** Starts Mythtv protocol level connection. Checks Mythtv protocol version
   3.144 + * supported by the backend and send the "ANN" command.
   3.145 + * 
   3.146 + * @param gmyth_socket the GMythSocket instance.
   3.147 + * @param hostname_backend The backend hostname or IP address.
   3.148 + * @param port The backend port to connect.
   3.149 + * @param blocking_client A flag to choose between blocking and non-blocking 
   3.150 + */
   3.151 +gboolean
   3.152 +gmyth_socket_connect_to_backend_events (GMythSocket *gmyth_socket, 
   3.153 +	const gchar *hostname_backend, gint port, gboolean blocking_client)
   3.154 +{
   3.155 +    if (!gmyth_socket_connect_to_backend_and_events ( gmyth_socket, hostname_backend, port,
   3.156 +    		blocking_client, TRUE) ) {
   3.157 +		gmyth_debug ("[%s] Could not open socket to backend machine in order to receive events [%s]\n", __FUNCTION__,
   3.158 +					hostname_backend );
   3.159 +		return FALSE;
   3.160 +    }
   3.161 +    
   3.162 +    return TRUE;
   3.163 +}
   3.164 +
   3.165  /** Closes the socket connection to the backend.
   3.166   * 
   3.167   * @param gmyth_socket The GMythSocket instance.
     4.1 --- a/gmyth/src/gmyth_socket.h	Sat Dec 02 03:41:47 2006 +0000
     4.2 +++ b/gmyth/src/gmyth_socket.h	Sat Dec 02 03:46:17 2006 +0000
     4.3 @@ -69,7 +69,7 @@
     4.4  	GObject parent;
     4.5  
     4.6  	/* socket descriptor */
     4.7 -	int sd;  
     4.8 +	gint sd;  
     4.9  	GIOChannel *sd_io_ch;
    4.10  
    4.11  	gchar *hostname;
    4.12 @@ -92,13 +92,18 @@
    4.13  gboolean        gmyth_socket_send_command (GMythSocket *gmyth_socket, 
    4.14                                             GString *command);
    4.15  GString *       gmyth_socket_receive_response (GMythSocket *gmyth_socket);
    4.16 -int             gmyth_socket_sendreceive_stringlist (GMythSocket *gmyth_socket, 
    4.17 +gint             gmyth_socket_sendreceive_stringlist (GMythSocket *gmyth_socket, 
    4.18                                                       GMythStringList *str_list);
    4.19  
    4.20  gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket,
    4.21                                        const gchar *hostname, gint port);
    4.22  gboolean        gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
    4.23 -                           const gchar *hostname_backend, int port, gboolean blocking_client);
    4.24 +                           const gchar *hostname_backend, gint port, 
    4.25 +                           gboolean blocking_client);
    4.26 +
    4.27 +gboolean        gmyth_socket_connect_to_backend_events (GMythSocket *gmyth_socket, 
    4.28 +                           const gchar *hostname_backend, gint port, 
    4.29 +                           gboolean blocking_client);
    4.30  
    4.31  GString *       gmyth_socket_get_local_hostname (void);
    4.32  
    4.33 @@ -112,7 +117,7 @@
    4.34  
    4.35  gboolean		gmyth_socket_write_stringlist(GMythSocket *gmyth_socket, 
    4.36                                                GMythStringList* str_list);
    4.37 -int			    gmyth_socket_read_stringlist(GMythSocket *gmyth_socket, 
    4.38 +gint			    gmyth_socket_read_stringlist(GMythSocket *gmyth_socket, 
    4.39                                               GMythStringList* str_list);
    4.40  G_END_DECLS
    4.41