Add ibus_message_iter_copy method;
authorPeng Huang <shawn.p.huang@gmail.com>
Wed, 8 Jul 2009 03:32:01 +0000 (11:32 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Wed, 8 Jul 2009 06:58:32 +0000 (14:58 +0800)
Add Ping method of org.freedesktop.IBus interface.

bus/ibusimpl.c
ibus/bus.py
ibus/interface/iibus.py
src/ibusmessage.c
src/ibusmessage.h

index 35cac369b676c106afe3cd2bf8623770bcfae731..66a99ee8beb4f96c6ee25d713bba37938896eab5 100644 (file)
@@ -1106,6 +1106,25 @@ _ibus_exit (BusIBusImpl     *ibus,
     return NULL;
 }
 
+static IBusMessage *
+_ibus_ping (BusIBusImpl     *ibus,
+            IBusMessage     *message,
+            BusConnection   *connection)
+{
+    IBusMessage *reply;
+    IBusMessageIter src, dst;
+    gboolean retval;
+
+    reply = ibus_message_new_method_return (message);
+
+    ibus_message_iter_init (message, &src);
+    ibus_message_iter_init_append (reply, &dst);
+
+    ibus_message_iter_copy_data (&dst, &src);
+
+    return reply;
+}
+
 static gboolean
 bus_ibus_impl_ibus_message (BusIBusImpl     *ibus,
                             BusConnection   *connection,
@@ -1133,6 +1152,7 @@ bus_ibus_impl_ibus_message (BusIBusImpl     *ibus,
         { IBUS_INTERFACE_IBUS, "ListEngines",           _ibus_list_engines },
         { IBUS_INTERFACE_IBUS, "ListActiveEngines",     _ibus_list_active_engines },
         { IBUS_INTERFACE_IBUS, "Exit",                  _ibus_exit },
+        { IBUS_INTERFACE_IBUS, "Ping",                  _ibus_ping },
         { NULL, NULL, NULL }
     };
 
index 973103d7f1a23cf4cf1e25866508e8166c9c3458..3f471f6df84b4b85aa3966b7c289391a3eb62559 100644 (file)
@@ -129,6 +129,15 @@ class Bus(object.Object):
     def exit(self, restart):
         return self.__ibus.Exit(restart)
 
+    def ping(self, data):
+        flag = isinstance(data, serializable.Serializable):
+        if flag:
+            data = serializable.serialize_object(data)
+        data = self.__ibus.Ping(data)
+        if flag:
+            data = serializable.deserialize_object(data)
+        return data
+
     def get_config(self):
         try:
             return self.__config
index fa71a717703f1536822f291cdbb1eff0cfa348d7..c7a333138cc2393fa0e9e173535d6aaa2a0fa355 100644 (file)
@@ -69,3 +69,6 @@ class IIBus(dbus.service.Object):
     @method(in_signature="b")
     def Exit(self, restart, dbusconn): pass
 
+    @method(in_signature="v" out_signature="v")
+    def Ping(self, data, dbusconn): pass
+
index 829a304762fc72d0f0edfc63627023af6c323cc8..7af888bd2bb62a0dfba38a17f6d78b8a0b319793 100644 (file)
@@ -503,18 +503,18 @@ ibus_message_iter_append (IBusMessageIter *iter,
             v = * (guint *)value;
             return dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT32, &v);
         }
-    case G_TYPE_ULONG:
-        {
-            dbus_uint64_t v;
-            v = * (gulong *)value;
-            return dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT64, &v);
-        }
     case G_TYPE_LONG:
         {
             dbus_int64_t v;
             v = * (glong *)value;
             return dbus_message_iter_append_basic (iter, DBUS_TYPE_INT64, &v);
         }
