changeset 11277:421a8523ad04

[gaim-migrate @ 13467] added support for lists and hash tables to libgaim-client committer: Tailor Script <tailor@pidgin.im>
author Piotr Zielinski <zielaj>
date Tue, 16 Aug 2005 15:22:35 +0000
parents 17ebda61c6ce
children 93258e8fb6d2
files src/Makefile.am src/dbus-analyze-functions.py src/dbus-server.c src/gaim-client-example.c src/gaim-client.c src/gtkmain.c
diffstat 6 files changed, 71 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Mon Aug 15 22:48:20 2005 +0000
+++ b/src/Makefile.am	Tue Aug 16 15:22:35 2005 +0000
@@ -188,7 +188,8 @@
 
 gaim_client_example_SOURCES = gaim-client-example.c
 
-gaim_client_example_DEPENDENCIES = @LIBOBJS@
+gaim_client_example_DEPENDENCIES = @LIBOBJS@ libgaim-client.la 
+
 gaim_client_example_LDADD = \
 	@LIBOBJS@ \
 	libgaim-client.la \
--- a/src/dbus-analyze-functions.py	Mon Aug 15 22:48:20 2005 +0000
+++ b/src/dbus-analyze-functions.py	Tue Aug 16 15:22:35 2005 +0000
@@ -190,11 +190,11 @@
         print 'dbus_g_proxy_call(gaim_proxy, "%s", NULL,' % ctopascal(self.function.name)
         
         for type_name in self.inputparams:
-            print "G_TYPE_%s, %s, " % type_name,
+            print "%s, %s, " % type_name,
         print "G_TYPE_INVALID,"
 
         for type_name in self.outputparams:
-            print "G_TYPE_%s, &%s, " % type_name,
+            print "%s, &%s, " % type_name,
         print "G_TYPE_INVALID);"
         
         for code in self.returncode:
@@ -209,7 +209,8 @@
             print "typedef struct _%s %s;" % (type[0], type[0])
             self.knowntypes.append(type[0])
 
-    # fixme
+    # fixme: import the definitions of the enumerations from gaim
+    # header files
     def definegaimenum(self, type):
         if (self.headersonly) and (type[0] not in self.knowntypes) \
                and (type[0] not in simpletypes):
@@ -218,28 +219,29 @@
        
     def inputsimple(self, type, name):
         self.paramshdr.append("%s %s" % (type[0], name))
-        self.inputparams.append(("INT", name))
+        self.inputparams.append(("G_TYPE_INT", name))
         self.definegaimenum(type)
 
     def inputvalist(self, type, name):
-        self.paramshdr.append("...")
+        self.paramshdr.append("va_list %s_NULL" % name)
 
     def inputstring(self, type, name):
         self.paramshdr.append("const char *%s" % name)
-        self.inputparams.append(("STRING", name))
+        self.inputparams.append(("G_TYPE_STRING", name))
         
     def inputgaimstructure(self, type, name):
-        self.paramshdr.append("%s *%s" % (type[0], name))
-        self.inputparams.append(("INT", "GPOINTER_TO_INT(%s)" % name))
+        self.paramshdr.append("const %s *%s" % (type[0], name))
+        self.inputparams.append(("G_TYPE_INT", "GPOINTER_TO_INT(%s)" % name))
         self.definegaimstructure(type)
 
     def inputpointer(self, type, name):
-        self.paramshdr.append("%s *%s" % (type[0], name))
-        self.inputparams.append(("INT", "0"))
+        name += "_NULL"
+        self.paramshdr.append("const %s *%s" % (type[0], name))
+        self.inputparams.append(("G_TYPE_INT", "0"))
         
     def inputhash(self, type, name):
-        raise myexception
-
+        self.paramshdr.append("const GHashTable *%s" % name)
+        self.inputparams.append(('dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING)', name))
 
     def outputvoid(self, type, name):
         self.functiontype = "void"
@@ -247,28 +249,33 @@
     def outputstring(self, type, name, const):
         self.functiontype = "char*"
         self.decls.append("char *%s = NULL;" % name)
-        self.outputparams.append(("STRING", name))
+        self.outputparams.append(("G_TYPE_STRING", name))
 #        self.returncode.append("NULLIFY(%s);" % name)
         self.returncode.append("return %s;" % name);
 
     def outputsimple(self, type, name):
         self.functiontype = type[0]
         self.decls.append("%s %s = 0;" % (type[0], name))
-        self.outputparams.append(("INT", name))
+        self.outputparams.append(("G_TYPE_INT", name))
         self.returncode.append("return %s;" % name);
         self.definegaimenum(type)
 
+    # we could add "const" to the return type but this would probably
+    # be a nuisance
     def outputgaimstructure(self, type, name):
         name = name + "_ID"
         self.functiontype = "%s*" % type[0]
         self.decls.append("int %s = 0;" % name)
