Main Page | Data Structures | File List | Data Fields | Globals

event.c

Go to the documentation of this file.
00001 /**
00002  * This file is part of alarmd
00003  *
00004  * Contact Person: David Weinehall <david.weinehall@nokia.com>
00005  *
00006  * Copyright (C) 2006 Nokia Corporation
00007  * alarmd and libalarm are free software; you can redistribute them
00008  * and/or modify them under the terms of the GNU Lesser General Public
00009  * License version 2.1 as published by the Free Software Foundation.
00010  *
00011  * alarmd and libalarm are distributed in the hope that they will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this software; if not, write to the Free
00018  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00019  * 02110-1301 USA
00020  */
00021 
00022 #include <glib.h>
00023 #include <glib-object.h>
00024 #include "include/alarm_event.h"
00025 #include "queue.h"
00026 #include "event.h"
00027 #include "action.h"
00028 #include "debug.h"
00029 
00030 static const time_t _day_in_seconds = 24 * 60 * 60;
00031 
00032 static void alarmd_event_init(AlarmdEvent *event);
00033 static void alarmd_event_class_init(AlarmdEventClass *klass);
00034 static void _alarmd_event_set_property(GObject *object,
00035                 guint param_id,
00036                 const GValue *value,
00037                 GParamSpec *pspec);
00038 static void _alarmd_event_get_property(GObject *object,
00039                 guint param_id,
00040                 GValue *value,
00041                 GParamSpec *pspec);
00042 
00043 static void _alarmd_event_real_fire(AlarmdEvent *event, gboolean delayed);
00044 static void _alarmd_event_fired(AlarmdEvent *event, gboolean delayed);
00045 static void _alarmd_event_real_cancel(AlarmdEvent *event);
00046 static void _alarmd_event_real_acknowledge(AlarmdEvent *event);
00047 static void _alarmd_event_real_snooze(AlarmdEvent *event);
00048 static void _alarmd_event_real_queue(AlarmdEvent *event, TimerPlugin *plugin);
00049 static void _alarmd_event_real_dequeue(AlarmdEvent *event);
00050 static void _alarmd_event_real_dequeued(AlarmdEvent *event);
00051 static time_t _alarmd_event_real_get_time(AlarmdEvent *event);
00052 static gint32 _alarmd_event_real_get_flags(AlarmdEvent *event);
00053 static void _alarmd_event_finalize(GObject *object);
00054 static void _alarmd_event_changed(AlarmdEvent *event, gpointer user_data);
00055 static GSList *_alarmd_event_get_saved_properties(void);
00056 static void _alarmd_event_action_acknowledge(AlarmdEvent *event, guint ack_type, AlarmdAction *action);
00057 static gboolean _alarmd_event_real_need_power_up(AlarmdEvent *event);
00058 static void _alarmd_event_time_changed(AlarmdObject *object);
00059 
00060 enum signals {
00061         SIGNAL_FIRE,
00062         SIGNAL_CANCEL,
00063         SIGNAL_ACKNOWLEDGE,
00064         SIGNAL_SNOOZE,
00065         SIGNAL_QUEUE,
00066         SIGNAL_DEQUEUE,
00067         SIGNAL_COUNT
00068 };
00069 
00070 enum properties {
00071         PROP_ACTION = 1,
00072         PROP_TIME,
00073         PROP_SNOOZE_INT,
00074         PROP_SNOOZE,
00075         PROP_COOKIE,
00076         PROP_QUEUE,
00077 };
00078 
00079 enum saved_props {
00080         S_ACTION,
00081         S_TIME,
00082         S_SNOOZE_INT,
00083         S_SNOOZE,
00084         S_COOKIE,
00085         S_COUNT
00086 };
00087 
00088 static const gchar * const saved_properties[S_COUNT] =
00089 {
00090         "action",
00091         "time",
00092         "snooze_interval",
00093         "snooze",
00094         "cookie",
00095 };
00096 
00097 static guint event_signals[SIGNAL_COUNT];
00098 
00099 typedef struct _AlarmdEventPrivate AlarmdEventPrivate;
00100 struct _AlarmdEventPrivate {
00101         TimerPlugin *queued;
00102         time_t alarm_time;
00103         guint snooze_interval;
00104         guint snooze;
00105         AlarmdAction *action;
00106         AlarmdQueue *queue;
00107         gulong action_changed_signal;
00108         gulong action_acknowledged_signal;
00109         glong cookie;
00110 };
00111 
00112 
00113 #define ALARMD_EVENT_GET_PRIVATE(obj) \
00114 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
00115                               ALARMD_TYPE_EVENT, AlarmdEventPrivate));
00116 
00117 
00118 GType alarmd_event_get_type(void)
00119 {
00120         static GType event_type = 0;
00121 
00122         if (!event_type)
00123         {
00124                 static const GTypeInfo event_info =
00125                 {
00126                         sizeof (AlarmdEventClass),
00127                         NULL,
00128                         NULL,
00129                         (GClassInitFunc) alarmd_event_class_init,
00130                         NULL,
00131                         NULL,
00132                         sizeof (AlarmdEvent),
00133                         0,
00134                         (GInstanceInitFunc) alarmd_event_init,
00135                         NULL
00136                 };
00137 
00138                 event_type = g_type_register_static(ALARMD_TYPE_OBJECT,
00139                                 "AlarmdEvent",
00140                                 &event_info, 0);
00141         }
00142 
00143         return event_type;
00144 }
00145 
00146 AlarmdEvent *alarmd_event_new(void)
00147 {
00148         AlarmdEvent *retval;
00149         ENTER_FUNC;
00150         retval = g_object_new(ALARMD_TYPE_EVENT, NULL);
00151         LEAVE_FUNC;
00152         return retval;
00153 }
00154 
00155 void alarmd_event_fire(AlarmdEvent *event, gboolean delayed)
00156 {
00157         ENTER_FUNC;
00158         g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_FIRE], 0, delayed);
00159         LEAVE_FUNC;
00160 }
00161 
00162 void alarmd_event_cancel(AlarmdEvent *event)
00163 {
00164         ENTER_FUNC;
00165         g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_CANCEL], 0);
00166         LEAVE_FUNC;
00167 }
00168 
00169 void alarmd_event_acknowledge(AlarmdEvent *event)
00170 {
00171         ENTER_FUNC;
00172         g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_ACKNOWLEDGE], 0);
00173         LEAVE_FUNC;
00174 }
00175 
00176 void alarmd_event_snooze(AlarmdEvent *event)
00177 {
00178         ENTER_FUNC;
00179         g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_SNOOZE], 0);
00180         LEAVE_FUNC;
00181 }
00182 
00183 void alarmd_event_queue(AlarmdEvent *event, TimerPlugin *plugin)
00184 {
00185         ENTER_FUNC;
00186         g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_QUEUE], 0, plugin);
00187         LEAVE_FUNC;
00188 }
00189 
00190 void alarmd_event_dequeue(AlarmdEvent *event)
00191 {
00192         ENTER_FUNC;
00193         g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_DEQUEUE], 0);
00194         LEAVE_FUNC;
00195 }
00196 
00197 time_t alarmd_event_get_time(AlarmdEvent *event)
00198 {
00199         AlarmdEventClass *klass = ALARMD_EVENT_GET_CLASS(event);
00200         time_t retval;
00201         ENTER_FUNC;
00202         retval = klass->get_time(event);
00203         LEAVE_FUNC;
00204         return retval;
00205 }
00206 
00207 static void alarmd_event_init(AlarmdEvent *event)
00208 {
00209         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00210         ENTER_FUNC;
00211 
00212         priv->queued = NULL;
00213         priv->snooze_interval = 0;
00214         priv->snooze = 0;
00215         priv->alarm_time = 0;
00216         priv->action = NULL;
00217         priv->cookie = 0;
00218         priv->queue = NULL;
00219         LEAVE_FUNC;
00220 }
00221 
00222 static void alarmd_event_class_init(AlarmdEventClass *klass)
00223 {
00224         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
00225         AlarmdObjectClass *aobject_class = ALARMD_OBJECT_CLASS(klass);
00226 
00227         ENTER_FUNC;
00228         g_type_class_add_private(klass, sizeof(AlarmdEventPrivate));
00229 
00230         gobject_class->set_property = _alarmd_event_set_property;
00231         gobject_class->get_property = _alarmd_event_get_property;
00232         gobject_class->finalize = _alarmd_event_finalize;
00233 
00234         aobject_class->get_saved_properties = _alarmd_event_get_saved_properties;
00235         aobject_class->time_changed = _alarmd_event_time_changed;
00236 
00237         klass->fire = _alarmd_event_real_fire;
00238         klass->cancel = _alarmd_event_real_cancel;
00239         klass->acknowledge = _alarmd_event_real_acknowledge;
00240         klass->snooze = _alarmd_event_real_snooze;
00241         klass->queue = _alarmd_event_real_queue;
00242         klass->dequeue = _alarmd_event_real_dequeue;
00243 
00244         klass->get_time = _alarmd_event_real_get_time;
00245         klass->get_flags = _alarmd_event_real_get_flags;
00246         klass->need_power_up = _alarmd_event_real_need_power_up;
00247 
00248         g_object_class_install_property(gobject_class,
00249                         PROP_ACTION,
00250                         g_param_spec_object("action",
00251                                 "Event's action.",
00252                                 "Action done when event is due.",
00253                                 ALARMD_TYPE_ACTION,
00254                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00255         g_object_class_install_property(gobject_class,
00256                         PROP_TIME,
00257                         g_param_spec_int64("time",
00258                                 "Event's time.",
00259                                 "Time when event is due.",
00260                                 0,
00261                                 G_MAXINT64,
00262                                 0,
00263                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00264         g_object_class_install_property(gobject_class,
00265                         PROP_SNOOZE_INT,
00266                         g_param_spec_uint("snooze_interval",
00267                                 "Postponing interval.",
00268                                 "Amount of time the event is postponed when snoozed.",
00269                                 0,
00270                                 G_MAXUINT,
00271                                 0,
00272                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00273         g_object_class_install_property(gobject_class,
00274                         PROP_SNOOZE,
00275                         g_param_spec_uint("snooze",
00276                                 "Time snoozed.",
00277                                 "Amount of time the event has been snoozed.",
00278                                 0,
00279                                 G_MAXUINT,
00280                                 0,
00281                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00282         g_object_class_install_property(gobject_class,
00283                         PROP_COOKIE,
00284                         g_param_spec_long("cookie",
00285                                 "Event's id.",
00286                                 "Unique ID for the event.",
00287                                 0,
00288                                 G_MAXLONG,
00289                                 0,
00290                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00291         g_object_class_install_property(gobject_class,
00292                         PROP_QUEUE,
00293                         g_param_spec_object("queue",
00294                                 "Queue the event is on.",
00295                                 "The queue that has the event.",
00296                                 ALARMD_TYPE_QUEUE,
00297                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00298 
00299         event_signals[SIGNAL_FIRE] = g_signal_new("fire",
00300                         G_TYPE_FROM_CLASS(gobject_class),
00301                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
00302                         G_STRUCT_OFFSET(AlarmdEventClass, fire),
00303                         NULL, NULL,
00304                         g_cclosure_marshal_VOID__BOOLEAN,
00305                         G_TYPE_NONE, 1,
00306                         G_TYPE_BOOLEAN);
00307         event_signals[SIGNAL_CANCEL] = g_signal_new("cancel",
00308                         G_TYPE_FROM_CLASS(gobject_class),
00309                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
00310                         G_STRUCT_OFFSET(AlarmdEventClass, cancel),
00311                         NULL, NULL,
00312                         g_cclosure_marshal_VOID__VOID,
00313                         G_TYPE_NONE, 0);
00314         event_signals[SIGNAL_ACKNOWLEDGE] = g_signal_new("acknowledge",
00315                         G_TYPE_FROM_CLASS(gobject_class),
00316                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
00317                         G_STRUCT_OFFSET(AlarmdEventClass, acknowledge),
00318                         NULL, NULL,
00319                         g_cclosure_marshal_VOID__VOID,
00320                         G_TYPE_NONE, 0);
00321         event_signals[SIGNAL_SNOOZE] = g_signal_new("snooze",
00322                         G_TYPE_FROM_CLASS(gobject_class),
00323                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
00324                         G_STRUCT_OFFSET(AlarmdEventClass, snooze),
00325                         NULL, NULL,
00326                         g_cclosure_marshal_VOID__VOID,
00327                         G_TYPE_NONE, 0);
00328         event_signals[SIGNAL_QUEUE] = g_signal_new("queue",
00329                         G_TYPE_FROM_CLASS(gobject_class),
00330                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
00331                         G_STRUCT_OFFSET(AlarmdEventClass, queue),
00332                         NULL, NULL,
00333                         g_cclosure_marshal_VOID__POINTER,
00334                         G_TYPE_NONE, 1,
00335                         G_TYPE_POINTER);
00336         event_signals[SIGNAL_DEQUEUE] = g_signal_new("dequeue",
00337                         G_TYPE_FROM_CLASS(gobject_class),
00338                         G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
00339                         G_STRUCT_OFFSET(AlarmdEventClass, dequeue),
00340                         NULL, NULL,
00341                         g_cclosure_marshal_VOID__VOID,
00342                         G_TYPE_NONE, 0);
00343         LEAVE_FUNC;
00344 }
00345 
00346 static void _alarmd_event_action_acknowledge(AlarmdEvent *event, guint ack_type, AlarmdAction *action)
00347 {
00348         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00349         ENTER_FUNC;
00350         (void)action;
00351 
00352         g_signal_handler_disconnect(priv->action, priv->action_acknowledged_signal);
00353         if (ack_type == ACK_NORMAL) {
00354                 g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_ACKNOWLEDGE], 0);
00355         } else {
00356                 g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_SNOOZE], 0);
00357         }
00358         LEAVE_FUNC;
00359 }
00360 
00361 static void _alarmd_event_real_fire(AlarmdEvent *event, gboolean delayed)
00362 {
00363         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00364         ENTER_FUNC;
00365 
00366         if (priv->action) {
00367                 if (delayed) {
00368                         gint flags;
00369                         g_object_get(priv->action, "flags", &flags, NULL);
00370                         if (flags & ALARM_EVENT_POSTPONE_DELAYED) {
00371                                 time_t now = time(NULL);
00372 
00373                                 if (now > priv->alarm_time + _day_in_seconds)
00374                                 {
00375                                         time_t d = now - priv->alarm_time;
00376                                         guint count = d / _day_in_seconds + 1;
00377                                         priv->alarm_time += count *
00378                                                 _day_in_seconds;
00379                                         g_object_set(event, 
00380                                                         "time",
00381                                                         priv->alarm_time,
00382                                                         NULL);
00383                                         LEAVE_FUNC;
00384                                         return;
00385                                 } else {
00386                                         delayed = FALSE;
00387                                 }
00388                         }
00389                 }
00390                 priv->action_acknowledged_signal = 
00391                         g_signal_connect_swapped(priv->action, "acknowledge", (GCallback)_alarmd_event_action_acknowledge, event);
00392                 alarmd_action_run(priv->action, delayed);
00393         } else {
00394                 g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_ACKNOWLEDGE], 0);
00395         }
00396         LEAVE_FUNC;
00397 }
00398 
00399 static void _alarmd_event_fired(AlarmdEvent *event, gboolean delayed)
00400 {
00401         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00402         ENTER_FUNC;
00403 
00404         DEBUG("%p: queued = NULL", event);
00405         DEBUG("Unreffing %p", event);
00406         g_object_unref(event);
00407         priv->queued = NULL;
00408         alarmd_event_fire(event, delayed);
00409         
00410         LEAVE_FUNC;
00411 }
00412 
00413 static void _alarmd_event_real_cancel(AlarmdEvent *event)
00414 {
00415         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00416         ENTER_FUNC;
00417         if (priv->queued) {
00418                 priv->queued->remove_event(priv->queued);
00419                 DEBUG("%p: queued = NULL", event);
00420                 priv->queued = NULL;
00421         }
00422         LEAVE_FUNC;
00423 }
00424 
00425 static void _alarmd_event_real_snooze(AlarmdEvent *event)
00426 {
00427         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00428         guint snooze;
00429         guint64 now = time(NULL);
00430         ENTER_FUNC;
00431 
00432         if (priv->snooze_interval) {
00433                 snooze = priv->snooze_interval;
00434         } else {
00435                 g_object_get(priv->queue, "snooze", &snooze, NULL);
00436         }
00437 
00438         priv->snooze += snooze;
00439 
00440         if (priv->alarm_time + priv->snooze * 60 < now) {
00441                 priv->snooze = (now - priv->alarm_time) / 60 + snooze;
00442         }
00443 
00444         alarmd_object_changed(ALARMD_OBJECT(event));
00445         LEAVE_FUNC;
00446 }
00447 
00448 static void _alarmd_event_real_acknowledge(AlarmdEvent *event)
00449 {
00450         ENTER_FUNC;
00451         g_signal_emit(ALARMD_OBJECT(event), event_signals[SIGNAL_CANCEL], 0);
00452         LEAVE_FUNC;
00453 }
00454 
00455 static void _alarmd_event_real_queue(AlarmdEvent *event, TimerPlugin *plugin)
00456 {
00457         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00458         ENTER_FUNC;
00459 
00460         if (priv->queued == plugin) {
00461                 DEBUG("%p already on given queue %p.", event, plugin);
00462                 LEAVE_FUNC;
00463                 return;
00464         }
00465 
00466         if (priv->queued) {
00467                 priv->queued->remove_event(priv->queued);
00468                 DEBUG("%p: queued = NULL", event);
00469                 priv->queued = NULL;
00470         }
00471         DEBUG("Reffing %p", event);
00472         g_object_ref(event);
00473         if (plugin->set_event(plugin, alarmd_event_get_time(event), (TimerCallback)_alarmd_event_fired, (TimerCancel)_alarmd_event_real_dequeued, event)) {
00474                 DEBUG("%p: queued = %p", event, plugin);
00475                 priv->queued = plugin;
00476 
00477         } else {
00478                 DEBUG("Unreffing %p", event);
00479                 DEBUG("%p: queued = NULL", event);
00480                 priv->queued = NULL;
00481                 g_object_unref(event);
00482         }
00483         LEAVE_FUNC;
00484 }
00485 
00486 static void _alarmd_event_real_dequeued(AlarmdEvent *event)
00487 {
00488         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00489         ENTER_FUNC;
00490 
00491         if (priv->queued != NULL) {
00492                 DEBUG("%p: queued = NULL", event);
00493                 priv->queued = NULL;
00494                 alarmd_event_dequeue(event);
00495                 DEBUG("Unreffing %p", event);
00496                 g_object_unref(event);
00497         }
00498 
00499         LEAVE_FUNC;
00500 }
00501 
00502 static void _alarmd_event_real_dequeue(AlarmdEvent *event)
00503 {
00504         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00505         ENTER_FUNC;
00506 
00507         if (priv->queued) {
00508                 priv->queued->remove_event(priv->queued);
00509                 DEBUG("%p: queued = NULL", event);
00510         }
00511         LEAVE_FUNC;
00512 }
00513 
00514 static time_t _alarmd_event_real_get_time(AlarmdEvent *event)
00515 {
00516         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00517         ENTER_FUNC;
00518         
00519         LEAVE_FUNC;
00520         return priv->alarm_time + priv->snooze * 60;
00521 }
00522 
00523 static gint32 _alarmd_event_real_get_flags(AlarmdEvent *event)
00524 {
00525         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00526         gint32 retval = 0;
00527         ENTER_FUNC;
00528 
00529         if (priv->action) {
00530                 g_object_get(G_OBJECT(priv->action), "flags", &retval, NULL);
00531         }
00532 
00533         LEAVE_FUNC;
00534         return retval;
00535 }
00536 
00537 static void _alarmd_event_changed(AlarmdEvent *event, gpointer user_data)
00538 {
00539         ENTER_FUNC;
00540         (void)user_data;
00541 
00542         alarmd_object_changed(ALARMD_OBJECT(event));
00543         LEAVE_FUNC;
00544 }
00545 
00546 static void _alarmd_event_set_property(GObject *object,
00547                 guint param_id,
00548                 const GValue *value,
00549                 GParamSpec *pspec)
00550 {
00551         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(object);
00552         ENTER_FUNC;
00553 
00554         DEBUG("param_id = %u", param_id);
00555 
00556         switch (param_id) {
00557         case PROP_ACTION:
00558                 if (priv->action) {
00559                         g_signal_handler_disconnect(priv->action, priv->action_changed_signal);
00560                         priv->action_changed_signal = 0;
00561                         g_object_set(priv->action, "event", NULL, NULL);
00562                         g_object_unref(priv->action);
00563                 }
00564                 priv->action = g_value_get_object(value);
00565                 if (priv->action) {
00566                         g_object_ref(priv->action);
00567                         priv->action_changed_signal = g_signal_connect(priv->action, "changed", (GCallback)_alarmd_event_changed, NULL);
00568                         g_object_set(priv->action, "event", object, NULL);
00569                 }
00570                 break;
00571         case PROP_TIME:
00572                 priv->alarm_time = g_value_get_int64(value);
00573                 break;
00574         case PROP_SNOOZE:
00575                 priv->snooze = g_value_get_uint(value);
00576                 break;
00577         case PROP_SNOOZE_INT:
00578                 priv->snooze_interval = g_value_get_uint(value);
00579                 break;
00580         case PROP_COOKIE:
00581                 priv->cookie = g_value_get_long(value);
00582                 break;
00583         case PROP_QUEUE:
00584                 if (priv->queue) {
00585                         alarmd_queue_remove_event(priv->queue,
00586                                         priv->cookie);
00587                         g_object_remove_weak_pointer(G_OBJECT(priv->queue),
00588                                         (gpointer *)&priv->queue);
00589                 }
00590                 priv->queue = g_value_get_object(value);
00591                 if (priv->queue) {
00592                         g_object_add_weak_pointer(G_OBJECT(priv->queue),
00593                                         (gpointer *)&priv->queue);
00594                 }
00595                 LEAVE_FUNC;
00596                 return;
00597                 break;
00598         default:
00599                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00600                 LEAVE_FUNC;
00601                 return;
00602                 break;
00603         }
00604         alarmd_object_changed(ALARMD_OBJECT(object));
00605         LEAVE_FUNC;
00606 }
00607 
00608 static void _alarmd_event_get_property(GObject *object,
00609                 guint param_id,
00610                 GValue *value,
00611                 GParamSpec *pspec)
00612 {
00613         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(object);
00614         ENTER_FUNC;
00615         switch (param_id) {
00616         case PROP_ACTION:
00617                 g_value_set_object(value, priv->action);
00618                 break;
00619         case PROP_TIME:
00620                 g_value_set_int64(value, priv->alarm_time);
00621                 break;
00622         case PROP_SNOOZE:
00623                 g_value_set_uint(value, priv->snooze);
00624                 break;
00625         case PROP_SNOOZE_INT:
00626                 g_value_set_uint(value, priv->snooze_interval);
00627                 break;
00628         case PROP_COOKIE:
00629                 g_value_set_long(value, priv->cookie);
00630                 break;
00631         case PROP_QUEUE:
00632                 g_value_set_object(value, priv->queue);
00633                 break;
00634         default:
00635                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00636                 LEAVE_FUNC;
00637                 return;
00638                 break;
00639         }
00640         LEAVE_FUNC;
00641 }
00642 
00643 static void _alarmd_event_finalize(GObject *object)
00644 {
00645         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(object);
00646         ENTER_FUNC;
00647 
00648         DEBUG("time: %lu", priv->alarm_time);
00649         DEBUG("queued: %p", priv->queued);
00650         if (priv->queue) {
00651                 g_object_remove_weak_pointer(G_OBJECT(priv->queue), (gpointer *)&priv->queue);
00652         }
00653         if (priv->action) {
00654                 g_object_set(priv->action, "event", NULL, NULL);
00655                 g_object_unref(priv->action);
00656                 priv->action = NULL;
00657         }
00658         G_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_EVENT)))->finalize(object);
00659         LEAVE_FUNC;
00660 }
00661 
00662 static GSList *_alarmd_event_get_saved_properties()
00663 {
00664         guint i;
00665         GSList *retval = NULL;
00666         ENTER_FUNC;
00667         retval = ALARMD_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_EVENT)))->get_saved_properties();
00668         for (i = 0; i < S_COUNT; i++) {
00669                 retval = g_slist_append(retval, (gpointer)saved_properties[i]);
00670         }
00671         LEAVE_FUNC;
00672         return retval;
00673 }
00674 
00675 static gboolean _alarmd_event_real_need_power_up(AlarmdEvent *event)
00676 {
00677         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00678         ENTER_FUNC;
00679         if (!priv->action) {
00680                 LEAVE_FUNC;
00681                 return FALSE;
00682         } else {
00683                 gboolean retval = alarmd_action_need_power_up(priv->action);
00684                 LEAVE_FUNC;
00685                 return retval;
00686         }
00687 }
00688 
00689 static void _alarmd_event_time_changed(AlarmdObject *object)
00690 {
00691         AlarmdEvent *event = ALARMD_EVENT(object);
00692         AlarmdEventPrivate *priv = ALARMD_EVENT_GET_PRIVATE(event);
00693 
00694         ENTER_FUNC;
00695         /* If we're on timer, the timer plugin will take care of us. */
00696         if (!priv->queued && alarmd_event_get_time(event) < time(NULL)) {
00697                 alarmd_event_fire(event, TRUE);
00698         }
00699         LEAVE_FUNC;
00700 }
00701 
00702 gboolean alarmd_event_need_power_up(AlarmdEvent *event)
00703 {
00704         AlarmdEventClass *klass = ALARMD_EVENT_GET_CLASS(event);
00705         gboolean retval;
00706         ENTER_FUNC;
00707         retval = klass->need_power_up(event);
00708         LEAVE_FUNC;
00709         return retval;
00710 }
00711 
00712 gint32 alarmd_event_get_flags(AlarmdEvent *event)
00713 {
00714         AlarmdEventClass *klass = ALARMD_EVENT_GET_CLASS(event);
00715         gint32 retval;
00716         ENTER_FUNC;
00717         retval = klass->get_flags(event);
00718         LEAVE_FUNC;
00719         return retval;
00720 }

Generated on Thu Dec 21 18:23:30 2006 for Alarmd by  doxygen 1.4.2