diff --git a/lib/searpc-client.c b/lib/searpc-client.c index 5d34792..9a8e51d 100644 --- a/lib/searpc-client.c +++ b/lib/searpc-client.c @@ -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 diff --git a/lib/searpc-client.h b/lib/searpc-client.h index 2dca169..615faf3 100644 --- a/lib/searpc-client.h +++ b/lib/searpc-client.h @@ -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 */ diff --git a/tests/searpc.c b/tests/searpc.c index 65df0a0..7b316a9 100644 --- a/tests/searpc.c +++ b/tests/searpc.c @@ -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) {