1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-09-01 04:47:16 +00:00

Add type 'int64'.

This commit is contained in:
killing
2011-10-20 20:55:11 +08:00
parent d9222f2e0b
commit 7fef7aa31e
6 changed files with 58 additions and 6 deletions

View File

@@ -26,6 +26,12 @@ type_table = {
"set_int_to_ret_object",
"json_array_add_int_element",
"-1"),
"int64": ("gint64",
"gint64",
"json_array_get_int_element",
"set_int_to_ret_object",
"json_array_add_int_element",
"-1"),
"object": ("GObject*",
"GObject*",
"",
@@ -240,7 +246,7 @@ def gen_fcall_declare_list():
dfun_template_with_gtype = r"""
#define SEARPC_CLIENT_DEFUN_${RET_TYPE}__${ARG_TYPES}(funcname, gtype) \
${ret_type_in_c} \
static ${ret_type_in_c} \
funcname (SearpcClient *client, ${args}) \
{ \
char *fcall, *fret; \
@@ -268,7 +274,7 @@ funcname (SearpcClient *client, ${args}) \
dfun_template_without_gtype = r"""
#define SEARPC_CLIENT_DEFUN_${RET_TYPE}__${ARG_TYPES}(funcname) \
${ret_type_in_c} \
static ${ret_type_in_c} \
funcname (SearpcClient *client, ${args}) \
{ \
char *fcall, *fret; \
@@ -332,7 +338,7 @@ def gen_dfun_macro_list():
async_dfun_template = r"""
#define SEARPC_CLIENT_ASYNC_DEFUN_${RET_TYPE}__${ARG_TYPES}(funcname, gtype) \
int \
static int \
funcname (SearpcClient *client, ${args} \
AsyncCallback callback, void *user_data) \
{ \

View File

@@ -10,6 +10,7 @@ func_table = [
[ "int", ["string", "int"] ],
[ "int", ["string", "string"] ],
[ "int", ["string", "string", "string"] ],
[ "int64", ["string"] ],
[ "string", [] ],
[ "string", ["string"] ],
[ "string", ["string", "int"] ],

View File

@@ -47,6 +47,8 @@ searpc_client_generic_callback (char *retstr, size_t len,
AsyncCallData *data = vdata;
GError *error = NULL;
void *result = NULL;
int ret;
gint64 ret64;
if (errstr) {
g_set_error (&error, 0, 500, "Transport error: %s", errstr);
@@ -55,9 +57,11 @@ searpc_client_generic_callback (char *retstr, size_t len,
} else {
/* parse result and call the callback */
if (strcmp(data->ret_type, "int") == 0) {
int ret = searpc_client_fret__int (retstr, len, &error);
printf ("ret is %d\n", ret);
result = (void *)(long)ret;
ret = searpc_client_fret__int (retstr, len, &error);
result = (void *)&ret;
} if (strcmp(data->ret_type, "int64") == 0) {
ret64 = searpc_client_fret__int64 (retstr, len, &error);
result = (void *)&ret64;
} else if (strcmp(data->ret_type, "string") == 0) {
result = (void *)searpc_client_fret__string (retstr, len, &error);
} else if (strcmp(data->ret_type, "object") == 0) {
@@ -208,6 +212,23 @@ searpc_client_fret__int (char *data, size_t len, GError **error)
return -1;
}
gint64
searpc_client_fret__int64 (char *data, size_t len, GError **error)
{
JsonParser *parser = NULL;
JsonNode *root = NULL;
JsonObject *object = NULL;
gint64 ret;
if (handle_ret_common(data, len, &parser, &root, &object, error) == 0) {
ret = json_object_get_int_member(object, "ret");
g_object_unref (parser);
return ret;
}
return -1;
}
GObject*
searpc_client_fret__object (GType gtype, char *data, size_t len, GError **error)
{

View File

@@ -68,6 +68,9 @@ searpc_client_fret__string (char *data, size_t len, GError **error);
int
searpc_client_fret__int (char *data, size_t len, GError **error);
gint64
searpc_client_fret__int64 (char *data, size_t len, GError **error);
GObject*
searpc_client_fret__object (GType gtype, char *data,
size_t len, GError **error);

View File

@@ -128,6 +128,26 @@ SearpcClient_Fret__Int(PyObject *self, PyObject *args)
}
static PyObject *
SearpcClient_Fret__Int64(PyObject *self, PyObject *args)
{
char *data;
gint64 res;
GError *error = NULL;
if (!PyArg_ParseTuple(args, "s", &data))
return NULL;
res = searpc_client_fret__int64(data, strlen(data), &error);
if (error) {
PyErr_SetString(SearpcError, error->message);
return NULL;
}
return PyLong_FromLongLong(res);;
}
#include "fcallfret.h"

View File

@@ -90,6 +90,7 @@ def gen_module_funcs_array():
type_table = {
"string" : ("char *", "s"),
"int" : ("int", "i"),
"int64" : ("gint64", "L"),
"object" : ("GObject *", "O"),
}