# HG changeset patch
# User rosfran
# Date 1176128355 -3600
# Node ID 5f15d749c024f58011d6a5d842a628ac8ab73466
# Parent 16312d0021cb6f7a6c2a57941174c17065b14182
[svn r517] Newly added GMythFile, a parent GObject to the GMythFileLocal and GMythFileTransfer.
diff -r 16312d0021cb -r 5f15d749c024 gmyth/src/gmyth_file.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth/src/gmyth_file.c Mon Apr 09 15:19:15 2007 +0100
@@ -0,0 +1,313 @@
+/**
+ * GMyth Library
+ *
+ * @file gmyth/gmyth_file.c
+ *
+ * @brief
GMythFile deals with the file streaming media remote/local
+ * transfering to the MythTV frontend.
+ *
+ * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
+ * @author Rosfran Lins Borges
+ *
+ *//*
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gmyth_file.h"
+#include "gmyth_recorder.h"
+#include "gmyth_util.h"
+#include "gmyth_socket.h"
+#include "gmyth_stringlist.h"
+#include "gmyth_debug.h"
+#include "gmyth_uri.h"
+#include "gmyth_marshal.h"
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define GMYTH_FILE_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TYPE, GMythFilePrivate))
+
+struct _GMythFilePrivate {
+ gboolean disposed;
+ gint64 offset;
+ guint64 filesize;
+
+ GMythBackendInfo *backend_info;
+
+ /* Myth URI structure */
+ gchar *filename;
+
+ gint file_id;
+};
+
+static void gmyth_file_class_init (GMythFileClass *klass);
+static void gmyth_file_init (GMythFile *object);
+static void gmyth_file_dispose (GObject *object);
+static void gmyth_file_finalize (GObject *object);
+
+G_DEFINE_TYPE(GMythFile, gmyth_file, GMYTH_FILE_TYPE)
+
+static void
+gmyth_file_class_init (GMythFileClass *klass)
+{
+ GObjectClass *gobject_class;
+ GMythFileClass *gtransfer_class;
+
+ gobject_class = (GObjectClass *) klass;
+ gtransfer_class = (GMythFileClass *) gobject_class;
+
+ gobject_class->dispose = gmyth_file_dispose;
+ gobject_class->finalize = gmyth_file_finalize;
+
+ g_type_class_add_private (gobject_class, sizeof (GMythFilePrivate));
+
+}
+
+static void
+gmyth_file_init (GMythFile *file)
+{
+ GMythFilePrivate *priv;
+ g_return_if_fail( file != NULL );
+
+ priv = GMYTH_FILE_GET_PRIVATE(file);
+}
+
+static void
+gmyth_file_dispose (GObject *object)
+{
+ GMythFilePrivate *priv;
+ GMythFile *file = GMYTH_FILE (object);
+
+ g_return_if_fail( file != NULL );
+
+ priv = GMYTH_FILE_GET_PRIVATE(file);
+
+ if (priv->disposed) {
+ /* If dispose did already run, return. */
+ return;
+ }
+
+ /* Make sure dispose does not run twice. */
+ priv->disposed = TRUE;
+
+ if (priv->backend_info != NULL ) {
+ g_object_unref (priv->backend_info );
+ priv->backend_info = NULL;
+ }
+
+ if (priv->filename != NULL ) {
+ g_free (priv->filename );
+ priv->filename = NULL;
+ }
+
+ G_OBJECT_CLASS (gmyth_file_parent_class)->dispose (object);
+}
+
+static void
+gmyth_file_finalize (GObject *object)
+{
+ g_signal_handlers_destroy (object);
+
+ G_OBJECT_CLASS (gmyth_file_parent_class)->finalize (object);
+}
+
+/**
+ * Creates a new instance of GMythFile.
+ *
+ * @param backend_info The BackendInfo instance, with all the MythTV network
+ * configuration data.
+ *
+ * @return a new instance of the File Transfer.
+ */
+GMythFile*
+gmyth_file_new (GMythBackendInfo *backend_info)
+{
+ GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL));
+ GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
+
+ priv->backend_info = g_object_ref (backend_info);
+
+ return file;
+}
+
+gchar*
+gmyth_file_get_file_name (GMythFile *file)
+{
+ GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
+
+ return g_strdup (priv->filename);
+}
+
+void
+gmyth_file_set_file_name (GMythFile *file, const gchar* filename)
+{
+ GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
+
+ return priv->filename = g_strdup (filename);
+}
+
+/**
+ * Creates a new instance of GMythFile.
+ *
+ * @param uri_str The URI poiting to the MythTV backend server.
+ *
+ * @return a new instance of the File Transfer.
+ */
+GMythFile*
+gmyth_file_new_with_uri (const gchar* uri_str)
+{
+ GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL));
+ GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
+
+ priv->backend_info = gmyth_backend_info_new_with_uri (uri_str);
+ return file;
+}
+
+/**
+ * Open a File Transfer connection in order to get a remote file.
+ *
+ * @param file The actual File Transfer instance.
+ * @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.
+ */
+gboolean
+gmyth_file_setup (GMythFile *file, const gchar* filename)
+{
+ gboolean ret = TRUE;
+ GMythFilePrivate *priv;
+
+ g_return_val_if_fail (file != NULL, FALSE);
+ g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE);
+
+ priv = GMYTH_FILE_GET_PRIVATE (file);
+
+ if (priv->filename != NULL)
+ {
+ gmyth_file_close (file);
+ }
+
+ priv->filename = g_strdup( filename );
+
+ return ret;
+}
+
+/**
+ * Closes a remote File Transfer connection.
+ *
+ * @param file The actual File Transfer instance.
+ */
+void
+gmyth_file_close (GMythFile *file )
+{
+ GMythFilePrivate *priv;
+
+ g_return_if_fail (file != NULL);
+
+ priv = GMYTH_FILE_GET_PRIVATE (file);
+
+ if (priv->filename) {
+ g_free (priv->filename);
+ priv->filename = NULL;
+ }
+
+}
+
+/**
+ * Gets the actual file size of the binary content.
+ *
+ * @param file The actual File Transfer instance.
+ *
+ * @return The actual file size in bytes.
+ */
+guint64
+gmyth_file_get_filesize (GMythFile *file)
+{
+ GMythFilePrivate *priv;
+
+ g_return_val_if_fail (file != NULL, 0);
+
+ priv = GMYTH_FILE_GET_PRIVATE (file);
+ return priv->filesize;
+}
+
+/**
+ * Sets the actual file size.
+ *
+ * @param file The actual File Transfer instance.
+ * @param filesize The actual File Transfer size, in bytes.
+ */
+void
+gmyth_file_set_filesize (GMythFile *file, guint64 filesize)
+{
+ GMythFilePrivate *priv;
+
+ g_return_val_if_fail (file != NULL, 0);
+
+ priv = GMYTH_FILE_GET_PRIVATE (file);
+
+ priv->filesize = filesize;
+}
+
+/**
+ * Gets the actual offset of the binary content.
+ *
+ * @param file The actual File Transfer instance.
+ *
+ * @return The actual file offset in bytes.
+ */
+gint64
+gmyth_file_get_offset (GMythFile *file)
+{
+ GMythFilePrivate *priv;
+
+ g_return_val_if_fail (file != NULL, 0);
+
+ priv = GMYTH_FILE_GET_PRIVATE (file);
+ return priv->offset;
+}
+
+/**
+ * Sets the actual file offset.
+ *
+ * @param file The actual File instance.
+ * @param filesize The actual File offset, in bytes.
+ */
+void
+gmyth_file_set_offset (GMythFile *file, gint64 offset)
+{
+ GMythFilePrivate *priv;
+
+ g_return_val_if_fail (file != NULL, 0);
+
+ priv = GMYTH_FILE_GET_PRIVATE (file);
+
+ priv->offset = offset;
+}
+
diff -r 16312d0021cb -r 5f15d749c024 gmyth/src/gmyth_file.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth/src/gmyth_file.h Mon Apr 09 15:19:15 2007 +0100
@@ -0,0 +1,92 @@
+/**
+ * GMyth Library
+ *
+ * @file gmyth/gmyth_file.h
+ *
+ * @brief GMythFile is the parent GMObject that deals with the file streaming
+ * media remote/local transfering to the MythTV frontend.
+ *
+ * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
+ * @author Rosfran Lins Borges
+ *
+ *//*
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __GMYTH_FILE_H__
+#define __GMYTH_FILE_H__
+
+#include
+#include
+
+#include "gmyth_uri.h"
+#include "gmyth_backendinfo.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+G_BEGIN_DECLS
+
+#define GMYTH_FILE_TYPE (gmyth_file_get_type ())
+#define GMYTH_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_FILE_TYPE, GMythFile))
+#define GMYTH_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TYPE, GMythFileClass))
+#define IS_GMYTH_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_FILE_TYPE))
+#define IS_GMYTH_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TYPE))
+#define GMYTH_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TYPE, GMythFileClass))
+
+typedef enum {
+ GMYTH_FILE_READ_OK = 0,
+ GMYTH_FILE_READ_NEXT_PROG_CHAIN = 1,
+ GMYTH_FILE_READ_ERROR = 2,
+ GMYTH_FILE_READ_EOF = 3
+} GMythFileReadResult;
+
+typedef struct _GMythFile GMythFile;
+typedef struct _GMythFileClass GMythFileClass;
+typedef struct _GMythFilePrivate GMythFilePrivate;
+
+struct _GMythFile
+{
+ GObject parent;
+};
+
+struct _GMythFileClass
+{
+ GObjectClass parent_class;
+};
+
+GType gmyth_file_get_type (void);
+GMythFile* gmyth_file_new (GMythBackendInfo *backend_info);
+gchar* gmyth_file_get_file_name (GMythFile *file);
+void gmyth_file_set_file_name (GMythFile *file, const gchar* filename);
+gboolean gmyth_file_setup (GMythFile *file,
+ const gchar* filename);
+void gmyth_file_close (GMythFile *file);
+gboolean gmyth_file_is_open (GMythFile *file);
+
+guint64 gmyth_file_get_filesize (GMythFile *file);
+void gmyth_file_set_filesize (GMythFile *file, guint64 filesize);
+
+gint64 gmyth_file_get_offset (GMythFile *file);
+void gmyth_file_set_offset (GMythFile *file, gint64 offset);
+
+G_END_DECLS
+
+#endif /* __GMYTH_FILE_H__ */