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

actionexec.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-object.h>
00023 #include <glib.h>
00024 #include <dbus/dbus.h>
00025 #include <osso-log.h>
00026 
00027 #include "include/alarm_event.h"
00028 
00029 #include "actionexec.h"
00030 #include "rpc-dbus.h"
00031 #include "rpc-systemui.h"
00032 #include "debug.h"
00033 
00034 static void alarmd_action_exec_init(AlarmdActionExec *action_exec);
00035 static void alarmd_action_exec_class_init(AlarmdActionExecClass *klass);
00036 static void _alarmd_action_exec_set_property(GObject *object,
00037                 guint param_id,
00038                 const GValue *value,
00039                 GParamSpec *pspec);
00040 static void _alarmd_action_exec_get_property(GObject *object,
00041                 guint param_id,
00042                 GValue *value,
00043                 GParamSpec *pspec);
00044 static void _alarmd_action_exec_do_action(AlarmdActionDialog *action);
00045 static void _alarmd_action_exec_finished(GPid pid, gint status, gpointer user_data);
00046 static void _alarmd_action_exec_finalize(GObject *object);
00047 static GSList *_alarmd_action_exec_get_saved_properties(void);
00048 
00049 enum properties {
00050         PROP_PATH = 1,
00051 };
00052 
00053 enum saved_props {
00054         S_PATH,
00055         S_COUNT
00056 };
00057 
00058 static const gchar * const saved_properties[S_COUNT] = {
00059         "path"
00060 };
00061 
00062 typedef struct _AlarmdActionExecPrivate AlarmdActionExecPrivate;
00063 struct _AlarmdActionExecPrivate {
00064         gchar *path;
00065 };
00066 
00067 #define ALARMD_ACTION_EXEC_GET_PRIVATE(obj) \
00068 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
00069                               ALARMD_TYPE_ACTION_EXEC, AlarmdActionExecPrivate));
00070 
00071 GType alarmd_action_exec_get_type(void)
00072 {
00073         static GType action_exec_type = 0;
00074 
00075         if (!action_exec_type)
00076         {
00077                 static const GTypeInfo action_exec_info =
00078                 {
00079                         sizeof (AlarmdActionExecClass),
00080                         NULL,
00081                         NULL,
00082                         (GClassInitFunc) alarmd_action_exec_class_init,
00083                         NULL,
00084                         NULL,
00085                         sizeof (AlarmdActionExec),
00086                         0,
00087                         (GInstanceInitFunc) alarmd_action_exec_init,
00088                         NULL
00089                 };
00090 
00091                 action_exec_type = g_type_register_static(ALARMD_TYPE_ACTION_DIALOG,
00092                                 "AlarmdActionExec",
00093                                 &action_exec_info, 0);
00094         }
00095 
00096         return action_exec_type;
00097 }
00098 
00099 static void alarmd_action_exec_class_init(AlarmdActionExecClass *klass)
00100 {
00101         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
00102         AlarmdObjectClass *aobject_class = ALARMD_OBJECT_CLASS(klass);
00103         AlarmdActionDialogClass *actiond_class = ALARMD_ACTION_DIALOG_CLASS(klass);
00104 
00105         ENTER_FUNC;
00106         g_type_class_add_private(klass, sizeof(AlarmdActionExecPrivate));
00107 
00108         gobject_class->set_property = _alarmd_action_exec_set_property;
00109         gobject_class->get_property = _alarmd_action_exec_get_property;
00110         gobject_class->finalize = _alarmd_action_exec_finalize;
00111         aobject_class->get_saved_properties = _alarmd_action_exec_get_saved_properties;
00112         actiond_class->do_action = _alarmd_action_exec_do_action;
00113 
00114         g_object_class_install_property(gobject_class,
00115                         PROP_PATH,
00116                         g_param_spec_string("path",
00117                                 "Path for the dbus call.",
00118                                 "Path of the method/signal.",
00119                                 NULL,
00120                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00121 
00122         LEAVE_FUNC;
00123 }
00124 
00125 static void alarmd_action_exec_init(AlarmdActionExec *action_exec)
00126 {
00127         AlarmdActionExecPrivate *priv = ALARMD_ACTION_EXEC_GET_PRIVATE(action_exec);
00128         ENTER_FUNC;
00129 
00130         priv->path = NULL;
00131         LEAVE_FUNC;
00132 }
00133 
00134 static void _alarmd_action_exec_set_property(GObject *object,
00135                 guint param_id,
00136                 const GValue *value,
00137                 GParamSpec *pspec)
00138 {
00139         AlarmdActionExecPrivate *priv = ALARMD_ACTION_EXEC_GET_PRIVATE(object);
00140         ENTER_FUNC;
00141 
00142         switch (param_id) {
00143         case PROP_PATH:
00144                 if (priv->path) {
00145                         g_free(priv->path);
00146                 }
00147                 priv->path = g_strdup(g_value_get_string(value));
00148                 break;
00149         default:
00150                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00151                 LEAVE_FUNC;
00152                 return;
00153         }
00154         alarmd_object_changed(ALARMD_OBJECT(object));
00155         LEAVE_FUNC;
00156 }
00157 
00158 static void _alarmd_action_exec_get_property(GObject *object,
00159                 guint param_id,
00160                 GValue *value,
00161                 GParamSpec *pspec)
00162 {
00163         AlarmdActionExecPrivate *priv = ALARMD_ACTION_EXEC_GET_PRIVATE(object);
00164         ENTER_FUNC;
00165 
00166         switch (param_id) {
00167         case PROP_PATH:
00168                 g_value_set_string(value, priv->path);
00169                 break;
00170         default:
00171                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00172         }
00173         LEAVE_FUNC;
00174 }
00175 
00176 static void _alarmd_action_exec_finalize(GObject *object)
00177 {
00178         AlarmdActionExecPrivate *priv = ALARMD_ACTION_EXEC_GET_PRIVATE(object);
00179         ENTER_FUNC;
00180 
00181         if (priv->path != NULL) {
00182                 g_free(priv->path);
00183         }
00184         G_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_ACTION_EXEC)))->finalize(object);
00185         LEAVE_FUNC;
00186 }
00187 
00188 static void _alarmd_action_exec_do_action(AlarmdActionDialog *action)
00189 {
00190         AlarmdActionExecPrivate *priv = ALARMD_ACTION_EXEC_GET_PRIVATE(action);
00191         gchar **argv;
00192         gint argc;
00193         GPid pid;
00194 
00195         ENTER_FUNC;
00196         
00197         if (priv->path) {
00198                 g_shell_parse_argv(priv->path, &argc, &argv, NULL);
00199                 if (argv != NULL) {
00200                         DLOG_DEBUG("Running command %s", priv->path);
00201                         g_spawn_async(g_get_home_dir(),
00202                                         argv,
00203                                         NULL,
00204                                         G_SPAWN_SEARCH_PATH |
00205                                         G_SPAWN_DO_NOT_REAP_CHILD,
00206                                         NULL,
00207                                         NULL,
00208                                         &pid,
00209                                         NULL);
00210                         g_object_ref(action);
00211                         g_child_watch_add_full(G_PRIORITY_DEFAULT,
00212                                         pid,
00213                                         _alarmd_action_exec_finished,
00214                                         action,
00215                                         g_object_unref);
00216                         g_strfreev(argv);
00217                         argv = NULL;
00218                 } else {
00219                         DLOG_ERR("Could not parse command.");
00220                         _alarmd_action_exec_finished(0, 0, action);
00221                 }
00222         } else {
00223                 DLOG_ERR("No command to execute.");
00224                 _alarmd_action_exec_finished(0, 0, action);
00225         }
00226 
00227         LEAVE_FUNC;
00228 }
00229 
00230 static void _alarmd_action_exec_finished(GPid pid, gint status, gpointer user_data)
00231 {
00232         ENTER_FUNC;
00233         (void)pid;
00234         (void)status;
00235 
00236         alarmd_action_acknowledge(ALARMD_ACTION(user_data), ACK_NORMAL);
00237         LEAVE_FUNC;
00238 }
00239 
00240 static GSList *_alarmd_action_exec_get_saved_properties(void)
00241 {
00242         guint i;
00243         GSList *retval = NULL;
00244         ENTER_FUNC;
00245         retval = ALARMD_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_ACTION_EXEC)))->get_saved_properties();
00246         for (i = 0; i < S_COUNT; i++) {
00247                 retval = g_slist_append(retval, (gpointer)saved_properties[i]);
00248         }
00249         LEAVE_FUNC;
00250         return retval;
00251 }

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