mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-05-11 00:24:20 +00:00
Outside build libsearpc.
This commit is contained in:
parent
3ff1ecd4d3
commit
d97e9e997a
@ -1,12 +1,21 @@
|
||||
generated_sources = searpc-signature.h marshal.h
|
||||
|
||||
AM_CFLAGS = @GLIB_CFLAGS@ \
|
||||
-I${top_srcdir}/lib
|
||||
-I${top_srcdir}/lib \
|
||||
-I${top_srcdir}/json-glib
|
||||
|
||||
# we need to generate the first
|
||||
BUILT_SOURCES = gensource
|
||||
|
||||
noinst_HEADERS = marshal.h
|
||||
|
||||
noinst_PROGRAMS = searpc-demo-server searpc-demo-client searpc-async-client
|
||||
|
||||
searpc_demo_server_SOURCES = searpc-demo-server.c searpc-demo-packet.h
|
||||
|
||||
searpc_demo_server_LDADD = ${top_builddir}/lib/libsearpc.la @LIB_WS32@ \
|
||||
@GLIB_CFLAGS@
|
||||
@GLIB_CFLAGS@ \
|
||||
${top_builddir}/json-glib/json-glib/libsearpc-json-glib.la
|
||||
|
||||
searpc_demo_client_SOURCES = searpc-demo-client.c searpc-demo-packet.h
|
||||
|
||||
@ -18,3 +27,13 @@ searpc_async_client_SOURCES = demo-async-client.c searpc-demo-packet.h
|
||||
searpc_async_client_LDADD = ${top_builddir}/lib/libsearpc.la @LIB_WS32@ \
|
||||
@GLIB_CFLAGS@
|
||||
|
||||
EXTRA_DIST = rpc_table.py
|
||||
|
||||
gensource: ${generated_sources}
|
||||
|
||||
${generated_sources}: rpc_table.py
|
||||
@echo "[libsearpc]: generating rpc header files"
|
||||
python ${top_srcdir}/lib/searpc-codegen.py rpc_table.py
|
||||
@echo "[libsearpc]: done"
|
||||
|
||||
DISTCLEANFILES = ${generated_sources}
|
||||
|
8
demo/rpc_table.py
Normal file
8
demo/rpc_table.py
Normal file
@ -0,0 +1,8 @@
|
||||
"""
|
||||
Define RPC functions needed to generate
|
||||
"""
|
||||
|
||||
# [ <ret-type>, [<arg_types>] ]
|
||||
func_table = [
|
||||
[ "int", ["string"] ],
|
||||
]
|
@ -7,6 +7,9 @@
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "json-glib/json-glib.h"
|
||||
#include "searpc-utils.h"
|
||||
|
||||
#include "searpc-server.h"
|
||||
#include "searpc-demo-packet.h"
|
||||
#define BUFLEN 256
|
||||
@ -31,10 +34,13 @@ searpc_strlen(const char *str)
|
||||
return strlen(str);
|
||||
}
|
||||
|
||||
#include "searpc-signature.h"
|
||||
#include "marshal.h"
|
||||
|
||||
static void
|
||||
start_rpc_service(void)
|
||||
{
|
||||
searpc_server_init();
|
||||
searpc_server_init(register_marshals);
|
||||
searpc_create_service("searpc-demo");
|
||||
|
||||
/* The first parameter is the implementation function.
|
||||
|
@ -7,25 +7,17 @@
|
||||
# * marshal.h: contains functions like `marshal_int__string()`
|
||||
#
|
||||
|
||||
generated_sources = searpc-signature.h marshal.h
|
||||
|
||||
# rpc_headers = fcall-impr.h searpc-fcall.h searpc-dfun.h searpc-signature.h searpc-marshal.h
|
||||
|
||||
AM_CFLAGS = @GLIB_CFLAGS@ \
|
||||
-I${top_builddir}/lib \
|
||||
-I${top_srcdir}/json-glib \
|
||||
-I${top_srcdir}/lib \
|
||||
-DG_LOG_DOMAIN=\"Searpc\"
|
||||
|
||||
# we need to generate the first
|
||||
BUILT_SOURCES = gensource
|
||||
|
||||
lib_LTLIBRARIES = libsearpc.la
|
||||
|
||||
include_HEADERS = searpc-client.h \
|
||||
searpc-server.h searpc-signature.h searpc-utils.h
|
||||
include_HEADERS = searpc-client.h searpc-server.h searpc-utils.h
|
||||
|
||||
noinst_HEADERS = searpc-utils.h marshal.h
|
||||
noinst_HEADERS = searpc-utils.h
|
||||
|
||||
libsearpc_la_SOURCES = searpc-client.c searpc-server.c $(generated_sources)
|
||||
|
||||
@ -35,14 +27,3 @@ libsearpc_la_LIBADD = @GLIB_LIBS@ \
|
||||
${top_builddir}/json-glib/json-glib/libsearpc-json-glib.la
|
||||
|
||||
dist_bin_SCRIPTS = searpc-codegen.py
|
||||
|
||||
EXTRA_DIST = rpc_table.py
|
||||
|
||||
gensource: ${generated_sources}
|
||||
|
||||
${generated_sources}: searpc-codegen.py rpc_table.py
|
||||
@echo "[libsearpc]: generating rpc header files"
|
||||
python searpc-codegen.py rpc_table.py
|
||||
@echo "[libsearpc]: done"
|
||||
|
||||
DISTCLEANFILES = ${generated_sources}
|
||||
|
@ -1,48 +0,0 @@
|
||||
"""
|
||||
Define RPC functions needed to generate
|
||||
"""
|
||||
|
||||
# [ <ret-type>, [<arg_types>] ]
|
||||
func_table = [
|
||||
[ "int", [] ],
|
||||
[ "int", ["int"] ],
|
||||
[ "int", ["int", "string"] ],
|
||||
[ "int", ["int", "string", "string"] ],
|
||||
[ "int", ["int", "string", "int", "int"] ],
|
||||
[ "int", ["string"] ],
|
||||
[ "int", ["string", "int"] ],
|
||||
[ "int", ["string", "int", "string"] ],
|
||||
[ "int", ["string", "int", "string", "string"] ],
|
||||
[ "int", ["string", "string"] ],
|
||||
[ "int", ["string", "string", "string"] ],
|
||||
[ "int", ["string", "string", "int", "int"] ],
|
||||
[ "int", ["string", "string", "string", "string"] ],
|
||||
[ "int", ["string", "string", "string", "string", "string"] ],
|
||||
[ "int64", [] ],
|
||||
[ "int64", ["string"] ],
|
||||
[ "string", [] ],
|
||||
[ "string", ["int"] ],
|
||||
[ "string", ["string"] ],
|
||||
[ "string", ["string", "int"] ],
|
||||
[ "string", ["string", "string"] ],
|
||||
[ "string", ["string", "string", "string"] ],
|
||||
[ "string", ["string", "string", "string", "string"] ],
|
||||
[ "string", ["string", "string", "string", "string", "int"] ],
|
||||
[ "string", ["string", "string", "string", "string", "string"] ],
|
||||
[ "string", ["string", "string", "string", "string", "string", "string"] ],
|
||||
[ "string", ["string", "string", "string", "string", "string", "int"] ],
|
||||
[ "objlist", [] ],
|
||||
[ "objlist", ["int"] ],
|
||||
[ "objlist", ["int", "int"] ],
|
||||
[ "objlist", ["string"] ],
|
||||
[ "objlist", ["string", "int"] ],
|
||||
[ "objlist", ["string", "int", "int"] ],
|
||||
[ "objlist", ["string", "string"] ],
|
||||
[ "objlist", ["string", "string", "string"] ],
|
||||
[ "objlist", ["string", "string", "int"] ],
|
||||
[ "objlist", ["string", "string", "int", "int"] ],
|
||||
[ "object", [] ],
|
||||
[ "object", ["int"] ],
|
||||
[ "object", ["string"] ],
|
||||
[ "object", ["string", "string"] ],
|
||||
]
|
@ -6,6 +6,7 @@ Generate function define macros.
|
||||
|
||||
import string
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
# type -> (<c type if used as parameter>, <c type if used as ret type>,
|
||||
@ -173,6 +174,7 @@ def gen_signature_list():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.append(os.getcwd())
|
||||
gen_marshal_functions()
|
||||
gen_marshal_register_function()
|
||||
gen_signature_list()
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "json-glib/json-glib.h"
|
||||
|
||||
#include "searpc-server.h"
|
||||
#include "searpc-utils.h"
|
||||
|
||||
@ -87,7 +85,7 @@ searpc_remove_service (const char *svc_name)
|
||||
}
|
||||
|
||||
/* Marshal functions */
|
||||
static inline void
|
||||
void
|
||||
set_string_to_ret_object (JsonObject *object, gchar *ret)
|
||||
{
|
||||
if (ret == NULL)
|
||||
@ -98,13 +96,13 @@ set_string_to_ret_object (JsonObject *object, gchar *ret)
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
void
|
||||
set_int_to_ret_object (JsonObject *object, gint64 ret)
|
||||
{
|
||||
json_object_set_int_member (object, "ret", ret);
|
||||
}
|
||||
|
||||
static inline void
|
||||
void
|
||||
set_object_to_ret_object (JsonObject *object, GObject *ret)
|
||||
{
|
||||
if (ret == NULL)
|
||||
@ -115,7 +113,7 @@ set_object_to_ret_object (JsonObject *object, GObject *ret)
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
void
|
||||
set_objlist_to_ret_object (JsonObject *object, GList *ret)
|
||||
{
|
||||
GList *ptr;
|
||||
@ -134,7 +132,7 @@ set_objlist_to_ret_object (JsonObject *object, GList *ret)
|
||||
}
|
||||
}
|
||||
|
||||
static gchar *
|
||||
gchar *
|
||||
marshal_set_ret_common (JsonObject *object, gsize *len, GError *error)
|
||||
{
|
||||
JsonNode *root = json_node_new (JSON_NODE_OBJECT);
|
||||
@ -158,7 +156,7 @@ marshal_set_ret_common (JsonObject *object, gsize *len, GError *error)
|
||||
return data;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
gchar *
|
||||
error_to_json (int code, const char *msg, gsize *len)
|
||||
{
|
||||
JsonObject *object = json_object_new ();
|
||||
@ -181,11 +179,8 @@ error_to_json (int code, const char *msg, gsize *len)
|
||||
return data;
|
||||
}
|
||||
|
||||
/* include the generated marshal functions */
|
||||
#include "marshal.h"
|
||||
|
||||
void
|
||||
searpc_server_init ()
|
||||
searpc_server_init (RegisterMarshalFunc register_func)
|
||||
{
|
||||
marshal_table = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
NULL, (GDestroyNotify)marshal_item_free);
|
||||
@ -193,7 +188,7 @@ searpc_server_init ()
|
||||
NULL, (GDestroyNotify)service_free);
|
||||
|
||||
/* register buildin marshal functions */
|
||||
register_marshals(marshal_table);
|
||||
register_func ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define SEARPC_SERVER_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#ifndef DFT_DOMAIN
|
||||
#define DFT_DOMAIN g_quark_from_string(G_LOG_DOMAIN)
|
||||
@ -10,13 +11,21 @@
|
||||
struct _JsonArray;
|
||||
typedef gchar* (*SearpcMarshalFunc) (void *func, struct _JsonArray *param_array,
|
||||
gsize *ret_len);
|
||||
typedef void (*RegisterMarshalFunc) (void);
|
||||
|
||||
void set_string_to_ret_object (JsonObject *object, gchar *ret);
|
||||
void set_int_to_ret_object (JsonObject *object, gint64 ret);
|
||||
void set_object_to_ret_object (JsonObject *object, GObject *ret);
|
||||
void set_objlist_to_ret_object (JsonObject *object, GList *ret);
|
||||
gchar *marshal_set_ret_common (JsonObject *object, gsize *len, GError *error);
|
||||
gchar *error_to_json (int code, const char *msg, gsize *len);
|
||||
|
||||
/**
|
||||
* searpc_server_init:
|
||||
*
|
||||
* Inititalize searpc server.
|
||||
*/
|
||||
void searpc_server_init ();
|
||||
void searpc_server_init (RegisterMarshalFunc register_func);
|
||||
|
||||
/**
|
||||
* searpc_server_final:
|
||||
@ -89,7 +98,4 @@ gchar *searpc_server_call_function (const char *service,
|
||||
*/
|
||||
char* searpc_compute_signature (gchar *ret_type, int pnum, ...);
|
||||
|
||||
/* Signatures */
|
||||
#include <searpc-signature.h>
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user