[svn r159] Filetransfer interface now receives GMythBackendInfo and file name instead of URI trunk
authormelunko
Thu Nov 30 21:29:38 2006 +0000 (2006-11-30)
branchtrunk
changeset 158517da097a261
parent 157 585b3db817a1
child 159 2db0e1da044a
[svn r159] Filetransfer interface now receives GMythBackendInfo and file name instead of URI
gmyth/src/gmyth_backendinfo.c
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_backendinfo.c	Thu Nov 30 21:25:06 2006 +0000
     1.2 +++ b/gmyth/src/gmyth_backendinfo.c	Thu Nov 30 21:29:38 2006 +0000
     1.3 @@ -119,14 +119,20 @@
     1.4      GMythBackendInfo *backend_info = 
     1.5          GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
     1.6          
     1.7 +printf ("XXX %s %d\n", __FUNCTION__, __LINE__);
     1.8      GMythURI* uri = gmyth_uri_new_with_value( uri_str );
     1.9 +printf ("XXX %s %d\n", __FUNCTION__, __LINE__);
    1.10      
    1.11      gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri ) );
    1.12 +printf ("XXX %s %d \n", __FUNCTION__, __LINE__);
    1.13      gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( uri ) );
    1.14 +printf ("XXX %s %d\n", __FUNCTION__, __LINE__);
    1.15      gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password( uri ) );
    1.16 +printf ("XXX %s %d\n", __FUNCTION__, __LINE__);
    1.17      gmyth_backend_info_set_db_name (backend_info, strlen( gmyth_uri_get_fragment( uri ) ) > 0 
    1.18      				? gmyth_uri_get_fragment( uri ) : gmyth_uri_get_query( uri ) );
    1.19      gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port( uri ) );
    1.20 +printf ("XXX %s %d\n", __FUNCTION__, __LINE__);
    1.21  
    1.22      return backend_info;
    1.23  }
     2.1 --- a/gmyth/src/gmyth_file_transfer.c	Thu Nov 30 21:25:06 2006 +0000
     2.2 +++ b/gmyth/src/gmyth_file_transfer.c	Thu Nov 30 21:29:38 2006 +0000
     2.3 @@ -33,7 +33,6 @@
     2.4   */
     2.5  
     2.6  #include "gmyth_file_transfer.h"
     2.7 -#include "gmyth_uri.h"
     2.8  #include "gmyth_livetv.h"
     2.9  #include "gmyth_util.h"
    2.10  #include "gmyth_socket.h"
    2.11 @@ -84,17 +83,11 @@
    2.12    GMYTH_RINGBUFFER_TYPE
    2.13  };
    2.14  
    2.15 -//static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT;
    2.16 -
    2.17 -//static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
    2.18 -/* static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ); */
    2.19  
    2.20  static GMutex*				mutex 					 = NULL;
    2.21  
    2.22  static GCond*					io_watcher_cond  = NULL;
    2.23  
    2.24 -//static GMainContext*	io_watcher_context  = NULL;
    2.25 -
    2.26  static void gmyth_file_transfer_class_init          (GMythFileTransferClass *klass);
    2.27  static void gmyth_file_transfer_init                (GMythFileTransfer *object);
    2.28  
    2.29 @@ -127,12 +120,9 @@
    2.30  { 
    2.31    g_return_if_fail( transfer != NULL );
    2.32  
    2.33 -  //transfer->card_id = num;
    2.34 -  //transfer->rec_id = -1;
    2.35 -  //transfer->recordernum = num;
    2.36 -
    2.37    transfer->readposition = 0;
    2.38    transfer->filesize = GMYTHTV_FILE_SIZE;
    2.39 +  transfer->filename = NULL;
    2.40    //transfer->timeoutisfast = FALSE;
    2.41  
    2.42    //transfer->userreadahead = GMYTHTV_USER_READ_AHEAD;
    2.43 @@ -140,6 +130,8 @@
    2.44  
    2.45    transfer->control_sock = NULL;
    2.46    transfer->sock = NULL;
    2.47 +
    2.48 +  transfer->backend_info = NULL;
    2.49    
    2.50    /* it is used for signalizing the event socket consumer thread */
    2.51    io_watcher_cond = g_cond_new();
    2.52 @@ -164,40 +156,39 @@
    2.53  
    2.54  // fixme: do we need the card_id????
    2.55  GMythFileTransfer*
    2.56 -gmyth_file_transfer_new ()
    2.57 +gmyth_file_transfer_new (GMythBackendInfo *backend_info)
    2.58  {
    2.59    GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER ( g_object_new (
    2.60  	GMYTH_FILE_TRANSFER_TYPE, FALSE ));
    2.61  
    2.62 +  if (backend_info != NULL) {
    2.63 +    g_object_ref (backend_info);
    2.64 +    transfer->backend_info = backend_info;
    2.65 +  }
    2.66 +
    2.67    return transfer;
    2.68  }
    2.69  
    2.70  gboolean
    2.71 -gmyth_file_transfer_open (GMythFileTransfer *transfer, GString *uri_str)
    2.72 +gmyth_file_transfer_open (GMythFileTransfer *transfer, const char *filename)
    2.73  {
    2.74    gboolean ret = TRUE;
    2.75  
    2.76 -  if (transfer->uri != NULL) {
    2.77 -    g_object_unref (G_OBJECT (transfer->uri));
    2.78 -    transfer->uri = NULL;
    2.79 +  g_assert (transfer);
    2.80 +  g_return_val_if_fail (transfer->backend_info != NULL, FALSE);
    2.81 +  g_return_val_if_fail (filename != NULL, FALSE);
    2.82 +      
    2.83 +  // FIXME: Verify if file_transfer has already been opened
    2.84 +  if (transfer->filename != NULL) {
    2.85 +    g_warning ("[%s] File transfer already opened!", __FUNCTION__);
    2.86 +    return FALSE;
    2.87    }
    2.88  
    2.89 -  if (transfer->hostname != NULL) {
    2.90 -    g_string_free (transfer->hostname, TRUE);
    2.91 -    transfer->hostname = NULL;
    2.92 -  }
    2.93 +  transfer->filename = g_strdup (filename);
    2.94  
    2.95 -  if (transfer->hostname != NULL) {
    2.96 -    g_string_free (transfer->hostname, TRUE);
    2.97 -    transfer->hostname = NULL;
    2.98 -  }
    2.99 -
   2.100 -  transfer->uri = gmyth_uri_new_with_value (uri_str->str);
   2.101 -  transfer->hostname = g_string_new (gmyth_uri_get_host(transfer->uri));
   2.102 -  transfer->port = gmyth_uri_get_port (transfer->uri);
   2.103 -
   2.104 -  gmyth_debug ("[%s] URI: %s\n", __FUNCTION__, uri_str->str);
   2.105 -  gmyth_debug ("hostname: %s, port %d\n", transfer->hostname->str, transfer->port);
   2.106 +  gmyth_debug ("[%s] File name: %s\n", __FUNCTION__, filename);
   2.107 +  gmyth_debug ("hostname: %s, port %d\n", transfer->backend_info->hostname, 
   2.108 +      transfer->backend_info->port);
   2.109    
   2.110    /* configure the control socket */
   2.111    if (transfer->control_sock == NULL) { 
   2.112 @@ -213,163 +204,19 @@
   2.113  
   2.114  }
   2.115  
   2.116 -/*
   2.117 -static gboolean*
   2.118 -//myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
   2.119 -myth_control_sock_listener( GIOChannel *io_channel )
   2.120 -{
   2.121 -
   2.122 -  GIOStatus io_status;
   2.123 -  GError *error = NULL;
   2.124 -  GIOCondition io_cond;
   2.125 -  GIOCondition condition;
   2.126 -  gchar *trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE*10 );
   2.127 -  guint recv = 0;
   2.128 -  gboolean* ret = g_new0( gboolean, 1 );
   2.129 -  //gboolean ret = TRUE;
   2.130 -  gsize len = 0;
   2.131 -  
   2.132 -  *ret = TRUE;
   2.133 -  //myth_control_acquire_context (TRUE);
   2.134 -  
   2.135 -  if ( io_channel == NULL ) {
   2.136 -  	g_debug ("Monitor socket is NULL!\n");
   2.137 -  	*ret = FALSE;
   2.138 -  	goto clean_up;
   2.139 -  }
   2.140 -  gmyth_debug ("Listening on Monitor socket...!\n");
   2.141 -  
   2.142 -  while (TRUE) {
   2.143 -	  	
   2.144 -	  condition = g_io_channel_get_buffer_condition( io_channel );
   2.145 -	  
   2.146 -	  //myth_control_acquire_context (TRUE);
   2.147 -	  
   2.148 -	  //while ( !has_io_access ) 
   2.149 -	  //	g_cond_wait( io_watcher_cond, mutex );
   2.150 -	  	
   2.151 -	  //myth_control_acquire_context (TRUE);  
   2.152 -	  
   2.153 -	  if (condition & G_IO_HUP) {
   2.154 -	    gmyth_debug ("Read end of pipe died!\n");
   2.155 -	    *ret = FALSE;
   2.156 -	    goto clean_up;
   2.157 -	  }
   2.158 -	    
   2.159 -	  if ( ( condition & G_IO_IN ) != 0 ) {
   2.160 -	  	io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
   2.161 -	    do 
   2.162 -	    {
   2.163 -	      //trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE );
   2.164 -	
   2.165 -	      io_status = g_io_channel_read_chars( io_channel, trash + recv, 
   2.166 -	      		GMYTHTV_BUFFER_SIZE, &len, &error);
   2.167 -	
   2.168 -	      gmyth_debug ( "[%s] Received data buffer from IO binary channel... %d bytes gone!\n", 
   2.169 -	      		__FUNCTION__, len );
   2.170 -	      		
   2.171 -	      recv += len;
   2.172 -	      
   2.173 -	      //msg = g_strconcat( msg, g_strdup(trash), NULL );
   2.174 -	      
   2.175 -	      //if ( trash != NULL )
   2.176 -	      //	g_free( trash );
   2.177 -	      	
   2.178 -	      io_cond = g_io_channel_get_buffer_condition( io_channel );
   2.179 -	
   2.180 -	    } while ( ( io_cond & G_IO_IN ) != 0 && ( io_status != G_IO_STATUS_ERROR ) );
   2.181 -	  }
   2.182 -	  
   2.183 -	  g_usleep( 300 );
   2.184 -	  
   2.185 -  }
   2.186 -  //ret = g_io_channel_read_chars ( source, &msg, &len, NULL, &err);
   2.187 -  if ( io_status == G_IO_STATUS_ERROR ) {
   2.188 -    gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" );
   2.189 -    *ret = FALSE;
   2.190 -  }
   2.191 -  gmyth_debug ("\n[%s]\tEVENT: Read %d bytes: %s\n\n", __FUNCTION__, len, trash != NULL ? trash : "[no event data]" );
   2.192 -
   2.193 -  //g_cond_signal( io_watcher_cond );
   2.194 -  
   2.195 -clean_up:
   2.196 -  //myth_control_release_context( );
   2.197 -  
   2.198 -  return ret;
   2.199 -
   2.200 -}
   2.201 -*/
   2.202 -
   2.203 -/*
   2.204 -static gboolean
   2.205 -gmyth_connect_to_backend_monitor (GMythFileTransfer *transfer, GString *hostname )
   2.206 -{
   2.207 -	gboolean ret = TRUE;
   2.208 -	GString *base_str = g_string_new( "" );	
   2.209 -	//guint source_id = 0;
   2.210 -
   2.211 -  transfer->event_sock = gmyth_socket_new();
   2.212 -  
   2.213 -  gmyth_socket_connect ( transfer->event_sock, transfer->hostname->str, transfer->port);
   2.214 -  g_string_printf( base_str, "ANN Monitor %s %d", hostname->str, TRUE );
   2.215 -
   2.216 -  gmyth_socket_send_command( transfer->event_sock, base_str );
   2.217 -  //GString *resp = gmyth_socket_receive_response( transfer->event_sock );
   2.218 -  gmyth_debug ( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
   2.219 -  monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_listener, transfer->event_sock->sd_io_ch, FALSE, NULL );
   2.220 -  io_watcher_context = g_main_context_default();
   2.221 -  GMainLoop *loop = g_main_loop_new( NULL, TRUE );
   2.222 -
   2.223 -  GSource *source;
   2.224 -
   2.225 -  if ( transfer->event_sock->sd_io_ch != NULL ) {
   2.226 -    source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN );
   2.227 -    //transfer->event_sock->sd_io_ch
   2.228 -  } else {
   2.229 -  	ret = FALSE;
   2.230 -  	goto cleanup;
   2.231 -  }
   2.232 -
   2.233 -  g_source_set_callback ( source, (GIOFunc)myth_control_sock_listener, NULL, NULL );
   2.234 -
   2.235 -  g_source_attach( source, io_watcher_context );
   2.236 -  
   2.237 -  if (source==NULL) {
   2.238 -    g_printerr( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
   2.239 -    goto cleanup;
   2.240 -  }
   2.241 -  gmyth_debug ( "[%s]\tOK! Starting listener on the MONITOR event socket...\n", __FUNCTION__ );
   2.242 -  
   2.243 -  //g_main_loop_run( loop );
   2.244 -
   2.245 -//cleanup:
   2.246 -  if ( source != NULL )
   2.247 -    g_source_unref( source );
   2.248 -
   2.249 -  gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n", 
   2.250 -  			__FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) );
   2.251 -  			
   2.252 -  return ret;
   2.253 -
   2.254 -}
   2.255 -*/
   2.256 -
   2.257  static gboolean
   2.258  gmyth_connect_to_backend (GMythFileTransfer *transfer)
   2.259  {
   2.260    GString *base_str = NULL;
   2.261 +  GMythStringList *strlist = NULL; 
   2.262    GString *hostname = NULL;
   2.263 -  GMythStringList *strlist = NULL; 
   2.264 -  gchar *path_dir = NULL;
   2.265    gboolean ret = TRUE;
   2.266  
   2.267    g_return_val_if_fail (transfer != NULL, FALSE );
   2.268 -  g_return_val_if_fail (transfer->uri != NULL, FALSE );
   2.269 -  g_return_val_if_fail (transfer->hostname != NULL, FALSE);
   2.270 -  g_return_val_if_fail (transfer->port > 0, FALSE);
   2.271 +  g_return_val_if_fail (transfer->filename != NULL, FALSE );
   2.272 +  g_return_val_if_fail (transfer->backend_info != NULL, FALSE);
   2.273  
   2.274    base_str = g_string_new ("");
   2.275 -  path_dir = gmyth_uri_get_path (transfer->uri);
   2.276  
   2.277    /* Creates the control socket */
   2.278    if (transfer->control_sock != NULL) {
   2.279 @@ -381,7 +228,7 @@
   2.280  
   2.281    // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version 
   2.282    if (!gmyth_socket_connect_to_backend (transfer->control_sock,
   2.283 -          transfer->hostname->str, transfer->port, TRUE)) {
   2.284 +          transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) {
   2.285  
   2.286      g_object_unref (transfer->control_sock);
   2.287      transfer->control_sock = NULL;
   2.288 @@ -395,7 +242,7 @@
   2.289    }
   2.290  
   2.291    transfer->sock = gmyth_socket_new ();
   2.292 -  gmyth_socket_connect (transfer->sock, transfer->hostname->str, transfer->port);
   2.293 +  gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port);
   2.294  
   2.295    strlist = gmyth_string_list_new();
   2.296    hostname = gmyth_socket_get_local_hostname();
   2.297 @@ -406,7 +253,7 @@
   2.298    	g_string_printf( base_str, "ANN FileTransfer %s", hostname->str);
   2.299  
   2.300    gmyth_string_list_append_string (strlist, base_str );
   2.301 -  gmyth_string_list_append_char_array (strlist, path_dir );
   2.302 +  gmyth_string_list_append_char_array (strlist, transfer->filename );
   2.303  
   2.304    gmyth_socket_write_stringlist (transfer->sock, strlist );
   2.305    gmyth_socket_read_stringlist (transfer->sock, strlist );
     3.1 --- a/gmyth/src/gmyth_file_transfer.h	Thu Nov 30 21:25:06 2006 +0000
     3.2 +++ b/gmyth/src/gmyth_file_transfer.h	Thu Nov 30 21:29:38 2006 +0000
     3.3 @@ -36,6 +36,7 @@
     3.4  #include "gmyth_socket.h"
     3.5  #include "gmyth_uri.h"
     3.6  #include "gmyth_livetv.h"
     3.7 +#include "gmyth_backendinfo.h"
     3.8  
     3.9  #include <stdio.h>
    3.10  #include <stdlib.h>
    3.11 @@ -71,7 +72,9 @@
    3.12  	GObject parent;
    3.13  
    3.14  	/* Myth URI structure */
    3.15 -	const GMythURI *uri;
    3.16 +	//const GMythURI *uri;
    3.17 +	gchar* filename;
    3.18 +	GMythBackendInfo *backend_info;
    3.19  	
    3.20  	/* MythTV version number */	
    3.21  	gint mythtv_version;
    3.22 @@ -88,22 +91,13 @@
    3.23  	//gint retries;
    3.24  
    3.25  	gint file_id;
    3.26 -	//gint rec_id;
    3.27 -	//gint recordernum;
    3.28 -	//gint card_id;
    3.29 -	GString *hostname;
    3.30 -	gint port;
    3.31 -	
    3.32 -	/* stores the messages coming from the backend */
    3.33 -	//GHashTable *backend_msgs;
    3.34  };
    3.35  
    3.36  GType          gmyth_file_transfer_get_type        (void);
    3.37  
    3.38 -//GMythFileTransfer* gmyth_file_transfer_new (gint num, GString *hostname, gshort port, gint mythtv_version );
    3.39 -GMythFileTransfer* gmyth_file_transfer_new ( );
    3.40 +GMythFileTransfer* gmyth_file_transfer_new ( GMythBackendInfo *backend_info );
    3.41  
    3.42 -gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer, GString *uri_str);
    3.43 +gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer, const gchar* filename);
    3.44  void gmyth_file_transfer_close (GMythFileTransfer *transfer);
    3.45  
    3.46  gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer);
    3.47 @@ -112,13 +106,6 @@
    3.48  gboolean gmyth_file_transfer_settimeout( GMythFileTransfer *transfer, gboolean fast);
    3.49  guint64 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer);
    3.50  
    3.51 -//gboolean gmyth_file_transfer_playback_setup( GMythFileTransfer **transfer, gboolean live_tv );
    3.52 -//gboolean gmyth_file_transfer_setup( GMythFileTransfer **transfer, gboolean live_tv );
    3.53 -//gboolean gmyth_file_transfer_livetv_setup( GMythFileTransfer **transfer, GMythSocket *live_sock );
    3.54 -//void gmyth_file_transfer_spawntv ( GMythFileTransfer *file_transfer, GString *tvchain_id );
    3.55 -//gboolean gmyth_file_transfer_is_recording( GMythFileTransfer *file_transfer );
    3.56 -//gint64  gmyth_file_transfer_get_file_position( GMythFileTransfer *file_transfer );
    3.57 -
    3.58  #define G_END_DECLS
    3.59  
    3.60  #endif /* __GMYTH_FILE_TRANSFER_H__ */
     4.1 --- a/gmyth/src/gmyth_socket.c	Thu Nov 30 21:25:06 2006 +0000
     4.2 +++ b/gmyth/src/gmyth_socket.c	Thu Nov 30 21:29:38 2006 +0000
     4.3 @@ -476,7 +476,7 @@
     4.4   */
     4.5  gboolean
     4.6  gmyth_socket_connect (GMythSocket *gmyth_socket,
     4.7 -	gchar *hostname, gint port)
     4.8 +	const gchar *hostname, gint port)
     4.9  {
    4.10      struct addrinfo *addr_info_data = NULL, *addr_info0 = NULL;
    4.11      gint ret_code = -1;
    4.12 @@ -683,7 +683,7 @@
    4.13   */
    4.14  gboolean
    4.15  gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
    4.16 -	gchar *hostname_backend, int port, gboolean blocking_client)
    4.17 +	const gchar *hostname_backend, int port, gboolean blocking_client)
    4.18  {
    4.19      if (!gmyth_socket_connect (gmyth_socket, hostname_backend, port)) {
    4.20  		g_warning ("[%s] Could not open socket to backend machine [%s]\n", __FUNCTION__,
     5.1 --- a/gmyth/src/gmyth_socket.h	Thu Nov 30 21:25:06 2006 +0000
     5.2 +++ b/gmyth/src/gmyth_socket.h	Thu Nov 30 21:29:38 2006 +0000
     5.3 @@ -96,10 +96,9 @@
     5.4                                                       GMythStringList *str_list);
     5.5  
     5.6  gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket,
     5.7 -                                      gchar *hostname, gint port);
     5.8 +                                      const gchar *hostname, gint port);
     5.9  gboolean        gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
    5.10 -                                                 gchar *hostname_backend, int port,
    5.11 -                                          		 gboolean blocking_client);
    5.12 +                           const gchar *hostname_backend, int port, gboolean blocking_client);
    5.13  
    5.14  GString *       gmyth_socket_get_local_hostname (void);
    5.15