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_check_db_connection (GObject *self,
93 const gchar *password,
96 static gboolean gmyth_dbus_server_get_channel_list (GObject *obj,
99 static gboolean gmyth_dbus_server_get_channel_info (GObject *obj,
103 static gboolean gmyth_dbus_server_file_exists (GObject *obj,
104 const gchar *file_name,
107 static gboolean gmyth_dbus_server_get_recorded_list (GObject *obj,
108 GPtrArray **channels,
110 static gboolean gmyth_dbus_server_get_recorded_info (GObject *obj,
111 const gchar *basename,
114 static gboolean gmyth_dbus_server_get_program_list (GObject *obj,
116 const gchar *start_time,
117 const gchar *end_time,
118 GPtrArray **program_list,
120 static gboolean gmyth_dbus_server_get_schedule_list (GObject *obj,
121 GPtrArray **schedule_list,
123 static gboolean gmyth_dbus_server_connected (GObject *obj,
126 static gboolean gmyth_dbus_server_disconnect (GObject *obj,
128 static void gmyth_dbus_server_internal_disconnect
131 static gboolean gmyth_dbus_server_get_server_info (GObject *obj,
132 guint64 *total_space,
136 static gboolean gmyth_dbus_server_get_thumbnail (GObject *obj,
140 static gboolean gmyth_dbus_server_get_channel_icon (GObject *obj,
144 static gboolean gmyth_dbus_server_stop_recording (GObject *obj,
148 static gboolean gmyth_dbus_server_add_schedule (GObject *obj,
150 const gchar *program_id,
151 const gchar *start_time,
152 const gchar *end_time,
154 const gchar *description,
157 static gboolean gmyth_dbus_server_add_exception (GObject *obj,
160 const gchar *program_id,
161 const gchar *start_time,
162 const gchar *end_time,
163 const gchar *description,
165 static gboolean gmyth_dbus_server_remove_schedule (GObject *obj,
170 #include "gmyth-dbus-server-glue.h"
173 static guint signals[LAST_SIGNAL] = { 0 };
175 G_DEFINE_TYPE (GMythDbusServer, gmyth_dbus_server, G_TYPE_OBJECT);
178 gmyth_dbus_server_class_init (GMythDbusServerClass *klass)
180 GObjectClass *object_class = G_OBJECT_CLASS (klass);
182 g_type_class_add_private (klass, sizeof (GMythDbusServerPrivate));
184 object_class->dispose = gmyth_dbus_server_dispose;
185 object_class->finalize = gmyth_dbus_server_finalize;
188 g_signal_new ("shutdown",
189 G_OBJECT_CLASS_TYPE (object_class),
190 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
193 g_cclosure_marshal_VOID__VOID,
194 G_TYPE_NONE, 0, G_TYPE_NONE);
196 dbus_g_object_type_install_info (GMYTH_DBUS_SERVER_TYPE,
197 &dbus_glib_gmyth_dbus_server_object_info);
201 gmyth_dbus_server_init (GMythDbusServer *self)
206 gmyth_dbus_server_dispose (GObject *object)
208 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->dispose (object);
212 gmyth_dbus_server_finalize (GObject *object)
214 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->finalize (object);
218 gmyth_dbus_server_connect_epg (GMythDbusServer *server, GError **error)
220 GMythDbusServerPrivate *priv;
221 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
223 if (!priv->connected)
227 GMYTH_DBUS_ERROR_CONNECTION,
230 gmyth_debug ("Not connected with MythTV Server");
236 priv->myth_epg = gmyth_epg_new();
237 if (!gmyth_epg_connect (priv->myth_epg, priv->myth_backend))
239 g_object_unref (priv->myth_epg);
240 priv->myth_epg = NULL;
244 GMYTH_DBUS_ERROR_EPG,
245 _("Fail to connect with EPG"));
246 gmyth_debug ("Fail to connected with EPG");
252 gmyth_debug ("Connected EPG");
257 gmyth_dbus_server_connect_scheduler (GMythDbusServer *server,
260 GMythDbusServerPrivate *priv;
261 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
263 if (!priv->connected)
267 GMYTH_DBUS_ERROR_CONNECTION,
270 gmyth_debug ("Not connected with MythTV Server");
274 if (!priv->myth_scheduler)
276 priv->myth_scheduler = gmyth_scheduler_new ();
277 if (!gmyth_scheduler_connect (priv->myth_scheduler,
280 g_object_unref (priv->myth_scheduler);
281 priv->myth_scheduler = NULL;
285 GMYTH_DBUS_ERROR_SCHEDULE,
286 _("Fail to connect with Schedule"));
288 gmyth_debug (_("Fail to connect with Schedule"));
293 gmyth_debug ("Connected with Schedule");
298 gmyth_dbus_server_connect (GObject *obj,
302 const gchar *password,
306 GMythDbusServerPrivate *priv;
310 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
314 gmyth_debug ("Release Old connection");
315 gmyth_dbus_server_internal_disconnect (obj, NULL);
318 gmyth_dbus_server_cancel_shutdown (GMYTH_DBUS_SERVER (obj));
320 priv->myth_backend = gmyth_backend_info_new_full (host,
326 s = gmyth_backend_info_get_connected_socket (priv->myth_backend);
329 gmyth_debug ("Connected");
330 priv->connected = TRUE;
335 gmyth_debug ("Fail to connect with MythTVServer");
336 priv->connected = FALSE;
337 g_object_unref (priv->myth_backend);
338 priv->myth_backend = NULL;
342 GMYTH_DBUS_ERROR_CONNECTION,
343 _("Fail to connect with backend"));
346 return priv->connected;
350 gmyth_dbus_server_connected (GObject *obj,
354 GMythDbusServerPrivate *priv;
358 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
360 if (priv->myth_backend)
368 gmyth_dbus_server_disconnect (GObject *obj,
371 GMythDbusServerPrivate *priv;
373 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
376 gmyth_dbus_server_internal_disconnect (obj, error);
377 priv->shutdown_cb_id = g_timeout_add (60000,
378 (GSourceFunc) gmyth_dbus_server_shutdown_cb, obj);
385 gmyth_dbus_server_internal_disconnect (GObject *obj,
388 GMythDbusServerPrivate *priv;
390 g_debug ("%s:%d", __FUNCTION__, __LINE__);
392 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
396 g_object_unref (priv->myth_epg);
397 priv->myth_epg = NULL;
401 if (priv->myth_backend)
403 g_object_unref (priv->myth_backend);
404 priv->myth_backend = NULL;
407 if (priv->myth_scheduler)
409 g_object_unref (priv->myth_scheduler);
410 priv->myth_scheduler = NULL;
413 priv->connected = FALSE;
417 gmyth_dbus_server_get_server_info (GObject *obj,
418 guint64 *total_space,
423 GMythBackendDetails *details;
424 GMythDbusServerPrivate *priv;
425 gboolean ret = FALSE;
428 g_debug ("%s:%d", __FUNCTION__, __LINE__);
429 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
431 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
433 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
439 GMYTH_DBUS_ERROR_MYTHTV,
440 _("MythTv not avaliable"));
446 gmyth_util_get_backend_details (socket,
450 *total_space = details->total_space;
451 *used_space = details->used_space;
452 *free_space = *total_space - *used_space;
453 gmyth_util_backend_details_free (details);
461 GMYTH_DBUS_ERROR_MYTHTV,
462 _("Fail to get MythTv details"));
465 g_object_unref (socket);
472 gmyth_dbus_server_parse_channel_info (GMythChannelInfo *info,
475 dbus_g_type_struct_set (val,
477 1, info->channel_num->str,
478 2, info->channel_name->str,
479 3, info->channel_icon->str,
484 gmyth_dbus_server_get_channel_info (GObject *obj,
490 GMythChannelInfo *ch_info;
491 GMythDbusServerPrivate *priv;
493 g_debug ("%s:%d", __FUNCTION__, __LINE__);
494 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
496 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
498 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
503 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
505 ch_info = gmyth_epg_get_channel_info (priv->myth_epg, channel_id);
509 g_value_init (&v, ch_type);
510 g_value_take_boxed (&v, dbus_g_type_specialized_construct (ch_type));
511 gmyth_dbus_server_parse_channel_info (ch_info, &v);
513 *info = g_value_get_boxed (&v);
520 GMYTH_DBUS_ERROR_EPG,
521 _("no channel info avaliable"));
529 gmyth_dbus_server_get_channel_list (GObject *obj,
530 GPtrArray **channels,
537 GMythDbusServerPrivate *priv;
539 g_debug ("%s:%d", __FUNCTION__, __LINE__);
540 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
542 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
543 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
548 len = gmyth_epg_get_channel_list (priv->myth_epg, &lst);
550 *channels = g_ptr_array_sized_new (len);
551 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
553 for (walk = lst; walk != NULL; walk = walk->next)
556 GMythChannelInfo *data;
558 data = (GMythChannelInfo *) walk->data;
560 g_value_init (&ch, ch_type);
561 g_value_take_boxed (&ch, dbus_g_type_specialized_construct (ch_type));
562 gmyth_dbus_server_parse_channel_info (data, &ch);
563 g_ptr_array_add (*channels, g_value_get_boxed (&ch));
566 gmyth_free_channel_list (lst);
571 gmyth_dbus_server_file_exists (GObject *obj,
572 const gchar *file_name,
576 GMythDbusServerPrivate *priv;
577 g_debug ("%s:%d", __FUNCTION__, __LINE__);
578 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
580 g_return_val_if_fail (priv->myth_backend, FALSE);
582 *exists = gmyth_util_file_exists (priv->myth_backend, file_name);
588 gmyth_dbus_server_get_program_list (GObject *obj,
590 const gchar *start_time,
591 const gchar *end_time,
592 GPtrArray **programs,
599 GTimeVal start_time_val;
600 GTimeVal end_time_val;
601 GMythDbusServerPrivate *priv;
603 g_debug ("%s:%d", __FUNCTION__, __LINE__);
604 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
606 g_return_val_if_fail (priv->myth_backend, FALSE);
607 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
610 g_time_val_from_iso8601 (start_time, &start_time_val);
611 g_time_val_from_iso8601 (end_time, &end_time_val);
614 len = gmyth_epg_get_program_list (priv->myth_epg,
620 *programs = g_ptr_array_sized_new (len);
621 program_type = GMYTH_DBUS_PROGRAM_G_TYPE;
623 for (walk = list; walk != NULL; walk = walk->next)
625 GValue program = { 0, };
628 GMythProgramInfo *data;
630 data = (GMythProgramInfo *) walk->data;
635 g_value_init (&program, program_type);
636 g_value_take_boxed (&program,
637 dbus_g_type_specialized_construct (program_type));
639 start_str = g_time_val_to_iso8601 (data->startts);
640 end_str = g_time_val_to_iso8601 (data->endts);
642 dbus_g_type_struct_set (&program,
647 4, data->subtitle->str,
648 5, data->description->str,
649 6, data->category->str,
652 g_ptr_array_add (*programs, g_value_get_boxed (&program));
658 gmyth_free_program_list (list);
660 g_debug ("%s:%d", __FUNCTION__, __LINE__);
665 gmyth_dbus_server_parse_recorded_info (RecordedInfo *info,
671 start_str = g_time_val_to_iso8601 (info->start_time);
672 end_str = g_time_val_to_iso8601 (info->end_time);
674 dbus_g_type_struct_set (val,
676 1, info->program_id->str,
681 6, info->subtitle->str,
682 7, info->description->str,
683 8, info->category->str,
684 9, info->basename->str,
692 gmyth_dbus_server_get_recorded_info (GObject *obj,
693 const gchar *basename,
698 GMythDbusServerPrivate *priv;
699 RecordedInfo *record_info;
702 g_debug ("%s:%d", __FUNCTION__, __LINE__);
703 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
705 g_return_val_if_fail (priv->myth_backend, FALSE);
707 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
710 record_type = GMYTH_DBUS_RECORD_G_TYPE;
712 record_info = gmyth_scheduler_get_recorded_info (priv->myth_scheduler,
719 g_value_init (&r, record_type);
720 g_value_take_boxed (&r,
721 dbus_g_type_specialized_construct (record_type));
723 gmyth_dbus_server_parse_recorded_info (record_info, &r);
724 gmyth_recorded_info_free (record_info);
726 *info = g_value_get_boxed (&r);
734 GMYTH_DBUS_ERROR_EPG,
735 _("no record info avaliable"));
744 gmyth_dbus_server_get_recorded_list (GObject *obj,
752 GMythDbusServerPrivate *priv;
754 g_debug ("%s:%d", __FUNCTION__, __LINE__);
755 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
757 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
758 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
762 len = gmyth_scheduler_get_recorded_list (priv->myth_scheduler,
765 record_type = GMYTH_DBUS_RECORD_G_TYPE;
766 *records = g_ptr_array_sized_new (len);
768 for (walk = list; walk != NULL; walk = walk->next)
770 GValue record = { 0, };
773 data = (RecordedInfo *) walk->data;
775 g_value_init (&record, record_type);
776 g_value_take_boxed (&record,
777 dbus_g_type_specialized_construct (record_type));
779 gmyth_dbus_server_parse_recorded_info (data, &record);
781 g_ptr_array_add (*records, g_value_get_boxed (&record));
782 //g_value_unset (&record);
785 gmyth_recorded_info_list_free (list);
792 gmyth_dbus_server_get_schedule_list (GObject *obj,
793 GPtrArray **schedules,
800 GMythDbusServerPrivate *priv;
802 g_debug ("%s:%d", __FUNCTION__, __LINE__);
803 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
805 g_return_val_if_fail (priv->myth_backend, FALSE);
806 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
810 len = gmyth_scheduler_get_schedule_list (priv->myth_scheduler,
813 *schedules = g_ptr_array_sized_new (len);
814 schedule_type = GMYTH_DBUS_SCHEDULE_G_TYPE;
816 for (walk = list; walk != NULL; walk = walk->next)
818 GValue schedule = { 0, };
820 gchar *start_str_time;
823 data = (ScheduleInfo *) walk->data;
825 g_value_init (&schedule, schedule_type);
826 g_value_take_boxed (&schedule,
827 dbus_g_type_specialized_construct (schedule_type));
829 start_str_time = g_time_val_to_iso8601 (data->start_time);
830 end_str_time = g_time_val_to_iso8601 (data->end_time);
832 dbus_g_type_struct_set (&schedule,
833 0, data->schedule_id,
834 1, data->program_id->str,
839 6, data->subtitle->str,
840 7, data->description->str,
841 8, data->category->str,
845 g_ptr_array_add (*schedules, g_value_get_boxed (&schedule));
847 g_free (start_str_time);
848 g_free (end_str_time);
851 gmyth_schedule_info_list_free (list);
858 gmyth_dbus_server_get_thumbnail (GObject *obj,
863 GMythFileTransfer *file_transfer;
865 GMythFileReadResult result;
866 GMythDbusServerPrivate *priv;
868 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
870 file_transfer = NULL;
872 g_return_val_if_fail (priv->myth_backend, FALSE);
874 if (!gmyth_util_file_exists (priv->myth_backend, uri))
878 GMYTH_DBUS_ERROR_MYTHTV,
879 _("File not exists"));
884 file_transfer = gmyth_file_transfer_new (priv->myth_backend);
886 if (!gmyth_file_transfer_open (file_transfer, uri))
890 GMYTH_DBUS_ERROR_MYTHTV,
891 _("Fail to open file"));
895 filesize = gmyth_file_transfer_get_filesize (file_transfer);
899 *image = g_byte_array_new ();
900 result = gmyth_file_transfer_read (file_transfer, *image, filesize, FALSE);
901 if (result == GMYTH_FILE_READ_ERROR)
905 GMYTH_DBUS_ERROR_MYTHTV,
906 _("Fail to read file"));
911 gmyth_file_transfer_close (file_transfer);
912 g_object_unref (file_transfer);
914 if (filesize > (*image)->len)
918 GMYTH_DBUS_ERROR_MYTHTV,
928 g_byte_array_free (*image, TRUE);
929 g_object_unref(file_transfer);
934 gmyth_dbus_server_get_channel_icon (GObject *obj,
939 GMythChannelInfo *channel = NULL;
942 GMythDbusServerPrivate *priv;
944 g_debug ("%s:%d", __FUNCTION__, __LINE__);
945 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
946 g_return_val_if_fail (priv->myth_backend, FALSE);
948 channel = gmyth_epg_get_channel_info (priv->myth_epg,
957 GMYTH_DBUS_ERROR_MYTHTV,
958 _("Invalid channel"));
963 if (!gmyth_epg_channel_has_icon(priv->myth_epg, channel))
965 gmyth_channel_info_free (channel);
968 GMYTH_DBUS_ERROR_MYTHTV,
969 _("Channel does not have icon available"));
976 if (!gmyth_epg_channel_get_icon (priv->myth_epg,
981 gmyth_channel_info_free (channel);
984 GMYTH_DBUS_ERROR_MYTHTV,
985 _("Could not get channel icon for channel id = %u"),
990 *icon = g_byte_array_sized_new (icon_length);
991 *icon = g_byte_array_append (*icon, icon_data, icon_length);
994 gmyth_channel_info_free(channel);
1000 gmyth_dbus_server_stop_recording (GObject *obj,
1005 gboolean ret = FALSE;
1006 GMythDbusServerPrivate *priv;
1008 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1009 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1011 g_return_val_if_fail (priv->myth_backend, FALSE);
1012 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1015 ret = gmyth_scheduler_stop_recording (priv->myth_scheduler,
1021 static ScheduleInfo*
1022 gmyth_dbus_server_new_schedule_info (const gchar* description,
1024 const gchar* program_id,
1025 GTimeVal *start_vtime,
1026 GTimeVal *end_vtime)
1028 ScheduleInfo *new_sched_info;
1030 new_sched_info = g_new0(ScheduleInfo, 1);
1032 /* record_id == -1 for generating a new id */
1033 new_sched_info->schedule_id = -1;
1035 new_sched_info->channel_id = channel_id;
1036 new_sched_info->program_id = g_string_new (program_id);
1037 new_sched_info->start_time = g_new0 (GTimeVal, 1);
1038 *new_sched_info->start_time = *start_vtime;
1039 new_sched_info->end_time = g_new0 (GTimeVal, 1);
1040 *new_sched_info->end_time = *end_vtime;
1042 /* TODO: there is no frequency field */
1043 /*new_sched_info->frequency = -1;*/
1045 if (description != NULL) {
1046 /* FIXME: description parameter is used as title and description */
1047 new_sched_info->title = g_string_new(description);
1048 new_sched_info->description = g_string_new(description);
1051 return new_sched_info;
1055 gmyth_dbus_server_add_schedule (GObject *obj,
1057 const gchar *program_id,
1058 const gchar *start_time,
1059 const gchar *end_time,
1061 const gchar *description,
1065 ScheduleInfo *sch_info;
1066 GTimeVal start_vtime;
1068 GMythDbusServerPrivate *priv;
1070 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1071 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1075 g_return_val_if_fail (priv->myth_backend, FALSE);
1077 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1081 g_time_val_from_iso8601 (start_time, &start_vtime);
1082 g_time_val_from_iso8601 (end_time, &end_vtime);
1084 sch_info = gmyth_dbus_server_new_schedule_info (description,
1090 if (sch_info != NULL) {
1091 GMythScheduleType type;
1093 gboolean has_record;
1096 GMYTH_SCHEDULE_ALL_OCCURRENCES :
1097 GMYTH_SCHEDULE_ONE_OCCURRENCE);
1099 g_get_current_time (&t_now);
1101 has_record = gmyth_scheduler_was_recorded_before (priv->myth_scheduler,
1103 (time_t) start_vtime.tv_sec);
1106 if ((t_now.tv_sec >= start_vtime.tv_sec)
1107 && (t_now.tv_sec <= end_vtime.tv_sec) && has_record)
1109 GMythSocket *socket;
1110 gboolean res = FALSE;
1112 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
1113 res = gmyth_scheduler_reactivate_schedule(priv->myth_scheduler,
1115 (time_t) start_vtime.tv_sec);
1117 GMythStringList *slist = gmyth_string_list_new();
1119 gmyth_string_list_append_char_array(slist, "RESCHEDULE_RECORDINGS 0");
1120 gmyth_socket_sendreceive_stringlist(socket, slist);
1121 res = (gmyth_string_list_get_int(slist, 0) == 1);
1122 g_object_unref(slist);
1125 g_object_unref(socket);
1130 if (!gmyth_scheduler_add_schedule_full (priv->myth_scheduler,
1134 g_warning("Could not add schedule entry");
1138 (*schedule_id) = sch_info->schedule_id;
1139 gmyth_schedule_info_free (sch_info);
1147 gmyth_dbus_server_add_exception (GObject *obj,
1150 const gchar *program_id,
1151 const gchar *start_time,
1152 const gchar *end_time,
1153 const gchar *description,
1156 ScheduleInfo *sch_info;
1157 GTimeVal start_vtime;
1159 GMythDbusServerPrivate *priv;
1161 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1162 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1164 g_return_val_if_fail (priv->myth_backend, FALSE);
1166 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1169 g_time_val_from_iso8601 (start_time, &start_vtime);
1170 g_time_val_from_iso8601 (end_time, &end_vtime);
1172 sch_info = gmyth_dbus_server_new_schedule_info (description,
1177 if (sch_info != NULL)
1179 if (!gmyth_scheduler_add_exception (priv->myth_scheduler,
1183 g_warning ("Could not add schedule exception");
1184 gmyth_schedule_info_free (sch_info);
1188 gmyth_schedule_info_free (sch_info);
1195 gmyth_dbus_server_remove_schedule (GObject *obj,
1199 GMythDbusServerPrivate *priv;
1201 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1202 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1204 g_return_val_if_fail (priv->myth_backend, FALSE);
1206 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1209 return gmyth_scheduler_delete_schedule (priv->myth_scheduler, schedule_id);
1213 gmyth_dbus_server_start_dbus_service (void)
1215 GError *error = NULL;
1217 DBusGConnection *bus;
1219 GMythDbusServer *self;
1221 self = g_object_new (GMYTH_DBUS_SERVER_TYPE, NULL);
1222 g_return_val_if_fail (self, FALSE);
1224 /* TODO: should verify if this service was already started */
1226 /* connect to session bus */
1227 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
1230 g_warning ("Could not connect to dbus: %s", error->message);
1231 g_error_free (error);
1235 /* register dbus object */
1236 dbus_g_connection_register_g_object (bus,
1237 GMYTH_DBUS_SERVER_PATH, G_OBJECT (self));
1239 proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
1240 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
1242 /* registering download manager service */
1243 if (!org_freedesktop_DBus_request_name (proxy, GMYTH_DBUS_SERVER_IFACE,
1244 0, &request_ret, &error))
1246 g_warning ("Unable to register dbus service: %d %s",
1247 error->code, error->message);
1248 g_error_free (error);
1252 if (request_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
1254 g_warning ("Got result code %u from requesting name", request_ret);
1261 g_object_unref (self);
1267 gmyth_dbus_server_cancel_shutdown (GMythDbusServer *self)
1269 GMythDbusServerPrivate *priv;
1271 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (self);
1273 if (priv->shutdown_cb_id)
1275 g_source_remove (priv->shutdown_cb_id);
1276 priv->shutdown_cb_id = 0;
1281 gmyth_dbus_server_shutdown_cb (GMythDbusServer *self)
1283 GMythDbusServerPrivate *priv;
1285 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (self);
1287 priv->shutdown_cb_id = 0;
1288 g_signal_emit (self, signals[SHUTDOWN], 0);
1293 gmyth_dbus_server_check_db_connection (GObject *obj,
1297 const gchar *password,
1300 GMythQuery *query = gmyth_query_new ();
1301 GMythBackendInfo *binfo;
1306 binfo = gmyth_backend_info_new_full (host, user, password, MYTH_DEFAULT_DB, port);
1308 ret = gmyth_query_connect_with_timeout (query, binfo, 2 /*seconds*/);
1309 gmyth_query_disconnect (query);
1311 g_object_unref (query);
1312 g_object_unref (binfo);
1315 g_set_error (error, GMYTH_DBUS_ERROR, GMYTH_DBUS_ERROR_CONNECTION,
1316 _("Fail to connect with backend"));