1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-09-02 05:14:48 +00:00

Support json value in async mode.

This commit is contained in:
Shuai Lin
2016-06-28 11:37:17 +08:00
parent 25ce2aeceb
commit 5fd3bb7176
3 changed files with 42 additions and 0 deletions

View File

@@ -132,6 +132,8 @@ searpc_client_call (SearpcClient *client, const char *fname,
else if (strcmp(ret_type, "objlist") == 0)
*((GList **)ret_ptr) = searpc_client_fret__objlist (gobject_type, fret,
ret_len, error);
else if (strcmp(ret_type, "json") == 0)
*((json_t **)ret_ptr) = searpc_client_fret__json(fret, ret_len, error);
else
g_warning ("unrecognized return type %s\n", ret_type);
@@ -372,6 +374,8 @@ searpc_client_generic_callback (char *retstr, size_t len,
} else if (strcmp(data->ret_type, "objlist") == 0) {
result = (void *)searpc_client_fret__objlist (
data->gtype, retstr, len, &error);
} else if (strcmp(data->ret_type, "json") == 0) {
result = (void *)searpc_client_fret__json (retstr, len, &error);
}
data->callback (result, data->cbdata, error);
@@ -517,6 +521,25 @@ searpc_client_async_call__objlist (SearpcClient *client,
return ret;
}
int
searpc_client_async_call__json (SearpcClient *client,
const char *fname,
AsyncCallback callback, void *cbdata,
int n_params, ...)
{
g_return_val_if_fail (fname != NULL, -1);
va_list args;
int ret;
va_start (args, n_params);
ret = searpc_client_async_call_v (client, fname, callback, "json",
0, cbdata,
n_params, args);
va_end (args);
return ret;
}
/*
* Returns -1 if error happens in parsing data or data contains error

View File

@@ -109,6 +109,12 @@ searpc_client_async_call__objlist (SearpcClient *client,
GType object_type, void *cbdata,
int n_params, ...);
int
searpc_client_async_call__json (SearpcClient *client,
const char *fname,
AsyncCallback callback, void *cbdata,
int n_params, ...);
/* called by the transport layer, the rpc layer should be able to
* modify the str, but not take ownership of it */

View File

@@ -357,6 +357,19 @@ test_searpc__simple_call_async (void)
2, "string", "hello", "int", 10);
}
void async_callback_json (void *result, void *user_data, GError *error)
{
cl_assert(json_integer_value(json_object_get((json_t*)result, "hello")) == 10);
}
void
test_searpc__simple_call_async_json (void)
{
searpc_client_async_call__json (client, "get_maman_bar_json",
async_callback_json, NULL,
2, "string", "hello", "int", 10);
}
void
test_searpc__pipe_simple_call (void)
{