+    case G_TYPE_ULONG:
+        {
+            dbus_uint64_t v;
+            v = * (gulong *)value;
+            return dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT64, &v);
+        }
     case G_TYPE_BOOLEAN:
         {
             dbus_bool_t v;
@@ -571,6 +571,155 @@ ibus_message_iter_append (IBusMessageIter *iter,
     return FALSE;
 }
 
+static gboolean
+gtype_is_basic (GType type)
+{
+    switch (type) {
+    case G_TYPE_CHAR:
+    case G_TYPE_INT:
+    case G_TYPE_UINT:
+    case G_TYPE_INT64:
+    case G_TYPE_UINT64:
+    case G_TYPE_BOOLEAN:
+    case G_TYPE_DOUBLE:
+    case G_TYPE_STRING:
+        return TRUE;
+    default:
+        if (type == IBUS_TYPE_OBJECT_PATH)
+            return TRUE;
+        return FALSE;
+    }
+}
+
+gboolean
+ibus_message_iter_copy_data (IBusMessageIter *dst,
+                             IBusMessageIter *src)
+{
+    GType type;
+    gconstpointer value;
+    gboolean retval;
+
+    type = ibus_message_iter_get_arg_type (src);
+
+    g_return_val_if_fail (type != G_TYPE_INVALID, FALSE);
+
+    if (gtype_is_basic (type)) {
+        ibus_message_iter_get_basic (src, &value);
+        retval = ibus_message_iter_append (dst, type, value);
+        g_return_val_if_fail (retval, FALSE);
+        return TRUE;
+    }
+
+    if (type == IBUS_TYPE_VARIANT) {
+        IBusMessageIter subdst, subsrc;
+        gchar *signature;
+
+        retval = ibus_message_iter_recurse (src, IBUS_TYPE_VARIANT, &subsrc);
+        g_return_val_if_fail (retval, FALSE);
+
+        signature = dbus_message_iter_get_signature (src);
+        g_return_val_if_fail (signature != NULL, FALSE);
+        retval = ibus_message_iter_open_container (dst,
+                                                   IBUS_TYPE_VARIANT,
+                                                   signature,
+                                                   &subdst);
+        dbus_free (signature);
+        g_return_val_if_fail (retval, FALSE);
+
+        retval = ibus_message_iter_copy_data (&subdst, &subsrc);
+        g_return_val_if_fail (retval, FALSE);
+
+        retval = ibus_message_iter_close_container (dst, &subdst);
+        g_return_val_if_fail (retval, FALSE);
+
+        dbus_message_iter_next (src);
+        return TRUE;
+    }
+    else if (type == IBUS_TYPE_ARRAY) {
+        IBusMessageIter subdst, subsrc;
+        gchar *signature;
+
+        retval = ibus_message_iter_recurse (src, IBUS_TYPE_ARRAY, &subsrc);
+        g_return_val_if_fail (retval, FALSE);
+
+        signature = dbus_message_iter_get_signature (src);
+        g_return_val_if_fail (signature != NULL, FALSE);
+        retval = ibus_message_iter_open_container (dst,
+                                                   IBUS_TYPE_ARRAY,
+                                                   signature,
+                                                   &subdst);
+        dbus_free (signature);
+        g_return_val_if_fail (retval, FALSE);
+
+        do {
+            retval = ibus_message_iter_copy_data (&subdst, &subsrc);
+            g_return_val_if_fail (retval, FALSE);
+        } while (ibus_message_iter_next (&subsrc));
+
+        retval = ibus_message_iter_close_container (dst, &subdst);
+        g_return_val_if_fail (retval, FALSE);
+
+        dbus_message_iter_next (src);
+        return TRUE;
+    }
+    else if (type == IBUS_TYPE_STRUCT) {
+        IBusMessageIter subdst, subsrc;
+        gchar *signature;
+
+        retval = ibus_message_iter_recurse (src, IBUS_TYPE_STRUCT, &subsrc);
+        g_return_val_if_fail (retval, FALSE);
+
+        signature = dbus_message_iter_get_signature (src);
+        g_return_val_if_fail (signature != NULL, FALSE);
+        retval = ibus_message_iter_open_container (dst,
+                                                   IBUS_TYPE_STRUCT,
+                                                   signature,
+                                                   &subdst);
+        dbus_free (signature);
+        g_return_val_if_fail (retval, FALSE);
+
+        do {
+            retval = ibus_message_iter_copy_data (&subdst, &subsrc);
+            g_return_val_if_fail (retval, FALSE);
+        } while (ibus_message_iter_next (&subsrc));
+
+        retval = ibus_message_iter_close_container (dst, &subdst);
+        g_return_val_if_fail (retval, FALSE);
+
+        dbus_message_iter_next (src);
+        return TRUE;
+    }
+    else if (type == IBUS_TYPE_DICT_ENTRY) {
+        IBusMessageIter subdst, subsrc;
+
+        retval = ibus_message_iter_recurse (src, IBUS_TYPE_DICT_ENTRY, &subsrc);
+        g_return_val_if_fail (retval, FALSE);
+
+        retval = ibus_message_iter_open_container (dst,
+                                                   IBUS_TYPE_DICT_ENTRY,
+                                                   NULL,
+                                                   &subdst);
+        g_return_val_if_fail (retval, FALSE);
+
+        /* copy key */
+        retval = ibus_message_iter_copy_data (&subdst, &subsrc);
+        g_return_val_if_fail (retval, FALSE);
+
+        /* copy value */
+        retval = ibus_message_iter_copy_data (&subdst, &subsrc);
+        g_return_val_if_fail (retval, FALSE);
+
+        retval = ibus_message_iter_close_container (dst, &subdst);
+        g_return_val_if_fail (retval, FALSE);
+
+        dbus_message_iter_next (src);
+        return TRUE;
+    }
+
+    return FALSE;
+
+}
+
 gboolean
 ibus_message_iter_init (IBusMessage     *message,
                         IBusMessageIter *iter)
index 02ce821354644ec673d8097615e1624b33e44a8a..905855394e5029de5534be6b10dc842586d6178c 100644 (file)
@@ -719,6 +719,9 @@ gboolean         ibus_message_iter_append       (IBusMessageIter    *iter,
                                                  GType               type,
                                                  gconstpointer       value);
 
+gboolean         ibus_message_iter_copy_data    (IBusMessageIter    *dst,
+                                                 IBusMessageIter    *src);
+
 /**
  * ibus_message_iter_init:
  * @message: An IBusMessage.