Merge branch 'gdbus-emit-signal-ids' into 'main'

codegen: Use g_signal_emit to emit signals

See merge request GNOME/glib!3488
This commit is contained in:
Philip Withnall 2023-06-30 09:27:00 +00:00
commit 2a077b30a4
2 changed files with 39 additions and 10 deletions

View File

@ -1728,6 +1728,22 @@ class CodeGenerator:
self.outfile.write(" &%s_%s.parent_struct,\n" % (prefix, a.name))
self.outfile.write(" NULL\n" "};\n" "\n")
def generate_signals_enum_for_interface(self, i):
if not i.signals:
return
self.outfile.write("enum\n{\n")
for s in i.signals:
self.outfile.write(f" {s.upper_id_name},\n")
self.outfile.write("};\n" "\n")
self.outfile.write(
"static unsigned "
f"{i.signals_enum_name}[{len(i.signals)}] = {{ 0 }};"
"\n"
"\n"
)
def generate_introspection_for_interface(self, i):
self.outfile.write(
"/* ---- Introspection data for %s ---- */\n" "\n" % (i.name)
@ -2164,15 +2180,17 @@ class CodeGenerator:
)
self.write_gtkdoc_deprecated_and_since_and_close(s, self.outfile, 2)
self.outfile.write(
' g_signal_new ("%s",\n'
" G_TYPE_FROM_INTERFACE (iface),\n"
" G_SIGNAL_RUN_LAST,\n"
" G_STRUCT_OFFSET (%sIface, %s),\n"
" NULL,\n" # accumulator
" NULL,\n" # accu_data
" g_cclosure_marshal_generic,\n"
" G_TYPE_NONE,\n"
" %d" % (s.name_hyphen, i.camel_name, s.name_lower, len(s.args))
f" {i.signals_enum_name}[{s.upper_id_name}] =\n"
' g_signal_new ("%s",\n'
" G_TYPE_FROM_INTERFACE (iface),\n"
" G_SIGNAL_RUN_LAST,\n"
" G_STRUCT_OFFSET (%sIface, %s),\n"
" NULL,\n" # accumulator
" NULL,\n" # accu_data
" g_cclosure_marshal_generic,\n"
" G_TYPE_NONE,\n"
" %d"
% (s.name_hyphen, i.camel_name, s.name_lower, len(s.args))
)
for a in s.args:
self.outfile.write(", %s" % (a.gtype))
@ -2496,7 +2514,10 @@ class CodeGenerator:
for a in s.args:
self.outfile.write(",\n %sarg_%s" % (a.ctype_in, a.name))
self.outfile.write(
")\n" "{\n" ' g_signal_emit_by_name (object, "%s"' % (s.name_hyphen)
")\n"
"{\n"
" g_signal_emit (object, "
f"{i.signals_enum_name}[{s.upper_id_name}], 0"
)
for a in s.args:
self.outfile.write(", arg_%s" % a.name)
@ -5227,6 +5248,7 @@ class CodeGenerator:
self.generate_body_preamble()
for i in self.ifaces:
self.generate_interface_intro(i)
self.generate_signals_enum_for_interface(i)
self.generate_introspection_for_interface(i)
self.generate_interface(i)
self.generate_property_accessors(i)

View File

@ -369,7 +369,11 @@ class Signal:
if overridden_name:
name = overridden_name
self.name_lower = utils.camel_case_to_uscore(name).lower().replace("-", "_")
self.name_upper = self.name_lower.upper()
self.name_hyphen = self.name_lower.replace("_", "-")
self.upper_id_name = "_".join(
[cns_upper, containing_iface.name_upper, self.name_upper]
)
arg_count = 0
for a in self.args:
@ -540,3 +544,6 @@ class Interface:
for a in self.annotations:
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
if self.signals:
self.signals_enum_name = "_".join([cns_upper, self.name_upper, "SIGNALS"])