summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-10-21 16:50:53 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-10-29 11:21:40 +0000
commit7ffbde3f23170ccc219ca969052efaf9c9a535bf (patch)
tree46e550df238eb8111e2079a05019f4035455941e
parent07e7c3d2768fe85eb2815aa93d695291565f931e (diff)
codegen: factor out copy_into_gvalue
I needed this for TpExportable (which is still work in progress), but it's already a small code reduction. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=59024 Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
-rw-r--r--tools/glib-client-gen.py68
-rw-r--r--tools/libglibcodegen.py23
2 files changed, 29 insertions, 62 deletions
diff --git a/tools/glib-client-gen.py b/tools/glib-client-gen.py
index 7d67c7165..a0fecf083 100644
--- a/tools/glib-client-gen.py
+++ b/tools/glib-client-gen.py
@@ -28,8 +28,8 @@ import xml.dom.minidom
from getopt import gnu_getopt
from libtpcodegen import file_set_contents, key_by_name, u
-from libglibcodegen import Signature, type_to_gtype, \
- get_docstring, xml_escape, get_deprecated
+from libglibcodegen import (Signature, type_to_gtype,
+ get_docstring, xml_escape, get_deprecated, copy_into_gvalue)
NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
@@ -205,36 +205,8 @@ class Generator(object):
self.b(' g_value_unset (args->values + %d);' % i)
self.b(' g_value_init (args->values + %d, %s);' % (i, gtype))
- if gtype == 'G_TYPE_STRING':
- self.b(' g_value_set_string (args->values + %d, %s);'
- % (i, name))
- elif marshaller == 'BOXED':
- self.b(' g_value_set_boxed (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_UCHAR':
- self.b(' g_value_set_uchar (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_BOOLEAN':
- self.b(' g_value_set_boolean (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_INT':
- self.b(' g_value_set_int (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_UINT':
- self.b(' g_value_set_uint (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_INT64':
- self.b(' g_value_set_int (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_UINT64':
- self.b(' g_value_set_uint64 (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_DOUBLE':
- self.b(' g_value_set_double (args->values + %d, %s);'
- % (i, name))
- else:
- assert False, ("Don't know how to put %s in a GValue"
- % gtype)
+ self.b(' ' + copy_into_gvalue('args->values + %d' % i,
+ gtype, marshaller, name))
self.b('')
self.b(' tp_proxy_signal_connection_v0_take_results (sc, args);')
@@ -573,36 +545,8 @@ class Generator(object):
self.b(' g_value_unset (args->values + %d);' % i)
self.b(' g_value_init (args->values + %d, %s);' % (i, gtype))
- if gtype == 'G_TYPE_STRING':
- self.b(' g_value_take_string (args->values + %d, %s);'
- % (i, name))
- elif marshaller == 'BOXED':
- self.b(' g_value_take_boxed (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_UCHAR':
- self.b(' g_value_set_uchar (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_BOOLEAN':
- self.b(' g_value_set_boolean (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_INT':
- self.b(' g_value_set_int (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_UINT':
- self.b(' g_value_set_uint (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_INT64':
- self.b(' g_value_set_int (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_UINT64':
- self.b(' g_value_set_uint (args->values + %d, %s);'
- % (i, name))
- elif gtype == 'G_TYPE_DOUBLE':
- self.b(' g_value_set_double (args->values + %d, %s);'
- % (i, name))
- else:
- assert False, ("Don't know how to put %s in a GValue"
- % gtype)
+ self.b(' ' + copy_into_gvalue('args->values + %d' % i,
+ gtype, marshaller, name))
self.b(' tp_proxy_pending_call_v0_take_results (user_data, '
'NULL, args);')
diff --git a/tools/libglibcodegen.py b/tools/libglibcodegen.py
index 6cd1a6277..0b703a5a8 100644
--- a/tools/libglibcodegen.py
+++ b/tools/libglibcodegen.py
@@ -170,3 +170,26 @@ def type_to_gtype(s):
# we just don't know ..
raise Exception("don't know the GType for " + s)
+
+
+def copy_into_gvalue(gvaluep, gtype, marshaller, name):
+ if gtype == 'G_TYPE_STRING':
+ return 'g_value_set_string (%s, %s);' % (gvaluep, name)
+ elif marshaller == 'BOXED':
+ return 'g_value_set_boxed (%s, %s);' % (gvaluep, name)
+ elif gtype == 'G_TYPE_UCHAR':
+ return 'g_value_set_uchar (%s, %s);' % (gvaluep, name)
+ elif gtype == 'G_TYPE_BOOLEAN':
+ return 'g_value_set_boolean (%s, %s);' % (gvaluep, name)
+ elif gtype == 'G_TYPE_INT':
+ return 'g_value_set_int (%s, %s);' % (gvaluep, name)
+ elif gtype == 'G_TYPE_UINT':
+ return 'g_value_set_uint (%s, %s);' % (gvaluep, name)
+ elif gtype == 'G_TYPE_INT64':
+ return 'g_value_set_int (%s, %s);' % (gvaluep, name)
+ elif gtype == 'G_TYPE_UINT64':
+ return 'g_value_set_uint64 (%s, %s);' % (gvaluep, name)
+ elif gtype == 'G_TYPE_DOUBLE':
+ return 'g_value_set_double (%s, %s);' % (gvaluep, name)
+ else:
+ raise AssertionError("Don't know how to put %s in a GValue" % gtype)