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

rpc-osso.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 <dbus/dbus.h>
00023 #include <libosso.h>
00024 #include <osso-log.h>
00025 #include "include/alarm_dbus.h"
00026 #include "dbusobjectfactory.h"
00027 #include "rpc-osso.h"
00028 #include "rpc-systemui.h"
00029 #include "queue.h"
00030 #include "event.h"
00031 #include "debug.h"
00032 
00033 static gint _bogus_rpc_f(const gchar *interface, const gchar *method,
00034         GArray *arguments, gpointer data,
00035         osso_rpc_t *retval);
00036 static void _osso_time_changed(gpointer data);
00037 static DBusHandlerResult _dbus_message_in(DBusConnection *connection,
00038                 DBusMessage *message,
00039                 void *user_data);
00040 static void _osso_hw_cb(osso_hw_state_t *state, gpointer data);
00041 
00042 osso_context_t *init_osso()
00043 {
00044         osso_context_t *retval = NULL;
00045         
00046         ENTER_FUNC;
00047         retval = osso_initialize(PACKAGE, VERSION, FALSE, NULL);
00048         
00049         if (!retval) {
00050                 DLOG_ERR("OSSO initialization failed.");
00051         }
00052         LEAVE_FUNC;
00053 
00054         return retval;
00055 }
00056 
00057 void set_osso_callbacks(osso_context_t *osso, AlarmdQueue *queue)
00058 {
00059         DBusConnection *bus = NULL;
00060         osso_hw_state_t state = { TRUE, FALSE, FALSE, FALSE, 0 };
00061         ENTER_FUNC;
00062         osso_rpc_set_default_cb_f(osso, _bogus_rpc_f, NULL);
00063         osso_time_set_notification_cb(osso, _osso_time_changed, queue);
00064         osso_hw_set_event_cb(osso, &state, _osso_hw_cb, NULL);
00065 
00066         bus = osso_get_dbus_connection(osso);
00067         g_object_ref(queue);
00068         dbus_connection_add_filter(bus, _dbus_message_in, queue, g_object_unref);
00069         bus = osso_get_sys_dbus_connection(osso);
00070         g_object_ref(queue);
00071         dbus_connection_add_filter(bus, _dbus_message_in, queue, g_object_unref);
00072         LEAVE_FUNC;
00073 }
00074 
00075 void deinit_osso(osso_context_t *osso, AlarmdQueue *queue)
00076 {
00077         DBusConnection *bus = NULL;
00078         ENTER_FUNC;
00079         bus = osso_get_dbus_connection(osso);
00080         dbus_connection_remove_filter(bus, _dbus_message_in, queue);
00081         bus = osso_get_sys_dbus_connection(osso);
00082         dbus_connection_remove_filter(bus, _dbus_message_in, queue);
00083         osso_deinitialize(osso);
00084         LEAVE_FUNC;
00085 }
00086 
00087 static gint _bogus_rpc_f(const gchar *interface, const gchar *method,
00088         GArray *arguments, gpointer data,
00089         osso_rpc_t *retval)
00090 {
00091         (void)interface;
00092         (void)method;
00093         (void)arguments;
00094         (void)data;
00095         (void)retval;
00096 
00097         return OSSO_INVALID;
00098 }
00099 
00100 static void _osso_time_changed(gpointer data)
00101 {
00102         ENTER_FUNC;
00103         DLOG_DEBUG("Time changed.");
00104         alarmd_object_time_changed(ALARMD_OBJECT(data));
00105         LEAVE_FUNC;
00106 }
00107 
00108 static DBusHandlerResult _dbus_message_in(DBusConnection *connection,
00109                 DBusMessage *message,
00110                 void *user_data)
00111 {
00112         ENTER_FUNC;
00113         if (dbus_message_is_method_call(message, ALARMD_INTERFACE, ALARM_EVENT_ADD)) {
00114                 DBusMessageIter iter;
00115                 GObject *new_obj;
00116                 glong retval = 0;
00117                 DLOG_DEBUG("Incoming %s request", ALARM_EVENT_ADD);
00118                 dbus_message_iter_init(message, &iter);
00119                 new_obj = dbus_object_factory(&iter);
00120                 if (new_obj) {
00121                         retval = alarmd_queue_add_event(ALARMD_QUEUE(user_data), ALARMD_EVENT(new_obj));
00122                         g_object_unref(new_obj);
00123                 } else {
00124                         DLOG_ERR("DBus parameters were not an object.");
00125                 }
00126                 if (!dbus_message_get_no_reply(message)) {
00127                         DBusMessage *reply =
00128                                 dbus_message_new_method_return(message);
00129                         if (reply) {
00130                                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &retval, DBUS_TYPE_INVALID);
00131                                 dbus_connection_send(connection, reply, NULL);
00132                                 dbus_message_unref(reply);
00133                         } else {
00134                                 DLOG_ERR("Could not create reply message.");
00135                         }
00136                 }
00137                 if (retval != 0) {
00138                         alarmd_object_changed(ALARMD_OBJECT(user_data));
00139                 }
00140                 LEAVE_FUNC;
00141                 return DBUS_HANDLER_RESULT_HANDLED;
00142         }
00143         if (dbus_message_is_method_call(message, ALARMD_INTERFACE, ALARM_EVENT_DEL)) {
00144                 dbus_int32_t event_id = 0;
00145                 gboolean status = FALSE;
00146                 DLOG_DEBUG("Incoming %s request", ALARM_EVENT_DEL);
00147                 dbus_message_get_args(message, NULL, DBUS_TYPE_INT32, &event_id, DBUS_TYPE_INVALID);
00148                 if (event_id) {
00149                         status = alarmd_queue_remove_event(ALARMD_QUEUE(user_data), (glong)event_id);
00150                 } else {
00151                         DLOG_WARN("Could not delete: no id supplied.");
00152                 }
00153                 if (!dbus_message_get_no_reply(message)) {
00154                         DBusMessage *reply = dbus_message_new_method_return(message);
00155                         if (reply) {
00156                                 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &status, DBUS_TYPE_INVALID);
00157                                 dbus_connection_send(connection, reply, NULL);
00158                                 dbus_message_unref(reply);
00159                         } else {
00160                                 DLOG_ERR("Could not create reply message.");
00161                         }
00162                 }
00163                 LEAVE_FUNC;
00164                 return DBUS_HANDLER_RESULT_HANDLED;
00165         }
00166         if (dbus_message_is_method_call(message, ALARMD_INTERFACE, ALARM_EVENT_QUERY)) {
00167                 dbus_uint64_t start_time = 0;
00168                 dbus_uint64_t end_time = 0;
00169                 gint32 flag_mask = 0;
00170                 gint32 flags = 0;
00171                 glong *status = FALSE;
00172                 guint n_params = 0;
00173                 DLOG_DEBUG("Incoming %s request", ALARM_EVENT_QUERY);
00174                 dbus_message_get_args(message, NULL, DBUS_TYPE_UINT64, &start_time, DBUS_TYPE_UINT64, &end_time, DBUS_TYPE_INT32, &flag_mask, DBUS_TYPE_INT32, &flags, DBUS_TYPE_INVALID);
00175                 DEBUG("start: %lld, end: %lld", start_time, end_time);
00176                 if (start_time < end_time) {
00177                         status = alarmd_queue_query_events(ALARMD_QUEUE(user_data), start_time, end_time, flag_mask, flags, &n_params);
00178                 } else {
00179                         DLOG_ERR("Could not query, invalid arguments.");
00180                 }
00181                 if (!dbus_message_get_no_reply(message)) {
00182                         DBusMessage *reply = dbus_message_new_method_return(message);
00183                         if (reply) {
00184                                 dbus_message_append_args(reply, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &status, n_params, DBUS_TYPE_INVALID);
00185                                 dbus_connection_send(connection, reply, NULL);
00186                                 dbus_message_unref(reply);
00187                         } else {
00188                                 DLOG_ERR("Could not create reply message.");
00189                         }
00190                 } else {
00191                         DLOG_WARN("Events queried but no reply wanted.");
00192                 }
00193                         
00194                 if (status) {
00195                         g_free(status);
00196                 }
00197                 LEAVE_FUNC;
00198                 return DBUS_HANDLER_RESULT_HANDLED;
00199         }
00200         if (dbus_message_is_method_call(message, ALARMD_INTERFACE, ALARM_EVENT_GET)) {
00201                 AlarmdEvent *event = NULL;
00202                 dbus_int32_t event_id = 0;
00203                 DLOG_DEBUG("Incoming %s request", ALARM_EVENT_GET);
00204                 dbus_message_get_args(message, NULL, DBUS_TYPE_INT32, &event_id, DBUS_TYPE_INVALID);
00205                 if (event_id) {
00206                         event = alarmd_queue_get_event(ALARMD_QUEUE(user_data), event_id);
00207                 } else {
00208                         DLOG_WARN("Could not get event: no id.");
00209                 }
00210                 if (!dbus_message_get_no_reply(message)) {
00211                         DBusMessage *reply =
00212                                 dbus_message_new_method_return(message);
00213                         if (reply) {
00214                                 if (event) {
00215                                         DBusMessageIter iter;
00216                                         dbus_message_iter_init_append(reply,
00217                                                         &iter);
00218                                         alarmd_object_to_dbus(
00219                                                         ALARMD_OBJECT(event),
00220                                                         &iter);
00221                                 }
00222                                 dbus_connection_send(connection, reply, NULL);
00223                                 dbus_message_unref(reply);
00224                         } else {
00225                                 DLOG_ERR("Could not create reply message.");
00226                         }
00227                 } else {
00228                         DLOG_WARN("Event queried but no reply wanted.");
00229                 }
00230                 LEAVE_FUNC;
00231                 return DBUS_HANDLER_RESULT_HANDLED;
00232         }
00233         if (dbus_message_is_method_call(message, ALARMD_INTERFACE, ALARMD_SNOOZE_GET)) {
00234                 dbus_uint32_t snooze = 0;
00235 
00236                 DLOG_DEBUG("Incoming %s request", ALARMD_SNOOZE_GET);
00237                 g_object_get(G_OBJECT(user_data), "snooze", &snooze, NULL);
00238                 if (!dbus_message_get_no_reply(message)) {
00239                         DBusMessage *reply =
00240                                 dbus_message_new_method_return(message);
00241 
00242                         if (reply) {
00243                                 dbus_message_append_args(reply,
00244                                                 DBUS_TYPE_UINT32, &snooze,
00245                                                 DBUS_TYPE_INVALID);
00246                                 dbus_connection_send(connection, reply, NULL);
00247                                 dbus_message_unref(reply);
00248                         } else {
00249                                 DLOG_ERR("Could not create reply message.");
00250                         }
00251                 } else {
00252                         DLOG_WARN("Snooze queried but no reply wanted.");
00253                 }
00254                 LEAVE_FUNC;
00255                 return DBUS_HANDLER_RESULT_HANDLED;
00256         }
00257         if (dbus_message_is_method_call(message, ALARMD_INTERFACE, ALARMD_SNOOZE_SET)) {
00258                 dbus_uint32_t snooze = 0;
00259 
00260                 DLOG_DEBUG("Incoming %s request", ALARMD_SNOOZE_SET);
00261                 dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &snooze, DBUS_TYPE_INVALID);
00262 
00263                 if (snooze) {
00264                         g_object_set(G_OBJECT(user_data), "snooze", snooze, NULL);
00265                 } else {
00266                         DLOG_WARN("Could not set snooze: no time specified.");
00267                 }
00268                 if (!dbus_message_get_no_reply(message)) {
00269                         DBusMessage *reply = dbus_message_new_method_return(message);
00270 
00271                         if (reply) {
00272                                 dbus_bool_t status = snooze != 0;
00273 
00274                                 dbus_message_append_args(reply,
00275                                                 DBUS_TYPE_BOOLEAN, &status,
00276                                                 DBUS_TYPE_INVALID);
00277                                 dbus_connection_send(connection, reply, NULL);
00278                                 dbus_message_unref(reply);
00279                         } else {
00280                                 DLOG_ERR("Could not create reply message.");
00281                         }
00282                 }
00283                 LEAVE_FUNC;
00284                 return DBUS_HANDLER_RESULT_HANDLED;
00285         }
00286         LEAVE_FUNC;
00287         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
00288 }
00289 
00290 static void _osso_hw_cb(osso_hw_state_t *state, gpointer data)
00291 {
00292         ENTER_FUNC;
00293         (void)data;
00294 
00295         if (state->shutdown_ind) {
00296                 DLOG_DEBUG("Shutdown indication -- closing all dialogs.");
00297                 systemui_ack_all_dialogs();
00298         }
00299 
00300         LEAVE_FUNC;
00301 }

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