Enlightenment CVS committal

Author  : sebastid
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_dbus


Modified Files:
        ecore_dbus.c ecore_dbus_marshal.c ecore_dbus_message.c 
        ecore_dbus_unmarshal.c 


Log Message:
More DBus work. Should soon be able to interact with haldaemon.

===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_dbus/ecore_dbus.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -3 -r1.16 -r1.17
--- ecore_dbus.c        26 Jul 2006 12:08:06 -0000      1.16
+++ ecore_dbus.c        26 Jul 2006 20:43:28 -0000      1.17
@@ -342,9 +342,9 @@
        printf("[ecore_dbus] received server data, %d bytes\n", e->size);
        while (e->size)
          {
-            Ecore_DBus_Event_Server_Data    *ev;
-            Ecore_DBus_Message_Field_UInt32 *serial;
-            char                            *method;
+            Ecore_DBus_Event_Server_Data *ev;
+            unsigned int                 *serial;
+            char                         *method;
 
             msg = _ecore_dbus_message_unmarshal(svr, (unsigned char 
*)(e->data) + offset, e->size);
             if (msg == NULL) break;
@@ -352,13 +352,13 @@
             e->size -= msg->length;
             printf("[ecore_dbus] dbus message length %u bytes, still %d\n",
                    msg->length, e->size);
-            ecore_dbus_message_print(msg);
+            //ecore_dbus_message_print(msg);
             /* Trap known messages */
             serial = ecore_dbus_message_header_field_get(msg, 
ECORE_DBUS_HEADER_FIELD_REPLY_SERIAL);
-            if (msg->type == ECORE_DBUS_MESSAGE_TYPE_METHOD_RETURN)
+            if ((serial) && (msg->type == 
ECORE_DBUS_MESSAGE_TYPE_METHOD_RETURN))
               {
 
-                 method = ecore_hash_remove(svr->methods, (void 
*)serial->value);
+                 method = ecore_hash_remove(svr->methods, (void *)(*serial));
                  if (method)
                    {
                       printf("Return from method: %s\n", method);
@@ -374,7 +374,17 @@
               }
             else
               {
-                 method = NULL;
+                 /* Get interface and member from the message */
+                 char buf[1024];
+
+                 char *interface, *member;
+                 interface = ecore_dbus_message_header_field_get(msg, 
ECORE_DBUS_HEADER_FIELD_INTERFACE);
+                 member = ecore_dbus_message_header_field_get(msg, 
ECORE_DBUS_HEADER_FIELD_MEMBER);
+                 if ((member) && (interface))
+                   snprintf(buf, sizeof(buf), "%s.%s", interface, member);
+                 else if (member)
+                   strcpy(buf, member);
+                 method = strdup(buf);
               }
             ev = malloc(sizeof(Ecore_DBus_Event_Server_Data));
             ev->type = msg->type;
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_dbus/ecore_dbus_marshal.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- ecore_dbus_marshal.c        25 Jul 2006 12:44:19 -0000      1.2
+++ ecore_dbus_marshal.c        26 Jul 2006 20:43:28 -0000      1.3
@@ -80,7 +80,6 @@
    str_len = strlen(str);
    _ecore_dbus_message_append_byte(msg, str_len);
 
-   /* + 1 for \0 */
    _ecore_dbus_message_append_bytes(msg, (unsigned char *)str, str_len + 1);
    return f;
 }
@@ -145,6 +144,7 @@
    _ecore_dbus_message_append_byte(msg, 1);
    /* signature */
    _ecore_dbus_message_append_byte(msg, type);
+   _ecore_dbus_message_append_byte(msg, '\0');
 
    switch (type)
      {
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_dbus/ecore_dbus_message.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ecore_dbus_message.c        25 Jul 2006 16:03:05 -0000      1.3
+++ ecore_dbus_message.c        26 Jul 2006 20:43:28 -0000      1.4
@@ -22,7 +22,7 @@
                                   char *fmt, ...)
 {
    unsigned int                    serial, body_start;
-   char                            action[1024];
+   char                            buf[1024];
    Ecore_DBus_Message_Field_Array *arr;
 
    if (!method) return 0;
@@ -144,10 +144,10 @@
    /* send message */
    ecore_dbus_server_send(svr, (char *)msg->buffer, msg->length);
    if (interface)
-     snprintf(action, sizeof(action), "%s.%s", interface, method);
+     snprintf(buf, sizeof(buf), "%s.%s", interface, method);
    else
-     strcpy(action, method);
-   ecore_hash_set(svr->methods, (void *)msg->serial, strdup(action));
+     strcpy(buf, method);
+   ecore_hash_set(svr->methods, (void *)msg->serial, strdup(buf));
 
    serial = msg->serial;
    _ecore_dbus_message_free(msg);
@@ -200,7 +200,19 @@
             Ecore_DBus_Message_Field_Variant *v;
 
             v = ecore_list_last(s->values);
-            return v->value;
+            switch (v->contained_type)
+              {
+               case ECORE_DBUS_DATA_TYPE_UINT32:
+                  return &ECORE_DBUS_MESSAGE_FIELD_UINT32(v->value)->value;
+               case ECORE_DBUS_DATA_TYPE_STRING:
+                  return ECORE_DBUS_MESSAGE_FIELD_STRING(v->value)->value;
+               case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
+                  return ECORE_DBUS_MESSAGE_FIELD_OBJECT_PATH(v->value)->value;
+               case ECORE_DBUS_DATA_TYPE_SIGNATURE:
+                  return ECORE_DBUS_MESSAGE_FIELD_SIGNATURE(v->value)->value;
+               default:
+                  return NULL;
+              }
          }
      }
    return NULL;
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_dbus/ecore_dbus_unmarshal.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- ecore_dbus_unmarshal.c      25 Jul 2006 16:03:05 -0000      1.4
+++ ecore_dbus_unmarshal.c      26 Jul 2006 20:43:28 -0000      1.5
@@ -30,6 +30,26 @@
 }
 
 static void *
