Commit 9114ed82 authored by Fargier Sylvain's avatar Fargier Sylvain Committed by Ross Burton
Browse files

Fix gupnp-binding-tool to generate headers usable in C++

parent b7ac6f70
......@@ -201,10 +201,6 @@ def printClientSyncActionBinding(a):
def printClientAsyncActionBinding(a):
# Magic struct to pass data around. Defined here so that we don't have
# multiple copies of the struct definition.
asyncdata = " struct {GCallback cb; gpointer userdata; } *cbdata;"
# User-callback prototype
indent = (24 + len (a.c_prefixed_name)) * " "
print "typedef void (*%s_reply) (GUPnPServiceProxy *proxy," % a.c_prefixed_name
......@@ -220,12 +216,12 @@ def printClientAsyncActionBinding(a):
print "%sGUPnPServiceProxyAction *action," % indent
print "%sgpointer user_data)" % indent
print "{"
print asyncdata
print " GUPnPAsyncData *cbdata;"
print " GError *error = NULL;"
for arg in a.out_args:
print " %s%s;" % (arg.related_var.ctype, arg.c_name)
print
print " cbdata = user_data;"
print " cbdata = (GUPnPAsyncData *) user_data;"
print " gupnp_service_proxy_end_action"
print " (proxy, action, &error,"
for arg in a.out_args:
......@@ -251,9 +247,9 @@ def printClientAsyncActionBinding(a):
print "%sgpointer userdata)" % indent
print "{"
print " GUPnPServiceProxyAction* action;"
print asyncdata
print " GUPnPAsyncData *cbdata;"
print
print " cbdata = g_slice_alloc (sizeof (*cbdata));"
print " cbdata = (GUPnPAsyncData *) g_slice_alloc (sizeof (*cbdata));"
print " cbdata->cb = G_CALLBACK (callback);"
print " cbdata->userdata = userdata;"
print " action = gupnp_service_proxy_begin_action"
......@@ -268,7 +264,6 @@ def printClientAsyncActionBinding(a):
def printClientVariableNotifyBinding(v):
asyncdata = " struct {GCallback cb; gpointer userdata; } *cbdata;"
ctype = re.sub ("^gchar", "const gchar", v.ctype);
# callback prototype
......@@ -287,10 +282,10 @@ def printClientVariableNotifyBinding(v):
print "%sGValue *value," % indent
print "%sgpointer userdata)" % indent
print "{"
print asyncdata
print " GUPnPAsyncData *cbdata;"
print " %s%s;" % (ctype, v.c_name)
print
print " cbdata = userdata;"
print " cbdata = (GUPnPAsyncData *) userdata;"
print " %s = %s (value);" % (v.c_name, v.get_function)
print " ((%s_changed_callback)cbdata->cb)" % v.c_prefixed_name
print " (proxy,"
......@@ -308,9 +303,9 @@ def printClientVariableNotifyBinding(v):
print "%s%s_changed_callback callback," % (indent, v.c_prefixed_name)
print "%sgpointer userdata)" % indent
print "{"
print asyncdata
print " GUPnPAsyncData *cbdata;"
print
print " cbdata = g_slice_alloc (sizeof (*cbdata));"
print " cbdata = (GUPnPAsyncData *) g_slice_alloc (sizeof (*cbdata));"
print " cbdata->cb = G_CALLBACK (callback);"
print " cbdata->userdata = userdata;"
print
......@@ -324,8 +319,6 @@ def printClientVariableNotifyBinding(v):
def printServerVariableQueryBinding(v):
asyncdata = " struct {GCallback cb; gpointer userdata; } *cbdata;"
# User callback proto
indent = (28 + len (v.ctype)+ len (v.c_prefixed_name)) * " "
print "typedef %s(*%s_query_callback) (GUPnPService *service," % (v.ctype, v.c_prefixed_name)
......@@ -339,12 +332,12 @@ def printServerVariableQueryBinding(v):
print "%sGValue *value," % indent
print "%sgpointer userdata)" % indent
print "{"
print asyncdata
print " GUPnPAsyncData *cbdata;"
print " %s%s;" % (v.ctype, v.c_name)
print
indent = (36 + len (v.c_name) + len (v.c_prefixed_name)) * " "
print " cbdata = userdata;"
print " cbdata = (GUPnPAsyncData *) userdata;"
print " %s = ((%s_query_callback)cbdata->cb) (service," % (v.c_name, v.c_prefixed_name)
print "%scbdata->userdata);" % indent
print " g_value_init (value, %s);" % v.gtype
......@@ -358,9 +351,9 @@ def printServerVariableQueryBinding(v):
print "%s%s_query_callback callback," % (indent, v.c_prefixed_name)
print "%sgpointer userdata)" % indent
print "{"
print asyncdata
print " GUPnPAsyncData *cbdata;"
print
print " cbdata = g_slice_alloc (sizeof (*cbdata));"
print " cbdata = (GUPnPAsyncData *) g_slice_alloc (sizeof (*cbdata));"
print " cbdata->cb = G_CALLBACK (callback);"
print " cbdata->userdata = userdata;"
print
......@@ -369,7 +362,7 @@ def printServerVariableQueryBinding(v):
print " G_CALLBACK (_%s_query_cb)," % v.c_prefixed_name
print " cbdata,"
print " _free_cb_data,"
print " 0);"
print " (GConnectFlags) 0);"
print "}"
print
......@@ -456,7 +449,12 @@ def printClientBindings(binding_name, actions, variables):
print "#define %s" % define
print
print "G_BEGIN_DECLS"
print "\n#ifndef __GUPNPASYNCDATA_TYPE__"
print "#define __GUPNPASYNCDATA_TYPE__"
print "typedef struct {GCallback cb; gpointer userdata; } GUPnPAsyncData;"
print "#endif"
for a in actions:
print "\n/* action %s */\n" % a.name
printClientSyncActionBinding(a)
......@@ -483,12 +481,16 @@ def printServerBindings(binding_name, actions, variables):
print "#define %s" % define
print
print "G_BEGIN_DECLS"
print
print "\n#ifndef __GUPNPASYNCDATA_TYPE__"
print "#define __GUPNPASYNCDATA_TYPE__"
print "typedef struct {GCallback cb; gpointer userdata; } GUPnPAsyncData;"
print "#endif"
print "static void"
print "_free_cb_data (gpointer data, GClosure *closure)"
print "{"
print " struct {GCallback cb; gpointer userdata; } *cbdata = data;"
print " GUPnPAsyncData *cbdata = (GUPnPAsyncData *) data;"
print " g_slice_free1 (sizeof (*cbdata), cbdata);"
print "}"
print
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment