Repository: celix Updated Branches: refs/heads/develop 53bc7bd83 -> 0f35e33a2
CELIX-324: Version support in dfi library Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/0f35e33a Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/0f35e33a Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/0f35e33a Branch: refs/heads/develop Commit: 0f35e33a200be0261abf0c841c8eb601e7b5f8c4 Parents: 53bc7bd Author: Bjoern Petri <[email protected]> Authored: Mon Dec 14 15:55:54 2015 +0100 Committer: Bjoern Petri <[email protected]> Committed: Mon Dec 14 15:55:54 2015 +0100 ---------------------------------------------------------------------- dfi/CMakeLists.txt | 3 ++- dfi/private/src/dyn_interface.c | 32 ++++++++++++++++++---- dfi/private/src/dyn_message.c | 34 +++++++++++++++++++---- dfi/private/test/dyn_interface_tests.cpp | 32 +++++++++++++++++----- dfi/private/test/dyn_message_tests.cpp | 39 ++++++++++++++++++--------- dfi/public/include/dyn_interface.h | 5 +++- dfi/public/include/dyn_message.h | 5 +++- 7 files changed, 119 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/0f35e33a/dfi/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/dfi/CMakeLists.txt b/dfi/CMakeLists.txt index 8c21938..8e3c0b1 100644 --- a/dfi/CMakeLists.txt +++ b/dfi/CMakeLists.txt @@ -23,6 +23,7 @@ include_directories( ${JANSSON_INCLUDE_DIRS} private/include public/include + ${PROJECT_SOURCE_DIR}/utils/public/include ) set(MEMSTREAM_SOURCES ) @@ -52,7 +53,7 @@ add_library(celix_dfi SHARED public/include/json_rpc.h ${MEMSTREAM_INCLUDES} ) -target_link_libraries(celix_dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY}) +target_link_libraries(celix_dfi celix_utils ${FFI_LIBRARIES} ${JANSSON_LIBRARY}) install(TARGETS celix_dfi DESTINATION lib COMPONENT framework) FILE(GLOB files "public/include/*.h" ${MEMSTREAM_INCLUDES}) http://git-wip-us.apache.org/repos/asf/celix/blob/0f35e33a/dfi/private/src/dyn_interface.c ---------------------------------------------------------------------- diff --git a/dfi/private/src/dyn_interface.c b/dfi/private/src/dyn_interface.c index d217d65..fdd872d 100644 --- a/dfi/private/src/dyn_interface.c +++ b/dfi/private/src/dyn_interface.c @@ -32,6 +32,7 @@ struct _dyn_interface_type { struct namvals_head annotations; struct types_head types; struct methods_head methods; + version_pt version; }; static const int OK = 0; @@ -74,6 +75,17 @@ int dynInterface_parse(FILE *descriptor, dyn_interface_type **out) { if (status == OK) { status = dynInterface_checkInterface(intf); } + + if(status==OK){ /* We are sure that version field is present in the header */ + char* version=NULL; + dynInterface_getVersionString(intf,&version); + if(version!=NULL){ + status = (version_createVersionFromString(version,&(intf->version)) == CELIX_SUCCESS)?OK:ERROR; + } + if(status==ERROR){ + LOG_ERROR("Invalid version (%s) in parsed descriptor\n",version); + } + } } else { status = ERROR; LOG_ERROR("Error allocating memory for dynamic interface\n"); @@ -349,10 +361,9 @@ void dynInterface_destroy(dyn_interface_type *intf) { dynCommon_clearNamValHead(&intf->header); dynCommon_clearNamValHead(&intf->annotations); - struct method_entry *mTmp = NULL; struct method_entry *mInfo = TAILQ_FIRST(&intf->methods); while (mInfo != NULL) { - mTmp = mInfo; + struct method_entry *mTmp = mInfo; mInfo = TAILQ_NEXT(mInfo, entries); if (mTmp->id != NULL) { @@ -367,15 +378,18 @@ void dynInterface_destroy(dyn_interface_type *intf) { free(mTmp); } - struct type_entry *tmp = NULL; struct type_entry *tInfo = TAILQ_FIRST(&intf->types); while (tInfo != NULL) { - tmp = tInfo; + struct type_entry *tmp = tInfo; tInfo = TAILQ_NEXT(tInfo, entries); dynType_destroy(tmp->type); free(tmp); } + if(intf->version!=NULL){ + version_destroy(intf->version); + } + free(intf); } } @@ -384,7 +398,15 @@ int dynInterface_getName(dyn_interface_type *intf, char **out) { return dynInterface_getEntryForHead(&intf->header, "name", out); } -int dynInterface_getVersion(dyn_interface_type *intf, char **version) { +int dynInterface_getVersion(dyn_interface_type* intf , version_pt* version){ + *version = intf->version; + if(*version==NULL){ + return ERROR; + } + return OK; +} + +int dynInterface_getVersionString(dyn_interface_type *intf, char **version) { return dynInterface_getEntryForHead(&intf->header, "version", version); } http://git-wip-us.apache.org/repos/asf/celix/blob/0f35e33a/dfi/private/src/dyn_message.c ---------------------------------------------------------------------- diff --git a/dfi/private/src/dyn_message.c b/dfi/private/src/dyn_message.c index c43412a..5ec6c7a 100644 --- a/dfi/private/src/dyn_message.c +++ b/dfi/private/src/dyn_message.c @@ -31,6 +31,7 @@ struct _dyn_message_type { struct namvals_head annotations; struct types_head types; dyn_type *msgType; + version_pt msgVersion; }; static const int OK = 0; @@ -72,6 +73,18 @@ int dynMessage_parse(FILE *descriptor, dyn_message_type **out) { if (status == OK) { status = dynMessage_checkMessage(msg); } + + if(status==OK){ /* We are sure that version field is present in the header */ + char* version=NULL; + dynMessage_getVersionString(msg,&version); + if(version!=NULL){ + status = (version_createVersionFromString(version,&(msg->msgVersion)) == CELIX_SUCCESS)?OK:ERROR; + } + if(status==ERROR){ + LOG_ERROR("Invalid version (%s) in parsed descriptor\n",version); + } + } + } else { status = ERROR; LOG_ERROR("Error allocating memory for dynamic message\n"); @@ -114,7 +127,7 @@ static int dynMessage_checkMessage(dyn_message_type *msg) { } static int dynMessage_parseSection(dyn_message_type *msg, FILE *stream) { - int status = OK; + int status; char *sectionName = NULL; status = dynCommon_eatChar(stream, ':'); @@ -260,7 +273,7 @@ static int dynMessage_parseTypes(dyn_message_type *msg, FILE *stream) { } static int dynMessage_parseMessage(dyn_message_type *msg, FILE *stream) { - int status = OK; + int status; //expected input <dynType>\n char *name = NULL; @@ -278,10 +291,9 @@ void dynMessage_destroy(dyn_message_type *msg) { dynCommon_clearNamValHead(&msg->header); dynCommon_clearNamValHead(&msg->annotations); - struct type_entry *tmp = NULL; struct type_entry *tInfo = TAILQ_FIRST(&msg->types); while (tInfo != NULL) { - tmp = tInfo; + struct type_entry *tmp = tInfo; tInfo = TAILQ_NEXT(tInfo, entries); dynType_destroy(tmp->type); free(tmp); @@ -291,6 +303,10 @@ void dynMessage_destroy(dyn_message_type *msg) { dynType_destroy(msg->msgType); } + if(msg->msgVersion != NULL){ + version_destroy(msg->msgVersion); + } + free(msg); } } @@ -299,7 +315,15 @@ int dynMessage_getName(dyn_message_type *msg, char **out) { return dynMessage_getEntryForHead(&msg->header, "name", out); } -int dynMessage_getVersion(dyn_message_type *msg, char **version) { +int dynMessage_getVersion(dyn_message_type *msg, version_pt* version){ + *version = msg->msgVersion; + if(*version==NULL){ + return ERROR; + } + return OK; +} + +int dynMessage_getVersionString(dyn_message_type *msg, char **version) { return dynMessage_getEntryForHead(&msg->header, "version", version); } http://git-wip-us.apache.org/repos/asf/celix/blob/0f35e33a/dfi/private/test/dyn_interface_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/dyn_interface_tests.cpp b/dfi/private/test/dyn_interface_tests.cpp index 08eb6f5..d3ef642 100644 --- a/dfi/private/test/dyn_interface_tests.cpp +++ b/dfi/private/test/dyn_interface_tests.cpp @@ -44,6 +44,23 @@ extern "C" { fprintf(stderr, "\n"); } + static void checkInterfaceVersion(dyn_interface_type* dynIntf, const char* v) { + int status; + + char *version = NULL; + status = dynInterface_getVersionString(dynIntf, &version); + CHECK_EQUAL(0, status); + STRCMP_EQUAL(v, version); + version_pt msgVersion = NULL, localMsgVersion = NULL; + int cmpVersion = -1; + version_createVersionFromString(version, &localMsgVersion); + status = dynInterface_getVersion(dynIntf, &msgVersion); + CHECK_EQUAL(0, status); + version_compareTo(msgVersion, localMsgVersion, &cmpVersion); + CHECK_EQUAL(cmpVersion, 0); + version_destroy(localMsgVersion); + } + static void test1(void) { int status = 0; dyn_interface_type *dynIntf = NULL; @@ -58,10 +75,7 @@ extern "C" { CHECK_EQUAL(0, status); STRCMP_EQUAL("calculator", name); - char *version = NULL; - status = dynInterface_getVersion(dynIntf, &version); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("1.0.0", version); + checkInterfaceVersion(dynIntf,"1.0.0"); char *annVal = NULL; status = dynInterface_getAnnotationEntry(dynIntf, "classname", &annVal); @@ -136,19 +150,25 @@ extern "C" { fclose(desc); dynInterface_destroy(dynIntf); - /* Invalid method section */ + /* Invalid type */ desc = fopen("descriptors/invalids/invalidType.descriptor", "r"); status = dynInterface_parse(desc, &dynIntf); CHECK_EQUAL(1, status); //Test fails because of space at the end of the type fclose(desc); dynInterface_destroy(dynIntf); - /* Invalid method section */ + /* Invalid metatype in method description */ desc = fopen("descriptors/invalids/invalidMetaType.descriptor", "r"); status = dynInterface_parse(desc, &dynIntf); CHECK_EQUAL(0, status); //Invalid meta type doesn't generate errors, just warnings fclose(desc); dynInterface_destroy(dynIntf); + + /* Invalid version section */ + desc = fopen("descriptors/invalids/invalidVersion.descriptor", "r"); + status = dynInterface_parse(desc, &dynIntf); + CHECK_EQUAL(1, status); //Invalid meta type doesn't generate errors, just warnings + fclose(desc); } } http://git-wip-us.apache.org/repos/asf/celix/blob/0f35e33a/dfi/private/test/dyn_message_tests.cpp ---------------------------------------------------------------------- diff --git a/dfi/private/test/dyn_message_tests.cpp b/dfi/private/test/dyn_message_tests.cpp index acaddf8..7aafcc3 100644 --- a/dfi/private/test/dyn_message_tests.cpp +++ b/dfi/private/test/dyn_message_tests.cpp @@ -45,6 +45,24 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch fprintf(stderr, "\n"); } +static void checkMessageVersion(dyn_message_type* dynMsg, const char* v){ + int status = 0; + + char *version = NULL; + status = dynMessage_getVersionString(dynMsg, &version); + CHECK_EQUAL(0, status); + STRCMP_EQUAL(v, version); + version_pt msgVersion = NULL, localMsgVersion = NULL; + int cmpVersion = -1; + version_createVersionFromString(version,&localMsgVersion); + status = dynMessage_getVersion(dynMsg,&msgVersion); + CHECK_EQUAL(0, status); + version_compareTo(msgVersion,localMsgVersion,&cmpVersion); + CHECK_EQUAL(cmpVersion,0); + version_destroy(localMsgVersion); + +} + static void msg_test1(void) { int status = 0; @@ -60,10 +78,7 @@ static void msg_test1(void) { CHECK_EQUAL(0, status); STRCMP_EQUAL("poi", name); - char *version = NULL; - status = dynMessage_getVersion(dynMsg, &version); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("1.0.0", version); + checkMessageVersion(dynMsg,"1.0.0"); char *annVal = NULL; status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal); @@ -98,10 +113,7 @@ static void msg_test2(void) { CHECK_EQUAL(0, status); STRCMP_EQUAL("track", name); - char *version = NULL; - status = dynMessage_getVersion(dynMsg, &version); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("0.0.1", version); + checkMessageVersion(dynMsg,"0.0.1"); char *annVal = NULL; status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal); @@ -135,10 +147,7 @@ static void msg_test3(void) { CHECK_EQUAL(0, status); STRCMP_EQUAL("logEntry", name); - char *version = NULL; - status = dynMessage_getVersion(dynMsg, &version); - CHECK_EQUAL(0, status); - STRCMP_EQUAL("1.0.0", version); + checkMessageVersion(dynMsg,"1.0.0"); char *annVal = NULL; status = dynMessage_getAnnotationEntry(dynMsg, "classname", &annVal); @@ -191,6 +200,12 @@ static void msg_invalid(void) { CHECK_EQUAL(1, status); fclose(desc); + desc = fopen("descriptors/invalids/invalidMsgInvalidVersion.descriptor", "r"); + assert(desc != NULL); + status = dynMessage_parse(desc, &dynMsg); + CHECK_EQUAL(1, status); + fclose(desc); + } } http://git-wip-us.apache.org/repos/asf/celix/blob/0f35e33a/dfi/public/include/dyn_interface.h ---------------------------------------------------------------------- diff --git a/dfi/public/include/dyn_interface.h b/dfi/public/include/dyn_interface.h index 51a2f41..54bf41c 100644 --- a/dfi/public/include/dyn_interface.h +++ b/dfi/public/include/dyn_interface.h @@ -24,6 +24,8 @@ #include "dyn_function.h" #include "dfi_log_util.h" +#include "version.h" + DFI_SETUP_LOG_HEADER(dynInterface); /* Description string @@ -53,7 +55,8 @@ int dynInterface_parse(FILE *descriptor, dyn_interface_type **out); void dynInterface_destroy(dyn_interface_type *intf); int dynInterface_getName(dyn_interface_type *intf, char **name); -int dynInterface_getVersion(dyn_interface_type *intf, char **version); +int dynInterface_getVersion(dyn_interface_type *intf, version_pt* version); +int dynInterface_getVersionString(dyn_interface_type *intf, char **version); int dynInterface_getHeaderEntry(dyn_interface_type *intf, const char *name, char **value); int dynInterface_getAnnotationEntry(dyn_interface_type *intf, const char *name, char **value); int dynInterface_methods(dyn_interface_type *intf, struct methods_head **list); http://git-wip-us.apache.org/repos/asf/celix/blob/0f35e33a/dfi/public/include/dyn_message.h ---------------------------------------------------------------------- diff --git a/dfi/public/include/dyn_message.h b/dfi/public/include/dyn_message.h index b2f5f0e..d1c8dd7 100644 --- a/dfi/public/include/dyn_message.h +++ b/dfi/public/include/dyn_message.h @@ -23,6 +23,8 @@ #include "dyn_type.h" #include "dfi_log_util.h" +#include "version.h" + DFI_SETUP_LOG_HEADER(dynMessage); /* Description string @@ -43,7 +45,8 @@ int dynMessage_parse(FILE *descriptor, dyn_message_type **out); void dynMessage_destroy(dyn_message_type *msg); int dynMessage_getName(dyn_message_type *msg, char **name); -int dynMessage_getVersion(dyn_message_type *msg, char **version); +int dynMessage_getVersion(dyn_message_type *msg, version_pt* version); +int dynMessage_getVersionString(dyn_message_type *msg, char **version); int dynMessage_getHeaderEntry(dyn_message_type *msg, const char *name, char **value); int dynMessage_getAnnotationEntry(dyn_message_type *msg, const char *name, char **value); int dynMessage_getMessageType(dyn_message_type *msg, dyn_type **type);
