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,
85 static gboolean gmyth_dbus_server_get_channel_list (GObject *obj,
88 static gboolean gmyth_dbus_server_get_channel_info (GObject *obj,
92 static gboolean gmyth_dbus_server_file_exists (GObject *obj,
93 const gchar *file_name,
96 static gboolean gmyth_dbus_server_get_recorded_list (GObject *obj,
99 static gboolean gmyth_dbus_server_get_recorded_info (GObject *obj,
100 const gchar *basename,
103 static gboolean gmyth_dbus_server_get_program_list (GObject *obj,
105 const gchar *start_time,
106 const gchar *end_time,
107 GPtrArray **program_list,
109 static gboolean gmyth_dbus_server_get_schedule_list (GObject *obj,
110 GPtrArray **schedule_list,
112 static gboolean gmyth_dbus_server_connected (GObject *obj,
115 static gboolean gmyth_dbus_server_disconnect (GObject *obj,
117 static void gmyth_dbus_server_internal_disconnect
120 static gboolean gmyth_dbus_server_get_server_info (GObject *obj,
121 guint64 *total_space,
125 static gboolean gmyth_dbus_server_get_thumbnail (GObject *obj,
129 static gboolean gmyth_dbus_server_get_channel_icon (GObject *obj,
133 static gboolean gmyth_dbus_server_stop_recording (GObject *obj,
137 static gboolean gmyth_dbus_server_add_schedule (GObject *obj,
140 const gchar *start_time,
141 const gchar *end_time,
143 const gchar *description,
146 static gboolean gmyth_dbus_server_add_exception (GObject *obj,
150 const gchar *start_time,
151 const gchar *end_time,
152 const gchar *description,
154 static gboolean gmyth_dbus_server_remove_schedule (GObject *obj,
159 #include "gmyth-dbus-server-glue.h"
162 static guint signals[LAST_SIGNAL] = { 0 };
164 G_DEFINE_TYPE (GMythDbusServer, gmyth_dbus_server, G_TYPE_OBJECT);
167 gmyth_dbus_server_class_init (GMythDbusServerClass *klass)
169 GObjectClass *object_class = G_OBJECT_CLASS (klass);
171 g_type_class_add_private (klass, sizeof (GMythDbusServerPrivate));
173 object_class->dispose = gmyth_dbus_server_dispose;
174 object_class->finalize = gmyth_dbus_server_finalize;
176 signals[DISCONNECTED] =
177 g_signal_new ("disconnected",
178 G_OBJECT_CLASS_TYPE (object_class),
179 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
182 g_cclosure_marshal_VOID__VOID,
183 G_TYPE_NONE, 0, G_TYPE_NONE);
185 dbus_g_object_type_install_info (GMYTH_DBUS_SERVER_TYPE,
186 &dbus_glib_gmyth_dbus_server_object_info);
190 gmyth_dbus_server_init (GMythDbusServer *self)
195 gmyth_dbus_server_dispose (GObject *object)
197 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->dispose (object);
201 gmyth_dbus_server_finalize (GObject *object)
203 G_OBJECT_CLASS (gmyth_dbus_server_parent_class)->finalize (object);
207 gmyth_dbus_server_connect_epg (GMythDbusServer *server, GError **error)
209 GMythDbusServerPrivate *priv;
210 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
212 if (!priv->connected)
216 GMYTH_DBUS_ERROR_CONNECTION,
224 priv->myth_epg = gmyth_epg_new();
225 if (!gmyth_epg_connect (priv->myth_epg, priv->myth_backend))
227 g_object_unref (priv->myth_epg);
228 priv->myth_epg = NULL;
232 GMYTH_DBUS_ERROR_EPG,
233 _("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,
290 GMythDbusServerPrivate *priv;
292 g_debug ("%s:%d", __FUNCTION__, __LINE__);
294 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
298 gmyth_dbus_server_internal_disconnect (obj, NULL);
301 priv->myth_backend = gmyth_backend_info_new_full (host,
307 s = gmyth_backend_info_get_connected_socket (priv->myth_backend);
310 priv->connected = TRUE;
315 priv->connected = FALSE;
316 g_object_unref (priv->myth_backend);
317 priv->myth_backend = NULL;
321 GMYTH_DBUS_ERROR_CONNECTION,
322 _("Fail to connect with backend"));
325 return priv->connected;
329 gmyth_dbus_server_connected (GObject *obj,
333 GMythDbusServerPrivate *priv;
335 g_debug ("%s:%d", __FUNCTION__, __LINE__);
337 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
339 if (priv->myth_backend)
347 gmyth_dbus_server_disconnect (GObject *obj,
350 GMythDbusServerPrivate *priv;
352 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
355 gmyth_dbus_server_internal_disconnect (obj, error);
356 g_signal_emit (obj, signals[DISCONNECTED], 0);
363 gmyth_dbus_server_internal_disconnect (GObject *obj,
366 GMythDbusServerPrivate *priv;
368 g_debug ("%s:%d", __FUNCTION__, __LINE__);
370 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
374 g_object_unref (priv->myth_epg);
375 priv->myth_epg = NULL;
379 if (priv->myth_backend)
381 g_object_unref (priv->myth_backend);
382 priv->myth_backend = NULL;
385 if (priv->myth_scheduler)
387 g_object_unref (priv->myth_scheduler);
388 priv->myth_scheduler = NULL;
391 priv->connected = FALSE;
395 gmyth_dbus_server_get_server_info (GObject *obj,
396 guint64 *total_space,
401 GMythBackendDetails *details;
402 GMythDbusServerPrivate *priv;
403 gboolean ret = FALSE;
406 g_debug ("%s:%d", __FUNCTION__, __LINE__);
407 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
409 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
411 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
417 GMYTH_DBUS_ERROR_MYTHTV,
418 _("MythTv not avaliable"));
424 gmyth_util_get_backend_details (socket,
428 *total_space = details->total_space;
429 *used_space = details->used_space;
430 *free_space = *total_space - *used_space;
431 gmyth_util_backend_details_free (details);
439 GMYTH_DBUS_ERROR_MYTHTV,
440 _("Fail to get MythTv details"));
443 g_object_unref (socket);
450 gmyth_dbus_server_parse_channel_info (GMythChannelInfo *info,
453 dbus_g_type_struct_set (val,
455 1, info->channel_num->str,
456 2, info->channel_name->str,
457 3, info->channel_icon->str,
462 gmyth_dbus_server_get_channel_info (GObject *obj,
468 GMythChannelInfo *ch_info;
469 GMythDbusServerPrivate *priv;
471 g_debug ("%s:%d", __FUNCTION__, __LINE__);
472 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
474 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
476 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
481 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
483 ch_info = gmyth_epg_get_channel_info (priv->myth_epg, channel_id);
487 g_value_init (&v, ch_type);
488 g_value_take_boxed (&v, dbus_g_type_specialized_construct (ch_type));
489 gmyth_dbus_server_parse_channel_info (ch_info, &v);
491 *info = g_value_get_boxed (&v);
498 GMYTH_DBUS_ERROR_EPG,
499 _("no channel info avaliable"));
507 gmyth_dbus_server_get_channel_list (GObject *obj,
508 GPtrArray **channels,
515 GMythDbusServerPrivate *priv;
517 g_debug ("%s:%d", __FUNCTION__, __LINE__);
518 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
520 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
521 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
526 len = gmyth_epg_get_channel_list (priv->myth_epg, &lst);
528 *channels = g_ptr_array_sized_new (len);
529 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
531 for (walk = lst; walk != NULL; walk = walk->next)
534 GMythChannelInfo *data;
536 data = (GMythChannelInfo *) walk->data;
538 g_value_init (&ch, ch_type);
539 g_value_take_boxed (&ch, dbus_g_type_specialized_construct (ch_type));
540 gmyth_dbus_server_parse_channel_info (data, &ch);
541 g_ptr_array_add (*channels, g_value_get_boxed (&ch));
544 gmyth_free_channel_list (lst);
549 gmyth_dbus_server_file_exists (GObject *obj,
550 const gchar *file_name,
554 GMythDbusServerPrivate *priv;
555 g_debug ("%s:%d", __FUNCTION__, __LINE__);
556 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
558 g_return_val_if_fail (priv->myth_backend, FALSE);
560 *exists = gmyth_util_file_exists (priv->myth_backend, file_name);
566 gmyth_dbus_server_get_program_list (GObject *obj,
568 const gchar *start_time,
569 const gchar *end_time,
570 GPtrArray **programs,
577 GTimeVal start_time_val;
578 GTimeVal end_time_val;
579 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);
585 if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
588 g_time_val_from_iso8601 (start_time, &start_time_val);
589 g_time_val_from_iso8601 (end_time, &end_time_val);
592 len = gmyth_epg_get_program_list (priv->myth_epg,
598 *programs = g_ptr_array_sized_new (len);
599 program_type = GMYTH_DBUS_PROGRAM_G_TYPE;
601 for (walk = list; walk != NULL; walk = walk->next)
603 GValue program = { 0, };
606 GMythProgramInfo *data;
608 data = (GMythProgramInfo *) walk->data;
613 g_value_init (&program, program_type);
614 g_value_take_boxed (&program,
615 dbus_g_type_specialized_construct (program_type));
617 start_str = g_time_val_to_iso8601 (data->startts);
618 end_str = g_time_val_to_iso8601 (data->endts);
620 dbus_g_type_struct_set (&program,
621 0, data->chanid->str,
625 4, data->subtitle->str,
626 5, data->description->str,
627 6, data->category->str,
630 g_ptr_array_add (*programs, g_value_get_boxed (&program));
636 gmyth_free_program_list (list);
638 g_debug ("%s:%d", __FUNCTION__, __LINE__);
643 gmyth_dbus_server_parse_recorded_info (RecordedInfo *info,
649 start_str = g_time_val_to_iso8601 (info->start_time);
650 end_str = g_time_val_to_iso8601 (info->end_time);
652 dbus_g_type_struct_set (val,
659 6, info->subtitle->str,
660 7, info->description->str,
661 8, info->category->str,
662 9, info->basename->str,
670 gmyth_dbus_server_get_recorded_info (GObject *obj,
671 const gchar *basename,
676 GMythDbusServerPrivate *priv;
677 RecordedInfo *record_info;
680 g_debug ("%s:%d", __FUNCTION__, __LINE__);
681 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
683 g_return_val_if_fail (priv->myth_backend, FALSE);
685 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
688 record_type = GMYTH_DBUS_RECORD_G_TYPE;
690 record_info = gmyth_scheduler_get_recorded_info (priv->myth_scheduler,
697 g_value_init (&r, record_type);
698 g_value_take_boxed (&r,
699 dbus_g_type_specialized_construct (record_type));
701 gmyth_dbus_server_parse_recorded_info (record_info, &r);
702 gmyth_recorded_info_free (record_info);
704 *info = g_value_get_boxed (&r);
712 GMYTH_DBUS_ERROR_EPG,
713 _("no record info avaliable"));
722 gmyth_dbus_server_get_recorded_list (GObject *obj,
730 GMythDbusServerPrivate *priv;
732 g_debug ("%s:%d", __FUNCTION__, __LINE__);
733 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
735 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
736 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
740 len = gmyth_scheduler_get_recorded_list (priv->myth_scheduler,
743 record_type = GMYTH_DBUS_RECORD_G_TYPE;
744 *records = g_ptr_array_sized_new (len);
746 for (walk = list; walk != NULL; walk = walk->next)
748 GValue record = { 0, };
751 data = (RecordedInfo *) walk->data;
753 g_value_init (&record, record_type);
754 g_value_take_boxed (&record,
755 dbus_g_type_specialized_construct (record_type));
757 gmyth_dbus_server_parse_recorded_info (data, &record);
759 g_ptr_array_add (*records, g_value_get_boxed (&record));
760 //g_value_unset (&record);
763 gmyth_recorded_info_list_free (list);
770 gmyth_dbus_server_get_schedule_list (GObject *obj,
771 GPtrArray **schedules,
778 GMythDbusServerPrivate *priv;
780 g_debug ("%s:%d", __FUNCTION__, __LINE__);
781 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
783 g_return_val_if_fail (priv->myth_backend, FALSE);
784 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
788 len = gmyth_scheduler_get_schedule_list (priv->myth_scheduler,
791 *schedules = g_ptr_array_sized_new (len);
792 schedule_type = GMYTH_DBUS_SCHEDULE_G_TYPE;
794 for (walk = list; walk != NULL; walk = walk->next)
796 GValue schedule = { 0, };
798 gchar *start_str_time;
801 data = (ScheduleInfo *) walk->data;
803 g_value_init (&schedule, schedule_type);
804 g_value_take_boxed (&schedule,
805 dbus_g_type_specialized_construct (schedule_type));
807 start_str_time = g_time_val_to_iso8601 (data->start_time);
808 end_str_time = g_time_val_to_iso8601 (data->end_time);
810 dbus_g_type_struct_set (&schedule,
811 0, data->schedule_id,
817 6, data->subtitle->str,
818 7, data->description->str,
819 8, data->category->str,
823 g_ptr_array_add (*schedules, g_value_get_boxed (&schedule));
825 g_free (start_str_time);
826 g_free (end_str_time);
829 gmyth_schedule_info_list_free (list);
836 gmyth_dbus_server_get_thumbnail (GObject *obj,
841 GMythFileTransfer *file_transfer;
843 GMythFileReadResult result;
844 GMythDbusServerPrivate *priv;
846 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
848 file_transfer = NULL;
850 g_return_val_if_fail (priv->myth_backend, FALSE);
852 if (!gmyth_util_file_exists (priv->myth_backend, uri))
856 GMYTH_DBUS_ERROR_MYTHTV,
857 _("File not exists"));
862 file_transfer = gmyth_file_transfer_new (priv->myth_backend);
864 if (!gmyth_file_transfer_open (file_transfer, uri))
868 GMYTH_DBUS_ERROR_MYTHTV,
869 _("Fail to open file"));
873 filesize = gmyth_file_transfer_get_filesize (file_transfer);
877 *image = g_byte_array_new ();
878 result = gmyth_file_transfer_read (file_transfer, *image, filesize, FALSE);
879 if (result == GMYTH_FILE_READ_ERROR)
883 GMYTH_DBUS_ERROR_MYTHTV,
884 _("Fail to read file"));
889 gmyth_file_transfer_close (file_transfer);
890 g_object_unref (file_transfer);
892 if (filesize > (*image)->len)
896 GMYTH_DBUS_ERROR_MYTHTV,
906 g_byte_array_free (*image, TRUE);
907 g_object_unref(file_transfer);
912 gmyth_dbus_server_get_channel_icon (GObject *obj,
917 GMythChannelInfo *channel = NULL;
920 GMythDbusServerPrivate *priv;
922 g_debug ("%s:%d", __FUNCTION__, __LINE__);
923 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
924 g_return_val_if_fail (priv->myth_backend, FALSE);
926 channel = gmyth_epg_get_channel_info (priv->myth_epg,
935 GMYTH_DBUS_ERROR_MYTHTV,
936 _("Invalid channel"));
941 if (!gmyth_epg_channel_has_icon(priv->myth_epg, channel))
943 gmyth_channel_info_free (channel);
946 GMYTH_DBUS_ERROR_MYTHTV,
947 _("Channel does not have icon available"));
954 if (!gmyth_epg_channel_get_icon (priv->myth_epg,
959 gmyth_channel_info_free (channel);
962 GMYTH_DBUS_ERROR_MYTHTV,
963 _("Could not get channel icon for channel id = %u"),
968 *icon = g_byte_array_sized_new (icon_length);
969 *icon = g_byte_array_append (*icon, icon_data, icon_length);
972 gmyth_channel_info_free(channel);
978 gmyth_dbus_server_stop_recording (GObject *obj,
983 gboolean ret = FALSE;
984 GMythDbusServerPrivate *priv;
986 g_debug ("%s:%d", __FUNCTION__, __LINE__);
987 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
989 g_return_val_if_fail (priv->myth_backend, FALSE);
990 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
993 ret = gmyth_scheduler_stop_recording (priv->myth_scheduler,
1000 gmyth_dbus_server_new_schedule_info (const gchar* description,
1003 GTimeVal *start_vtime,
1004 GTimeVal *end_vtime)
1006 ScheduleInfo *new_sched_info;
1008 new_sched_info = g_new0(ScheduleInfo, 1);
1010 /* record_id == -1 for generating a new id */
1011 new_sched_info->schedule_id = -1;
1013 new_sched_info->channel_id = channel_id;
1014 new_sched_info->program_id = program_id;
1015 new_sched_info->start_time = g_new0 (GTimeVal, 1);
1016 *new_sched_info->start_time = *start_vtime;
1017 new_sched_info->end_time = g_new0 (GTimeVal, 1);
1018 *new_sched_info->end_time = *end_vtime;
1020 /* TODO: there is no frequency field */
1021 /*new_sched_info->frequency = -1;*/
1023 if (description != NULL) {
1024 /* FIXME: description parameter is used as title and description */
1025 new_sched_info->title = g_string_new(description);
1026 new_sched_info->description = g_string_new(description);
1029 return new_sched_info;
1033 gmyth_dbus_server_add_schedule (GObject *obj,
1036 const gchar *start_time,
1037 const gchar *end_time,
1039 const gchar *description,
1043 ScheduleInfo *sch_info;
1044 GTimeVal start_vtime;
1046 GMythDbusServerPrivate *priv;
1048 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1049 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1053 g_return_val_if_fail (priv->myth_backend, FALSE);
1055 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1059 g_time_val_from_iso8601 (start_time, &start_vtime);
1060 g_time_val_from_iso8601 (end_time, &end_vtime);
1061 sch_info = gmyth_dbus_server_new_schedule_info (description,
1066 if (sch_info != NULL) {
1067 GMythScheduleType type;
1069 gboolean has_record;
1072 GMYTH_SCHEDULE_ALL_OCCURRENCES :
1073 GMYTH_SCHEDULE_ONE_OCCURRENCE);
1075 g_get_current_time (&t_now);
1077 has_record = gmyth_scheduler_was_recorded_before (priv->myth_scheduler,
1079 (time_t) start_vtime.tv_sec);
1082 if ((t_now.tv_sec >= start_vtime.tv_sec)
1083 && (t_now.tv_sec <= end_vtime.tv_sec) && has_record)
1085 GMythSocket *socket;
1086 gboolean res = FALSE;
1088 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
1089 res = gmyth_scheduler_reactivate_schedule(priv->myth_scheduler,
1091 (time_t) start_vtime.tv_sec);
1093 GMythStringList *slist = gmyth_string_list_new();
1095 gmyth_string_list_append_char_array(slist, "RESCHEDULE_RECORDINGS 0");
1096 gmyth_socket_sendreceive_stringlist(socket, slist);
1097 res = (gmyth_string_list_get_int(slist, 0) == 1);
1098 g_object_unref(slist);
1101 g_object_unref(socket);
1106 if (!gmyth_scheduler_add_schedule_full (priv->myth_scheduler,
1110 g_warning("Could not add schedule entry");
1114 (*schedule_id) = sch_info->schedule_id;
1115 gmyth_schedule_info_free (sch_info);
1123 gmyth_dbus_server_add_exception (GObject *obj,
1127 const gchar *start_time,
1128 const gchar *end_time,
1129 const gchar *description,
1132 ScheduleInfo *sch_info;
1133 GTimeVal start_vtime;
1135 GMythDbusServerPrivate *priv;
1137 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1138 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1140 g_return_val_if_fail (priv->myth_backend, FALSE);
1142 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1145 g_time_val_from_iso8601 (start_time, &start_vtime);
1146 g_time_val_from_iso8601 (end_time, &end_vtime);
1148 sch_info = gmyth_dbus_server_new_schedule_info (description,
1153 if (sch_info != NULL)
1155 if (!gmyth_scheduler_add_exception (priv->myth_scheduler,
1159 g_warning ("Could not add schedule exception");
1160 gmyth_schedule_info_free (sch_info);
1164 gmyth_schedule_info_free (sch_info);
1171 gmyth_dbus_server_remove_schedule (GObject *obj,
1175 GMythDbusServerPrivate *priv;
1177 g_debug ("%s:%d", __FUNCTION__, __LINE__);
1178 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1180 g_return_val_if_fail (priv->myth_backend, FALSE);
1182 if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1185 return gmyth_scheduler_delete_schedule (priv->myth_scheduler, schedule_id);
1189 gmyth_dbus_server_start_dbus_service (void)
1191 GError *error = NULL;
1193 DBusGConnection *bus;
1195 GMythDbusServer *self;
1197 self = g_object_new (GMYTH_DBUS_SERVER_TYPE, NULL);
1198 g_return_val_if_fail (self, FALSE);
1200 /* TODO: should verify if this service was already started */
1202 /* connect to session bus */
1203 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
1206 g_warning ("Could not connect to dbus: %s", error->message);
1207 g_error_free (error);
1211 /* register dbus object */
1212 dbus_g_connection_register_g_object (bus,
1213 GMYTH_DBUS_SERVER_PATH, G_OBJECT (self));
1215 proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
1216 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
1218 /* registering download manager service */
1219 if (!org_freedesktop_DBus_request_name (proxy, GMYTH_DBUS_SERVER_IFACE,
1220 0, &request_ret, &error))
1222 g_warning ("Unable to register dbus service: %d %s",
1223 error->code, error->message);
1224 g_error_free (error);
1228 if (request_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
1230 g_warning ("Got result code %u from requesting name", request_ret);
1237 g_object_unref (self);