# HG changeset patch # User rosfran # Date 1176386293 -3600 # Node ID ad51640dd2cd15a5d1c8dc18aa4bb207c54a131c # Parent dfa28b22a36cdd6c13c88198ca75455f0a1f25e8 [svn r535] Fixed to the older GMythFileTransfer revision (no GObject inheritance). diff -r dfa28b22a36c -r ad51640dd2cd gmyth/src/gmyth_file.c --- a/gmyth/src/gmyth_file.c Thu Apr 12 13:22:53 2007 +0100 +++ b/gmyth/src/gmyth_file.c Thu Apr 12 14:58:13 2007 +0100 @@ -219,7 +219,7 @@ g_return_if_fail( file != NULL ); g_return_if_fail( filename != NULL ); - g_object_set (G_OBJECT (file), "filename", &filename, NULL); + g_object_set (G_OBJECT (file), "filename", &filename, NULL); } @@ -369,11 +369,12 @@ break; } - if (priv->filename != NULL) { - g_free (priv->filename); - priv->filename = NULL; - } - priv->filename = g_value_dup_string (value); + //if (priv->filename != NULL) { + // g_free (priv->filename); + // priv->filename = NULL; + //} + priv->filename = g_value_dup_string (value); + gmyth_debug( "Changed the filename to [%s]!", priv->filename ); break; } case PROP_GMYTH_FILE_OFFSET: @@ -392,11 +393,12 @@ break; } - if (priv->backend_info != NULL) { - g_object_unref (priv->backend_info); - priv->backend_info = NULL; - } + //if (priv->backend_info != NULL) { + // g_object_unref (priv->backend_info); + // priv->backend_info = NULL; + //} priv->backend_info = g_value_get_object (value); + gmyth_debug( "Changed the backend info to [%s]!", gmyth_backend_info_get_hostname( priv->backend_info ) ); break; } case PROP_GMYTH_FILE_FILEID: @@ -420,6 +422,7 @@ switch (prop_id) { case PROP_GMYTH_FILE_FILENAME: { + gmyth_debug( "Got the filename to [%s]!", priv->filename ); g_value_set_string (value, priv->filename); break; } diff -r dfa28b22a36c -r ad51640dd2cd gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Thu Apr 12 13:22:53 2007 +0100 +++ b/gmyth/src/gmyth_file_transfer.c Thu Apr 12 14:58:13 2007 +0100 @@ -69,20 +69,26 @@ }; struct _GMythFileTransferPrivate { - GMythRecorder *recorder; + GMythRecorder *recorder; - gboolean do_next_program_chain; - gboolean disposed; - gboolean livetv_wait; + gboolean do_next_program_chain; + gboolean disposed; + gboolean livetv_wait; + gint64 offset; + guint64 filesize; + /* Myth URI structure */ + gchar *filename; + GMythBackendInfo *backend_info; + /* MythTV version number */ - gint mythtv_version; + gint mythtv_version; /* socket descriptors */ - GMythSocket *control_sock; - GMythSocket *sock; - GMutex *mutex; - gint file_id; + GMythSocket *control_sock; + GMythSocket *sock; + GMutex *mutex; + gint file_id; }; static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass); @@ -95,7 +101,7 @@ static gboolean _control_acquire_context (GMythFileTransfer *transfer, gboolean do_wait); static gboolean _control_release_context (GMythFileTransfer *transfer); -G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, GMYTH_FILE_TYPE) +G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, G_TYPE_OBJECT) static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass) @@ -175,11 +181,21 @@ priv->sock = NULL; } + if (priv->backend_info != NULL ) { + g_object_unref (priv->backend_info ); + priv->backend_info = NULL; + } + if (priv->recorder != NULL ) { g_object_unref (priv->recorder ); priv->recorder = NULL; } - + + if (priv->filename != NULL ) { + g_free (priv->filename ); + priv->filename = NULL; + } + G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->dispose (object); } @@ -202,24 +218,20 @@ GMythFileTransfer* gmyth_file_transfer_new (GMythBackendInfo *backend_info) { - GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); - - backend_info = g_object_ref( backend_info ); - - g_object_set (G_OBJECT (transfer), "backend-info", &backend_info, NULL); + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); + GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); - return transfer; + priv->backend_info = g_object_ref (backend_info); + return transfer; } gchar* gmyth_file_transfer_get_file_name (GMythFileTransfer *transfer) { - gchar *filename; - - g_object_get( G_OBJECT(transfer), "filename", &filename, NULL ); + GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); - return g_strdup (filename); + return g_strdup (priv->filename); } /** @@ -232,24 +244,18 @@ GMythFileTransfer* gmyth_file_transfer_new_with_uri (const gchar* uri_str) { - GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); - gmyth_debug( "URI str = %s", uri_str ); - GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri (uri_str); - /* - GValue val = {0,}; - g_value_init (&val, G_TYPE_OBJECT); - g_value_set_object (&val, gmyth_backend_info_new_with_uri (uri_str)); - */ - g_object_set(G_OBJECT (transfer), "backend-info", &backend_info, NULL); + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); + GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); - return transfer; + priv->backend_info = gmyth_backend_info_new_with_uri (uri_str); + return transfer; } /** * Open a File Transfer connection in order to get a remote file. * * @param transfer The actual File Transfer instance. - * @param filename The file name of the remote file to be transferred to the client. + * @param filename The file name of the remote file to be transfered to the client. * * @return true, if the connection opening had been done successfully. */ @@ -258,27 +264,30 @@ { gboolean ret = TRUE; GMythFileTransferPrivate *priv; - gchar *fname = NULL; g_return_val_if_fail (transfer != NULL, FALSE); g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE); priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); - - //if ( ) - gmyth_file_set_file_name( GMYTH_FILE(transfer), filename ); + + if (priv->filename != NULL) + { + gmyth_file_transfer_close (transfer); + } + + priv->filename = g_strdup( filename ); /* configure the control socket */ if (priv->control_sock == NULL) { if (!_connect_to_backend (transfer)) { - gmyth_debug ("Connection to backend failed (Control Socket)."); + gmyth_debug ("Connection to backend failed (Control Socket).\n"); ret = FALSE; } } else { - gmyth_debug("Remote transfer control socket already created."); + gmyth_debug("Remote transfer control socket already created.\n"); } - gmyth_debug ("Got file with size = %lld.\n", gmyth_file_get_filesize(GMYTH_FILE(transfer))); + gmyth_debug ("Got file with size = %lld.\n", priv->filesize); return ret; } @@ -298,15 +307,13 @@ GMythStringList *strlist = NULL; gboolean ret = TRUE; GMythFileTransferPrivate *priv; - GMythBackendInfo *backend_info; g_return_val_if_fail (transfer != NULL, FALSE ); - - g_object_get( GMYTH_FILE(transfer), "backend-info", &backend_info, NULL ); priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); _control_acquire_context (transfer, TRUE); + /* Creates the control socket */ if (priv->control_sock != NULL) { @@ -319,7 +326,7 @@ priv->control_sock = gmyth_socket_new(); // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version if (!gmyth_socket_connect_to_backend (priv->control_sock, - backend_info->hostname, backend_info->port, TRUE)) { + priv->backend_info->hostname, priv->backend_info->port, TRUE)) { g_object_unref (priv->control_sock); priv->control_sock = NULL; @@ -333,8 +340,8 @@ } priv->sock = gmyth_socket_new (); - gmyth_socket_connect (priv->sock, backend_info->hostname, backend_info->port); - gmyth_debug ("Connecting file transfer... (%s, %d)", backend_info->hostname, backend_info->port); + gmyth_socket_connect (priv->sock, priv->backend_info->hostname, priv->backend_info->port); + gmyth_debug ("Connecting file transfer... (%s, %d)", priv->backend_info->hostname, priv->backend_info->port); strlist = gmyth_string_list_new(); hostname = gmyth_socket_get_local_hostname(); @@ -345,7 +352,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, gmyth_file_get_file_name(GMYTH_FILE(transfer))); + gmyth_string_list_append_char_array (strlist, priv->filename); gmyth_socket_write_stringlist (priv->sock, strlist ); gmyth_socket_read_stringlist (priv->sock, strlist ); @@ -354,14 +361,13 @@ priv->file_id = gmyth_string_list_get_int (strlist, 1); /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */ - gmyth_file_set_filesize( GMYTH_FILE(transfer), gmyth_util_decode_long_long (strlist, 2) ); + priv->filesize = gmyth_util_decode_long_long (strlist, 2); - gmyth_debug ( "***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", - priv->file_id, gmyth_file_get_filesize(GMYTH_FILE(transfer)) ); + gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__, + priv->file_id, priv->filesize ); - if ( gmyth_file_get_filesize(GMYTH_FILE(transfer)) < 0 ) { - gmyth_debug ( "Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", - gmyth_file_get_filesize(GMYTH_FILE(transfer)) ); + if (priv->filesize < 0 ) { + gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, priv->filesize); g_object_unref (priv->sock); priv->sock = NULL; ret = FALSE; @@ -488,6 +494,11 @@ priv->control_sock = NULL; } + if (priv->filename) { + g_free (priv->filename); + priv->filename = NULL; + } + _control_release_context (transfer); } @@ -528,13 +539,14 @@ if (pos > 0 ) gmyth_string_list_append_uint64 (strlist, pos); else - gmyth_string_list_append_uint64 (strlist, gmyth_file_get_offset( GMYTH_FILE(transfer) ) ); + gmyth_string_list_append_uint64 (strlist, priv->offset); gmyth_socket_sendreceive_stringlist (priv->control_sock, strlist); gint64 retval = gmyth_string_list_get_int64 (strlist, 0); - gmyth_file_set_offset( GMYTH_FILE(transfer), retval ); - gmyth_debug ( "Got reading position pointer from the streaming = %lld\n", retval ); + priv->offset = retval; + gmyth_debug ( "[%s] got reading position pointer from the streaming = %lld\n", + __FUNCTION__, retval ); g_object_unref (strlist); g_string_free (query, TRUE); @@ -599,13 +611,13 @@ * @return The actual block size (in bytes) returned by REQUEST_BLOCK message, * or the error code. */ -GMythFileReadResult +GMythFileTransferReadResult gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, gint size, gboolean read_unlimited) { gint bytes_sent = 0; gsize bytes_read = 0; gint64 total_read = 0; - GMythFileReadResult retval = GMYTH_FILE_READ_OK; + GMythFileTransferReadResult retval = GMYTH_FILE_TRANSFER_READ_OK; GMythFileTransferPrivate *priv; GError *error = NULL; @@ -624,7 +636,7 @@ GString *query; g_return_val_if_fail (transfer != NULL, FALSE); - g_return_val_if_fail (data != NULL, GMYTH_FILE_READ_ERROR); + g_return_val_if_fail (data != NULL, GMYTH_FILE_TRANSFER_READ_ERROR); priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); @@ -642,12 +654,12 @@ io_cond_control = g_io_channel_get_buffer_condition( io_channel ); if (priv->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) ) { g_printerr( "gmyth_file_transfer_read(): Called with no raw socket.\n" ); - return GMYTH_FILE_READ_ERROR; + return GMYTH_FILE_TRANSFER_READ_ERROR; } if (priv->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) ) { g_printerr( "gmyth_file_transfer_read(): Called with no control socket.\n" ); - return GMYTH_FILE_READ_ERROR; + return GMYTH_FILE_TRANSFER_READ_ERROR; } query = g_string_new (GMYTHTV_QUERY_HEADER); @@ -696,24 +708,22 @@ gmyth_debug ("Error on io_channel"); g_free (data_buffer); g_object_unref (strlist); - retval = GMYTH_FILE_READ_ERROR; + retval = GMYTH_FILE_TRANSFER_READ_ERROR; goto error; } /* append new data to the increasing byte array */ data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read); - gmyth_file_set_offset( GMYTH_FILE(transfer), - gmyth_file_get_offset( GMYTH_FILE(transfer) ) + bytes_read ); + priv->offset += bytes_read; - if ( !read_unlimited && ( gmyth_file_get_filesize( GMYTH_FILE(transfer) ) > 0 ) && - ( gmyth_file_get_offset( GMYTH_FILE(transfer) ) == gmyth_file_get_filesize( GMYTH_FILE(transfer) ) ) ) { - retval = GMYTH_FILE_READ_EOF; + if (!read_unlimited && (priv->filesize > 0) && (priv->offset == priv->filesize)) { + retval = GMYTH_FILE_TRANSFER_READ_EOF; goto error; } g_free (data_buffer); } else { - retval = GMYTH_FILE_READ_ERROR; + retval = GMYTH_FILE_TRANSFER_READ_ERROR; } if (strlist!=NULL) @@ -734,12 +744,11 @@ if (priv->recorder != NULL && priv->do_next_program_chain) { - retval = GMYTH_FILE_READ_NEXT_PROG_CHAIN; + retval = GMYTH_FILE_TRANSFER_READ_NEXT_PROG_CHAIN; GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info (priv->recorder); if (prog_info != NULL && prog_info->pathname != NULL && strlen( prog_info->pathname->str ) > 0 && - g_ascii_strcasecmp( prog_info->pathname->str, - gmyth_file_get_file_name( GMYTH_FILE(transfer) ) ) != 0 ) + g_ascii_strcasecmp( prog_info->pathname->str, priv->filename ) != 0 ) ret = gmyth_file_transfer_open (transfer, g_strrstr( prog_info->pathname->str, "/" ) ); if (prog_info != NULL ) @@ -749,7 +758,7 @@ gmyth_debug( "Cannot change to the next program info!" ); else gmyth_debug( "OK!!! MOVED to the next program info [%s]!", - gmyth_file_get_file_name( GMYTH_FILE(transfer) ) ); + priv->filename ); } } /* if */ @@ -766,12 +775,12 @@ } if ( total_read > 0 ) - gmyth_file_set_offset( GMYTH_FILE(transfer), - gmyth_file_get_offset( GMYTH_FILE(transfer) ) + total_read ); + priv->offset += total_read; return retval; } + static void _file_transfer_program_info_changed( GMythFileTransfer *transfer, gint msg_code, gpointer livetv_recorder ) @@ -855,11 +864,10 @@ guint64 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer) { - guint64 filesize; - + GMythFileTransferPrivate *priv; + g_return_val_if_fail (transfer != NULL, 0); - - g_object_get( GMYTH_FILE(transfer), "filesize", &filesize, NULL ); - return filesize; + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); + return priv->filesize; } diff -r dfa28b22a36c -r ad51640dd2cd gmyth/src/gmyth_file_transfer.h --- a/gmyth/src/gmyth_file_transfer.h Thu Apr 12 13:22:53 2007 +0100 +++ b/gmyth/src/gmyth_file_transfer.h Thu Apr 12 14:58:13 2007 +0100 @@ -32,7 +32,6 @@ #include #include -#include "gmyth_file.h" #include "gmyth_socket.h" #include "gmyth_uri.h" #include "gmyth_backendinfo.h" @@ -53,18 +52,27 @@ #define IS_GMYTH_FILE_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TRANSFER_TYPE)) #define GMYTH_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass)) +typedef enum { + GMYTH_FILE_TRANSFER_READ_OK = 0, + GMYTH_FILE_TRANSFER_READ_NEXT_PROG_CHAIN = 1, + GMYTH_FILE_TRANSFER_READ_ERROR = 2, + GMYTH_FILE_TRANSFER_READ_EOF = 3 +} GMythFileTransferReadResult; + + typedef struct _GMythFileTransfer GMythFileTransfer; typedef struct _GMythFileTransferClass GMythFileTransferClass; typedef struct _GMythFileTransferPrivate GMythFileTransferPrivate; struct _GMythFileTransfer { - GMythFile parent; + GObject parent; }; + struct _GMythFileTransferClass { - GMythFileClass parent_class; + GObjectClass parent_class; /* callbacks */ guint program_info_changed_handler_signal_id; @@ -82,7 +90,7 @@ const gchar* filename); void gmyth_file_transfer_close (GMythFileTransfer *transfer); gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer); -GMythFileReadResult +GMythFileTransferReadResult gmyth_file_transfer_read (GMythFileTransfer *transfer, GByteArray *data, gint size, diff -r dfa28b22a36c -r ad51640dd2cd gmyth/src/gmyth_uri.c --- a/gmyth/src/gmyth_uri.c Thu Apr 12 13:22:53 2007 +0100 +++ b/gmyth/src/gmyth_uri.c Thu Apr 12 14:58:13 2007 +0100 @@ -374,7 +374,6 @@ uri->fragment = g_string_new_len (value+currIdx+sharpIdx+1, uriLen-(currIdx+sharpIdx+1)); } - /* gmyth_debug( "[%s] GMythURI: host = %s, port = %d, path = %s, query = %s, fragment = %s, "\ "user = %s, password = %s.\n", __FUNCTION__, gmyth_uri_print_field( uri->host ), uri->port, @@ -383,7 +382,6 @@ gmyth_uri_print_field( uri->fragment ), gmyth_uri_print_field ( uri->user ), gmyth_uri_print_field( uri->password ) ); - */ } @@ -421,7 +419,9 @@ if ( ret ) gmyth_debug( "This URI is a LiveTV recording..." ); - + else + gmyth_debug( "This URI is a stored remote recording." ); + return ret; }