#! /usr/bin/python # Copyright (C) 2008 OpenedHand Ltd # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 2, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin # St, Fifth Floor, Boston, MA 02110-1301 USA import sys import xml.etree.ElementTree as ET xml = ET.parse(sys.argv[1]) class Argument: name = None direction = None gtype = None ctype = None def findStateArgType(name): for argElement in xml.findall("{urn:schemas-upnp-org:service-1-0}serviceStateTable/{urn:schemas-upnp-org:service-1-0}stateVariable"): arg_name = argElement.find("{urn:schemas-upnp-org:service-1-0}name").text if arg_name == name: return argElement.find("{urn:schemas-upnp-org:service-1-0}dataType").text return None def mapTypes(argElement, arg): dataType = findStateArgType(argElement.find("{urn:schemas-upnp-org:service-1-0}relatedStateVariable").text) if dataType == "string": arg.ctype = "char *" arg.gtype = "G_TYPE_STRING" elif dataType == "ui2": # Stupid GType doesn't have short types, so use an int anyway. arg.ctype = "unsigned int" arg.gtype = "G_TYPE_UINT" elif dataType == "ui4": arg.ctype = "unsigned int" arg.gtype = "G_TYPE_UINT" elif dataType == "boolean": arg.ctype = "gboolean" arg.gtype = "G_TYPE_BOOLEAN" else: raise Exception("Unknown dataType %s" % dataType) for actionElement in xml.findall("{urn:schemas-upnp-org:service-1-0}actionList/{urn:schemas-upnp-org:service-1-0}action"): function_name = actionElement.find("{urn:schemas-upnp-org:service-1-0}name").text print "static inline gboolean" print "%s (GUPnPServiceProxy *proxy," % function_name in_args = [] out_args = [] for argElement in actionElement.findall("{urn:schemas-upnp-org:service-1-0}argumentList/{urn:schemas-upnp-org:service-1-0}argument"): arg = Argument() arg.name = argElement.find("{urn:schemas-upnp-org:service-1-0}name").text arg.direction = argElement.find("{urn:schemas-upnp-org:service-1-0}direction").text arg.ctype = "char*" arg.gtype = "G_TYPE_STRING" mapTypes(argElement, arg) if arg.direction == "in": in_args.append(arg) else: out_args.append(arg) indent = (2 + len (function_name)) * " " for arg in in_args: print "%s%s in_%s," % (indent, arg.ctype, arg.name) for arg in out_args: print "%s%s* out_%s," % (indent, arg.ctype, arg.name) print "%sGError **error)\n{" % indent print " return gupnp_service_proxy_send_action (proxy, \"%s\", error, " % function_name for arg in in_args: print " \"%s\", %s, in_%s," % (arg.name, arg.gtype, arg.name) print " NULL, " for arg in out_args: print " \"%s\", %s, out_%s," % (arg.name, arg.gtype, arg.name) print " NULL" print " );" print "}\n"