gmyth/tests/main.c
author renatofilho
Wed May 16 23:55:23 2007 +0100 (2007-05-16)
branchtrunk
changeset 681 1d488185037f
parent 564 1b897f699097
child 750 312d6bc514f3
permissions -rw-r--r--
[svn r687] removed some debug messages
     1 #include <glib-object.h>
     2 #include <glib.h>
     3 #include <gmyth/gmyth.h>
     4 
     5 #include "common.h"
     6 
     7 int
     8 main (int args, const char **argv)
     9 {
    10     const char *uri = argv[1];
    11     GMythURI *gmyth_uri = NULL;
    12     gboolean res;
    13     GMythBackendInfo *backend_info = NULL;
    14     g_type_init ();
    15     g_thread_init (NULL);
    16 
    17     fprintf(stdout, SYNC_STRING);
    18     fflush(NULL);
    19     getchar();
    20 
    21     backend_info = gmyth_backend_info_new ();
    22     gmyth_uri = gmyth_uri_new_with_value (uri);
    23 
    24     gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (gmyth_uri));
    25     gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port (gmyth_uri));
    26     
    27     res = gmyth_util_file_exists (backend_info, uri);
    28     if (res == FALSE) {
    29         g_debug ("file not exists");
    30         return -1;
    31     }
    32     GMythFileTransfer *file_transfer = gmyth_file_transfer_new (backend_info);
    33     GString *hostname = g_string_new (uri);
    34     res = gmyth_file_transfer_open (file_transfer, uri);
    35     if (res == FALSE) {
    36         g_debug ("Fail to open server");
    37         return  -1;
    38     }
    39 
    40     gint64 filesize = gmyth_file_transfer_get_filesize (file_transfer);
    41     if (filesize <= 0) {
    42         g_debug ("filesize is 0");
    43         return -1;
    44     }
    45 
    46     GByteArray *data = g_byte_array_new ();
    47     guint num = gmyth_file_transfer_read (file_transfer, data, filesize, FALSE);
    48     g_debug ("read %d bytes", num);
    49 
    50     if ( data != NULL )
    51 	g_byte_array_free (data, TRUE);
    52     if ( file_transfer != NULL )
    53 	g_object_unref (file_transfer);
    54     if ( gmyth_uri != NULL )
    55 	g_object_unref (gmyth_uri);
    56     if ( hostname != NULL )
    57 	g_string_free (hostname, TRUE);
    58 
    59     return (0);
    60 }
    61