Fixed a small issue of an error not reported in json_serializer, added an extra test and edited some log statements
Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/d3408980 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/d3408980 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/d3408980 Branch: refs/heads/develop Commit: d340898029489b525ce009350ff376ffd9d68376 Parents: 5262482 Author: Pepijn Noltes <pepijnnol...@gmail.com> Authored: Tue Sep 22 21:05:10 2015 +0200 Committer: Pepijn Noltes <pepijnnol...@gmail.com> Committed: Tue Sep 22 21:05:10 2015 +0200 ---------------------------------------------------------------------- .../json_serializer.c | 19 ++++++- .../descriptors/example2.descriptor | 9 +++ .../dyn_type_tests.cpp | 51 +++++++++++++++++ .../json_rpc_tests.cpp | 60 ++++++++++++++++++++ .../rsa/private/src/import_registration_dfi.c | 2 +- .../rsa/private/src/remote_service_admin_dfi.c | 2 + 6 files changed, 139 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c index 0fb07fc..eb38dbc 100644 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/json_serializer.c @@ -90,11 +90,18 @@ static int jsonSerializer_parseObject(dyn_type *type, json_t *object, void *inst static int jsonSerializer_parseObjectMember(dyn_type *type, const char *name, json_t *val, void *inst) { int status = OK; - int index = dynType_complex_indexForName(type, name); void *valp = NULL; dyn_type *valType = NULL; - status = dynType_complex_valLocAt(type, index, inst, &valp); + int index = dynType_complex_indexForName(type, name); + if (index < 0) { + LOG_ERROR("Cannot find index for member '%s'", name); + status = ERROR; + } + + if (status == OK) { + status = dynType_complex_valLocAt(type, index, inst, &valp); + } if (status == OK ) { status = dynType_complex_dynTypeAt(type, index, &valType); @@ -113,6 +120,12 @@ static int jsonSerializer_parseAny(dyn_type *type, void *loc, json_t *val) { dyn_type *subType = NULL; char c = dynType_descriptorType(type); + /* + printf("parseAny with descriptor '%c' :", c); + json_dumpf(val, stdout, 0); //TODO remove + printf("\n"); + */ + float *f; //F double *d; //D char *b; //B @@ -225,7 +238,7 @@ static int jsonSerializer_parseSequence(dyn_type *seq, json_t *array, void *seqL json_array_foreach(array, index, val) { void *valLoc = NULL; status = dynType_sequence_increaseLengthAndReturnLastLoc(seq, seqLoc, &valLoc); - //LOG_DEBUG("Got sequence loc %p", valLoc); + //LOG_DEBUG("Got sequence loc %p for index %zu", valLoc, index); if (status == OK) { status = jsonSerializer_parseAny(itemType, valLoc, val); http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example2.descriptor ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example2.descriptor b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example2.descriptor new file mode 100644 index 0000000..38bf442 --- /dev/null +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/descriptors/example2.descriptor @@ -0,0 +1,9 @@ +:header +type=interface +name=example +version=1.0.0 +:annotations +:types +item={DD a b} +:methods +example1=items(#am=handle;P#am=out;**[Litem;)N http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp index 2f05bd1..ae14c0f 100644 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface_tst/dyn_type_tests.cpp @@ -210,3 +210,54 @@ TEST(DynTypeTests, MetaInfoTest) { dynType_destroy(type); } +TEST(DynTypeTests, SequenceWithPointerTest) { + struct val { + double a; + double b; + }; + + struct item { + int64_t a; + const char *text; + struct val val; + double c; + double d; + long e; + }; + + struct item_sequence { + uint32_t cap; + uint32_t len; + struct item **buf; + }; + + dyn_type *type = NULL; + int rc = 0; + rc = dynType_parseWithStr("Tval={DD a b};Titem={Jtlval;DDJ a text val c d e};**[Litem;", NULL, NULL, &type); + CHECK_EQUAL(0, rc); + + struct item_sequence *seq = NULL; + rc = dynType_alloc(type, (void **)&seq); + CHECK_EQUAL(0, rc); + CHECK(seq != NULL); + + dynType_free(type, seq); + + /* + + + struct item_sequence *items = (struct item_sequence *) calloc(1,sizeof(struct item_sequence)); + items->buf = (struct item **) calloc(2, sizeof(struct item *)); + items->cap = 2; + items->len = 2; + items->buf[0] = (struct item *)calloc(1, sizeof(struct item)); + items->buf[0]->text = strdup("boe"); + items->buf[1] = (struct item *)calloc(1, sizeof(struct item)); + items->buf[1]->text = strdup("boe2"); + + dynType_free(type, items); + */ + + dynType_destroy(type); +} + http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/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 6ebf1c3..6140bec 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 @@ -131,6 +131,17 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch return 0; } + struct item { + double a; + double b; + }; + + struct item_seq { + uint32_t cap; + uint32_t len; + struct item **buf; + }; + struct tst_serv { void *handle; int (*add)(void *, double, double, double *); @@ -221,6 +232,51 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch dynInterface_destroy(intf); } + static void handleTestOutputSequence(void) { + dyn_interface_type *intf = NULL; + FILE *desc = fopen("descriptors/example2.descriptor", "r"); + CHECK(desc != NULL); + int rc = dynInterface_parse(desc, &intf); + CHECK_EQUAL(0, rc); + + 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, "example1") == 0) { + func = entry->dynFunc; + break; + } + } + CHECK(func != NULL); + + //dyn_type *arg = dynFunction_argumentTypeForIndex(func, 1); + //dynType_print(arg, stdout); + + const char *reply = "{\"r\":[{\"a\":1.0,\"b\":1.5},{\"a\":2.0,\"b\":2.5}]}"; + + void *args[2]; + args[0] = NULL; + args[1] = NULL; + + struct item_seq *result = NULL; + void *out = &result; + args[1] = &out; + + rc = jsonRpc_handleReply(func, reply, args); + CHECK_EQUAL(0, rc); + CHECK_EQUAL(2, result->len); + CHECK_EQUAL(1.0, result->buf[0]->a); + CHECK_EQUAL(1.5, result->buf[0]->b); + CHECK_EQUAL(2.0, result->buf[1]->a); + CHECK_EQUAL(2.5, result->buf[1]->b); + + + free(result->buf); + free(result); + dynInterface_destroy(intf); } + } TEST_GROUP(JsonRpcTests) { @@ -257,4 +313,8 @@ TEST(JsonRpcTests, callOut) { callTestOutput(); } +TEST(JsonRpcTests, handleOutSeq) { + handleTestOutputSequence(); +} + http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c index 56144d9..680a75a 100644 --- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c +++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c @@ -249,7 +249,7 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret //printf("request sended. got reply '%s' with status %i\n", reply, rc); if (rc == 0) { - //printf("handling reply\n"); + //printf("Handling reply '%s'\n", reply); status = jsonRpc_handleReply(entry->dynFunc, reply, args); } http://git-wip-us.apache.org/repos/asf/celix/blob/d3408980/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c index 54d08d3..9ea470b 100644 --- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c +++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c @@ -444,6 +444,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) { celix_status_t status = CELIX_SUCCESS; + logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing exported service"); service_reference_pt ref = NULL; status = exportRegistration_getExportReference(registration, &ref); @@ -620,6 +621,7 @@ celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt admin, e celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt registration) { celix_status_t status = CELIX_SUCCESS; + logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing imported service"); celixThreadMutex_lock(&admin->importedServicesLock); importRegistration_close(registration);