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;
70 #define GMYTH_DBUS_SERVER_GET_PRIVATE(o) \
71 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GMYTH_DBUS_SERVER_TYPE, GMythDbusServerPrivate))
73 static void gmyth_dbus_server_class_init (GMythDbusServerClass *klass);
74 static void gmyth_dbus_server_init (GMythDbusServer *self);
75 static void gmyth_dbus_server_dispose (GObject *object);
76 static void gmyth_dbus_server_finalize (GObject *object);
79 static gboolean gmyth_dbus_server_connect (GObject *obj,
83 const gchar *password,
86 static gboolean gmyth_dbus_server_get_channel_list (GObject *obj,
89 static gboolean gmyth_dbus_server_get_channel_info (GObject *obj,
93 static gboolean gmyth_dbus_server_file_exists (GObject *obj,
94 const gchar *file_name,
97 static gboolean gmyth_dbus_server_get_recorded_list (GObject *obj,
100 static gboolean gmyth_dbus_server_get_recorded_info (GObject *obj,
101 const gchar *basename,
104 static gboolean gmyth_dbus_server_get_program_list (GObject *obj,
106 const gchar *start_time,
107 const gchar *end_time,
108 GPtrArray **program_list,
110 static gboolean gmyth_dbus_server_get_schedule_list (GObject *obj,
111 GPtrArray **schedule_list,
113 static gboolean gmyth_dbus_server_connected (GObject *obj,
116 static gboolean gmyth_dbus_server_disconnect (GObject *obj,
118 static void gmyth_dbus_server_internal_disconnect
121 static gboolean gmyth_dbus_server_get_server_info (GObject *obj,
122 guint64 *total_space,
126 static gboolean gmyth_dbus_server_get_thumbnail (GObject *obj,
130 static gboolean gmyth_dbus_server_get_channel_icon (GObject *obj,
134 static gboolean gmyth_dbus_server_stop_recording (GObject *obj,
138 static gboolean gmyth_dbus_server_add_schedule (GObject *obj,
141 const gchar *start_time,
142 const gchar *end_time,
144 const gchar *description,
147 static gboolean gmyth_dbus_server_add_exception (GObject *obj,
151 const gchar *start_time,
152 const gchar *end_time,
153 const gchar *description,
155 static gboolean gmyth_dbus_server_remove_schedule (GObject *obj,
160 #include "gmyth-dbus-server-glue.h"
163 static guint signals[LAST_SIGNAL] = { 0 };
165 G_DEFINE_TYPE (GMythDbusServer, gmyth_dbus_server, G_TYPE_OBJECT);
168 gmyth_dbus_server_class_init (GMythDbusServerClass *klass)
170 GObjectClass *object_class = G_OBJECT_CLASS (klass);
172 g_type_class_add_private (klass, sizeof (GMythDbusServerPrivate));
174 object_class->dispose = gmyth_dbus_server_dispose;
175 object_class->finalize = gmyth_dbus_server_finalize;
177 signals[DISCONNECTED] =
178 g_signal_new ("disconnected",
179 G_OBJECT_CLASS_TYPE (object_class),
180 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
183 g_cclosure_marshal_VOID__VOID,
184 G_TYPE_NONE, 0, G_TYPE_NONE);
186 dbus_g_object_type_install_info (GMYTH_DBUS_SERVER_TYPE,
187 &dbus_glib_gmyth_dbus_server_object_info);
191 gmyth_dbus_server_init (GMythDbusServer *self)
196 gmyth_dbus_server_dispose (GObject *object)
198 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->dispose (object);
202 gmyth_dbus_server_finalize (GObject *object)
204 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->finalize (object);
208 gmyth_dbus_server_connect_epg (GMythDbusServer *server, GError **error)
210 GMythDbusServerPrivate *priv;
211 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
213 if (!priv->connected)
217 GMYTH_DBUS_ERROR_CONNECTION,
225 priv->myth_epg = gmyth_epg_new();
226 if (!gmyth_epg_connect (priv->myth_epg, priv->myth_backend))
228 g_object_unref (priv->myth_epg);
229 priv->myth_epg = NULL;
233 GMYTH_DBUS_ERROR_EPG,
234 _("Fail to connect with EPG"));
244 gmyth_dbus_server_connect_scheduler (GMythDbusServer *server,
247 GMythDbusServerPrivate *priv;
248 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
250 if (!priv->connected)
254 GMYTH_DBUS_ERROR_CONNECTION,
260 if (!priv->myth_scheduler)
262 priv->myth_scheduler = gmyth_scheduler_new ();
263 if (!gmyth_scheduler_connect (priv->myth_scheduler,
266 g_object_unref (priv->myth_scheduler);
267 priv->myth_scheduler = NULL;
271 GMYTH_DBUS_ERROR_SCHEDULE,
272 _("Fail to connect with Schedule"));
282 gmyth_dbus_server_connect (GObject *obj,
286 const gchar *password,
291 GMythDbusServerPrivate *priv;
293 g_debug ("%s:%d", __FUNCTION__, __LINE__);
295 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
299 gmyth_dbus_server_internal_disconnect (obj, error);
302 priv->myth_backend = gmyth_backend_info_new_full (host,
308 s = gmyth_backend_info_get_connected_socket (priv->myth_backend);
316 g_object_unref (priv->myth_backend);
317 priv->myth_backend = NULL;
322 GMYTH_DBUS_ERROR_CONNECTION,
323 _("Fail to connect with backend"));
326 priv->connected = *result;
331 gmyth_dbus_server_connected (GObject *obj,
335 GMythDbusServerPrivate *priv;
337 g_debug ("%s:%d", __FUNCTION__, __LINE__);
339 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
341 if (priv->myth_backend)
349 gmyth_dbus_server_disconnect (GObject *obj,
353 gmyth_dbus_server_internal_disconnect (obj, error);
354 g_signal_emit (obj, signals[DISCONNECTED], 0);
360 gmyth_dbus_server_internal_disconnect (GObject *obj,
363 GMythDbusServerPrivate *priv;
365 g_debug ("%s:%d", __FUNCTION__, __LINE__);
367 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
371 g_object_unref (priv->myth_epg);
372 priv->myth_epg = NULL;
376 if (priv->myth_backend)
378 g_object_unref (priv->myth_backend);
379 priv->myth_backend = NULL;
382 if (priv->myth_scheduler)
384 g_object_unref (priv->myth_scheduler);
385 priv->myth_scheduler = NULL;
390 gmyth_dbus_server_get_server_info (GObject *obj,
391 guint64 *total_space,
396 GMythBackendDetails *details;
397 GMythDbusServerPrivate *priv;
398 gboolean ret = FALSE;
401 g_debug ("%s:%d", __FUNCTION__, __LINE__);
402 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
404 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
406 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
412 GMYTH_DBUS_ERROR_MYTHTV,
413 _("MythTv not avaliable"));
419 gmyth_util_get_backend_details (socket,
423 *total_space = details->total_space;
424 *used_space = details->used_space;
425 *free_space = *total_space - *used_space;
426 gmyth_util_backend_details_free (details);
434 GMYTH_DBUS_ERROR_MYTHTV,
435 _("Fail to get MythTv details"));
438 g_object_unref (socket);
445 gmyth_dbus_server_parse_channel_info (GMythChannelInfo *info,
448 dbus_g_type_struct_set (val,
450 1, info->channel_num->str,
451 2, info->channel_name->str,
452 3, info->channel_icon->str,
457 gmyth_dbus_server_get_channel_info (GObject *obj,
463 GMythChannelInfo *ch_info;
464 GMythDbusServerPrivate *priv;
466 g_debug ("%s:%d", __FUNCTION__, __LINE__);
467 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
469 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
471 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
476 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
478 ch_info = gmyth_epg_get_channel_info (priv->myth_epg, channel_id);
482 g_value_init (&v, ch_type);
483 g_value_take_boxed (&v, dbus_g_type_specialized_construct (ch_type));
484 gmyth_dbus_server_parse_channel_info (ch_info, &v);
486 *info = g_value_get_boxed (&v);
493 GMYTH_DBUS_ERROR_EPG,
494 _("no channel info avaliable"));
502 gmyth_dbus_server_get_channel_list (GObject *obj,
503 GPtrArray **channels,
510 GMythDbusServerPrivate *priv;
512 g_debug ("%s:%d", __FUNCTION__, __LINE__);
513 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
515 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
516 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
521 len = gmyth_epg_get_channel_list (priv->myth_epg, &lst);
523 *channels = g_ptr_array_sized_new (len);
524 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
526 for (walk = lst; walk != NULL; walk = walk->next)
529 GMythChannelInfo *data;
531 data = (GMythChannelInfo *) walk->data;
533 g_value_init (&ch, ch_type);
534 g_value_take_boxed (&ch, dbus_g_type_specialized_construct (ch_type));
535 gmyth_dbus_server_parse_channel_info (data, &ch);
536 g_ptr_array_add (*channels, g_value_get_boxed (&ch));
539 gmyth_free_channel_list (lst);
544 gmyth_dbus_server_file_exists (GObject *obj,
545 const gchar *file_name,
549 GMythDbusServerPrivate *priv;
550 g_debug ("%s:%d", __FUNCTION__, __LINE__);
551 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
553 g_return_val_if_fail (priv->myth_backend, FALSE);
555 *exists = gmyth_util_file_exists (priv->myth_backend, file_name);
561 gmyth_dbus_server_get_program_list (GObject *obj,
563 const gchar *start_time,
564 const gchar *end_time,
565 GPtrArray **programs,
572 GTimeVal start_time_val;
573 GTimeVal end_time_val;
574 GMythDbusServerPrivate *priv;
576 g_debug ("%s:%d", __FUNCTION__, __LINE__);
577 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
579 g_return_val_if_fail (priv->myth_backend, FALSE);
580 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
583 g_time_val_from_iso8601 (start_time, &start_time_val);
584 g_time_val_from_iso8601 (end_time, &end_time_val);
587 len = gmyth_epg_get_program_list (priv->myth_epg,
593 *programs = g_ptr_array_sized_new (len);
594 program_type = GMYTH_DBUS_PROGRAM_G_TYPE;
596 for (walk = list; walk != NULL; walk = walk->next)
598 GValue program = { 0, };
601 GMythProgramInfo *data;
603 data = (GMythProgramInfo *) walk->data;
608 g_value_init (&program, program_type);
609 g_value_take_boxed (&program,
610 dbus_g_type_specialized_construct (program_type));
612 start_str = g_time_val_to_iso8601 (data->startts);
613 end_str = g_time_val_to_iso8601 (data->endts);
615 dbus_g_type_struct_set (&program,
616 0, data->chanid->str,
620 4, data->subtitle->str,
621 5, data->description->str,
622 6, data->category->str,
625 g_ptr_array_add (*programs, g_value_get_boxed (&program));
631 gmyth_free_program_list (list);
633 g_debug ("%s:%d", __FUNCTION__, __LINE__);
638 gmyth_dbus_server_parse_recorded_info (RecordedInfo *info,
644 start_str = g_time_val_to_iso8601 (info->start_time);
645 end_str = g_time_val_to_iso8601 (info->end_time);
647 dbus_g_type_struct_set (val,
654 6, info->subtitle->str,
655 7, info->description->str,
656 8, info->category->str,
657 9, info->basename->str,
665 gmyth_dbus_server_get_recorded_info (GObject *obj,
666 const gchar *basename,
671 GMythDbusServerPrivate *priv;
672 RecordedInfo *record_info;
675 g_debug ("%s:%d", __FUNCTION__, __LINE__);
676 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
678 g_return_val_if_fail (priv->myth_backend, FALSE);
680 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
683 record_type = GMYTH_DBUS_RECORD_G_TYPE;
685 record_info = gmyth_scheduler_get_recorded_info (priv->myth_scheduler,
692 g_value_init (&r, record_type);
693 g_value_take_boxed (&r,
694 dbus_g_type_specialized_construct (record_type));
696 gmyth_dbus_server_parse_recorded_info (record_info, &r);
697 gmyth_recorded_info_free (record_info);
699 *info = g_value_get_boxed (&r);
707 GMYTH_DBUS_ERROR_EPG,
708 _("no record info avaliable"));
717 gmyth_dbus_server_get_recorded_list (GObject *obj,
725 GMythDbusServerPrivate *priv;
727 g_debug ("%s:%d", __FUNCTION__, __LINE__);
728 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
730 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
731 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
735 len = gmyth_scheduler_get_recorded_list (priv->myth_scheduler,
738 record_type = GMYTH_DBUS_RECORD_G_TYPE;
739 *records = g_ptr_array_sized_new (len);
741 for (walk = list; walk != NULL; walk = walk->next)
743 GValue record = { 0, };
746 data = (RecordedInfo *) walk->data;
748 g_value_init (&record, record_type);
749 g_value_take_boxed (&record,
750 dbus_g_type_specialized_construct (record_type));
752 gmyth_dbus_server_parse_recorded_info (data, &record);
754 g_ptr_array_add (*records, g_value_get_boxed (&record));
755 //g_value_unset (&record);
758 gmyth_recorded_info_list_free (list);
765 gmyth_dbus_server_get_schedule_list (GObject *obj,
766 GPtrArray **schedules,
773 GMythDbusServerPrivate *priv;
775 g_debug ("%s:%d", __FUNCTION__, __LINE__);
776 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
778 g_return_val_if_fail (priv->myth_backend, FALSE);
779 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
783 len = gmyth_scheduler_get_schedule_list (priv->myth_scheduler,
786 *schedules = g_ptr_array_sized_new (len);
787 schedule_type = GMYTH_DBUS_SCHEDULE_G_TYPE;
789 for (walk = list; walk != NULL; walk = walk->next)
791 GValue schedule = { 0, };
793 gchar *start_str_time;
796 data = (ScheduleInfo *) walk->data;
798 g_value_init (&schedule, schedule_type);
799 g_value_take_boxed (&schedule,
800 dbus_g_type_specialized_construct (schedule_type));
802 start_str_time = g_time_val_to_iso8601 (data->start_time);
803 end_str_time = g_time_val_to_iso8601 (data->end_time);
805 dbus_g_type_struct_set (&schedule,
806 0, data->schedule_id,
812 6, data->subtitle->str,
813 7, data->description->str,
814 8, data->category->str,
818 g_ptr_array_add (*schedules, g_value_get_boxed (&schedule));
820 g_free (start_str_time);
821 g_free (end_str_time);
824 gmyth_schedule_info_list_free (list);
831 gmyth_dbus_server_get_thumbnail (GObject *obj,
836 GMythFileTransfer *file_transfer;
838 GMythFileReadResult result;
839 GMythDbusServerPrivate *priv;
841 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
843 file_transfer = NULL;
845 g_return_val_if_fail (priv->myth_backend, FALSE);
847 if (!gmyth_util_file_exists (priv->myth_backend, uri))
851 GMYTH_DBUS_ERROR_MYTHTV,
852 _("File not exists"));
857 file_transfer = gmyth_file_transfer_new (priv->myth_backend);
859 if (!gmyth_file_transfer_open (file_transfer, uri))
863 GMYTH_DBUS_ERROR_MYTHTV,
864 _("Fail to open file"));
868 filesize = gmyth_file_transfer_get_filesize (file_transfer);
872 *image = g_byte_array_new ();
873 result = gmyth_file_transfer_read (file_transfer, *image, filesize, FALSE);
874 if (result == GMYTH_FILE_READ_ERROR)
878 GMYTH_DBUS_ERROR_MYTHTV,
879 _("Fail to read file"));
884 gmyth_file_transfer_close (file_transfer);
885 g_object_unref (file_transfer);
887 if (filesize > (*image)->len)
891 GMYTH_DBUS_ERROR_MYTHTV,
901 g_byte_array_free (*image, TRUE);
902 g_object_unref(file_transfer);
907 gmyth_dbus_server_get_channel_icon (GObject *obj,
912 GMythChannelInfo *channel = NULL;
915 GMythDbusServerPrivate *priv;
917 g_debug ("%s:%d", __FUNCTION__, __LINE__);
918 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
919 g_return_val_if_fail (priv->myth_backend, FALSE);
921 channel = gmyth_epg_get_channel_info (priv->myth_epg,
930 GMYTH_DBUS_ERROR_MYTHTV,
931 _("Invalid channel"));
936 if (!gmyth_epg_channel_has_icon(priv->myth_epg, channel))
938 gmyth_channel_info_free (channel);
941 GMYTH_DBUS_ERROR_MYTHTV,
942 _("Channel does not have icon available"));
949 if (!gmyth_epg_channel_get_icon (priv->myth_epg,
954 gmyth_channel_info_free (channel);
957 GMYTH_DBUS_ERROR_MYTHTV,
958 _("Could not get channel icon for channel id = %u"),
963 *icon = g_byte_array_sized_new (icon_length);
964 *icon = g_byte_array_append (*icon, icon_data, icon_length);
967 gmyth_channel_info_free(channel);
973 gmyth_dbus_server_stop_recording (GObject *obj,
978 gboolean ret = FALSE;
979 GMythDbusServerPrivate *priv;
981 g_debug ("%s:%d", __FUNCTION__, __LINE__);
982 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
984 g_return_val_if_fail (priv->myth_backend, FALSE);
985 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
988 ret = gmyth_scheduler_stop_recording (priv->myth_scheduler,
995 gmyth_dbus_server_new_schedule_info (const gchar* description,
998 GTimeVal *start_vtime,
1001 ScheduleInfo *new_sched_info;
1003 new_sched_info = g_new0(ScheduleInfo, 1);
1005 /* record_id == -1 for generating a new id */
1006 new_sched_info->schedule_id = -1;
1008 new_sched_info->channel_id = channel_id;
1009 new_sched_info->program_id = program_id;
1010 new_sched_info->start_time = g_new0 (GTimeVal, 1);
1011 *new_sched_info->start_time = *start_vtime;
1012 new_sched_info->end_time = g_new0 (GTimeVal, 1);
1013 *new_sched_info->end_time = *end_vtime;
1015 /* TODO: there is no frequency field */
1016 /*new_sched_info->frequency = -1;*/
1018 if (description != NULL) {
1019 /* FIXME: description parameter is used as title and description */
1020 new_sched_info->title = g_string_new(description);
1021 new_sched_info->description = g_string_new(description);
1024 return new_sched_info;
1028 gmyth_dbus_server_add_schedule (GObject *obj,
1031 const gchar *start_time,
1032 const gchar *end_time,
1034 const gchar *description,
1038 ScheduleInfo *sch_info;
1039 GTimeVal start_vtime;
1041 GMythDbusServerPrivate *priv;
1043 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1044 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1048 g_return_val_if_fail (priv->myth_backend, FALSE);
1050 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1054 g_time_val_from_iso8601 (start_time, &start_vtime);
1055 g_time_val_from_iso8601 (end_time, &end_vtime);
1056 sch_info = gmyth_dbus_server_new_schedule_info (description,
1061 if (sch_info != NULL) {
1062 GMythScheduleType type;
1064 gboolean has_record;
1067 GMYTH_SCHEDULE_ALL_OCCURRENCES :
1068 GMYTH_SCHEDULE_ONE_OCCURRENCE);
1070 g_get_current_time (&t_now);
1072 has_record = gmyth_scheduler_was_recorded_before (priv->myth_scheduler,
1074 (time_t) start_vtime.tv_sec);
1077 if ((t_now.tv_sec >= start_vtime.tv_sec)
1078 && (t_now.tv_sec <= end_vtime.tv_sec) && has_record)
1080 GMythSocket *socket;
1081 gboolean res = FALSE;
1083 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
1084 res = gmyth_scheduler_reactivate_schedule(priv->myth_scheduler,
1086 (time_t) start_vtime.tv_sec);
1088 GMythStringList *slist = gmyth_string_list_new();
1090 gmyth_string_list_append_char_array(slist, "RESCHEDULE_RECORDINGS 0");
1091 gmyth_socket_sendreceive_stringlist(socket, slist);
1092 res = (gmyth_string_list_get_int(slist, 0) == 1);
1093 g_object_unref(slist);
1096 g_object_unref(socket);
1101 if (!gmyth_scheduler_add_schedule_full (priv->myth_scheduler,
1105 g_warning("Could not add schedule entry");
1109 (*schedule_id) = sch_info->schedule_id;
1110 gmyth_schedule_info_free (sch_info);
1118 gmyth_dbus_server_add_exception (GObject *obj,
1122 const gchar *start_time,
1123 const gchar *end_time,
1124 const gchar *description,
1127 ScheduleInfo *sch_info;
1128 GTimeVal start_vtime;
1130 GMythDbusServerPrivate *priv;
1132 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1133 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1135 g_return_val_if_fail (priv->myth_backend, FALSE);
1137 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1140 g_time_val_from_iso8601 (start_time, &start_vtime);
1141 g_time_val_from_iso8601 (end_time, &end_vtime);
1143 sch_info = gmyth_dbus_server_new_schedule_info (description,
1148 if (sch_info != NULL)
1150 if (!gmyth_scheduler_add_exception (priv->myth_scheduler,
1154 g_warning ("Could not add schedule exception");
1155 gmyth_schedule_info_free (sch_info);
1159 gmyth_schedule_info_free (sch_info);
1166 gmyth_dbus_server_remove_schedule (GObject *obj,
1170 GMythDbusServerPrivate *priv;
1172 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1173 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1175 g_return_val_if_fail (priv->myth_backend, FALSE);
1177 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1180 return gmyth_scheduler_delete_schedule (priv->myth_scheduler, schedule_id);
1184 gmyth_dbus_server_start_dbus_service (void)
1186 GError *error = NULL;
1188 DBusGConnection *bus;
1190 GMythDbusServer *self;
1192 self = g_object_new (GMYTH_DBUS_SERVER_TYPE, NULL);
1193 g_return_val_if_fail (self, FALSE);
1195 /* TODO: should verify if this service was already started */
1197 /* connect to session bus */
1198 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
1201 g_warning ("Could not connect to dbus: %s", error->message);
1202 g_error_free (error);
1206 /* register dbus object */
1207 dbus_g_connection_register_g_object (bus,
1208 GMYTH_DBUS_SERVER_PATH, G_OBJECT (self));
1210 proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
1211 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
1213 /* registering download manager service */
1214 if (!org_freedesktop_DBus_request_name (proxy, GMYTH_DBUS_SERVER_IFACE,
1215 0, &request_ret, &error))
1217 g_warning ("Unable to register dbus service: %d %s",
1218 error->code, error->message);
1219 g_error_free (error);
1223 if (request_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
1225 g_warning ("Got result code %u from requesting name", request_ret);
1232 g_object_unref (self);