[svn r517] Newly added GMythFile, a parent GObject to the GMythFileLocal and GMythFileTransfer. trunk
authorrosfran
Mon Apr 09 15:19:15 2007 +0100 (2007-04-09)
branchtrunk
changeset 5125f15d749c024
parent 511 16312d0021cb
child 513 12a61040588d
[svn r517] Newly added GMythFile, a parent GObject to the GMythFileLocal and GMythFileTransfer.
gmyth/src/gmyth_file.c
gmyth/src/gmyth_file.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth/src/gmyth_file.c	Mon Apr 09 15:19:15 2007 +0100
     1.3 @@ -0,0 +1,313 @@
     1.4 +/**
     1.5 + * GMyth Library
     1.6 + *
     1.7 + * @file gmyth/gmyth_file.c
     1.8 + * 
     1.9 + * @brief <p> GMythFile deals with the file streaming media remote/local
    1.10 + * transfering to the MythTV frontend.
    1.11 + *
    1.12 + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    1.13 + * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
    1.14 + *
    1.15 + *//*
    1.16 + * 
    1.17 + * This program is free software; you can redistribute it and/or modify
    1.18 + * it under the terms of the GNU Lesser General Public License as published by
    1.19 + * the Free Software Foundation; either version 2 of the License, or
    1.20 + * (at your option) any later version.
    1.21 + *
    1.22 + * This program is distributed in the hope that it will be useful,
    1.23 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.24 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.25 + * GNU General Public License for more details.
    1.26 + *
    1.27 + * You should have received a copy of the GNU Lesser General Public License
    1.28 + * along with this program; if not, write to the Free Software
    1.29 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.30 + */
    1.31 + 
    1.32 +#ifdef HAVE_CONFIG_H
    1.33 +#include "config.h"
    1.34 +#endif
    1.35 +
    1.36 +#include "gmyth_file.h"
    1.37 +#include "gmyth_recorder.h"
    1.38 +#include "gmyth_util.h"
    1.39 +#include "gmyth_socket.h"
    1.40 +#include "gmyth_stringlist.h"
    1.41 +#include "gmyth_debug.h"
    1.42 +#include "gmyth_uri.h"
    1.43 +#include "gmyth_marshal.h"
    1.44 +
    1.45 +#include <unistd.h>
    1.46 +#include <glib.h>
    1.47 +
    1.48 +#include <arpa/inet.h>
    1.49 +#include <sys/types.h>
    1.50 +#include <sys/socket.h>
    1.51 +#include <netdb.h>
    1.52 +#include <errno.h>
    1.53 +#include <stdlib.h>
    1.54 +#include <assert.h>
    1.55 +
    1.56 +#define GMYTH_FILE_GET_PRIVATE(obj) \
    1.57 +    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TYPE, GMythFilePrivate))
    1.58 +
    1.59 +struct _GMythFilePrivate {
    1.60 +	gboolean disposed;
    1.61 +    gint64 offset;
    1.62 +    guint64 filesize;
    1.63 +    
    1.64 +    GMythBackendInfo        *backend_info;
    1.65 +
    1.66 +	/* Myth URI structure */
    1.67 +	gchar                   *filename;
    1.68 +
    1.69 +	gint 					file_id;
    1.70 +};
    1.71 +
    1.72 +static void gmyth_file_class_init          (GMythFileClass *klass);
    1.73 +static void gmyth_file_init                (GMythFile *object);
    1.74 +static void gmyth_file_dispose             (GObject *object);
    1.75 +static void gmyth_file_finalize            (GObject *object);
    1.76 +
    1.77 +G_DEFINE_TYPE(GMythFile, gmyth_file, GMYTH_FILE_TYPE)
    1.78 +
    1.79 +static void
    1.80 +gmyth_file_class_init (GMythFileClass *klass)
    1.81 +{
    1.82 +    GObjectClass *gobject_class;
    1.83 +    GMythFileClass *gtransfer_class;
    1.84 +
    1.85 +    gobject_class = (GObjectClass *) klass;
    1.86 +    gtransfer_class = (GMythFileClass *) gobject_class;
    1.87 +
    1.88 +    gobject_class->dispose  = gmyth_file_dispose;
    1.89 +    gobject_class->finalize = gmyth_file_finalize;
    1.90 +  
    1.91 +    g_type_class_add_private (gobject_class, sizeof (GMythFilePrivate));
    1.92 +
    1.93 +}
    1.94 +
    1.95 +static void
    1.96 +gmyth_file_init (GMythFile *file)
    1.97 +{ 
    1.98 +    GMythFilePrivate *priv;
    1.99 +    g_return_if_fail( file != NULL );
   1.100 +
   1.101 +    priv = GMYTH_FILE_GET_PRIVATE(file);	
   1.102 +}
   1.103 +
   1.104 +static void
   1.105 +gmyth_file_dispose  (GObject *object)
   1.106 +{	
   1.107 +    GMythFilePrivate *priv;
   1.108 +	GMythFile *file = GMYTH_FILE (object);
   1.109 +
   1.110 +    g_return_if_fail( file != NULL );
   1.111 +
   1.112 +    priv = GMYTH_FILE_GET_PRIVATE(file);	
   1.113 +
   1.114 +    if (priv->disposed) {
   1.115 +        /* If dispose did already run, return. */
   1.116 +        return;
   1.117 +    }
   1.118 +    
   1.119 +    /* Make sure dispose does not run twice. */
   1.120 +    priv->disposed = TRUE;
   1.121 +    
   1.122 +    if (priv->backend_info != NULL ) {
   1.123 +        g_object_unref (priv->backend_info );
   1.124 +        priv->backend_info = NULL;
   1.125 +    }
   1.126 +
   1.127 +    if (priv->filename != NULL ) {
   1.128 +        g_free (priv->filename );
   1.129 +        priv->filename = NULL;
   1.130 +    }
   1.131 +
   1.132 +    G_OBJECT_CLASS (gmyth_file_parent_class)->dispose (object);
   1.133 +}
   1.134 +
   1.135 +static void
   1.136 +gmyth_file_finalize (GObject *object)
   1.137 +{
   1.138 +  g_signal_handlers_destroy (object);
   1.139 +
   1.140 +  G_OBJECT_CLASS (gmyth_file_parent_class)->finalize (object);
   1.141 +}
   1.142 +
   1.143 +/** 
   1.144 + * Creates a new instance of GMythFile.
   1.145 + * 
   1.146 + * @param backend_info The BackendInfo instance, with all the MythTV network 
   1.147 + * 										 configuration data.
   1.148 + * 
   1.149 + * @return a new instance of the File Transfer. 
   1.150 + */
   1.151 +GMythFile*
   1.152 +gmyth_file_new (GMythBackendInfo *backend_info)
   1.153 +{
   1.154 +  GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL));
   1.155 +  GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
   1.156 +  
   1.157 +  priv->backend_info = g_object_ref (backend_info);
   1.158 +  
   1.159 +  return file;
   1.160 +}
   1.161 +
   1.162 +gchar*
   1.163 +gmyth_file_get_file_name (GMythFile *file)
   1.164 +{
   1.165 +    GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
   1.166 +
   1.167 +    return g_strdup (priv->filename);
   1.168 +}
   1.169 +
   1.170 +void
   1.171 +gmyth_file_set_file_name (GMythFile *file, const gchar* filename)
   1.172 +{
   1.173 +    GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
   1.174 +
   1.175 +    return priv->filename = g_strdup (filename);
   1.176 +}
   1.177 +
   1.178 +/** 
   1.179 + * Creates a new instance of GMythFile.
   1.180 + * 
   1.181 + * @param uri_str The URI poiting to the MythTV backend server.
   1.182 + * 
   1.183 + * @return a new instance of the File Transfer. 
   1.184 + */
   1.185 +GMythFile* 
   1.186 +gmyth_file_new_with_uri (const gchar* uri_str)
   1.187 +{
   1.188 +  GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL));
   1.189 +  GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
   1.190 +
   1.191 +  priv->backend_info = gmyth_backend_info_new_with_uri (uri_str);
   1.192 +  return file;
   1.193 +}
   1.194 +
   1.195 +/** 
   1.196 + * Open a File Transfer connection in order to get a remote file.
   1.197 + * 
   1.198 + * @param file The actual File Transfer instance. 
   1.199 + * @param filename The file name of the remote file to be transfered to the client.
   1.200 + * 
   1.201 + * @return <code>true</code>, if the connection opening had been done successfully. 
   1.202 + */
   1.203 +gboolean
   1.204 +gmyth_file_setup (GMythFile *file, const gchar* filename)
   1.205 +{
   1.206 +    gboolean ret = TRUE;
   1.207 +    GMythFilePrivate *priv;
   1.208 +  
   1.209 +    g_return_val_if_fail (file != NULL, FALSE);
   1.210 +    g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE);
   1.211 +
   1.212 +    priv = GMYTH_FILE_GET_PRIVATE (file);
   1.213 +
   1.214 +    if (priv->filename != NULL)
   1.215 +    {
   1.216 +        gmyth_file_close (file);
   1.217 +    }
   1.218 +
   1.219 +    priv->filename = g_strdup( filename );
   1.220 +
   1.221 +    return ret;
   1.222 +}
   1.223 +
   1.224 +/** 
   1.225 + * Closes a remote File Transfer connection.
   1.226 + * 
   1.227 + * @param file The actual File Transfer instance. 
   1.228 + */
   1.229 +void
   1.230 +gmyth_file_close (GMythFile *file )
   1.231 +{
   1.232 +    GMythFilePrivate *priv;
   1.233 +
   1.234 +    g_return_if_fail (file != NULL);
   1.235 +
   1.236 +    priv = GMYTH_FILE_GET_PRIVATE (file);
   1.237 +
   1.238 +    if (priv->filename) {
   1.239 +        g_free (priv->filename);
   1.240 +        priv->filename = NULL;
   1.241 +    }
   1.242 +
   1.243 +}
   1.244 +
   1.245 +/** 
   1.246 + * Gets the actual file size of the binary content.
   1.247 + * 
   1.248 + * @param file The actual File Transfer instance.
   1.249 + * 
   1.250 + * @return The actual file size in bytes. 
   1.251 + */
   1.252 +guint64
   1.253 +gmyth_file_get_filesize (GMythFile *file)
   1.254 +{
   1.255 +    GMythFilePrivate *priv;
   1.256 +
   1.257 +    g_return_val_if_fail (file != NULL, 0);
   1.258 +
   1.259 +    priv = GMYTH_FILE_GET_PRIVATE (file);
   1.260 +    return priv->filesize;
   1.261 +}
   1.262 +
   1.263 +/** 
   1.264 + * Sets the actual file size.
   1.265 + * 
   1.266 + * @param file The actual File Transfer instance.
   1.267 + * @param filesize The actual File Transfer size, in bytes.
   1.268 + */
   1.269 +void
   1.270 +gmyth_file_set_filesize (GMythFile *file, guint64 filesize)
   1.271 +{
   1.272 +    GMythFilePrivate *priv;
   1.273 +
   1.274 +    g_return_val_if_fail (file != NULL, 0);
   1.275 +
   1.276 +    priv = GMYTH_FILE_GET_PRIVATE (file);
   1.277 +    
   1.278 +    priv->filesize = filesize;
   1.279 +}
   1.280 +
   1.281 +/** 
   1.282 + * Gets the actual offset of the binary content.
   1.283 + * 
   1.284 + * @param file The actual File Transfer instance.
   1.285 + * 
   1.286 + * @return The actual file offset in bytes. 
   1.287 + */
   1.288 +gint64
   1.289 +gmyth_file_get_offset (GMythFile *file)
   1.290 +{
   1.291 +    GMythFilePrivate *priv;
   1.292 +
   1.293 +    g_return_val_if_fail (file != NULL, 0);
   1.294 +
   1.295 +    priv = GMYTH_FILE_GET_PRIVATE (file);
   1.296 +    return priv->offset;
   1.297 +}
   1.298 +
   1.299 +/**
   1.300 + * Sets the actual file offset.
   1.301 + * 
   1.302 + * @param file The actual File instance.
   1.303 + * @param filesize The actual File offset, in bytes.
   1.304 + */
   1.305 +void
   1.306 +gmyth_file_set_offset (GMythFile *file, gint64 offset)
   1.307 +{
   1.308 +    GMythFilePrivate *priv;
   1.309 +
   1.310 +    g_return_val_if_fail (file != NULL, 0);
   1.311 +
   1.312 +    priv = GMYTH_FILE_GET_PRIVATE (file);
   1.313 +    
   1.314 +    priv->offset = offset;
   1.315 +}
   1.316 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gmyth/src/gmyth_file.h	Mon Apr 09 15:19:15 2007 +0100
     2.3 @@ -0,0 +1,92 @@
     2.4 +/**
     2.5 + * GMyth Library
     2.6 + *
     2.7 + * @file gmyth/gmyth_file.h
     2.8 + * 
     2.9 + * @brief <p> GMythFile is the parent GMObject that deals with the file streaming 
    2.10 + * media remote/local transfering to the MythTV frontend.
    2.11 + *
    2.12 + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    2.13 + * @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
    2.14 + *
    2.15 + *//*
    2.16 + * 
    2.17 + * This program is free software; you can redistribute it and/or modify
    2.18 + * it under the terms of the GNU Lesser General Public License as published by
    2.19 + * the Free Software Foundation; either version 2 of the License, or
    2.20 + * (at your option) any later version.
    2.21 + *
    2.22 + * This program is distributed in the hope that it will be useful,
    2.23 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.24 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.25 + * GNU General Public License for more details.
    2.26 + *
    2.27 + * You should have received a copy of the GNU Lesser General Public License
    2.28 + * along with this program; if not, write to the Free Software
    2.29 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.30 + */
    2.31 + 
    2.32 +#ifndef __GMYTH_FILE_H__
    2.33 +#define __GMYTH_FILE_H__
    2.34 +
    2.35 +#include <glib-object.h>
    2.36 +#include <glib.h>
    2.37 +
    2.38 +#include "gmyth_uri.h"
    2.39 +#include "gmyth_backendinfo.h"
    2.40 +
    2.41 +#include <stdio.h>
    2.42 +#include <stdlib.h>
    2.43 +#include <string.h>
    2.44 +#include <netdb.h>
    2.45 +#include <sys/socket.h>
    2.46 +#include <unistd.h>
    2.47 +
    2.48 +G_BEGIN_DECLS
    2.49 +
    2.50 +#define GMYTH_FILE_TYPE               (gmyth_file_get_type ())
    2.51 +#define GMYTH_FILE(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_FILE_TYPE, GMythFile))
    2.52 +#define GMYTH_FILE_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TYPE, GMythFileClass))
    2.53 +#define IS_GMYTH_FILE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_FILE_TYPE))
    2.54 +#define IS_GMYTH_FILE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TYPE))
    2.55 +#define GMYTH_FILE_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TYPE, GMythFileClass))
    2.56 +
    2.57 +typedef enum {
    2.58 +    GMYTH_FILE_READ_OK                 = 0,
    2.59 +    GMYTH_FILE_READ_NEXT_PROG_CHAIN    = 1,
    2.60 +    GMYTH_FILE_READ_ERROR              = 2,
    2.61 +    GMYTH_FILE_READ_EOF                = 3
    2.62 +} GMythFileReadResult;
    2.63 +
    2.64 +typedef struct _GMythFile         GMythFile;
    2.65 +typedef struct _GMythFileClass    GMythFileClass;
    2.66 +typedef struct _GMythFilePrivate  GMythFilePrivate;
    2.67 +
    2.68 +struct _GMythFile
    2.69 +{
    2.70 +	GObject 				parent;
    2.71 +};
    2.72 +
    2.73 +struct _GMythFileClass
    2.74 +{
    2.75 +	GObjectClass           parent_class;
    2.76 +};
    2.77 +
    2.78 +GType               gmyth_file_get_type         (void);
    2.79 +GMythFile*          gmyth_file_new              (GMythBackendInfo *backend_info);
    2.80 +gchar*              gmyth_file_get_file_name    (GMythFile *file);
    2.81 +void                gmyth_file_set_file_name    (GMythFile *file, const gchar* filename);
    2.82 +gboolean            gmyth_file_setup            (GMythFile *file, 
    2.83 +                                				    const gchar* filename);
    2.84 +void                gmyth_file_close            (GMythFile *file);
    2.85 +gboolean            gmyth_file_is_open          (GMythFile *file);
    2.86 +
    2.87 +guint64             gmyth_file_get_filesize     (GMythFile *file);
    2.88 +void                gmyth_file_set_filesize     (GMythFile *file, guint64 filesize);
    2.89 +
    2.90 +gint64              gmyth_file_get_offset       (GMythFile *file);
    2.91 +void                gmyth_file_set_offset       (GMythFile *file, gint64 offset);
    2.92 +
    2.93 +G_END_DECLS
    2.94 +
    2.95 +#endif /* __GMYTH_FILE_H__ */