Mercurial > pidgin
comparison libpurple/dbus-analyze-functions.py @ 19114:6de2e9ba0930
merge of '2970edca111b3535ae0703e3c866ad1c3b87df94'
and 'a2b508e8680ac3f20965226a5dd83f7e2a3b15bb'
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Sun, 24 Jun 2007 02:56:09 +0000 |
parents | 5d1058768970 |
children | 476e16ce29d0 |
comparison
equal
deleted
inserted
replaced
19102:7f26e5b98b15 | 19114:6de2e9ba0930 |
---|---|
1 import re | 1 import re |
2 import string | 2 import string |
3 import sys | 3 import sys |
4 | 4 |
5 # types translated into "int" | 5 # types translated into "int" |
6 simpletypes = ["int", "gint", "guint", "gboolean"] | 6 simpletypes = ["int", "gint", "guint", "gboolean", "gpointer", "size_t", "gssize", "time_t"] |
7 | 7 |
8 # List "excluded" contains functions that shouldn't be exported via | 8 # List "excluded" contains functions that shouldn't be exported via |
9 # DBus. If you remove a function from this list, please make sure | 9 # DBus. If you remove a function from this list, please make sure |
10 # that it does not break "make" with the configure option | 10 # that it does not break "make" with the configure option |
11 # "--enable-dbus" turned on. | 11 # "--enable-dbus" turned on. |
30 # as pointer to a struct, instead of a pointer to an enum. This | 30 # as pointer to a struct, instead of a pointer to an enum. This |
31 # causes a compilation error. Someone should fix this script. | 31 # causes a compilation error. Someone should fix this script. |
32 "purple_log_read", | 32 "purple_log_read", |
33 ] | 33 ] |
34 | 34 |
35 # This is a list of functions that return a GList* whose elements are | 35 # This is a list of functions that return a GList* or GSList * whose elements |
36 # string, not pointers to objects. | 36 # are strings, not pointers to objects. |
37 stringlists = [ | 37 stringlists = [ |
38 "purple_prefs_get_path_list", | 38 "purple_prefs_get_path_list", |
39 "purple_prefs_get_string_list", | 39 "purple_prefs_get_string_list", |
40 "purple_uri_list_extract_filenames", | 40 "purple_uri_list_extract_filenames", |
41 "purple_uri_list_extract_uris", | 41 "purple_uri_list_extract_uris", |
42 ] | |
43 | |
44 # This is a list of functions that return a GList* or GSList* that should | |
45 # not be freed. Ideally, this information should be obtained from the Doxygen | |
46 # documentation at some point. | |
47 constlists = [ | |
48 "purple_account_get_status_types", | |
49 "purple_accounts_get_all", | |
50 "purple_account_option_get_list", | |
51 "purple_connections_get_all", | |
52 "purple_connections_get_connecting", | |
53 "purple_get_conversations", | |
54 "purple_get_ims", | |
55 "purple_get_chats", | |
56 "purple_conv_chat_get_users", | |
57 "purple_conv_chat_get_ignored", | |
58 "purple_mime_document_get_fields", | |
59 "purple_mime_document_get_parts", | |
60 "purple_mime_part_get_fields", | |
61 "purple_notify_user_info_get_entries", | |
62 "purple_request_fields_get_required", | |
63 "purple_request_field_list_get_selected", | |
64 "purple_request_field_list_get_items", | |
65 "purple_savedstatuses_get_all", | |
66 "purple_status_type_get_attrs", | |
67 "purple_presence_get_statuses", | |
42 ] | 68 ] |
43 | 69 |
44 pointer = "#pointer#" | 70 pointer = "#pointer#" |
45 myexception = "My Exception" | 71 myexception = "My Exception" |
46 | 72 |
91 self.flush() | 117 self.flush() |
92 | 118 |
93 | 119 |
94 def processinput(self, type, name): | 120 def processinput(self, type, name): |
95 const = False | 121 const = False |
122 unsigned = False | |
96 if type[0] == "const": | 123 if type[0] == "const": |
97 type = type[1:] | 124 type = type[1:] |
98 const = True | 125 const = True |
99 | 126 |
127 if type[0] == "unsigned": | |
128 type = type[1:] | |
129 unsigned = True | |
130 | |
100 if len(type) == 1: | 131 if len(type) == 1: |
101 # simple types (int, gboolean, etc.) and enums | 132 # simple types (int, gboolean, etc.) and enums |
102 if (type[0] in simpletypes) or ((type[0].startswith("Purple") and not type[0].endswith("Callback"))): | 133 if (type[0] in simpletypes) or ((type[0].startswith("Purple") and not type[0].endswith("Callback"))): |
103 return self.inputsimple(type, name) | 134 return self.inputsimple(type, name, unsigned) |
104 | 135 |
105 # pointers ... | 136 # pointers ... |
106 if (len(type) == 2) and (type[1] == pointer): | 137 if (len(type) == 2) and (type[1] == pointer): |
107 # strings | 138 # strings |
108 if type[0] in ["char", "gchar"]: | 139 if type[0] in ["char", "gchar"]: |
109 if const: | 140 if const: |
110 return self.inputstring(type, name) | 141 return self.inputstring(type, name, unsigned) |
111 else: | 142 else: |
112 raise myexception | 143 raise myexception |
113 | 144 |
114 elif type[0] == "GHashTable": | 145 elif type[0] == "GHashTable": |
115 return self.inputhash(type, name) | 146 return self.inputhash(type, name) |
150 # handles | 181 # handles |
151 if type[0].startswith("Purple"): | 182 if type[0].startswith("Purple"): |
152 return self.outputpurplestructure(type, name) | 183 return self.outputpurplestructure(type, name) |
153 | 184 |
154 if type[0] in ["GList", "GSList"]: | 185 if type[0] in ["GList", "GSList"]: |
155 return self.outputlist(type, name, const) | 186 return self.outputlist(type, name) |
156 | 187 |
157 raise myexception | 188 raise myexception |
158 | 189 |
159 | 190 |
160 class ClientBinding (Binding): | 191 class ClientBinding (Binding): |
204 if (self.headersonly) and (type[0] not in self.knowntypes): | 235 if (self.headersonly) and (type[0] not in self.knowntypes): |
205 print "struct _%s;" % type[0] | 236 print "struct _%s;" % type[0] |
206 print "typedef struct _%s %s;" % (type[0], type[0]) | 237 print "typedef struct _%s %s;" % (type[0], type[0]) |
207 self.knowntypes.append(type[0]) | 238 self.knowntypes.append(type[0]) |
208 | 239 |
209 def inputsimple(self, type, name): | 240 def inputsimple(self, type, name, us): |
210 self.paramshdr.append("%s %s" % (type[0], name)) | 241 self.paramshdr.append("%s %s" % (type[0], name)) |
211 self.inputparams.append(("G_TYPE_INT", name)) | 242 if us: |
212 | 243 self.inputparams.append(("G_TYPE_UINT", name)) |
213 def inputstring(self, type, name): | 244 else: |
214 self.paramshdr.append("const char *%s" % name) | 245 self.inputparams.append(("G_TYPE_INT", name)) |
246 | |
247 def inputstring(self, type, name, us): | |
248 if us: | |
249 self.paramshdr.append("const unsigned char *%s" % name) | |
250 else: | |
251 self.paramshdr.append("const char *%s" % name) | |
215 self.inputparams.append(("G_TYPE_STRING", name)) | 252 self.inputparams.append(("G_TYPE_STRING", name)) |
216 | 253 |
217 def inputpurplestructure(self, type, name): | 254 def inputpurplestructure(self, type, name): |
218 self.paramshdr.append("const %s *%s" % (type[0], name)) | 255 self.paramshdr.append("const %s *%s" % (type[0], name)) |
219 self.inputparams.append(("G_TYPE_INT", "GPOINTER_TO_INT(%s)" % name)) | 256 self.inputparams.append(("G_TYPE_INT", "GPOINTER_TO_INT(%s)" % name)) |
252 self.decls.append("int %s = 0;" % name) | 289 self.decls.append("int %s = 0;" % name) |
253 self.outputparams.append(("G_TYPE_INT", "%s" % name)) | 290 self.outputparams.append(("G_TYPE_INT", "%s" % name)) |
254 self.returncode.append("return (%s*) GINT_TO_POINTER(%s);" % (type[0], name)); | 291 self.returncode.append("return (%s*) GINT_TO_POINTER(%s);" % (type[0], name)); |
255 self.definepurplestructure(type) | 292 self.definepurplestructure(type) |
256 | 293 |
257 def outputlist(self, type, name, const): | 294 def outputlist(self, type, name): |
258 self.functiontype = "%s*" % type[0] | 295 self.functiontype = "%s*" % type[0] |
259 self.decls.append("GArray *%s;" % name) | 296 self.decls.append("GArray *%s;" % name) |
260 self.outputparams.append(('dbus_g_type_get_collection("GArray", G_TYPE_INT)', name)) | 297 self.outputparams.append(('dbus_g_type_get_collection("GArray", G_TYPE_INT)', name)) |
261 self.returncode.append("return garray_int_to_%s(%s);" % | 298 self.returncode.append("return garray_int_to_%s(%s);" % |
262 (type[0].lower(), name)); | 299 (type[0].lower(), name)); |
296 print "\treply_DBUS = dbus_message_new_method_return (message_DBUS);" | 333 print "\treply_DBUS = dbus_message_new_method_return (message_DBUS);" |
297 | 334 |
298 print "\tdbus_message_append_args(reply_DBUS,", | 335 print "\tdbus_message_append_args(reply_DBUS,", |
299 for param in self.cparamsout: | 336 for param in self.cparamsout: |
300 if type(param) is str: | 337 if type(param) is str: |
301 print "%s," % param | 338 print "%s," % param, |
302 else: | 339 else: |
303 print "DBUS_TYPE_%s, &%s," % param, | 340 print "DBUS_TYPE_%s, &%s," % param, |
304 print "DBUS_TYPE_INVALID);" | 341 print "DBUS_TYPE_INVALID);" |
305 | 342 |
306 for code in self.ccodeout: | 343 for code in self.ccodeout: |
320 self.addstring("out", type, name) | 357 self.addstring("out", type, name) |
321 | 358 |
322 | 359 |
323 # input parameters | 360 # input parameters |
324 | 361 |
325 def inputsimple(self, type, name): | 362 def inputsimple(self, type, name, us): |
326 self.cdecls.append("\tdbus_int32_t %s;" % name) | 363 if us: |
327 self.cparams.append(("INT32", name)) | 364 self.cdecls.append("\tdbus_int32_t %s;" % name) |
328 self.addintype("i", name) | 365 self.cparams.append(("INT32", name)) |
329 | 366 self.addintype("i", name) |
330 def inputstring(self, type, name): | 367 else: |
331 self.cdecls.append("\tconst char *%s;" % name) | 368 self.cdecls.append("\tdbus_uint32_t %s;" % name) |
369 self.cparams.append(("UINT32", name)) | |
370 self.addintype("u", name) | |
371 | |
372 def inputstring(self, type, name, us): | |
373 if us: | |
374 self.cdecls.append("\tconst unsigned char *%s;" % name) | |
375 else: | |
376 self.cdecls.append("\tconst char *%s;" % name) | |
332 self.cparams.append(("STRING", name)) | 377 self.cparams.append(("STRING", name)) |
333 self.ccode .append("\tNULLIFY(%s);" % name) | 378 self.ccode.append("\t%s = (%s && %s[0]) ? %s : NULL;" % (name,name,name,name)) |
334 self.addintype("s", name) | 379 self.addintype("s", name) |
335 | 380 |
336 def inputhash(self, type, name): | 381 def inputhash(self, type, name): |
337 self.argfunc = "purple_dbus_message_get_args" | 382 self.argfunc = "purple_dbus_message_get_args" |
338 self.cdecls.append("\tDBusMessageIter %s_ITER;" % name) | 383 self.cdecls.append("\tDBusMessageIter %s_ITER;" % name) |
388 self.cparamsout.append(("INT32", name)) | 433 self.cparamsout.append(("INT32", name)) |
389 self.addouttype("i", name) | 434 self.addouttype("i", name) |
390 | 435 |
391 # GList*, GSList*, assume that list is a list of objects | 436 # GList*, GSList*, assume that list is a list of objects |
392 # unless the function is in stringlists | 437 # unless the function is in stringlists |
393 def outputlist(self, type, name, const): | 438 def outputlist(self, type, name): |
394 self.cdecls.append("\tdbus_int32_t %s_LEN;" % name) | 439 self.cdecls.append("\tdbus_int32_t %s_LEN;" % name) |
395 self.ccodeout.append("\tg_free(%s);" % name) | 440 self.ccodeout.append("\tg_free(%s);" % name) |
396 | 441 |
397 if const: | 442 self.cdecls.append("\t%s *list;" % type[0]); |
398 const_prefix = "const_" | |
399 else: | |
400 const_prefix = "" | |
401 | |
402 if (const): | |
403 self.cdecls.append("\tconst %s *list;" % type[0]); | |
404 else: | |
405 self.cdecls.append("\t%s *list;" % type[0]); | |
406 | 443 |
407 if self.function.name in stringlists: | 444 if self.function.name in stringlists: |
408 self.cdecls.append("\tchar **%s;" % name) | 445 self.cdecls.append("\tchar **%s;" % name) |
409 self.ccode.append("\tlist = %s;" % self.call) | 446 self.ccode.append("\tlist = %s;" % self.call) |
410 self.ccode.append("\t%s = (char **)purple_const_%s_to_array(list, &%s_LEN);" % \ | 447 self.ccode.append("\t%s = (char **)purple_%s_to_array(list, FALSE, &%s_LEN);" % \ |
411 (name, type[0], name)) | 448 (name, type[0], name)) |
412 self.cparamsout.append("\tDBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &%s, %s_LEN" \ | 449 self.cparamsout.append("DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &%s, %s_LEN" \ |
413 % (name, name)) | 450 % (name, name)) |
414 if (not const): | 451 if (not (self.function.name in constlists)): |
415 type_name = type[0].lower()[1:] | 452 type_name = type[0].lower()[1:] |
416 self.ccodeout.append("\tg_%s_foreach(list, (GFunc)g_free, NULL);" % type_name) | 453 self.ccodeout.append("\tg_%s_foreach(list, (GFunc)g_free, NULL);" % type_name) |
417 self.ccodeout.append("\tg_%s_free(list);" % type_name) | 454 self.ccodeout.append("\tg_%s_free(list);" % type_name) |
418 self.addouttype("as", name) | 455 self.addouttype("as", name) |
419 else: | 456 else: |
420 self.cdecls.append("\tdbus_int32_t *%s;" % name) | 457 self.cdecls.append("\tdbus_int32_t *%s;" % name) |
421 self.ccode.append("\tlist = %s;" % self.call) | 458 self.ccode.append("\tlist = %s;" % self.call) |
422 self.ccode.append("\t%s = purple_dbusify_const_%s(list, &%s_LEN);" % \ | 459 self.ccode.append("\t%s = purple_dbusify_%s(list, FALSE, &%s_LEN);" % \ |
423 (name, type[0], name)) | 460 (name, type[0], name)) |
424 if (not const): | 461 if (not (self.function.name in constlists)): |
425 self.ccode.append("\tg_%s_free(list);" % type[0].lower()[1:]) | 462 self.ccode.append("\tg_%s_free(list);" % type[0].lower()[1:]) |
426 self.cparamsout.append("\tDBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &%s, %s_LEN" \ | 463 self.cparamsout.append("DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &%s, %s_LEN" \ |
427 % (name, name)) | 464 % (name, name)) |
428 self.addouttype("ai", name) | 465 self.addouttype("ai", name) |
429 | 466 |
430 | 467 |
431 class BindingSet: | 468 class BindingSet: |