00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <glib.h>
00023 #include <glib-object.h>
00024 #include "include/alarm_event.h"
00025 #include "action.h"
00026 #include "event.h"
00027 #include "rpc-systemui.h"
00028 #include "rpc-statusbar.h"
00029 #include "debug.h"
00030
00031 static void _alarmd_action_set_property(GObject *object,
00032 guint param_id,
00033 const GValue *value,
00034 GParamSpec *pspec);
00035 static void _alarmd_action_get_property(GObject *object,
00036 guint param_id,
00037 GValue *value,
00038 GParamSpec *pspec);
00039 static void _alarmd_action_finalize(GObject *object);
00040 static void alarmd_action_init(AlarmdAction *action);
00041 static void alarmd_action_class_init(AlarmdActionClass *klass);
00042 static void _alarmd_action_real_run(AlarmdAction *action, gboolean delayed);
00043 static void _alarmd_action_real_acknowledge(AlarmdAction *action,
00044 AlarmdActionAckType ack_type);
00045 static gboolean _alarmd_action_real_need_power_up(AlarmdAction *action);
00046 static GSList *_alarmd_action_get_saved_properties(void);
00047
00048
00049 enum properties {
00050 PROP_EVENT = 1,
00051 PROP_FLAGS,
00052 };
00053
00054 enum saved_props {
00055 S_FLAGS,
00056 S_COUNT
00057 };
00058
00059 static const gchar * const saved_properties[S_COUNT] = {
00060 "flags",
00061 };
00062
00063 enum signals {
00064 SIGNAL_RUN,
00065 SIGNAL_ACKNOWLEDGE,
00066 SIGNAL_COUNT
00067 };
00068
00069 static guint action_signals[SIGNAL_COUNT];
00070
00071 #define ALARMD_ACTION_GET_PRIVATE(obj) \
00072 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
00073 ALARMD_TYPE_ACTION, AlarmdActionPrivate));
00074
00075 typedef struct _AlarmdActionPrivate AlarmdActionPrivate;
00076 struct _AlarmdActionPrivate {
00077 AlarmdEvent *event;
00078 gint32 flags;
00079 };
00080
00081
00082 GType alarmd_action_get_type(void)
00083 {
00084 static GType action_type = 0;
00085
00086 if (!action_type)
00087 {
00088 static const GTypeInfo action_info =
00089 {
00090 sizeof (AlarmdActionClass),
00091 NULL,
00092 NULL,
00093 (GClassInitFunc) alarmd_action_class_init,
00094 NULL,
00095 NULL,
00096 sizeof (AlarmdAction),
00097 0,
00098 (GInstanceInitFunc) alarmd_action_init,
00099 NULL
00100 };
00101
00102 action_type = g_type_register_static(ALARMD_TYPE_OBJECT,
00103 "AlarmdAction",
00104 &action_info, 0);
00105 }
00106
00107 return action_type;
00108 }
00109
00110 AlarmdAction *alarmd_action_new(void)
00111 {
00112 AlarmdAction *retval;
00113 ENTER_FUNC;
00114 retval = g_object_new(ALARMD_TYPE_ACTION, NULL);
00115 LEAVE_FUNC;
00116 return retval;
00117 }
00118
00119 void alarmd_action_run(AlarmdAction *action, gboolean delayed)
00120 {
00121 ENTER_FUNC;
00122 g_signal_emit(action, action_signals[SIGNAL_RUN], 0, delayed);
00123 LEAVE_FUNC;
00124 }
00125
00126 static void alarmd_action_init(AlarmdAction *action)
00127 {
00128 ENTER_FUNC;
00129 (void)action;
00130 LEAVE_FUNC;
00131 }
00132
00133 static void _alarmd_action_set_property(GObject *object,
00134 guint param_id,
00135 const GValue *value,
00136 GParamSpec *pspec)
00137 {
00138 AlarmdActionPrivate *priv = ALARMD_ACTION_GET_PRIVATE(object);
00139 ENTER_FUNC;
00140 switch (param_id) {
00141 case PROP_EVENT:
00142 if (priv->event) {
00143 g_object_remove_weak_pointer(G_OBJECT(priv->event),
00144 (gpointer *)&priv->event);
00145 }
00146 priv->event = g_value_get_object(value);
00147 if (priv->event) {
00148 g_object_add_weak_pointer(G_OBJECT(priv->event),
00149 (gpointer *)&priv->event);
00150 }
00151 break;
00152 case PROP_FLAGS:
00153 if (priv->flags & ALARM_EVENT_SHOW_ICON) {
00154 statusbar_hide_icon();
00155 }
00156 priv->flags = g_value_get_int(value);
00157 if (priv->flags & ALARM_EVENT_SHOW_ICON) {
00158 statusbar_show_icon();
00159 }
00160 break;
00161 default:
00162 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00163 LEAVE_FUNC;
00164 return;
00165 }
00166
00167 LEAVE_FUNC;
00168 }
00169
00170 static void _alarmd_action_get_property(GObject *object,
00171 guint param_id,
00172 GValue *value,
00173 GParamSpec *pspec)
00174 {
00175 AlarmdActionPrivate *priv = ALARMD_ACTION_GET_PRIVATE(object);
00176 ENTER_FUNC;
00177 switch (param_id) {
00178 case PROP_EVENT:
00179 g_value_set_object(value, priv->event);
00180 break;
00181 case PROP_FLAGS:
00182 g_value_set_int(value, priv->flags);
00183 break;
00184 default:
00185 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00186 }
00187 LEAVE_FUNC;
00188 }
00189
00190 static void _alarmd_action_finalize(GObject *object)
00191 {
00192 AlarmdActionPrivate *priv = ALARMD_ACTION_GET_PRIVATE(object);
00193 ENTER_FUNC;
00194 if (priv->flags & ALARM_EVENT_SHOW_ICON) {
00195 statusbar_hide_icon();
00196 }
00197 if (priv->event) {
00198 g_object_remove_weak_pointer(G_OBJECT(priv->event),
00199 (gpointer *)&priv->event);
00200 }
00201 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_ACTION)))->finalize(object);
00202 LEAVE_FUNC;
00203
00204 }
00205
00206 static void alarmd_action_class_init(AlarmdActionClass *klass)
00207 {
00208 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
00209 AlarmdObjectClass *aobject_class = ALARMD_OBJECT_CLASS(klass);
00210 ENTER_FUNC;
00211
00212 g_type_class_add_private(klass, sizeof(AlarmdActionPrivate));
00213
00214 gobject_class->set_property = _alarmd_action_set_property;
00215 gobject_class->get_property = _alarmd_action_get_property;
00216 gobject_class->finalize = _alarmd_action_finalize;
00217
00218 aobject_class->get_saved_properties = _alarmd_action_get_saved_properties;
00219
00220 klass->run = _alarmd_action_real_run;
00221 klass->need_power_up = _alarmd_action_real_need_power_up;
00222 klass->acknowledge = _alarmd_action_real_acknowledge;
00223
00224
00225
00226
00227
00228
00229 action_signals[SIGNAL_RUN] = g_signal_new("run",
00230 G_TYPE_FROM_CLASS(gobject_class),
00231 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
00232 G_STRUCT_OFFSET(AlarmdActionClass, run),
00233 NULL, NULL,
00234 g_cclosure_marshal_VOID__BOOLEAN,
00235 G_TYPE_NONE, 1,
00236 G_TYPE_BOOLEAN);
00237 action_signals[SIGNAL_ACKNOWLEDGE] = g_signal_new("acknowledge",
00238 G_TYPE_FROM_CLASS(gobject_class),
00239 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
00240 G_STRUCT_OFFSET(AlarmdActionClass, acknowledge),
00241 NULL, NULL,
00242 g_cclosure_marshal_VOID__UINT,
00243 G_TYPE_NONE, 1,
00244 G_TYPE_UINT);
00245
00246 g_object_class_install_property(gobject_class,
00247 PROP_EVENT,
00248 g_param_spec_object("event",
00249 "Event of the action.",
00250 "Event of the action.",
00251 ALARMD_TYPE_EVENT,
00252 G_PARAM_READABLE | G_PARAM_WRITABLE));
00253 g_object_class_install_property(gobject_class,
00254 PROP_FLAGS,
00255 g_param_spec_int("flags",
00256 "Flags of the action.",
00257 "Flags of the action.",
00258 G_MININT32,
00259 G_MAXINT32,
00260 0,
00261 G_PARAM_READABLE | G_PARAM_WRITABLE));
00262
00263 LEAVE_FUNC;
00264 }
00265
00266 static void _alarmd_action_real_run(AlarmdAction *action, gboolean delayed)
00267 {
00268 ENTER_FUNC;
00269 (void)delayed;
00270 alarmd_action_acknowledge(action, ACK_NORMAL);
00271 LEAVE_FUNC;
00272 }
00273
00274 void alarmd_action_acknowledge(AlarmdAction *action, guint ack_type)
00275 {
00276 ENTER_FUNC;
00277 g_signal_emit(ALARMD_OBJECT(action), action_signals[SIGNAL_ACKNOWLEDGE], 0, ack_type);
00278 LEAVE_FUNC;
00279 }
00280
00281 gboolean alarmd_action_need_power_up(AlarmdAction *action)
00282 {
00283 AlarmdActionClass *klass = ALARMD_ACTION_GET_CLASS(action);
00284 gboolean retval;
00285 ENTER_FUNC;
00286 retval = klass->need_power_up(action);
00287 LEAVE_FUNC;
00288 return retval;
00289 }
00290
00291 static gboolean _alarmd_action_real_need_power_up(AlarmdAction *action)
00292 {
00293 AlarmdActionPrivate *priv = ALARMD_ACTION_GET_PRIVATE(action);
00294 ENTER_FUNC;
00295 DEBUG("Need: %s", priv->flags & ALARM_EVENT_BOOT ? "true" : "false");
00296 LEAVE_FUNC;
00297 return priv->flags & ALARM_EVENT_BOOT ? TRUE : FALSE;
00298 }
00299
00300 static void _alarmd_action_real_acknowledge(AlarmdAction *action,
00301 AlarmdActionAckType ack_type)
00302 {
00303 ENTER_FUNC;
00304 (void)action;
00305 (void)ack_type;
00306
00307 update_mce_alarm_visibility();
00308 LEAVE_FUNC;
00309 }
00310
00311 static GSList *_alarmd_action_get_saved_properties(void)
00312 {
00313 guint i;
00314 GSList *retval = NULL;
00315 ENTER_FUNC;
00316 retval = ALARMD_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_ACTION)))->get_saved_properties();
00317 for (i = 0; i < S_COUNT; i++) {
00318 retval = g_slist_append(retval, (gpointer)saved_properties[i]);
00319 }
00320 LEAVE_FUNC;
00321 return retval;
00322 }
00323