CELIX-237: Added support for (external) type refernces in dyn_type. update .travis.yml to make all then make test
Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/3a150398 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/3a150398 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/3a150398 Branch: refs/heads/feature/CELIX-237_rsa-ffi Commit: 3a1503988cddf82e2c836759bfd14cb61a176b90 Parents: 825359e Author: Pepijn Noltes <[email protected]> Authored: Wed Jul 8 10:35:54 2015 +0200 Committer: Pepijn Noltes <[email protected]> Committed: Wed Jul 8 10:35:54 2015 +0200 ---------------------------------------------------------------------- .travis.yml | 2 +- .../dynamic_function_interface/dyn_function.c | 4 ++-- .../dynamic_function_interface/dyn_type.c | 24 ++++++++++++++------ .../dynamic_function_interface/dyn_type.h | 9 ++++---- .../tst/dyn_type_tests.cpp | 15 ++++++------ .../tst/json_serializer_tests.cpp | 8 +++---- 6 files changed, 37 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/3a150398/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml index affb7ca..4379c51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,4 @@ before_script: - cmake -DENABLE_CODE_COVERAGE=ON -DCMAKE_SKIP_BUILD_RPATH=FALSE -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DCMAKE_INSTALL_PREFIX=../install .. script: - - make test + - make all && make test http://git-wip-us.apache.org/repos/asf/celix/blob/3a150398/remote_services/dynamic_function_interface/dyn_function.c ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/dyn_function.c b/remote_services/dynamic_function_interface/dyn_function.c index dbe414d..0bb0d53 100644 --- a/remote_services/dynamic_function_interface/dyn_function.c +++ b/remote_services/dynamic_function_interface/dyn_function.c @@ -89,9 +89,9 @@ static int dynFunction_parseDescriptor(const char *descriptor, dyn_type **argume returnDesc[len] = '\0'; LOG_DEBUG("returnDesc is '%s'\n", returnDesc); - status = dynType_create(argDesc, arguments); + status = dynType_create(argDesc, NULL, arguments); if (status == 0) { - status = dynType_create(returnDesc, funcReturn); + status = dynType_create(returnDesc, NULL, funcReturn); } } else { status = 1; http://git-wip-us.apache.org/repos/asf/celix/blob/3a150398/remote_services/dynamic_function_interface/dyn_type.c ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/dyn_type.c b/remote_services/dynamic_function_interface/dyn_type.c index 0c85f43..f4c982f 100644 --- a/remote_services/dynamic_function_interface/dyn_type.c +++ b/remote_services/dynamic_function_interface/dyn_type.c @@ -15,7 +15,7 @@ DFI_SETUP_LOG(dynType) -static int dynType_createWithStream(FILE *stream, dyn_type *parent, dyn_type **type); +static int dynType_createWithStream(FILE *stream, dyn_type *parent, struct dyn_type_list_head *typeReferences, dyn_type **result); static void dynType_clear(dyn_type *type); static void dynType_clearComplex(dyn_type *type); static void dynType_clearSequence(dyn_type *type); @@ -57,11 +57,11 @@ static const int DT_ERROR = 1; static const int DT_MEM_ERROR = 2; static const int DT_PARSE_ERROR = 3; -int dynType_create(const char *descriptor, dyn_type **type) { +int dynType_create(const char *descriptor, struct dyn_type_list_head *typeReferences, dyn_type **type) { int status = DT_OK; FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r"); if (stream != NULL) { - status = dynType_createWithStream(stream, NULL, type); + status = dynType_createWithStream(stream, NULL, typeReferences, type); if (status == DT_OK) { int c = fgetc(stream); if (c != '\0' && c != EOF) { @@ -77,12 +77,13 @@ int dynType_create(const char *descriptor, dyn_type **type) { return status; } -static int dynType_createWithStream(FILE *stream, dyn_type *parent, dyn_type **result) { +static int dynType_createWithStream(FILE *stream, dyn_type *parent, struct dyn_type_list_head *typeReferences, dyn_type **result) { int status = DT_OK; dyn_type *type = calloc(1, sizeof(*type)); if (type != NULL) { type->parent = parent; type->type = DYN_TYPE_INVALID; + type->typeReferences = typeReferences; TAILQ_INIT(&type->nestedTypesHead); status = dynType_parse(stream, type); if (status == DT_OK) { @@ -333,7 +334,7 @@ static int dynType_parseSequence(FILE *stream, dyn_type *type) { type->descriptor = '['; type->sequence.seqType.elements = seq_types; - status = dynType_createWithStream(stream, type, &type->sequence.itemType); + status = dynType_createWithStream(stream, type, NULL, &type->sequence.itemType); if (status == DT_OK) { type->ffiType = &type->sequence.seqType; @@ -364,7 +365,7 @@ static int dynType_parseTypedPointer(FILE *stream, dyn_type *type) { type->descriptor = '*'; type->ffiType = &ffi_type_pointer; - status = dynType_createWithStream(stream, type, &type->typedPointer.typedType); + status = dynType_createWithStream(stream, type, NULL, &type->typedPointer.typedType); return status; } @@ -604,8 +605,17 @@ static ffi_type * dynType_ffiTypeFor(int c) { static dyn_type * dynType_findType(dyn_type *type, char *name) { dyn_type *result = NULL; - struct nested_entry *entry = NULL; + + if (type->typeReferences != NULL) { + TAILQ_FOREACH(entry, type->typeReferences, entries) { + if (strcmp(name, entry->type.name) == 0) { + result = &entry->type; + break; + } + } + } + TAILQ_FOREACH(entry, &type->nestedTypesHead, entries) { if (strcmp(name, entry->type.name) == 0) { result = &entry->type; http://git-wip-us.apache.org/repos/asf/celix/blob/3a150398/remote_services/dynamic_function_interface/dyn_type.h ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/dyn_type.h b/remote_services/dynamic_function_interface/dyn_type.h index 42319ad..904487a 100644 --- a/remote_services/dynamic_function_interface/dyn_type.h +++ b/remote_services/dynamic_function_interface/dyn_type.h @@ -76,13 +76,16 @@ typedef struct _dyn_type dyn_type; +TAILQ_HEAD(dyn_type_list_head, nested_entry); + struct _dyn_type { char *name; char descriptor; int type; ffi_type *ffiType; dyn_type *parent; - TAILQ_HEAD(, nested_entry) nestedTypesHead; + struct dyn_type_list_head *typeReferences; //NOTE: not owned + struct dyn_type_list_head nestedTypesHead; union { struct { TAILQ_HEAD(, complex_type_entry) entriesHead; @@ -108,8 +111,6 @@ struct complex_type_entry { TAILQ_ENTRY(complex_type_entry) entries; }; -TAILQ_HEAD(dyn_type_list_head, nested_entry); - struct nested_entry { dyn_type type; TAILQ_ENTRY(nested_entry) entries; @@ -120,7 +121,7 @@ struct nested_entry { DFI_SETUP_LOG_HEADER(dynType); //generic -int dynType_create(const char *descriptor, dyn_type **type); +int dynType_create(const char *descriptor, struct dyn_type_list_head *typeReferences, dyn_type **type); void dynType_destroy(dyn_type *type); int dynType_alloc(dyn_type *type, void **bufLoc); void dynType_print(dyn_type *type); http://git-wip-us.apache.org/repos/asf/celix/blob/3a150398/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp index 706e9af..1b011c3 100644 --- a/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp +++ b/remote_services/dynamic_function_interface/tst/dyn_type_tests.cpp @@ -23,14 +23,14 @@ extern "C" { dyn_type *type; int i; type = NULL; - //printf("\n-- example %s with descriptor string '%s' --\n", exName, descriptorStr); - int status = dynType_create(descriptorStr, &type); + printf("\n-- example %s with descriptor string '%s' --\n", exName, descriptorStr); + int status = dynType_create(descriptorStr, NULL, &type); CHECK_EQUAL(0, status); if (status == 0) { - //dynType_print(type); + dynType_print(type); dynType_destroy(type); } - //printf("--\n\n"); + printf("--\n\n"); } } @@ -106,7 +106,7 @@ TEST(DynTypeTests, ParseRandomGarbageTest) { //printf("ParseRandomGarbageTest iteration %i with descriptor string '%s'\n", k, descriptorStr); dyn_type *type = NULL; - int status = dynType_create(descriptorStr, &type); + int status = dynType_create(descriptorStr, NULL, &type); if (status == 0) { dynType_destroy(type); } @@ -122,7 +122,7 @@ TEST(DynTypeTests, AssignTest1) { struct ex1 inst; const char *desc = "{III a b c}"; dyn_type *type = NULL; - int status = dynType_create(desc, &type); + int status = dynType_create(desc, NULL, &type); CHECK_EQUAL(0, status); int32_t val1 = 2; int32_t val2 = 4; @@ -146,7 +146,7 @@ TEST(DynTypeTests, AssignTest2) { struct ex inst; const char *desc = "{I{DD a b} a b}"; dyn_type *type = NULL; - int status = dynType_create(desc, &type); + int status = dynType_create(desc, NULL, &type); CHECK_EQUAL(0, status); int32_t a = 2; double b_a = 1.1; @@ -167,6 +167,7 @@ TEST(DynTypeTests, AssignTest2) { CHECK_EQUAL(1.2, inst.b.b); } + //TODO allocating / freeing //TODO sequences http://git-wip-us.apache.org/repos/asf/celix/blob/3a150398/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp b/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp index 6cabe8a..30d3e71 100644 --- a/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp +++ b/remote_services/dynamic_function_interface/tst/json_serializer_tests.cpp @@ -136,7 +136,7 @@ static void tests() { type = NULL; inst = NULL; - rc = dynType_create(example1_descriptor, &type); + rc = dynType_create(example1_descriptor, NULL, &type); CHECK_EQUAL(0, rc); rc = json_deserialize(type, example1_input, &inst); CHECK_EQUAL(0, rc); @@ -146,7 +146,7 @@ static void tests() { type = NULL; inst = NULL; - rc = dynType_create(example2_descriptor, &type); + rc = dynType_create(example2_descriptor, NULL, &type); CHECK_EQUAL(0, rc); rc = json_deserialize(type, example2_input, &inst); CHECK_EQUAL(0, rc); @@ -155,7 +155,7 @@ static void tests() { type = NULL; inst = NULL; - rc = dynType_create(example3_descriptor, &type); + rc = dynType_create(example3_descriptor, NULL, &type); CHECK_EQUAL(0, rc); rc = json_deserialize(type, example3_input, &inst); CHECK_EQUAL(0, rc); @@ -163,7 +163,7 @@ static void tests() { type = NULL; inst = NULL; - rc = dynType_create(example4_descriptor, &type); + rc = dynType_create(example4_descriptor, NULL, &type); CHECK_EQUAL(0, rc); rc = json_deserialize(type, example4_input, &inst); CHECK_EQUAL(0, rc);
