# HG changeset patch # User melunko # Date 1177037923 -3600 # Node ID 3fe481998d738120cec51c2205aec176a7cc34db # Parent 9e589622f097edb385c028094db3172d7b06cf30 [svn r584] Added samples/gmyth-cat. Currently working only remote files (not livetv) diff -r 9e589622f097 -r 3fe481998d73 gmyth/Makefile.am --- a/gmyth/Makefile.am Thu Apr 19 23:03:58 2007 +0100 +++ b/gmyth/Makefile.am Fri Apr 20 03:58:43 2007 +0100 @@ -1,4 +1,4 @@ -SUBDIRS= src tests +SUBDIRS= src samples tests ### all of the standard pc files we need to generate #pcfiles = gmyth-@GMYTH_MAJORMINOR@.pc diff -r 9e589622f097 -r 3fe481998d73 gmyth/configure.ac --- a/gmyth/configure.ac Thu Apr 19 23:03:58 2007 +0100 +++ b/gmyth/configure.ac Fri Apr 20 03:58:43 2007 +0100 @@ -189,6 +189,7 @@ AC_OUTPUT([ Makefile src/Makefile +samples/Makefile tests/Makefile gmyth.pc]) diff -r 9e589622f097 -r 3fe481998d73 gmyth/samples/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/samples/Makefile.am Fri Apr 20 03:58:43 2007 +0100 @@ -0,0 +1,17 @@ +bin_PROGRAMS = gmyth-cat + +gmyth_cat_SOURCES = \ + gmyth_cat.c + +LDADD = \ + $(top_builddir)/src/.libs/libgmyth.la + +LDFLAGS = \ + @GLIB_LIBS@ @GOBJECT_LIBS@ @GTHREAD_LIBS@ @LIBCURL_LIBS@ + +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src \ + $(GLIB_CFLAGS) \ + $(GOBJECT_CFLAGS) + diff -r 9e589622f097 -r 3fe481998d73 gmyth/samples/gmyth_cat.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/samples/gmyth_cat.c Fri Apr 20 03:58:43 2007 +0100 @@ -0,0 +1,100 @@ + +#include +#include + +#include + +static gboolean +_parse_args (int argc, char *argv[], GMythBackendInfo *b_info, char** filename) +{ + GError *error = NULL; + GOptionContext *context; + + gchar *host_ip = NULL; + gint host_port = 0; + + GOptionEntry entries[] = + { + { "hostname", 'h', 0, G_OPTION_ARG_STRING, &host_ip, "Mythtv backend hostname or IP address", "IP_ADDRESS" }, + { "port", 'p', 0, G_OPTION_ARG_INT, &host_port, "Mythtv backend port", "PORT" }, + { "filename", 'f', 0, G_OPTION_ARG_STRING, filename, "Recorded file name available in the Mythtv backend", "FILE" }, + { NULL } + }; + + context = g_option_context_new ("- loads a mythtv backend recorded file and prints it on the standard output\n"); + g_option_context_add_main_entries (context, entries, NULL); + g_option_context_parse (context, &argc, &argv, &error); + g_option_context_set_help_enabled (context, TRUE); + + g_option_context_free (context); + + gmyth_backend_info_set_hostname (b_info, host_ip); + gmyth_backend_info_set_port (b_info, host_port); + + g_free (host_ip); + + return TRUE; +} + +int +main (int argc, char *argv[]) +{ + gboolean res = FALSE; + gchar *filename = NULL; + GMythBackendInfo *b_info; + GByteArray *array = NULL; + GMythFileTransfer *transfer; + guint64 size = 0, total = 0; + + g_type_init (); + g_thread_init (NULL); + + b_info = gmyth_backend_info_new (); + + res = _parse_args (argc, argv, b_info, &filename); + if (!res) { + g_printerr ("Argument invalid. Type --help\n"); + return 1; + } + + if (!gmyth_util_file_exists (b_info, filename)) { + g_printerr ("File %s was not found in the mythtv server\n", filename); + return 1; + } + + transfer = gmyth_file_transfer_new (b_info); + if (!gmyth_file_transfer_open (transfer, filename)) { + g_printerr ("File %s could not be opened\n", filename); + return 1; + } + + size = gmyth_file_transfer_get_filesize (transfer); + while (total != size) { + GMythFileReadResult res; + + array = g_byte_array_new (); + res = gmyth_file_transfer_read (transfer, array, + (size - total) > 64000 ? 64000 : (size - total), + FALSE); + if ((res != GMYTH_FILE_READ_OK) && (res != GMYTH_FILE_READ_EOF)) { + g_byte_array_free (array, TRUE); + g_printerr ("Error while reading the file: aborting!!\n"); + break; + } + + fwrite (array->data, array->len, 1, stdout); + fflush (stdout); + + total += array->len; + g_byte_array_free (array, TRUE); + } + + g_free (filename); + + gmyth_file_transfer_close (transfer); + g_object_unref (transfer); + + g_object_unref (b_info); + + return 0; +}