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,
143 const gchar *program_id,
144 const gchar *start_time,
145 const gchar *end_time,
147 const gchar *description,
150 static gboolean gmyth_dbus_server_add_exception (GObject *obj,
153 const gchar *program_id,
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,
223 gmyth_debug ("Not connected with MythTV Server");
229 priv->myth_epg = gmyth_epg_new();
230 if (!gmyth_epg_connect (priv->myth_epg, priv->myth_backend))
232 g_object_unref (priv->myth_epg);
233 priv->myth_epg = NULL;
237 GMYTH_DBUS_ERROR_EPG,
238 _("Fail to connect with EPG"));
239 gmyth_debug ("Fail to connected with EPG");
245 gmyth_debug ("Connected EPG");
250 gmyth_dbus_server_connect_scheduler (GMythDbusServer *server,
253 GMythDbusServerPrivate *priv;
254 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
256 if (!priv->connected)
260 GMYTH_DBUS_ERROR_CONNECTION,
263 gmyth_debug ("Not connected with MythTV Server");
267 if (!priv->myth_scheduler)
269 priv->myth_scheduler = gmyth_scheduler_new ();
270 if (!gmyth_scheduler_connect (priv->myth_scheduler,
273 g_object_unref (priv->myth_scheduler);
274 priv->myth_scheduler = NULL;
278 GMYTH_DBUS_ERROR_SCHEDULE,
279 _("Fail to connect with Schedule"));
281 gmyth_debug (_("Fail to connect with Schedule"));
286 gmyth_debug ("Connected with Schedule");
291 gmyth_dbus_server_connect (GObject *obj,
295 const gchar *password,
299 GMythDbusServerPrivate *priv;
303 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
307 gmyth_debug ("Release Old connection");
308 gmyth_dbus_server_internal_disconnect (obj, NULL);
311 gmyth_dbus_server_cancel_shutdown (GMYTH_DBUS_SERVER (obj));
313 priv->myth_backend = gmyth_backend_info_new_full (host,
319 s = gmyth_backend_info_get_connected_socket (priv->myth_backend);
322 gmyth_debug ("Connected");
323 priv->connected = TRUE;
328 gmyth_debug ("Fail to connect with MythTVServer");
329 priv->connected = FALSE;
330 g_object_unref (priv->myth_backend);
331 priv->myth_backend = NULL;
335 GMYTH_DBUS_ERROR_CONNECTION,
336 _("Fail to connect with backend"));
339 return priv->connected;
343 gmyth_dbus_server_connected (GObject *obj,
347 GMythDbusServerPrivate *priv;
351 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
353 if (priv->myth_backend)
361 gmyth_dbus_server_disconnect (GObject *obj,
364 GMythDbusServerPrivate *priv;
366 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
369 gmyth_dbus_server_internal_disconnect (obj, error);
370 priv->shutdown_cb_id = g_timeout_add (60000,
371 (GSourceFunc) gmyth_dbus_server_shutdown_cb, obj);
378 gmyth_dbus_server_internal_disconnect (GObject *obj,
381 GMythDbusServerPrivate *priv;
383 g_debug ("%s:%d", __FUNCTION__, __LINE__);
385 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
389 g_object_unref (priv->myth_epg);
390 priv->myth_epg = NULL;
394 if (priv->myth_backend)
396 g_object_unref (priv->myth_backend);
397 priv->myth_backend = NULL;
400 if (priv->myth_scheduler)
402 g_object_unref (priv->myth_scheduler);
403 priv->myth_scheduler = NULL;
406 priv->connected = FALSE;
410 gmyth_dbus_server_get_server_info (GObject *obj,
411 guint64 *total_space,
416 GMythBackendDetails *details;
417 GMythDbusServerPrivate *priv;
418 gboolean ret = FALSE;
421 g_debug ("%s:%d", __FUNCTION__, __LINE__);
422 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
424 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
426 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
432 GMYTH_DBUS_ERROR_MYTHTV,
433 _("MythTv not avaliable"));
439 gmyth_util_get_backend_details (socket,
443 *total_space = details->total_space;
444 *used_space = details->used_space;
445 *free_space = *total_space - *used_space;
446 gmyth_util_backend_details_free (details);
454 GMYTH_DBUS_ERROR_MYTHTV,
455 _("Fail to get MythTv details"));
458 g_object_unref (socket);
465 gmyth_dbus_server_parse_channel_info (GMythChannelInfo *info,
468 dbus_g_type_struct_set (val,
470 1, info->channel_num->str,
471 2, info->channel_name->str,
472 3, info->channel_icon->str,
477 gmyth_dbus_server_get_channel_info (GObject *obj,
483 GMythChannelInfo *ch_info;
484 GMythDbusServerPrivate *priv;
486 g_debug ("%s:%d", __FUNCTION__, __LINE__);
487 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
489 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
491 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
496 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
498 ch_info = gmyth_epg_get_channel_info (priv->myth_epg, channel_id);
502 g_value_init (&v, ch_type);
503 g_value_take_boxed (&v, dbus_g_type_specialized_construct (ch_type));
504 gmyth_dbus_server_parse_channel_info (ch_info, &v);
506 *info = g_value_get_boxed (&v);
513 GMYTH_DBUS_ERROR_EPG,
514 _("no channel info avaliable"));
522 gmyth_dbus_server_get_channel_list (GObject *obj,
523 GPtrArray **channels,
530 GMythDbusServerPrivate *priv;
532 g_debug ("%s:%d", __FUNCTION__, __LINE__);
533 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
535 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
536 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
541 len = gmyth_epg_get_channel_list (priv->myth_epg, &lst);
543 *channels = g_ptr_array_sized_new (len);
544 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
546 for (walk = lst; walk != NULL; walk = walk->next)
549 GMythChannelInfo *data;
551 data = (GMythChannelInfo *) walk->data;
553 g_value_init (&ch, ch_type);
554 g_value_take_boxed (&ch, dbus_g_type_specialized_construct (ch_type));
555 gmyth_dbus_server_parse_channel_info (data, &ch);
556 g_ptr_array_add (*channels, g_value_get_boxed (&ch));
559 gmyth_free_channel_list (lst);
564 gmyth_dbus_server_file_exists (GObject *obj,
565 const gchar *file_name,
569 GMythDbusServerPrivate *priv;
570 g_debug ("%s:%d", __FUNCTION__, __LINE__);
571 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
573 g_return_val_if_fail (priv->myth_backend, FALSE);
575 *exists = gmyth_util_file_exists (priv->myth_backend, file_name);
581 gmyth_dbus_server_get_program_list (GObject *obj,
583 const gchar *start_time,
584 const gchar *end_time,
585 GPtrArray **programs,
592 GTimeVal start_time_val;
593 GTimeVal end_time_val;
594 GMythDbusServerPrivate *priv;
596 g_debug ("%s:%d", __FUNCTION__, __LINE__);
597 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
599 g_return_val_if_fail (priv->myth_backend, FALSE);
600 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
603 g_time_val_from_iso8601 (start_time, &start_time_val);
604 g_time_val_from_iso8601 (end_time, &end_time_val);
607 len = gmyth_epg_get_program_list (priv->myth_epg,
613 *programs = g_ptr_array_sized_new (len);
614 program_type = GMYTH_DBUS_PROGRAM_G_TYPE;
616 for (walk = list; walk != NULL; walk = walk->next)
618 GValue program = { 0, };
621 GMythProgramInfo *data;
623 data = (GMythProgramInfo *) walk->data;
628 g_value_init (&program, program_type);
629 g_value_take_boxed (&program,
630 dbus_g_type_specialized_construct (program_type));
632 start_str = g_time_val_to_iso8601 (data->startts);
633 end_str = g_time_val_to_iso8601 (data->endts);
635 dbus_g_type_struct_set (&program,
640 4, data->subtitle->str,
641 5, data->description->str,
642 6, data->category->str,
645 g_ptr_array_add (*programs, g_value_get_boxed (&program));
651 gmyth_free_program_list (list);
653 g_debug ("%s:%d", __FUNCTION__, __LINE__);
658 gmyth_dbus_server_parse_recorded_info (RecordedInfo *info,
664 start_str = g_time_val_to_iso8601 (info->start_time);
665 end_str = g_time_val_to_iso8601 (info->end_time);
667 dbus_g_type_struct_set (val,
669 1, info->program_id->str,
674 6, info->subtitle->str,
675 7, info->description->str,
676 8, info->category->str,
677 9, info->basename->str,
685 gmyth_dbus_server_get_recorded_info (GObject *obj,
686 const gchar *basename,
691 GMythDbusServerPrivate *priv;
692 RecordedInfo *record_info;
695 g_debug ("%s:%d", __FUNCTION__, __LINE__);
696 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
698 g_return_val_if_fail (priv->myth_backend, FALSE);
700 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
703 record_type = GMYTH_DBUS_RECORD_G_TYPE;
705 record_info = gmyth_scheduler_get_recorded_info (priv->myth_scheduler,
712 g_value_init (&r, record_type);
713 g_value_take_boxed (&r,
714 dbus_g_type_specialized_construct (record_type));
716 gmyth_dbus_server_parse_recorded_info (record_info, &r);
717 gmyth_recorded_info_free (record_info);
719 *info = g_value_get_boxed (&r);
727 GMYTH_DBUS_ERROR_EPG,
728 _("no record info avaliable"));
737 gmyth_dbus_server_get_recorded_list (GObject *obj,
745 GMythDbusServerPrivate *priv;
747 g_debug ("%s:%d", __FUNCTION__, __LINE__);
748 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
750 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
751 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
755 len = gmyth_scheduler_get_recorded_list (priv->myth_scheduler,
758 record_type = GMYTH_DBUS_RECORD_G_TYPE;
759 *records = g_ptr_array_sized_new (len);
761 for (walk = list; walk != NULL; walk = walk->next)
763 GValue record = { 0, };
766 data = (RecordedInfo *) walk->data;
768 g_value_init (&record, record_type);
769 g_value_take_boxed (&record,
770 dbus_g_type_specialized_construct (record_type));
772 gmyth_dbus_server_parse_recorded_info (data, &record);
774 g_ptr_array_add (*records, g_value_get_boxed (&record));
775 //g_value_unset (&record);
778 gmyth_recorded_info_list_free (list);
785 gmyth_dbus_server_get_schedule_list (GObject *obj,
786 GPtrArray **schedules,
793 GMythDbusServerPrivate *priv;
795 g_debug ("%s:%d", __FUNCTION__, __LINE__);
796 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
798 g_return_val_if_fail (priv->myth_backend, FALSE);
799 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
803 len = gmyth_scheduler_get_schedule_list (priv->myth_scheduler,
806 *schedules = g_ptr_array_sized_new (len);
807 schedule_type = GMYTH_DBUS_SCHEDULE_G_TYPE;
809 for (walk = list; walk != NULL; walk = walk->next)
811 GValue schedule = { 0, };
813 gchar *start_str_time;
816 data = (ScheduleInfo *) walk->data;
818 g_value_init (&schedule, schedule_type);
819 g_value_take_boxed (&schedule,
820 dbus_g_type_specialized_construct (schedule_type));
822 start_str_time = g_time_val_to_iso8601 (data->start_time);
823 end_str_time = g_time_val_to_iso8601 (data->end_time);
825 dbus_g_type_struct_set (&schedule,
826 0, data->schedule_id,
827 1, data->program_id->str,
832 6, data->subtitle->str,
833 7, data->description->str,
834 8, data->category->str,
838 g_ptr_array_add (*schedules, g_value_get_boxed (&schedule));
840 g_free (start_str_time);
841 g_free (end_str_time);
844 gmyth_schedule_info_list_free (list);
851 gmyth_dbus_server_get_thumbnail (GObject *obj,
856 GMythFileTransfer *file_transfer;
858 GMythFileReadResult result;
859 GMythDbusServerPrivate *priv;
861 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
863 file_transfer = NULL;
865 g_return_val_if_fail (priv->myth_backend, FALSE);
867 if (!gmyth_util_file_exists (priv->myth_backend, uri))
871 GMYTH_DBUS_ERROR_MYTHTV,
872 _("File not exists"));
877 file_transfer = gmyth_file_transfer_new (priv->myth_backend);
879 if (!gmyth_file_transfer_open (file_transfer, uri))
883 GMYTH_DBUS_ERROR_MYTHTV,
884 _("Fail to open file"));
888 filesize = gmyth_file_transfer_get_filesize (file_transfer);
892 *image = g_byte_array_new ();
893 result = gmyth_file_transfer_read (file_transfer, *image, filesize, FALSE);
894 if (result == GMYTH_FILE_READ_ERROR)
898 GMYTH_DBUS_ERROR_MYTHTV,
899 _("Fail to read file"));
904 gmyth_file_transfer_close (file_transfer);
905 g_object_unref (file_transfer);
907 if (filesize > (*image)->len)
911 GMYTH_DBUS_ERROR_MYTHTV,
921 g_byte_array_free (*image, TRUE);
922 g_object_unref(file_transfer);
927 gmyth_dbus_server_get_channel_icon (GObject *obj,
932 GMythChannelInfo *channel = NULL;
935 GMythDbusServerPrivate *priv;
937 g_debug ("%s:%d", __FUNCTION__, __LINE__);
938 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
939 g_return_val_if_fail (priv->myth_backend, FALSE);
941 channel = gmyth_epg_get_channel_info (priv->myth_epg,
950 GMYTH_DBUS_ERROR_MYTHTV,
951 _("Invalid channel"));
956 if (!gmyth_epg_channel_has_icon(priv->myth_epg, channel))
958 gmyth_channel_info_free (channel);
961 GMYTH_DBUS_ERROR_MYTHTV,
962 _("Channel does not have icon available"));
969 if (!gmyth_epg_channel_get_icon (priv->myth_epg,
974 gmyth_channel_info_free (channel);
977 GMYTH_DBUS_ERROR_MYTHTV,
978 _("Could not get channel icon for channel id = %u"),
983 *icon = g_byte_array_sized_new (icon_length);
984 *icon = g_byte_array_append (*icon, icon_data, icon_length);
987 gmyth_channel_info_free(channel);
993 gmyth_dbus_server_stop_recording (GObject *obj,
998 gboolean ret = FALSE;
999 GMythDbusServerPrivate *priv;
1001 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1002 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1004 g_return_val_if_fail (priv->myth_backend, FALSE);
1005 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1008 ret = gmyth_scheduler_stop_recording (priv->myth_scheduler,
1014 static ScheduleInfo*
1015 gmyth_dbus_server_new_schedule_info (const gchar* description,
1017 const gchar* program_id,
1018 GTimeVal *start_vtime,
1019 GTimeVal *end_vtime)
1021 ScheduleInfo *new_sched_info;
1023 new_sched_info = g_new0(ScheduleInfo, 1);
1025 /* record_id == -1 for generating a new id */
1026 new_sched_info->schedule_id = -1;
1028 new_sched_info->channel_id = channel_id;
1029 new_sched_info->program_id = g_string_new (program_id);
1030 new_sched_info->start_time = g_new0 (GTimeVal, 1);
1031 *new_sched_info->start_time = *start_vtime;
1032 new_sched_info->end_time = g_new0 (GTimeVal, 1);
1033 *new_sched_info->end_time = *end_vtime;
1035 /* TODO: there is no frequency field */
1036 /*new_sched_info->frequency = -1;*/
1038 if (description != NULL) {
1039 /* FIXME: description parameter is used as title and description */
1040 new_sched_info->title = g_string_new(description);
1041 new_sched_info->description = g_string_new(description);
1044 return new_sched_info;
1048 gmyth_dbus_server_add_schedule (GObject *obj,
1050 const gchar *program_id,
1051 const gchar *start_time,
1052 const gchar *end_time,
1054 const gchar *description,
1058 ScheduleInfo *sch_info;
1059 GTimeVal start_vtime;
1061 GMythDbusServerPrivate *priv;
1063 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1064 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1068 g_return_val_if_fail (priv->myth_backend, FALSE);
1070 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1074 g_time_val_from_iso8601 (start_time, &start_vtime);
1075 g_time_val_from_iso8601 (end_time, &end_vtime);
1076 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1077 sch_info = gmyth_dbus_server_new_schedule_info (description,
1083 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1084 if (sch_info != NULL) {
1085 GMythScheduleType type;
1087 gboolean has_record;
1090 GMYTH_SCHEDULE_ALL_OCCURRENCES :
1091 GMYTH_SCHEDULE_ONE_OCCURRENCE);
1093 g_get_current_time (&t_now);
1095 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1096 has_record = gmyth_scheduler_was_recorded_before (priv->myth_scheduler,
1098 (time_t) start_vtime.tv_sec);
1101 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1102 if ((t_now.tv_sec >= start_vtime.tv_sec)
1103 && (t_now.tv_sec <= end_vtime.tv_sec) && has_record)
1105 GMythSocket *socket;
1106 gboolean res = FALSE;
1108 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1109 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
1110 res = gmyth_scheduler_reactivate_schedule(priv->myth_scheduler,
1112 (time_t) start_vtime.tv_sec);
1114 GMythStringList *slist = gmyth_string_list_new();
1116 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1117 gmyth_string_list_append_char_array(slist, "RESCHEDULE_RECORDINGS 0");
1118 gmyth_socket_sendreceive_stringlist(socket, slist);
1119 res = (gmyth_string_list_get_int(slist, 0) == 1);
1120 g_object_unref(slist);
1121 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1123 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1125 g_object_unref(socket);
1130 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1131 if (!gmyth_scheduler_add_schedule_full (priv->myth_scheduler,
1135 g_warning("Could not add schedule entry");
1139 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1140 (*schedule_id) = sch_info->schedule_id;
1141 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1142 gmyth_schedule_info_free (sch_info);
1143 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1151 gmyth_dbus_server_add_exception (GObject *obj,
1154 const gchar *program_id,
1155 const gchar *start_time,
1156 const gchar *end_time,
1157 const gchar *description,
1160 ScheduleInfo *sch_info;
1161 GTimeVal start_vtime;
1163 GMythDbusServerPrivate *priv;
1165 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1166 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1168 g_return_val_if_fail (priv->myth_backend, FALSE);
1170 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1173 g_time_val_from_iso8601 (start_time, &start_vtime);
1174 g_time_val_from_iso8601 (end_time, &end_vtime);
1176 sch_info = gmyth_dbus_server_new_schedule_info (description,
1181 if (sch_info != NULL)
1183 if (!gmyth_scheduler_add_exception (priv->myth_scheduler,
1187 g_warning ("Could not add schedule exception");
1188 gmyth_schedule_info_free (sch_info);
1192 gmyth_schedule_info_free (sch_info);
1199 gmyth_dbus_server_remove_schedule (GObject *obj,
1203 GMythDbusServerPrivate *priv;
1205 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1206 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1208 g_return_val_if_fail (priv->myth_backend, FALSE);
1210 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1213 return gmyth_scheduler_delete_schedule (priv->myth_scheduler, schedule_id);
1217 gmyth_dbus_server_start_dbus_service (void)
1219 GError *error = NULL;
1221 DBusGConnection *bus;
1223 GMythDbusServer *self;
1225 self = g_object_new (GMYTH_DBUS_SERVER_TYPE, NULL);
1226 g_return_val_if_fail (self, FALSE);
1228 /* TODO: should verify if this service was already started */
1230 /* connect to session bus */
1231 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
1234 g_warning ("Could not connect to dbus: %s", error->message);
1235 g_error_free (error);
1239 /* register dbus object */
1240 dbus_g_connection_register_g_object (bus,
1241 GMYTH_DBUS_SERVER_PATH, G_OBJECT (self));
1243 proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
1244 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
1246 /* registering download manager service */
1247 if (!org_freedesktop_DBus_request_name (proxy, GMYTH_DBUS_SERVER_IFACE,
1248 0, &request_ret, &error))
1250 g_warning ("Unable to register dbus service: %d %s",
1251 error->code, error->message);
1252 g_error_free (error);
1256 if (request_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
1258 g_warning ("Got result code %u from requesting name", request_ret);
1265 g_object_unref (self);
1271 gmyth_dbus_server_cancel_shutdown (GMythDbusServer *self)
1273 GMythDbusServerPrivate *priv;
1275 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (self);
1277 if (priv->shutdown_cb_id)
1279 g_source_remove (priv->shutdown_cb_id);
1280 priv->shutdown_cb_id = 0;
1285 gmyth_dbus_server_shutdown_cb (GMythDbusServer *self)
1287 GMythDbusServerPrivate *priv;
1289 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (self);
1291 priv->shutdown_cb_id = 0;
1292 g_signal_emit (self, signals[SHUTDOWN], 0);