-        self.outputparams.append(("INT", "%s" % name))
+        self.outputparams.append(("G_TYPE_INT", "%s" % name))
         self.returncode.append("return (%s*) GINT_TO_POINTER(%s);" % (type[0], name));
         self.definegaimstructure(type)
 
     def outputlist(self, type, name):
-        raise myexception
-
+        self.functiontype = "%s*" % type[0]
+        self.decls.append("GArray *%s;" % name)
+        self.outputparams.append(('dbus_g_type_get_collection("GArray", G_TYPE_INT)', name))
+        self.returncode.append("return garray_int_to_%s(%s);" %
+                               (type[0].lower(), name));
 
  
 class ServerBinding (Binding):
@@ -535,6 +542,8 @@
 else:
     fprefix = ""
 
+sys.stderr.write("%s: Functions not exported:\n" % sys.argv[0])
+
 if "client" in options:
     bindings = ClientBindingSet(sys.stdin, fprefix,
                                 options.has_key("headers"))
--- a/src/dbus-server.c	Mon Aug 15 22:48:20 2005 +0000
+++ b/src/dbus-server.c	Tue Aug 16 15:22:35 2005 +0000
@@ -144,9 +144,9 @@
 
 dbus_bool_t
 gaim_dbus_message_get_args (DBusMessage     *message,
-                       DBusError       *error,
-		       int              first_arg_type,
-		       ...)
+			    DBusError       *error,
+			    int              first_arg_type,
+			    ...)
 {
   dbus_bool_t retval;
   va_list var_args;
@@ -431,10 +431,6 @@
 }
 
 
-/**************************************************************************/
-/** @name Signals                                                         */
-/**************************************************************************/
-
 static const char *gettext(const char **ptr) {
     const char *text = *ptr;
     *ptr += strlen(text) + 1;
@@ -675,13 +671,19 @@
 void gaim_dbus_signal_emit_gaim(char *name, int num_values, 
 				GaimValue **values, va_list vargs)
 {
-	/* pass name */
     DBusMessage *signal;
     DBusMessageIter iter;
     char *newname;
 
     g_return_if_fail(gaim_dbus_connection);
     
+    /* The test below is a hack that prevents our "dbus-method-called"
+       signal from being propagated to dbus.  What we really need is a
+       flag for each signal that states whether this signal is to be
+       dbus-propagated or not. */
+    if (!strcmp(name, "dbus-method-called"))
+	return;
+
     newname =  gaim_dbus_convert_signal_name(name);
     signal = dbus_message_new_signal(DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, newname);
     dbus_message_iter_init_append(signal, &iter);
@@ -701,8 +703,6 @@
 
 gboolean gaim_dbus_init(void) 
 {
-    gaim_debug_register_category("dbus");
-
     gaim_dbus_init_ids();
     return gaim_dbus_dispatch_init() ;
 }
--- a/src/gaim-client-example.c	Mon Aug 15 22:48:20 2005 +0000
+++ b/src/gaim-client-example.c	Tue Aug 16 15:22:35 2005 +0000
@@ -22,10 +22,19 @@
 int main (int argc, char **argv)
 {
     GaimAccount *account;
+    GList *alist, *node;
+
     gaim_init();
     
-    account = gaim_accounts_find_any("", "");
-    g_print("Alias: %s\n", gaim_account_get_alias(account));
+    alist = gaim_accounts_get_all();
+    for (node = alist; node; node = node->next) {
+	GaimAccount *account = (GaimAccount*) node->data;
+	char *name = gaim_account_get_username(account);
+	g_print("Name: %s\n", name);
+	g_free(name);
+    }
+
+    g_list_free(alist);
 
     return 0;
 }
--- a/src/gaim-client.c	Mon Aug 15 22:48:20 2005 +0000
+++ b/src/gaim-client.c	Tue Aug 16 15:22:35 2005 +0000
@@ -10,6 +10,28 @@
 static DBusGConnection *bus;
 static DBusGProxy *gaim_proxy;
 
+static GList *garray_int_to_glist(GArray *array) {
+    GList *list = NULL;
+    int i;
+
+    for(i = 0; i < array->len; i++) 
+	list = g_list_append(list, GINT_TO_POINTER(g_array_index(array,gint,i)));
+
+    g_array_free(array, TRUE);
+    return list;
+}
+
+static GSList *garray_int_to_gslist(GArray *array) {
+    GSList *list = NULL;
+    int i;
+
+    for(i = 0; i < array->len; i++) 
+	list = g_slist_append(list, GINT_TO_POINTER(g_array_index(array,gint,i)));
+
+    g_array_free(array, TRUE);
+    return list;
+}
+
 #include "gaim-client-bindings.c"
 
 static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
--- a/src/gtkmain.c	Mon Aug 15 22:48:20 2005 +0000
+++ b/src/gtkmain.c	Tue Aug 16 15:22:35 2005 +0000
@@ -685,10 +685,6 @@
 	startup_notification_complete();
 #endif
 
-#ifdef HAVE_DBUS
- 	gaim_dbus_connect(gaim_dbus_object); 
-#endif
-
 	gtk_main();
 
 #ifdef _WIN32