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

dbusobjectfactory.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 <glib-object.h>
00024 #include "dbusobjectfactory.h"
00025 #include "object.h"
00026 #include "debug.h"
00027 
00028 GObject *dbus_object_factory(DBusMessageIter *iter)
00029 {
00030         const gchar *type_name = NULL;
00031         guint n_params = 0;
00032         guint i = 0;
00033         GParameter *params = NULL;
00034         GObject *retval = NULL;
00035         GType object_type = 0;
00036 
00037         ENTER_FUNC;
00038 
00039         if (iter == NULL || dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH) {
00040                 LEAVE_FUNC;
00041                 return NULL;
00042         }
00043 
00044         dbus_message_iter_get_basic(iter, &type_name);
00045 
00046         if (type_name == NULL || *type_name == '\0') {
00047                 LEAVE_FUNC;
00048                 return NULL;
00049         }
00050         object_type = g_type_from_name(type_name + 1);
00051 
00052         if (!dbus_message_iter_next(iter) ||
00053                         dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32) {
00054                 LEAVE_FUNC;
00055                 return NULL;
00056         }
00057 
00058         dbus_message_iter_get_basic(iter, &n_params);
00059 
00060         params = g_new0(GParameter, n_params);
00061 
00062         for (i = 0; i < n_params; i++) {
00063                 if (!dbus_message_iter_next(iter)) {
00064                         DEBUG("Ran out of parameters1.");
00065                         break;
00066                 }
00067                 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
00068                         dbus_message_iter_get_basic(iter, &params[i].name);
00069                         DEBUG("Parameter '%s'", params[i].name);
00070                 } else {
00071                         DEBUG("Wrong parameter type.");
00072                         break;
00073                 }
00074                 if (!dbus_message_iter_next(iter)) {
00075                         DEBUG("Ran out of parameters2.");
00076                         break;
00077                 }
00078                 switch (dbus_message_iter_get_arg_type(iter)) {
00079                 case DBUS_TYPE_BYTE:
00080                         {
00081                                 gchar value;
00082                                 g_value_init(&params[i].value, G_TYPE_CHAR);
00083                                 dbus_message_iter_get_basic(iter, &value);
00084                                 g_value_set_char(&params[i].value, value);
00085                                 break;
00086                         }
00087                 case DBUS_TYPE_BOOLEAN:
00088                         {
00089                                 dbus_bool_t value;
00090                                 g_value_init(&params[i].value, G_TYPE_BOOLEAN);
00091                                 dbus_message_iter_get_basic(iter, &value);
00092                                 g_value_set_boolean(&params[i].value, value);
00093                                 break;
00094                         }
00095                 case DBUS_TYPE_INT16:
00096                         {
00097                                 dbus_int16_t value;
00098                                 g_value_init(&params[i].value, G_TYPE_INT);
00099                                 dbus_message_iter_get_basic(iter, &value);
00100                                 g_value_set_int(&params[i].value, value);
00101                                 break;
00102                         }
00103                 case DBUS_TYPE_UINT16:
00104                         {
00105                                 dbus_uint16_t value;
00106                                 g_value_init(&params[i].value, G_TYPE_UINT);
00107                                 dbus_message_iter_get_basic(iter, &value);
00108                                 g_value_set_uint(&params[i].value, value);
00109                                 break;
00110                         }
00111                 case DBUS_TYPE_INT32:
00112                         {
00113                                 dbus_int32_t value;
00114                                 g_value_init(&params[i].value, G_TYPE_INT);
00115                                 dbus_message_iter_get_basic(iter, &value);
00116                                 g_value_set_int(&params[i].value, value);
00117                                 break;
00118                         }
00119                 case DBUS_TYPE_UINT32:
00120                         {
00121                                 dbus_uint32_t value;
00122                                 g_value_init(&params[i].value, G_TYPE_UINT);
00123                                 dbus_message_iter_get_basic(iter, &value);
00124                                 g_value_set_uint(&params[i].value, value);
00125                                 break;
00126                         }
00127 #ifdef DBUS_HAVE_INT64
00128                 case DBUS_TYPE_INT64:
00129                         {
00130                                 dbus_int64_t value;
00131                                 g_value_init(&params[i].value, G_TYPE_INT64);
00132                                 dbus_message_iter_get_basic(iter, &value);
00133                                 g_value_set_int64(&params[i].value, value);
00134                                 break;
00135                         }
00136                 case DBUS_TYPE_UINT64:
00137                         {
00138                                 dbus_uint64_t value;
00139                                 g_value_init(&params[i].value, G_TYPE_UINT64);
00140                                 dbus_message_iter_get_basic(iter, &value);
00141                                 g_value_set_uint64(&params[i].value, value);
00142                                 break;
00143                         }
00144 #endif
00145                 case DBUS_TYPE_DOUBLE:
00146                         {
00147                                 double value;
00148                                 g_value_init(&params[i].value, G_TYPE_DOUBLE);
00149                                 dbus_message_iter_get_basic(iter, &value);
00150                                 g_value_set_double(&params[i].value, value);
00151                                 break;
00152                         }
00153                 case DBUS_TYPE_STRING:
00154                         {
00155                                 gchar *value = NULL;
00156                                 g_value_init(&params[i].value, G_TYPE_STRING);
00157                                 dbus_message_iter_get_basic(iter, &value);
00158                                 g_value_set_string(&params[i].value, value);
00159                                 break;
00160                         }
00161                 case DBUS_TYPE_OBJECT_PATH:
00162                         {
00163                                 GObject *value = dbus_object_factory(iter);
00164                                 g_value_init(&params[i].value, G_TYPE_OBJECT);
00165                                 g_value_set_object(&params[i].value, value);
00166                                 if (value) {
00167                                         g_object_unref(value);
00168                                 }
00169                                 break;
00170                         }
00171                 default:
00172                         DEBUG("Unsupported type.");
00173                         break;
00174                 }
00175         }
00176 
00177         if (i == n_params) {
00178                 retval = g_object_newv(object_type, n_params, params);
00179         }
00180         alarmd_gparameterv_free(params, n_params);
00181         LEAVE_FUNC;
00182         return retval;
00183 }

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