branches/gmyth-0.1b/tests/main.c
author rosfran
Wed Feb 14 22:24:39 2007 +0000 (2007-02-14)
branchtrunk
changeset 362 6d7b5baf170b
permissions -rw-r--r--
[svn r364] Fixed a mutual exclusion bug on the Monitor Handler GIOChannel read callback.
     1 #include <glib-object.h>
     2 #include "gmyth.h"
     3 
     4 int
     5 main (int args, const char **argv)
     6 {
     7     const char *uri = argv[1];
     8     GMythURI *gmyth_uri = NULL;
     9     gboolean res;
    10     GMythBackendInfo *backend_info;
    11     g_type_init ();
    12     g_thread_init (NULL);
    13 
    14     backend_info = gmyth_backend_info_new ();
    15     gmyth_uri = gmyth_uri_new_with_value (uri);
    16 
    17     gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (gmyth_uri));
    18     gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port (gmyth_uri));
    19     
    20     res = gmyth_util_file_exists (backend_info, uri);
    21     if (res == FALSE) {
    22         g_debug ("file not exists");
    23         return -1;
    24     }
    25     GMythFileTransfer *file_transfer = gmyth_file_transfer_new ();
    26     GString *hostname = g_string_new (uri);
    27     res = gmyth_file_transfer_open (file_transfer, hostname);
    28     if (res == FALSE) {
    29         g_debug ("Fail to open server");
    30         return  -1;
    31     }
    32 
    33     guint64 filesize = gmyth_file_transfer_get_filesize (file_transfer);
    34     if (filesize <= 0) {
    35         g_debug ("filesize is 0");
    36         return -1;
    37     }
    38 
    39     GByteArray *data = g_byte_array_new ();
    40     guint num = gmyth_file_transfer_read (file_transfer, data, filesize, FALSE);
    41     g_debug ("read %d bytes", num);
    42 
    43     g_byte_array_free (data, TRUE);
    44     g_object_unref (file_transfer);
    45     g_object_unref (gmyth_uri);
    46     g_string_free (hostname, TRUE);
    47 
    48     return 0;    
    49 }