1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-08-10 17:01:36 +00:00

Rename gencode.py to searpc-codegen.py

Other projects should use searpc-codegen.py to generate its
specific marshal functions and register to server
This commit is contained in:
plt 2012-06-07 20:00:21 +08:00
parent a9c5f4d06b
commit b86dfb60a1
2 changed files with 23 additions and 33 deletions

View File

@ -1,17 +1,10 @@
# Five files are generated by a python script: # Two 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: # Used in server:
# #
# * searpc-signature.h: contains functions like `searpc_signature_int__string()`. # * searpc-signature.h: contains functions like `searpc_signature_int__string()`.
# * searpc-marshal.h: contains functions like `marshal_int__string()` # * marshal.h: contains functions like `marshal_int__string()`
# #
generated_sources = searpc-signature.h marshal.h generated_sources = searpc-signature.h marshal.h
@ -41,16 +34,15 @@ libsearpc_la_LDFLAGS = -version-info 1:2:0 -no-undefined
libsearpc_la_LIBADD = @GLIB_LIBS@ \ libsearpc_la_LIBADD = @GLIB_LIBS@ \
${top_builddir}/json-glib/json-glib/libsearpc-json-glib.la ${top_builddir}/json-glib/json-glib/libsearpc-json-glib.la
genrpc_files = gencode.py rpc_table.py dist_bin_SCRIPTS = searpc-codegen.py
EXTRA_DIST = ${genrpc_files} EXTRA_DIST = rpc_table.py
gensource: ${generated_sources} gensource: ${generated_sources}
${generated_sources}: gencode.py rpc_table.py ${generated_sources}: searpc-codegen.py rpc_table.py
@echo "[libsearpc]: generating rpc header files" @echo "[libsearpc]: generating rpc header files"
python gencode.py gen-signature > searpc-signature.h python searpc-codegen.py rpc_table.py
python gencode.py gen-marshal > marshal.h
@echo "[libsearpc]: done" @echo "[libsearpc]: done"
DISTCLEANFILES = ${generated_sources} DISTCLEANFILES = ${generated_sources}

View File

@ -101,16 +101,15 @@ def generate_marshal(ret_type, arg_types):
def gen_marshal_functions(): def gen_marshal_functions():
from rpc_table import func_table from rpc_table import func_table
f = open('marshal.h', 'w')
for item in func_table: for item in func_table:
print generate_marshal(item[0], item[1]) print >>f, generate_marshal(item[0], item[1])
f.close()
marshal_register_item = r""" marshal_register_item = r"""
{ {
MarshalItem *item = g_new0(MarshalItem, 1); searpc_server_register_marshal (${signature_name}(), ${marshal_name});
item->mfunc = ${marshal_name};
item->signature = ${signature_name}();
g_hash_table_insert (marshal_table, (gpointer)item->signature, item);
} }
""" """
@ -132,11 +131,13 @@ def generate_marshal_register_item(ret_type, arg_types):
def gen_marshal_register_function(): def gen_marshal_register_function():
from rpc_table import func_table from rpc_table import func_table
print "static void register_marshals(GHashTable *marshal_table)""" f = open('marshal.h', 'a')
print "{" print >>f, "static void register_marshals()"""
print >>f, "{"
for item in func_table: for item in func_table:
print generate_marshal_register_item(item[0], item[1]), print >>f, generate_marshal_register_item(item[0], item[1]),
print "}" print >>f, "}"
f.close()
signature_template = r""" signature_template = r"""
inline static gchar * inline static gchar *
@ -165,16 +166,13 @@ def generate_signature(ret_type, arg_types):
def gen_signature_list(): def gen_signature_list():
from rpc_table import func_table from rpc_table import func_table
f = open('searpc-signature.h', 'w')
for item in func_table: for item in func_table:
print generate_signature(item[0], item[1]) print >>f,generate_signature(item[0], item[1])
f.close()
if __name__ == "__main__": if __name__ == "__main__":
command = sys.argv[1] gen_marshal_functions()
if command == "gen-marshal": gen_marshal_register_function()
gen_marshal_functions() gen_signature_list()
gen_marshal_register_function()
elif command == "gen-signature":
gen_signature_list()
else:
print "Unknown command %s" % (command)