Mercurial > pidgin.yaz
comparison src/dbus-analyze-functions.py @ 11187:744c0708d11f
[gaim-migrate @ 13303]
gaim-remote.py implements the functionality of standard gaim-remote,
but using DBus. It can also call all gaim functions exported via
DBus.
dbus-analize-function.py can now produce dbus bindings for GHashTable
arguments.
committer: Tailor Script <tailor@pidgin.im>
author | Piotr Zielinski <zielaj> |
---|---|
date | Wed, 03 Aug 2005 23:54:37 +0000 |
parents | 57af14280b5f |
children | 66f872f30e40 |
comparison
equal
deleted
inserted
replaced
11186:bbe84acea03a | 11187:744c0708d11f |
---|---|
37 # "gint" : ("i", None), | 37 # "gint" : ("i", None), |
38 # "guint" : ("u", None), | 38 # "guint" : ("u", None), |
39 # "gboolean" : ("i", "int") | 39 # "gboolean" : ("i", "int") |
40 # } | 40 # } |
41 | 41 |
42 | |
42 simpletypes = ["int", "gint", "guint", "gboolean"] | 43 simpletypes = ["int", "gint", "guint", "gboolean"] |
43 | 44 |
44 # for enum in file("dbus-auto-enums.txt"): | 45 # for enum in file("dbus-auto-enums.txt"): |
45 # simpletypes[enum.strip()] = ("i", "int") | 46 # simpletypes[enum.strip()] = ("i", "int") |
46 | 47 |
47 # functions that shouldn't be exported | 48 # functions that shouldn't be exported |
48 | 49 |
49 excluded = ["gaim_accounts_load", "gaim_account_set_presence", | 50 excluded = ["gaim_accounts_load", "gaim_account_set_presence", |
50 "gaim_conv_placement_get_fnc_id", "gaim_conv_placement_add_fnc"] | 51 "gaim_conv_placement_get_fnc_id", "gaim_conv_placement_add_fnc", |
52 "gaim_presence_add_list"] | |
53 | |
54 stringlists = [] | |
51 | 55 |
52 pointer = "#pointer#" | 56 pointer = "#pointer#" |
53 | 57 |
54 functions = [] | 58 functions = [] |
55 | 59 |
75 print "DBusMessage *reply_DBUS;" | 79 print "DBusMessage *reply_DBUS;" |
76 | 80 |
77 for decl in cdecls: | 81 for decl in cdecls: |
78 print decl | 82 print decl |
79 | 83 |
80 print "dbus_message_get_args(message_DBUS, error_DBUS, ", | 84 print "%s(message_DBUS, error_DBUS, " % argfunc, |
81 for param in cparams: | 85 for param in cparams: |
82 print "DBUS_TYPE_%s, &%s," % param, | 86 print "DBUS_TYPE_%s, &%s," % param, |
83 print "DBUS_TYPE_INVALID);" | 87 print "DBUS_TYPE_INVALID);" |
84 | 88 |
85 print "CHECK_ERROR(error_DBUS);" | 89 print "CHECK_ERROR(error_DBUS);" |
103 print "return reply_DBUS;\n}\n" | 107 print "return reply_DBUS;\n}\n" |
104 | 108 |
105 functions.append((function, dparams)) | 109 functions.append((function, dparams)) |
106 | 110 |
107 def c_clear(): | 111 def c_clear(): |
108 global cparams, cdecls, ccode, cparamsout, ccodeout, dparams | 112 global cparams, cdecls, ccode, cparamsout, ccodeout, dparams, argfunc |
109 dparams = "" | 113 dparams = "" |
110 cparams = [] | 114 cparams = [] |
111 cdecls = [] | 115 cdecls = [] |
112 ccode = [] | 116 ccode = [] |
113 cparamsout = [] | 117 cparamsout = [] |
114 ccodeout = [] | 118 ccodeout = [] |
119 argfunc = "dbus_message_get_args" | |
115 | 120 |
116 | 121 |
117 def addstring(*items): | 122 def addstring(*items): |
118 global dparams | 123 global dparams |
119 for item in items: | 124 for item in items: |
135 print "#define GAIM_DBUS_REGISTER_BINDINGS(handle) gaim_dbus_register_bindings(handle, bindings_DBUS)" | 140 print "#define GAIM_DBUS_REGISTER_BINDINGS(handle) gaim_dbus_register_bindings(handle, bindings_DBUS)" |
136 | 141 |
137 # processing an input parameter | 142 # processing an input parameter |
138 | 143 |
139 def inputvar(mytype, name): | 144 def inputvar(mytype, name): |
140 global ccode, cparams, cdecls | 145 global ccode, cparams, cdecls, ccodeout, argfunc |
141 const = False | 146 const = False |
142 if mytype[0] == "const": | 147 if mytype[0] == "const": |
143 mytype = mytype[1:] | 148 mytype = mytype[1:] |
144 const = True | 149 const = True |
145 | 150 |
146 # simple types (int, gboolean, etc.) and enums | 151 |
147 if (len(mytype) == 1) and \ | 152 |
148 ((mytype[0] in simpletypes) or (mytype[0].startswith("Gaim"))): | 153 |
149 cdecls.append("dbus_int32_t %s;" % name) | 154 if len(mytype) == 1: |
150 cparams.append(("INT32", name)) | 155 # simple types (int, gboolean, etc.) and enums |
151 addintype("i", name) | 156 if (mytype[0] in simpletypes) or (mytype[0].startswith("Gaim")): |
152 return | 157 cdecls.append("dbus_int32_t %s;" % name) |
153 | 158 cparams.append(("INT32", name)) |
154 # pointers ... | 159 addintype("i", name) |
155 | 160 return |
161 | |
162 # va_list, replace by NULL | |
163 if mytype[0] == "va_list": | |
164 cdecls.append("va_list %s;" % name); | |
165 ccode.append("%s = NULL;" % name); | |
166 return | |
167 | |
168 # pointers ... | |
156 if (len(mytype) == 2) and (mytype[1] == pointer): | 169 if (len(mytype) == 2) and (mytype[1] == pointer): |
157 # strings | 170 # strings |
158 if mytype[0] == "char": | 171 if mytype[0] == "char": |
159 if const: | 172 if const: |
160 cdecls.append("const char *%s;" % name) | 173 cdecls.append("const char *%s;" % name) |
163 addintype("s", name) | 176 addintype("s", name) |
164 return | 177 return |
165 else: | 178 else: |
166 raise myexception | 179 raise myexception |
167 | 180 |
181 # memory leak if an error occurs later ... | |
182 elif mytype[0] == "GHashTable": | |
183 argfunc = "gaim_dbus_message_get_args" | |
184 cdecls.append("DBusMessageIter %s_ITER;" % name) | |
185 cdecls.append("GHashTable *%s;" % name) | |
186 cparams.append(("ARRAY", "%s_ITER" % name)) | |
187 ccode.append("%s = gaim_dbus_iter_hash_table(&%s_ITER, error_DBUS);" \ | |
188 % (name, name)) | |
189 ccode.append("CHECK_ERROR(error_DBUS);") | |
190 ccodeout.append("g_hash_table_destroy(%s);" % name) | |
191 addintype("a{ss}", name) | |
192 return | |
193 | |
168 # known object types are transformed to integer handles | 194 # known object types are transformed to integer handles |
169 elif mytype[0].startswith("Gaim"): | 195 elif mytype[0].startswith("Gaim"): |
170 cdecls.append("dbus_int32_t %s_ID;" % name) | 196 cdecls.append("dbus_int32_t %s_ID;" % name) |
171 cdecls.append("%s *%s;" % (mytype[0], name)) | 197 cdecls.append("%s *%s;" % (mytype[0], name)) |
172 cparams.append(("INT32", name + "_ID")) | 198 cparams.append(("INT32", name + "_ID")) |
188 | 214 |
189 | 215 |
190 | 216 |
191 # processing an output parameter | 217 # processing an output parameter |
192 | 218 |
193 def outputvar(mytype, name, call): | 219 def outputvar(mytype, name, call, function): |
194 # the "void" type is simple ... | 220 # the "void" type is simple ... |
195 if mytype == ["void"]: | 221 if mytype == ["void"]: |
196 ccode.append("%s;" % call) # just call the function | 222 ccode.append("%s;" % call) # just call the function |
197 return | 223 return |
198 | 224 |
199 # a constant string | 225 const = False |
200 if mytype == ["const", "char", pointer]: | 226 if mytype[0] == "const": |
227 mytype = mytype[1:] | |
228 const = True | |
229 | |
230 | |
231 # a string | |
232 if mytype == ["char", pointer]: | |
201 cdecls.append("const char *%s;" % name) | 233 cdecls.append("const char *%s;" % name) |
202 ccode.append("%s = null_to_empty(%s);" % (name, call)) | 234 ccode.append("%s = null_to_empty(%s);" % (name, call)) |
203 cparamsout.append(("STRING", name)) | 235 cparamsout.append(("STRING", name)) |
204 addouttype("s", name) | 236 addouttype("s", name) |
237 if not const: | |
238 ccodeout.append("g_free(%s);" % name) | |
205 return | 239 return |
206 | 240 |
207 # simple types (ints, booleans, enums, ...) | 241 # simple types (ints, booleans, enums, ...) |
208 if (len(mytype) == 1) and \ | 242 if (len(mytype) == 1) and \ |
209 ((mytype[0] in simpletypes) or (mytype[0].startswith("Gaim"))): | 243 ((mytype[0] in simpletypes) or (mytype[0].startswith("Gaim"))): |
223 cparamsout.append(("INT32", name)) | 257 cparamsout.append(("INT32", name)) |
224 addouttype("i", name) | 258 addouttype("i", name) |
225 return | 259 return |
226 | 260 |
227 # GList*, GSList*, assume that list is a list of objects | 261 # GList*, GSList*, assume that list is a list of objects |
228 # not a list of strings!!! | 262 |
229 # this does NOT release memory occupied by the list | 263 # fixme: at the moment, we do NOT free the memory occupied by |
264 # the list, we should free it if the list has NOT been declared const | |
265 | |
266 # fixme: we assume that this is a list of objects, not a list | |
267 # of strings | |
268 | |
230 if mytype[0] in ["GList", "GSList"]: | 269 if mytype[0] in ["GList", "GSList"]: |
231 cdecls.append("dbus_int32_t %s_LEN;" % name) | 270 cdecls.append("dbus_int32_t %s_LEN;" % name) |
232 cdecls.append("dbus_int32_t *%s;" % name) | 271 ccodeout.append("g_free(%s);" % name) |
233 ccode.append("%s = gaim_dbusify_%s(%s, FALSE, &%s_LEN);" % \ | 272 |
234 (name, mytype[0], call, name)) | 273 if function in stringlists: |
235 cparamsout.append("DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &%s, %s_LEN" \ | 274 cdecls.append("char **%s;" % name) |
275 ccode.append("%s = gaim_%s_to_array(%s, FALSE, &%s_LEN);" % \ | |
276 (name, mytype[0], call, name)) | |
277 cparamsout.append("DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &%s, %s_LEN" \ | |
236 % (name, name)) | 278 % (name, name)) |
237 ccodeout.append("g_free(%s);" % name) | 279 addouttype("as", name) |
238 addouttype("ai", name) | 280 else: |
281 cdecls.append("dbus_int32_t *%s;" % name) | |
282 ccode.append("%s = gaim_dbusify_%s(%s, FALSE, &%s_LEN);" % \ | |
283 (name, mytype[0], call, name)) | |
284 cparamsout.append("DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &%s, %s_LEN" \ | |
285 % (name, name)) | |
286 addouttype("ai", name) | |
239 return | 287 return |
240 | 288 |
241 raise myexception | 289 raise myexception |
242 | 290 |
243 | 291 |
253 | 301 |
254 origfunction = function | 302 origfunction = function |
255 function = function.lower() | 303 function = function.lower() |
256 | 304 |
257 names = [] | 305 names = [] |
306 unnamed = 0 | |
258 for param in paramlist: | 307 for param in paramlist: |
259 tokens = param.split() | 308 tokens = param.split() |
260 if len(tokens) < 2: | 309 if len(tokens) == 0: |
261 raise myexception | 310 raise myexception |
262 type, name = tokens[:-1], tokens[-1] | 311 if (len(tokens) == 1) or (tokens[-1] == pointer): |
312 unnamed += 1 | |
313 type, name = tokens, "param%i" % unnamed | |
314 else: | |
315 type, name = tokens[:-1], tokens[-1] | |
263 inputvar(type, name) | 316 inputvar(type, name) |
264 names.append(name) | 317 names.append(name) |
265 | 318 |
266 outputvar(functiontype, "RESULT", | 319 outputvar(functiontype, "RESULT", |
267 "%s(%s)" % (origfunction, ", ".join(names))) | 320 "%s(%s)" % (origfunction, ", ".join(names)), function) |
268 | 321 |
269 c_print(function) | 322 c_print(function) |
270 | 323 |
271 | 324 |
272 | 325 |