# HG changeset patch # User melunko # Date 1164922178 0 # Node ID 517da097a26157823c3ef02ab825a47f9fde8a52 # Parent 585b3db817a13c890d38a8f89f7e4c4f789e7587 [svn r159] Filetransfer interface now receives GMythBackendInfo and file name instead of URI diff -r 585b3db817a1 -r 517da097a261 gmyth/src/gmyth_backendinfo.c --- a/gmyth/src/gmyth_backendinfo.c Thu Nov 30 21:25:06 2006 +0000 +++ b/gmyth/src/gmyth_backendinfo.c Thu Nov 30 21:29:38 2006 +0000 @@ -119,14 +119,20 @@ GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL)); +printf ("XXX %s %d\n", __FUNCTION__, __LINE__); GMythURI* uri = gmyth_uri_new_with_value( uri_str ); +printf ("XXX %s %d\n", __FUNCTION__, __LINE__); gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri ) ); +printf ("XXX %s %d \n", __FUNCTION__, __LINE__); gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( uri ) ); +printf ("XXX %s %d\n", __FUNCTION__, __LINE__); gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password( uri ) ); +printf ("XXX %s %d\n", __FUNCTION__, __LINE__); gmyth_backend_info_set_db_name (backend_info, strlen( gmyth_uri_get_fragment( uri ) ) > 0 ? gmyth_uri_get_fragment( uri ) : gmyth_uri_get_query( uri ) ); gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port( uri ) ); +printf ("XXX %s %d\n", __FUNCTION__, __LINE__); return backend_info; } diff -r 585b3db817a1 -r 517da097a261 gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Thu Nov 30 21:25:06 2006 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Thu Nov 30 21:29:38 2006 +0000 @@ -33,7 +33,6 @@ */ #include "gmyth_file_transfer.h" -#include "gmyth_uri.h" #include "gmyth_livetv.h" #include "gmyth_util.h" #include "gmyth_socket.h" @@ -84,17 +83,11 @@ GMYTH_RINGBUFFER_TYPE }; -//static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT; - -//static gboolean* myth_control_sock_listener( GIOChannel *io_channel ); -/* static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ); */ static GMutex* mutex = NULL; static GCond* io_watcher_cond = NULL; -//static GMainContext* io_watcher_context = NULL; - static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass); static void gmyth_file_transfer_init (GMythFileTransfer *object); @@ -127,12 +120,9 @@ { g_return_if_fail( transfer != NULL ); - //transfer->card_id = num; - //transfer->rec_id = -1; - //transfer->recordernum = num; - transfer->readposition = 0; transfer->filesize = GMYTHTV_FILE_SIZE; + transfer->filename = NULL; //transfer->timeoutisfast = FALSE; //transfer->userreadahead = GMYTHTV_USER_READ_AHEAD; @@ -140,6 +130,8 @@ transfer->control_sock = NULL; transfer->sock = NULL; + + transfer->backend_info = NULL; /* it is used for signalizing the event socket consumer thread */ io_watcher_cond = g_cond_new(); @@ -164,40 +156,39 @@ // fixme: do we need the card_id???? GMythFileTransfer* -gmyth_file_transfer_new () +gmyth_file_transfer_new (GMythBackendInfo *backend_info) { GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER ( g_object_new ( GMYTH_FILE_TRANSFER_TYPE, FALSE )); + if (backend_info != NULL) { + g_object_ref (backend_info); + transfer->backend_info = backend_info; + } + return transfer; } gboolean -gmyth_file_transfer_open (GMythFileTransfer *transfer, GString *uri_str) +gmyth_file_transfer_open (GMythFileTransfer *transfer, const char *filename) { gboolean ret = TRUE; - if (transfer->uri != NULL) { - g_object_unref (G_OBJECT (transfer->uri)); - transfer->uri = NULL; + g_assert (transfer); + g_return_val_if_fail (transfer->backend_info != NULL, FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + + // FIXME: Verify if file_transfer has already been opened + if (transfer->filename != NULL) { + g_warning ("[%s] File transfer already opened!", __FUNCTION__); + return FALSE; } - if (transfer->hostname != NULL) { - g_string_free (transfer->hostname, TRUE); - transfer->hostname = NULL; - } + transfer->filename = g_strdup (filename); - if (transfer->hostname != NULL) { - g_string_free (transfer->hostname, TRUE); - transfer->hostname = NULL; - } - - transfer->uri = gmyth_uri_new_with_value (uri_str->str); - transfer->hostname = g_string_new (gmyth_uri_get_host(transfer->uri)); - transfer->port = gmyth_uri_get_port (transfer->uri); - - gmyth_debug ("[%s] URI: %s\n", __FUNCTION__, uri_str->str); - gmyth_debug ("hostname: %s, port %d\n", transfer->hostname->str, transfer->port); + gmyth_debug ("[%s] File name: %s\n", __FUNCTION__, filename); + gmyth_debug ("hostname: %s, port %d\n", transfer->backend_info->hostname, + transfer->backend_info->port); /* configure the control socket */ if (transfer->control_sock == NULL) { @@ -213,163 +204,19 @@ } -/* -static gboolean* -//myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ) -myth_control_sock_listener( GIOChannel *io_channel ) -{ - - GIOStatus io_status; - GError *error = NULL; - GIOCondition io_cond; - GIOCondition condition; - gchar *trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE*10 ); - guint recv = 0; - gboolean* ret = g_new0( gboolean, 1 ); - //gboolean ret = TRUE; - gsize len = 0; - - *ret = TRUE; - //myth_control_acquire_context (TRUE); - - if ( io_channel == NULL ) { - g_debug ("Monitor socket is NULL!\n"); - *ret = FALSE; - goto clean_up; - } - gmyth_debug ("Listening on Monitor socket...!\n"); - - while (TRUE) { - - condition = g_io_channel_get_buffer_condition( io_channel ); - - //myth_control_acquire_context (TRUE); - - //while ( !has_io_access ) - // g_cond_wait( io_watcher_cond, mutex ); - - //myth_control_acquire_context (TRUE); - - if (condition & G_IO_HUP) { - gmyth_debug ("Read end of pipe died!\n"); - *ret = FALSE; - goto clean_up; - } - - if ( ( condition & G_IO_IN ) != 0 ) { - io_status = g_io_channel_set_encoding( io_channel, NULL, &error ); - do - { - //trash = g_new0( gchar, GMYTHTV_BUFFER_SIZE ); - - io_status = g_io_channel_read_chars( io_channel, trash + recv, - GMYTHTV_BUFFER_SIZE, &len, &error); - - gmyth_debug ( "[%s] Received data buffer from IO binary channel... %d bytes gone!\n", - __FUNCTION__, len ); - - recv += len; - - //msg = g_strconcat( msg, g_strdup(trash), NULL ); - - //if ( trash != NULL ) - // g_free( trash ); - - io_cond = g_io_channel_get_buffer_condition( io_channel ); - - } while ( ( io_cond & G_IO_IN ) != 0 && ( io_status != G_IO_STATUS_ERROR ) ); - } - - g_usleep( 300 ); - - } - //ret = g_io_channel_read_chars ( source, &msg, &len, NULL, &err); - if ( io_status == G_IO_STATUS_ERROR ) { - gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" ); - *ret = FALSE; - } - gmyth_debug ("\n[%s]\tEVENT: Read %d bytes: %s\n\n", __FUNCTION__, len, trash != NULL ? trash : "[no event data]" ); - - //g_cond_signal( io_watcher_cond ); - -clean_up: - //myth_control_release_context( ); - - return ret; - -} -*/ - -/* -static gboolean -gmyth_connect_to_backend_monitor (GMythFileTransfer *transfer, GString *hostname ) -{ - gboolean ret = TRUE; - GString *base_str = g_string_new( "" ); - //guint source_id = 0; - - transfer->event_sock = gmyth_socket_new(); - - gmyth_socket_connect ( transfer->event_sock, transfer->hostname->str, transfer->port); - g_string_printf( base_str, "ANN Monitor %s %d", hostname->str, TRUE ); - - gmyth_socket_send_command( transfer->event_sock, base_str ); - //GString *resp = gmyth_socket_receive_response( transfer->event_sock ); - gmyth_debug ( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str ); - monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_listener, transfer->event_sock->sd_io_ch, FALSE, NULL ); - io_watcher_context = g_main_context_default(); - GMainLoop *loop = g_main_loop_new( NULL, TRUE ); - - GSource *source; - - if ( transfer->event_sock->sd_io_ch != NULL ) { - source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN ); - //transfer->event_sock->sd_io_ch - } else { - ret = FALSE; - goto cleanup; - } - - g_source_set_callback ( source, (GIOFunc)myth_control_sock_listener, NULL, NULL ); - - g_source_attach( source, io_watcher_context ); - - if (source==NULL) { - g_printerr( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ ); - goto cleanup; - } - gmyth_debug ( "[%s]\tOK! Starting listener on the MONITOR event socket...\n", __FUNCTION__ ); - - //g_main_loop_run( loop ); - -//cleanup: - if ( source != NULL ) - g_source_unref( source ); - - gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n", - __FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) ); - - return ret; - -} -*/ - static gboolean gmyth_connect_to_backend (GMythFileTransfer *transfer) { GString *base_str = NULL; + GMythStringList *strlist = NULL; GString *hostname = NULL; - GMythStringList *strlist = NULL; - gchar *path_dir = NULL; gboolean ret = TRUE; g_return_val_if_fail (transfer != NULL, FALSE ); - g_return_val_if_fail (transfer->uri != NULL, FALSE ); - g_return_val_if_fail (transfer->hostname != NULL, FALSE); - g_return_val_if_fail (transfer->port > 0, FALSE); + g_return_val_if_fail (transfer->filename != NULL, FALSE ); + g_return_val_if_fail (transfer->backend_info != NULL, FALSE); base_str = g_string_new (""); - path_dir = gmyth_uri_get_path (transfer->uri); /* Creates the control socket */ if (transfer->control_sock != NULL) { @@ -381,7 +228,7 @@ // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version if (!gmyth_socket_connect_to_backend (transfer->control_sock, - transfer->hostname->str, transfer->port, TRUE)) { + transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) { g_object_unref (transfer->control_sock); transfer->control_sock = NULL; @@ -395,7 +242,7 @@ } transfer->sock = gmyth_socket_new (); - gmyth_socket_connect (transfer->sock, transfer->hostname->str, transfer->port); + gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port); strlist = gmyth_string_list_new(); hostname = gmyth_socket_get_local_hostname(); @@ -406,7 +253,7 @@ g_string_printf( base_str, "ANN FileTransfer %s", hostname->str); gmyth_string_list_append_string (strlist, base_str ); - gmyth_string_list_append_char_array (strlist, path_dir ); + gmyth_string_list_append_char_array (strlist, transfer->filename ); gmyth_socket_write_stringlist (transfer->sock, strlist ); gmyth_socket_read_stringlist (transfer->sock, strlist ); diff -r 585b3db817a1 -r 517da097a261 gmyth/src/gmyth_file_transfer.h --- a/gmyth/src/gmyth_file_transfer.h Thu Nov 30 21:25:06 2006 +0000 +++ b/gmyth/src/gmyth_file_transfer.h Thu Nov 30 21:29:38 2006 +0000 @@ -36,6 +36,7 @@ #include "gmyth_socket.h" #include "gmyth_uri.h" #include "gmyth_livetv.h" +#include "gmyth_backendinfo.h" #include #include @@ -71,7 +72,9 @@ GObject parent; /* Myth URI structure */ - const GMythURI *uri; + //const GMythURI *uri; + gchar* filename; + GMythBackendInfo *backend_info; /* MythTV version number */ gint mythtv_version; @@ -88,22 +91,13 @@ //gint retries; gint file_id; - //gint rec_id; - //gint recordernum; - //gint card_id; - GString *hostname; - gint port; - - /* stores the messages coming from the backend */ - //GHashTable *backend_msgs; }; GType gmyth_file_transfer_get_type (void); -//GMythFileTransfer* gmyth_file_transfer_new (gint num, GString *hostname, gshort port, gint mythtv_version ); -GMythFileTransfer* gmyth_file_transfer_new ( ); +GMythFileTransfer* gmyth_file_transfer_new ( GMythBackendInfo *backend_info ); -gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer, GString *uri_str); +gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer, const gchar* filename); void gmyth_file_transfer_close (GMythFileTransfer *transfer); gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer); @@ -112,13 +106,6 @@ gboolean gmyth_file_transfer_settimeout( GMythFileTransfer *transfer, gboolean fast); guint64 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer); -//gboolean gmyth_file_transfer_playback_setup( GMythFileTransfer **transfer, gboolean live_tv ); -//gboolean gmyth_file_transfer_setup( GMythFileTransfer **transfer, gboolean live_tv ); -//gboolean gmyth_file_transfer_livetv_setup( GMythFileTransfer **transfer, GMythSocket *live_sock ); -//void gmyth_file_transfer_spawntv ( GMythFileTransfer *file_transfer, GString *tvchain_id ); -//gboolean gmyth_file_transfer_is_recording( GMythFileTransfer *file_transfer ); -//gint64 gmyth_file_transfer_get_file_position( GMythFileTransfer *file_transfer ); - #define G_END_DECLS #endif /* __GMYTH_FILE_TRANSFER_H__ */ diff -r 585b3db817a1 -r 517da097a261 gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Thu Nov 30 21:25:06 2006 +0000 +++ b/gmyth/src/gmyth_socket.c Thu Nov 30 21:29:38 2006 +0000 @@ -476,7 +476,7 @@ */ gboolean gmyth_socket_connect (GMythSocket *gmyth_socket, - gchar *hostname, gint port) + const gchar *hostname, gint port) { struct addrinfo *addr_info_data = NULL, *addr_info0 = NULL; gint ret_code = -1; @@ -683,7 +683,7 @@ */ gboolean gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, - gchar *hostname_backend, int port, gboolean blocking_client) + const gchar *hostname_backend, int port, gboolean blocking_client) { if (!gmyth_socket_connect (gmyth_socket, hostname_backend, port)) { g_warning ("[%s] Could not open socket to backend machine [%s]\n", __FUNCTION__, diff -r 585b3db817a1 -r 517da097a261 gmyth/src/gmyth_socket.h --- a/gmyth/src/gmyth_socket.h Thu Nov 30 21:25:06 2006 +0000 +++ b/gmyth/src/gmyth_socket.h Thu Nov 30 21:29:38 2006 +0000 @@ -96,10 +96,9 @@ GMythStringList *str_list); gboolean gmyth_socket_connect (GMythSocket *gmyth_socket, - gchar *hostname, gint port); + const gchar *hostname, gint port); gboolean gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, - gchar *hostname_backend, int port, - gboolean blocking_client); + const gchar *hostname_backend, int port, gboolean blocking_client); GString * gmyth_socket_get_local_hostname (void);