rosfran@637
|
1 |
#include <glib-object.h>
|
rosfran@637
|
2 |
|
rosfran@637
|
3 |
#include "common.h"
|
rosfran@637
|
4 |
|
rosfran@637
|
5 |
#include <gmyth/gmyth_uri.h>
|
rosfran@637
|
6 |
#include <gmyth/gmyth_backendinfo.h>
|
rosfran@637
|
7 |
#include <gmyth/gmyth_file.h>
|
rosfran@637
|
8 |
#include <gmyth/gmyth_file_transfer.h>
|
rosfran@637
|
9 |
#include <gmyth/gmyth_file_local.h>
|
rosfran@637
|
10 |
#include <gmyth/gmyth_common.h>
|
rosfran@637
|
11 |
|
rosfran@637
|
12 |
#define URI_FILE_TRANSFER_DEFAULT "myth://192.168.3.165:6543/"
|
rosfran@637
|
13 |
|
rosfran@637
|
14 |
static gboolean
|
rosfran@637
|
15 |
test_file_download_setup( gchar *uri ) {
|
rosfran@637
|
16 |
GMythFile *file = NULL;
|
rosfran@637
|
17 |
GMythFileReadResult result;
|
rosfran@637
|
18 |
gint64 num_bytes;
|
rosfran@637
|
19 |
GByteArray *file_buffer = g_byte_array_new ();
|
rosfran@637
|
20 |
gboolean ret = TRUE;
|
rosfran@637
|
21 |
gboolean is_local = FALSE;
|
rosfran@637
|
22 |
|
rosfran@637
|
23 |
if ( NULL == uri)
|
rosfran@637
|
24 |
uri = g_strdup( URI_FILE_TRANSFER_DEFAULT );
|
rosfran@637
|
25 |
|
rosfran@637
|
26 |
GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri);
|
rosfran@637
|
27 |
|
rosfran@637
|
28 |
GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri(uri);
|
rosfran@637
|
29 |
|
rosfran@637
|
30 |
/* Check if the file is local to this specific client renderer, and tries to open
|
rosfran@637
|
31 |
* a local connection
|
rosfran@637
|
32 |
*/
|
rosfran@637
|
33 |
if ( gmyth_uri_is_local_file(gmyth_uri)) {
|
rosfran@637
|
34 |
g_debug( "Opening local file connection to download...");
|
rosfran@637
|
35 |
file = GMYTH_FILE(gmyth_file_local_new(backend_info));
|
rosfran@637
|
36 |
ret = gmyth_file_local_open( GMYTH_FILE_LOCAL( file ) );
|
rosfran@637
|
37 |
} else {
|
rosfran@637
|
38 |
g_debug( "Opening remote file connection to download...");
|
rosfran@637
|
39 |
file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
|
rosfran@637
|
40 |
ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(file), uri);
|
rosfran@637
|
41 |
}
|
rosfran@637
|
42 |
|
rosfran@637
|
43 |
if (NULL == file) {
|
rosfran@637
|
44 |
g_debug("FileTransfer is NULL");
|
rosfran@637
|
45 |
ret = FALSE;
|
rosfran@637
|
46 |
goto init_failed;
|
rosfran@637
|
47 |
}
|
rosfran@637
|
48 |
|
rosfran@637
|
49 |
g_debug( "uri = %s", uri);
|
rosfran@637
|
50 |
|
rosfran@637
|
51 |
if (ret == FALSE) {
|
rosfran@637
|
52 |
g_debug("MythTV FileTransfer request failed when setting up socket connection!");
|
rosfran@637
|
53 |
goto init_failed;
|
rosfran@637
|
54 |
}
|
rosfran@637
|
55 |
|
rosfran@637
|
56 |
g_debug( "MythTV FileTransfer filesize = %lld",
|
rosfran@637
|
57 |
num_bytes = gmyth_file_get_filesize( file ) );
|
rosfran@637
|
58 |
|
rosfran@637
|
59 |
is_local = gmyth_uri_is_local_file(gmyth_uri);
|
rosfran@637
|
60 |
|
rosfran@637
|
61 |
do
|
rosfran@637
|
62 |
{
|
rosfran@637
|
63 |
|
rosfran@637
|
64 |
if ( is_local )
|
rosfran@637
|
65 |
result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(file),
|
rosfran@637
|
66 |
file_buffer,
|
rosfran@637
|
67 |
num_bytes, FALSE );
|
rosfran@637
|
68 |
else
|
rosfran@637
|
69 |
result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(file),
|
rosfran@637
|
70 |
file_buffer,
|
rosfran@637
|
71 |
num_bytes, FALSE );
|
rosfran@637
|
72 |
|
rosfran@637
|
73 |
} while ( result == GMYTH_FILE_READ_OK );
|
rosfran@637
|
74 |
|
rosfran@637
|
75 |
init_failed:
|
rosfran@637
|
76 |
|
rosfran@637
|
77 |
if ( file != NULL)
|
rosfran@637
|
78 |
g_object_unref(file);
|
rosfran@637
|
79 |
|
rosfran@637
|
80 |
if ( gmyth_uri != NULL)
|
rosfran@637
|
81 |
g_object_unref( gmyth_uri);
|
rosfran@637
|
82 |
|
rosfran@637
|
83 |
if ( backend_info != NULL)
|
rosfran@637
|
84 |
g_object_unref( backend_info);
|
rosfran@637
|
85 |
|
rosfran@637
|
86 |
return ret;
|
rosfran@637
|
87 |
|
rosfran@637
|
88 |
}
|
rosfran@637
|
89 |
|
rosfran@637
|
90 |
gint
|
rosfran@637
|
91 |
main(gint args, const gchar **argv) {
|
rosfran@637
|
92 |
gboolean ret = FALSE;
|
rosfran@637
|
93 |
|
rosfran@637
|
94 |
g_type_init();
|
rosfran@637
|
95 |
|
rosfran@637
|
96 |
g_thread_init(NULL);
|
rosfran@637
|
97 |
|
rosfran@637
|
98 |
fprintf(stdout, SYNC_STRING);
|
rosfran@637
|
99 |
fflush(NULL);
|
rosfran@637
|
100 |
getchar();
|
rosfran@637
|
101 |
|
rosfran@637
|
102 |
if ( args > 1)
|
rosfran@637
|
103 |
ret = test_file_download_setup( argv[1]);
|
rosfran@637
|
104 |
|
rosfran@637
|
105 |
if ( !ret)
|
rosfran@637
|
106 |
g_debug("Error when running LiveTV setup test script!");
|
rosfran@637
|
107 |
else
|
rosfran@637
|
108 |
g_debug("LiveTV setup test script finished with success.");
|
rosfran@637
|
109 |
|
rosfran@637
|
110 |
return (0);
|
rosfran@637
|
111 |
}
|
rosfran@637
|
112 |
|