diff --git a/.gitignore b/.gitignore index f8855d3..000483c 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,11 @@ libtool ltmain.sh missing py-compile +cscope.files +cscope.out +lib/fcall-impr.h +lib/marshal.h +lib/searpc-dfun.h +lib/searpc-fcall.h +lib/searpc-signature.h +tests/test-searpc \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index 628a60f..994ae96 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/lib ACLOCAL_AMFLAGS = -I m4 -GNU_STANDARD_FILES = README COPYING COPYING.LESSER AUTHORS ChangeLog NEWS +GNU_STANDARD_FILES = README.markdown COPYING AUTHORS ChangeLog NEWS EXTRA_DIST = $(GNU_STANDARD_FILES) diff --git a/README.markdown b/README.markdown index 31de118..41429a2 100644 --- a/README.markdown +++ b/README.markdown @@ -20,7 +20,7 @@ contains three fields: Example -====== +======= Client ------ @@ -41,7 +41,7 @@ a SearpcClient object and supply a transport function. For example: * define a RPC function which takes a string argument and returns * an integer. The xxx_INT__STRING naming convention is used to * indicate the types of the param(string) and the return value(int). - */ + */ SEARPC_CLIENT_DEFUN_INT__STRING(searpc_strlen) /* create an rpc_client and supply the transport function. */ @@ -124,7 +124,7 @@ prototype of this function is: * function in the fucntion hash table. * signature: the identifier used to get the corresponding marshal. * Returns: a gboolean value indicating success or failure - */ + */ gboolean searpc_server_register_function (void *func, const gchar *fname, const gchar *signature) Before calling `searpc_server_register_function`, you need to call @@ -150,7 +150,7 @@ The prototype of `searpc_server_call_function` is: * len: The length of **`data`**. * ret_len: Place to hold the length of the JSON data stream to be returned * Returns: The JSON data containing the result of the RPC - */ + */ gchar* searpc_server_call_function (gchar *data, gsize len, gsize *ret_len) The value returned by `searpc_server_call_function()` is the JSON data @@ -183,7 +183,7 @@ See the demo program for a more detailed example. Demos -====== +===== There are well-commented demos in both C and Python. @@ -220,5 +220,3 @@ The following packages are required to build libsearpc: * gobject-2.0 >= 2.16.0 * json-glib-1.0 >= 0.10.2 * pygobject-2.0 >= 2.0 (if you choose to build pysearpc) - - diff --git a/configure.ac b/configure.ac index 989f227..130f33a 100644 --- a/configure.ac +++ b/configure.ac @@ -13,8 +13,6 @@ AM_INIT_AUTOMAKE([1.9 foreign]) AC_PROG_CC AC_PROG_LIBTOOL - - # Checks for header files. AC_CHECK_HEADERS([arpa/inet.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h]) @@ -43,7 +41,7 @@ AM_CONDITIONAL([COMPILE_DEMO], [test x${compile_demo} = xyes]) AC_ARG_ENABLE([compile-python], [AS_HELP_STRING([--enable-compile-python], [compile pysearpc @<:@default: no@:>@])], -[compile_python=${enableval}], [compile_python=no]) +[compile_python=${enableval}], [compile_python=yes]) AM_CONDITIONAL([COMPILE_PYTHON], [test x${compile_python} = xyes]) diff --git a/demo/searpc-demo-client.c b/demo/searpc-demo-client.c index 150fe3f..7d71ee6 100644 --- a/demo/searpc-demo-client.c +++ b/demo/searpc-demo-client.c @@ -27,7 +27,7 @@ static char *transport_callback(void *arg, const char *fcall_str, char buf[BUFLEN]; packet *pac, *pac_ret; - fd = (int) arg; + fd = (int)(long) arg; pac = (packet *)buf; /* construct the packet */ @@ -88,7 +88,7 @@ main(int argc, char *argv[]) /* create an rpc_client and supply the transport function. */ rpc_client = searpc_client_new(); rpc_client->transport = transport_callback; - rpc_client->arg = (void *)sockfd; + rpc_client->arg = (void *)(long)sockfd; /* call the client-side funcion */ ret = searpc_strlen(rpc_client, "hello searpc", &error); diff --git a/lib/Makefile.am b/lib/Makefile.am index 122ecac..0c7f919 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,38 +1,54 @@ -rpc_headers = fcall-impr.h searpc-fcall.h searpc-dfun.h searpc-signature.h searpc-marshal.h +# Five files are generated by a python script: +# Used in client: +# +# * fcall-impr.h: contains the implementation of functions like +# `searpc_client_fcall__string_string`. These function is used by the +# client to pack the RPC call to json data. +# * searpc-fcall.h: constains the declaration of the functions in fcall-impr.h +# * searpc-dfun.h: contains macros like `SEARPC_CLIENT_DEFUN_INT__STRING(funcname)`. +# +# Used in server: +# +# * searpc-signature.h: contains functions like `searpc_signature_int__string()`. +# * searpc-marshal.h: contains functions like `marshal_int__string()` +# -genrpc_files = gen-dfun-macro.py rpc_table.py +generated_sources = fcall-impr.h searpc-fcall.h searpc-dfun.h \ + searpc-signature.h marshal.h # rpc_headers = fcall-impr.h searpc-fcall.h searpc-dfun.h searpc-signature.h searpc-marshal.h AM_CFLAGS = @GLIB2_CFLAGS@ @GOBJECT_CFLAGS@ @JSON_GLIB_CFLAGS@ -I${top_builddir}/lib -I${top_srcdir}/lib -# we need to generate the headers first -BUILT_SOURCES = genrpc +# we need to generate the first +BUILT_SOURCES = gensource lib_LTLIBRARIES = libsearpc.la -include_HEADERS = searpc-client.h searpc-server.h searpc-utils.h +include_HEADERS = searpc-fcall.h searpc-client.h searpc-dfun.h searpc-server.h -libsearpc_la_SOURCES = searpc-client.c searpc-server.c +noinst_HEADERS = searpc-utils.h fcall-impr.h marshal.h -EXTRA_libsearpc_la_SOURCES = ${genrpc_files} +libsearpc_la_SOURCES = searpc-client.c searpc-server.c $(generated_sources) -libsearpc_la_LDFLAGS = -Wl,-z -Wl,defs -version-info 1:0:0 +libsearpc_la_LDFLAGS = -Wl,-z -Wl,defs -version-info 1:1:0 libsearpc_la_LIBADD = @GLIB2_LIBS@ @GOBJECT_LIBS@ @JSON_GLIB_LIBS@ +genrpc_files = gencode.py rpc_table.py -genrpc: ${rpc_headers} ${genrpc_files} +dist_data_DATA = ${genrpc_files} +gensource: ${generated_sources} -${rpc_headers}: ${genrpc_files} +${generated_sources}: gencode.py rpc_table.py @echo "[libsearpc]: generating rpc header files" - python $< gen-fcall > fcall-impr.h - python $< gen-fcall-declare > searpc-fcall.h - python $< gen-dfun-macro > searpc-dfun.h - python $< gen-signature > searpc-signature.h - python $< gen-marshal > searpc-marshal.h + python gencode.py gen-fcall > fcall-impr.h + python gencode.py gen-fcall-declare > searpc-fcall.h + python gencode.py gen-dfun-macro > searpc-dfun.h + python gencode.py gen-signature > searpc-signature.h + python gencode.py gen-marshal > marshal.h @echo "[libsearpc]: done" -CLEANFILES = ${rpc_headers} \ No newline at end of file +DISTCLEANFILES = ${generated_sources} \ No newline at end of file diff --git a/lib/gen-dfun-macro.py b/lib/gencode.py similarity index 99% rename from lib/gen-dfun-macro.py rename to lib/gencode.py index a8620b7..9a75659 100644 --- a/lib/gen-dfun-macro.py +++ b/lib/gencode.py @@ -342,3 +342,5 @@ if __name__ == "__main__": gen_fcall_declare_list() elif command == "gen-dfun-macro": gen_dfun_macro_list() + else: + print "Unknown command %s" % (command) diff --git a/lib/searpc-client.h b/lib/searpc-client.h index 7b51782..4abab89 100644 --- a/lib/searpc-client.h +++ b/lib/searpc-client.h @@ -13,6 +13,7 @@ typedef struct { } SearpcClient; SearpcClient *searpc_client_new (); + void searpc_client_free (SearpcClient *client); char* searpc_client_transport_send (SearpcClient *client, @@ -22,24 +23,23 @@ char* searpc_client_transport_send (SearpcClient *client, #include -/** - * searpc_client_fret__string: - * @data: the return string of RPC call - * @len: then length of @data - * @error: return location for a #GError, or %NULL - * - * Extract return value of type `char*` from the return string of RPC - * call. - */ -char* searpc_client_fret__string (char *data, size_t len, GError **error); -int searpc_client_fret__int (char *data, size_t len, GError **error); -GObject* searpc_client_fret__object (GType gtype, char *data, - size_t len, GError **error); -GList* searpc_client_fret__objlist (GType gtype, char *data, - size_t len, GError **error); +char* +searpc_client_fret__string (char *data, size_t len, GError **error); +int +searpc_client_fret__int (char *data, size_t len, GError **error); +GObject* +searpc_client_fret__object (GType gtype, char *data, + size_t len, GError **error); + +GList* +searpc_client_fret__objlist (GType gtype, char *data, + size_t len, GError **error); + +/* in case of transport error, the following code and message will be + * set in GError */ #define TRANSPORT_ERROR "Transport Error" #define TRANSPORT_ERROR_CODE 500 diff --git a/lib/searpc-server.c b/lib/searpc-server.c index 41b22ca..276515f 100644 --- a/lib/searpc-server.c +++ b/lib/searpc-server.c @@ -100,7 +100,7 @@ marshal_set_ret_common (JsonObject *object, gsize *len, GError *error) } /* include the generated marshal functions */ -#include +#include "marshal.h" void searpc_server_init () diff --git a/lib/searpc-server.h b/lib/searpc-server.h index e5d6348..2a358dc 100644 --- a/lib/searpc-server.h +++ b/lib/searpc-server.h @@ -54,6 +54,6 @@ gchar *searpc_server_call_function (gchar *func, gsize len, gsize *ret_len); char* searpc_compute_signature (gchar *ret_type, int pnum, ...); /* Signatures */ -#include "searpc-signature.h" +#include #endif diff --git a/pysearpc/Makefile.am b/pysearpc/Makefile.am index b0756b0..b6bd4b3 100644 --- a/pysearpc/Makefile.am +++ b/pysearpc/Makefile.am @@ -1,14 +1,16 @@ -EXTRA_DIST = pysearpc-demo-client.py -genrpc_files = pysearpc-gen-dfun-macro.py rpc_table.py +genrpc_files = pygencode.py rpc_table.py AM_CFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" \ -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \ @GLIB2_CFLAGS@ @PYGOBJECT_CFLAGS@ \ -I/usr/include/python$(PYTHON_VERSION) \ - -I${top_builddir}/lib -I${top_srcdir}/lib + -I${top_builddir}/lib \ + -I${top_srcdir}/lib -pkgpyexec_PYTHON = __init__.py client.py pysearpc-gen-dfun-macro.py +pkgpyexec_PYTHON = __init__.py client.py + +BUILT_SOURCES = fcallfret.h # generating the fcallfret module pkgpyexec_LTLIBRARIES = fcallfret.la @@ -17,11 +19,9 @@ fcallfret_la_LDFLAGS = -module -avoid-version -export-symbols-regex initfcallfre fcallfret_la_SOURCES = fcallfret.c fcallfret.h fcallfret_la_LIBADD = @GLIB2_LIBS@ @GOBJECT_LIBS@ $(top_builddir)/lib/libsearpc.la -EXTRA_fcallfret_la_SOURCES = ${genrpc_files} +dist_data_DATA = ${genrpc_files} -CLEANFILES = fcallfret.h +fcallfret.h: ${genrpc_files} + python pygencode.py > fcallfret.h -fcallfret.c: ${genrpc_files} - python $< gen-searpcclient > fcallfret.h - -.PHONY: fcallfret.c \ No newline at end of file +DISTCLEANFILES = fcallfret.h \ No newline at end of file diff --git a/pysearpc/pygencode.py b/pysearpc/pygencode.py new file mode 100644 index 0000000..682837d --- /dev/null +++ b/pysearpc/pygencode.py @@ -0,0 +1,173 @@ +#!/usr/bin/python + + +import string +import sys + +sys.path += ['../'] + +module_func_array_template = r""" +static PyMethodDef SearpcClientModule_Functions[] = { + ${array} + {NULL, NULL, 0, NULL}, +}; +""" + +func_item_template = r""" + {"${pyfuncname}", (PyCFunction)${cfuncname}, + METH_VARARGS, "" },""" + + +def gen_fcall_funcs_array(arg_types): + + fcall_array = "" + + if len(arg_types) == 0: + pyfuncname = "fcall__void" + cfuncname = "SearpcClient_Fcall__Void" + else: + pyfuncname = "fcall__" + "_".join(arg_types) + tmplist = [] + for arg in arg_types: + tmplist.append(string.capitalize(arg)) + + cfuncname = "SearpcClient_Fcall__" + "_".join(tmplist) + + return string.Template(func_item_template)\ + .substitute(pyfuncname=pyfuncname, + cfuncname=cfuncname) + + +def gen_fret_funcs_array(ret_type): + + fret_array = "" + + if ret_type is None: + pyfuncname = "fret__void" + cfuncname = "SearpcClient_Fret__Void" + else: + pyfuncname = "fret__" + ret_type + cfuncname = "SearpcClient_Fret__" + string.capitalize(ret_type) + + return string.Template(func_item_template)\ + .substitute(pyfuncname=pyfuncname, + cfuncname=cfuncname) + + +def gen_module_funcs_array(): + """ + Generate static PyMethodDef SearpcClientModule_Functions[] + """ + from rpc_table import func_table + + # generate fcall methods array + fcall_array = "" + arg_types_list = [] + for item in func_table: + if item[1] not in arg_types_list: + arg_types_list.append(item[1]) + + for item in arg_types_list: + fcall_array += gen_fcall_funcs_array(item) + + # generate fret methods array + fret_array = "" + ret_types_list = [] + for item in func_table: + if item[0] not in ret_types_list: + ret_types_list.append(item[0]) + + for item in ret_types_list: + fret_array += gen_fret_funcs_array(item) + + array = fcall_array + array += fret_array + + print string.Template(module_func_array_template)\ + .substitute(array=array) + + +type_table = { + "string" : ("char *", "s"), + "int" : ("int", "i"), + "object" : ("GObject *", "O"), +} + + +fcall_template = r""" +static PyObject * +SearpcClient_Fcall__${Suffix}(PyObject *self, + PyObject *args) +{ + char *fname; +${def_args} + char *fcall; + gsize len; + + if (!PyArg_ParseTuple(args, "${fmt}", ${args_addr})) + return NULL; + + fcall = searpc_client_fcall__${suffix}(${args}); + + return PyString_FromString(fcall); +} +""" + + +def gen_fcall_func(arg_types): + + if len(arg_types) == 0: + Suffix = "Void" + suffix = "void" + def_args = "" + kwargs_str = "NULL" + fmt = "s" + args_addr = "&fname" + args = "fname, &len" + return string.Template(fcall_template)\ + .substitute(Suffix=Suffix, suffix=suffix, + def_args=def_args, kwargs_str=kwargs_str, + fmt=fmt, args_addr=args_addr, args=args) + + tmplist = [] + for arg in arg_types: + tmplist.append(string.capitalize(arg)) + Suffix = "_".join(tmplist) + suffix = "_".join(arg_types) + def_args = "" + kwargs_str = "" + fmt = "s" + args_addr = "&fname" + args = "fname" + for i, arg_type in enumerate(arg_types): + def_args += " " + type_table[arg_type][0] + " param" + \ + str(i + 1) + ";\n" + kwargs_str += '"param' + str(i + 1) + '", ' + fmt += type_table[arg_type][1] + args_addr += ", ¶m" + str(i + 1) + args += ", param" + str(i + 1) + kwargs_str += "NULL" + args += ", &len" + return string.Template(fcall_template)\ + .substitute(Suffix=Suffix, suffix=suffix, + def_args=def_args, kwargs_str=kwargs_str, + fmt=fmt, args_addr=args_addr, args=args) + + +def gen_fcall_list(): + + from rpc_table import func_table + + arg_types_list = [] + for item in func_table: + if item[1] not in arg_types_list: + arg_types_list.append(item[1]) + + for item in arg_types_list: + print gen_fcall_func(item) + + +if __name__ == "__main__": + gen_fcall_list() + gen_module_funcs_array() + diff --git a/pysearpc/pysearpc-gen-dfun-macro.py b/pysearpc/pysearpc-gen-dfun-macro.py deleted file mode 100644 index fcfcd13..0000000 --- a/pysearpc/pysearpc-gen-dfun-macro.py +++ /dev/null @@ -1,357 +0,0 @@ -#!/usr/bin/python - -""" -Generate function define macros. -""" - -import string -import sys - -sys.path += ['../'] - - -# XXX: generate searpc-client.h file -module_func_array_template = r""" -static PyMethodDef SearpcClientModule_Functions[] = { - ${array} - {NULL, NULL, 0, NULL}, -}; -""" - -func_item_template = r""" - {"${pyfuncname}", (PyCFunction)${cfuncname}, - METH_VARARGS, "" },""" - - -def gen_fcall_funcs_array(arg_types): - - fcall_array = "" - - if len(arg_types) == 0: - pyfuncname = "fcall__void" - cfuncname = "SearpcClient_Fcall__Void" - else: - pyfuncname = "fcall__" + "_".join(arg_types) - tmplist = [] - for arg in arg_types: - tmplist.append(string.capitalize(arg)) - - cfuncname = "SearpcClient_Fcall__" + "_".join(tmplist) - - return string.Template(func_item_template)\ - .substitute(pyfuncname=pyfuncname, - cfuncname=cfuncname) - - -def gen_fret_funcs_array(ret_type): - - fret_array = "" - - if ret_type is None: - pyfuncname = "fret__void" - cfuncname = "SearpcClient_Fret__Void" - else: - pyfuncname = "fret__" + ret_type - cfuncname = "SearpcClient_Fret__" + string.capitalize(ret_type) - - return string.Template(func_item_template)\ - .substitute(pyfuncname=pyfuncname, - cfuncname=cfuncname) - - -def gen_module_funcs_array(): - - from rpc_table import func_table - - # generate fcall methods array - fcall_array = "" - arg_types_list = [] - for item in func_table: - if item[1] not in arg_types_list: - arg_types_list.append(item[1]) - - for item in arg_types_list: - fcall_array += gen_fcall_funcs_array(item) - - # generate fret methods array - fret_array = "" - ret_types_list = [] - for item in func_table: - if item[0] not in ret_types_list: - ret_types_list.append(item[0]) - - for item in ret_types_list: - fret_array += gen_fret_funcs_array(item) - - array = fcall_array - array += fret_array - - print string.Template(module_func_array_template)\ - .substitute(array=array) - - -type_table = { - "string" : ("char *", "s"), - "int" : ("int", "i"), - "object" : ("GObject *", "O"), -} - - -fcall_template = r""" -static PyObject * -SearpcClient_Fcall__${Suffix}(PyObject *self, - PyObject *args) -{ - char *fname; -${def_args} - char *fcall; - gsize len; - - if (!PyArg_ParseTuple(args, "${fmt}", ${args_addr})) - return NULL; - - fcall = searpc_client_fcall__${suffix}(${args}); - - return PyString_FromString(fcall); -} -""" - - -def gen_fcall_func(arg_types): - - if len(arg_types) == 0: - Suffix = "Void" - suffix = "void" - def_args = "" - kwargs_str = "NULL" - fmt = "s" - args_addr = "&fname" - args = "fname, &len" - return string.Template(fcall_template)\ - .substitute(Suffix=Suffix, suffix=suffix, - def_args=def_args, kwargs_str=kwargs_str, - fmt=fmt, args_addr=args_addr, args=args) - - tmplist = [] - for arg in arg_types: - tmplist.append(string.capitalize(arg)) - Suffix = "_".join(tmplist) - suffix = "_".join(arg_types) - def_args = "" - kwargs_str = "" - fmt = "s" - args_addr = "&fname" - args = "fname" - for i, arg_type in enumerate(arg_types): - def_args += " " + type_table[arg_type][0] + " param" + \ - str(i + 1) + ";\n" - kwargs_str += '"param' + str(i + 1) + '", ' - fmt += type_table[arg_type][1] - args_addr += ", ¶m" + str(i + 1) - args += ", param" + str(i + 1) - kwargs_str += "NULL" - args += ", &len" - return string.Template(fcall_template)\ - .substitute(Suffix=Suffix, suffix=suffix, - def_args=def_args, kwargs_str=kwargs_str, - fmt=fmt, args_addr=args_addr, args=args) - - -def gen_fcall_list(): - - from rpc_table import func_table - - arg_types_list = [] - for item in func_table: - if item[1] not in arg_types_list: - arg_types_list.append(item[1]) - - for item in arg_types_list: - print gen_fcall_func(item) - - -ret_table = { - "string" : "PyString_FromString", - "int" : "PyLong_FromLong", - "object" : "pygobject_new", -} - - -fret_template = r""" -static PyObject * -SearpcClient_Fret__${Suffix}(PyObject *self, - PyObject *args) -{ - char *data; -${def_args} - GError *error = NULL; - - if (!PyArg_ParseTuple(args, "${fmt}", ${args_addr})) - return NULL; - - res = searpc_client_fret__${suffix}(${args}, strlen(data), &error); - - return ${ret_func}; -} -""" - -fret_objlist_template = r""" -static PyObject *SearpcClient_Fret__Objlist(PyObject *self, - PyObject *args) -{ - char *data; - GType type; - PyObject *type_obj, *res, *tmp; - GList *list, *p; - GError *error = NULL; - static char *kwlist[] = { "type", "data", NULL }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os", - kwlist, &type_obj, &data)) - return NULL; - - type = pyg_type_from_object(type_obj); - list = searpc_client_fret__objlist(type, data, strlen(data), &error); - - res = PyList_New(0); - for (p = list; p; p = p->next) { - tmp = pygobject_new(p->data); - PyList_Append(res, tmp); - } - - return res; -} -""" - - -def gen_fret_func(ret_type): - - if ret_type == "objlist": - return fret_objlist_template - - Suffix = string.capitalize(ret_type) - suffix = ret_type - def_args = "" - kwargs_str = "" - fmt = "" - args_addr = "" - args = "" - if ret_type == "object": - def_args += " GType type;\n" - def_args += " PyObject *type_obj;\n" - def_args += " GObject *res;" - kwargs_str = '"type", "data", NULL' - fmt = "Os" - args_addr = "&type_obj, &data" - args = "type, data" - else: - def_args += " " + type_table[ret_type][0] + " res;" - kwargs_str = '"data", NULL' - fmt = "s" - args_addr = "&data" - args = "data" - - ret_func = ret_table[ret_type] + "(res);" - - return string.Template(fret_template)\ - .substitute(Suffix=Suffix, suffix=suffix, - def_args=def_args, kwargs_str=kwargs_str, - fmt=fmt, args_addr=args_addr, args=args, - ret_func=ret_func) - - -def gen_fret_list(): - - from rpc_table import func_table - - ret_type_list = [] - for item in func_table: - if item[0] not in ret_type_list: - ret_type_list.append(item[0]) - - for item in ret_type_list: - print gen_fret_func(item) - - -# XXX: generate searpc.py file -searpc_file_hdr_template = r""" -import os -import sys -sys.path += ['', '.libs'] -import json -import new -import types - -from searpc_client import SearpcClientBase -""" - -searpc_client_template = r""" -class SearpcClient(SearpcClientBase): - pass - -def searpc_client_transport_send(client, fcall): - return client.transport_send(fcall, client.priv) -""" - -searpc_defun_template = r""" -def defun_${ret_type}__${args_type}(func): - def newfunc(${args1}): - fcall = self.fcall__${args_type}(${args2}) - fret = searpc_client_transport_send(self, fcall) - if fret is None: - return None - return self.fret__${ret_type}(${obj_type}fret) - return newfunc -""" - -def gen_decorator(ret_type, args_type_list): - - if len(args_type_list) == 0: - args_type = "void" - args1 = "self" - args2 = "func.__name__" - - return string.Template(searpc_defun_template)\ - .substitute(ret_type=ret_type, args_type=args_type, - args1=args1, args2=args2, obj_type="") - - args_type = "_".join(args_type_list) - args1 = "self" - args2 = "func.__name__" - obj_type = "" - if ret_type == "object" or ret_type == "objlist": - args1 += ", obj_type" - obj_type = "obj_type, " - for i, arg_type in enumerate(args_type_list): - args1 += ", param" + str(i + 1) - args2 += ", param" + str(i + 1) - - return string.Template(searpc_defun_template)\ - .substitute(ret_type=ret_type, args_type=args_type, - args1=args1, args2=args2, obj_type=obj_type) - - -def gen_func_decorator(): - - from rpc_table import func_table - - for item in func_table: - print gen_decorator(item[0], item[1]) - - -def gen_pysearpc(): - print searpc_file_hdr_template - print searpc_client_template - gen_func_decorator() - - -if __name__ == "__main__": - cmd = sys.argv[1] - - if cmd == "gen-searpcclient": - gen_fcall_list() - gen_module_funcs_array() - elif cmd == "gen-pysearpc": - gen_pysearpc() - else: - print "arg error" diff --git a/pysearpc/rpc_table.py b/pysearpc/rpc_table.py deleted file mode 100644 index 5ae4dc5..0000000 --- a/pysearpc/rpc_table.py +++ /dev/null @@ -1,20 +0,0 @@ -""" -Define RPC functions needed to generate -""" - -# [ , [] ] -func_table = [ - [ "int", ["string"] ], - [ "int", ["string", "string"] ], - [ "string", [] ], - [ "string", ["string"] ], - [ "string", ["string", "int"] ], - [ "objlist", [] ], - [ "objlist", ["string"] ], - [ "objlist", ["int", "int"] ], - [ "objlist", ["string", "int"] ], - [ "objlist", ["string", "int", "int"] ], - [ "objlist", ["string", "string", "int"] ], - [ "object", [] ], - [ "object", ["string"] ], -] diff --git a/pysearpc/rpc_table.py b/pysearpc/rpc_table.py new file mode 120000 index 0000000..b2aad45 --- /dev/null +++ b/pysearpc/rpc_table.py @@ -0,0 +1 @@ +../lib/rpc_table.py \ No newline at end of file