File: gmyth_test_filetransfer.c

package info (click to toggle)
gmyth 1%3A0.7.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,256 kB
  • ctags: 1,230
  • sloc: ansic: 11,662; sh: 8,936; makefile: 222
file content (96 lines) | stat: -rw-r--r-- 2,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <glib-object.h>

#include "common.h"

#include <gmyth/gmyth_uri.h>
#include <gmyth/gmyth_backendinfo.h>
#include <gmyth/gmyth_livetv.h>
#include <gmyth/gmyth_file.h>
#include <gmyth/gmyth_file_transfer.h>
#include <gmyth/gmyth_file_local.h>
#include <gmyth/gmyth_common.h>

#define URI_FILE_TRANSFER_DEFAULT	"myth://192.168.3.165:6543/"

static          gboolean
test_file_transfer_setup(gchar * uri)
{
    GMythFile      *file = NULL;
    gboolean        ret = TRUE;

    if (NULL == uri)
        uri = g_strdup(URI_FILE_TRANSFER_DEFAULT);

    GMythURI       *gmyth_uri = gmyth_uri_new_with_value(uri);

    GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri(uri);

    /*
     * Check if the file is local to this specific client renderer, and
     * tries to open a local connection 
     */
    if (gmyth_uri_is_local_file(gmyth_uri)) {
        g_debug("Opening local file connection to download...");
        file = GMYTH_FILE(gmyth_file_local_new(backend_info));
        ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(file));
    } else {
        g_debug("Opening remote file connection to download...");
        file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
        ret = gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(file), uri);
    }

    if (NULL == file) {
        g_debug("FileTransfer is NULL");
        ret = FALSE;
        goto init_failed;
    }

    g_debug("uri = %s", uri);

    if (ret == FALSE) {
        g_debug
            ("MythTV FileTransfer request failed when setting up socket connection!");
        goto init_failed;
    }

    g_debug("MythTV FileTransfer filesize = %lld",
            gmyth_file_get_filesize(file));

  init_failed:

    if (file != NULL)
        g_object_unref(file);

    if (gmyth_uri != NULL)
        g_object_unref(gmyth_uri);

    if (backend_info != NULL)
        g_object_unref(backend_info);

    return ret;

}

gint
main(gint args, const gchar ** argv)
{
    gboolean        ret = FALSE;

    g_type_init();

    g_thread_init(NULL);

    fprintf(stdout, SYNC_STRING);
    fflush(NULL);
    getchar();

    if (args > 1)
        ret = test_file_transfer_setup(argv[1]);

    if (!ret)
        g_debug("Error when running LiveTV setup test script!");
    else
        g_debug("LiveTV setup test script finished with success.");

    return (0);
}