[svn r584] Added samples/gmyth-cat. Currently working only remote files (not livetv) trunk
authormelunko
Fri Apr 20 03:58:43 2007 +0100 (2007-04-20)
branchtrunk
changeset 5793fe481998d73
parent 578 9e589622f097
child 580 7efc73147f5e
[svn r584] Added samples/gmyth-cat. Currently working only remote files (not livetv)
gmyth/Makefile.am
gmyth/configure.ac
gmyth/samples/Makefile.am
gmyth/samples/gmyth_cat.c
     1.1 --- a/gmyth/Makefile.am	Thu Apr 19 23:03:58 2007 +0100
     1.2 +++ b/gmyth/Makefile.am	Fri Apr 20 03:58:43 2007 +0100
     1.3 @@ -1,4 +1,4 @@
     1.4 -SUBDIRS= src tests
     1.5 +SUBDIRS= src samples tests
     1.6  
     1.7  ### all of the standard pc files we need to generate
     1.8  #pcfiles = gmyth-@GMYTH_MAJORMINOR@.pc
     2.1 --- a/gmyth/configure.ac	Thu Apr 19 23:03:58 2007 +0100
     2.2 +++ b/gmyth/configure.ac	Fri Apr 20 03:58:43 2007 +0100
     2.3 @@ -189,6 +189,7 @@
     2.4  AC_OUTPUT([
     2.5  Makefile
     2.6  src/Makefile
     2.7 +samples/Makefile
     2.8  tests/Makefile
     2.9  gmyth.pc])
    2.10  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gmyth/samples/Makefile.am	Fri Apr 20 03:58:43 2007 +0100
     3.3 @@ -0,0 +1,17 @@
     3.4 +bin_PROGRAMS = gmyth-cat
     3.5 +
     3.6 +gmyth_cat_SOURCES = \
     3.7 +        gmyth_cat.c
     3.8 +
     3.9 +LDADD = \
    3.10 +        $(top_builddir)/src/.libs/libgmyth.la
    3.11 +
    3.12 +LDFLAGS = \
    3.13 +        @GLIB_LIBS@ @GOBJECT_LIBS@ @GTHREAD_LIBS@ @LIBCURL_LIBS@
    3.14 +
    3.15 +INCLUDES = \
    3.16 +        -I$(top_srcdir) \
    3.17 +        -I$(top_srcdir)/src \
    3.18 +        $(GLIB_CFLAGS) \
    3.19 +        $(GOBJECT_CFLAGS)
    3.20 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/gmyth/samples/gmyth_cat.c	Fri Apr 20 03:58:43 2007 +0100
     4.3 @@ -0,0 +1,100 @@
     4.4 +
     4.5 +#include <stdio.h>
     4.6 +#include <glib.h> 
     4.7 +
     4.8 +#include <gmyth.h>
     4.9 +
    4.10 +static gboolean
    4.11 +_parse_args (int argc, char *argv[], GMythBackendInfo *b_info, char** filename)
    4.12 +{
    4.13 +    GError *error = NULL;
    4.14 +    GOptionContext *context;
    4.15 +
    4.16 +    gchar *host_ip = NULL;
    4.17 +    gint host_port = 0;
    4.18 +
    4.19 +    GOptionEntry entries[] = 
    4.20 +    {
    4.21 +        { "hostname", 'h', 0, G_OPTION_ARG_STRING, &host_ip, "Mythtv backend hostname or IP address", "IP_ADDRESS" },
    4.22 +        { "port", 'p', 0, G_OPTION_ARG_INT, &host_port, "Mythtv backend port", "PORT" },
    4.23 +        { "filename", 'f', 0, G_OPTION_ARG_STRING, filename, "Recorded file name available in the Mythtv backend", "FILE" },
    4.24 +        { NULL }
    4.25 +    };
    4.26 +
    4.27 +    context = g_option_context_new ("- loads a mythtv backend recorded file and prints it on the standard output\n");
    4.28 +    g_option_context_add_main_entries (context, entries, NULL);
    4.29 +    g_option_context_parse (context, &argc, &argv, &error);
    4.30 +    g_option_context_set_help_enabled (context, TRUE);
    4.31 +
    4.32 +    g_option_context_free (context);
    4.33 +    
    4.34 +    gmyth_backend_info_set_hostname (b_info, host_ip);
    4.35 +    gmyth_backend_info_set_port (b_info, host_port);
    4.36 +
    4.37 +    g_free (host_ip);
    4.38 +
    4.39 +    return TRUE;
    4.40 +}
    4.41 +
    4.42 +int 
    4.43 +main (int argc, char *argv[])
    4.44 +{
    4.45 +    gboolean res = FALSE;
    4.46 +    gchar *filename = NULL;
    4.47 +    GMythBackendInfo *b_info;
    4.48 +    GByteArray *array = NULL;
    4.49 +    GMythFileTransfer *transfer;
    4.50 +    guint64 size = 0, total = 0;
    4.51 +
    4.52 +    g_type_init ();
    4.53 +    g_thread_init (NULL);
    4.54 +    
    4.55 +    b_info = gmyth_backend_info_new ();
    4.56 +
    4.57 +    res = _parse_args (argc, argv, b_info, &filename);
    4.58 +    if (!res) {
    4.59 +        g_printerr ("Argument invalid. Type --help\n");
    4.60 +        return 1;
    4.61 +    }
    4.62 +
    4.63 +    if (!gmyth_util_file_exists (b_info, filename)) {
    4.64 +        g_printerr ("File %s was not found in the mythtv server\n", filename);
    4.65 +        return 1;
    4.66 +    }
    4.67 +
    4.68 +    transfer = gmyth_file_transfer_new (b_info);
    4.69 +    if (!gmyth_file_transfer_open (transfer, filename)) {
    4.70 +        g_printerr ("File %s could not be opened\n", filename);
    4.71 +        return 1;
    4.72 +    }
    4.73 +
    4.74 +    size = gmyth_file_transfer_get_filesize (transfer);
    4.75 +    while (total != size) {
    4.76 +        GMythFileReadResult res;
    4.77 +
    4.78 +        array = g_byte_array_new ();
    4.79 +        res = gmyth_file_transfer_read (transfer, array, 
    4.80 +                                       (size - total) > 64000 ? 64000 : (size - total),
    4.81 +                                       FALSE);
    4.82 +        if ((res != GMYTH_FILE_READ_OK) && (res != GMYTH_FILE_READ_EOF)) {
    4.83 +           g_byte_array_free (array, TRUE);
    4.84 +           g_printerr ("Error while reading the file: aborting!!\n");
    4.85 +           break;
    4.86 +        }
    4.87 +
    4.88 +        fwrite (array->data, array->len, 1, stdout);
    4.89 +        fflush (stdout);
    4.90 +
    4.91 +        total += array->len;
    4.92 +        g_byte_array_free (array, TRUE);
    4.93 +    }
    4.94 +    
    4.95 +    g_free (filename);
    4.96 +
    4.97 +    gmyth_file_transfer_close (transfer);
    4.98 +    g_object_unref (transfer);
    4.99 +
   4.100 +    g_object_unref (b_info);
   4.101 +
   4.102 +    return 0;
   4.103 +}