#!/usr/bin/python import sys typemap = { # C types 'unsigned int': ['xmlrpc_int32', 'i'], 'char*': ['const char*', 's'], # Khep types 'khep_hand_t': ['xmlrpc_int32', 'i'], 'khep_speed_t': ['xmlrpc_int32', 'i'], 'khep_cmd_ret_code_t': ['xmlrpc_int32', 'i'], 'led_t': ['xmlrpc_int32', 'i'], 'led_status_t': ['xmlrpc_int32', 'i'] } # List of functions to export funcs = [ ['khep_cmd_ret_code_t', 'khep_cmd_config_speedctrl', ['khep_hand_t', 'unsigned int', 'unsigned int', 'unsigned int']], ['khep_cmd_ret_code_t', 'khep_cmd_setled', ['khep_hand_t', 'led_t', 'led_status_t']] ] #FIXME: max arg count = 26 def produce_xmlrpc_skel(f, s): varname = 'a' typetuple = "" s.write("static xmlrpc_value *\n") s.write("rpc_%s (xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) {\n" % f[1]) # Declare variables for arg in f[2]: s.write("%s %s;\n" % (typemap[arg][0], varname)) varname = chr(ord(varname)+1) typetuple += typemap[arg][1] s.write("xmlrpc_parse_value(env, param_array, \"(%s)\"," % (typetuple)) for i in range(ord('a'), ord(varname)-1): s.write("&%s," % chr(i)) s.write("&%s);\n" % chr(ord(varname)-1)) s.write("if ( env->fault_occurred ) return NULL;\n") s.write("%s res = %s(" % (typemap[f[0]][0], f[1])) s.write("handles[a].fd,") for i in range(ord('b'), ord(varname)-1): s.write("%s," % chr(i)) s.write("%s);\n" % chr(ord(varname)-1)) s.write("return xmlrpc_build_value(env, \"%s\", res);\n" % typemap[f[0]][1]) s.write("}\n") ### s = open("functions.h", "w") for f in funcs: produce_xmlrpc_skel(f, s) s.close()