diff --git a/Makefile.am b/Makefile.am index 92f8f0f..628a60f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,44 +1,16 @@ +AM_CPPFLAGS = -I$(top_srcdir)/lib + ACLOCAL_AMFLAGS = -I m4 -GNU_STANDARD_FILES = README README.markdown COPYING COPYING.LESSER AUTHORS ChangeLog News -EXTRA_DIST = $(GNU_STANDARD_FILES) rpc_table.py gen-dfun-macro.py -SUBDIRS = tests . pysearpc +GNU_STANDARD_FILES = README COPYING COPYING.LESSER AUTHORS ChangeLog NEWS -AM_CFLAGS = @GLIB2_CFLAGS@ @GOBJECT_CFLAGS@ \ - -I$(top_srcdir)/include -I$(top_srcdir)/include/ccnet \ - -I$(top_builddir)/include \ - @JSON_GLIB_CFLAGS@ +EXTRA_DIST = $(GNU_STANDARD_FILES) - -if COMPILE_DEMO -noinst_PROGRAMS = searpc-demo-server searpc-demo-client - -searpc_demo_server_SOURCES = searpc-demo-server.c searpc-demo-packet.h - -searpc_demo_server_LDADD = ./libsearpc.la - -searpc_demo_client_SOURCES = searpc-demo-client.c searpc-demo-packet.h - -searpc_demo_client_LDADD = ./libsearpc.la +if COMPILE_PYTHON + PYTHONDIR = pysearpc endif -# we need to generate the headers first -# BUILT_SOURCES = genrpc +if COMPILE_DEMO + MAKE_DEMO = demo +endif - -pkglib_LTLIBRARIES = libsearpc.la - -include_HEADERS = searpc-client.h searpc-server.h searpc-utils.h - -libsearpc_la_SOURCES = searpc-client.c searpc-server.c - -libsearpc_la_LDFLAGS = -Wl,-z -Wl,defs - -libsearpc_la_LIBADD = @GLIB2_LIBS@ @GOBJECT_LIBS@ \ - @JSON_GLIB_LIBS@ - -genrpc: gen-dfun-macro.py - python gen-dfun-macro.py gen-fcall > fcall-impr.h - python gen-dfun-macro.py gen-fcall-declare > searpc-fcall.h - python gen-dfun-macro.py gen-dfun-macro > searpc-dfun.h - python gen-dfun-macro.py gen-signature > searpc-signature.h - python gen-dfun-macro.py gen-marshal > searpc-marshal.h +SUBDIRS = lib ${PYTHONDIR} ${MAKE_DEMO} tests \ No newline at end of file diff --git a/configure.ac b/configure.ac index 4a3b9d9..6183eea 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.67]) AC_INIT([libsearpc], [1.0], [freeplant@gmail.com]) -AC_CONFIG_SRCDIR([searpc-server.c]) +AC_CONFIG_SRCDIR([lib/searpc-server.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) @@ -79,6 +79,8 @@ fi AC_CONFIG_FILES([Makefile + lib/Makefile + demo/Makefile pysearpc/Makefile tests/Makefile]) AC_OUTPUT diff --git a/demo/Makefile.am b/demo/Makefile.am new file mode 100644 index 0000000..06a6da3 --- /dev/null +++ b/demo/Makefile.am @@ -0,0 +1,12 @@ +AM_CFLAGS = @GLIB2_CFLAGS@ @GOBJECT_CFLAGS@ @JSON_GLIB_CFLAGS@ -I${top_builddir}/lib -I${top_srcdir}/lib + +noinst_PROGRAMS = searpc-demo-server searpc-demo-client + +searpc_demo_server_SOURCES = searpc-demo-server.c searpc-demo-packet.h + +searpc_demo_server_LDADD = ${top_builddir}/lib/libsearpc.la + +searpc_demo_client_SOURCES = searpc-demo-client.c searpc-demo-packet.h + +searpc_demo_client_LDADD = ${top_builddir}/lib/libsearpc.la + diff --git a/searpc-demo-client.c b/demo/searpc-demo-client.c similarity index 100% rename from searpc-demo-client.c rename to demo/searpc-demo-client.c diff --git a/searpc-demo-packet.h b/demo/searpc-demo-packet.h similarity index 100% rename from searpc-demo-packet.h rename to demo/searpc-demo-packet.h diff --git a/searpc-demo-server.c b/demo/searpc-demo-server.c similarity index 100% rename from searpc-demo-server.c rename to demo/searpc-demo-server.c diff --git a/fcall-impr.h b/fcall-impr.h deleted file mode 100644 index 5b1efc2..0000000 --- a/fcall-impr.h +++ /dev/null @@ -1,111 +0,0 @@ - -char* -searpc_client_fcall__string (const char* fname, const gchar* param1, gsize *len) -{ - JsonArray *array; - - g_return_val_if_fail (fname != NULL, NULL); - - array = json_array_new (); - json_array_add_string_element (array, fname); - json_array_add_string_or_null_element (array, param1); - - return fcall_common(array, len); -} - - -char* -searpc_client_fcall__string_string (const char* fname, const gchar* param1, const gchar* param2, gsize *len) -{ - JsonArray *array; - - g_return_val_if_fail (fname != NULL, NULL); - - array = json_array_new (); - json_array_add_string_element (array, fname); - json_array_add_string_or_null_element (array, param1); - json_array_add_string_or_null_element (array, param2); - - return fcall_common(array, len); -} - - -char* -searpc_client_fcall__void (const char* fname, gsize *len) -{ - JsonArray *array; - - g_return_val_if_fail (fname != NULL, NULL); - - array = json_array_new (); - json_array_add_string_element (array, fname); - - return fcall_common(array, len); -} - - -char* -searpc_client_fcall__string_int (const char* fname, const gchar* param1, int param2, gsize *len) -{ - JsonArray *array; - - g_return_val_if_fail (fname != NULL, NULL); - - array = json_array_new (); - json_array_add_string_element (array, fname); - json_array_add_string_or_null_element (array, param1); - json_array_add_int_element (array, param2); - - return fcall_common(array, len); -} - - -char* -searpc_client_fcall__int_int (const char* fname, int param1, int param2, gsize *len) -{ - JsonArray *array; - - g_return_val_if_fail (fname != NULL, NULL); - - array = json_array_new (); - json_array_add_string_element (array, fname); - json_array_add_int_element (array, param1); - json_array_add_int_element (array, param2); - - return fcall_common(array, len); -} - - -char* -searpc_client_fcall__string_int_int (const char* fname, const gchar* param1, int param2, int param3, gsize *len) -{ - JsonArray *array; - - g_return_val_if_fail (fname != NULL, NULL); - - array = json_array_new (); - json_array_add_string_element (array, fname); - json_array_add_string_or_null_element (array, param1); - json_array_add_int_element (array, param2); - json_array_add_int_element (array, param3); - - return fcall_common(array, len); -} - - -char* -searpc_client_fcall__string_string_int (const char* fname, const gchar* param1, const gchar* param2, int param3, gsize *len) -{ - JsonArray *array; - - g_return_val_if_fail (fname != NULL, NULL); - - array = json_array_new (); - json_array_add_string_element (array, fname); - json_array_add_string_or_null_element (array, param1); - json_array_add_string_or_null_element (array, param2); - json_array_add_int_element (array, param3); - - return fcall_common(array, len); -} - diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..c84507b --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,38 @@ + +rpc_headers = fcall-impr.h searpc-fcall.h searpc-dfun.h searpc-signature.h searpc-marshal.h + +genrpc_files = gen-dfun-macro.py rpc_table.py + +# 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 + +pkglib_LTLIBRARIES = libsearpc.la + +include_HEADERS = searpc-client.h searpc-server.h searpc-utils.h + +libsearpc_la_SOURCES = searpc-client.c searpc-server.c + +EXTRA_libsearpc_la_SOURCES = ${genrpc_files} + +libsearpc_la_LDFLAGS = -Wl,-z -Wl,defs + +libsearpc_la_LIBADD = @GLIB2_LIBS@ @GOBJECT_LIBS@ @JSON_GLIB_LIBS@ + + +genrpc: ${rpc_headers} ${genrpc_files} + + +${rpc_headers}: ${genrpc_files} + @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 + @echo "[libsearpc]: done" + +CLEANFILES = ${rpc_headers} \ No newline at end of file diff --git a/gen-dfun-macro.py b/lib/gen-dfun-macro.py similarity index 100% rename from gen-dfun-macro.py rename to lib/gen-dfun-macro.py diff --git a/rpc_table.py b/lib/rpc_table.py similarity index 100% rename from rpc_table.py rename to lib/rpc_table.py diff --git a/searpc-client.c b/lib/searpc-client.c similarity index 100% rename from searpc-client.c rename to lib/searpc-client.c diff --git a/searpc-client.h b/lib/searpc-client.h similarity index 100% rename from searpc-client.h rename to lib/searpc-client.h diff --git a/searpc-server.c b/lib/searpc-server.c similarity index 100% rename from searpc-server.c rename to lib/searpc-server.c diff --git a/searpc-server.h b/lib/searpc-server.h similarity index 97% rename from searpc-server.h rename to lib/searpc-server.h index 2a358dc..e5d6348 100644 --- a/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 +#include "searpc-signature.h" #endif diff --git a/searpc-utils.h b/lib/searpc-utils.h similarity index 100% rename from searpc-utils.h rename to lib/searpc-utils.h diff --git a/pysearpc/Makefile.am b/pysearpc/Makefile.am index 71dc229..b0756b0 100644 --- a/pysearpc/Makefile.am +++ b/pysearpc/Makefile.am @@ -1,28 +1,27 @@ EXTRA_DIST = pysearpc-demo-client.py +genrpc_files = pysearpc-gen-dfun-macro.py rpc_table.py + AM_CFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" \ -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \ - -I$(top_srcdir) \ - -I$(top_srcdir)/include \ - @GLIB2_CFLAGS@ \ - @PYGOBJECT_CFLAGS@ \ - -I/usr/include/python$(PYTHON_VERSION) + @GLIB2_CFLAGS@ @PYGOBJECT_CFLAGS@ \ + -I/usr/include/python$(PYTHON_VERSION) \ + -I${top_builddir}/lib -I${top_srcdir}/lib -if COMPILE_PYTHON -pkgpyexec_PYTHON = __init__.py client.py gen-dfun-macro.py +pkgpyexec_PYTHON = __init__.py client.py pysearpc-gen-dfun-macro.py # generating the fcallfret module pkgpyexec_LTLIBRARIES = fcallfret.la fcallfret_la_LDFLAGS = -module -avoid-version -export-symbols-regex initfcallfret fcallfret_la_SOURCES = fcallfret.c fcallfret.h -fcallfret_la_LIBADD = @GLIB2_LIBS@ @GOBJECT_LIBS@ $(top_builddir)/libsearpc.la +fcallfret_la_LIBADD = @GLIB2_LIBS@ @GOBJECT_LIBS@ $(top_builddir)/lib/libsearpc.la + +EXTRA_fcallfret_la_SOURCES = ${genrpc_files} CLEANFILES = fcallfret.h -fcallfret.c: gen-dfun-macro.py +fcallfret.c: ${genrpc_files} python $< gen-searpcclient > fcallfret.h -.PHONY: fcallfret.c -endif - +.PHONY: fcallfret.c \ No newline at end of file diff --git a/pysearpc/fcallfret.c b/pysearpc/fcallfret.c index b4bac28..b9c03a3 100644 --- a/pysearpc/fcallfret.c +++ b/pysearpc/fcallfret.c @@ -24,7 +24,7 @@ #include #include -#include <../searpc-client.h> +#include <../lib/searpc-client.h> #include static PyObject *SearpcError; diff --git a/pysearpc/gen-dfun-macro.py b/pysearpc/pysearpc-gen-dfun-macro.py similarity index 100% rename from pysearpc/gen-dfun-macro.py rename to pysearpc/pysearpc-gen-dfun-macro.py diff --git a/pysearpc/pysearpc_transport.py b/pysearpc/pysearpc_transport.py deleted file mode 100644 index 565a501..0000000 --- a/pysearpc/pysearpc_transport.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -import sys -sys.path += ['', '.libs'] - -RPC_PROC_ID = 1003 - -SC_CLIENT_CALL = "301" -SS_CLIENT_CALL = "CLIENT CALL" -SC_SERVER_RET = "311" -SS_SERVER_RET = "SERVER RET" - - -def searpc_transport_send(fcall, priv): - - if priv.peerid is None: - proc_name = "%s-rpcserver" % (priv.service) - else: - proc_name = "remote %s %s-rpcserver" % (priv.peerid, priv.service) - - priv.session.send_request(RPC_PROC_ID, proc_name) - if priv.session.read_response() < 0: - return None - rsp = priv.session.response - if rsp[0] != "200": - print "[Sea RPC] failed to start rpc server.\n" - return None - - priv.session.send_update(RPC_PROC_ID, "301", "CLIENT CALL", - fcall, len(fcall)) - if priv.session.read_response() < 0: - return None - rsp = priv.session.response - if rsp[0] == SC_SERVER_RET: - return rsp[2] - else: - print "[Sea RPC] Bad response: %s %s.\n" % (rsp[0], rsp[1]) - return None diff --git a/pysearpc/rpc_table.py b/pysearpc/rpc_table.py new file mode 100644 index 0000000..5ae4dc5 --- /dev/null +++ b/pysearpc/rpc_table.py @@ -0,0 +1,20 @@ +""" +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/searpc-dfun.h b/searpc-dfun.h deleted file mode 100644 index 458815f..0000000 --- a/searpc-dfun.h +++ /dev/null @@ -1,351 +0,0 @@ - -#define SEARPC_CLIENT_DEFUN_INT__STRING(funcname) \ -int \ -funcname (SearpcClient *client, const gchar* param1, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - int result; \ - \ - fcall = searpc_client_fcall__string (#funcname, \ - param1, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return -1; \ - } \ - result = searpc_client_fret__int (fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_INT__STRING_STRING(funcname) \ -int \ -funcname (SearpcClient *client, const gchar* param1, const gchar* param2, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - int result; \ - \ - fcall = searpc_client_fcall__string_string (#funcname, \ - param1, param2, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return -1; \ - } \ - result = searpc_client_fret__int (fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_STRING__VOID(funcname) \ -gchar* \ -funcname (SearpcClient *client, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - gchar* result; \ - \ - fcall = searpc_client_fcall__void (#funcname, \ - &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__string (fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_STRING__STRING(funcname) \ -gchar* \ -funcname (SearpcClient *client, const gchar* param1, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - gchar* result; \ - \ - fcall = searpc_client_fcall__string (#funcname, \ - param1, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__string (fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_STRING__STRING_INT(funcname) \ -gchar* \ -funcname (SearpcClient *client, const gchar* param1, int param2, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - gchar* result; \ - \ - fcall = searpc_client_fcall__string_int (#funcname, \ - param1, param2, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__string (fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_OBJLIST__VOID(funcname, gtype) \ -GList* \ -funcname (SearpcClient *client, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - GList* result; \ - \ - fcall = searpc_client_fcall__void (#funcname, \ - &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__objlist (gtype, fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_OBJLIST__STRING(funcname, gtype) \ -GList* \ -funcname (SearpcClient *client, const gchar* param1, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - GList* result; \ - \ - fcall = searpc_client_fcall__string (#funcname, \ - param1, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__objlist (gtype, fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_OBJLIST__INT_INT(funcname, gtype) \ -GList* \ -funcname (SearpcClient *client, int param1, int param2, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - GList* result; \ - \ - fcall = searpc_client_fcall__int_int (#funcname, \ - param1, param2, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__objlist (gtype, fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_OBJLIST__STRING_INT(funcname, gtype) \ -GList* \ -funcname (SearpcClient *client, const gchar* param1, int param2, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - GList* result; \ - \ - fcall = searpc_client_fcall__string_int (#funcname, \ - param1, param2, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__objlist (gtype, fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_OBJLIST__STRING_INT_INT(funcname, gtype) \ -GList* \ -funcname (SearpcClient *client, const gchar* param1, int param2, int param3, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - GList* result; \ - \ - fcall = searpc_client_fcall__string_int_int (#funcname, \ - param1, param2, param3, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__objlist (gtype, fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_OBJLIST__STRING_STRING_INT(funcname, gtype) \ -GList* \ -funcname (SearpcClient *client, const gchar* param1, const gchar* param2, int param3, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - GList* result; \ - \ - fcall = searpc_client_fcall__string_string_int (#funcname, \ - param1, param2, param3, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__objlist (gtype, fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_OBJECT__VOID(funcname, gtype) \ -GObject* \ -funcname (SearpcClient *client, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - GObject* result; \ - \ - fcall = searpc_client_fcall__void (#funcname, \ - &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__object (gtype, fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - - -#define SEARPC_CLIENT_DEFUN_OBJECT__STRING(funcname, gtype) \ -GObject* \ -funcname (SearpcClient *client, const gchar* param1, GError **error) \ -{ \ - char *fcall, *fret; \ - size_t fcall_len, ret_len; \ - GObject* result; \ - \ - fcall = searpc_client_fcall__string (#funcname, \ - param1, &fcall_len); \ - fret = searpc_client_transport_send (client, \ - fcall, \ - fcall_len, \ - &ret_len); \ - if (!fret) { \ - g_free (fcall); \ - g_set_error (error, 0, TRANSPORT_ERROR_CODE, TRANSPORT_ERROR); \ - return NULL; \ - } \ - result = searpc_client_fret__object (gtype, fret, ret_len, error); \ - \ - g_free (fcall); \ - g_free (fret); \ - return result; \ -} - diff --git a/searpc-fcall.h b/searpc-fcall.h deleted file mode 100644 index f2a71e9..0000000 --- a/searpc-fcall.h +++ /dev/null @@ -1,21 +0,0 @@ - -char* searpc_client_fcall__string (const char* fname, const gchar* param1, gsize *len); - - -char* searpc_client_fcall__string_string (const char* fname, const gchar* param1, const gchar* param2, gsize *len); - - -char* searpc_client_fcall__void (const char* fname, gsize *len); - - -char* searpc_client_fcall__string_int (const char* fname, const gchar* param1, int param2, gsize *len); - - -char* searpc_client_fcall__int_int (const char* fname, int param1, int param2, gsize *len); - - -char* searpc_client_fcall__string_int_int (const char* fname, const gchar* param1, int param2, int param3, gsize *len); - - -char* searpc_client_fcall__string_string_int (const char* fname, const gchar* param1, const gchar* param2, int param3, gsize *len); - diff --git a/searpc-marshal.h b/searpc-marshal.h deleted file mode 100644 index eea3c96..0000000 --- a/searpc-marshal.h +++ /dev/null @@ -1,281 +0,0 @@ - -static gchar * -marshal_int__string (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - - int ret = ((int (*)(const gchar*, GError **))func) (param1, &error); - - JsonObject *object = json_object_new (); - set_int_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_int__string_string (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - const gchar* param2 = json_array_get_string_or_null_element (param_array, 2); - - int ret = ((int (*)(const gchar*, const gchar*, GError **))func) (param1, param2, &error); - - JsonObject *object = json_object_new (); - set_int_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_string__void (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - - gchar* ret = ((gchar* (*)(GError **))func) (&error); - - JsonObject *object = json_object_new (); - set_string_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_string__string (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - - gchar* ret = ((gchar* (*)(const gchar*, GError **))func) (param1, &error); - - JsonObject *object = json_object_new (); - set_string_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_string__string_int (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - int param2 = json_array_get_int_element (param_array, 2); - - gchar* ret = ((gchar* (*)(const gchar*, int, GError **))func) (param1, param2, &error); - - JsonObject *object = json_object_new (); - set_string_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_objlist__void (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - - GList* ret = ((GList* (*)(GError **))func) (&error); - - JsonObject *object = json_object_new (); - set_objlist_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_objlist__string (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - - GList* ret = ((GList* (*)(const gchar*, GError **))func) (param1, &error); - - JsonObject *object = json_object_new (); - set_objlist_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_objlist__int_int (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - int param1 = json_array_get_int_element (param_array, 1); - int param2 = json_array_get_int_element (param_array, 2); - - GList* ret = ((GList* (*)(int, int, GError **))func) (param1, param2, &error); - - JsonObject *object = json_object_new (); - set_objlist_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_objlist__string_int (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - int param2 = json_array_get_int_element (param_array, 2); - - GList* ret = ((GList* (*)(const gchar*, int, GError **))func) (param1, param2, &error); - - JsonObject *object = json_object_new (); - set_objlist_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_objlist__string_int_int (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - int param2 = json_array_get_int_element (param_array, 2); - int param3 = json_array_get_int_element (param_array, 3); - - GList* ret = ((GList* (*)(const gchar*, int, int, GError **))func) (param1, param2, param3, &error); - - JsonObject *object = json_object_new (); - set_objlist_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_objlist__string_string_int (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - const gchar* param2 = json_array_get_string_or_null_element (param_array, 2); - int param3 = json_array_get_int_element (param_array, 3); - - GList* ret = ((GList* (*)(const gchar*, const gchar*, int, GError **))func) (param1, param2, param3, &error); - - JsonObject *object = json_object_new (); - set_objlist_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_object__void (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - - GObject* ret = ((GObject* (*)(GError **))func) (&error); - - JsonObject *object = json_object_new (); - set_object_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - - -static gchar * -marshal_object__string (void *func, JsonArray *param_array, gsize *ret_len) -{ - GError *error = NULL; - const gchar* param1 = json_array_get_string_or_null_element (param_array, 1); - - GObject* ret = ((GObject* (*)(const gchar*, GError **))func) (param1, &error); - - JsonObject *object = json_object_new (); - set_object_to_ret_object (object, ret); - return marshal_set_ret_common (object, ret_len, error); -} - -static void register_marshals(GHashTable *marshal_table) -{ - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_int__string; - item->signature = searpc_signature_int__string(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_int__string_string; - item->signature = searpc_signature_int__string_string(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_string__void; - item->signature = searpc_signature_string__void(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_string__string; - item->signature = searpc_signature_string__string(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_string__string_int; - item->signature = searpc_signature_string__string_int(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_objlist__void; - item->signature = searpc_signature_objlist__void(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_objlist__string; - item->signature = searpc_signature_objlist__string(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_objlist__int_int; - item->signature = searpc_signature_objlist__int_int(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_objlist__string_int; - item->signature = searpc_signature_objlist__string_int(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_objlist__string_int_int; - item->signature = searpc_signature_objlist__string_int_int(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_objlist__string_string_int; - item->signature = searpc_signature_objlist__string_string_int(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_object__void; - item->signature = searpc_signature_object__void(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } - - { - MarshalItem *item = g_new0(MarshalItem, 1); - item->mfunc = marshal_object__string; - item->signature = searpc_signature_object__string(); - g_hash_table_insert (marshal_table, (gpointer)item->signature, item); - } -} diff --git a/searpc-signature.h b/searpc-signature.h deleted file mode 100644 index 9100e18..0000000 --- a/searpc-signature.h +++ /dev/null @@ -1,91 +0,0 @@ - -inline static const gchar * -searpc_signature_int__string() -{ - return searpc_compute_signature ("int", 1, "string"); -} - - -inline static const gchar * -searpc_signature_int__string_string() -{ - return searpc_compute_signature ("int", 2, "string", "string"); -} - - -inline static const gchar * -searpc_signature_string__void() -{ - return searpc_compute_signature ("string", 0); -} - - -inline static const gchar * -searpc_signature_string__string() -{ - return searpc_compute_signature ("string", 1, "string"); -} - - -inline static const gchar * -searpc_signature_string__string_int() -{ - return searpc_compute_signature ("string", 2, "string", "int"); -} - - -inline static const gchar * -searpc_signature_objlist__void() -{ - return searpc_compute_signature ("objlist", 0); -} - - -inline static const gchar * -searpc_signature_objlist__string() -{ - return searpc_compute_signature ("objlist", 1, "string"); -} - - -inline static const gchar * -searpc_signature_objlist__int_int() -{ - return searpc_compute_signature ("objlist", 2, "int", "int"); -} - - -inline static const gchar * -searpc_signature_objlist__string_int() -{ - return searpc_compute_signature ("objlist", 2, "string", "int"); -} - - -inline static const gchar * -searpc_signature_objlist__string_int_int() -{ - return searpc_compute_signature ("objlist", 3, "string", "int", "int"); -} - - -inline static const gchar * -searpc_signature_objlist__string_string_int() -{ - return searpc_compute_signature ("objlist", 3, "string", "string", "int"); -} - - -inline static const gchar * -searpc_signature_object__void() -{ - return searpc_compute_signature ("object", 0); -} - - -inline static const gchar * -searpc_signature_object__string() -{ - return searpc_compute_signature ("object", 1, "string"); -} - diff --git a/tests/Makefile.am b/tests/Makefile.am index 29607d5..5bd1676 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,13 +1,13 @@ -AM_CFLAGS = -I$(top_srcdir)/include @GLIB2_CFLAGS@ @GOBJECT_CFLAGS@ \ - -I$(top_srcdir)/lib -I$(top_srcdir)/lib/searpc \ - @JSON_GLIB_CFLAGS@ +AM_CFLAGS = @GLIB2_CFLAGS@ @GOBJECT_CFLAGS@ @JSON_GLIB_CFLAGS@ \ + -I${top_builddir}/lib -I${top_srcdir}/lib + check_PROGRAMS = test-searpc test_searpc_SOURCES = test-searpc.c test_searpc_LDADD = @GLIB2_LIBS@ @GOBJECT_LIBS@ \ - $(top_builddir)/libsearpc.la + $(top_builddir)/lib/libsearpc.la test_searpc_LDFLAGS = -static TESTS = test-searpc