def __call__(self): nodes = self.dom.getElementsByTagName('node') nodes.sort(key=key_by_name) self.h('#include <glib-object.h>') self.h('#include <dbus/dbus-glib.h>') for header in self.headers: self.h('#include %s' % header) self.h('') self.h('') self.h('G_BEGIN_DECLS') self.h('') self.b('#include "%s.h"' % self.basename) self.b('') for node in nodes: self.do_node(node) self.h('') self.h('G_END_DECLS') self.b('') for header in self.end_headers: self.b('#include %s' % header) self.h('') self.b('') file_set_contents(self.basename + '.h', u('\n').join(self.__header).encode('utf-8')) file_set_contents(self.basename + '.c', u('\n').join(self.__body).encode('utf-8')) file_set_contents(self.basename + '-gtk-doc.h', u('\n').join(self.__docs).encode('utf-8'))
def __call__(self): self.do_header() self.do_body() self.do_footer() file_set_contents(self.output_base + '.h', u('').join(self.__header).encode('utf-8')) file_set_contents(self.output_base + '-gtk-doc.h', u('').join(self.__docs).encode('utf-8'))
def __call__(self): for f in self.h, self.c: self.do_header(f) self.do_body() file_set_contents(self.implfile, u('').join(self.impls).encode('utf-8')) file_set_contents(self.declfile, u('').join(self.decls).encode('utf-8')) file_set_contents(self.docfile, u('').join(self.docs).encode('utf-8'))
def __call__(self): errors = self.errors.getElementsByTagNameNS(NS_TP, 'error') self.b('#include <telepathy-glib/errors.h>') self.b('') self.b('const gchar *') self.b('tp_error_get_dbus_name (TpError error)') self.b('{') self.b(' switch (error)') self.b(' {') for error in errors: ns = error.parentNode.getAttribute('namespace') nick = error.getAttribute('name').replace(' ', '') uc_nick = error.getAttribute('name').replace(' ', '_').replace( '.', '_').upper() name = 'TP_ERROR_STR_' + uc_nick error_name = '%s.%s' % (ns, nick) self.d('/**') self.d(' * %s:' % name) self.d(' *') self.d(' * The D-Bus error name %s' % error_name) self.d(' *') self.d(' * %s' % xml_escape(get_docstring(error))) self.d(' */') self.d('') self.h('#define %s "%s"' % (name, error_name)) self.b(' case TP_ERROR_%s:' % uc_nick) self.b(' return %s;' % name) self.b(' default:') self.b(' g_return_val_if_reached (NULL);') self.b(' }') self.b('}') # make both files end with a newline self.h('') self.b('') file_set_contents(self.basename + '.h', u('\n').join(self.__header).encode('utf-8')) file_set_contents(self.basename + '.c', u('\n').join(self.__body).encode('utf-8')) file_set_contents(self.basename + '-gtk-doc.h', u('\n').join(self.__docs).encode('utf-8'))
def __call__(self): errors = self.errors.getElementsByTagNameNS(NS_TP, 'error') self.b('#include <telepathy-glib/errors.h>') self.b('') self.b('const gchar *') self.b('tp_error_get_dbus_name (TpError error)') self.b('{') self.b(' switch (error)') self.b(' {') for error in errors: ns = error.parentNode.getAttribute('namespace') nick = error.getAttribute('name').replace(' ', '') uc_nick = error.getAttribute('name').replace(' ', '_').replace('.', '_').upper() name = 'TP_ERROR_STR_' + uc_nick error_name = '%s.%s' % (ns, nick) self.d('/**') self.d(' * %s:' % name) self.d(' *') self.d(' * The D-Bus error name %s' % error_name) self.d(' *') self.d(' * %s' % xml_escape(get_docstring(error))) self.d(' */') self.d('') self.h('#define %s "%s"' % (name, error_name)) self.b(' case TP_ERROR_%s:' % uc_nick) self.b(' return %s;' % name) self.b(' default:') self.b(' g_return_val_if_reached (NULL);') self.b(' }') self.b('}') # make both files end with a newline self.h('') self.b('') file_set_contents(self.basename + '.h', u('\n').join(self.__header).encode('utf-8')) file_set_contents(self.basename + '.c', u('\n').join(self.__body).encode('utf-8')) file_set_contents(self.basename + '-gtk-doc.h', u('\n').join(self.__docs).encode('utf-8'))
def __call__(self): mappings = self.dom.getElementsByTagNameNS(NS_TP, 'mapping') structs = self.dom.getElementsByTagNameNS(NS_TP, 'struct') for mapping in mappings: self.do_mapping_header(mapping) for sig in self.need_mappings: self.h('GType %stype_dbus_hash_%s (void);\n\n' % (self.prefix_, self.need_mappings[sig])) self.c('GType\n%stype_dbus_hash_%s (void)\n{\n' % (self.prefix_, self.need_mappings[sig])) self.c(' static GType t = 0;\n\n') self.c(' if (G_UNLIKELY (t == 0))\n') # FIXME: translate sig into two GTypes items = tuple(Signature(sig)) gtypes = types_to_gtypes(items) self.c(' t = dbus_g_type_get_map ("GHashTable", ' '%s, %s);\n' % (gtypes[0], gtypes[1])) self.c(' return t;\n') self.c('}\n\n') for struct in structs: self.do_struct_header(struct) for sig in self.need_structs: self.h('GType %stype_dbus_struct_%s (void);\n\n' % (self.prefix_, self.need_structs[sig])) self.c('GType\n%stype_dbus_struct_%s (void)\n{\n' % (self.prefix_, self.need_structs[sig])) self.c(' static GType t = 0;\n\n') self.c(' if (G_UNLIKELY (t == 0))\n') self.c(' t = dbus_g_type_get_struct ("GValueArray",\n') items = tuple(Signature(sig)) gtypes = types_to_gtypes(items) for gtype in gtypes: self.c(' %s,\n' % gtype) self.c(' G_TYPE_INVALID);\n') self.c(' return t;\n') self.c('}\n\n') for sig in self.need_struct_arrays: self.h('GType %stype_dbus_array_%s (void);\n\n' % (self.prefix_, self.need_struct_arrays[sig])) self.c('GType\n%stype_dbus_array_%s (void)\n{\n' % (self.prefix_, self.need_struct_arrays[sig])) self.c(' static GType t = 0;\n\n') self.c(' if (G_UNLIKELY (t == 0))\n') self.c(' t = dbus_g_type_get_collection ("GPtrArray", ' '%stype_dbus_struct_%s ());\n' % (self.prefix_, self.need_struct_arrays[sig])) self.c(' return t;\n') self.c('}\n\n') for sig in self.need_other_arrays: self.h('GType %stype_dbus_array_of_%s (void);\n\n' % (self.prefix_, self.need_other_arrays[sig])) self.c('GType\n%stype_dbus_array_of_%s (void)\n{\n' % (self.prefix_, self.need_other_arrays[sig])) self.c(' static GType t = 0;\n\n') self.c(' if (G_UNLIKELY (t == 0))\n') if sig[:2] == 'a{' and sig[-1:] == '}': # array of mappings self.c(' t = dbus_g_type_get_collection (' '"GPtrArray", ' '%stype_dbus_hash_%s ());\n' % (self.prefix_, escape_as_identifier(sig[2:-1]))) elif sig[:2] == 'a(' and sig[-1:] == ')': # array of arrays of struct self.c(' t = dbus_g_type_get_collection (' '"GPtrArray", ' '%stype_dbus_array_%s ());\n' % (self.prefix_, escape_as_identifier(sig[2:-1]))) elif sig[:1] == 'a': # array of arrays of non-struct self.c(' t = dbus_g_type_get_collection (' '"GPtrArray", ' '%stype_dbus_array_of_%s ());\n' % (self.prefix_, escape_as_identifier(sig[1:]))) else: raise AssertionError("array of '%s' not supported" % sig) self.c(' return t;\n') self.c('}\n\n') file_set_contents(self.output + '.h', u('').join(self.header).encode('utf-8')) file_set_contents(self.output + '-body.h', u('').join(self.body).encode('utf-8')) file_set_contents(self.output + '-gtk-doc.h', u('').join(self.docs).encode('utf-8'))
def __call__(self): if self.guard is not None: self.h('#ifndef %s' % self.guard) self.h('#define %s' % self.guard) self.h('') self.h('G_BEGIN_DECLS') self.h('') self.b('/* We don\'t want gtkdoc scanning this file, it\'ll get') self.b(' * confused by seeing function definitions, so mark it as: */') self.b('/*<private_header>*/') self.b('') nodes = self.dom.getElementsByTagName('node') nodes.sort(key=key_by_name) for node in nodes: self.do_interface(node) if self.group is not None: self.b('/*') self.b(' * %s_%s_add_signals:' % (self.prefix_lc, self.group)) self.b(' * @self: the #TpProxy') self.b(' * @quark: a quark whose string value is the interface') self.b(' * name whose signals should be added') self.b(' * @proxy: the D-Bus proxy to which to add the signals') self.b(' * @unused: not used for anything') self.b(' *') self.b(' * Tell dbus-glib that @proxy has the signatures of all') self.b(' * signals on the given interface, if it\'s one we') self.b(' * support.') self.b(' *') self.b(' * This function should be used as a signal handler for') self.b(' * #TpProxy::interface-added.') self.b(' */') self.b('static void') self.b('%s_%s_add_signals (TpProxy *self G_GNUC_UNUSED,' % (self.prefix_lc, self.group)) self.b(' guint quark,') self.b(' DBusGProxy *proxy,') self.b(' gpointer unused G_GNUC_UNUSED)') self.b('{') for node in nodes: iface = node.getElementsByTagName('interface')[0] self.iface_dbus = iface.getAttribute('name') signals = node.getElementsByTagName('signal') if not signals: continue name = node.getAttribute('name').replace('/', '').lower() self.iface_uc = name.upper() self.b(' if (quark == %s)' % self.get_iface_quark()) self.b(' %s_add_signals_for_%s (proxy);' % (self.prefix_lc, name)) self.b('}') self.b('') self.h('G_END_DECLS') self.h('') if self.guard is not None: self.h('#endif /* defined (%s) */' % self.guard) self.h('') file_set_contents(self.basename + '.h', u('\n').join(self.__header).encode('utf-8')) file_set_contents(self.basename + '-body.h', u('\n').join(self.__body).encode('utf-8')) file_set_contents(self.basename + '-gtk-doc.h', u('\n').join(self.__docs).encode('utf-8'))