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

actiondbus.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 "actiondbus.h"
00030 #include "rpc-dbus.h"
00031 #include "rpc-systemui.h"
00032 #include "debug.h"
00033 
00034 static void alarmd_action_dbus_init(AlarmdActionDbus *action_dbus);
00035 static void alarmd_action_dbus_class_init(AlarmdActionDbusClass *klass);
00036 static void _alarmd_action_dbus_set_property(GObject *object,
00037                 guint param_id,
00038                 const GValue *value,
00039                 GParamSpec *pspec);
00040 static void _alarmd_action_dbus_get_property(GObject *object,
00041                 guint param_id,
00042                 GValue *value,
00043                 GParamSpec *pspec);
00044 static void _alarmd_action_dbus_do_action(AlarmdActionDialog *action);
00045 static void _alarmd_action_dbus_finalize(GObject *object);
00046 static GSList *_alarmd_action_dbus_get_saved_properties(void);
00047 
00048 enum properties {
00049         PROP_INTERFACE = 1,
00050         PROP_SERVICE,
00051         PROP_PATH,
00052         PROP_NAME,
00053 };
00054 
00055 enum saved_props {
00056         S_INTERFACE,
00057         S_SERVICE,
00058         S_PATH,
00059         S_NAME,
00060         S_COUNT
00061 };
00062 
00063 static const gchar * const saved_properties[S_COUNT] = {
00064         "interface",
00065         "service",
00066         "path",
00067         "name"
00068 };
00069 
00070 typedef struct _AlarmdActionDbusPrivate AlarmdActionDbusPrivate;
00071 struct _AlarmdActionDbusPrivate {
00072         gchar *interface;
00073         gchar *service;
00074         gchar *path;
00075         gchar *name;
00076 };
00077 
00078 #define ALARMD_ACTION_DBUS_GET_PRIVATE(obj) \
00079 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
00080                               ALARMD_TYPE_ACTION_DBUS, AlarmdActionDbusPrivate));
00081 
00082 GType alarmd_action_dbus_get_type(void)
00083 {
00084         static GType action_dbus_type = 0;
00085 
00086         if (!action_dbus_type)
00087         {
00088                 static const GTypeInfo action_dbus_info =
00089                 {
00090                         sizeof (AlarmdActionDbusClass),
00091                         NULL,
00092                         NULL,
00093                         (GClassInitFunc) alarmd_action_dbus_class_init,
00094                         NULL,
00095                         NULL,
00096                         sizeof (AlarmdActionDbus),
00097                         0,
00098                         (GInstanceInitFunc) alarmd_action_dbus_init,
00099                         NULL
00100                 };
00101 
00102                 action_dbus_type = g_type_register_static(ALARMD_TYPE_ACTION_DIALOG,
00103                                 "AlarmdActionDbus",
00104                                 &action_dbus_info, 0);
00105         }
00106 
00107         return action_dbus_type;
00108 }
00109 
00110 static void alarmd_action_dbus_class_init(AlarmdActionDbusClass *klass)
00111 {
00112         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
00113         AlarmdObjectClass *aobject_class = ALARMD_OBJECT_CLASS(klass);
00114         AlarmdActionDialogClass *actiond_class = ALARMD_ACTION_DIALOG_CLASS(klass);
00115 
00116         ENTER_FUNC;
00117         g_type_class_add_private(klass, sizeof(AlarmdActionDbusPrivate));
00118 
00119         gobject_class->set_property = _alarmd_action_dbus_set_property;
00120         gobject_class->get_property = _alarmd_action_dbus_get_property;
00121         gobject_class->finalize = _alarmd_action_dbus_finalize;
00122         aobject_class->get_saved_properties = _alarmd_action_dbus_get_saved_properties;
00123         
00124         actiond_class->do_action = _alarmd_action_dbus_do_action;
00125 
00126         g_object_class_install_property(gobject_class,
00127                         PROP_INTERFACE,
00128                         g_param_spec_string("interface",
00129                                 "Interface for the dbus call.",
00130                                 "Interface the method/signal should be sent to/from.",
00131                                 NULL,
00132                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00133         g_object_class_install_property(gobject_class,
00134                         PROP_SERVICE,
00135                         g_param_spec_string("service",
00136                                 "Service for the dbus call.",
00137                                 "Service the method should be sent to.",
00138                                 NULL,
00139                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00140         g_object_class_install_property(gobject_class,
00141                         PROP_PATH,
00142                         g_param_spec_string("path",
00143                                 "Path for the dbus call.",
00144                                 "Path of the method/signal.",
00145                                 NULL,
00146                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00147         g_object_class_install_property(gobject_class,
00148                         PROP_NAME,
00149                         g_param_spec_string("name",
00150                                 "Name for the dbus call.",
00151                                 "Name of the method/signal.",
00152                                 NULL,
00153                                 G_PARAM_READABLE | G_PARAM_WRITABLE));
00154         LEAVE_FUNC;
00155 }
00156 
00157 static void alarmd_action_dbus_init(AlarmdActionDbus *action_dbus)
00158 {
00159         AlarmdActionDbusPrivate *priv = ALARMD_ACTION_DBUS_GET_PRIVATE(action_dbus);
00160         ENTER_FUNC;
00161 
00162         priv->interface = NULL;
00163         priv->service = NULL;
00164         priv->path = NULL;
00165         priv->name = NULL;
00166         LEAVE_FUNC;
00167 }
00168 
00169 static void _alarmd_action_dbus_set_property(GObject *object,
00170                 guint param_id,
00171                 const GValue *value,
00172                 GParamSpec *pspec)
00173 {
00174         AlarmdActionDbusPrivate *priv = ALARMD_ACTION_DBUS_GET_PRIVATE(object);
00175         ENTER_FUNC;
00176 
00177         switch (param_id) {
00178         case PROP_INTERFACE:
00179                 if (priv->interface) {
00180                         g_free(priv->interface);
00181                 }
00182                 priv->interface = g_strdup(g_value_get_string(value));
00183                 break;
00184         case PROP_SERVICE:
00185                 if (priv->service) {
00186                         g_free(priv->service);
00187                 }
00188                 priv->service = g_strdup(g_value_get_string(value));
00189                 break;
00190         case PROP_PATH:
00191                 if (priv->path) {
00192                         g_free(priv->path);
00193                 }
00194                 priv->path = g_strdup(g_value_get_string(value));
00195                 break;
00196         case PROP_NAME:
00197                 if (priv->name) {
00198                         g_free(priv->name);
00199                 }
00200                 priv->name = g_strdup(g_value_get_string(value));
00201                 break;
00202         default:
00203                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00204                 LEAVE_FUNC;
00205                 return;
00206         }
00207         alarmd_object_changed(ALARMD_OBJECT(object));
00208         LEAVE_FUNC;
00209 }
00210 
00211 static void _alarmd_action_dbus_get_property(GObject *object,
00212                 guint param_id,
00213                 GValue *value,
00214                 GParamSpec *pspec)
00215 {
00216         AlarmdActionDbusPrivate *priv = ALARMD_ACTION_DBUS_GET_PRIVATE(object);
00217         ENTER_FUNC;
00218 
00219         switch (param_id) {
00220         case PROP_INTERFACE:
00221                 g_value_set_string(value, priv->interface);
00222                 break;
00223         case PROP_SERVICE:
00224                 g_value_set_string(value, priv->service);
00225                 break;
00226         case PROP_PATH:
00227                 g_value_set_string(value, priv->path);
00228                 break;
00229         case PROP_NAME:
00230                 g_value_set_string(value, priv->name);
00231                 break;
00232         default:
00233                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00234         }
00235         LEAVE_FUNC;
00236 }
00237 
00238 static void _alarmd_action_dbus_finalize(GObject *object)
00239 {
00240         AlarmdActionDbusPrivate *priv = ALARMD_ACTION_DBUS_GET_PRIVATE(object);
00241         ENTER_FUNC;
00242 
00243         if (priv->interface != NULL) {
00244                 g_free(priv->interface);
00245         }
00246         if (priv->service != NULL) {
00247                 g_free(priv->service);
00248         }
00249         if (priv->path != NULL) {
00250                 g_free(priv->path);
00251         }
00252         if (priv->name != NULL) {
00253                 g_free(priv->name);
00254         }
00255 
00256         G_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_ACTION_DBUS)))->finalize(object);
00257         LEAVE_FUNC;
00258 }
00259 
00260 static void _alarmd_action_dbus_do_action(AlarmdActionDialog *action)
00261 {
00262         AlarmdActionDbusPrivate *priv = ALARMD_ACTION_DBUS_GET_PRIVATE(action);
00263         DBusConnection *conn;
00264         guint flags;
00265 
00266         ENTER_FUNC;
00267 
00268         g_object_get(action, "flags", &flags, NULL);
00269         conn = get_dbus_connection(((flags & ALARM_EVENT_SYSTEM) ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION));
00270         if (conn != NULL) {
00271                 DLOG_DEBUG("Sending DBus message to %s\n", priv->path);
00272                 dbus_do_call(conn, NULL, (flags & ALARM_EVENT_ACTIVATION), priv->service, priv->path, priv->interface, priv->name, DBUS_TYPE_INVALID);
00273                 dbus_connection_unref(conn);
00274         } else {
00275                 DLOG_WARN("Could not get DBus bus for sending message.");
00276         }
00277         alarmd_action_acknowledge(ALARMD_ACTION(action), ACK_NORMAL);
00278 
00279         LEAVE_FUNC;
00280 }
00281 
00282 static GSList *_alarmd_action_dbus_get_saved_properties(void)
00283 {
00284         guint i;
00285         GSList *retval = NULL;
00286         ENTER_FUNC;
00287         retval = ALARMD_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_ACTION_DBUS)))->get_saved_properties();
00288         for (i = 0; i < S_COUNT; i++) {
00289                 retval = g_slist_append(retval, (gpointer)saved_properties[i]);
00290         }
00291         LEAVE_FUNC;
00292         return retval;
00293 }

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