[svn r877] gmyth-dbus configure.ac: package renamed from myth-dbus to gmyth-dbus
2 * @author Hallyson Melo <hallyson.melo@indt.org.br>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <glib/gprintf.h>
26 #include <glib/gstdio.h>
29 #include <libgnomevfs/gnome-vfs-module.h>
30 #include <libgnomevfs/gnome-vfs-utils.h>
32 #include <gmyth/gmyth_file.h>
33 #include <gmyth/gmyth_file_transfer.h>
34 #include <gmyth/gmyth_file_local.h>
35 #include <gmyth/gmyth_livetv.h>
36 #include <gmyth/gmyth_uri.h>
37 #include <gmyth/gmyth_recorder.h>
38 #include <gmyth/gmyth_backendinfo.h>
39 #include <gmyth/gmyth_util.h>
40 #include <gmyth/gmyth_remote_util.h>
41 #include <gmyth/gmyth_tvchain.h>
42 #include <gmyth/gmyth_programinfo.h>
44 #define GST_MYTHTV_ID_NUM 1
45 #define MYTHTV_VERSION_DEFAULT 30
46 #define MYTHTV_TRANSFER_MAX_WAITS 100
49 * internal GnomeVFS plug-in buffer size ( 120 Kbytes )
51 #define MYTHTV_BUFFER_SIZE 80*1024
53 * internally sized GnomeVFS plug-in buffer ( 4 Kbytes )
55 #define MYTHTV_MAX_VFS_BUFFER_SIZE 4096
57 * maximum number of bytes to be requested to the MythTV backend ( 64
60 #define MYTHTV_MAX_REQUEST_SIZE 64*1024
65 GMythBackendInfo *backend_info;
67 GMythRecorder *live_recorder;
71 gboolean is_livetv; /* it is, or not a Live TV content
73 gboolean is_local_file; /* tell if the file is local to the
74 * current content transfer */
83 static GnomeVFSResult do_read(GnomeVFSMethod * method,
84 GnomeVFSMethodHandle * method_handle,
86 GnomeVFSFileSize num_bytes,
87 GnomeVFSFileSize * bytes_read,
88 GnomeVFSContext * context);
90 static GnomeVFSResult myth_connection_start(MythtvHandle * method_handle);
91 static void myth_destroy_handle(MythtvHandle * method_handle);
92 static GnomeVFSResult myth_handle_new(GnomeVFSURI * uri,
93 MythtvHandle ** method_handle);
94 static GnomeVFSResult myth_get_file_info(MythtvHandle * myth_handle,
96 GnomeVFSFileInfo * info);
99 myth_handle_new(GnomeVFSURI * uri, MythtvHandle ** method_handle)
104 _GNOME_VFS_METHOD_PARAM_CHECK(*method_handle == NULL);
106 if (gnome_vfs_uri_get_host_name(uri) == NULL) {
107 return GNOME_VFS_ERROR_INVALID_HOST_NAME;
110 *method_handle = g_new0(MythtvHandle, 1);
111 (*method_handle)->mythtv_version = MYTHTV_VERSION_DEFAULT;
113 (*method_handle)->is_livetv = FALSE;
114 (*method_handle)->is_local_file = FALSE;
116 tmp_str1 = gnome_vfs_uri_to_string(uri, GNOME_VFS_URI_HIDE_NONE);
117 tmp_str2 = gnome_vfs_unescape_string(tmp_str1, "");
119 gchar *tmp_str3 = strstr(tmp_str2, ".nuv.avi");
120 if (tmp_str3 != NULL) {
124 (*method_handle)->backend_info =
125 gmyth_backend_info_new_with_uri(tmp_str2);
126 (*method_handle)->gmyth_uri = gmyth_uri_new_with_value(tmp_str2);
134 myth_destroy_handle(MythtvHandle * method_handle)
136 // TODO: abort if in tranfer state
138 if (method_handle->backend_info != NULL) {
139 g_object_unref(method_handle->backend_info);
140 method_handle->backend_info = NULL;
143 if (method_handle->channel_name != NULL) {
144 g_free(method_handle->channel_name);
145 method_handle->channel_name = NULL;
148 if (method_handle->livetv != NULL) {
149 g_object_unref(method_handle->livetv);
150 method_handle->livetv = NULL;
153 if (method_handle->file != NULL) {
154 g_object_unref(method_handle->file);
155 method_handle->file = NULL;
158 if (method_handle->gmyth_uri != NULL) {
159 g_object_unref(method_handle->gmyth_uri);
160 method_handle->gmyth_uri = NULL;
163 g_free(method_handle);
166 static GnomeVFSResult
167 myth_get_file_info(MythtvHandle * myth_handle,
168 GnomeVFSURI * uri, GnomeVFSFileInfo * info)
171 GMythBackendInfo *backend_info;
175 _GNOME_VFS_METHOD_PARAM_CHECK(info != NULL);
177 g_debug("%s - %d", __FUNCTION__, __LINE__);
179 if (myth_handle == NULL) {
183 tmp_str1 = gnome_vfs_uri_to_string(uri, GNOME_VFS_URI_HIDE_NONE);
184 tmp_str2 = gnome_vfs_unescape_string(tmp_str1, "");
186 backend_info = gmyth_backend_info_new_with_uri(tmp_str2);
187 gmyth_uri = gmyth_uri_new_with_value(tmp_str2);
192 backend_info = g_object_ref(myth_handle->backend_info);
193 gmyth_uri = g_object_ref(myth_handle->gmyth_uri);
196 info->valid_fields = 0;
197 info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE |
198 GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE |
199 GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS;
201 info->type = GNOME_VFS_FILE_TYPE_REGULAR;
204 * fixme: get from file extension?
206 info->mime_type = g_strdup("video/x-nuv");
207 info->permissions = GNOME_VFS_PERM_USER_READ |
208 GNOME_VFS_PERM_OTHER_READ | GNOME_VFS_PERM_GROUP_READ;
210 info->name = g_strdup(gmyth_uri_get_path(gmyth_uri));
213 * file size for remote files
215 is_livetv = gmyth_uri_is_livetv(gmyth_uri);
217 if (is_livetv == FALSE) {
218 GMythFile *file = NULL;
219 gboolean ret = FALSE;
222 * Verifies if the file exists
224 if (!gmyth_util_file_exists(backend_info,
225 gmyth_uri_get_path(gmyth_uri))) {
226 g_object_unref(file);
227 g_object_unref(backend_info);
228 g_debug("NOT FOUND %s/%d", __FUNCTION__, __LINE__);
229 return GNOME_VFS_ERROR_NOT_FOUND;
232 is_local = gmyth_uri_is_local_file(gmyth_uri);
233 if (is_local == TRUE) {
234 file = GMYTH_FILE(gmyth_file_local_new(backend_info));
235 ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(file));
237 file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
238 ret = gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(file),
239 gmyth_uri_get_path(gmyth_uri));
243 g_object_unref(file);
244 g_object_unref(backend_info);
245 g_debug("NOT FOUND %s/%d", __FUNCTION__, __LINE__);
246 return GNOME_VFS_ERROR_NOT_FOUND;
249 info->size = gmyth_file_get_filesize(file);
250 info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_SIZE;
251 g_object_unref(file);
254 g_object_unref(backend_info);
255 g_object_unref(gmyth_uri);
260 static GnomeVFSResult
261 myth_connection_start(MythtvHandle * method_handle)
263 GnomeVFSResult result = GNOME_VFS_OK;
265 _GNOME_VFS_METHOD_PARAM_CHECK(method_handle != NULL);
266 _GNOME_VFS_METHOD_PARAM_CHECK(method_handle->backend_info != NULL);
269 * Connect to the backend
271 if ((method_handle->is_livetv =
272 gmyth_uri_is_livetv(method_handle->gmyth_uri)) == TRUE) {
273 method_handle->livetv =
274 gmyth_livetv_new(method_handle->backend_info);
275 method_handle->channel_name =
276 gmyth_uri_get_channel_name(method_handle->gmyth_uri);
278 if (method_handle->channel_name != NULL) {
279 if (gmyth_livetv_channel_name_setup(method_handle->livetv,
281 channel_name) == FALSE) {
282 result = GNOME_VFS_ERROR_INVALID_URI;
285 } else if (gmyth_livetv_setup(method_handle->livetv) == FALSE) {
286 result = GNOME_VFS_ERROR_INVALID_URI;
291 method_handle->file =
292 GMYTH_FILE(gmyth_livetv_create_file_transfer
293 (method_handle->livetv));
295 if (method_handle->file == NULL) {
296 result = GNOME_VFS_ERROR_INVALID_URI;
297 g_debug("MythTV FileTransfer is NULL!\n");
301 if (!gmyth_file_transfer_open
302 (GMYTH_FILE_TRANSFER(method_handle->file),
303 method_handle->livetv->uri !=
304 NULL ? gmyth_uri_get_path(method_handle->livetv->
305 uri) : method_handle->livetv->
306 proginfo->pathname->str)) {
308 g_debug("Couldn't open MythTV FileTransfer is NULL!\n");
309 result = GNOME_VFS_ERROR_NOT_OPEN;
315 * Verifies if the file exists
317 if (!gmyth_util_file_exists(method_handle->backend_info,
318 gmyth_uri_get_path(method_handle->
321 g_debug("NOT FOUND %s/%d", __FUNCTION__, __LINE__);
325 if ((method_handle->is_local_file =
326 gmyth_uri_is_local_file(method_handle->gmyth_uri)) == TRUE) {
327 method_handle->file =
328 GMYTH_FILE(gmyth_file_local_new
329 (method_handle->backend_info));
331 gmyth_file_local_open(GMYTH_FILE_LOCAL
332 (method_handle->file));
334 method_handle->file =
335 GMYTH_FILE(gmyth_file_transfer_new
336 (method_handle->backend_info));
338 gmyth_file_transfer_open(GMYTH_FILE_TRANSFER
339 (method_handle->file),
340 gmyth_uri_get_path(method_handle->
345 * sets the Playback monitor connection
349 g_debug("NOT FOUND %s/%d", __FUNCTION__, __LINE__);
350 result = GNOME_VFS_ERROR_NOT_FOUND;
353 } /* if - LiveTV or not? */
355 method_handle->configured = TRUE;
357 if (method_handle->file == NULL) {
358 result = GNOME_VFS_ERROR_NOT_OPEN;
366 static GnomeVFSResult
367 do_open(GnomeVFSMethod * method,
368 GnomeVFSMethodHandle ** method_handle,
369 GnomeVFSURI * uri, GnomeVFSOpenMode mode,
370 GnomeVFSContext * context)
372 MythtvHandle *myth_handle = NULL;
373 GnomeVFSResult result = GNOME_VFS_OK;
375 _GNOME_VFS_METHOD_PARAM_CHECK(method_handle != NULL);
376 _GNOME_VFS_METHOD_PARAM_CHECK(uri != NULL);
378 if (mode & GNOME_VFS_OPEN_WRITE) {
379 return GNOME_VFS_ERROR_INVALID_OPEN_MODE;
382 result = myth_handle_new(uri, &myth_handle);
383 if (result != GNOME_VFS_OK)
386 result = myth_connection_start(myth_handle);
387 if (result != GNOME_VFS_OK) {
388 myth_destroy_handle(myth_handle);
393 *method_handle = (GnomeVFSMethodHandle *) myth_handle;
398 static GnomeVFSResult
399 do_create(GnomeVFSMethod * method,
400 GnomeVFSMethodHandle ** method_handle,
402 GnomeVFSOpenMode mode,
403 gboolean exclusive, guint perm, GnomeVFSContext * context)
405 return GNOME_VFS_ERROR_NOT_SUPPORTED;
408 static GnomeVFSResult
409 do_close(GnomeVFSMethod * method,
410 GnomeVFSMethodHandle * method_handle, GnomeVFSContext * context)
412 MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
414 myth_destroy_handle(myth_handle);
420 static GnomeVFSResult
421 do_read(GnomeVFSMethod * method,
422 GnomeVFSMethodHandle * method_handle,
424 GnomeVFSFileSize num_bytes,
425 GnomeVFSFileSize * bytes_read, GnomeVFSContext * context)
427 GnomeVFSResult retval = GNOME_VFS_OK;
428 MythtvHandle *myth_handle;
429 GMythFileReadResult result;
430 GByteArray *myth_buffer = g_byte_array_new();
432 _GNOME_VFS_METHOD_PARAM_CHECK(method_handle != NULL);
434 myth_handle = (MythtvHandle *) method_handle;
435 if (myth_handle->is_local_file)
436 result = gmyth_file_local_read(GMYTH_FILE_LOCAL(myth_handle->file),
438 num_bytes, myth_handle->is_livetv);
441 gmyth_file_transfer_read(GMYTH_FILE_TRANSFER
442 (myth_handle->file), myth_buffer,
443 num_bytes, myth_handle->is_livetv);
445 if (result == GMYTH_FILE_READ_ERROR) {
446 retval = GNOME_VFS_ERROR_IO;
449 if (result == GMYTH_FILE_READ_EOF) {
450 retval = GNOME_VFS_ERROR_EOF;
453 if (myth_buffer->len > 0) {
454 g_memmove(buffer, myth_buffer->data, myth_buffer->len);
455 *bytes_read = (GnomeVFSFileSize) myth_buffer->len;
456 myth_handle->offset += myth_buffer->len;
457 g_byte_array_free(myth_buffer, TRUE);
463 static GnomeVFSResult
464 do_write(GnomeVFSMethod * method,
465 GnomeVFSMethodHandle * method_handle,
466 gconstpointer buffer,
467 GnomeVFSFileSize num_bytes,
468 GnomeVFSFileSize * bytes_written, GnomeVFSContext * context)
470 return GNOME_VFS_ERROR_NOT_SUPPORTED;
473 static GnomeVFSResult
474 do_seek(GnomeVFSMethod * method,
475 GnomeVFSMethodHandle * method_handle,
476 GnomeVFSSeekPosition whence,
477 GnomeVFSFileOffset offset, GnomeVFSContext * context)
479 MythtvHandle *myth_handle;
480 guint64 whence_p = 0;
481 gint64 new_offset = 0;
483 _GNOME_VFS_METHOD_PARAM_CHECK(method_handle != NULL);
485 myth_handle = (MythtvHandle *) method_handle;
487 g_debug("seek offset %" G_GINT64_FORMAT " whence %d", offset, whence);
489 if (gmyth_uri_is_livetv(myth_handle->gmyth_uri))
490 return GNOME_VFS_ERROR_NOT_SUPPORTED;
493 case GNOME_VFS_SEEK_START:
496 case GNOME_VFS_SEEK_CURRENT:
497 whence_p = myth_handle->offset;
499 case GNOME_VFS_SEEK_END:
500 return GNOME_VFS_ERROR_NOT_SUPPORTED;
504 gmyth_file_transfer_seek(myth_handle->file, offset, whence_p);
505 if (new_offset != 0) {
506 myth_handle->offset = new_offset;
510 return GNOME_VFS_ERROR_NOT_SUPPORTED;
513 static GnomeVFSResult
514 do_tell(GnomeVFSMethod * method,
515 GnomeVFSMethodHandle * method_handle,
516 GnomeVFSFileSize * offset_return)
518 MythtvHandle *myth_handle = NULL;
520 _GNOME_VFS_METHOD_PARAM_CHECK(method_handle != NULL);
522 myth_handle = (MythtvHandle *) method_handle;
523 *offset_return = myth_handle->offset;
528 static GnomeVFSResult
529 do_truncate_handle(GnomeVFSMethod * method,
530 GnomeVFSMethodHandle * method_handle,
531 GnomeVFSFileSize where, GnomeVFSContext * context)
533 return GNOME_VFS_ERROR_READ_ONLY;
536 static GnomeVFSResult
537 do_open_directory(GnomeVFSMethod * method,
538 GnomeVFSMethodHandle ** method_handle,
540 GnomeVFSFileInfoOptions options,
541 GnomeVFSContext * context)
543 return GNOME_VFS_ERROR_NOT_SUPPORTED;
546 static GnomeVFSResult
547 do_close_directory(GnomeVFSMethod * method,
548 GnomeVFSMethodHandle * method_handle,
549 GnomeVFSContext * context)
551 return GNOME_VFS_ERROR_NOT_SUPPORTED;
554 static GnomeVFSResult
555 do_read_directory(GnomeVFSMethod * method,
556 GnomeVFSMethodHandle * method_handle,
557 GnomeVFSFileInfo * file_info, GnomeVFSContext * context)
559 return GNOME_VFS_ERROR_NOT_SUPPORTED;
563 static GnomeVFSResult
564 do_get_file_info(GnomeVFSMethod * method,
566 GnomeVFSFileInfo * file_info,
567 GnomeVFSFileInfoOptions options,
568 GnomeVFSContext * context)
570 return myth_get_file_info(NULL, uri, file_info);
573 static GnomeVFSResult
574 do_get_file_info_from_handle(GnomeVFSMethod * method,
575 GnomeVFSMethodHandle * method_handle,
576 GnomeVFSFileInfo * file_info,
577 GnomeVFSFileInfoOptions options,
578 GnomeVFSContext * context)
580 MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
582 return myth_get_file_info(myth_handle, NULL, file_info);
586 do_is_local(GnomeVFSMethod * method, const GnomeVFSURI * uri)
591 static GnomeVFSResult
592 do_make_directory(GnomeVFSMethod * method,
593 GnomeVFSURI * uri, guint perm, GnomeVFSContext * context)
595 return GNOME_VFS_ERROR_READ_ONLY;
598 static GnomeVFSResult
599 do_remove_directory(GnomeVFSMethod * method,
600 GnomeVFSURI * uri, GnomeVFSContext * context)
602 return GNOME_VFS_ERROR_READ_ONLY;
605 static GnomeVFSResult
606 do_move(GnomeVFSMethod * method,
607 GnomeVFSURI * old_uri,
608 GnomeVFSURI * new_uri,
609 gboolean force_replace, GnomeVFSContext * context)
611 return GNOME_VFS_ERROR_READ_ONLY;
614 static GnomeVFSResult
615 do_unlink(GnomeVFSMethod * method,
616 GnomeVFSURI * uri, GnomeVFSContext * context)
618 return GNOME_VFS_ERROR_READ_ONLY;
621 static GnomeVFSResult
622 do_check_same_fs(GnomeVFSMethod * method,
625 gboolean * same_fs_return, GnomeVFSContext * context)
627 return GNOME_VFS_ERROR_NOT_SUPPORTED;
630 static GnomeVFSResult
631 do_set_file_info(GnomeVFSMethod * method,
633 const GnomeVFSFileInfo * info,
634 GnomeVFSSetFileInfoMask mask, GnomeVFSContext * context)
636 return GNOME_VFS_ERROR_READ_ONLY;
639 static GnomeVFSResult
640 do_truncate(GnomeVFSMethod * method,
642 GnomeVFSFileSize where, GnomeVFSContext * context)
644 return GNOME_VFS_ERROR_READ_ONLY;
647 static GnomeVFSResult
648 do_find_directory(GnomeVFSMethod * method,
649 GnomeVFSURI * near_uri,
650 GnomeVFSFindDirectoryKind kind,
651 GnomeVFSURI ** result_uri,
652 gboolean create_if_needed,
653 gboolean find_if_needed,
654 guint permissions, GnomeVFSContext * context)
656 return GNOME_VFS_ERROR_NOT_SUPPORTED;
659 static GnomeVFSResult
660 do_create_symbolic_link(GnomeVFSMethod * method,
662 const char *target_reference,
663 GnomeVFSContext * context)
665 return GNOME_VFS_ERROR_READ_ONLY;
668 static GnomeVFSResult
669 do_monitor_add(GnomeVFSMethod * method,
670 GnomeVFSMethodHandle ** method_handle_return,
671 GnomeVFSURI * uri, GnomeVFSMonitorType monitor_type)
673 return GNOME_VFS_ERROR_NOT_SUPPORTED;
676 static GnomeVFSResult
677 do_monitor_cancel(GnomeVFSMethod * method,
678 GnomeVFSMethodHandle * method_handle)
680 return GNOME_VFS_ERROR_NOT_SUPPORTED;
683 static GnomeVFSResult
684 do_file_control(GnomeVFSMethod * method,
685 GnomeVFSMethodHandle * method_handle,
686 const char *operation,
687 gpointer operation_data, GnomeVFSContext * context)
689 return GNOME_VFS_ERROR_NOT_SUPPORTED;
692 static GnomeVFSMethod method = {
693 sizeof(GnomeVFSMethod),
706 do_get_file_info_from_handle,
716 do_create_symbolic_link,
724 vfs_module_init(const char *method_name, const char *args)
730 vfs_module_shutdown(GnomeVFSMethod * method)