Return-Path: X-Original-To: apmail-celix-commits-archive@www.apache.org Delivered-To: apmail-celix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ED486183C7 for ; Tue, 3 Nov 2015 15:09:28 +0000 (UTC) Received: (qmail 30901 invoked by uid 500); 3 Nov 2015 15:09:28 -0000 Delivered-To: apmail-celix-commits-archive@celix.apache.org Received: (qmail 30853 invoked by uid 500); 3 Nov 2015 15:09:28 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 30129 invoked by uid 99); 3 Nov 2015 15:09:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2015 15:09:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3D695E13CE; Tue, 3 Nov 2015 15:09:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pnoltes@apache.org To: commits@celix.apache.org Date: Tue, 03 Nov 2015 15:09:55 -0000 Message-Id: <4ab20106155c4bd892838c388b218149@git.apache.org> In-Reply-To: <1112eec2abbb4c4fa0d84c6d16881b78@git.apache.org> References: <1112eec2abbb4c4fa0d84c6d16881b78@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [29/50] [abbrv] celix git commit: CELIX-273: Added sring handling for output parameters CELIX-273: Added sring handling for output parameters Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/57991e92 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/57991e92 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/57991e92 Branch: refs/heads/master Commit: 57991e923c13c49575d33b32591a4acafe6f5d42 Parents: 1006790 Author: Bjoern Petri Authored: Wed Oct 28 19:24:32 2015 +0100 Committer: Bjoern Petri Committed: Wed Oct 28 19:24:32 2015 +0100 ---------------------------------------------------------------------- .../dynamic_function_interface/json_rpc.c | 40 +++++++++----- .../descriptors/example4.descriptor | 2 +- .../json_rpc_tests.cpp | 56 +++++++++++++++++--- 3 files changed, 78 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/57991e92/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c index 48f9ba5..14967a5 100644 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_rpc.c @@ -145,22 +145,26 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, c dynType_free(argType, args[i]); } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) { if (ptr != NULL) { - dyn_type *typedType = NULL; if (status == OK) { status = dynType_typedPointer_getTypedType(argType, &typedType); } - - dyn_type *typedTypedType = NULL; - if (status == OK) { - status = dynType_typedPointer_getTypedType(typedType, &typedTypedType); + if (dynType_descriptorType(typedType) == 't') { + status = jsonSerializer_serializeJson(typedType, (void*) &ptr, &jsonResult); } + else { + dyn_type *typedTypedType = NULL; + if (status == OK) { + status = dynType_typedPointer_getTypedType(typedType, &typedTypedType); + } - status = jsonSerializer_serializeJson(typedTypedType, ptr, &jsonResult); + status = jsonSerializer_serializeJson(typedTypedType, ptr, &jsonResult); - if (status == OK) { - dynType_free(typedTypedType, ptr); + if (status == OK) { + dynType_free(typedTypedType, ptr); + } } + } else { LOG_DEBUG("Output ptr is null"); } @@ -272,13 +276,13 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[] void **out = (void **) args[i]; size_t size = 0; - dynType_typedPointer_getTypedType(argType, &argType); if (dynType_descriptorType(argType) == 't') { status = jsonSerializer_deserializeJson(argType, result, &tmp); size = strnlen(((char *) *(char**) tmp), 1024 * 1024); memcpy(*out, *(void**) tmp, size); } else { + dynType_typedPointer_getTypedType(argType, &argType); status = jsonSerializer_deserializeJson(argType, result, &tmp); size = dynType_size(argType); memcpy(*out, tmp, size); @@ -287,11 +291,21 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[] dynType_free(argType, tmp); } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) { dyn_type *subType = NULL; + dynType_typedPointer_getTypedType(argType, &subType); - dyn_type *subSubType = NULL; - dynType_typedPointer_getTypedType(subType, &subSubType); - void **out = (void **) args[i]; - status = jsonSerializer_deserializeJson(subSubType, result, *out); + + if (dynType_descriptorType(subType) == 't') { + void* tmp = NULL; + status = jsonSerializer_deserializeJson(subType, result, &tmp); + void ***out = (void ***) args[i]; + **out = * (void**) tmp; + } + else { + dyn_type *subSubType = NULL; + dynType_typedPointer_getTypedType(subType, &subSubType); + void **out = (void **) args[i]; + status = jsonSerializer_deserializeJson(subSubType, result, *out); + } } else { //skip } http://git-wip-us.apache.org/repos/asf/celix/blob/57991e92/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor index 542d21b..4c959c4 100644 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example4.descriptor @@ -5,4 +5,4 @@ version=1.0.0 :annotations :types :methods -getName(V)t=getName(#am=handle;P#am=pre;*t)N +getName(V)t=getName(#am=handle;P#am=out;*t)N http://git-wip-us.apache.org/repos/asf/celix/blob/57991e92/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp index c84ccd1..0a7d297 100644 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/json_rpc_tests.cpp @@ -81,6 +81,11 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch return 0; } + int getName_example4(void *handle, char** result) { + *result = strdup("allocatedInFunction"); + return 0; + } + struct tst_seq { uint32_t cap; uint32_t len; @@ -150,6 +155,11 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch int (*stats)(void *, struct tst_seq, struct tst_StatsResult **); }; + struct tst_serv_example4 { + void *handle; + int (*getName_example4)(void *, char** name); + }; + void callTestPreAllocated(void) { dyn_interface_type *intf = NULL; FILE *desc = fopen("descriptors/example1.descriptor", "r"); @@ -287,6 +297,32 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch } + + + void callTestOutChar(void) { + dyn_interface_type *intf = NULL; + FILE *desc = fopen("descriptors/example4.descriptor", "r"); + CHECK(desc != NULL); + int rc = dynInterface_parse(desc, &intf); + CHECK_EQUAL(0, rc); + fclose(desc); + + char *result = NULL; + + struct tst_serv_example4 serv; + serv.handle = NULL; + serv.getName_example4 = getName_example4; + + rc = jsonRpc_call(intf, &serv, "{\"m\":\"getName(V)t\", \"a\": []}", &result); + CHECK_EQUAL(0, rc); + + STRCMP_CONTAINS("allocatedInFunction", result); + + free(result); + dynInterface_destroy(intf); + } + + void handleTestOutChar(void) { dyn_interface_type *intf = NULL; FILE *desc = fopen("descriptors/example4.descriptor", "r"); @@ -305,23 +341,26 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch break; } } + CHECK(func != NULL); - const char *reply = "{\"r\": \"this is an pre-allocated string\" }"; - char *result = (char*) calloc(50, sizeof(*result)); + const char *reply = "{\"r\": \"this is a test string\" }"; + char *result = NULL; + void *out = &result; void *args[2]; args[0] = NULL; - args[1] = &result; + args[1] = &out; rc = jsonRpc_handleReply(func, reply, args); - STRCMP_EQUAL("this is an pre-allocated string", result); + STRCMP_EQUAL("this is a test string", result); free(result); dynInterface_destroy(intf); } + } TEST_GROUP(JsonRpcTests) { @@ -362,8 +401,13 @@ TEST(JsonRpcTests, handleOutSeq) { handleTestOutputSequence(); } -TEST(JsonRpcTests, handleOutChar) { - handleTestOutChar(); + + +TEST(JsonRpcTests, callTestOutChar) { + callTestOutChar(); } +TEST(JsonRpcTests, handleOutChar) { + handleTestOutChar(); +}