You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by bp...@apache.org on 2015/10/27 16:30:59 UTC
celix git commit: CELIX-237: fixed handling of preAlloated char*
output params
Repository: celix
Updated Branches:
refs/heads/develop e5dfdf536 -> 343e53faf
CELIX-237: fixed handling of preAlloated char* output params
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/343e53fa
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/343e53fa
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/343e53fa
Branch: refs/heads/develop
Commit: 343e53faf70f28e94a8328ae077b4a014e69ef46
Parents: e5dfdf5
Author: Bjoern Petri <bp...@apache.org>
Authored: Tue Oct 27 16:30:15 2015 +0100
Committer: Bjoern Petri <bp...@apache.org>
Committed: Tue Oct 27 16:30:15 2015 +0100
----------------------------------------------------------------------
.../dynamic_function_interface/json_rpc.c | 28 +++++++++-----
.../json_rpc_tests.cpp | 40 ++++++++++++++++++++
2 files changed, 58 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/343e53fa/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 1aa0d62..48f9ba5 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
@@ -268,21 +268,29 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]
dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
- //FIXME need a tmp because deserialize does always does a create (add option?)
- dyn_type *subType = NULL;
- dynType_typedPointer_getTypedType(argType, &subType);
void *tmp = NULL;
- size_t size = dynType_size(subType);
- status = jsonSerializer_deserializeJson(subType, result, &tmp);
- void **out = (void **)args[i];
- memcpy(*out, tmp, size);
- dynType_free(subType, tmp);
+ 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 {
+ status = jsonSerializer_deserializeJson(argType, result, &tmp);
+ size = dynType_size(argType);
+ memcpy(*out, tmp, size);
+ }
+
+ 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];
+ void **out = (void **) args[i];
status = jsonSerializer_deserializeJson(subSubType, result, *out);
} else {
//skip
@@ -293,4 +301,4 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]
json_decref(replyJson);
return status;
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/343e53fa/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 f49f9a5..c84ccd1 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
@@ -286,6 +286,42 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
dynInterface_destroy(intf);
}
+
+ void handleTestOutChar(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);
+
+ struct methods_head *head;
+ dynInterface_methods(intf, &head);
+ dyn_function_type *func = NULL;
+ struct method_entry *entry = NULL;
+ TAILQ_FOREACH(entry, head, entries) {
+ if (strcmp(entry->name, "getName") == 0) {
+ func = entry->dynFunc;
+ break;
+ }
+ }
+ CHECK(func != NULL);
+
+ const char *reply = "{\"r\": \"this is an pre-allocated string\" }";
+ char *result = (char*) calloc(50, sizeof(*result));
+
+ void *args[2];
+ args[0] = NULL;
+ args[1] = &result;
+
+ rc = jsonRpc_handleReply(func, reply, args);
+
+ STRCMP_EQUAL("this is an pre-allocated string", result);
+
+ free(result);
+ dynInterface_destroy(intf);
+ }
+
}
TEST_GROUP(JsonRpcTests) {
@@ -326,4 +362,8 @@ TEST(JsonRpcTests, handleOutSeq) {
handleTestOutputSequence();
}
+TEST(JsonRpcTests, handleOutChar) {
+ handleTestOutChar();
+}
+