4 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
5 * @author Renato Filho <renato.filho@indt.org.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <glib/gi18n.h>
30 #include <gmyth/gmyth.h>
31 #include <dbus/dbus-glib-bindings.h>
33 #include "gmyth-dbus-common.h"
34 #include "gmyth-dbus-server.h"
36 #define MYTH_DEFAULT_DB "mythconverg"
46 GMYTH_DBUS_ERROR_MYTHTV,
47 GMYTH_DBUS_ERROR_CONNECTION,
49 GMYTH_DBUS_ERROR_SCHEDULE
52 #define GMYTH_DBUS_ERROR gmyth_dbus_error_quark ()
55 gmyth_dbus_error_quark (void)
57 return g_quark_from_static_string ("gmyth-dbus-error-quark");
60 typedef struct _GMythDbusServerPrivate GMythDbusServerPrivate;
62 struct _GMythDbusServerPrivate
64 GMythBackendInfo *myth_backend;
67 GMythScheduler *myth_scheduler;
72 #define GMYTH_DBUS_SERVER_GET_PRIVATE(o) \
73 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GMYTH_DBUS_SERVER_TYPE, GMythDbusServerPrivate))
75 static void gmyth_dbus_server_class_init (GMythDbusServerClass *klass);
76 static void gmyth_dbus_server_init (GMythDbusServer *self);
77 static void gmyth_dbus_server_dispose (GObject *object);
78 static void gmyth_dbus_server_finalize (GObject *object);
79 static void gmyth_dbus_server_cancel_shutdown (GMythDbusServer *self);
80 static gboolean gmyth_dbus_server_shutdown_cb (GMythDbusServer *self);
83 static gboolean gmyth_dbus_server_connect (GObject *obj,
87 const gchar *password,
89 static gboolean gmyth_dbus_server_get_channel_list (GObject *obj,
92 static gboolean gmyth_dbus_server_get_channel_info (GObject *obj,
96 static gboolean gmyth_dbus_server_file_exists (GObject *obj,
97 const gchar *file_name,
100 static gboolean gmyth_dbus_server_get_recorded_list (GObject *obj,
101 GPtrArray **channels,
103 static gboolean gmyth_dbus_server_get_recorded_info (GObject *obj,
104 const gchar *basename,
107 static gboolean gmyth_dbus_server_get_program_list (GObject *obj,
109 const gchar *start_time,
110 const gchar *end_time,
111 GPtrArray **program_list,
113 static gboolean gmyth_dbus_server_get_schedule_list (GObject *obj,
114 GPtrArray **schedule_list,
116 static gboolean gmyth_dbus_server_connected (GObject *obj,
119 static gboolean gmyth_dbus_server_disconnect (GObject *obj,
121 static void gmyth_dbus_server_internal_disconnect
124 static gboolean gmyth_dbus_server_get_server_info (GObject *obj,
125 guint64 *total_space,
129 static gboolean gmyth_dbus_server_get_thumbnail (GObject *obj,
133 static gboolean gmyth_dbus_server_get_channel_icon (GObject *obj,
137 static gboolean gmyth_dbus_server_stop_recording (GObject *obj,
141 static gboolean gmyth_dbus_server_add_schedule (GObject *obj,
144 const gchar *start_time,
145 const gchar *end_time,
147 const gchar *description,
150 static gboolean gmyth_dbus_server_add_exception (GObject *obj,
154 const gchar *start_time,
155 const gchar *end_time,
156 const gchar *description,
158 static gboolean gmyth_dbus_server_remove_schedule (GObject *obj,
163 #include "gmyth-dbus-server-glue.h"
166 static guint signals[LAST_SIGNAL] = { 0 };
168 G_DEFINE_TYPE (GMythDbusServer, gmyth_dbus_server, G_TYPE_OBJECT);
171 gmyth_dbus_server_class_init (GMythDbusServerClass *klass)
173 GObjectClass *object_class = G_OBJECT_CLASS (klass);
175 g_type_class_add_private (klass, sizeof (GMythDbusServerPrivate));
177 object_class->dispose = gmyth_dbus_server_dispose;
178 object_class->finalize = gmyth_dbus_server_finalize;
181 g_signal_new ("shutdown",
182 G_OBJECT_CLASS_TYPE (object_class),
183 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
186 g_cclosure_marshal_VOID__VOID,
187 G_TYPE_NONE, 0, G_TYPE_NONE);
189 dbus_g_object_type_install_info (GMYTH_DBUS_SERVER_TYPE,
190 &dbus_glib_gmyth_dbus_server_object_info);
194 gmyth_dbus_server_init (GMythDbusServer *self)
199 gmyth_dbus_server_dispose (GObject *object)
201 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->dispose (object);
205 gmyth_dbus_server_finalize (GObject *object)
207 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->finalize (object);
211 gmyth_dbus_server_connect_epg (GMythDbusServer *server, GError **error)
213 GMythDbusServerPrivate *priv;
214 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
216 if (!priv->connected)
220 GMYTH_DBUS_ERROR_CONNECTION,
228 priv->myth_epg = gmyth_epg_new();
229 if (!gmyth_epg_connect (priv->myth_epg, priv->myth_backend))
231 g_object_unref (priv->myth_epg);
232 priv->myth_epg = NULL;
236 GMYTH_DBUS_ERROR_EPG,
237 _("Fail to connect with EPG"));
248 gmyth_dbus_server_connect_scheduler (GMythDbusServer *server,
251 GMythDbusServerPrivate *priv;
252 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
254 if (!priv->connected)
258 GMYTH_DBUS_ERROR_CONNECTION,
264 if (!priv->myth_scheduler)
266 priv->myth_scheduler = gmyth_scheduler_new ();
267 if (!gmyth_scheduler_connect (priv->myth_scheduler,
270 g_object_unref (priv->myth_scheduler);
271 priv->myth_scheduler = NULL;
275 GMYTH_DBUS_ERROR_SCHEDULE,
276 _("Fail to connect with Schedule"));
286 gmyth_dbus_server_connect (GObject *obj,
290 const gchar *password,
294 GMythDbusServerPrivate *priv;
296 g_debug ("%s:%d", __FUNCTION__, __LINE__);
298 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
302 gmyth_dbus_server_internal_disconnect (obj, NULL);
305 gmyth_dbus_server_cancel_shutdown (GMYTH_DBUS_SERVER (obj));
307 priv->myth_backend = gmyth_backend_info_new_full (host,
313 s = gmyth_backend_info_get_connected_socket (priv->myth_backend);
316 priv->connected = TRUE;
321 priv->connected = FALSE;
322 g_object_unref (priv->myth_backend);
323 priv->myth_backend = NULL;
327 GMYTH_DBUS_ERROR_CONNECTION,
328 _("Fail to connect with backend"));
331 return priv->connected;
335 gmyth_dbus_server_connected (GObject *obj,
339 GMythDbusServerPrivate *priv;
341 g_debug ("%s:%d", __FUNCTION__, __LINE__);
343 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
345 if (priv->myth_backend)
353 gmyth_dbus_server_disconnect (GObject *obj,
356 GMythDbusServerPrivate *priv;
358 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
361 gmyth_dbus_server_internal_disconnect (obj, error);
362 priv->shutdown_cb_id = g_timeout_add (60000,
363 (GSourceFunc) gmyth_dbus_server_shutdown_cb, obj);
370 gmyth_dbus_server_internal_disconnect (GObject *obj,
373 GMythDbusServerPrivate *priv;
375 g_debug ("%s:%d", __FUNCTION__, __LINE__);
377 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
381 g_object_unref (priv->myth_epg);
382 priv->myth_epg = NULL;
386 if (priv->myth_backend)
388 g_object_unref (priv->myth_backend);
389 priv->myth_backend = NULL;
392 if (priv->myth_scheduler)
394 g_object_unref (priv->myth_scheduler);
395 priv->myth_scheduler = NULL;
398 priv->connected = FALSE;
402 gmyth_dbus_server_get_server_info (GObject *obj,
403 guint64 *total_space,
408 GMythBackendDetails *details;
409 GMythDbusServerPrivate *priv;
410 gboolean ret = FALSE;
413 g_debug ("%s:%d", __FUNCTION__, __LINE__);
414 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
416 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
418 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
424 GMYTH_DBUS_ERROR_MYTHTV,
425 _("MythTv not avaliable"));
431 gmyth_util_get_backend_details (socket,
435 *total_space = details->total_space;
436 *used_space = details->used_space;
437 *free_space = *total_space - *used_space;
438 gmyth_util_backend_details_free (details);
446 GMYTH_DBUS_ERROR_MYTHTV,
447 _("Fail to get MythTv details"));
450 g_object_unref (socket);
457 gmyth_dbus_server_parse_channel_info (GMythChannelInfo *info,
460 dbus_g_type_struct_set (val,
462 1, info->channel_num->str,
463 2, info->channel_name->str,
464 3, info->channel_icon->str,
469 gmyth_dbus_server_get_channel_info (GObject *obj,
475 GMythChannelInfo *ch_info;
476 GMythDbusServerPrivate *priv;
478 g_debug ("%s:%d", __FUNCTION__, __LINE__);
479 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
481 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
483 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
488 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
490 ch_info = gmyth_epg_get_channel_info (priv->myth_epg, channel_id);
494 g_value_init (&v, ch_type);
495 g_value_take_boxed (&v, dbus_g_type_specialized_construct (ch_type));
496 gmyth_dbus_server_parse_channel_info (ch_info, &v);
498 *info = g_value_get_boxed (&v);
505 GMYTH_DBUS_ERROR_EPG,
506 _("no channel info avaliable"));
514 gmyth_dbus_server_get_channel_list (GObject *obj,
515 GPtrArray **channels,
522 GMythDbusServerPrivate *priv;
524 g_debug ("%s:%d", __FUNCTION__, __LINE__);
525 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
527 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
528 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
533 len = gmyth_epg_get_channel_list (priv->myth_epg, &lst);
535 *channels = g_ptr_array_sized_new (len);
536 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
538 for (walk = lst; walk != NULL; walk = walk->next)
541 GMythChannelInfo *data;
543 data = (GMythChannelInfo *) walk->data;
545 g_value_init (&ch, ch_type);
546 g_value_take_boxed (&ch, dbus_g_type_specialized_construct (ch_type));
547 gmyth_dbus_server_parse_channel_info (data, &ch);
548 g_ptr_array_add (*channels, g_value_get_boxed (&ch));
551 gmyth_free_channel_list (lst);
556 gmyth_dbus_server_file_exists (GObject *obj,
557 const gchar *file_name,
561 GMythDbusServerPrivate *priv;
562 g_debug ("%s:%d", __FUNCTION__, __LINE__);
563 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
565 g_return_val_if_fail (priv->myth_backend, FALSE);
567 *exists = gmyth_util_file_exists (priv->myth_backend, file_name);
573 gmyth_dbus_server_get_program_list (GObject *obj,
575 const gchar *start_time,
576 const gchar *end_time,
577 GPtrArray **programs,
584 GTimeVal start_time_val;
585 GTimeVal end_time_val;
586 GMythDbusServerPrivate *priv;
588 g_debug ("%s:%d", __FUNCTION__, __LINE__);
589 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
591 g_return_val_if_fail (priv->myth_backend, FALSE);
592 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
595 g_time_val_from_iso8601 (start_time, &start_time_val);
596 g_time_val_from_iso8601 (end_time, &end_time_val);
599 len = gmyth_epg_get_program_list (priv->myth_epg,
605 *programs = g_ptr_array_sized_new (len);
606 program_type = GMYTH_DBUS_PROGRAM_G_TYPE;
608 for (walk = list; walk != NULL; walk = walk->next)
610 GValue program = { 0, };
613 GMythProgramInfo *data;
615 data = (GMythProgramInfo *) walk->data;
620 g_value_init (&program, program_type);
621 g_value_take_boxed (&program,
622 dbus_g_type_specialized_construct (program_type));
624 start_str = g_time_val_to_iso8601 (data->startts);
625 end_str = g_time_val_to_iso8601 (data->endts);
627 dbus_g_type_struct_set (&program,
628 0, data->chanid->str,
632 4, data->subtitle->str,
633 5, data->description->str,
634 6, data->category->str,
637 g_ptr_array_add (*programs, g_value_get_boxed (&program));
643 gmyth_free_program_list (list);
645 g_debug ("%s:%d", __FUNCTION__, __LINE__);
650 gmyth_dbus_server_parse_recorded_info (RecordedInfo *info,
656 start_str = g_time_val_to_iso8601 (info->start_time);
657 end_str = g_time_val_to_iso8601 (info->end_time);
659 dbus_g_type_struct_set (val,
666 6, info->subtitle->str,
667 7, info->description->str,
668 8, info->category->str,
669 9, info->basename->str,
677 gmyth_dbus_server_get_recorded_info (GObject *obj,
678 const gchar *basename,
683 GMythDbusServerPrivate *priv;
684 RecordedInfo *record_info;
687 g_debug ("%s:%d", __FUNCTION__, __LINE__);
688 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
690 g_return_val_if_fail (priv->myth_backend, FALSE);
692 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
695 record_type = GMYTH_DBUS_RECORD_G_TYPE;
697 record_info = gmyth_scheduler_get_recorded_info (priv->myth_scheduler,
704 g_value_init (&r, record_type);
705 g_value_take_boxed (&r,
706 dbus_g_type_specialized_construct (record_type));
708 gmyth_dbus_server_parse_recorded_info (record_info, &r);
709 gmyth_recorded_info_free (record_info);
711 *info = g_value_get_boxed (&r);
719 GMYTH_DBUS_ERROR_EPG,
720 _("no record info avaliable"));
729 gmyth_dbus_server_get_recorded_list (GObject *obj,
737 GMythDbusServerPrivate *priv;
739 g_debug ("%s:%d", __FUNCTION__, __LINE__);
740 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
742 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
743 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
747 len = gmyth_scheduler_get_recorded_list (priv->myth_scheduler,
750 record_type = GMYTH_DBUS_RECORD_G_TYPE;
751 *records = g_ptr_array_sized_new (len);
753 for (walk = list; walk != NULL; walk = walk->next)
755 GValue record = { 0, };
758 data = (RecordedInfo *) walk->data;
760 g_value_init (&record, record_type);
761 g_value_take_boxed (&record,
762 dbus_g_type_specialized_construct (record_type));
764 gmyth_dbus_server_parse_recorded_info (data, &record);
766 g_ptr_array_add (*records, g_value_get_boxed (&record));
767 //g_value_unset (&record);
770 gmyth_recorded_info_list_free (list);
777 gmyth_dbus_server_get_schedule_list (GObject *obj,
778 GPtrArray **schedules,
785 GMythDbusServerPrivate *priv;
787 g_debug ("%s:%d", __FUNCTION__, __LINE__);
788 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
790 g_return_val_if_fail (priv->myth_backend, FALSE);
791 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
795 len = gmyth_scheduler_get_schedule_list (priv->myth_scheduler,
798 *schedules = g_ptr_array_sized_new (len);
799 schedule_type = GMYTH_DBUS_SCHEDULE_G_TYPE;
801 for (walk = list; walk != NULL; walk = walk->next)
803 GValue schedule = { 0, };
805 gchar *start_str_time;
808 data = (ScheduleInfo *) walk->data;
810 g_value_init (&schedule, schedule_type);
811 g_value_take_boxed (&schedule,
812 dbus_g_type_specialized_construct (schedule_type));
814 start_str_time = g_time_val_to_iso8601 (data->start_time);
815 end_str_time = g_time_val_to_iso8601 (data->end_time);
817 dbus_g_type_struct_set (&schedule,
818 0, data->schedule_id,
824 6, data->subtitle->str,
825 7, data->description->str,
826 8, data->category->str,
830 g_ptr_array_add (*schedules, g_value_get_boxed (&schedule));
832 g_free (start_str_time);
833 g_free (end_str_time);
836 gmyth_schedule_info_list_free (list);
843 gmyth_dbus_server_get_thumbnail (GObject *obj,
848 GMythFileTransfer *file_transfer;
850 GMythFileReadResult result;
851 GMythDbusServerPrivate *priv;
853 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
855 file_transfer = NULL;
857 g_return_val_if_fail (priv->myth_backend, FALSE);
859 if (!gmyth_util_file_exists (priv->myth_backend, uri))
863 GMYTH_DBUS_ERROR_MYTHTV,
864 _("File not exists"));
869 file_transfer = gmyth_file_transfer_new (priv->myth_backend);
871 if (!gmyth_file_transfer_open (file_transfer, uri))
875 GMYTH_DBUS_ERROR_MYTHTV,
876 _("Fail to open file"));
880 filesize = gmyth_file_transfer_get_filesize (file_transfer);
884 *image = g_byte_array_new ();
885 result = gmyth_file_transfer_read (file_transfer, *image, filesize, FALSE);
886 if (result == GMYTH_FILE_READ_ERROR)
890 GMYTH_DBUS_ERROR_MYTHTV,
891 _("Fail to read file"));
896 gmyth_file_transfer_close (file_transfer);
897 g_object_unref (file_transfer);
899 if (filesize > (*image)->len)
903 GMYTH_DBUS_ERROR_MYTHTV,
913 g_byte_array_free (*image, TRUE);
914 g_object_unref(file_transfer);
919 gmyth_dbus_server_get_channel_icon (GObject *obj,
924 GMythChannelInfo *channel = NULL;
927 GMythDbusServerPrivate *priv;
929 g_debug ("%s:%d", __FUNCTION__, __LINE__);
930 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
931 g_return_val_if_fail (priv->myth_backend, FALSE);
933 channel = gmyth_epg_get_channel_info (priv->myth_epg,
942 GMYTH_DBUS_ERROR_MYTHTV,
943 _("Invalid channel"));
948 if (!gmyth_epg_channel_has_icon(priv->myth_epg, channel))
950 gmyth_channel_info_free (channel);
953 GMYTH_DBUS_ERROR_MYTHTV,
954 _("Channel does not have icon available"));
961 if (!gmyth_epg_channel_get_icon (priv->myth_epg,
966 gmyth_channel_info_free (channel);
969 GMYTH_DBUS_ERROR_MYTHTV,
970 _("Could not get channel icon for channel id = %u"),
975 *icon = g_byte_array_sized_new (icon_length);
976 *icon = g_byte_array_append (*icon, icon_data, icon_length);
979 gmyth_channel_info_free(channel);
985 gmyth_dbus_server_stop_recording (GObject *obj,
990 gboolean ret = FALSE;
991 GMythDbusServerPrivate *priv;
993 g_debug ("%s:%d", __FUNCTION__, __LINE__);
994 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
996 g_return_val_if_fail (priv->myth_backend, FALSE);
997 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1000 ret = gmyth_scheduler_stop_recording (priv->myth_scheduler,
1006 static ScheduleInfo*
1007 gmyth_dbus_server_new_schedule_info (const gchar* description,
1010 GTimeVal *start_vtime,
1011 GTimeVal *end_vtime)
1013 ScheduleInfo *new_sched_info;
1015 new_sched_info = g_new0(ScheduleInfo, 1);
1017 /* record_id == -1 for generating a new id */
1018 new_sched_info->schedule_id = -1;
1020 new_sched_info->channel_id = channel_id;
1021 new_sched_info->program_id = program_id;
1022 new_sched_info->start_time = g_new0 (GTimeVal, 1);
1023 *new_sched_info->start_time = *start_vtime;
1024 new_sched_info->end_time = g_new0 (GTimeVal, 1);
1025 *new_sched_info->end_time = *end_vtime;
1027 /* TODO: there is no frequency field */
1028 /*new_sched_info->frequency = -1;*/
1030 if (description != NULL) {
1031 /* FIXME: description parameter is used as title and description */
1032 new_sched_info->title = g_string_new(description);
1033 new_sched_info->description = g_string_new(description);
1036 return new_sched_info;
1040 gmyth_dbus_server_add_schedule (GObject *obj,
1043 const gchar *start_time,
1044 const gchar *end_time,
1046 const gchar *description,
1050 ScheduleInfo *sch_info;
1051 GTimeVal start_vtime;
1053 GMythDbusServerPrivate *priv;
1055 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1056 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1060 g_return_val_if_fail (priv->myth_backend, FALSE);
1062 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1066 g_time_val_from_iso8601 (start_time, &start_vtime);
1067 g_time_val_from_iso8601 (end_time, &end_vtime);
1068 sch_info = gmyth_dbus_server_new_schedule_info (description,
1073 if (sch_info != NULL) {
1074 GMythScheduleType type;
1076 gboolean has_record;
1079 GMYTH_SCHEDULE_ALL_OCCURRENCES :
1080 GMYTH_SCHEDULE_ONE_OCCURRENCE);
1082 g_get_current_time (&t_now);
1084 has_record = gmyth_scheduler_was_recorded_before (priv->myth_scheduler,
1086 (time_t) start_vtime.tv_sec);
1089 if ((t_now.tv_sec >= start_vtime.tv_sec)
1090 && (t_now.tv_sec <= end_vtime.tv_sec) && has_record)
1092 GMythSocket *socket;
1093 gboolean res = FALSE;
1095 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
1096 res = gmyth_scheduler_reactivate_schedule(priv->myth_scheduler,
1098 (time_t) start_vtime.tv_sec);
1100 GMythStringList *slist = gmyth_string_list_new();
1102 gmyth_string_list_append_char_array(slist, "RESCHEDULE_RECORDINGS 0");
1103 gmyth_socket_sendreceive_stringlist(socket, slist);
1104 res = (gmyth_string_list_get_int(slist, 0) == 1);
1105 g_object_unref(slist);
1108 g_object_unref(socket);
1113 if (!gmyth_scheduler_add_schedule_full (priv->myth_scheduler,
1117 g_warning("Could not add schedule entry");
1121 (*schedule_id) = sch_info->schedule_id;
1122 gmyth_schedule_info_free (sch_info);
1130 gmyth_dbus_server_add_exception (GObject *obj,
1134 const gchar *start_time,
1135 const gchar *end_time,
1136 const gchar *description,
1139 ScheduleInfo *sch_info;
1140 GTimeVal start_vtime;
1142 GMythDbusServerPrivate *priv;
1144 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1145 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1147 g_return_val_if_fail (priv->myth_backend, FALSE);
1149 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1152 g_time_val_from_iso8601 (start_time, &start_vtime);
1153 g_time_val_from_iso8601 (end_time, &end_vtime);
1155 sch_info = gmyth_dbus_server_new_schedule_info (description,
1160 if (sch_info != NULL)
1162 if (!gmyth_scheduler_add_exception (priv->myth_scheduler,
1166 g_warning ("Could not add schedule exception");
1167 gmyth_schedule_info_free (sch_info);
1171 gmyth_schedule_info_free (sch_info);
1178 gmyth_dbus_server_remove_schedule (GObject *obj,
1182 GMythDbusServerPrivate *priv;
1184 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1185 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1187 g_return_val_if_fail (priv->myth_backend, FALSE);
1189 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1192 return gmyth_scheduler_delete_schedule (priv->myth_scheduler, schedule_id);
1196 gmyth_dbus_server_start_dbus_service (void)
1198 GError *error = NULL;
1200 DBusGConnection *bus;
1202 GMythDbusServer *self;
1204 self = g_object_new (GMYTH_DBUS_SERVER_TYPE, NULL);
1205 g_return_val_if_fail (self, FALSE);
1207 /* TODO: should verify if this service was already started */
1209 /* connect to session bus */
1210 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
1213 g_warning ("Could not connect to dbus: %s", error->message);
1214 g_error_free (error);
1218 /* register dbus object */
1219 dbus_g_connection_register_g_object (bus,
1220 GMYTH_DBUS_SERVER_PATH, G_OBJECT (self));
1222 proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
1223 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
1225 /* registering download manager service */
1226 if (!org_freedesktop_DBus_request_name (proxy, GMYTH_DBUS_SERVER_IFACE,
1227 0, &request_ret, &error))
1229 g_warning ("Unable to register dbus service: %d %s",
1230 error->code, error->message);
1231 g_error_free (error);
1235 if (request_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
1237 g_warning ("Got result code %u from requesting name", request_ret);
1244 g_object_unref (self);
1250 gmyth_dbus_server_cancel_shutdown (GMythDbusServer *self)
1252 GMythDbusServerPrivate *priv;
1254 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (self);
1256 if (priv->shutdown_cb_id)
1258 g_source_remove (priv->shutdown_cb_id);
1259 priv->shutdown_cb_id = 0;
1264 gmyth_dbus_server_shutdown_cb (GMythDbusServer *self)
1266 GMythDbusServerPrivate *priv;
1268 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (self);
1270 priv->shutdown_cb_id = 0;
1271 g_signal_emit (self, signals[SHUTDOWN], 0);