[svn r534] Added GObject inheritance to the GMythFile* modules.
1.1 --- a/gmyth/src/Makefile.am Thu Apr 12 00:01:16 2007 +0100
1.2 +++ b/gmyth/src/Makefile.am Thu Apr 12 13:22:53 2007 +0100
1.3 @@ -29,9 +29,10 @@
1.4 gmyth_jobqueue.c \
1.5 gmyth_transcoder.c \
1.6 gmyth_recprofile.c \
1.7 + gmyth_file.c \
1.8 + gmyth_file_local.c \
1.9 $(BUILT_SOURCES)
1.10
1.11 -
1.12 EXTRA_libgmyth_la_SOURCES = gmyth_marshal.list
1.13
1.14 gmyth_marshal.h: gmyth_marshal.list
1.15 @@ -88,6 +89,8 @@
1.16 gmyth_vlc.h \
1.17 gmyth_jobqueue.h \
1.18 gmyth_transcoder.h \
1.19 - gmyth_recprofile.h
1.20 + gmyth_recprofile.h \
1.21 + gmyth_file.h \
1.22 + gmyth_file_local.h
1.23
1.24 CLEANFILES = $(BUILT_SOURCES)
2.1 --- a/gmyth/src/gmyth_backendinfo.c Thu Apr 12 00:01:16 2007 +0100
2.2 +++ b/gmyth/src/gmyth_backendinfo.c Thu Apr 12 13:22:53 2007 +0100
2.3 @@ -283,13 +283,42 @@
2.4 gmyth_backend_info_get_uri (GMythBackendInfo *backend_info)
2.5 {
2.6 GMythURI *uri = NULL;
2.7 - gchar* uri_str = g_strdup_printf( "myth://%s:%s@%s:%d/?%s", backend_info->username, backend_info->password,
2.8 - backend_info->hostname, backend_info->port, backend_info->db_name );
2.9 + gchar* uri_str = g_strdup("");
2.10 + gchar *user_info = g_strdup("");
2.11 + gchar *db_data = g_strdup("");
2.12 +
2.13 + if ( ( backend_info->username != NULL && strlen(backend_info->username) > 0 ) )
2.14 + user_info = g_strdup_printf( "%s:%s@", backend_info->username, backend_info->password );
2.15 +
2.16 + if ( backend_info->db_name != NULL && strlen(backend_info->db_name) > 0 )
2.17 + {
2.18 + if ( ( g_strrstr( backend_info->db_name, "_" ) != NULL ) )
2.19 + db_data = backend_info->db_name;
2.20 + else
2.21 + db_data = g_strdup_printf( "?%s&", backend_info->db_name );
2.22 + }
2.23 + //else if ( ( ( g_strrstr( backend_info->path, "livetv" ) != NULL ) ||
2.24 + // ( g_strrstr( backend_info->path, "/?" ) != NULL ) )
2.25 +
2.26 + uri_str = g_strdup_printf( "myth://%s%s:%d/%s", user_info != NULL && strlen( user_info ) > 0 ? g_strdup( user_info ) : "", backend_info->hostname,
2.27 + backend_info->port, db_data != NULL && strlen( db_data ) > 0 ? g_strdup( db_data ) : "");
2.28 uri = gmyth_uri_new_with_value (uri_str);
2.29
2.30 + if ( user_info != NULL )
2.31 + g_free( user_info );
2.32 +
2.33 + if ( db_data != NULL )
2.34 + g_free( db_data );
2.35 +
2.36 g_free (uri_str);
2.37
2.38 return uri;
2.39 }
2.40
2.41 -
2.42 +gboolean
2.43 +gmyth_backend_info_is_local_file(GMythBackendInfo *backend_info)
2.44 +{
2.45 + g_return_val_if_fail (backend_info != NULL, FALSE);
2.46 +
2.47 + return gmyth_uri_is_local_file( gmyth_backend_info_get_uri( backend_info ) );
2.48 +}
3.1 --- a/gmyth/src/gmyth_backendinfo.h Thu Apr 12 00:01:16 2007 +0100
3.2 +++ b/gmyth/src/gmyth_backendinfo.h Thu Apr 12 13:22:53 2007 +0100
3.3 @@ -106,6 +106,8 @@
3.4
3.5 GMythURI* gmyth_backend_info_get_uri (GMythBackendInfo *backend_info);
3.6
3.7 +gboolean gmyth_backend_info_is_local_file(GMythBackendInfo *backend_info);
3.8 +
3.9 G_END_DECLS
3.10
3.11 #endif /* __GMYTH_BACKEND_INFO_H__ */
4.1 --- a/gmyth/src/gmyth_file.c Thu Apr 12 00:01:16 2007 +0100
4.2 +++ b/gmyth/src/gmyth_file.c Thu Apr 12 13:22:53 2007 +0100
4.3 @@ -123,7 +123,7 @@
4.4 (gobject_class, PROP_GMYTH_FILE_BACKEND_INFO,
4.5 g_param_spec_object ("backend-info", "backend-info",
4.6 "The Backend Information about the remote server",
4.7 - GMYTH_FILE_TYPE, G_PARAM_READWRITE));
4.8 + G_TYPE_OBJECT, G_PARAM_READWRITE));
4.9
4.10 g_object_class_install_property
4.11 (gobject_class, PROP_GMYTH_FILE_FILEID,
4.12 @@ -195,10 +195,7 @@
4.13 {
4.14 GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL));
4.15
4.16 - GValue val = {0,};
4.17 - g_value_init (&val, G_TYPE_OBJECT);
4.18 - g_value_set_object (&val, backend_info);
4.19 - g_object_set_property (G_OBJECT (file), "backend-info", &val);
4.20 + g_object_set(G_OBJECT (file), "backend-info", &backend_info, NULL);
4.21
4.22 return file;
4.23 }
4.24 @@ -206,17 +203,24 @@
4.25 gchar*
4.26 gmyth_file_get_file_name (GMythFile *file)
4.27 {
4.28 - GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
4.29 + gchar *filename;
4.30 +
4.31 + g_return_val_if_fail( file != NULL, NULL );
4.32 + g_return_val_if_fail( filename != NULL, NULL );
4.33 +
4.34 + g_object_get(G_OBJECT (file), "filename", &filename, NULL);
4.35
4.36 - return g_strdup (priv->filename);
4.37 + return filename;
4.38 }
4.39
4.40 void
4.41 gmyth_file_set_file_name (GMythFile *file, const gchar* filename)
4.42 -{
4.43 - GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
4.44 +{
4.45 + g_return_if_fail( file != NULL );
4.46 + g_return_if_fail( filename != NULL );
4.47 +
4.48 + g_object_set (G_OBJECT (file), "filename", &filename, NULL);
4.49
4.50 - return priv->filename = g_strdup (filename);
4.51 }
4.52
4.53 /**
5.1 --- a/gmyth/src/gmyth_file_local.c Thu Apr 12 00:01:16 2007 +0100
5.2 +++ b/gmyth/src/gmyth_file_local.c Thu Apr 12 13:22:53 2007 +0100
5.3 @@ -153,14 +153,9 @@
5.4 GMythFileLocal*
5.5 gmyth_file_local_new (GMythBackendInfo *backend_info)
5.6 {
5.7 - GMythFileLocal *file_local = NULL;
5.8 - GValue val = {0,};
5.9 - g_value_init (&val, G_TYPE_OBJECT);
5.10 - g_value_set_object (&val, backend_info);
5.11 - g_object_set_property (G_OBJECT (file), "backend-info", &val);
5.12 + GMythFileLocal *file_local = GMYTH_FILE_LOCAL (g_object_new (GMYTH_FILE_LOCAL_TYPE, NULL));
5.13
5.14 - file_local = GMYTH_FILE_LOCAL (g_object_new (GMYTH_FILE_TYPE,
5.15 - "backend-info", val, NULL));
5.16 + g_object_set ( GMYTH_FILE( file_local ), "backend-info", &backend_info, NULL );
5.17
5.18 return file_local;
5.19 }
5.20 @@ -175,7 +170,7 @@
5.21 GMythFileLocal*
5.22 gmyth_file_local_new_with_uri (const gchar* uri_str)
5.23 {
5.24 - GMythFileLocal *file_local = GMYTH_FILE_LOCAL (g_object_new (GMYTH_FILE_TYPE, NULL));
5.25 + GMythFileLocal *file_local = GMYTH_FILE_LOCAL (g_object_new (GMYTH_FILE_LOCAL_TYPE, NULL));
5.26 GMythURI *uri = gmyth_uri_new_with_value(uri_str);
5.27
5.28 gmyth_debug( "GMythURI path segment = %s", gmyth_uri_get_path(uri) );
5.29 @@ -241,8 +236,6 @@
5.30 void
5.31 gmyth_file_local_close (GMythFileLocal *file_local )
5.32 {
5.33 - GMythFileLocalPrivate *priv;
5.34 -
5.35 g_return_if_fail (file_local != NULL);
5.36 }
5.37
5.38 @@ -314,8 +307,6 @@
5.39 GIOCondition io_cond;
5.40 GIOStatus io_status = G_IO_STATUS_NORMAL;
5.41
5.42 - gboolean ret = TRUE;
5.43 -
5.44 g_return_val_if_fail (file_local != NULL, FALSE);
5.45 g_return_val_if_fail (data != NULL, GMYTH_FILE_READ_ERROR);
5.46
5.47 @@ -348,8 +339,8 @@
5.48 data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
5.49 total_read += bytes_read;
5.50
5.51 - if (!read_unlimited && ( gmyth_file_local_get_file_size(file_local) > 0) &&
5.52 - (gmyth_file_local_get_offset(file_local) == gmyth_file_local_get_file_size(file_local))) {
5.53 + if (!read_unlimited && ( gmyth_file_local_get_filesize(file_local) > 0) &&
5.54 + (gmyth_file_local_get_offset(file_local) == gmyth_file_local_get_filesize(file_local))) {
5.55 retval = GMYTH_FILE_READ_EOF;
5.56 goto error;
5.57 }
5.58 @@ -374,6 +365,28 @@
5.59 return retval;
5.60 }
5.61
5.62 +gint64
5.63 +gmyth_file_local_seek(GMythFileLocal *file_local, gint64 pos, GSeekType whence)
5.64 +{
5.65 + GMythFileLocalPrivate *priv;
5.66 +
5.67 + GError *error;
5.68 +
5.69 + GIOStatus io_status = G_IO_STATUS_NORMAL;
5.70 +
5.71 + g_return_val_if_fail (file_local != NULL, -1);
5.72 +
5.73 + priv = GMYTH_FILE_LOCAL_GET_PRIVATE (file_local);
5.74 +
5.75 + io_status = g_io_channel_seek_position (priv->file_io, pos, whence, &error);
5.76 +
5.77 + if ( io_status == G_IO_STATUS_ERROR )
5.78 + pos = -1;
5.79 +
5.80 + return pos;
5.81 +
5.82 +}
5.83 +
5.84 /**
5.85 * Gets the actual file_local size of the binary content.
5.86 *
5.87 @@ -386,7 +399,7 @@
5.88 {
5.89 g_return_val_if_fail (file_local != NULL, 0);
5.90
5.91 - return gmyth_file_get_filesize( GMYTH_FILE(g_type_peek_parent(file_local)) );
5.92 + return gmyth_file_get_filesize( GMYTH_FILE(file_local) );
5.93 }
5.94
5.95 /**
5.96 @@ -400,7 +413,7 @@
5.97 {
5.98 g_return_if_fail (file_local != NULL);
5.99
5.100 - gmyth_file_set_filesize( GMYTH_FILE(g_type_peek_parent(file_local)), filesize );
5.101 + gmyth_file_set_filesize( GMYTH_FILE(file_local), filesize );
5.102 }
5.103
5.104 /**
5.105 @@ -415,7 +428,7 @@
5.106 {
5.107 g_return_val_if_fail (file_local != NULL, 0);
5.108
5.109 - return gmyth_file_get_offset ( GMYTH_FILE(g_type_peek_parent(file_local)));;
5.110 + return gmyth_file_get_offset ( GMYTH_FILE(file_local) );
5.111 }
5.112
5.113 /**
5.114 @@ -429,6 +442,6 @@
5.115 {
5.116 g_return_if_fail (file_local != NULL);
5.117
5.118 - gmyth_file_set_offset( GMYTH_FILE(g_type_peek_parent(file_local)), offset );
5.119 + gmyth_file_set_offset( GMYTH_FILE( file_local ), offset );
5.120 }
5.121
6.1 --- a/gmyth/src/gmyth_file_local.h Thu Apr 12 00:01:16 2007 +0100
6.2 +++ b/gmyth/src/gmyth_file_local.h Thu Apr 12 13:22:53 2007 +0100
6.3 @@ -69,7 +69,7 @@
6.4
6.5 GType gmyth_file_local_get_type (void);
6.6 GMythFileLocal* gmyth_file_local_new (GMythBackendInfo *backend_info);
6.7 -GMythFileLocal* gmyth_file_local_new_with_uri (GMythBackendInfo *backend_info, const gchar* uri);
6.8 +GMythFileLocal* gmyth_file_local_new_with_uri (const gchar* uri);
6.9 gchar* gmyth_file_local_get_file_name (GMythFileLocal *file_local);
6.10 void gmyth_file_local_set_file_name (GMythFileLocal *file_local, const gchar* filename);
6.11 gboolean gmyth_file_local_open (GMythFileLocal *file_local);
6.12 @@ -80,6 +80,10 @@
6.13 GByteArray *data,
6.14 gint size,
6.15 gboolean read_unlimited);
6.16 +
6.17 +gint64 gmyth_file_local_seek (GMythFileLocal *file_local,
6.18 + gint64 pos, GSeekType whence);
6.19 +
6.20 guint64 gmyth_file_local_get_filesize (GMythFileLocal *file_local);
6.21 void gmyth_file_local_set_filesize (GMythFileLocal *file, guint64 filesize);
6.22
7.1 --- a/gmyth/src/gmyth_file_transfer.c Thu Apr 12 00:01:16 2007 +0100
7.2 +++ b/gmyth/src/gmyth_file_transfer.c Thu Apr 12 13:22:53 2007 +0100
7.3 @@ -69,26 +69,20 @@
7.4 };
7.5
7.6 struct _GMythFileTransferPrivate {
7.7 - GMythRecorder *recorder;
7.8 + GMythRecorder *recorder;
7.9
7.10 - gboolean do_next_program_chain;
7.11 - gboolean disposed;
7.12 - gboolean livetv_wait;
7.13 - gint64 offset;
7.14 - guint64 filesize;
7.15 + gboolean do_next_program_chain;
7.16 + gboolean disposed;
7.17 + gboolean livetv_wait;
7.18
7.19 - /* Myth URI structure */
7.20 - gchar *filename;
7.21 - GMythBackendInfo *backend_info;
7.22 -
7.23 /* MythTV version number */
7.24 - gint mythtv_version;
7.25 + gint mythtv_version;
7.26
7.27 /* socket descriptors */
7.28 - GMythSocket *control_sock;
7.29 - GMythSocket *sock;
7.30 - GMutex *mutex;
7.31 - gint file_id;
7.32 + GMythSocket *control_sock;
7.33 + GMythSocket *sock;
7.34 + GMutex *mutex;
7.35 + gint file_id;
7.36 };
7.37
7.38 static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass);
7.39 @@ -101,7 +95,7 @@
7.40 static gboolean _control_acquire_context (GMythFileTransfer *transfer, gboolean do_wait);
7.41 static gboolean _control_release_context (GMythFileTransfer *transfer);
7.42
7.43 -G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, G_TYPE_OBJECT)
7.44 +G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, GMYTH_FILE_TYPE)
7.45
7.46 static void
7.47 gmyth_file_transfer_class_init (GMythFileTransferClass *klass)
7.48 @@ -181,21 +175,11 @@
7.49 priv->sock = NULL;
7.50 }
7.51
7.52 - if (priv->backend_info != NULL ) {
7.53 - g_object_unref (priv->backend_info );
7.54 - priv->backend_info = NULL;
7.55 - }
7.56 -
7.57 if (priv->recorder != NULL ) {
7.58 g_object_unref (priv->recorder );
7.59 priv->recorder = NULL;
7.60 }
7.61 -
7.62 - if (priv->filename != NULL ) {
7.63 - g_free (priv->filename );
7.64 - priv->filename = NULL;
7.65 - }
7.66 -
7.67 +
7.68 G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->dispose (object);
7.69 }
7.70
7.71 @@ -218,20 +202,24 @@
7.72 GMythFileTransfer*
7.73 gmyth_file_transfer_new (GMythBackendInfo *backend_info)
7.74 {
7.75 - GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
7.76 - GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
7.77 + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
7.78 +
7.79 + backend_info = g_object_ref( backend_info );
7.80 +
7.81 + g_object_set (G_OBJECT (transfer), "backend-info", &backend_info, NULL);
7.82
7.83 - priv->backend_info = g_object_ref (backend_info);
7.84 - return transfer;
7.85 + return transfer;
7.86 }
7.87
7.88
7.89 gchar*
7.90 gmyth_file_transfer_get_file_name (GMythFileTransfer *transfer)
7.91 {
7.92 - GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
7.93 + gchar *filename;
7.94 +
7.95 + g_object_get( G_OBJECT(transfer), "filename", &filename, NULL );
7.96
7.97 - return g_strdup (priv->filename);
7.98 + return g_strdup (filename);
7.99 }
7.100
7.101 /**
7.102 @@ -244,18 +232,24 @@
7.103 GMythFileTransfer*
7.104 gmyth_file_transfer_new_with_uri (const gchar* uri_str)
7.105 {
7.106 - GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
7.107 - GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
7.108 + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
7.109 + gmyth_debug( "URI str = %s", uri_str );
7.110 + GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri (uri_str);
7.111 + /*
7.112 + GValue val = {0,};
7.113 + g_value_init (&val, G_TYPE_OBJECT);
7.114 + g_value_set_object (&val, gmyth_backend_info_new_with_uri (uri_str));
7.115 + */
7.116 + g_object_set(G_OBJECT (transfer), "backend-info", &backend_info, NULL);
7.117
7.118 - priv->backend_info = gmyth_backend_info_new_with_uri (uri_str);
7.119 - return transfer;
7.120 + return transfer;
7.121 }
7.122
7.123 /**
7.124 * Open a File Transfer connection in order to get a remote file.
7.125 *
7.126 * @param transfer The actual File Transfer instance.
7.127 - * @param filename The file name of the remote file to be transfered to the client.
7.128 + * @param filename The file name of the remote file to be transferred to the client.
7.129 *
7.130 * @return <code>true</code>, if the connection opening had been done successfully.
7.131 */
7.132 @@ -264,30 +258,27 @@
7.133 {
7.134 gboolean ret = TRUE;
7.135 GMythFileTransferPrivate *priv;
7.136 + gchar *fname = NULL;
7.137
7.138 g_return_val_if_fail (transfer != NULL, FALSE);
7.139 g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE);
7.140
7.141 priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
7.142 -
7.143 - if (priv->filename != NULL)
7.144 - {
7.145 - gmyth_file_transfer_close (transfer);
7.146 - }
7.147 -
7.148 - priv->filename = g_strdup( filename );
7.149 +
7.150 + //if ( )
7.151 + gmyth_file_set_file_name( GMYTH_FILE(transfer), filename );
7.152
7.153 /* configure the control socket */
7.154 if (priv->control_sock == NULL) {
7.155 if (!_connect_to_backend (transfer)) {
7.156 - gmyth_debug ("Connection to backend failed (Control Socket).\n");
7.157 + gmyth_debug ("Connection to backend failed (Control Socket).");
7.158 ret = FALSE;
7.159 }
7.160 } else {
7.161 - gmyth_debug("Remote transfer control socket already created.\n");
7.162 + gmyth_debug("Remote transfer control socket already created.");
7.163 }
7.164
7.165 - gmyth_debug ("Got file with size = %lld.\n", priv->filesize);
7.166 + gmyth_debug ("Got file with size = %lld.\n", gmyth_file_get_filesize(GMYTH_FILE(transfer)));
7.167
7.168 return ret;
7.169 }
7.170 @@ -307,13 +298,15 @@
7.171 GMythStringList *strlist = NULL;
7.172 gboolean ret = TRUE;
7.173 GMythFileTransferPrivate *priv;
7.174 + GMythBackendInfo *backend_info;
7.175
7.176 g_return_val_if_fail (transfer != NULL, FALSE );
7.177 +
7.178 + g_object_get( GMYTH_FILE(transfer), "backend-info", &backend_info, NULL );
7.179
7.180 priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
7.181 _control_acquire_context (transfer, TRUE);
7.182
7.183 -
7.184 /* Creates the control socket */
7.185
7.186 if (priv->control_sock != NULL) {
7.187 @@ -326,7 +319,7 @@
7.188 priv->control_sock = gmyth_socket_new();
7.189 // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version
7.190 if (!gmyth_socket_connect_to_backend (priv->control_sock,
7.191 - priv->backend_info->hostname, priv->backend_info->port, TRUE)) {
7.192 + backend_info->hostname, backend_info->port, TRUE)) {
7.193
7.194 g_object_unref (priv->control_sock);
7.195 priv->control_sock = NULL;
7.196 @@ -340,8 +333,8 @@
7.197 }
7.198
7.199 priv->sock = gmyth_socket_new ();
7.200 - gmyth_socket_connect (priv->sock, priv->backend_info->hostname, priv->backend_info->port);
7.201 - gmyth_debug ("Connecting file transfer... (%s, %d)", priv->backend_info->hostname, priv->backend_info->port);
7.202 + gmyth_socket_connect (priv->sock, backend_info->hostname, backend_info->port);
7.203 + gmyth_debug ("Connecting file transfer... (%s, %d)", backend_info->hostname, backend_info->port);
7.204
7.205 strlist = gmyth_string_list_new();
7.206 hostname = gmyth_socket_get_local_hostname();
7.207 @@ -352,7 +345,7 @@
7.208 g_string_printf (base_str, "ANN FileTransfer %s", hostname->str);
7.209
7.210 gmyth_string_list_append_string (strlist, base_str );
7.211 - gmyth_string_list_append_char_array (strlist, priv->filename);
7.212 + gmyth_string_list_append_char_array (strlist, gmyth_file_get_file_name(GMYTH_FILE(transfer)));
7.213
7.214 gmyth_socket_write_stringlist (priv->sock, strlist );
7.215 gmyth_socket_read_stringlist (priv->sock, strlist );
7.216 @@ -361,13 +354,14 @@
7.217 priv->file_id = gmyth_string_list_get_int (strlist, 1);
7.218
7.219 /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
7.220 - priv->filesize = gmyth_util_decode_long_long (strlist, 2);
7.221 + gmyth_file_set_filesize( GMYTH_FILE(transfer), gmyth_util_decode_long_long (strlist, 2) );
7.222
7.223 - gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__,
7.224 - priv->file_id, priv->filesize );
7.225 + gmyth_debug ( "***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n",
7.226 + priv->file_id, gmyth_file_get_filesize(GMYTH_FILE(transfer)) );
7.227
7.228 - if (priv->filesize < 0 ) {
7.229 - gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, priv->filesize);
7.230 + if ( gmyth_file_get_filesize(GMYTH_FILE(transfer)) < 0 ) {
7.231 + gmyth_debug ( "Got filesize equals to %llu is lesser than 0 [invalid stream file]\n",
7.232 + gmyth_file_get_filesize(GMYTH_FILE(transfer)) );
7.233 g_object_unref (priv->sock);
7.234 priv->sock = NULL;
7.235 ret = FALSE;
7.236 @@ -494,11 +488,6 @@
7.237 priv->control_sock = NULL;
7.238 }
7.239
7.240 - if (priv->filename) {
7.241 - g_free (priv->filename);
7.242 - priv->filename = NULL;
7.243 - }
7.244 -
7.245 _control_release_context (transfer);
7.246 }
7.247
7.248 @@ -539,14 +528,13 @@
7.249 if (pos > 0 )
7.250 gmyth_string_list_append_uint64 (strlist, pos);
7.251 else
7.252 - gmyth_string_list_append_uint64 (strlist, priv->offset);
7.253 + gmyth_string_list_append_uint64 (strlist, gmyth_file_get_offset( GMYTH_FILE(transfer) ) );
7.254
7.255 gmyth_socket_sendreceive_stringlist (priv->control_sock, strlist);
7.256
7.257 gint64 retval = gmyth_string_list_get_int64 (strlist, 0);
7.258 - priv->offset = retval;
7.259 - gmyth_debug ( "[%s] got reading position pointer from the streaming = %lld\n",
7.260 - __FUNCTION__, retval );
7.261 + gmyth_file_set_offset( GMYTH_FILE(transfer), retval );
7.262 + gmyth_debug ( "Got reading position pointer from the streaming = %lld\n", retval );
7.263
7.264 g_object_unref (strlist);
7.265 g_string_free (query, TRUE);
7.266 @@ -611,13 +599,13 @@
7.267 * @return The actual block size (in bytes) returned by REQUEST_BLOCK message,
7.268 * or the error code.
7.269 */
7.270 -GMythFileTransferReadResult
7.271 +GMythFileReadResult
7.272 gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, gint size, gboolean read_unlimited)
7.273 {
7.274 gint bytes_sent = 0;
7.275 gsize bytes_read = 0;
7.276 gint64 total_read = 0;
7.277 - GMythFileTransferReadResult retval = GMYTH_FILE_TRANSFER_READ_OK;
7.278 + GMythFileReadResult retval = GMYTH_FILE_READ_OK;
7.279 GMythFileTransferPrivate *priv;
7.280
7.281 GError *error = NULL;
7.282 @@ -636,7 +624,7 @@
7.283 GString *query;
7.284
7.285 g_return_val_if_fail (transfer != NULL, FALSE);
7.286 - g_return_val_if_fail (data != NULL, GMYTH_FILE_TRANSFER_READ_ERROR);
7.287 + g_return_val_if_fail (data != NULL, GMYTH_FILE_READ_ERROR);
7.288
7.289 priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
7.290
7.291 @@ -654,12 +642,12 @@
7.292 io_cond_control = g_io_channel_get_buffer_condition( io_channel );
7.293 if (priv->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) ) {
7.294 g_printerr( "gmyth_file_transfer_read(): Called with no raw socket.\n" );
7.295 - return GMYTH_FILE_TRANSFER_READ_ERROR;
7.296 + return GMYTH_FILE_READ_ERROR;
7.297 }
7.298
7.299 if (priv->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) ) {
7.300 g_printerr( "gmyth_file_transfer_read(): Called with no control socket.\n" );
7.301 - return GMYTH_FILE_TRANSFER_READ_ERROR;
7.302 + return GMYTH_FILE_READ_ERROR;
7.303 }
7.304
7.305 query = g_string_new (GMYTHTV_QUERY_HEADER);
7.306 @@ -708,22 +696,24 @@
7.307 gmyth_debug ("Error on io_channel");
7.308 g_free (data_buffer);
7.309 g_object_unref (strlist);
7.310 - retval = GMYTH_FILE_TRANSFER_READ_ERROR;
7.311 + retval = GMYTH_FILE_READ_ERROR;
7.312 goto error;
7.313 }
7.314
7.315 /* append new data to the increasing byte array */
7.316 data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
7.317 - priv->offset += bytes_read;
7.318 + gmyth_file_set_offset( GMYTH_FILE(transfer),
7.319 + gmyth_file_get_offset( GMYTH_FILE(transfer) ) + bytes_read );
7.320
7.321 - if (!read_unlimited && (priv->filesize > 0) && (priv->offset == priv->filesize)) {
7.322 - retval = GMYTH_FILE_TRANSFER_READ_EOF;
7.323 + if ( !read_unlimited && ( gmyth_file_get_filesize( GMYTH_FILE(transfer) ) > 0 ) &&
7.324 + ( gmyth_file_get_offset( GMYTH_FILE(transfer) ) == gmyth_file_get_filesize( GMYTH_FILE(transfer) ) ) ) {
7.325 + retval = GMYTH_FILE_READ_EOF;
7.326 goto error;
7.327 }
7.328
7.329 g_free (data_buffer);
7.330 } else {
7.331 - retval = GMYTH_FILE_TRANSFER_READ_ERROR;
7.332 + retval = GMYTH_FILE_READ_ERROR;
7.333 }
7.334
7.335 if (strlist!=NULL)
7.336 @@ -744,11 +734,12 @@
7.337 if (priv->recorder != NULL &&
7.338 priv->do_next_program_chain)
7.339 {
7.340 - retval = GMYTH_FILE_TRANSFER_READ_NEXT_PROG_CHAIN;
7.341 + retval = GMYTH_FILE_READ_NEXT_PROG_CHAIN;
7.342 GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info (priv->recorder);
7.343
7.344 if (prog_info != NULL && prog_info->pathname != NULL && strlen( prog_info->pathname->str ) > 0 &&
7.345 - g_ascii_strcasecmp( prog_info->pathname->str, priv->filename ) != 0 )
7.346 + g_ascii_strcasecmp( prog_info->pathname->str,
7.347 + gmyth_file_get_file_name( GMYTH_FILE(transfer) ) ) != 0 )
7.348 ret = gmyth_file_transfer_open (transfer, g_strrstr( prog_info->pathname->str, "/" ) );
7.349
7.350 if (prog_info != NULL )
7.351 @@ -758,7 +749,7 @@
7.352 gmyth_debug( "Cannot change to the next program info!" );
7.353 else
7.354 gmyth_debug( "OK!!! MOVED to the next program info [%s]!",
7.355 - priv->filename );
7.356 + gmyth_file_get_file_name( GMYTH_FILE(transfer) ) );
7.357 }
7.358
7.359 } /* if */
7.360 @@ -775,12 +766,12 @@
7.361 }
7.362
7.363 if ( total_read > 0 )
7.364 - priv->offset += total_read;
7.365 + gmyth_file_set_offset( GMYTH_FILE(transfer),
7.366 + gmyth_file_get_offset( GMYTH_FILE(transfer) ) + total_read );
7.367
7.368 return retval;
7.369 }
7.370
7.371 -
7.372 static void
7.373 _file_transfer_program_info_changed( GMythFileTransfer *transfer,
7.374 gint msg_code, gpointer livetv_recorder )
7.375 @@ -864,10 +855,11 @@
7.376 guint64
7.377 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer)
7.378 {
7.379 - GMythFileTransferPrivate *priv;
7.380 + guint64 filesize;
7.381 +
7.382 + g_return_val_if_fail (transfer != NULL, 0);
7.383 +
7.384 + g_object_get( GMYTH_FILE(transfer), "filesize", &filesize, NULL );
7.385
7.386 - g_return_val_if_fail (transfer != NULL, 0);
7.387 -
7.388 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
7.389 - return priv->filesize;
7.390 + return filesize;
7.391 }
8.1 --- a/gmyth/src/gmyth_file_transfer.h Thu Apr 12 00:01:16 2007 +0100
8.2 +++ b/gmyth/src/gmyth_file_transfer.h Thu Apr 12 13:22:53 2007 +0100
8.3 @@ -32,6 +32,7 @@
8.4 #include <glib-object.h>
8.5 #include <glib.h>
8.6
8.7 +#include "gmyth_file.h"
8.8 #include "gmyth_socket.h"
8.9 #include "gmyth_uri.h"
8.10 #include "gmyth_backendinfo.h"
8.11 @@ -52,27 +53,18 @@
8.12 #define IS_GMYTH_FILE_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TRANSFER_TYPE))
8.13 #define GMYTH_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass))
8.14
8.15 -typedef enum {
8.16 - GMYTH_FILE_TRANSFER_READ_OK = 0,
8.17 - GMYTH_FILE_TRANSFER_READ_NEXT_PROG_CHAIN = 1,
8.18 - GMYTH_FILE_TRANSFER_READ_ERROR = 2,
8.19 - GMYTH_FILE_TRANSFER_READ_EOF = 3
8.20 -} GMythFileTransferReadResult;
8.21 -
8.22 -
8.23 typedef struct _GMythFileTransfer GMythFileTransfer;
8.24 typedef struct _GMythFileTransferClass GMythFileTransferClass;
8.25 typedef struct _GMythFileTransferPrivate GMythFileTransferPrivate;
8.26
8.27 struct _GMythFileTransfer
8.28 {
8.29 - GObject parent;
8.30 + GMythFile parent;
8.31 };
8.32
8.33 -
8.34 struct _GMythFileTransferClass
8.35 {
8.36 - GObjectClass parent_class;
8.37 + GMythFileClass parent_class;
8.38
8.39 /* callbacks */
8.40 guint program_info_changed_handler_signal_id;
8.41 @@ -90,7 +82,7 @@
8.42 const gchar* filename);
8.43 void gmyth_file_transfer_close (GMythFileTransfer *transfer);
8.44 gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer);
8.45 -GMythFileTransferReadResult
8.46 +GMythFileReadResult
8.47 gmyth_file_transfer_read (GMythFileTransfer *transfer,
8.48 GByteArray *data,
8.49 gint size,
9.1 --- a/gmyth/src/gmyth_recorder.c Thu Apr 12 00:01:16 2007 +0100
9.2 +++ b/gmyth/src/gmyth_recorder.c Thu Apr 12 13:22:53 2007 +0100
9.3 @@ -1210,5 +1210,5 @@
9.4 g_string_free (query, TRUE);
9.5
9.6 return fr;
9.7 +
9.8 }
9.9 -
10.1 --- a/gmyth/src/gmyth_remote_util.c Thu Apr 12 00:01:16 2007 +0100
10.2 +++ b/gmyth/src/gmyth_remote_util.c Thu Apr 12 13:22:53 2007 +0100
10.3 @@ -45,7 +45,7 @@
10.4 * @return the remote encoder instance available, or NULL if any error happens.
10.5 */
10.6 GMythRecorder*
10.7 -remote_request_next_free_recorder (GMythSocket *socket, int curr)
10.8 +remote_request_next_free_recorder (GMythSocket *socket, gint curr)
10.9 {
10.10 GMythRecorder *recorder = NULL;
10.11 GString *hostname;
11.1 --- a/gmyth/src/gmyth_remote_util.h Thu Apr 12 00:01:16 2007 +0100
11.2 +++ b/gmyth/src/gmyth_remote_util.h Thu Apr 12 13:22:53 2007 +0100
11.3 @@ -34,7 +34,7 @@
11.4
11.5 G_BEGIN_DECLS
11.6
11.7 -GMythRecorder* remote_request_next_free_recorder (GMythSocket *socket, int curr);
11.8 +GMythRecorder* remote_request_next_free_recorder (GMythSocket *socket, gint curr);
11.9 gint gmyth_remote_util_get_free_recorder_count (GMythSocket *socket);
11.10
11.11 G_END_DECLS
12.1 --- a/gmyth/src/gmyth_socket.c Thu Apr 12 00:01:16 2007 +0100
12.2 +++ b/gmyth/src/gmyth_socket.c Thu Apr 12 13:22:53 2007 +0100
12.3 @@ -151,7 +151,7 @@
12.4 }
12.5 */
12.6
12.7 -static const gchar *PATH_PROC_NET_DEV = "/proc/net/dev";
12.8 +const gchar *PATH_PROC_NET_DEV = "/proc/net/dev";
12.9
12.10 /** Gets the list of all local network interfaces (using the /proc/net/dev directory).
12.11 *
12.12 @@ -159,7 +159,7 @@
12.13 * to be applied just like a filter.
12.14 * @return List with all the local net interfaces.
12.15 */
12.16 -static GList *
12.17 +GList *
12.18 gmyth_socket_get_local_addrs( GList *current_connections )
12.19 {
12.20
12.21 @@ -208,14 +208,11 @@
12.22 return local_addrs;
12.23 }
12.24
12.25 -
12.26 -
12.27 /**
12.28 * Get only the local addresses from the primary interface
12.29 */
12.30 -/*
12.31 -static gchar *
12.32 -gmyth_socket_get_primary_addr()
12.33 +gchar *
12.34 +gmyth_socket_get_primary_addr(void)
12.35 {
12.36 gchar *if_eth0 = g_new0( gchar, sizeof(struct ifaddr)-1 );
12.37 GList *if_tmp = NULL;
12.38 @@ -237,7 +234,6 @@
12.39
12.40 return if_eth0;
12.41 }
12.42 -*/
12.43
12.44 /** This function retrieves the local hostname of the
12.45 * client machine.
12.46 @@ -245,7 +241,7 @@
12.47 * @return GString* get local hostname.
12.48 */
12.49 GString *
12.50 -gmyth_socket_get_local_hostname ()
12.51 +gmyth_socket_get_local_hostname (void)
12.52 {
12.53 char hname[50];
12.54 gint res = gethostname (hname, 50);
13.1 --- a/gmyth/src/gmyth_socket.h Thu Apr 12 00:01:16 2007 +0100
13.2 +++ b/gmyth/src/gmyth_socket.h Thu Apr 12 13:22:53 2007 +0100
13.3 @@ -110,7 +110,9 @@
13.4 const gchar *hostname_backend, gint port,
13.5 gboolean blocking_client);
13.6
13.7 -GString * gmyth_socket_get_local_hostname (void);
13.8 +gchar *gmyth_socket_get_primary_addr(void);
13.9 +
13.10 +GString *gmyth_socket_get_local_hostname (void);
13.11
13.12 void gmyth_socket_close_connection (GMythSocket *gmyth_socket);
13.13
14.1 --- a/gmyth/src/gmyth_uri.c Thu Apr 12 00:01:16 2007 +0100
14.2 +++ b/gmyth/src/gmyth_uri.c Thu Apr 12 13:22:53 2007 +0100
14.3 @@ -32,6 +32,7 @@
14.4 #endif
14.5
14.6 #include "gmyth_uri.h"
14.7 +#include "gmyth_socket.h"
14.8
14.9 #include <glib.h>
14.10 #include <string.h>
14.11 @@ -356,7 +357,7 @@
14.12 uri->path = g_string_new_len (value+currIdx, uriLen-currIdx );
14.13 }
14.14
14.15 - gmyth_debug( "uri value: %s", value );
14.16 + //gmyth_debug( "uri value: %s", value );
14.17 uri->query = g_string_new ( g_strstr_len( value, strlen(value), GMYTH_URI_QUESTION_DELIM ) );
14.18
14.19 eIdx = gmyth_strstr( value+currIdx, GMYTH_URI_QUESTION_DELIM );
14.20 @@ -373,6 +374,7 @@
14.21 uri->fragment = g_string_new_len (value+currIdx+sharpIdx+1, uriLen-(currIdx+sharpIdx+1));
14.22 }
14.23
14.24 + /*
14.25 gmyth_debug( "[%s] GMythURI: host = %s, port = %d, path = %s, query = %s, fragment = %s, "\
14.26 "user = %s, password = %s.\n", __FUNCTION__,
14.27 gmyth_uri_print_field( uri->host ), uri->port,
14.28 @@ -381,6 +383,7 @@
14.29 gmyth_uri_print_field( uri->fragment ),
14.30 gmyth_uri_print_field ( uri->user ),
14.31 gmyth_uri_print_field( uri->password ) );
14.32 + */
14.33
14.34 }
14.35
14.36 @@ -482,3 +485,37 @@
14.37 return -1;
14.38
14.39 }
14.40 +
14.41 +/**
14.42 + * Checks if the URI instance represents a reference to a local file.
14.43 + *
14.44 + * @param uri The GMythURI instance.
14.45 + *
14.46 + * @return <code>true</code>, if the URI points to a local file.
14.47 + */
14.48 +gboolean
14.49 +gmyth_uri_is_local_file( const GMythURI* uri )
14.50 +{
14.51 + gboolean ret = FALSE;
14.52 + gint len = -1;
14.53 +
14.54 + GString *hostname = gmyth_socket_get_local_hostname();
14.55 +
14.56 + g_return_val_if_fail( uri != NULL, FALSE );
14.57 +
14.58 + len = strlen( gmyth_uri_get_host(uri) );
14.59 +
14.60 + // gmyth_debug("URI: host = %s, hostname = %s.", uri->host->str, hostname != NULL ? hostname->str : "[no hostname]");
14.61 +
14.62 + ret = ( NULL != hostname && ( g_ascii_strncasecmp( uri->host->str,
14.63 + (hostname)->str, len ) == 0 ) /*||
14.64 + ( g_ascii_strncasecmp( gmyth_uri_get_host(uri), gmyth_socket_get_primary_addr(), len ) == 0 ) */ );
14.65 +
14.66 + if ( ret )
14.67 + gmyth_debug( "This URI is a local file..." );
14.68 + else
14.69 + gmyth_debug( "This URI is NOT a local file..." );
14.70 +
14.71 + return ret;
14.72 +
14.73 +}
15.1 --- a/gmyth/src/gmyth_uri.h Thu Apr 12 00:01:16 2007 +0100
15.2 +++ b/gmyth/src/gmyth_uri.h Thu Apr 12 13:22:53 2007 +0100
15.3 @@ -53,11 +53,11 @@
15.4 * Define
15.5 ****************************************/
15.6
15.7 -#define GMYTH_URI_KNKOWN_PORT (-1)
15.8 -#define GMYTH_URI_DEFAULT_HTTP_PORT 80
15.9 -#define GMYTH_URI_DEFAULT_FTP_PORT 21
15.10 +#define GMYTH_URI_KNKOWN_PORT (-1)
15.11 +#define GMYTH_URI_DEFAULT_HTTP_PORT 80
15.12 +#define GMYTH_URI_DEFAULT_FTP_PORT 21
15.13 #define GMYTH_URI_DEFAULT_PATH "/"
15.14 -#define GMYTH_URI_MAXLEN 256
15.15 +#define GMYTH_URI_MAXLEN 256
15.16
15.17 #define GMYTH_URI_PROTOCOL_DELIM "://"
15.18 #define GMYTH_URI_USER_DELIM "@"
15.19 @@ -105,20 +105,21 @@
15.20 GType gmyth_uri_get_type (void);
15.21 GMythURI* gmyth_uri_new (void);
15.22 GMythURI* gmyth_uri_new_with_value (const gchar *value);
15.23 -gboolean gmyth_uri_is_equals ( GMythURI* uri1, GMythURI* uri2 );
15.24 -gboolean gmyth_uri_is_livetv ( GMythURI* uri );
15.25 -gint gmyth_uri_get_channel_num( GMythURI* uri );
15.26 -gchar* gmyth_uri_get_channel_name( GMythURI* uri );
15.27 +gboolean gmyth_uri_is_equals ( GMythURI* uri1, GMythURI* uri2 );
15.28 +gboolean gmyth_uri_is_livetv ( GMythURI* uri );
15.29 +gint gmyth_uri_get_channel_num( GMythURI* uri );
15.30 +gchar* gmyth_uri_get_channel_name( GMythURI* uri );
15.31
15.32 +gboolean gmyth_uri_is_local_file( const GMythURI* uri );
15.33
15.34 -#define gmyth_uri_get_host(urip) ( urip->host != NULL ? urip->host->str : "" )
15.35 -#define gmyth_uri_get_port(urip) ( urip->port )
15.36 -#define gmyth_uri_get_protocol(urip) ( urip->protocol != NULL ? urip->protocol->str : "" )
15.37 -#define gmyth_uri_get_path(urip) ( urip->path != NULL ? urip->path->str : "" )
15.38 -#define gmyth_uri_get_user(urip) ( urip->user != NULL ? urip->user->str : "" )
15.39 +#define gmyth_uri_get_host(urip) ( urip->host != NULL ? urip->host->str : "" )
15.40 +#define gmyth_uri_get_port(urip) ( urip->port )
15.41 +#define gmyth_uri_get_protocol(urip) ( urip->protocol != NULL ? urip->protocol->str : "" )
15.42 +#define gmyth_uri_get_path(urip) ( urip->path != NULL ? urip->path->str : "" )
15.43 +#define gmyth_uri_get_user(urip) ( urip->user != NULL ? urip->user->str : "" )
15.44 #define gmyth_uri_get_password(urip) ( urip->password != NULL ? urip->password->str : "" )
15.45 -#define gmyth_uri_get_fragment(urip) ( urip->fragment != NULL ? urip->fragment->str : "" )
15.46 -#define gmyth_uri_get_query(urip) ( urip->query != NULL ? urip->query->str : "" )
15.47 +#define gmyth_uri_get_fragment(urip) ( urip->fragment != NULL ? urip->fragment->str : "" )
15.48 +#define gmyth_uri_get_query(urip) ( urip->query != NULL ? urip->query->str : "" )
15.49
15.50 G_END_DECLS
15.51
16.1 --- a/gmyth/src/gmyth_util.c Thu Apr 12 00:01:16 2007 +0100
16.2 +++ b/gmyth/src/gmyth_util.c Thu Apr 12 13:22:53 2007 +0100
16.3 @@ -541,7 +541,6 @@
16.4 return basename;
16.5 }
16.6
16.7 -
16.8 /**
16.9 * Gets the channel list.
16.10 *