summaryrefslogtreecommitdiff
path: root/src/lib/eldbus/eldbus_message_from_eina_value.c
diff options
context:
space:
mode:
authorGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-01-09 14:20:14 -0200
committerCedric BAIL <cedric@osg.samsung.com>2015-12-10 12:02:30 -0800
commit10fa1b5b4b2454437c00a9b8931bb3f9ddb9e99c (patch)
treeb4238f5f83b55463ad2e88e97dc968f2a607a668 /src/lib/eldbus/eldbus_message_from_eina_value.c
parent48b22214493958fc852f101009b0e8a88aa77e05 (diff)
eldbus: add efl.model implementation.
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/eldbus/eldbus_message_from_eina_value.c')
-rw-r--r--src/lib/eldbus/eldbus_message_from_eina_value.c124
1 files changed, 122 insertions, 2 deletions
diff --git a/src/lib/eldbus/eldbus_message_from_eina_value.c b/src/lib/eldbus/eldbus_message_from_eina_value.c
index 05bb9f5e41..3d594fb6ab 100644
--- a/src/lib/eldbus/eldbus_message_from_eina_value.c
+++ b/src/lib/eldbus/eldbus_message_from_eina_value.c
@@ -1,6 +1,8 @@
1#include "eldbus_private.h" 1#include "eldbus_private.h"
2#include "eldbus_private_types.h" 2#include "eldbus_private_types.h"
3 3
4#include <dbus/dbus-protocol.h>
5
4static Eina_Bool 6static Eina_Bool
5_compatible_type(int dbus_type, const Eina_Value_Type *value_type) 7_compatible_type(int dbus_type, const Eina_Value_Type *value_type)
6{ 8{
@@ -205,7 +207,7 @@ _array_append(const char *type, const Eina_Value *value_array, Eldbus_Message_It
205} 207}
206 208
207static Eina_Bool 209static Eina_Bool
208_basic_append(char type, const Eina_Value *value, const Eina_Value_Struct_Desc *desc, unsigned idx, Eldbus_Message_Iter *iter) 210_basic_append_value_struct(char type, const Eina_Value *value, const Eina_Value_Struct_Desc *desc, unsigned idx, Eldbus_Message_Iter *iter)
209{ 211{
210 EINA_SAFETY_ON_FALSE_RETURN_VAL( 212 EINA_SAFETY_ON_FALSE_RETURN_VAL(
211 _compatible_type(type, desc->members[idx].type), EINA_FALSE); 213 _compatible_type(type, desc->members[idx].type), EINA_FALSE);
@@ -305,7 +307,7 @@ _message_iter_from_eina_value_struct(const char *signature, Eldbus_Message_Iter
305 { 307 {
306 DBG("type: %s", type); 308 DBG("type: %s", type);
307 if (type[0] != 'v' && !type[1]) 309 if (type[0] != 'v' && !type[1])
308 r = _basic_append(type[0], value, st.desc, i, iter); 310 r = _basic_append_value_struct(type[0], value, st.desc, i, iter);
309 else if (type[0] == 'a') 311 else if (type[0] == 'a')
310 { 312 {
311 Eina_Value value_array; 313 Eina_Value value_array;
@@ -367,3 +369,121 @@ eldbus_message_from_eina_value(const char *signature, Eldbus_Message *msg, const
367 369
368 return _message_iter_from_eina_value_struct(signature, iter, value); 370 return _message_iter_from_eina_value_struct(signature, iter, value);
369} 371}
372
373static Eina_Bool
374_basic_append_value(char type, const Eina_Value *value, Eldbus_Message_Iter *iter)
375{
376 EINA_SAFETY_ON_NULL_RETURN_VAL(value, EINA_FALSE);
377 const Eina_Value_Type *value_type = eina_value_type_get(value);
378 EINA_SAFETY_ON_FALSE_RETURN_VAL(_compatible_type(type, value_type), EINA_FALSE);
379 switch (type)
380 {
381 case 'i'://int
382 case 'h'://fd
383 {
384 int32_t i;
385 eina_value_get(value, &i);
386 eldbus_message_iter_basic_append(iter, type, i);
387 break;
388 }
389 case 's':
390 case 'o'://object path
391 case 'g'://signature
392 {
393 const char *txt;
394 eina_value_get(value, &txt);
395 eldbus_message_iter_basic_append(iter, type, txt);
396 break;
397 }
398 case 'b'://boolean
399 case 'y'://byte
400 {
401 unsigned char byte;
402 eina_value_get(value, &byte);
403 eldbus_message_iter_basic_append(iter, type, byte);
404 break;
405 }
406 case 'n'://int16
407 {
408 int16_t i;
409 eina_value_get(value, &i);
410 eldbus_message_iter_basic_append(iter, type, i);
411 break;
412 }
413 case 'q'://uint16
414 {
415 uint16_t i;
416 eina_value_get(value, &i);
417 eldbus_message_iter_basic_append(iter, type, i);
418 break;
419 }
420 case 'u'://uint32
421 {
422 uint32_t i;
423 eina_value_get(value, &i);
424 eldbus_message_iter_basic_append(iter, type, i);
425 break;
426 }
427 case 'x'://int64
428 {
429 int64_t i;
430 eina_value_get(value, &i);
431 eldbus_message_iter_basic_append(iter, type, i);
432 break;
433 }
434 case 't'://uint64
435 {
436 uint64_t i;
437 eina_value_get(value, &i);
438 eldbus_message_iter_basic_append(iter, type, i);
439 break;
440 }
441 case 'd'://double
442 {
443 double d;
444 eina_value_get(value, &d);
445 eldbus_message_iter_basic_append(iter, type, d);
446 break;
447 }
448 default:
449 ERR("Unexpected type %c", type);
450 return EINA_FALSE;
451 }
452 return EINA_TRUE;
453}
454
455Eina_Bool
456_message_iter_from_eina_value(const char *signature, Eldbus_Message_Iter *iter, const Eina_Value *value)
457{
458 EINA_SAFETY_ON_NULL_RETURN_VAL(value, EINA_FALSE);
459
460 const Eina_Value_Type *value_type = eina_value_type_get(value);
461 if (EINA_VALUE_TYPE_STRUCT == value_type || EINA_VALUE_TYPE_ARRAY == value_type)
462 return _message_iter_from_eina_value_struct(signature, iter, value);
463
464 Eina_Bool result = EINA_TRUE;
465 DBusSignatureIter signature_iter;
466 dbus_signature_iter_init(&signature_iter, signature);
467 char *type;
468 while ((type = dbus_signature_iter_get_signature(&signature_iter)))
469 {
470 DBG("type: %s", type);
471 if (DBUS_TYPE_VARIANT != type[0] && DBUS_TYPE_INVALID == type[1])
472 result = _basic_append_value(type[0], value, iter);
473 else if (DBUS_TYPE_ARRAY == type[0] ||
474 DBUS_STRUCT_BEGIN_CHAR == type[0] ||
475 DBUS_TYPE_VARIANT == type[0])
476 {
477 ERR("Not a basic type");
478 result = EINA_FALSE;
479 }
480 else
481 {
482 ERR("Unknown type %c", type[0]);
483 result = EINA_FALSE;
484 }
485 dbus_free(type);
486 if (!result || !dbus_signature_iter_next(&signature_iter)) break;
487 }
488 return result;
489}