1.1 --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Thu Feb 15 14:07:50 2007 +0000
1.2 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Thu Feb 15 14:33:08 2007 +0000
1.3 @@ -48,483 +48,558 @@
1.4 /* maximum number of bytes to be requested to the MythTV backend ( 64 Kbytes ) */
1.5 #define MYTHTV_MAX_REQUEST_SIZE 1024*64
1.6
1.7 -static GnomeVFSResult do_read (GnomeVFSMethod *method,
1.8 - GnomeVFSMethodHandle *method_handle,
1.9 - gpointer buffer,
1.10 - GnomeVFSFileSize num_bytes,
1.11 - GnomeVFSFileSize *bytes_read,
1.12 - GnomeVFSContext *context);
1.13 +static GnomeVFSResult do_read (GnomeVFSMethod * method,
1.14 + GnomeVFSMethodHandle * method_handle,
1.15 + gpointer buffer,
1.16 + GnomeVFSFileSize num_bytes,
1.17 + GnomeVFSFileSize * bytes_read,
1.18 + GnomeVFSContext * context);
1.19
1.20 typedef struct {
1.21 - GMythFileTransfer *file_transfer;
1.22 - GMythLiveTV *livetv;
1.23 - gchar *channel_name;
1.24 -
1.25 - gint mythtv_version;
1.26 - gint64 content_size;
1.27 - guint64 bytes_read;
1.28 + GMythFileTransfer *file_transfer;
1.29 + GMythLiveTV *livetv;
1.30 + gchar *channel_name;
1.31
1.32 - GByteArray *buffer;
1.33 - gsize buffer_remain;
1.34 - gboolean is_livetv;
1.35 -
1.36 - gboolean configured;
1.37 -
1.38 + gint mythtv_version;
1.39 + gint64 content_size;
1.40 + guint64 bytes_read;
1.41 +
1.42 + GByteArray *buffer;
1.43 + gsize buffer_remain;
1.44 + gboolean is_livetv;
1.45 +
1.46 + gboolean configured;
1.47 +
1.48 } MythtvHandle;
1.49
1.50 //static MythtvHandle *myth_handle = NULL;
1.51
1.52 static GnomeVFSResult
1.53 -do_open (GnomeVFSMethod *method,
1.54 - GnomeVFSMethodHandle **method_handle,
1.55 - GnomeVFSURI *uri,
1.56 - GnomeVFSOpenMode mode,
1.57 - GnomeVFSContext *context)
1.58 -{
1.59 - MythtvHandle *myth_handle = NULL;
1.60 - GMythBackendInfo *backend_info = NULL;
1.61 - GMythURI *gmyth_uri = NULL;
1.62 - gboolean ret = TRUE;
1.63 +do_open (GnomeVFSMethod * method,
1.64 + GnomeVFSMethodHandle ** method_handle,
1.65 + GnomeVFSURI * uri,
1.66 + GnomeVFSOpenMode mode, GnomeVFSContext * context)
1.67 +{
1.68 + MythtvHandle *myth_handle = NULL;
1.69 + GMythBackendInfo *backend_info = NULL;
1.70 + GMythURI *gmyth_uri = NULL;
1.71 + gboolean ret = TRUE;
1.72
1.73 - _GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL);
1.74 - _GNOME_VFS_METHOD_PARAM_CHECK (uri != NULL);
1.75 + _GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL);
1.76 + _GNOME_VFS_METHOD_PARAM_CHECK (uri != NULL);
1.77
1.78 - if (mode & GNOME_VFS_OPEN_WRITE) {
1.79 - return GNOME_VFS_ERROR_NOT_PERMITTED;
1.80 - }
1.81 + if (mode & GNOME_VFS_OPEN_WRITE) {
1.82 + return GNOME_VFS_ERROR_NOT_PERMITTED;
1.83 + }
1.84
1.85 - if (gnome_vfs_uri_get_host_name (uri) == NULL) {
1.86 - return GNOME_VFS_ERROR_INVALID_HOST_NAME;
1.87 - }
1.88 -
1.89 - /*
1.90 - if ( method_handle != NULL && *method_handle != NULL )
1.91 - {
1.92 - myth_handle = (MythtvHandle*)*method_handle;
1.93 - //if ( !myth_handle->configured )
1.94 - }
1.95 - */
1.96 -
1.97 - if ( ( NULL == myth_handle ) || !myth_handle->configured ) {
1.98 - myth_handle = g_new0 (MythtvHandle, 1);
1.99 -
1.100 - myth_handle->configured = FALSE;
1.101 -
1.102 - myth_handle->is_livetv = FALSE;
1.103 -
1.104 - /* Initialize mythtv handler*/
1.105 - myth_handle->file_transfer = NULL;
1.106 - myth_handle->livetv = NULL;
1.107 - myth_handle->mythtv_version = MYTHTV_VERSION_DEFAULT;
1.108 - myth_handle->bytes_read = 0;
1.109 - myth_handle->content_size = (GnomeVFSFileSize) - 1;
1.110 -
1.111 - /* Creates and fills out the backend info structure */
1.112 - backend_info = gmyth_backend_info_new_with_uri (
1.113 - gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
1.114 -
1.115 - /* creates an instance of */
1.116 - gmyth_uri = gmyth_uri_new_with_value(
1.117 - gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
1.118 -
1.119 - myth_handle->is_livetv = gmyth_uri_is_livetv( gmyth_uri );
1.120 -
1.121 - /* Connect to the backend */
1.122 - if ( gmyth_uri != NULL && myth_handle->is_livetv == TRUE ) {
1.123 -
1.124 - if ( NULL == myth_handle->livetv )
1.125 - {
1.126 - myth_handle->livetv = gmyth_livetv_new ();
1.127 -
1.128 - myth_handle->channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.129 -
1.130 - g_debug( "[%s] Channel name = %s\n", __FUNCTION__, myth_handle->channel_name );
1.131 -
1.132 - if ( myth_handle->channel_name != NULL ) {
1.133 - if (gmyth_livetv_channel_name_setup (myth_handle->livetv, myth_handle->channel_name,
1.134 - backend_info) == FALSE) {
1.135 - g_object_unref( gmyth_uri );
1.136 - ret = FALSE;
1.137 - }
1.138 - } else {
1.139 - if ( gmyth_livetv_setup (myth_handle->livetv, backend_info) == FALSE ) {
1.140 - g_object_unref( gmyth_uri );
1.141 - ret = FALSE;
1.142 - }
1.143 - }
1.144 - }
1.145 -
1.146 - if ( NULL == myth_handle->file_transfer ) {
1.147 - myth_handle->file_transfer = gmyth_livetv_create_file_transfer (myth_handle->livetv);
1.148 -
1.149 - if (NULL == myth_handle->file_transfer) {
1.150 - ret = FALSE;
1.151 - g_debug ("MythTV FileTransfer is NULL!\n");
1.152 - return GNOME_VFS_ERROR_NOT_OPEN;
1.153 - }
1.154 -
1.155 - if ( !gmyth_file_transfer_open( myth_handle->file_transfer, myth_handle->livetv->uri != NULL ?
1.156 - gmyth_uri_get_path(myth_handle->livetv->uri) :
1.157 - myth_handle->livetv->proginfo->pathname->str ) )
1.158 - {
1.159 - g_debug ("Couldn't open MythTV FileTransfer is NULL!\n");
1.160 - g_object_unref( myth_handle->file_transfer );
1.161 - myth_handle->file_transfer = NULL;
1.162 + if (gnome_vfs_uri_get_host_name (uri) == NULL) {
1.163 + return GNOME_VFS_ERROR_INVALID_HOST_NAME;
1.164 + }
1.165 +
1.166 + /*
1.167 + if ( method_handle != NULL && *method_handle != NULL )
1.168 + {
1.169 + myth_handle = (MythtvHandle*)*method_handle;
1.170 + //if ( !myth_handle->configured )
1.171 + }
1.172 + */
1.173 +
1.174 + if ((NULL == myth_handle) || !myth_handle->configured) {
1.175 + myth_handle = g_new0 (MythtvHandle, 1);
1.176 +
1.177 + myth_handle->configured = FALSE;
1.178 +
1.179 + myth_handle->is_livetv = FALSE;
1.180 +
1.181 + /* Initialize mythtv handler */
1.182 + myth_handle->file_transfer = NULL;
1.183 + myth_handle->livetv = NULL;
1.184 + myth_handle->mythtv_version = MYTHTV_VERSION_DEFAULT;
1.185 + myth_handle->bytes_read = 0;
1.186 + myth_handle->content_size = (GnomeVFSFileSize) - 1;
1.187 +
1.188 + /* Creates and fills out the backend info structure */
1.189 + backend_info =
1.190 + gmyth_backend_info_new_with_uri
1.191 + (gnome_vfs_unescape_string
1.192 + (gnome_vfs_uri_to_string
1.193 + (uri, GNOME_VFS_URI_HIDE_NONE), ""));
1.194 +
1.195 + /* creates an instance of */
1.196 + gmyth_uri =
1.197 + gmyth_uri_new_with_value (gnome_vfs_unescape_string
1.198 + (gnome_vfs_uri_to_string
1.199 + (uri,
1.200 + GNOME_VFS_URI_HIDE_NONE),
1.201 + ""));
1.202 +
1.203 + myth_handle->is_livetv = gmyth_uri_is_livetv (gmyth_uri);
1.204 +
1.205 + /* Connect to the backend */
1.206 + if (gmyth_uri != NULL && myth_handle->is_livetv == TRUE) {
1.207 +
1.208 + if (NULL == myth_handle->livetv) {
1.209 + myth_handle->livetv = gmyth_livetv_new ();
1.210 +
1.211 + myth_handle->channel_name =
1.212 + gmyth_uri_get_channel_name (gmyth_uri);
1.213 +
1.214 + g_debug ("[%s] Channel name = %s\n",
1.215 + __FUNCTION__,
1.216 + myth_handle->channel_name);
1.217 +
1.218 + if (myth_handle->channel_name != NULL) {
1.219 + if (gmyth_livetv_channel_name_setup
1.220 + (myth_handle->livetv,
1.221 + myth_handle->channel_name,
1.222 + backend_info) == FALSE) {
1.223 + g_object_unref (gmyth_uri);
1.224 ret = FALSE;
1.225 }
1.226 - } /* if - FileTransfer is NULL, or not */
1.227 -
1.228 - } else {
1.229 -
1.230 - if (NULL == myth_handle->file_transfer ) {
1.231 -
1.232 - myth_handle->file_transfer = gmyth_file_transfer_new (backend_info);
1.233 -
1.234 - /* Verifies if the file exists */
1.235 - if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) {
1.236 - g_object_unref (backend_info);
1.237 - ret = FALSE;
1.238 - }
1.239 -
1.240 - /* sets the Playback monitor connection */
1.241 - ret = gmyth_file_transfer_open ( myth_handle->file_transfer,
1.242 - gmyth_uri_get_path (gmyth_uri) );
1.243 -
1.244 - }
1.245 -
1.246 - } /* if - LiveTV or not? */
1.247 -
1.248 - if (ret == FALSE) {
1.249 - g_debug ("MythTV FileTransfer open error.\n");
1.250 - return GNOME_VFS_ERROR_NOT_OPEN;
1.251 - }
1.252 -
1.253 - myth_handle->configured = TRUE;
1.254 -
1.255 - g_object_unref (backend_info);
1.256 -
1.257 - if ( gmyth_uri != NULL )
1.258 - g_object_unref( gmyth_uri );
1.259 -
1.260 - myth_handle->buffer = g_byte_array_sized_new (MYTHTV_BUFFER_SIZE);
1.261 - myth_handle->buffer_remain = 0;
1.262 -
1.263 - g_return_val_if_fail (myth_handle->file_transfer != NULL, GNOME_VFS_ERROR_NOT_OPEN);
1.264 -
1.265 - if ( /*myth_handle->file_transfer->filesize <= 0 && */myth_handle->is_livetv ) {
1.266 - myth_handle->content_size = gmyth_recorder_get_file_position(myth_handle->livetv->recorder);
1.267 - } else {
1.268 - myth_handle->content_size = myth_handle->file_transfer->filesize;
1.269 - }
1.270 -
1.271 - } /* if - configured or not? */
1.272 -
1.273 - *method_handle = (GnomeVFSMethodHandle *) myth_handle;
1.274 + } else {
1.275 + if (gmyth_livetv_setup
1.276 + (myth_handle->livetv,
1.277 + backend_info) == FALSE) {
1.278 + g_object_unref (gmyth_uri);
1.279 + ret = FALSE;
1.280 + }
1.281 + }
1.282 + }
1.283
1.284 - return GNOME_VFS_OK;
1.285 + if (NULL == myth_handle->file_transfer) {
1.286 + myth_handle->file_transfer =
1.287 + gmyth_livetv_create_file_transfer
1.288 + (myth_handle->livetv);
1.289 +
1.290 + if (NULL == myth_handle->file_transfer) {
1.291 + ret = FALSE;
1.292 + g_debug
1.293 + ("MythTV FileTransfer is NULL!\n");
1.294 + return GNOME_VFS_ERROR_NOT_OPEN;
1.295 + }
1.296 +
1.297 + if (!gmyth_file_transfer_open
1.298 + (myth_handle->file_transfer,
1.299 + myth_handle->livetv->uri !=
1.300 + NULL ?
1.301 + gmyth_uri_get_path (myth_handle->
1.302 + livetv->
1.303 + uri) :
1.304 + myth_handle->livetv->proginfo->
1.305 + pathname->str)) {
1.306 + g_debug
1.307 + ("Couldn't open MythTV FileTransfer is NULL!\n");
1.308 + g_object_unref (myth_handle->
1.309 + file_transfer);
1.310 + myth_handle->file_transfer = NULL;
1.311 + ret = FALSE;
1.312 + }
1.313 + }
1.314 + /* if - FileTransfer is NULL, or not */
1.315 + } else {
1.316 +
1.317 + if (NULL == myth_handle->file_transfer) {
1.318 +
1.319 + myth_handle->file_transfer =
1.320 + gmyth_file_transfer_new (backend_info);
1.321 +
1.322 + /* Verifies if the file exists */
1.323 + if (!gmyth_util_file_exists
1.324 + (backend_info,
1.325 + gmyth_uri_get_path (gmyth_uri))) {
1.326 + g_object_unref (backend_info);
1.327 + ret = FALSE;
1.328 + }
1.329 +
1.330 + /* sets the Playback monitor connection */
1.331 + ret =
1.332 + gmyth_file_transfer_open (myth_handle->
1.333 + file_transfer,
1.334 + gmyth_uri_get_path
1.335 + (gmyth_uri));
1.336 +
1.337 + }
1.338 +
1.339 + } /* if - LiveTV or not? */
1.340 +
1.341 + if (ret == FALSE) {
1.342 + g_debug ("MythTV FileTransfer open error.\n");
1.343 + return GNOME_VFS_ERROR_NOT_OPEN;
1.344 + }
1.345 +
1.346 + myth_handle->configured = TRUE;
1.347 +
1.348 + g_object_unref (backend_info);
1.349 +
1.350 + if (gmyth_uri != NULL)
1.351 + g_object_unref (gmyth_uri);
1.352 +
1.353 + myth_handle->buffer =
1.354 + g_byte_array_sized_new (MYTHTV_BUFFER_SIZE);
1.355 + myth_handle->buffer_remain = 0;
1.356 +
1.357 + g_return_val_if_fail (myth_handle->file_transfer != NULL,
1.358 + GNOME_VFS_ERROR_NOT_OPEN);
1.359 +
1.360 + if ( /*myth_handle->file_transfer->filesize <= 0 && */
1.361 + myth_handle->is_livetv) {
1.362 + myth_handle->content_size =
1.363 + gmyth_recorder_get_file_position (myth_handle->
1.364 + livetv->
1.365 + recorder);
1.366 + } else {
1.367 + myth_handle->content_size =
1.368 + myth_handle->file_transfer->filesize;
1.369 + }
1.370 +
1.371 + }
1.372 + /* if - configured or not? */
1.373 + *method_handle = (GnomeVFSMethodHandle *) myth_handle;
1.374 +
1.375 + return GNOME_VFS_OK;
1.376 }
1.377
1.378 static GnomeVFSResult
1.379 -do_read (GnomeVFSMethod *method,
1.380 - GnomeVFSMethodHandle *method_handle,
1.381 - gpointer buffer,
1.382 - GnomeVFSFileSize num_bytes,
1.383 - GnomeVFSFileSize *bytes_read,
1.384 - GnomeVFSContext *context)
1.385 +do_read (GnomeVFSMethod * method,
1.386 + GnomeVFSMethodHandle * method_handle,
1.387 + gpointer buffer,
1.388 + GnomeVFSFileSize num_bytes,
1.389 + GnomeVFSFileSize * bytes_read, GnomeVFSContext * context)
1.390 {
1.391 - MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
1.392 - GnomeVFSFileSize bytes_to_read = num_bytes;
1.393 + MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
1.394 + GnomeVFSFileSize bytes_to_read = num_bytes;
1.395
1.396 - if ( !myth_handle->is_livetv && ( myth_handle->bytes_read >= myth_handle->content_size ) )
1.397 - return GNOME_VFS_ERROR_EOF;
1.398 + if (!myth_handle->is_livetv
1.399 + && (myth_handle->bytes_read >= myth_handle->content_size))
1.400 + return GNOME_VFS_ERROR_EOF;
1.401
1.402 - /* fixme: change this to min math function */
1.403 - if (( myth_handle->content_size > 0 ) )
1.404 - {
1.405 - if ( !myth_handle->is_livetv &&
1.406 - ( num_bytes > ( myth_handle->content_size - myth_handle->bytes_read ) ) )
1.407 - {
1.408 - bytes_to_read = myth_handle->content_size - myth_handle->bytes_read;
1.409 - }
1.410 - }
1.411 + /* fixme: change this to min math function */
1.412 + if ((myth_handle->content_size > 0)) {
1.413 + if (!myth_handle->is_livetv &&
1.414 + (num_bytes >
1.415 + (myth_handle->content_size -
1.416 + myth_handle->bytes_read))) {
1.417 + bytes_to_read =
1.418 + myth_handle->content_size -
1.419 + myth_handle->bytes_read;
1.420 + }
1.421 + }
1.422
1.423 - /* Loop sending the Myth File Transfer request:
1.424 - * Retry whilst authentication fails and we supply it. */
1.425 - if ( ( myth_handle->buffer_remain = myth_handle->buffer->len ) < bytes_to_read )
1.426 - {
1.427 - gint buffer_size;
1.428 -
1.429 - while ( MYTHTV_BUFFER_SIZE != myth_handle->buffer_remain ) {
1.430 -
1.431 - /* resize buffer length request to no more than MYTHTV_MAX_REQUEST_SIZE */
1.432 - if ( ( MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain ) <= MYTHTV_MAX_REQUEST_SIZE )
1.433 - buffer_size = MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain;
1.434 - else
1.435 - buffer_size = MYTHTV_MAX_REQUEST_SIZE;
1.436 -
1.437 - GByteArray *tmp_buffer = g_byte_array_new();
1.438 -
1.439 - g_debug ("XXXXXXXXXX Asking %d bytes (there is %d bytes in the buffer)\n",
1.440 - buffer_size, myth_handle->buffer_remain);
1.441 -
1.442 - gint len = gmyth_file_transfer_read (myth_handle->file_transfer,
1.443 - tmp_buffer, buffer_size, TRUE);
1.444 -
1.445 + /* Loop sending the Myth File Transfer request:
1.446 + * Retry whilst authentication fails and we supply it. */
1.447 + if ((myth_handle->buffer_remain =
1.448 + myth_handle->buffer->len) < bytes_to_read) {
1.449 + gint buffer_size;
1.450 +
1.451 + while (MYTHTV_BUFFER_SIZE != myth_handle->buffer_remain) {
1.452 +
1.453 + /* resize buffer length request to no more than MYTHTV_MAX_REQUEST_SIZE */
1.454 + if ((MYTHTV_BUFFER_SIZE -
1.455 + myth_handle->buffer_remain) <=
1.456 + MYTHTV_MAX_REQUEST_SIZE)
1.457 + buffer_size =
1.458 + MYTHTV_BUFFER_SIZE -
1.459 + myth_handle->buffer_remain;
1.460 + else
1.461 + buffer_size = MYTHTV_MAX_REQUEST_SIZE;
1.462 +
1.463 + GByteArray *tmp_buffer = g_byte_array_new ();
1.464 +
1.465 + g_debug
1.466 + ("XXXXXXXXXX Asking %d bytes (there is %d bytes in the buffer)\n",
1.467 + buffer_size, myth_handle->buffer_remain);
1.468 +
1.469 + gint len =
1.470 + gmyth_file_transfer_read (myth_handle->
1.471 + file_transfer,
1.472 + tmp_buffer,
1.473 + buffer_size, TRUE);
1.474 +
1.475 if (!myth_handle->is_livetv && len < 0) {
1.476 - g_byte_array_free (tmp_buffer, TRUE);
1.477 - g_debug ("Fail to read bytes");
1.478 - return GNOME_VFS_ERROR_IO;
1.479 - } /*else if (len == 0) {
1.480 - g_byte_array_free (tmp_buffer, TRUE);
1.481 - g_warning ("End of file probably achieved");
1.482 - return GNOME_VFS_ERROR_EOF;
1.483 - }*/
1.484 -
1.485 - myth_handle->buffer = g_byte_array_append ( myth_handle->buffer,
1.486 - tmp_buffer->data, len );
1.487 -
1.488 + g_byte_array_free (tmp_buffer, TRUE);
1.489 + g_debug ("Fail to read bytes");
1.490 + return GNOME_VFS_ERROR_IO;
1.491 + }
1.492 + /*else if (len == 0) {
1.493 + g_byte_array_free (tmp_buffer, TRUE);
1.494 + g_warning ("End of file probably achieved");
1.495 + return GNOME_VFS_ERROR_EOF;
1.496 + } */
1.497 + myth_handle->buffer =
1.498 + g_byte_array_append (myth_handle->buffer,
1.499 + tmp_buffer->data, len);
1.500 +
1.501 myth_handle->buffer_remain += len;
1.502
1.503 - if ( tmp_buffer != NULL )
1.504 - {
1.505 - g_byte_array_free ( tmp_buffer, TRUE );
1.506 - tmp_buffer = NULL;
1.507 + if (tmp_buffer != NULL) {
1.508 + g_byte_array_free (tmp_buffer, TRUE);
1.509 + tmp_buffer = NULL;
1.510 }
1.511 - } /* while - iterates until fills the internal buffer */
1.512 -
1.513 - } /* if - got from the network, or not */
1.514 -
1.515 - bytes_to_read = ( bytes_to_read > myth_handle->buffer_remain ) ? myth_handle->buffer_remain : bytes_to_read;
1.516 - /* gets the first buffer_size bytes from the byte array buffer variable */
1.517 + } /* while - iterates until fills the internal buffer */
1.518
1.519 - g_memmove (buffer, myth_handle->buffer->data, bytes_to_read);
1.520 + }
1.521 + /* if - got from the network, or not */
1.522 + bytes_to_read =
1.523 + (bytes_to_read >
1.524 + myth_handle->buffer_remain) ? myth_handle->
1.525 + buffer_remain : bytes_to_read;
1.526 + /* gets the first buffer_size bytes from the byte array buffer variable */
1.527
1.528 - myth_handle->bytes_read += bytes_to_read;
1.529 - myth_handle->buffer_remain -= bytes_to_read;
1.530 + g_memmove (buffer, myth_handle->buffer->data, bytes_to_read);
1.531 +
1.532 + myth_handle->bytes_read += bytes_to_read;
1.533 + myth_handle->buffer_remain -= bytes_to_read;
1.534
1.535 /* flushs the newly buffer got from byte array */
1.536 - myth_handle->buffer = g_byte_array_remove_range (myth_handle->buffer, 0, bytes_to_read);
1.537 - g_debug ("Got from %llu bytes from internal buffer. (there are %d bytes in the buffer, from a total of %llu dispatched.)\n",
1.538 - bytes_to_read, myth_handle->buffer_remain, myth_handle->bytes_read );
1.539 -
1.540 - *bytes_read = bytes_to_read;
1.541 + myth_handle->buffer =
1.542 + g_byte_array_remove_range (myth_handle->buffer, 0,
1.543 + bytes_to_read);
1.544 + g_debug
1.545 + ("Got from %llu bytes from internal buffer. (there are %d bytes in the buffer, from a total of %llu dispatched.)\n",
1.546 + bytes_to_read, myth_handle->buffer_remain,
1.547 + myth_handle->bytes_read);
1.548
1.549 - return GNOME_VFS_OK;
1.550 + *bytes_read = bytes_to_read;
1.551 +
1.552 + return GNOME_VFS_OK;
1.553 }
1.554
1.555 static GnomeVFSResult
1.556 -do_close (GnomeVFSMethod *method,
1.557 - GnomeVFSMethodHandle *method_handle,
1.558 - GnomeVFSContext *context)
1.559 +do_close (GnomeVFSMethod * method,
1.560 + GnomeVFSMethodHandle * method_handle, GnomeVFSContext * context)
1.561 {
1.562
1.563 - MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
1.564 -
1.565 - //if ( NULL == myth_handle || myth_handle->configured ) {
1.566 -
1.567 - if (myth_handle->file_transfer != NULL) {
1.568 - g_object_unref (myth_handle->file_transfer);
1.569 - myth_handle->file_transfer = NULL;
1.570 - }
1.571 -
1.572 - if (myth_handle->is_livetv && myth_handle->livetv != NULL) {
1.573 - g_object_unref (myth_handle->livetv);
1.574 - myth_handle->livetv = NULL;
1.575 - }
1.576 -
1.577 - if (myth_handle->buffer) {
1.578 - g_byte_array_free (myth_handle->buffer, TRUE);
1.579 - myth_handle->buffer = NULL;
1.580 - }
1.581 -
1.582 - myth_handle->configured = FALSE;
1.583 -
1.584 - g_free (myth_handle);
1.585 -
1.586 - myth_handle = NULL;
1.587 -
1.588 - // }
1.589 -
1.590 - return GNOME_VFS_OK;
1.591 + MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
1.592 +
1.593 + //if ( NULL == myth_handle || myth_handle->configured ) {
1.594 +
1.595 + if (myth_handle->file_transfer != NULL) {
1.596 + g_object_unref (myth_handle->file_transfer);
1.597 + myth_handle->file_transfer = NULL;
1.598 + }
1.599 +
1.600 + if (myth_handle->is_livetv && myth_handle->livetv != NULL) {
1.601 + g_object_unref (myth_handle->livetv);
1.602 + myth_handle->livetv = NULL;
1.603 + }
1.604 +
1.605 + if (myth_handle->buffer) {
1.606 + g_byte_array_free (myth_handle->buffer, TRUE);
1.607 + myth_handle->buffer = NULL;
1.608 + }
1.609 +
1.610 + myth_handle->configured = FALSE;
1.611 +
1.612 + g_free (myth_handle);
1.613 +
1.614 + myth_handle = NULL;
1.615 +
1.616 + // }
1.617 +
1.618 + return GNOME_VFS_OK;
1.619 }
1.620
1.621 static GnomeVFSResult
1.622 -do_get_file_info (GnomeVFSMethod *method,
1.623 - GnomeVFSURI *uri,
1.624 - GnomeVFSFileInfo *file_info,
1.625 - GnomeVFSFileInfoOptions options,
1.626 - GnomeVFSContext *context)
1.627 +do_get_file_info (GnomeVFSMethod * method,
1.628 + GnomeVFSURI * uri,
1.629 + GnomeVFSFileInfo * file_info,
1.630 + GnomeVFSFileInfoOptions options,
1.631 + GnomeVFSContext * context)
1.632 {
1.633 - GMythFileTransfer *file_transfer = NULL;
1.634 - GMythRecorder *recorder = NULL;
1.635 - GMythTVChain *tvchain = NULL;
1.636 - GMythBackendInfo *backend_info = NULL;
1.637 - GMythURI *gmyth_uri = NULL;
1.638 - GMythSocket *socket = NULL;
1.639 - gboolean is_livetv = FALSE;
1.640 - gboolean ret = TRUE;
1.641 - gboolean res = TRUE;
1.642 -
1.643 - /* Creates and fills out the backend info structure */
1.644 - backend_info = gmyth_backend_info_new_with_uri (
1.645 - gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
1.646 -
1.647 - /* creates an instance of */
1.648 - gmyth_uri = gmyth_uri_new_with_value(
1.649 - gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
1.650 + GMythFileTransfer *file_transfer = NULL;
1.651 + GMythRecorder *recorder = NULL;
1.652 + GMythTVChain *tvchain = NULL;
1.653 + GMythBackendInfo *backend_info = NULL;
1.654 + GMythURI *gmyth_uri = NULL;
1.655 + GMythSocket *socket = NULL;
1.656 + gboolean is_livetv = FALSE;
1.657 + gboolean ret = TRUE;
1.658 + gboolean res = TRUE;
1.659
1.660 - is_livetv = gmyth_uri_is_livetv( gmyth_uri );
1.661 + /* Creates and fills out the backend info structure */
1.662 + backend_info =
1.663 + gmyth_backend_info_new_with_uri (gnome_vfs_unescape_string
1.664 + (gnome_vfs_uri_to_string
1.665 + (uri,
1.666 + GNOME_VFS_URI_HIDE_NONE),
1.667 + ""));
1.668
1.669 - file_info->valid_fields = file_info->valid_fields
1.670 - | GNOME_VFS_FILE_INFO_FIELDS_TYPE
1.671 - | GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE
1.672 - | GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS;
1.673 - file_info->type = GNOME_VFS_FILE_TYPE_REGULAR;
1.674 - /* fixme: get from file extension? */
1.675 - file_info->mime_type = g_strdup ("video/x-nuv");
1.676 - file_info->permissions =
1.677 - GNOME_VFS_PERM_USER_READ |
1.678 - GNOME_VFS_PERM_OTHER_READ |
1.679 - GNOME_VFS_PERM_GROUP_READ;
1.680 -
1.681 - g_print( "gnome_vfs_uri == %s | gmyth_uri == %s.\n",
1.682 - gnome_vfs_uri_get_path (uri),
1.683 - gmyth_uri_get_path (gmyth_uri) );
1.684 + /* creates an instance of */
1.685 + gmyth_uri =
1.686 + gmyth_uri_new_with_value (gnome_vfs_unescape_string
1.687 + (gnome_vfs_uri_to_string
1.688 + (uri, GNOME_VFS_URI_HIDE_NONE),
1.689 + ""));
1.690
1.691 - /* Connect to the backend */
1.692 - if ( gmyth_uri != NULL && is_livetv == TRUE ) {
1.693 -
1.694 - /* start to get file info from LiveTV remote encoder */
1.695 - socket = gmyth_socket_new ();
1.696 -
1.697 - /* FIME: Implement this at gmyth_socket */
1.698 - res = gmyth_socket_connect_to_backend (socket, backend_info->hostname,
1.699 - backend_info->port, TRUE);
1.700 - if (!res) {
1.701 - g_print ("[%s] LiveTV can not connect to backend", __FUNCTION__);
1.702 - res = FALSE;
1.703 - goto error;
1.704 - }
1.705 + is_livetv = gmyth_uri_is_livetv (gmyth_uri);
1.706
1.707 - if ( gmyth_remote_util_get_free_recorder_count (socket) <= 0 ) {
1.708 - g_print ("No free remote encoder available.");
1.709 - res = FALSE;
1.710 - goto error;
1.711 - }
1.712 -
1.713 - /* Gets the recorder num */
1.714 - recorder = remote_request_next_free_recorder (socket, -1);
1.715 -
1.716 - //if ( socket != NULL )
1.717 - // g_object_unref (socket);
1.718 -
1.719 - if ( recorder == NULL ) {
1.720 - g_print ("[%s] None remote encoder available", __FUNCTION__);
1.721 - res = FALSE;
1.722 - goto error;
1.723 - }
1.724 -
1.725 - /* Init remote encoder. Opens its control socket. */
1.726 - res = gmyth_recorder_setup(recorder);
1.727 - if ( !res ) {
1.728 - g_print ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
1.729 - res = FALSE;
1.730 - goto error;
1.731 - }
1.732 -
1.733 - /* Creates livetv chain handler */
1.734 - tvchain = gmyth_tvchain_new();
1.735 - gmyth_tvchain_initialize ( tvchain, backend_info );
1.736 -
1.737 - if ( tvchain == NULL || tvchain->tvchain_id == NULL ) {
1.738 - res = FALSE;
1.739 - goto error;
1.740 - }
1.741 -
1.742 - // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
1.743 - res = gmyth_recorder_spawntv ( recorder,
1.744 - gmyth_tvchain_get_id(tvchain) );
1.745 - if (!res) {
1.746 - g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
1.747 - res = FALSE;
1.748 - goto error;
1.749 - }
1.750 -
1.751 - //gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.752 -
1.753 - /* DEBUG message */
1.754 - GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( recorder );
1.755 -
1.756 - if ( prog_info != NULL )
1.757 - {
1.758 - //gmyth_program_info_print( prog_info );
1.759 - g_debug( "Program Info: %s\n", gmyth_program_info_to_string( prog_info ) );
1.760 -
1.761 - g_print( "path = %s", prog_info->pathname->str );
1.762 -
1.763 - file_info->name = g_strdup ( g_strrstr( prog_info->pathname->str, "/" ) );
1.764 -
1.765 - } else {
1.766 - file_info->name = g_strdup ( "LiveTV.nuv" );
1.767 - file_info->size = gmyth_recorder_get_file_position( recorder );
1.768 - }
1.769 -
1.770 - if ( recorder != NULL )
1.771 - g_object_unref (recorder);
1.772 -
1.773 - if ( prog_info != NULL )
1.774 - g_object_unref( prog_info );
1.775 + file_info->valid_fields = file_info->valid_fields
1.776 + | GNOME_VFS_FILE_INFO_FIELDS_TYPE
1.777 + | GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE
1.778 + | GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS;
1.779 + file_info->type = GNOME_VFS_FILE_TYPE_REGULAR;
1.780 + /* fixme: get from file extension? */
1.781 + file_info->mime_type = g_strdup ("video/x-nuv");
1.782 + file_info->permissions =
1.783 + GNOME_VFS_PERM_USER_READ |
1.784 + GNOME_VFS_PERM_OTHER_READ | GNOME_VFS_PERM_GROUP_READ;
1.785
1.786 - if ( tvchain != NULL )
1.787 - g_object_unref (tvchain);
1.788 -
1.789 - file_info->size = (GnomeVFSFileSize) - 1;
1.790 + g_print ("gnome_vfs_uri == %s | gmyth_uri == %s.\n",
1.791 + gnome_vfs_uri_get_path (uri),
1.792 + gmyth_uri_get_path (gmyth_uri));
1.793
1.794 - } else {
1.795 -
1.796 - /* start to get file info from remote file encoder */
1.797 - file_transfer = gmyth_file_transfer_new (backend_info);
1.798 -
1.799 - /* Verifies if the file exists */
1.800 - if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) {
1.801 - g_object_unref (backend_info);
1.802 - return GNOME_VFS_ERROR_NOT_FOUND;
1.803 - }
1.804 -
1.805 - /* sets the Playback monitor connection */
1.806 - ret = gmyth_file_transfer_open ( file_transfer, gmyth_uri_get_path (gmyth_uri) );
1.807 -
1.808 - file_info->name = g_strdup ( gnome_vfs_uri_get_path (uri) );
1.809 -
1.810 - } /* if - LiveTV or not? */
1.811 -
1.812 - if (ret == FALSE) {
1.813 - g_debug ("MythTV FileTransfer open error\n");
1.814 - return GNOME_VFS_ERROR_NOT_OPEN;
1.815 - }
1.816 -
1.817 - if ( ret == TRUE && file_transfer != NULL ) {
1.818 - file_info->size = gmyth_file_transfer_get_filesize (file_transfer);
1.819 - if ( file_transfer )
1.820 - g_object_unref (file_transfer);
1.821 - }
1.822 + /* Connect to the backend */
1.823 + if (gmyth_uri != NULL && is_livetv == TRUE) {
1.824
1.825 - file_info->block_count = GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT;
1.826 - file_info->io_block_size = GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE;
1.827 -
1.828 -error:
1.829 - if (backend_info)
1.830 - g_object_unref (backend_info);
1.831 -
1.832 - if (!res)
1.833 - return GNOME_VFS_ERROR_IO;
1.834 + /* start to get file info from LiveTV remote encoder */
1.835 + socket = gmyth_socket_new ();
1.836
1.837 - return GNOME_VFS_OK;
1.838 + /* FIME: Implement this at gmyth_socket */
1.839 + res =
1.840 + gmyth_socket_connect_to_backend (socket,
1.841 + backend_info->
1.842 + hostname,
1.843 + backend_info->port,
1.844 + TRUE);
1.845 + if (!res) {
1.846 + g_print ("[%s] LiveTV can not connect to backend",
1.847 + __FUNCTION__);
1.848 + res = FALSE;
1.849 + goto error;
1.850 + }
1.851 +
1.852 + if (gmyth_remote_util_get_free_recorder_count (socket) <=
1.853 + 0) {
1.854 + g_print ("No free remote encoder available.");
1.855 + res = FALSE;
1.856 + goto error;
1.857 + }
1.858 +
1.859 + /* Gets the recorder num */
1.860 + recorder = remote_request_next_free_recorder (socket, -1);
1.861 +
1.862 + //if ( socket != NULL )
1.863 + // g_object_unref (socket);
1.864 +
1.865 + if (recorder == NULL) {
1.866 + g_print ("[%s] None remote encoder available",
1.867 + __FUNCTION__);
1.868 + res = FALSE;
1.869 + goto error;
1.870 + }
1.871 +
1.872 + /* Init remote encoder. Opens its control socket. */
1.873 + res = gmyth_recorder_setup (recorder);
1.874 + if (!res) {
1.875 + g_print
1.876 + ("[%s] Fail while setting remote encoder\n",
1.877 + __FUNCTION__);
1.878 + res = FALSE;
1.879 + goto error;
1.880 + }
1.881 +
1.882 + /* Creates livetv chain handler */
1.883 + tvchain = gmyth_tvchain_new ();
1.884 + gmyth_tvchain_initialize (tvchain, backend_info);
1.885 +
1.886 + if (tvchain == NULL || tvchain->tvchain_id == NULL) {
1.887 + res = FALSE;
1.888 + goto error;
1.889 + }
1.890 + // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
1.891 + res = gmyth_recorder_spawntv (recorder,
1.892 + gmyth_tvchain_get_id
1.893 + (tvchain));
1.894 + if (!res) {
1.895 + g_warning ("[%s] Fail while spawn tv\n",
1.896 + __FUNCTION__);
1.897 + res = FALSE;
1.898 + goto error;
1.899 + }
1.900 + //gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.901 +
1.902 + /* DEBUG message */
1.903 + GMythProgramInfo *prog_info =
1.904 + gmyth_recorder_get_current_program_info (recorder);
1.905 +
1.906 + if (prog_info != NULL) {
1.907 + //gmyth_program_info_print( prog_info );
1.908 + g_debug ("Program Info: %s\n",
1.909 + gmyth_program_info_to_string (prog_info));
1.910 +
1.911 + g_print ("path = %s", prog_info->pathname->str);
1.912 +
1.913 + file_info->name =
1.914 + g_strdup (g_strrstr
1.915 + (prog_info->pathname->str, "/"));
1.916 +
1.917 + } else {
1.918 + file_info->name = g_strdup ("LiveTV.nuv");
1.919 + file_info->size =
1.920 + gmyth_recorder_get_file_position (recorder);
1.921 + }
1.922 +
1.923 + if (recorder != NULL)
1.924 + g_object_unref (recorder);
1.925 +
1.926 + if (prog_info != NULL)
1.927 + g_object_unref (prog_info);
1.928 +
1.929 + if (tvchain != NULL)
1.930 + g_object_unref (tvchain);
1.931 +
1.932 + file_info->size = (GnomeVFSFileSize) - 1;
1.933 +
1.934 + } else {
1.935 +
1.936 + /* start to get file info from remote file encoder */
1.937 + file_transfer = gmyth_file_transfer_new (backend_info);
1.938 +
1.939 + /* Verifies if the file exists */
1.940 + if (!gmyth_util_file_exists
1.941 + (backend_info, gmyth_uri_get_path (gmyth_uri))) {
1.942 + g_object_unref (backend_info);
1.943 + return GNOME_VFS_ERROR_NOT_FOUND;
1.944 + }
1.945 +
1.946 + /* sets the Playback monitor connection */
1.947 + ret =
1.948 + gmyth_file_transfer_open (file_transfer,
1.949 + gmyth_uri_get_path
1.950 + (gmyth_uri));
1.951 +
1.952 + file_info->name = g_strdup (gnome_vfs_uri_get_path (uri));
1.953 +
1.954 + } /* if - LiveTV or not? */
1.955 +
1.956 + if (ret == FALSE) {
1.957 + g_debug ("MythTV FileTransfer open error\n");
1.958 + return GNOME_VFS_ERROR_NOT_OPEN;
1.959 + }
1.960 +
1.961 + if (ret == TRUE && file_transfer != NULL) {
1.962 + file_info->size =
1.963 + gmyth_file_transfer_get_filesize (file_transfer);
1.964 + if (file_transfer)
1.965 + g_object_unref (file_transfer);
1.966 + }
1.967 +
1.968 + file_info->block_count = GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT;
1.969 + file_info->io_block_size =
1.970 + GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE;
1.971 +
1.972 + error:
1.973 + if (backend_info)
1.974 + g_object_unref (backend_info);
1.975 +
1.976 + if (!res)
1.977 + return GNOME_VFS_ERROR_IO;
1.978 +
1.979 + return GNOME_VFS_OK;
1.980 }
1.981
1.982 static gboolean
1.983 -do_is_local (GnomeVFSMethod *method,
1.984 - const GnomeVFSURI *uri)
1.985 +do_is_local (GnomeVFSMethod * method, const GnomeVFSURI * uri)
1.986 {
1.987 return FALSE;
1.988 }
1.989 @@ -567,6 +642,6 @@
1.990 }
1.991
1.992 void
1.993 -vfs_module_shutdown (GnomeVFSMethod *method)
1.994 +vfs_module_shutdown (GnomeVFSMethod * method)
1.995 {
1.996 }