leo_sobral@2
|
1 |
/* vim: set sw=2: -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2; c-indent-level: 2-*- */
|
leo_sobral@2
|
2 |
/**
|
leo_sobral@2
|
3 |
* GStreamer plug-in properties:
|
leo_sobral@2
|
4 |
* - location (backend server hostname/URL) [ex.: myth://192.168.1.73:28722/1000_1092091.nuv]
|
leo_sobral@2
|
5 |
* - path (qurl - remote file to be opened)
|
leo_sobral@2
|
6 |
* - port number
|
leo_sobral@2
|
7 |
* @author Rosfran Lins Borges <rosfran.borges@indt.org.br>
|
leo_sobral@2
|
8 |
*/
|
leo_sobral@2
|
9 |
|
leo_sobral@2
|
10 |
#include "myth_file_transfer.h"
|
leo_sobral@2
|
11 |
#include "myth_uri.h"
|
leo_sobral@2
|
12 |
#include "myth_livetv.h"
|
leo_sobral@2
|
13 |
#include <gmyth/gmyth_util.h>
|
leo_sobral@2
|
14 |
#include <gmyth/gmyth_socket.h>
|
leo_sobral@2
|
15 |
#include <gmyth/gmyth_stringlist.h>
|
leo_sobral@2
|
16 |
|
leo_sobral@2
|
17 |
#include <unistd.h>
|
leo_sobral@2
|
18 |
#include <glib.h>
|
leo_sobral@2
|
19 |
|
leo_sobral@2
|
20 |
#include <arpa/inet.h>
|
leo_sobral@2
|
21 |
#include <sys/types.h>
|
leo_sobral@2
|
22 |
#include <sys/socket.h>
|
leo_sobral@2
|
23 |
#include <netdb.h>
|
leo_sobral@2
|
24 |
#include <errno.h>
|
leo_sobral@2
|
25 |
#include <stdlib.h>
|
leo_sobral@2
|
26 |
|
leo_sobral@2
|
27 |
#define MYTHTV_QUERY_HEADER "QUERY_FILETRANSFER"
|
leo_sobral@2
|
28 |
#define MYTHTV_RECORDER_HEADER "QUERY_RECORDER"
|
leo_sobral@2
|
29 |
|
leo_sobral@2
|
30 |
/* default values to the file transfer parameters */
|
leo_sobral@2
|
31 |
#define MYTHTV_USER_READ_AHEAD FALSE
|
leo_sobral@2
|
32 |
#define MYTHTV_RETRIES 1
|
leo_sobral@2
|
33 |
#define MYTHTV_FILE_SIZE -1
|
leo_sobral@2
|
34 |
|
rosfran@34
|
35 |
#define MYTHTV_BUFFER_SIZE 256*1024
|
leo_sobral@2
|
36 |
|
leo_sobral@2
|
37 |
#define MYTHTV_VERSION 30
|
leo_sobral@2
|
38 |
|
leo_sobral@2
|
39 |
#define MYTHTV_TRANSFER_MAX_WAITS 700
|
leo_sobral@2
|
40 |
|
leo_sobral@2
|
41 |
#ifdef MYTHTV_ENABLE_DEBUG
|
leo_sobral@2
|
42 |
#define MYTHTV_ENABLE_DEBUG 1
|
leo_sobral@2
|
43 |
#else
|
leo_sobral@2
|
44 |
#undef MYTHTV_ENABLE_DEBUG
|
leo_sobral@2
|
45 |
#endif
|
leo_sobral@2
|
46 |
|
leo_sobral@2
|
47 |
/* this NDEBUG is to maintain compatibility with GMyth library */
|
leo_sobral@2
|
48 |
#ifndef NDEBUG
|
leo_sobral@2
|
49 |
#define MYTHTV_ENABLE_DEBUG 1
|
leo_sobral@2
|
50 |
#endif
|
leo_sobral@2
|
51 |
|
leo_sobral@2
|
52 |
static guint wait_to_transfer = 0;
|
leo_sobral@2
|
53 |
|
leo_sobral@2
|
54 |
enum myth_sock_types {
|
leo_sobral@2
|
55 |
MYTH_PLAYBACK_TYPE = 0,
|
leo_sobral@2
|
56 |
MYTH_MONITOR_TYPE,
|
leo_sobral@2
|
57 |
MYTH_FILETRANSFER_TYPE,
|
leo_sobral@2
|
58 |
MYTH_RINGBUFFER_TYPE
|
leo_sobral@2
|
59 |
};
|
leo_sobral@2
|
60 |
|
leo_sobral@2
|
61 |
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
leo_sobral@2
|
62 |
|
leo_sobral@2
|
63 |
static void myth_file_transfer_class_init (MythFileTransferClass *klass);
|
leo_sobral@2
|
64 |
static void myth_file_transfer_init (MythFileTransfer *object);
|
leo_sobral@2
|
65 |
|
leo_sobral@2
|
66 |
static void myth_file_transfer_dispose (GObject *object);
|
leo_sobral@2
|
67 |
static void myth_file_transfer_finalize (GObject *object);
|
leo_sobral@2
|
68 |
|
leo_sobral@2
|
69 |
static GMythSocket *myth_connect_to_transfer_backend( MythFileTransfer **transfer, guint sock_type );
|
leo_sobral@2
|
70 |
static void* myth_init_io_watchers( void *data );
|
leo_sobral@2
|
71 |
|
leo_sobral@2
|
72 |
void myth_file_transfer_close( MythFileTransfer *transfer );
|
leo_sobral@2
|
73 |
|
leo_sobral@2
|
74 |
G_DEFINE_TYPE(MythFileTransfer, myth_file_transfer, G_TYPE_OBJECT)
|
leo_sobral@2
|
75 |
|
leo_sobral@2
|
76 |
static guint64
|
leo_sobral@2
|
77 |
mmyth_util_decode_long_long( GMythStringList *strlist, guint offset )
|
leo_sobral@2
|
78 |
{
|
leo_sobral@2
|
79 |
|
leo_sobral@2
|
80 |
guint64 ret_value = 0LL;
|
leo_sobral@2
|
81 |
|
leo_sobral@2
|
82 |
g_return_val_if_fail( strlist != NULL, ret_value );
|
leo_sobral@2
|
83 |
|
leo_sobral@2
|
84 |
if ( offset < gmyth_string_list_length( strlist ))
|
leo_sobral@2
|
85 |
g_printerr( "[%s] Offset is lower than the GMythStringList (offset = %d)!\n", __FUNCTION__, offset );
|
leo_sobral@2
|
86 |
g_return_val_if_fail( offset < gmyth_string_list_length( strlist ), ret_value );
|
leo_sobral@2
|
87 |
|
leo_sobral@2
|
88 |
gint l1 = gmyth_string_list_get_int( strlist, offset );
|
leo_sobral@2
|
89 |
gint l2 = gmyth_string_list_get_int( strlist, offset + 1 );
|
leo_sobral@2
|
90 |
|
leo_sobral@2
|
91 |
ret_value = ((guint64)(l2) & 0xffffffffLL) | ((guint64)(l1) << 32);
|
leo_sobral@2
|
92 |
|
leo_sobral@2
|
93 |
return ret_value;
|
leo_sobral@2
|
94 |
|
leo_sobral@2
|
95 |
}
|
leo_sobral@2
|
96 |
|
leo_sobral@2
|
97 |
static void
|
leo_sobral@2
|
98 |
myth_file_transfer_class_init (MythFileTransferClass *klass)
|
leo_sobral@2
|
99 |
{
|
leo_sobral@2
|
100 |
GObjectClass *gobject_class;
|
leo_sobral@2
|
101 |
|
leo_sobral@2
|
102 |
gobject_class = (GObjectClass *) klass;
|
leo_sobral@2
|
103 |
|
leo_sobral@2
|
104 |
gobject_class->dispose = myth_file_transfer_dispose;
|
leo_sobral@2
|
105 |
gobject_class->finalize = myth_file_transfer_finalize;
|
leo_sobral@2
|
106 |
}
|
leo_sobral@2
|
107 |
|
leo_sobral@2
|
108 |
static void
|
leo_sobral@2
|
109 |
myth_file_transfer_init (MythFileTransfer *myth_file_transfer)
|
leo_sobral@2
|
110 |
{
|
leo_sobral@2
|
111 |
g_return_if_fail( myth_file_transfer != NULL );
|
leo_sobral@2
|
112 |
myth_file_transfer->mythtv_version = MYTHTV_VERSION;
|
leo_sobral@2
|
113 |
}
|
leo_sobral@2
|
114 |
|
leo_sobral@2
|
115 |
static void
|
leo_sobral@2
|
116 |
myth_file_transfer_dispose (GObject *object)
|
leo_sobral@2
|
117 |
{
|
leo_sobral@2
|
118 |
MythFileTransfer *myth_file_transfer = MYTH_FILE_TRANSFER(object);
|
leo_sobral@2
|
119 |
|
leo_sobral@2
|
120 |
myth_file_transfer_close( myth_file_transfer );
|
leo_sobral@2
|
121 |
|
leo_sobral@2
|
122 |
G_OBJECT_CLASS (myth_file_transfer_parent_class)->dispose (object);
|
leo_sobral@2
|
123 |
}
|
leo_sobral@2
|
124 |
|
leo_sobral@2
|
125 |
static void
|
leo_sobral@2
|
126 |
myth_file_transfer_finalize (GObject *object)
|
leo_sobral@2
|
127 |
{
|
leo_sobral@2
|
128 |
g_signal_handlers_destroy (object);
|
leo_sobral@2
|
129 |
|
leo_sobral@2
|
130 |
G_OBJECT_CLASS (myth_file_transfer_parent_class)->finalize (object);
|
leo_sobral@2
|
131 |
}
|
leo_sobral@2
|
132 |
|
leo_sobral@2
|
133 |
MythFileTransfer*
|
leo_sobral@2
|
134 |
myth_file_transfer_new (gint num, GString *uri_str, gshort port, gint mythtv_version)
|
leo_sobral@2
|
135 |
{
|
leo_sobral@2
|
136 |
MythFileTransfer *transfer = MYTH_FILE_TRANSFER ( g_object_new (
|
leo_sobral@2
|
137 |
MYTH_FILE_TRANSFER_TYPE, FALSE ));
|
leo_sobral@2
|
138 |
|
leo_sobral@2
|
139 |
if ( mythtv_version > 0 )
|
leo_sobral@2
|
140 |
transfer->mythtv_version = mythtv_version;
|
leo_sobral@2
|
141 |
|
leo_sobral@2
|
142 |
transfer->card_id = num;
|
leo_sobral@2
|
143 |
|
leo_sobral@2
|
144 |
transfer->rec_id = -1;
|
leo_sobral@2
|
145 |
|
rosfran@30
|
146 |
transfer->recordernum = num;
|
leo_sobral@2
|
147 |
transfer->uri = myth_uri_new ( uri_str->str );
|
leo_sobral@2
|
148 |
|
leo_sobral@2
|
149 |
transfer->hostname = g_string_new( myth_uri_gethost(transfer->uri) );
|
leo_sobral@2
|
150 |
g_print( "\t--> transfer->hostname = %s\n", transfer->hostname->str );
|
leo_sobral@2
|
151 |
|
leo_sobral@2
|
152 |
if ( port >= 0 )
|
leo_sobral@2
|
153 |
transfer->port = port;
|
leo_sobral@2
|
154 |
else
|
leo_sobral@2
|
155 |
transfer->port = myth_uri_getport( transfer->uri );
|
leo_sobral@2
|
156 |
|
leo_sobral@2
|
157 |
g_print( "\t--> transfer->port = %d\n", transfer->port );
|
leo_sobral@2
|
158 |
|
leo_sobral@2
|
159 |
transfer->readposition = 0;
|
leo_sobral@2
|
160 |
transfer->filesize = MYTHTV_FILE_SIZE;
|
leo_sobral@2
|
161 |
transfer->timeoutisfast = FALSE;
|
leo_sobral@2
|
162 |
|
leo_sobral@2
|
163 |
transfer->userreadahead = MYTHTV_USER_READ_AHEAD;
|
leo_sobral@2
|
164 |
transfer->retries = MYTHTV_RETRIES;
|
leo_sobral@2
|
165 |
|
leo_sobral@2
|
166 |
transfer->live_tv = FALSE;
|
leo_sobral@2
|
167 |
|
leo_sobral@2
|
168 |
transfer->query = g_string_new( MYTHTV_QUERY_HEADER );
|
leo_sobral@2
|
169 |
g_string_append_printf ( transfer->query, " %d", transfer->recordernum );
|
leo_sobral@2
|
170 |
g_print( "\t--> transfer->query = %s\n", transfer->query->str );
|
leo_sobral@2
|
171 |
|
leo_sobral@2
|
172 |
transfer->control_sock = NULL;
|
leo_sobral@2
|
173 |
transfer->event_sock = NULL;
|
leo_sobral@2
|
174 |
transfer->sock = NULL;
|
leo_sobral@2
|
175 |
|
leo_sobral@2
|
176 |
return transfer;
|
leo_sobral@2
|
177 |
}
|
leo_sobral@2
|
178 |
|
leo_sobral@2
|
179 |
gboolean
|
leo_sobral@2
|
180 |
myth_file_transfer_livetv_setup( MythFileTransfer **transfer, GMythSocket *live_socket )
|
leo_sobral@2
|
181 |
{
|
leo_sobral@2
|
182 |
(*transfer)->sock = live_socket;
|
leo_sobral@2
|
183 |
g_object_ref( live_socket );
|
leo_sobral@2
|
184 |
|
leo_sobral@2
|
185 |
return TRUE;
|
leo_sobral@2
|
186 |
}
|
leo_sobral@2
|
187 |
|
leo_sobral@2
|
188 |
gboolean
|
leo_sobral@2
|
189 |
myth_file_transfer_playback_setup( MythFileTransfer **transfer, gboolean live_tv )
|
leo_sobral@2
|
190 |
{
|
leo_sobral@2
|
191 |
|
leo_sobral@2
|
192 |
gboolean ret = TRUE;
|
leo_sobral@2
|
193 |
|
leo_sobral@2
|
194 |
(*transfer)->live_tv = live_tv;
|
leo_sobral@2
|
195 |
|
leo_sobral@2
|
196 |
printf("[%s] Running config to the %s...\n", __FUNCTION__, live_tv ? "LiveTV" : "FileTransfer" );
|
leo_sobral@2
|
197 |
|
leo_sobral@2
|
198 |
/* configure the control socket */
|
leo_sobral@2
|
199 |
if ((*transfer)->control_sock == NULL) {
|
leo_sobral@2
|
200 |
|
leo_sobral@2
|
201 |
if ( myth_connect_to_transfer_backend ( transfer, MYTH_PLAYBACK_TYPE ) == NULL ) {
|
leo_sobral@2
|
202 |
g_printerr( "Connection to backend failed (Control Socket).\n" );
|
leo_sobral@2
|
203 |
ret = FALSE;
|
leo_sobral@2
|
204 |
}
|
leo_sobral@2
|
205 |
|
leo_sobral@2
|
206 |
} else {
|
leo_sobral@2
|
207 |
g_warning("Remote transfer control socket already created.\n");
|
leo_sobral@2
|
208 |
}
|
leo_sobral@2
|
209 |
|
leo_sobral@2
|
210 |
return ret;
|
leo_sobral@2
|
211 |
|
leo_sobral@2
|
212 |
}
|
leo_sobral@2
|
213 |
|
leo_sobral@2
|
214 |
gboolean
|
leo_sobral@2
|
215 |
myth_file_transfer_setup( MythFileTransfer **transfer, gboolean live_tv )
|
leo_sobral@2
|
216 |
{
|
leo_sobral@2
|
217 |
GMythStringList *strlist = NULL;
|
leo_sobral@2
|
218 |
|
leo_sobral@2
|
219 |
gboolean ret = TRUE;
|
leo_sobral@2
|
220 |
|
leo_sobral@2
|
221 |
(*transfer)->live_tv = live_tv;
|
leo_sobral@2
|
222 |
|
leo_sobral@2
|
223 |
printf("[%s] Running config to the %s...\n", __FUNCTION__, live_tv ? "LiveTV" : "FileTransfer" );
|
leo_sobral@2
|
224 |
|
leo_sobral@2
|
225 |
#if 0
|
rosfran@30
|
226 |
/* configure the control socket */
|
rosfran@30
|
227 |
if ((*transfer)->control_sock == NULL) {
|
leo_sobral@2
|
228 |
|
rosfran@30
|
229 |
if ( myth_connect_to_transfer_backend ( transfer, MYTH_PLAYBACK_TYPE ) == NULL ) {
|
leo_sobral@2
|
230 |
g_printerr( "Connection to backend failed (Event Socket).\n" );
|
leo_sobral@2
|
231 |
ret = FALSE;
|
leo_sobral@2
|
232 |
}
|
leo_sobral@2
|
233 |
|
leo_sobral@2
|
234 |
} else {
|
leo_sobral@2
|
235 |
g_warning("Remote transfer control socket already created.\n");
|
leo_sobral@2
|
236 |
}
|
leo_sobral@2
|
237 |
#endif
|
leo_sobral@2
|
238 |
|
leo_sobral@2
|
239 |
/* configure the socket */
|
leo_sobral@2
|
240 |
if ( (*transfer)->sock == NULL ) {
|
leo_sobral@2
|
241 |
|
leo_sobral@2
|
242 |
//if ( live_tv == FALSE ) {
|
leo_sobral@2
|
243 |
|
leo_sobral@2
|
244 |
if ( myth_connect_to_transfer_backend ( transfer, MYTH_FILETRANSFER_TYPE ) == NULL ) {
|
leo_sobral@2
|
245 |
g_printerr ("Connection to backend failed (Raw Transfer Socket).\n");
|
leo_sobral@2
|
246 |
ret = FALSE;
|
leo_sobral@2
|
247 |
}
|
leo_sobral@2
|
248 |
|
leo_sobral@2
|
249 |
if ( !(*transfer)->live_tv && (*transfer)->control_sock != NULL) {
|
leo_sobral@2
|
250 |
strlist = gmyth_string_list_new();
|
leo_sobral@2
|
251 |
g_string_printf ( (*transfer)->query, "%s %d", MYTHTV_QUERY_HEADER, (*transfer)->recordernum );
|
leo_sobral@2
|
252 |
|
leo_sobral@2
|
253 |
gmyth_string_list_append_string( strlist, (*transfer)->query );
|
leo_sobral@2
|
254 |
gmyth_string_list_append_char_array( strlist, "IS_OPEN" );
|
leo_sobral@2
|
255 |
|
leo_sobral@2
|
256 |
gmyth_socket_write_stringlist( (*transfer)->control_sock, strlist );
|
leo_sobral@2
|
257 |
gmyth_socket_read_stringlist( (*transfer)->control_sock, strlist );
|
leo_sobral@2
|
258 |
|
leo_sobral@2
|
259 |
if ( strlist!=NULL && gmyth_string_list_get_int( strlist, 0 ) == 1 ) {
|
leo_sobral@2
|
260 |
g_print( "[%s] Remote Myth FileTransfer socket is open!\n", __FUNCTION__ );
|
leo_sobral@2
|
261 |
} else {
|
leo_sobral@2
|
262 |
g_print( "[%s] Remote Myth FileTransfer socket is CLOSED! See the MythTV Server Backend for configuration details...\n", __FUNCTION__ );
|
leo_sobral@2
|
263 |
ret = FALSE;
|
leo_sobral@2
|
264 |
}
|
leo_sobral@2
|
265 |
}
|
leo_sobral@2
|
266 |
|
leo_sobral@2
|
267 |
} else {
|
leo_sobral@2
|
268 |
g_warning("Remote transfer (raw) socket already created.\n");
|
leo_sobral@2
|
269 |
}
|
leo_sobral@2
|
270 |
|
leo_sobral@2
|
271 |
return ret;
|
leo_sobral@2
|
272 |
}
|
leo_sobral@2
|
273 |
|
leo_sobral@2
|
274 |
static GMythSocket *
|
leo_sobral@2
|
275 |
myth_connect_to_transfer_backend( MythFileTransfer **transfer, guint sock_type )
|
leo_sobral@2
|
276 |
{
|
leo_sobral@2
|
277 |
GMythSocket *sock = NULL;
|
leo_sobral@2
|
278 |
|
leo_sobral@2
|
279 |
g_return_val_if_fail( transfer != NULL && *transfer != NULL, NULL );
|
leo_sobral@2
|
280 |
g_return_val_if_fail( (*transfer)->uri != NULL, NULL );
|
leo_sobral@2
|
281 |
|
leo_sobral@2
|
282 |
g_static_mutex_lock (&mutex);
|
leo_sobral@2
|
283 |
|
leo_sobral@2
|
284 |
gchar *path_dir = myth_uri_getpath( (*transfer)->uri );
|
leo_sobral@2
|
285 |
//g_print( "\t--> %s: path_dir = %s\n", __FUNCTION__, path_dir );
|
leo_sobral@2
|
286 |
|
leo_sobral@2
|
287 |
gchar *stype = g_strdup( "" );
|
leo_sobral@2
|
288 |
|
leo_sobral@2
|
289 |
// if ( (*transfer)->live_tv == FALSE ) {
|
leo_sobral@2
|
290 |
|
leo_sobral@2
|
291 |
sock = gmyth_socket_new();
|
leo_sobral@2
|
292 |
|
leo_sobral@2
|
293 |
gmyth_socket_connect( &sock, (*transfer)->hostname->str, (*transfer)->port );
|
leo_sobral@2
|
294 |
|
leo_sobral@2
|
295 |
/*
|
leo_sobral@2
|
296 |
} else {
|
leo_sobral@2
|
297 |
sock = (*transfer)->sock;
|
leo_sobral@2
|
298 |
}
|
leo_sobral@2
|
299 |
*/
|
leo_sobral@2
|
300 |
#ifdef MYTHTV_ENABLE_DEBUG
|
leo_sobral@2
|
301 |
|
leo_sobral@2
|
302 |
g_print( "[%s] --> Creating socket... (%s, %d)\n", __FUNCTION__, (*transfer)->hostname->str, (*transfer)->port );
|
leo_sobral@2
|
303 |
#endif
|
leo_sobral@2
|
304 |
|
leo_sobral@2
|
305 |
GMythStringList *strlist = NULL;
|
leo_sobral@2
|
306 |
|
leo_sobral@2
|
307 |
GString *hostname = g_string_new( myth_uri_gethost( (*transfer)->uri ) );
|
leo_sobral@2
|
308 |
GString *base_str = g_string_new( "" );
|
leo_sobral@2
|
309 |
|
leo_sobral@2
|
310 |
if ( gmyth_socket_check_protocol_version_number (sock, (*transfer)->mythtv_version) ) {
|
leo_sobral@2
|
311 |
|
leo_sobral@2
|
312 |
if (sock == NULL) {
|
leo_sobral@2
|
313 |
stype = (sock_type==MYTH_PLAYBACK_TYPE) ? "control socket" : "file data socket";
|
leo_sobral@2
|
314 |
g_printerr( "FileTransfer, open_socket(%s): \n"
|
leo_sobral@2
|
315 |
"\t\t\tCould not connect to server \"%s\" @ port %d\n", stype,
|
leo_sobral@2
|
316 |
(*transfer)->hostname->str, (*transfer)->port );
|
leo_sobral@2
|
317 |
g_object_unref(sock);
|
leo_sobral@2
|
318 |
g_static_mutex_unlock (&mutex);
|
leo_sobral@2
|
319 |
return NULL;
|
leo_sobral@2
|
320 |
}
|
leo_sobral@2
|
321 |
|
leo_sobral@2
|
322 |
hostname = gmyth_socket_get_local_hostname();
|
leo_sobral@2
|
323 |
|
leo_sobral@2
|
324 |
g_print( "[%s] local hostname = %s\n", __FUNCTION__, hostname->str );
|
leo_sobral@2
|
325 |
|
leo_sobral@2
|
326 |
if ( sock_type == MYTH_PLAYBACK_TYPE )
|
leo_sobral@2
|
327 |
{
|
leo_sobral@2
|
328 |
(*transfer)->control_sock = sock;
|
leo_sobral@2
|
329 |
g_string_printf( base_str, "ANN Playback %s %d", hostname->str, FALSE );
|
leo_sobral@2
|
330 |
|
leo_sobral@2
|
331 |
gmyth_socket_send_command( (*transfer)->control_sock, base_str );
|
leo_sobral@2
|
332 |
GString *resp = gmyth_socket_receive_response( (*transfer)->control_sock );
|
leo_sobral@2
|
333 |
g_print( "[%s] Got Playback response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
|
leo_sobral@2
|
334 |
}
|
leo_sobral@2
|
335 |
else if ( sock_type == MYTH_MONITOR_TYPE )
|
leo_sobral@2
|
336 |
{
|
leo_sobral@2
|
337 |
(*transfer)->event_sock = sock;
|
leo_sobral@2
|
338 |
g_string_printf( base_str, "ANN Monitor %s %d", hostname->str, TRUE );
|
leo_sobral@2
|
339 |
|
leo_sobral@2
|
340 |
gmyth_socket_send_command( (*transfer)->event_sock, base_str );
|
leo_sobral@2
|
341 |
GString *resp = gmyth_socket_receive_response( (*transfer)->event_sock );
|
leo_sobral@2
|
342 |
g_print( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
|
leo_sobral@2
|
343 |
g_thread_create( myth_init_io_watchers, (void*)(*transfer), FALSE, NULL );
|
leo_sobral@2
|
344 |
|
leo_sobral@2
|
345 |
g_printerr( "[%s] Watch listener function to the IO control channel on thread %p.\n", __FUNCTION__, g_thread_self() );
|
leo_sobral@2
|
346 |
|
leo_sobral@2
|
347 |
}
|
leo_sobral@2
|
348 |
else if ( sock_type == MYTH_FILETRANSFER_TYPE )
|
leo_sobral@2
|
349 |
{
|
leo_sobral@2
|
350 |
(*transfer)->sock = sock;
|
leo_sobral@2
|
351 |
strlist = gmyth_string_list_new();
|
leo_sobral@2
|
352 |
//g_string_printf( base_str, "ANN FileTransfer %s %d %d", hostname->str,
|
leo_sobral@2
|
353 |
// transfer->userreadahead, transfer->retries );
|
leo_sobral@2
|
354 |
g_string_printf( base_str, "ANN FileTransfer %s", hostname->str );
|
leo_sobral@2
|
355 |
|
leo_sobral@2
|
356 |
gmyth_string_list_append_string( strlist, base_str );
|
leo_sobral@2
|
357 |
gmyth_string_list_append_char_array( strlist, path_dir );
|
leo_sobral@2
|
358 |
|
leo_sobral@2
|
359 |
gmyth_socket_write_stringlist( (*transfer)->sock, strlist );
|
leo_sobral@2
|
360 |
gmyth_socket_read_stringlist( (*transfer)->sock, strlist );
|
leo_sobral@2
|
361 |
|
leo_sobral@2
|
362 |
/* socket number, where all the stream data comes from - got from the MythTV remote backend */
|
leo_sobral@2
|
363 |
(*transfer)->recordernum = gmyth_string_list_get_int( strlist, 1 );
|
leo_sobral@2
|
364 |
|
leo_sobral@2
|
365 |
/* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
|
leo_sobral@2
|
366 |
(*transfer)->filesize = mmyth_util_decode_long_long( strlist, 2 );
|
leo_sobral@2
|
367 |
|
leo_sobral@2
|
368 |
printf( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__,
|
leo_sobral@2
|
369 |
(*transfer)->recordernum, (*transfer)->filesize );
|
leo_sobral@2
|
370 |
|
leo_sobral@2
|
371 |
if ( (*transfer)->filesize <= 0 ) {
|
leo_sobral@2
|
372 |
g_print( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, (*transfer)->filesize );
|
leo_sobral@2
|
373 |
g_object_unref(sock);
|
leo_sobral@2
|
374 |
sock = NULL;
|
leo_sobral@2
|
375 |
}
|
leo_sobral@2
|
376 |
}
|
leo_sobral@2
|
377 |
else if ( sock_type == MYTH_RINGBUFFER_TYPE )
|
leo_sobral@2
|
378 |
{
|
leo_sobral@2
|
379 |
(*transfer)->sock = sock;
|
leo_sobral@2
|
380 |
//myth_file_transfer_spawntv( (*transfer), NULL );
|
leo_sobral@2
|
381 |
|
leo_sobral@2
|
382 |
strlist = gmyth_string_list_new();
|
leo_sobral@2
|
383 |
g_string_printf( base_str, "ANN RingBuffer %s %d", hostname->str, (*transfer)->card_id );
|
leo_sobral@2
|
384 |
|
leo_sobral@2
|
385 |
gmyth_socket_send_command( (*transfer)->sock, base_str );
|
leo_sobral@2
|
386 |
GString *resp = gmyth_socket_receive_response( (*transfer)->sock );
|
leo_sobral@2
|
387 |
g_print( "[%s] Got RingBuffer response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
|
leo_sobral@2
|
388 |
|
leo_sobral@2
|
389 |
}
|
leo_sobral@2
|
390 |
|
leo_sobral@2
|
391 |
}
|
leo_sobral@2
|
392 |
|
leo_sobral@2
|
393 |
printf("[%s] ANN %s sent: %s\n", (sock_type==MYTH_PLAYBACK_TYPE) ? "Playback" : (sock_type==MYTH_FILETRANSFER_TYPE) ? "FileTransfer" : "Monitor", __FUNCTION__, base_str->str);
|
leo_sobral@2
|
394 |
|
leo_sobral@2
|
395 |
if ( strlist != NULL )
|
leo_sobral@2
|
396 |
g_object_unref( strlist );
|
leo_sobral@2
|
397 |
|
leo_sobral@2
|
398 |
g_static_mutex_unlock (&mutex);
|
leo_sobral@2
|
399 |
|
leo_sobral@2
|
400 |
return sock;
|
leo_sobral@2
|
401 |
}
|
leo_sobral@2
|
402 |
|
leo_sobral@2
|
403 |
void
|
leo_sobral@2
|
404 |
myth_file_transfer_spawntv ( MythFileTransfer *file_transfer,
|
leo_sobral@2
|
405 |
GString *tvchain_id )
|
leo_sobral@2
|
406 |
{
|
leo_sobral@2
|
407 |
GMythStringList *str_list;
|
leo_sobral@2
|
408 |
|
leo_sobral@2
|
409 |
g_debug ("myth_file_transfer_spawntv.\n");
|
leo_sobral@2
|
410 |
|
leo_sobral@2
|
411 |
str_list = gmyth_string_list_new ();
|
leo_sobral@2
|
412 |
|
leo_sobral@2
|
413 |
g_string_printf( file_transfer->query, "%s %d", MYTHTV_RECORDER_HEADER,
|
leo_sobral@2
|
414 |
file_transfer->card_id );
|
leo_sobral@2
|
415 |
gmyth_string_list_append_string (str_list, file_transfer->query);
|
leo_sobral@2
|
416 |
gmyth_string_list_append_string (str_list, g_string_new ("SPAWN_LIVETV"));
|
leo_sobral@2
|
417 |
if (tvchain_id!=NULL) {
|
leo_sobral@2
|
418 |
gmyth_string_list_append_string (str_list, tvchain_id);
|
leo_sobral@2
|
419 |
gmyth_string_list_append_int (str_list, FALSE); // PIP = FALSE (0)
|
leo_sobral@2
|
420 |
}
|
leo_sobral@2
|
421 |
|
leo_sobral@2
|
422 |
gmyth_socket_sendreceive_stringlist ( file_transfer->sock, str_list );
|
leo_sobral@2
|
423 |
|
leo_sobral@2
|
424 |
//GString *str = NULL;
|
leo_sobral@2
|
425 |
|
leo_sobral@2
|
426 |
//if (str_list!=NULL && (str = gmyth_string_list_get_string( str_list, 0 )) != NULL && strcasecmp( str->str, "ok" ) != 0 ) {
|
leo_sobral@2
|
427 |
// g_print( "[%s]\t\tSpawnLiveTV is OK!\n", __FUNCTION__ );
|
leo_sobral@2
|
428 |
//}
|
leo_sobral@2
|
429 |
if (str_list!=NULL)
|
leo_sobral@2
|
430 |
g_object_unref (str_list);
|
leo_sobral@2
|
431 |
|
leo_sobral@2
|
432 |
}
|
leo_sobral@2
|
433 |
|
leo_sobral@2
|
434 |
gboolean
|
leo_sobral@2
|
435 |
myth_file_transfer_is_recording ( MythFileTransfer *file_transfer )
|
leo_sobral@2
|
436 |
{
|
leo_sobral@2
|
437 |
gboolean ret = TRUE;
|
leo_sobral@2
|
438 |
|
leo_sobral@2
|
439 |
GMythStringList *str_list = gmyth_string_list_new ();
|
leo_sobral@2
|
440 |
|
leo_sobral@2
|
441 |
g_debug ( "[%s]\n", __FUNCTION__ );
|
leo_sobral@2
|
442 |
g_static_mutex_lock (&mutex);
|
leo_sobral@2
|
443 |
|
leo_sobral@2
|
444 |
g_string_printf( file_transfer->query, "%s %d", MYTHTV_RECORDER_HEADER,
|
leo_sobral@2
|
445 |
file_transfer->rec_id >= 0 ? file_transfer->rec_id : file_transfer->card_id );
|
leo_sobral@2
|
446 |
gmyth_string_list_append_string (str_list, file_transfer->query);
|
leo_sobral@2
|
447 |
gmyth_string_list_append_string (str_list, g_string_new ("IS_RECORDING"));
|
leo_sobral@2
|
448 |
|
leo_sobral@2
|
449 |
gmyth_socket_sendreceive_stringlist ( file_transfer->control_sock, str_list );
|
leo_sobral@2
|
450 |
|
leo_sobral@2
|
451 |
if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 )
|
leo_sobral@2
|
452 |
{
|
leo_sobral@2
|
453 |
GString *str = NULL;
|
leo_sobral@2
|
454 |
if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp( str->str, "bad" )!= 0 ) {
|
leo_sobral@2
|
455 |
gint is_rec = gmyth_string_list_get_int( str_list, 0 );
|
leo_sobral@2
|
456 |
if ( is_rec != 0 )
|
leo_sobral@2
|
457 |
ret = TRUE;
|
leo_sobral@2
|
458 |
else
|
leo_sobral@2
|
459 |
ret = FALSE;
|
leo_sobral@2
|
460 |
}
|
leo_sobral@2
|
461 |
}
|
leo_sobral@2
|
462 |
g_print( "[%s] %s, stream is %s being recorded!\n", __FUNCTION__, ret ? "YES" : "NO", ret ? "" : "NOT" );
|
leo_sobral@2
|
463 |
g_static_mutex_unlock (&mutex);
|
leo_sobral@2
|
464 |
|
leo_sobral@2
|
465 |
if ( str_list != NULL )
|
leo_sobral@2
|
466 |
g_object_unref (str_list);
|
leo_sobral@2
|
467 |
|
leo_sobral@2
|
468 |
return ret;
|
leo_sobral@2
|
469 |
|
leo_sobral@2
|
470 |
}
|
leo_sobral@2
|
471 |
|
leo_sobral@2
|
472 |
guint64
|
leo_sobral@2
|
473 |
myth_file_transfer_get_file_position ( MythFileTransfer *file_transfer )
|
leo_sobral@2
|
474 |
{
|
leo_sobral@2
|
475 |
guint64 pos = 0;
|
leo_sobral@2
|
476 |
|
leo_sobral@2
|
477 |
GMythStringList *str_list = gmyth_string_list_new ();
|
leo_sobral@2
|
478 |
|
leo_sobral@2
|
479 |
g_debug ( "[%s]\n", __FUNCTION__ );
|
leo_sobral@2
|
480 |
g_static_mutex_lock (&mutex);
|
leo_sobral@2
|
481 |
|
leo_sobral@2
|
482 |
g_string_printf( file_transfer->query, "%s %d", MYTHTV_RECORDER_HEADER,
|
leo_sobral@2
|
483 |
file_transfer->rec_id >= 0 ? file_transfer->rec_id : file_transfer->card_id );
|
leo_sobral@2
|
484 |
|
leo_sobral@2
|
485 |
gmyth_string_list_append_string (str_list, file_transfer->query);
|
leo_sobral@2
|
486 |
gmyth_string_list_append_string (str_list, g_string_new ("GET_FILE_POSITION"));
|
leo_sobral@2
|
487 |
|
leo_sobral@2
|
488 |
gmyth_socket_sendreceive_stringlist ( file_transfer->control_sock, str_list );
|
leo_sobral@2
|
489 |
|
leo_sobral@2
|
490 |
if ( str_list != NULL && gmyth_string_list_length(str_list) > 0 )
|
leo_sobral@2
|
491 |
{
|
leo_sobral@2
|
492 |
GString *str = NULL;
|
leo_sobral@2
|
493 |
if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp ( str->str, "bad" ) != 0 )
|
leo_sobral@2
|
494 |
pos = gmyth_util_decode_long_long( str_list, 0 );
|
leo_sobral@2
|
495 |
}
|
leo_sobral@2
|
496 |
g_static_mutex_unlock (&mutex);
|
leo_sobral@2
|
497 |
|
leo_sobral@2
|
498 |
#ifndef MYTHTV_ENABLE_DEBUG
|
leo_sobral@2
|
499 |
|
leo_sobral@2
|
500 |
g_print( "[%s] Got file position = %llu\n", __FUNCTION__, pos );
|
leo_sobral@2
|
501 |
#endif
|
leo_sobral@2
|
502 |
if (str_list!=NULL)
|
leo_sobral@2
|
503 |
g_object_unref (str_list);
|
leo_sobral@2
|
504 |
|
leo_sobral@2
|
505 |
return pos;
|
leo_sobral@2
|
506 |
|
leo_sobral@2
|
507 |
}
|
leo_sobral@2
|
508 |
|
leo_sobral@2
|
509 |
glong
|
leo_sobral@2
|
510 |
myth_file_transfer_get_recordernum( MythFileTransfer *transfer )
|
leo_sobral@2
|
511 |
{
|
leo_sobral@2
|
512 |
return transfer->recordernum;
|
leo_sobral@2
|
513 |
}
|
leo_sobral@2
|
514 |
|
leo_sobral@2
|
515 |
glong
|
leo_sobral@2
|
516 |
myth_file_transfer_get_filesize( MythFileTransfer *transfer )
|
leo_sobral@2
|
517 |
{
|
leo_sobral@2
|
518 |
return transfer->filesize;
|
leo_sobral@2
|
519 |
}
|
leo_sobral@2
|
520 |
|
leo_sobral@2
|
521 |
gboolean
|
leo_sobral@2
|
522 |
myth_file_transfer_isopen( MythFileTransfer *transfer )
|
leo_sobral@2
|
523 |
{
|
leo_sobral@2
|
524 |
return (transfer->sock != NULL && transfer->control_sock != NULL);
|
leo_sobral@2
|
525 |
}
|
leo_sobral@2
|
526 |
|
leo_sobral@2
|
527 |
void
|
leo_sobral@2
|
528 |
myth_file_transfer_close( MythFileTransfer *transfer )
|
leo_sobral@2
|
529 |
{
|
leo_sobral@2
|
530 |
GMythStringList *strlist;
|
leo_sobral@2
|
531 |
|
leo_sobral@2
|
532 |
if (transfer->control_sock == NULL)
|
leo_sobral@2
|
533 |
return;
|
leo_sobral@2
|
534 |
|
leo_sobral@2
|
535 |
strlist = gmyth_string_list_new( );
|
leo_sobral@2
|
536 |
|
leo_sobral@2
|
537 |
g_string_printf( transfer->query, "%s %d", MYTHTV_QUERY_HEADER,
|
leo_sobral@2
|
538 |
transfer->recordernum );
|
leo_sobral@2
|
539 |
gmyth_string_list_append_string( strlist, transfer->query );
|
leo_sobral@2
|
540 |
gmyth_string_list_append_char_array( strlist, "DONE" );
|
leo_sobral@2
|
541 |
|
leo_sobral@2
|
542 |
|
leo_sobral@2
|
543 |
if ( gmyth_socket_sendreceive_stringlist(transfer->control_sock, strlist) <= 0 )
|
leo_sobral@2
|
544 |
{
|
leo_sobral@2
|
545 |
g_printerr( "Remote file timeout.\n" );
|
leo_sobral@2
|
546 |
}
|
leo_sobral@2
|
547 |
|
leo_sobral@2
|
548 |
if (transfer->sock)
|
leo_sobral@2
|
549 |
{
|
leo_sobral@2
|
550 |
g_object_unref( transfer->sock );
|
leo_sobral@2
|
551 |
transfer->sock = NULL;
|
leo_sobral@2
|
552 |
}
|
leo_sobral@2
|
553 |
|
leo_sobral@2
|
554 |
if (transfer->control_sock)
|
leo_sobral@2
|
555 |
{
|
leo_sobral@2
|
556 |
g_object_unref( transfer->control_sock );
|
leo_sobral@2
|
557 |
transfer->control_sock = NULL;
|
leo_sobral@2
|
558 |
}
|
leo_sobral@2
|
559 |
|
leo_sobral@2
|
560 |
}
|
leo_sobral@2
|
561 |
|
leo_sobral@2
|
562 |
void
|
leo_sobral@2
|
563 |
myth_file_transfer_reset_controlsock( MythFileTransfer *transfer )
|
leo_sobral@2
|
564 |
{
|
leo_sobral@2
|
565 |
if (transfer->control_sock == NULL)
|
leo_sobral@2
|
566 |
{
|
leo_sobral@2
|
567 |
g_printerr( "myth_file_transfer_reset_controlsock(): Called with no control socket" );
|
leo_sobral@2
|
568 |
return;
|
leo_sobral@2
|
569 |
}
|
leo_sobral@2
|
570 |
|
leo_sobral@2
|
571 |
GString *str = gmyth_socket_receive_response( transfer->control_sock );
|
leo_sobral@2
|
572 |
|
leo_sobral@2
|
573 |
g_string_free( str, TRUE );
|
leo_sobral@2
|
574 |
}
|
leo_sobral@2
|
575 |
|
leo_sobral@2
|
576 |
void
|
leo_sobral@2
|
577 |
myth_file_transfer_reset_sock( MythFileTransfer *transfer )
|
leo_sobral@2
|
578 |
{
|
leo_sobral@2
|
579 |
if ( transfer->sock == NULL )
|
leo_sobral@2
|
580 |
{
|
leo_sobral@2
|
581 |
g_printerr( "myth_file_transfer_reset_sock(): Called with no raw socket" );
|
leo_sobral@2
|
582 |
return;
|
leo_sobral@2
|
583 |
}
|
leo_sobral@2
|
584 |
|
leo_sobral@2
|
585 |
GString *str = gmyth_socket_receive_response( transfer->sock );
|
leo_sobral@2
|
586 |
|
leo_sobral@2
|
587 |
g_string_free( str, TRUE );
|
leo_sobral@2
|
588 |
}
|
leo_sobral@2
|
589 |
|
leo_sobral@2
|
590 |
void
|
leo_sobral@2
|
591 |
myth_file_transfer_reset( MythFileTransfer *transfer )
|
leo_sobral@2
|
592 |
{
|
leo_sobral@2
|
593 |
myth_file_transfer_reset_controlsock( transfer );
|
leo_sobral@2
|
594 |
myth_file_transfer_reset_sock( transfer );
|
leo_sobral@2
|
595 |
}
|
leo_sobral@2
|
596 |
|
leo_sobral@2
|
597 |
guint64
|
leo_sobral@2
|
598 |
myth_file_transfer_seek(MythFileTransfer *transfer, guint64 pos, gint whence)
|
leo_sobral@2
|
599 |
{
|
leo_sobral@2
|
600 |
if (transfer->sock == NULL)
|
leo_sobral@2
|
601 |
{
|
leo_sobral@2
|
602 |
g_printerr( "[%s] myth_file_transfer_seek(): Called with no socket", __FUNCTION__ );
|
leo_sobral@2
|
603 |
return 0;
|
leo_sobral@2
|
604 |
}
|
leo_sobral@2
|
605 |
|
leo_sobral@2
|
606 |
if (transfer->control_sock == NULL)
|
leo_sobral@2
|
607 |
return 0;
|
leo_sobral@2
|
608 |
|
leo_sobral@2
|
609 |
// if (!controlSock->isOpen() || controlSock->error())
|
leo_sobral@2
|
610 |
// return 0;
|
leo_sobral@2
|
611 |
|
leo_sobral@2
|
612 |
GMythStringList *strlist = gmyth_string_list_new();
|
leo_sobral@2
|
613 |
g_string_printf (transfer->query, "%s %d", MYTHTV_QUERY_HEADER, transfer->recordernum);
|
rosfran@30
|
614 |
gmyth_string_list_append_string( strlist, transfer->query );
|
leo_sobral@2
|
615 |
gmyth_string_list_append_char_array( strlist, "SEEK" );
|
leo_sobral@2
|
616 |
gmyth_string_list_append_uint64( strlist, pos );
|
rosfran@30
|
617 |
|
rosfran@30
|
618 |
gmyth_string_list_append_int( strlist, whence );
|
leo_sobral@2
|
619 |
|
leo_sobral@2
|
620 |
if (pos > 0 )
|
leo_sobral@2
|
621 |
gmyth_string_list_append_uint64( strlist, pos );
|
leo_sobral@2
|
622 |
else
|
leo_sobral@2
|
623 |
gmyth_string_list_append_uint64( strlist, transfer->readposition );
|
rosfran@30
|
624 |
|
leo_sobral@2
|
625 |
gmyth_socket_sendreceive_stringlist( transfer->control_sock, strlist );
|
leo_sobral@2
|
626 |
|
leo_sobral@2
|
627 |
guint64 retval = gmyth_string_list_get_uint64(strlist, 0);
|
leo_sobral@2
|
628 |
transfer->readposition = retval;
|
leo_sobral@2
|
629 |
g_print( "[%s] got reading position pointer from the streaming = %llu\n",
|
leo_sobral@2
|
630 |
__FUNCTION__, retval );
|
leo_sobral@2
|
631 |
|
leo_sobral@2
|
632 |
//myth_file_transfer_reset( transfer );
|
leo_sobral@2
|
633 |
|
leo_sobral@2
|
634 |
return retval;
|
leo_sobral@2
|
635 |
}
|
leo_sobral@2
|
636 |
|
leo_sobral@2
|
637 |
static gboolean
|
leo_sobral@2
|
638 |
myth_control_sock_listener( GIOChannel *source, GIOCondition condition, gpointer data )
|
leo_sobral@2
|
639 |
{
|
leo_sobral@2
|
640 |
|
leo_sobral@2
|
641 |
GIOStatus ret;
|
leo_sobral@2
|
642 |
GError *err = NULL;
|
leo_sobral@2
|
643 |
gchar *msg = g_strdup("");
|
leo_sobral@2
|
644 |
|
leo_sobral@2
|
645 |
gsize len;
|
leo_sobral@2
|
646 |
if (condition & G_IO_HUP)
|
leo_sobral@2
|
647 |
g_error ("Read end of pipe died!\n");
|
leo_sobral@2
|
648 |
ret = g_io_channel_read_line ( source, &msg, &len, NULL, &err);
|
leo_sobral@2
|
649 |
if ( ret == G_IO_STATUS_ERROR )
|
leo_sobral@2
|
650 |
g_error ("[%s] Error reading: %s\n", __FUNCTION__, err != NULL ? err->message : "" );
|
leo_sobral@2
|
651 |
g_print ("\n\n\n\n\n\n[%s]\t\tEVENT: Read %u bytes: %s\n\n\n\n\n", __FUNCTION__, len, msg != NULL ? msg : "" );
|
leo_sobral@2
|
652 |
if ( msg != NULL )
|
leo_sobral@2
|
653 |
g_free (msg);
|
leo_sobral@2
|
654 |
|
leo_sobral@2
|
655 |
return TRUE;
|
leo_sobral@2
|
656 |
|
leo_sobral@2
|
657 |
}
|
leo_sobral@2
|
658 |
|
leo_sobral@2
|
659 |
static void*
|
leo_sobral@2
|
660 |
myth_init_io_watchers( void *data )
|
leo_sobral@2
|
661 |
{
|
leo_sobral@2
|
662 |
MythFileTransfer *transfer = (MythFileTransfer*)data;
|
leo_sobral@2
|
663 |
GMainContext *context = g_main_context_new();
|
leo_sobral@2
|
664 |
GMainLoop *loop = g_main_loop_new( NULL, FALSE );
|
leo_sobral@2
|
665 |
|
leo_sobral@2
|
666 |
GSource *source = NULL;
|
leo_sobral@2
|
667 |
|
leo_sobral@2
|
668 |
if ( transfer->event_sock->sd_io_ch != NULL )
|
leo_sobral@2
|
669 |
source = g_io_create_watch( transfer->event_sock->sd_io_ch, G_IO_IN | G_IO_HUP );
|
leo_sobral@2
|
670 |
|
leo_sobral@2
|
671 |
g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL );
|
leo_sobral@2
|
672 |
|
leo_sobral@2
|
673 |
g_source_attach( source, context );
|
leo_sobral@2
|
674 |
|
leo_sobral@2
|
675 |
if (source==NULL)
|
leo_sobral@2
|
676 |
g_printerr( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
|
leo_sobral@2
|
677 |
|
leo_sobral@2
|
678 |
g_main_loop_run( loop );
|
leo_sobral@2
|
679 |
|
leo_sobral@2
|
680 |
g_source_unref( source );
|
leo_sobral@2
|
681 |
|
leo_sobral@2
|
682 |
g_main_loop_unref( loop );
|
leo_sobral@2
|
683 |
|
leo_sobral@2
|
684 |
g_main_context_unref( context );
|
leo_sobral@2
|
685 |
|
leo_sobral@2
|
686 |
return NULL;
|
leo_sobral@2
|
687 |
}
|
leo_sobral@2
|
688 |
|
rosfran@34
|
689 |
gint
|
leo_sobral@2
|
690 |
myth_file_transfer_read(MythFileTransfer *transfer, void *data, gint size, gboolean read_unlimited)
|
leo_sobral@2
|
691 |
{
|
leo_sobral@2
|
692 |
gint recv = 0;
|
leo_sobral@2
|
693 |
gsize bytes_read = 0;
|
leo_sobral@2
|
694 |
gint sent = 0;
|
rosfran@34
|
695 |
guint remaining = 0;
|
leo_sobral@2
|
696 |
gboolean response = FALSE;
|
leo_sobral@2
|
697 |
|
leo_sobral@2
|
698 |
GIOChannel *io_channel;
|
leo_sobral@2
|
699 |
GIOChannel *io_channel_control;
|
leo_sobral@2
|
700 |
|
leo_sobral@2
|
701 |
GIOCondition io_cond;
|
leo_sobral@2
|
702 |
GIOCondition io_cond_control;
|
leo_sobral@2
|
703 |
GIOStatus io_status = G_IO_STATUS_NORMAL, io_status_control = G_IO_STATUS_NORMAL;
|
leo_sobral@2
|
704 |
|
leo_sobral@2
|
705 |
gint buf_len = MYTHTV_BUFFER_SIZE;
|
leo_sobral@2
|
706 |
|
leo_sobral@2
|
707 |
GMythStringList *strlist = NULL;
|
leo_sobral@2
|
708 |
GError *error = NULL;
|
leo_sobral@2
|
709 |
|
leo_sobral@2
|
710 |
gchar *trash = g_strdup("");
|
leo_sobral@2
|
711 |
|
leo_sobral@2
|
712 |
g_return_val_if_fail ( data != NULL, -2 );
|
leo_sobral@2
|
713 |
|
leo_sobral@2
|
714 |
/* gets the size of the entire file, if the size requested is lesser than 0 */
|
leo_sobral@2
|
715 |
if ( size <= 0 )
|
leo_sobral@2
|
716 |
size = transfer->filesize;
|
leo_sobral@2
|
717 |
|
leo_sobral@2
|
718 |
io_channel = transfer->sock->sd_io_ch;
|
leo_sobral@2
|
719 |
io_channel_control = transfer->control_sock->sd_io_ch;
|
leo_sobral@2
|
720 |
|
leo_sobral@2
|
721 |
//g_io_channel_set_flags( io_channel, G_IO_FLAG_APPEND |
|
leo_sobral@2
|
722 |
// G_IO_STATUS_AGAIN | G_IO_FLAG_IS_READABLE | G_IO_FLAG_IS_WRITEABLE |
|
leo_sobral@2
|
723 |
// G_IO_FLAG_IS_SEEKABLE, NULL );
|
leo_sobral@2
|
724 |
|
leo_sobral@2
|
725 |
io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
|
leo_sobral@2
|
726 |
if ( io_status == G_IO_STATUS_NORMAL )
|
leo_sobral@2
|
727 |
g_print( "[%s] Setting encoding to binary data socket).\n", __FUNCTION__ );
|
leo_sobral@2
|
728 |
|
leo_sobral@2
|
729 |
io_cond = g_io_channel_get_buffer_condition( io_channel );
|
leo_sobral@2
|
730 |
|
leo_sobral@2
|
731 |
io_cond_control = g_io_channel_get_buffer_condition( io_channel );
|
leo_sobral@2
|
732 |
|
leo_sobral@2
|
733 |
if ( transfer->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) )
|
leo_sobral@2
|
734 |
{
|
leo_sobral@2
|
735 |
g_printerr( "myth_file_transfer_read(): Called with no raw socket.\n" );
|
leo_sobral@2
|
736 |
recv = -1;
|
leo_sobral@2
|
737 |
goto cleanup;
|
leo_sobral@2
|
738 |
}
|
leo_sobral@2
|
739 |
|
leo_sobral@2
|
740 |
if ( transfer->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) )
|
leo_sobral@2
|
741 |
{
|
leo_sobral@2
|
742 |
g_printerr( "myth_file_transfer_read(): Called with no control socket.\n" );
|
leo_sobral@2
|
743 |
recv = -1;
|
leo_sobral@2
|
744 |
goto cleanup;
|
leo_sobral@2
|
745 |
}
|
leo_sobral@2
|
746 |
|
leo_sobral@2
|
747 |
/*
|
leo_sobral@2
|
748 |
if (!controlSock->isOpen() || controlSock->error())
|
leo_sobral@2
|
749 |
return -1;
|
leo_sobral@2
|
750 |
*/
|
leo_sobral@2
|
751 |
|
leo_sobral@2
|
752 |
if ( ( io_cond & G_IO_IN ) != 0 ) {
|
leo_sobral@2
|
753 |
do
|
leo_sobral@2
|
754 |
{
|
rosfran@34
|
755 |
trash = g_new0( gchar, MYTHTV_BUFFER_SIZE );
|
leo_sobral@2
|
756 |
|
rosfran@34
|
757 |
io_status = g_io_channel_read_chars( io_channel, trash,
|
rosfran@34
|
758 |
MYTHTV_BUFFER_SIZE, &bytes_read, &error);
|
leo_sobral@2
|
759 |
|
rosfran@34
|
760 |
g_print( "[%s] cleaning buffer on IO binary channel... %d bytes gone!\n",
|
rosfran@34
|
761 |
__FUNCTION__, bytes_read );
|
rosfran@34
|
762 |
|
rosfran@34
|
763 |
if ( trash != NULL )
|
rosfran@34
|
764 |
g_free( trash );
|
rosfran@34
|
765 |
|
leo_sobral@2
|
766 |
io_cond = g_io_channel_get_buffer_condition( io_channel );
|
leo_sobral@2
|
767 |
|
rosfran@34
|
768 |
} while ( ( io_cond & G_IO_IN ) != 0 && ( io_status != G_IO_STATUS_ERROR ) && (error == NULL) );
|
leo_sobral@2
|
769 |
|
rosfran@34
|
770 |
//if ( trash!= NULL )
|
rosfran@34
|
771 |
// g_free( trash );
|
leo_sobral@2
|
772 |
}
|
leo_sobral@2
|
773 |
|
leo_sobral@2
|
774 |
if ( ( io_cond_control & G_IO_IN ) != 0 ) {
|
leo_sobral@2
|
775 |
GMythStringList *strlist_tmp = gmyth_string_list_new();
|
leo_sobral@2
|
776 |
gmyth_socket_read_stringlist( transfer->control_sock, strlist_tmp );
|
leo_sobral@2
|
777 |
g_object_unref( strlist_tmp );
|
leo_sobral@2
|
778 |
}
|
leo_sobral@2
|
779 |
|
leo_sobral@2
|
780 |
wait_to_transfer = 0;
|
leo_sobral@2
|
781 |
|
rosfran@30
|
782 |
//while ( transfer->live_tv && ( myth_file_transfer_get_file_position( transfer ) < 4096 ) &&
|
rosfran@30
|
783 |
// wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS )
|
rosfran@30
|
784 |
// g_usleep( 1000*50 ); /* waits just for 2/10 second */
|
leo_sobral@2
|
785 |
|
leo_sobral@2
|
786 |
//g_thread_create( myth_init_io_watchers, (void*)transfer, FALSE, NULL );
|
leo_sobral@2
|
787 |
//g_printerr( "[%s] Watch listener function to the IO control channel on thread %p.\n", __FUNCTION__, g_thread_self() );
|
leo_sobral@2
|
788 |
|
rosfran@30
|
789 |
//g_static_mutex_lock (&mutex);
|
rosfran@30
|
790 |
//strlist = gmyth_string_list_new();
|
leo_sobral@2
|
791 |
|
rosfran@31
|
792 |
g_string_printf ( transfer->query, "%s %d",
|
rosfran@31
|
793 |
/*transfer->live_tv ? MYTHTV_RECORDER_HEADER :*/ MYTHTV_QUERY_HEADER,
|
leo_sobral@2
|
794 |
/* transfer->live_tv ? transfer->card_id :*/ transfer->recordernum ); // transfer->recordernum
|
leo_sobral@2
|
795 |
g_print( "\t[%s] Transfer_query = %s\n", __FUNCTION__, transfer->query->str );
|
rosfran@30
|
796 |
|
leo_sobral@2
|
797 |
sent = size;
|
rosfran@34
|
798 |
remaining = size - recv;
|
rosfran@30
|
799 |
//g_static_mutex_unlock( &mutex );
|
leo_sobral@2
|
800 |
//data = (void*)g_new0( gchar, size );
|
leo_sobral@2
|
801 |
|
rosfran@30
|
802 |
//g_io_channel_flush( io_channel, NULL );
|
rosfran@30
|
803 |
|
rosfran@34
|
804 |
//g_static_mutex_lock( &mutex );
|
leo_sobral@2
|
805 |
|
leo_sobral@2
|
806 |
io_cond = g_io_channel_get_buffer_condition( io_channel );
|
leo_sobral@2
|
807 |
|
rosfran@34
|
808 |
while ( recv < size && !response )//&& ( io_cond & G_IO_IN ) != 0 )
|
leo_sobral@2
|
809 |
{
|
rosfran@34
|
810 |
g_io_channel_flush( io_channel_control, NULL );
|
rosfran@34
|
811 |
|
rosfran@34
|
812 |
strlist = gmyth_string_list_new();
|
rosfran@34
|
813 |
gmyth_string_list_append_char_array( strlist, transfer->query->str );
|
rosfran@34
|
814 |
gmyth_string_list_append_char_array( strlist,
|
rosfran@34
|
815 |
/*transfer->live_tv ? "REQUEST_BLOCK_RINGBUF" :*/ "REQUEST_BLOCK" );
|
rosfran@34
|
816 |
gmyth_string_list_append_int( strlist, remaining );
|
rosfran@34
|
817 |
gmyth_socket_write_stringlist( transfer->control_sock, strlist );
|
rosfran@34
|
818 |
|
rosfran@34
|
819 |
guint count_bytes = 0;
|
rosfran@34
|
820 |
|
leo_sobral@2
|
821 |
do
|
leo_sobral@2
|
822 |
{
|
rosfran@34
|
823 |
//buf_len = ( sent - recv ) > MYTHTV_BUFFER_SIZE ? MYTHTV_BUFFER_SIZE : ( sent - recv );
|
rosfran@34
|
824 |
if ( remaining > MYTHTV_BUFFER_SIZE ) {
|
rosfran@34
|
825 |
buf_len = MYTHTV_BUFFER_SIZE;
|
rosfran@34
|
826 |
} else {
|
rosfran@34
|
827 |
buf_len = remaining;
|
rosfran@34
|
828 |
}
|
rosfran@34
|
829 |
|
rosfran@34
|
830 |
bytes_read = 0;
|
leo_sobral@2
|
831 |
|
leo_sobral@2
|
832 |
io_status = g_io_channel_read_chars( io_channel, data + recv,
|
rosfran@30
|
833 |
buf_len, &bytes_read, &error );
|
rosfran@31
|
834 |
|
rosfran@31
|
835 |
//g_static_mutex_unlock( &mutex );
|
leo_sobral@2
|
836 |
/*
|
leo_sobral@2
|
837 |
GString *sss = g_string_new("");
|
leo_sobral@2
|
838 |
sss = g_string_append_len( sss, (gchar*)data+recv, bytes_read );
|
leo_sobral@2
|
839 |
|
leo_sobral@2
|
840 |
g_print( "[%s] Reading buffer (length = %d)\n", __FUNCTION__, bytes_read);
|
leo_sobral@2
|
841 |
*/
|
leo_sobral@2
|
842 |
if ( bytes_read > 0 )
|
leo_sobral@2
|
843 |
{
|
rosfran@34
|
844 |
//if ( bytes_read <= buf_len )
|
rosfran@34
|
845 |
recv += bytes_read;
|
rosfran@34
|
846 |
count_bytes += bytes_read;
|
rosfran@34
|
847 |
remaining -= bytes_read;
|
rosfran@34
|
848 |
g_print( "[%s] Reading buffer (bytes read = %d, remaining = %d)\n", __FUNCTION__, bytes_read, remaining );
|
rosfran@34
|
849 |
if ( remaining == 0 ) {
|
rosfran@34
|
850 |
break;
|
rosfran@34
|
851 |
}
|
rosfran@34
|
852 |
} else {
|
rosfran@34
|
853 |
break;
|
rosfran@34
|
854 |
}
|
rosfran@34
|
855 |
|
rosfran@34
|
856 |
//if ( remaining > 0 ) {
|
leo_sobral@2
|
857 |
|
leo_sobral@2
|
858 |
if ( io_status == G_IO_STATUS_EOF ) {
|
rosfran@34
|
859 |
g_print( "[%s] got EOS!", __FUNCTION__ );
|
leo_sobral@2
|
860 |
break;
|
leo_sobral@2
|
861 |
} else if ( io_status == G_IO_STATUS_ERROR ) {
|
rosfran@34
|
862 |
g_print( "[%s] myth_file_transfer_read(): socket error.\n", __FUNCTION__ );
|
leo_sobral@2
|
863 |
break;
|
leo_sobral@2
|
864 |
}
|
rosfran@34
|
865 |
//}
|
leo_sobral@2
|
866 |
|
leo_sobral@2
|
867 |
/* increase buffer size, to allow get more data (do not obey to the buffer size) */
|
leo_sobral@2
|
868 |
if ( read_unlimited == TRUE ) {
|
rosfran@34
|
869 |
// FOR NOW, DO NOTHING!!!
|
leo_sobral@2
|
870 |
//if ( recv > buf_len )
|
leo_sobral@2
|
871 |
// sent += (bytes_read - buf_len) + 1;
|
leo_sobral@2
|
872 |
}
|
leo_sobral@2
|
873 |
|
leo_sobral@2
|
874 |
/* verify if the input (read) buffer is ready to receive data */
|
leo_sobral@2
|
875 |
io_cond = g_io_channel_get_buffer_condition( io_channel );
|
leo_sobral@2
|
876 |
|
leo_sobral@2
|
877 |
g_print( "[%s]\t io_cond %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__,
|
leo_sobral@2
|
878 |
( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" );
|
rosfran@34
|
879 |
|
rosfran@34
|
880 |
//if ( recv == size )
|
rosfran@34
|
881 |
//break;
|
leo_sobral@2
|
882 |
|
rosfran@34
|
883 |
} while ( remaining > 0 );//&& ( io_status == G_IO_STATUS_NORMAL ) );
|
rosfran@34
|
884 |
|
rosfran@34
|
885 |
// if ( ( recv < size ) ) {
|
rosfran@34
|
886 |
// finish_read = FALSE;
|
rosfran@34
|
887 |
//}
|
leo_sobral@2
|
888 |
|
leo_sobral@2
|
889 |
io_cond_control = g_io_channel_get_buffer_condition( io_channel_control );
|
rosfran@34
|
890 |
if ( remaining == 0 )//( io_cond_control & G_IO_IN ) != 0 )
|
leo_sobral@2
|
891 |
{
|
leo_sobral@2
|
892 |
gmyth_socket_read_stringlist( transfer->control_sock, strlist );
|
rosfran@34
|
893 |
if ( strlist != NULL && gmyth_string_list_length( strlist ) > 0 )
|
rosfran@34
|
894 |
{
|
rosfran@34
|
895 |
sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error
|
rosfran@34
|
896 |
g_print( "[%s] got SENT buffer message = %d\n", __FUNCTION__, sent );
|
rosfran@34
|
897 |
if ( sent != 0 )
|
rosfran@34
|
898 |
{
|
rosfran@34
|
899 |
g_print( "[%s]\t received = %d bytes, backend says %d bytes sent, "\
|
rosfran@34
|
900 |
"io_cond %s prepared for reading! (G_IO_IN) !!!\n\n", __FUNCTION__,
|
rosfran@34
|
901 |
recv, sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" );
|
leo_sobral@2
|
902 |
|
rosfran@34
|
903 |
if ( sent == count_bytes )
|
rosfran@34
|
904 |
{
|
rosfran@34
|
905 |
response = ( recv == size );
|
rosfran@34
|
906 |
g_print( "[%s]\t\tsent %d, which is equals to bytes_read = %d\n\n",
|
rosfran@34
|
907 |
__FUNCTION__, sent, count_bytes );
|
rosfran@34
|
908 |
if ( response == TRUE )
|
rosfran@34
|
909 |
break;
|
rosfran@34
|
910 |
}
|
rosfran@34
|
911 |
else
|
rosfran@34
|
912 |
{
|
rosfran@34
|
913 |
g_print( "[%s]\t\tsent %d, which is NOT equals to bytes_read = %d\n\n",
|
rosfran@34
|
914 |
__FUNCTION__, sent, count_bytes );
|
rosfran@34
|
915 |
goto cleanup;
|
rosfran@34
|
916 |
//response = FALSE;
|
rosfran@34
|
917 |
//break;
|
rosfran@34
|
918 |
}
|
rosfran@34
|
919 |
} else {
|
rosfran@34
|
920 |
break;
|
rosfran@34
|
921 |
//goto cleanup;
|
rosfran@34
|
922 |
} // if
|
rosfran@34
|
923 |
} // if - reading control response from backend
|
rosfran@34
|
924 |
} else {
|
rosfran@34
|
925 |
response = FALSE;
|
rosfran@34
|
926 |
} // if - stringlist response
|
rosfran@34
|
927 |
|
rosfran@34
|
928 |
} // while
|
rosfran@34
|
929 |
|
rosfran@34
|
930 |
io_cond_control = g_io_channel_get_buffer_condition( io_channel_control );
|
rosfran@34
|
931 |
// io_cond = g_io_channel_get_buffer_condition( io_channel );
|
rosfran@34
|
932 |
|
rosfran@34
|
933 |
if ( ( ( io_cond_control & G_IO_IN ) != 0 ) &&
|
rosfran@34
|
934 |
( response || ( recv == size ) ) )
|
leo_sobral@2
|
935 |
{
|
leo_sobral@2
|
936 |
if ( gmyth_socket_read_stringlist( transfer->control_sock, strlist ) > 0 )
|
leo_sobral@2
|
937 |
{
|
rosfran@34
|
938 |
if ( strlist != NULL && gmyth_string_list_length(strlist) > 0 )
|
rosfran@34
|
939 |
{
|
rosfran@34
|
940 |
sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error
|
rosfran@34
|
941 |
g_print( "[%s]\t received = %d bytes -\tNOW returning from reading buffer I/O socket "\
|
rosfran@34
|
942 |
"[%s prepared for reading]! (G_IO_IN) !!!\n\n", __FUNCTION__,
|
rosfran@34
|
943 |
sent, ( ( io_cond & G_IO_IN ) != 0 ) ? "IS" : "IS NOT" );
|
leo_sobral@2
|
944 |
}
|
leo_sobral@2
|
945 |
}
|
leo_sobral@2
|
946 |
else
|
leo_sobral@2
|
947 |
{
|
leo_sobral@2
|
948 |
g_printerr ( "myth_file_transfer_read(): No response from control socket.");
|
rosfran@31
|
949 |
recv = -1;
|
rosfran@31
|
950 |
}
|
rosfran@31
|
951 |
|
rosfran@34
|
952 |
}
|
rosfran@34
|
953 |
else if ( error != NULL )
|
rosfran@34
|
954 |
{
|
rosfran@31
|
955 |
g_printerr( "[%s] Error occurred: (%d, %s)\n", __FUNCTION__, error->code, error->message );
|
rosfran@34
|
956 |
}
|
leo_sobral@2
|
957 |
|
leo_sobral@2
|
958 |
cleanup:
|
rosfran@34
|
959 |
//g_static_mutex_unlock (&mutex);
|
leo_sobral@2
|
960 |
|
leo_sobral@2
|
961 |
if ( trash != NULL )
|
leo_sobral@2
|
962 |
g_free( trash );
|
leo_sobral@2
|
963 |
|
leo_sobral@2
|
964 |
if ( strlist != NULL )
|
leo_sobral@2
|
965 |
g_object_unref( strlist );
|
leo_sobral@2
|
966 |
|
leo_sobral@2
|
967 |
g_print( "myth_file_transfer_read(): reqd=%d, rcvd=%d, rept=%d, "\
|
leo_sobral@2
|
968 |
"(rcvd and rept MUST be the same!)\n", size,
|
leo_sobral@2
|
969 |
recv, sent );
|
leo_sobral@2
|
970 |
|
rosfran@34
|
971 |
//if ( ( recv != size ) || ( sent != size ) ) {
|
rosfran@34
|
972 |
//recv = size;
|
leo_sobral@2
|
973 |
//}
|
leo_sobral@2
|
974 |
|
rosfran@30
|
975 |
if ( error != NULL ) {
|
rosfran@31
|
976 |
g_printerr( "Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message,
|
leo_sobral@2
|
977 |
error->code );
|
rosfran@30
|
978 |
g_error_free( error );
|
rosfran@30
|
979 |
}
|
leo_sobral@2
|
980 |
|
leo_sobral@2
|
981 |
return recv;
|
leo_sobral@2
|
982 |
}
|
leo_sobral@2
|
983 |
|
rosfran@31
|
984 |
void
|
leo_sobral@2
|
985 |
myth_file_transfer_settimeout( MythFileTransfer *transfer, gboolean fast )
|
leo_sobral@2
|
986 |
{
|
leo_sobral@2
|
987 |
|
leo_sobral@2
|
988 |
GMythStringList *strlist = NULL;
|
leo_sobral@2
|
989 |
|
leo_sobral@2
|
990 |
if ( transfer->timeoutisfast == fast )
|
leo_sobral@2
|
991 |
return;
|
leo_sobral@2
|
992 |
|
leo_sobral@2
|
993 |
if ( transfer->sock == NULL )
|
leo_sobral@2
|
994 |
{
|
leo_sobral@2
|
995 |
g_printerr( "myth_file_transfer_settimeout(): Called with no socket" );
|
leo_sobral@2
|
996 |
return;
|
leo_sobral@2
|
997 |
}
|
leo_sobral@2
|
998 |
|
leo_sobral@2
|
999 |
if ( transfer->control_sock == NULL )
|
leo_sobral@2
|
1000 |
return;
|
leo_sobral@2
|
1001 |
|
leo_sobral@2
|
1002 |
strlist = gmyth_string_list_new();
|
leo_sobral@2
|
1003 |
gmyth_string_list_append_string( strlist, transfer->query );
|
leo_sobral@2
|
1004 |
gmyth_string_list_append_char_array( strlist, "SET_TIMEOUT" );
|
leo_sobral@2
|
1005 |
gmyth_string_list_append_int( strlist, fast );
|
leo_sobral@2
|
1006 |
|
leo_sobral@2
|
1007 |
gmyth_socket_write_stringlist( transfer->control_sock, strlist );
|
leo_sobral@2
|
1008 |
gmyth_socket_read_stringlist( transfer->control_sock, strlist );
|
leo_sobral@2
|
1009 |
|
leo_sobral@2
|
1010 |
transfer->timeoutisfast = fast;
|
leo_sobral@2
|
1011 |
|
leo_sobral@2
|
1012 |
}
|
leo_sobral@2
|
1013 |
|
leo_sobral@2
|
1014 |
#ifdef DO_TESTING
|
leo_sobral@2
|
1015 |
|
leo_sobral@2
|
1016 |
int
|
leo_sobral@2
|
1017 |
main( int argc, char *argv[] )
|
leo_sobral@2
|
1018 |
{
|
leo_sobral@2
|
1019 |
g_type_init();
|
leo_sobral@2
|
1020 |
|
leo_sobral@2
|
1021 |
MythFileTransfer *file_transfer = myth_file_transfer_new( 1,
|
leo_sobral@2
|
1022 |
g_string_new("myth://192.168.1.109:6543/jshks.nuv"), -1, MYTHTV_VERSION );
|
leo_sobral@2
|
1023 |
myth_file_transfer_setup( &file_transfer );
|
leo_sobral@2
|
1024 |
gchar *data = g_strdup("");
|
leo_sobral@2
|
1025 |
|
leo_sobral@2
|
1026 |
gint num = myth_file_transfer_read( file_transfer, data, -1 );
|
leo_sobral@2
|
1027 |
|
leo_sobral@2
|
1028 |
return 0;
|
leo_sobral@2
|
1029 |
|
leo_sobral@2
|
1030 |
}
|
leo_sobral@2
|
1031 |
|
leo_sobral@2
|
1032 |
#endif
|