+_ecore_dbus_message_unmarshal_boolean(Ecore_DBus_Message *msg, int *size)
+{
+   Ecore_DBus_Message_Field_Boolean *f;
+   unsigned int                      old_length;
+
+   old_length = msg->length;
+   f = _ecore_dbus_message_field_new(msg, ECORE_DBUS_DATA_TYPE_BOOLEAN);
+   f->value = _ecore_dbus_message_read_uint32(msg);
+   if (*size < (msg->length - old_length))
+     {
+       /* TODO: Free message field */
+       printf("Ecore_DBus: To few bytes for boolean: got %d need %d\n",
+              *size, (msg->length - old_length));
+       return NULL;
+     }
+   *size -= (msg->length - old_length);
+   return f;
+}
+
+static void *
 _ecore_dbus_message_unmarshal_int32(Ecore_DBus_Message *msg, int *size)
 {
    Ecore_DBus_Message_Field_Int32 *f;
@@ -220,7 +240,6 @@
    old_length = msg->length;
    f = _ecore_dbus_message_field_new(msg, ECORE_DBUS_DATA_TYPE_VARIANT);
    ecore_list_prepend(msg->recurse, f);
-   f->contained_type = type;
 
    /* signature length */
    length = _ecore_dbus_message_read_byte(msg);
@@ -232,6 +251,9 @@
      }
    /* signature */
    type = _ecore_dbus_message_read_byte(msg);
+   f->contained_type = type;
+   /* Read '\0' from signature */
+   _ecore_dbus_message_read_byte(msg);
    if (*size < (msg->length - old_length))
      {
        /* TODO: Free message field */
@@ -326,10 +348,10 @@
 Ecore_DBus_Message *
 _ecore_dbus_message_unmarshal(Ecore_DBus_Server *svr, unsigned char *message, 
int size)
 {
-   Ecore_DBus_Message                 *msg;
-   Ecore_DBus_Message_Field_Array     *arr;
-   Ecore_DBus_Message_Field_Signature *sig;
-   unsigned int                        old_length;
+   Ecore_DBus_Message             *msg;
+   Ecore_DBus_Message_Field_Array *arr;
+   char                           *sig;
+   unsigned int                    old_length;
 
    /* init */
    if (size < 16)
@@ -381,16 +403,16 @@
    /* message body */
    if (sig)
      {
-       char *s;
-
-       s = sig->value;
-       while (*s)
+       while (*sig)
          {
             Ecore_DBus_Data_Type  type;
 
-            type = *s;
+            type = *sig;
             switch (type)
               {
+               case ECORE_DBUS_DATA_TYPE_BOOLEAN:
+                  _ecore_dbus_message_unmarshal_boolean(msg, &size);
+                  break;
                case ECORE_DBUS_DATA_TYPE_INT32:
                   _ecore_dbus_message_unmarshal_int32(msg, &size);
                   break;
@@ -410,11 +432,10 @@
                     {
                        Ecore_DBus_Message_Field_Array *arr;
                        Ecore_DBus_Unmarshal_Func func;
-                       s++;
-                       type = *s;
+                       sig++;
+                       type = *sig;
                        arr = _ecore_dbus_message_unmarshal_array_begin(msg, 
type, &size);
                        func = _ecore_dbus_message_unmarshal_func(type);
-                       printf("Arr: %d %d %d %c %p\n", msg->length, 
arr->start, arr->end, type, func);
                        while (msg->length < arr->end)
                          (*func)(msg, &size);
                        _ecore_dbus_message_unmarshal_array_end(msg, arr);
@@ -422,7 +443,6 @@
                   break;
                case ECORE_DBUS_DATA_TYPE_INVALID:
                case ECORE_DBUS_DATA_TYPE_BYTE:
-               case ECORE_DBUS_DATA_TYPE_BOOLEAN:
                case ECORE_DBUS_DATA_TYPE_INT16:
                case ECORE_DBUS_DATA_TYPE_UINT16:
                case ECORE_DBUS_DATA_TYPE_INT64:
@@ -441,7 +461,7 @@
                   printf("[ecore_dbus] unknown/unhandled data type %c\n", 
type);
                   break;
               }
-            s++;
+            sig++;
          }
      }
    return msg;



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to