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 gmyth_dbus_server_check_server_connection (GObject *obj,
100 static gboolean gmyth_dbus_server_get_channel_list (GObject *obj,
101 GPtrArray **channels,
103 static gboolean gmyth_dbus_server_get_channel_info (GObject *obj,
107 static gboolean gmyth_dbus_server_file_exists (GObject *obj,
108 const gchar *file_name,
111 static gboolean gmyth_dbus_server_get_recorded_list (GObject *obj,
112 GPtrArray **channels,
114 static gboolean gmyth_dbus_server_get_recorded_info (GObject *obj,
115 const gchar *basename,
118 static gboolean gmyth_dbus_server_get_program_list (GObject *obj,
120 const gchar *start_time,
121 const gchar *end_time,
122 GPtrArray **program_list,
124 static gboolean gmyth_dbus_server_get_schedule_list (GObject *obj,
125 GPtrArray **schedule_list,
127 static gboolean gmyth_dbus_server_connected (GObject *obj,
130 static gboolean gmyth_dbus_server_disconnect (GObject *obj,
132 static void gmyth_dbus_server_internal_disconnect
135 static gboolean gmyth_dbus_server_get_server_info (GObject *obj,
136 guint64 *total_space,
140 static gboolean gmyth_dbus_server_get_thumbnail (GObject *obj,
144 static gboolean gmyth_dbus_server_get_channel_icon (GObject *obj,
148 static gboolean gmyth_dbus_server_stop_recording (GObject *obj,
152 static gboolean gmyth_dbus_server_add_schedule (GObject *obj,
154 const gchar *program_id,
155 const gchar *start_time,
156 const gchar *end_time,
158 const gchar *description,
161 static gboolean gmyth_dbus_server_add_exception (GObject *obj,
164 const gchar *program_id,
165 const gchar *start_time,
166 const gchar *end_time,
167 const gchar *description,
169 static gboolean gmyth_dbus_server_remove_schedule (GObject *obj,
174 #include "gmyth-dbus-server-glue.h"
177 static guint signals[LAST_SIGNAL] = { 0 };
179 G_DEFINE_TYPE (GMythDbusServer, gmyth_dbus_server, G_TYPE_OBJECT);
182 gmyth_dbus_server_class_init (GMythDbusServerClass *klass)
184 GObjectClass *object_class = G_OBJECT_CLASS (klass);
186 g_type_class_add_private (klass, sizeof (GMythDbusServerPrivate));
188 object_class->dispose = gmyth_dbus_server_dispose;
189 object_class->finalize = gmyth_dbus_server_finalize;
192 g_signal_new ("shutdown",
193 G_OBJECT_CLASS_TYPE (object_class),
194 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
197 g_cclosure_marshal_VOID__VOID,
198 G_TYPE_NONE, 0, G_TYPE_NONE);
200 dbus_g_object_type_install_info (GMYTH_DBUS_SERVER_TYPE,
201 &dbus_glib_gmyth_dbus_server_object_info);
205 gmyth_dbus_server_init (GMythDbusServer *self)
210 gmyth_dbus_server_dispose (GObject *object)
212 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->dispose (object);
216 gmyth_dbus_server_finalize (GObject *object)
218 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->finalize (object);
222 gmyth_dbus_server_connect_epg (GMythDbusServer *server, GError **error)
224 GMythDbusServerPrivate *priv;
225 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
227 if (!priv->connected)
231 GMYTH_DBUS_ERROR_CONNECTION,
234 gmyth_debug ("Not connected with MythTV Server");
240 priv->myth_epg = gmyth_epg_new();
241 if (!gmyth_epg_connect (priv->myth_epg, priv->myth_backend))
243 g_object_unref (priv->myth_epg);
244 priv->myth_epg = NULL;
248 GMYTH_DBUS_ERROR_EPG,
249 _("Fail to connect with EPG"));
250 gmyth_debug ("Fail to connected with EPG");
256 gmyth_debug ("Connected EPG");
261 gmyth_dbus_server_connect_scheduler (GMythDbusServer *server,
264 GMythDbusServerPrivate *priv;
265 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
267 if (!priv->connected)
271 GMYTH_DBUS_ERROR_CONNECTION,
274 gmyth_debug ("Not connected with MythTV Server");
278 if (!priv->myth_scheduler)
280 priv->myth_scheduler = gmyth_scheduler_new ();
281 if (!gmyth_scheduler_connect (priv->myth_scheduler,
284 g_object_unref (priv->myth_scheduler);
285 priv->myth_scheduler = NULL;
289 GMYTH_DBUS_ERROR_SCHEDULE,
290 _("Fail to connect with Schedule"));
292 gmyth_debug (_("Fail to connect with Schedule"));
297 gmyth_debug ("Connected with Schedule");
302 gmyth_dbus_server_connect (GObject *obj,
306 const gchar *password,
310 GMythDbusServerPrivate *priv;
314 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
318 gmyth_debug ("Release Old connection");
319 gmyth_dbus_server_internal_disconnect (obj, NULL);
322 gmyth_dbus_server_cancel_shutdown (GMYTH_DBUS_SERVER (obj));
324 priv->myth_backend = gmyth_backend_info_new_full (host,
330 s = gmyth_backend_info_get_connected_socket (priv->myth_backend);
333 gmyth_debug ("Connected");
334 priv->connected = TRUE;
339 gmyth_debug ("Fail to connect with MythTVServer");
340 priv->connected = FALSE;
341 g_object_unref (priv->myth_backend);
342 priv->myth_backend = NULL;
346 GMYTH_DBUS_ERROR_CONNECTION,
347 _("Fail to connect with backend"));
350 return priv->connected;
354 gmyth_dbus_server_connected (GObject *obj,
358 GMythDbusServerPrivate *priv;
362 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
364 if (priv->myth_backend)
372 gmyth_dbus_server_disconnect (GObject *obj,
375 GMythDbusServerPrivate *priv;
377 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
380 gmyth_dbus_server_internal_disconnect (obj, error);
381 priv->shutdown_cb_id = g_timeout_add (60000,
382 (GSourceFunc) gmyth_dbus_server_shutdown_cb, obj);
389 gmyth_dbus_server_internal_disconnect (GObject *obj,
392 GMythDbusServerPrivate *priv;
394 g_debug ("%s:%d", __FUNCTION__, __LINE__);
396 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
400 g_object_unref (priv->myth_epg);
401 priv->myth_epg = NULL;
405 if (priv->myth_backend)
407 g_object_unref (priv->myth_backend);
408 priv->myth_backend = NULL;
411 if (priv->myth_scheduler)
413 g_object_unref (priv->myth_scheduler);
414 priv->myth_scheduler = NULL;
417 priv->connected = FALSE;
421 gmyth_dbus_server_get_server_info (GObject *obj,
422 guint64 *total_space,
427 GMythBackendDetails *details;
428 GMythDbusServerPrivate *priv;
429 gboolean ret = FALSE;
432 g_debug ("%s:%d", __FUNCTION__, __LINE__);
433 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
435 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
437 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
443 GMYTH_DBUS_ERROR_MYTHTV,
444 _("MythTv not avaliable"));
450 gmyth_util_get_backend_details (socket,
454 *total_space = details->total_space;
455 *used_space = details->used_space;
456 *free_space = *total_space - *used_space;
457 gmyth_util_backend_details_free (details);
465 GMYTH_DBUS_ERROR_MYTHTV,
466 _("Fail to get MythTv details"));
469 g_object_unref (socket);
476 gmyth_dbus_server_parse_channel_info (GMythChannelInfo *info,
479 dbus_g_type_struct_set (val,
481 1, info->channel_num->str,
482 2, info->channel_name->str,
483 3, info->channel_icon->str,
488 gmyth_dbus_server_get_channel_info (GObject *obj,
494 GMythChannelInfo *ch_info;
495 GMythDbusServerPrivate *priv;
497 g_debug ("%s:%d", __FUNCTION__, __LINE__);
498 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
500 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
502 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
507 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
509 ch_info = gmyth_epg_get_channel_info (priv->myth_epg, channel_id);
513 g_value_init (&v, ch_type);
514 g_value_take_boxed (&v, dbus_g_type_specialized_construct (ch_type));
515 gmyth_dbus_server_parse_channel_info (ch_info, &v);
517 *info = g_value_get_boxed (&v);
524 GMYTH_DBUS_ERROR_EPG,
525 _("no channel info avaliable"));
533 gmyth_dbus_server_get_channel_list (GObject *obj,
534 GPtrArray **channels,
541 GMythDbusServerPrivate *priv;
543 g_debug ("%s:%d", __FUNCTION__, __LINE__);
544 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
546 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
547 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
552 len = gmyth_epg_get_channel_list (priv->myth_epg, &lst);
554 *channels = g_ptr_array_sized_new (len);
555 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
557 for (walk = lst; walk != NULL; walk = walk->next)
560 GMythChannelInfo *data;
562 data = (GMythChannelInfo *) walk->data;
564 g_value_init (&ch, ch_type);
565 g_value_take_boxed (&ch, dbus_g_type_specialized_construct (ch_type));
566 gmyth_dbus_server_parse_channel_info (data, &ch);
567 g_ptr_array_add (*channels, g_value_get_boxed (&ch));
570 gmyth_free_channel_list (lst);
575 gmyth_dbus_server_file_exists (GObject *obj,
576 const gchar *file_name,
580 GMythDbusServerPrivate *priv;
581 g_debug ("%s:%d", __FUNCTION__, __LINE__);
582 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
584 g_return_val_if_fail (priv->myth_backend, FALSE);
586 *exists = gmyth_util_file_exists (priv->myth_backend, file_name);
592 gmyth_dbus_server_get_program_list (GObject *obj,
594 const gchar *start_time,
595 const gchar *end_time,
596 GPtrArray **programs,
603 GTimeVal start_time_val;
604 GTimeVal end_time_val;
605 GMythDbusServerPrivate *priv;
607 g_debug ("%s:%d", __FUNCTION__, __LINE__);
608 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
610 g_return_val_if_fail (priv->myth_backend, FALSE);
611 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
614 g_time_val_from_iso8601 (start_time, &start_time_val);
615 g_time_val_from_iso8601 (end_time, &end_time_val);
618 len = gmyth_epg_get_program_list (priv->myth_epg,
624 *programs = g_ptr_array_sized_new (len);
625 program_type = GMYTH_DBUS_PROGRAM_G_TYPE;
627 for (walk = list; walk != NULL; walk = walk->next)
629 GValue program = { 0, };
632 GMythProgramInfo *data;
634 data = (GMythProgramInfo *) walk->data;
639 g_value_init (&program, program_type);
640 g_value_take_boxed (&program,
641 dbus_g_type_specialized_construct (program_type));
643 start_str = g_time_val_to_iso8601 (data->startts);
644 end_str = g_time_val_to_iso8601 (data->endts);
646 dbus_g_type_struct_set (&program,
651 4, data->subtitle->str,
652 5, data->description->str,
653 6, data->category->str,
656 g_ptr_array_add (*programs, g_value_get_boxed (&program));
662 gmyth_free_program_list (list);
664 g_debug ("%s:%d", __FUNCTION__, __LINE__);
669 gmyth_dbus_server_parse_recorded_info (RecordedInfo *info,
675 start_str = g_time_val_to_iso8601 (info->start_time);
676 end_str = g_time_val_to_iso8601 (info->end_time);
678 dbus_g_type_struct_set (val,
680 1, info->program_id->str,
685 6, info->subtitle->str,
686 7, info->description->str,
687 8, info->category->str,
688 9, info->basename->str,
696 gmyth_dbus_server_get_recorded_info (GObject *obj,
697 const gchar *basename,
702 GMythDbusServerPrivate *priv;
703 RecordedInfo *record_info;
706 g_debug ("%s:%d", __FUNCTION__, __LINE__);
707 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
709 g_return_val_if_fail (priv->myth_backend, FALSE);
711 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
714 record_type = GMYTH_DBUS_RECORD_G_TYPE;
716 record_info = gmyth_scheduler_get_recorded_info (priv->myth_scheduler,
723 g_value_init (&r, record_type);
724 g_value_take_boxed (&r,
725 dbus_g_type_specialized_construct (record_type));
727 gmyth_dbus_server_parse_recorded_info (record_info, &r);
728 gmyth_recorded_info_free (record_info);
730 *info = g_value_get_boxed (&r);
738 GMYTH_DBUS_ERROR_EPG,
739 _("no record info avaliable"));
748 gmyth_dbus_server_get_recorded_list (GObject *obj,
756 GMythDbusServerPrivate *priv;
758 g_debug ("%s:%d", __FUNCTION__, __LINE__);
759 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
761 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
762 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
766 len = gmyth_scheduler_get_recorded_list (priv->myth_scheduler,
769 record_type = GMYTH_DBUS_RECORD_G_TYPE;
770 *records = g_ptr_array_sized_new (len);
772 for (walk = list; walk != NULL; walk = walk->next)
774 GValue record = { 0, };
777 data = (RecordedInfo *) walk->data;
779 g_value_init (&record, record_type);
780 g_value_take_boxed (&record,
781 dbus_g_type_specialized_construct (record_type));
783 gmyth_dbus_server_parse_recorded_info (data, &record);
785 g_ptr_array_add (*records, g_value_get_boxed (&record));
786 //g_value_unset (&record);
789 gmyth_recorded_info_list_free (list);
796 gmyth_dbus_server_get_schedule_list (GObject *obj,
797 GPtrArray **schedules,
804 GMythDbusServerPrivate *priv;
806 g_debug ("%s:%d", __FUNCTION__, __LINE__);
807 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
809 g_return_val_if_fail (priv->myth_backend, FALSE);
810 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
814 len = gmyth_scheduler_get_schedule_list (priv->myth_scheduler,
817 *schedules = g_ptr_array_sized_new (len);
818 schedule_type = GMYTH_DBUS_SCHEDULE_G_TYPE;
820 for (walk = list; walk != NULL; walk = walk->next)
822 GValue schedule = { 0, };
824 gchar *start_str_time;
827 data = (ScheduleInfo *) walk->data;
829 g_value_init (&schedule, schedule_type);
830 g_value_take_boxed (&schedule,
831 dbus_g_type_specialized_construct (schedule_type));
833 start_str_time = g_time_val_to_iso8601 (data->start_time);
834 end_str_time = g_time_val_to_iso8601 (data->end_time);
836 dbus_g_type_struct_set (&schedule,
837 0, data->schedule_id,
838 1, data->program_id->str,
843 6, data->subtitle->str,
844 7, data->description->str,
845 8, data->category->str,
849 g_ptr_array_add (*schedules, g_value_get_boxed (&schedule));
851 g_free (start_str_time);
852 g_free (end_str_time);
855 gmyth_schedule_info_list_free (list);
862 gmyth_dbus_server_get_thumbnail (GObject *obj,
867 GMythFileTransfer *file_transfer;
869 GMythFileReadResult result;
870 GMythDbusServerPrivate *priv;
872 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
874 file_transfer = NULL;
876 g_return_val_if_fail (priv->myth_backend, FALSE);
878 if (!gmyth_util_file_exists (priv->myth_backend, uri))
882 GMYTH_DBUS_ERROR_MYTHTV,
883 _("File not exists"));
888 file_transfer = gmyth_file_transfer_new (priv->myth_backend);
890 if (!gmyth_file_transfer_open (file_transfer, uri))
894 GMYTH_DBUS_ERROR_MYTHTV,
895 _("Fail to open file"));
899 filesize = gmyth_file_transfer_get_filesize (file_transfer);
903 *image = g_byte_array_new ();
904 result = gmyth_file_transfer_read (file_transfer, *image, filesize, FALSE);
905 if (result == GMYTH_FILE_READ_ERROR)
909 GMYTH_DBUS_ERROR_MYTHTV,
910 _("Fail to read file"));
915 gmyth_file_transfer_close (file_transfer);
916 g_object_unref (file_transfer);
918 if (filesize > (*image)->len)
922 GMYTH_DBUS_ERROR_MYTHTV,
932 g_byte_array_free (*image, TRUE);
933 g_object_unref(file_transfer);
938 gmyth_dbus_server_get_channel_icon (GObject *obj,
943 GMythChannelInfo *channel = NULL;
946 GMythDbusServerPrivate *priv;
948 g_debug ("%s:%d", __FUNCTION__, __LINE__);
949 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
950 g_return_val_if_fail (priv->myth_backend, FALSE);
952 channel = gmyth_epg_get_channel_info (priv->myth_epg,
961 GMYTH_DBUS_ERROR_MYTHTV,
962 _("Invalid channel"));
967 if (!gmyth_epg_channel_has_icon(priv->myth_epg, channel))
969 gmyth_channel_info_free (channel);
972 GMYTH_DBUS_ERROR_MYTHTV,
973 _("Channel does not have icon available"));
980 if (!gmyth_epg_channel_get_icon (priv->myth_epg,
985 gmyth_channel_info_free (channel);
988 GMYTH_DBUS_ERROR_MYTHTV,
989 _("Could not get channel icon for channel id = %u"),
994 *icon = g_byte_array_sized_new (icon_length);
995 *icon = g_byte_array_append (*icon, icon_data, icon_length);
998 gmyth_channel_info_free(channel);
1004 gmyth_dbus_server_stop_recording (GObject *obj,
1009 gboolean ret = FALSE;
1010 GMythDbusServerPrivate *priv;
1012 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1013 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1015 g_return_val_if_fail (priv->myth_backend, FALSE);
1016 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1019 ret = gmyth_scheduler_stop_recording (priv->myth_scheduler,
1025 static ScheduleInfo*
1026 gmyth_dbus_server_new_schedule_info (const gchar* description,
1028 const gchar* program_id,
1029 GTimeVal *start_vtime,
1030 GTimeVal *end_vtime)
1032 ScheduleInfo *new_sched_info;
1034 new_sched_info = g_new0(ScheduleInfo, 1);
1036 /* record_id == -1 for generating a new id */
1037 new_sched_info->schedule_id = -1;
1039 new_sched_info->channel_id = channel_id;
1040 new_sched_info->program_id = g_string_new (program_id);
1041 new_sched_info->start_time = g_new0 (GTimeVal, 1);
1042 *new_sched_info->start_time = *start_vtime;
1043 new_sched_info->end_time = g_new0 (GTimeVal, 1);
1044 *new_sched_info->end_time = *end_vtime;
1046 /* TODO: there is no frequency field */
1047 /*new_sched_info->frequency = -1;*/
1049 if (description != NULL) {
1050 /* FIXME: description parameter is used as title and description */
1051 new_sched_info->title = g_string_new(description);
1052 new_sched_info->description = g_string_new(description);
1055 return new_sched_info;
1059 gmyth_dbus_server_add_schedule (GObject *obj,
1061 const gchar *program_id,
1062 const gchar *start_time,
1063 const gchar *end_time,
1065 const gchar *description,
1069 ScheduleInfo *sch_info;
1070 GTimeVal start_vtime;
1072 GMythDbusServerPrivate *priv;
1074 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1075 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1079 g_return_val_if_fail (priv->myth_backend, FALSE);
1081 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1085 g_time_val_from_iso8601 (start_time, &start_vtime);
1086 g_time_val_from_iso8601 (end_time, &end_vtime);
1088 sch_info = gmyth_dbus_server_new_schedule_info (description,
1094 if (sch_info != NULL) {
1095 GMythScheduleType type;
1097 gboolean has_record;
1100 GMYTH_SCHEDULE_ALL_OCCURRENCES :
1101 GMYTH_SCHEDULE_ONE_OCCURRENCE);
1103 g_get_current_time (&t_now);
1105 has_record = gmyth_scheduler_was_recorded_before (priv->myth_scheduler,
1107 (time_t) start_vtime.tv_sec);
1110 if ((t_now.tv_sec >= start_vtime.tv_sec)
1111 && (t_now.tv_sec <= end_vtime.tv_sec) && has_record)
1113 GMythSocket *socket;
1114 gboolean res = FALSE;
1116 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
1117 res = gmyth_scheduler_reactivate_schedule(priv->myth_scheduler,
1119 (time_t) start_vtime.tv_sec);
1121 GMythStringList *slist = gmyth_string_list_new();
1123 gmyth_string_list_append_char_array(slist, "RESCHEDULE_RECORDINGS 0");
1124 gmyth_socket_sendreceive_stringlist(socket, slist);
1125 res = (gmyth_string_list_get_int(slist, 0) == 1);
1126 g_object_unref(slist);
1129 g_object_unref(socket);
1134 if (!gmyth_scheduler_add_schedule_full (priv->myth_scheduler,
1138 g_warning("Could not add schedule entry");
1142 (*schedule_id) = sch_info->schedule_id;
1143 gmyth_schedule_info_free (sch_info);
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);
1297 gmyth_dbus_server_check_db_connection (GObject *obj,
1301 const gchar *password,
1304 GMythQuery *query = gmyth_query_new ();
1305 GMythBackendInfo *binfo;
1310 binfo = gmyth_backend_info_new_full (host, user, password, MYTH_DEFAULT_DB, port);
1312 ret = gmyth_query_connect_with_timeout (query, binfo, 10 /*seconds*/);
1313 gmyth_query_disconnect (query);
1315 g_object_unref (query);
1316 g_object_unref (binfo);
1319 g_set_error (error, GMYTH_DBUS_ERROR, GMYTH_DBUS_ERROR_CONNECTION,
1320 _("Fail to connect with backend database"));
1327 gmyth_dbus_server_check_server_connection (GObject *obj,
1332 GMythSocket *msocket = gmyth_socket_new ();
1337 g_debug ("Checking server connection");
1338 ret = gmyth_socket_connect_with_timeout (msocket, host, port, 2);
1339 g_debug ("Return %s", ret ? "ok" : "bad");
1340 gmyth_socket_close_connection (msocket);
1342 g_object_unref (msocket);
1345 g_set_error (error, GMYTH_DBUS_ERROR, GMYTH_DBUS_ERROR_CONNECTION,
1346 _("Fail to connect with backend"));