00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00043 #include <stdlib.h>
00044 #include <string.h>
00045
00046 #include "easydbus-core.h"
00047 #include "debug.h"
00048 #include "dict_entry_internal.h"
00049 #include "variant_internal.h"
00050 #include "elem_internal.h"
00051 #include "utils.h"
00052
00063 struct EasyDbus_container *
00064 easydbus_dict_entry_build_container (enum event_type type,
00065 void *container,
00066 DBusMessageIter * iter)
00067 {
00068 struct EasyDbus_container *dict_entry = NULL;
00069 struct EasyDbus_container *variant = NULL;
00070 DBusMessageIter subiter;
00071 int i32 = 0, i = 0;
00072 unsigned int ui32 = 0;
00073 short i16 = 0;
00074 char byte = 0;
00075 char *string = NULL;
00076 unsigned short ui16 = 0;
00077 long long i64 = 0;
00078 double d = 0;
00079 unsigned long long ui64 = 0;
00080
00081 #ifdef EASYDBUS_DEBUG
00082 char *signature = NULL;
00083 #endif
00084
00085 if (container == NULL || iter == NULL)
00086 return NULL;
00087
00088 dict_entry =
00089 easydbus_container_create_skeleton (EASYDBUS_ELTYPE_DICT_ENTRY);
00090
00091 if (dict_entry == NULL)
00092 return NULL;
00093
00094
00095
00096
00097 memset (&subiter, 0, sizeof (DBusMessageIter));
00098
00099 dbus_message_iter_recurse (iter, &subiter);
00100
00101 #ifdef EASYDBUS_DEBUG
00102 signature = dbus_message_iter_get_signature (&subiter);
00103 EasyDbusDebug ("Current Signature = %s", signature);
00104 dbus_free (signature);
00105 #endif
00106
00107 for (i = 0; i < 2; i++) {
00108 switch (dbus_message_iter_get_arg_type (&subiter)) {
00109 case DBUS_TYPE_STRING:
00110 dbus_message_iter_get_basic (&subiter, &string);
00111 EasyDbusDebug ("founded string = %s\n", string);
00112 easydbus_dict_entry_add_string (dict_entry, string);
00113 break;
00114 case DBUS_TYPE_INT32:
00115 dbus_message_iter_get_basic (&subiter, &i32);
00116 EasyDbusDebug ("founded int32 = %d", i32);
00117 easydbus_dict_entry_add_i32 (dict_entry, i32);
00118 break;
00119 case DBUS_TYPE_UINT32:
00120 dbus_message_iter_get_basic (&subiter, &ui32);
00121 EasyDbusDebug ("founded uint32 = %d", ui32);
00122 easydbus_dict_entry_add_ui32 (dict_entry, ui32);
00123 break;
00124 case DBUS_TYPE_INT16:
00125 dbus_message_iter_get_basic (&subiter, &i16);
00126 EasyDbusDebug ("founded int16 = %d", i16);
00127 easydbus_dict_entry_add_i16 (dict_entry, i16);
00128 break;
00129 case DBUS_TYPE_UINT16:
00130 dbus_message_iter_get_basic (&subiter, &ui16);
00131 EasyDbusDebug ("founded uint16 = %d", ui16);
00132 easydbus_dict_entry_add_ui16 (dict_entry, ui16);
00133 break;
00134 case DBUS_TYPE_INT64:
00135 dbus_message_iter_get_basic (&subiter, &i64);
00136 EasyDbusDebug ("founded int64 = %lld", i64);
00137 easydbus_dict_entry_add_i64 (dict_entry, i64);
00138 break;
00139 case DBUS_TYPE_UINT64:
00140 dbus_message_iter_get_basic (&subiter, &ui64);
00141 EasyDbusDebug ("founded uint64 = %lld", ui64);
00142 easydbus_dict_entry_add_ui64 (dict_entry, ui64);
00143 break;
00144 case DBUS_TYPE_BYTE:
00145 dbus_message_iter_get_basic (&subiter, &byte);
00146 EasyDbusDebug ("founded byte = %d", byte);
00147 easydbus_dict_entry_add_byte (dict_entry, byte);
00148 break;
00149 case DBUS_TYPE_BOOLEAN:
00150 dbus_message_iter_get_basic (&subiter, &byte);
00151 EasyDbusDebug ("founded boolean = %d", byte);
00152 easydbus_dict_entry_add_boolean (dict_entry, byte);
00153 break;
00154 case DBUS_TYPE_DOUBLE:
00155 dbus_message_iter_get_basic (&subiter, &d);
00156 EasyDbusDebug ("founded double = %f", d);
00157 easydbus_dict_entry_add_double (dict_entry, d);
00158 break;
00159 case DBUS_TYPE_OBJECT_PATH:
00160 dbus_message_iter_get_basic (&subiter, &string);
00161 EasyDbusDebug ("founded obj_path = %s\n", string);
00162 easydbus_dict_entry_add_obj_path (dict_entry, string);
00163 break;
00164 case DBUS_TYPE_SIGNATURE:
00165 dbus_message_iter_get_basic (&subiter, &string);
00166 EasyDbusDebug ("founded signature = %s\n", string);
00167 easydbus_dict_entry_add_signature (dict_entry, string);
00168 break;
00169 case DBUS_TYPE_VARIANT:
00170 variant = easydbus_variant_build_elem
00171 (type, (void *) container, &subiter);
00172 if (variant != NULL) {
00173 easydbus_dict_entry_add_variant (dict_entry, variant);
00174 EasyDbusDebug ("Added variant to container");
00175 }
00176 else
00177 EasyDbusDebug ("Error on add variant to container");
00178 break;
00179 default:
00180 goto error;
00181 break;
00182 }
00183 dbus_message_iter_next (&subiter);
00184 }
00185
00186 return dict_entry;
00187
00188 error:
00189 if (dict_entry != NULL)
00190 easydbus_container_free (dict_entry);
00191 return NULL;
00192 }
00193
00205 int
00206 easydbus_add_dict_entry_tomsg (DBusMessage * msg,
00207 DBusMessageIter * iter,
00208 struct EasyDbus_elem *el)
00209 {
00210 int i;
00211 DBusMessageIter iter2;
00212 struct EasyDbus_elem *dict_entry = NULL;
00213
00214 int ret_val = 0;
00215
00224 dbus_message_iter_open_container (iter,
00225 DBUS_TYPE_DICT_ENTRY, NULL,
00226
00227 &iter2);
00228 dict_entry = (struct EasyDbus_elem *)
00229 el->payload.p_container->p_data;
00230
00231 for (i = 0; i < 2; i++) {
00232 switch (dict_entry->type) {
00233 case EASYDBUS_ELTYPE_STRING:
00234 dbus_message_iter_append_basic (&iter2,
00235 DBUS_TYPE_STRING,
00236 &dict_entry->payload.
00237 string);
00238 break;
00239 case EASYDBUS_ELTYPE_BYTE:
00240 dbus_message_iter_append_basic (&iter2,
00241 DBUS_TYPE_BYTE,
00242 &dict_entry->payload.
00243 byte);
00244 break;
00245 case EASYDBUS_ELTYPE_BOOLEAN:
00246 dbus_message_iter_append_basic (&iter2,
00247 DBUS_TYPE_BOOLEAN,
00248 &dict_entry->payload.
00249 boolean);
00250 break;
00251 case EASYDBUS_ELTYPE_DOUBLE:
00252 dbus_message_iter_append_basic (&iter2,
00253 DBUS_TYPE_DOUBLE,
00254 &dict_entry->payload.
00255 Double);
00256 break;
00257 case EASYDBUS_ELTYPE_INT16:
00258 dbus_message_iter_append_basic (&iter2,
00259 DBUS_TYPE_INT16,
00260 &dict_entry->payload.i16);
00261 break;
00262 case EASYDBUS_ELTYPE_UINT16:
00263 dbus_message_iter_append_basic (&iter2,
00264 DBUS_TYPE_UINT16,
00265 &dict_entry->payload.
00266 ui16);
00267 break;
00268 case EASYDBUS_ELTYPE_INT32:
00269 dbus_message_iter_append_basic (&iter2,
00270 DBUS_TYPE_INT32,
00271 &dict_entry->payload.i32);
00272 break;
00273 case EASYDBUS_ELTYPE_UINT32:
00274 dbus_message_iter_append_basic (&iter2,
00275 DBUS_TYPE_UINT32,
00276 &dict_entry->payload.
00277 ui32);
00278 break;
00279 case EASYDBUS_ELTYPE_INT64:
00280 dbus_message_iter_append_basic (&iter2,
00281 DBUS_TYPE_INT64,
00282 &dict_entry->payload.i64);
00283 break;
00284 case EASYDBUS_ELTYPE_UINT64:
00285 dbus_message_iter_append_basic (&iter2,
00286 DBUS_TYPE_UINT64,
00287 &dict_entry->payload.
00288 ui64);
00289 break;
00290 case EASYDBUS_ELTYPE_OBJECT_PATH:
00291 dbus_message_iter_append_basic (&iter2,
00292 DBUS_TYPE_OBJECT_PATH,
00293 &dict_entry->payload.
00294 string);
00295 break;
00296 case EASYDBUS_ELTYPE_SIGNATURE:
00297 dbus_message_iter_append_basic (&iter2,
00298 DBUS_TYPE_SIGNATURE,
00299 &dict_entry->payload.
00300 string);
00301 break;
00302 case EASYDBUS_ELTYPE_VARIANT:
00303 if (add_variant_to_container_on_msg
00304 (msg, dict_entry, &iter2)) {
00305 ret_val = -1;
00306 goto end;
00307 }
00308 break;
00309 default:
00310 EasyDbusDebug ("Element not managed!");
00311 ret_val = -1;
00312 goto end;
00313 break;
00314 }
00315 dict_entry = dict_entry->next;
00316 }
00317 end:
00318 dbus_message_iter_close_container (iter, &iter2);
00319
00320 return ret_val;
00321 }
00322