From 34f0e990127ab3bf9857f557a968193a6b5fa6b2 Mon Sep 17 00:00:00 2001 From: PengZheng Date: Sat, 29 Jul 2023 18:43:03 +0800 Subject: [PATCH 1/4] Remove export_import example from Celix examples This was done as the example was outdated and caused confusion as it did not reflect the current state of the Celix library. Clearing out such outdated references keeps the examples relevant and avoids spreading incorrect or outdated information about the library usage. --- examples/celix-examples/CMakeLists.txt | 3 - .../export_import/CMakeLists.txt | 59 ---------------- .../export_import/include/test.h | 34 --------- .../export_import/include/test2.h | 34 --------- .../export_import/src/activator.c | 69 ------------------- .../celix-examples/export_import/src/test.c | 32 --------- .../celix-examples/export_import/src/test2.c | 32 --------- 7 files changed, 263 deletions(-) delete mode 100644 examples/celix-examples/export_import/CMakeLists.txt delete mode 100644 examples/celix-examples/export_import/include/test.h delete mode 100644 examples/celix-examples/export_import/include/test2.h delete mode 100644 examples/celix-examples/export_import/src/activator.c delete mode 100644 examples/celix-examples/export_import/src/test.c delete mode 100644 examples/celix-examples/export_import/src/test2.c diff --git a/examples/celix-examples/CMakeLists.txt b/examples/celix-examples/CMakeLists.txt index c05966ec0..42a1f7699 100644 --- a/examples/celix-examples/CMakeLists.txt +++ b/examples/celix-examples/CMakeLists.txt @@ -40,9 +40,6 @@ if (EXAMPLES) add_subdirectory(readme_cxx_examples) endif () - #TODO refactor export_import - #add_subdirectory(export_import) - add_subdirectory(http_example) add_subdirectory(embedding) add_subdirectory(track_tracker_example) diff --git a/examples/celix-examples/export_import/CMakeLists.txt b/examples/celix-examples/export_import/CMakeLists.txt deleted file mode 100644 index fa5fa8d03..000000000 --- a/examples/celix-examples/export_import/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -if(NOT APPLE) - #Importing and exporting libraries not (yet) work under OSX. - - add_library(hello_testlib SHARED - private/src/test - ) - set_library_version(hello_testlib "4.3.2") # sets target propery VERSION to 4.3.2 and SOVERSION to 4 - - - add_library(hello_test2lib SHARED - private/src/test2 - ) - set_library_version(hello_test2lib "3.3.3") - - add_celix_bundle(hello_bundle - VERSION "1.2" - SOURCES - private/src/activator.c - IMPORT_LIBRARIES hello_test2lib - ) - - add_celix_bundle(hello_export - VERSION "1.0" - NO_ACTIVATOR - EXPORT_LIBRARIES hello_test2lib - ) - - celix_bundle_private_libs(hello_bundle - hello_testlib - ) - - add_celix_container(helloworld_byref - GROUP experimental #import/export feature is experimental - BUNDLES hello_export hello_bundle ${CELIX_SHELL_BUNDLE} ${CELIX_SHELL_TUI_BUNDLE} - ) - - add_celix_container(helloworld_withcopy - GROUP experimental #import/export feature is experimental - COPY #Ensures that bundles are copied in the deploy location - BUNDLES hello_export hello_bundle ${SHELL_BUNDLE} ${SHELL_TUI_BUNDLE} - ) -endif() diff --git a/examples/celix-examples/export_import/include/test.h b/examples/celix-examples/export_import/include/test.h deleted file mode 100644 index 04c70468c..000000000 --- a/examples/celix-examples/export_import/include/test.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * test.h - * - * \date 12 Feb 2014 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef TEST_H_ -#define TEST_H_ - - -void doo(void); - - -#endif /* TEST_H_ */ diff --git a/examples/celix-examples/export_import/include/test2.h b/examples/celix-examples/export_import/include/test2.h deleted file mode 100644 index ef159061e..000000000 --- a/examples/celix-examples/export_import/include/test2.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * test.h - * - * \date 12 Feb 2014 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef TEST2_H_ -#define TEST2_H_ - - -void bar(void); - - -#endif /* TEST2_H_ */ diff --git a/examples/celix-examples/export_import/src/activator.c b/examples/celix-examples/export_import/src/activator.c deleted file mode 100644 index 3a2522a05..000000000 --- a/examples/celix-examples/export_import/src/activator.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * activator.c - * - * \date Aug 20, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include - -#include "bundle_activator.h" - -#include "test.h" -#include "test2.h" - -struct userData { - char * word; -}; - -celix_status_t bundleActivator_create(celix_bundle_context_t *context, void **userData) { - celix_status_t status = CELIX_SUCCESS; - *userData = malloc(sizeof(struct userData)); - if (*userData != NULL) { - ((struct userData *)(*userData))->word = "World"; - } else { - status = CELIX_START_ERROR; - } - return status; -} - -celix_status_t bundleActivator_start(void * userData, celix_bundle_context_t *context) { - struct userData * data = (struct userData *) userData; - printf("Hello %s\n", data->word); - - doo(); - bar(); - - return CELIX_SUCCESS; -} - -celix_status_t bundleActivator_stop(void * userData, celix_bundle_context_t *context) { - struct userData * data = (struct userData *) userData; - printf("Goodbye %s\n", data->word); - return CELIX_SUCCESS; -} - -celix_status_t bundleActivator_destroy(void * userData, celix_bundle_context_t *context) { - free(userData); - return CELIX_SUCCESS; -} diff --git a/examples/celix-examples/export_import/src/test.c b/examples/celix-examples/export_import/src/test.c deleted file mode 100644 index 0c6087d14..000000000 --- a/examples/celix-examples/export_import/src/test.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * test.c - * - * \date 12 Feb 2014 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include - -void doo() -{ - printf("Hello from second lib\n"); -} diff --git a/examples/celix-examples/export_import/src/test2.c b/examples/celix-examples/export_import/src/test2.c deleted file mode 100644 index 705512f75..000000000 --- a/examples/celix-examples/export_import/src/test2.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * test2.c - * - * \date 12 Feb 2014 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include - -void bar() -{ - printf("Hello from (imported) third lib\n"); -} From 55f15fa7fa24a9aeef394ff6464ba676e3f9bac3 Mon Sep 17 00:00:00 2001 From: PengZheng Date: Sat, 29 Jul 2023 19:04:26 +0800 Subject: [PATCH 2/4] [#531] Remove buggy Export-Library/Import-Library header parsing codes. --- libs/framework/src/manifest_parser.c | 354 +-------------------------- 1 file changed, 2 insertions(+), 352 deletions(-) diff --git a/libs/framework/src/manifest_parser.c b/libs/framework/src/manifest_parser.c index 074945e34..46275bed3 100644 --- a/libs/framework/src/manifest_parser.c +++ b/libs/framework/src/manifest_parser.c @@ -50,12 +50,6 @@ struct manifestParser { linked_list_pt requirements; }; -static linked_list_pt manifestParser_parseImportHeader(const char* header); -static linked_list_pt manifestParser_parseExportHeader(module_pt module, const char* header); -static linked_list_pt manifestParser_parseDelimitedString(const char* value, const char* delim); -static linked_list_pt manifestParser_parseStandardHeaderClause(const char* clauseString); -static linked_list_pt manifestParser_parseStandardHeader(const char* header); - celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, manifest_parser_pt *manifest_parser) { celix_status_t status; manifest_parser_pt parser; @@ -76,8 +70,8 @@ celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, mani version_createEmptyVersion(&parser->bundleVersion); } - parser->capabilities = manifestParser_parseExportHeader(owner, manifest_getValue(manifest, OSGI_FRAMEWORK_EXPORT_LIBRARY)); - parser->requirements = manifestParser_parseImportHeader(manifest_getValue(manifest, OSGI_FRAMEWORK_IMPORT_LIBRARY)); + linkedList_create(&parser->capabilities); + linkedList_create(&parser->requirements); *manifest_parser = parser; @@ -106,350 +100,6 @@ celix_status_t manifestParser_destroy(manifest_parser_pt mp) { return CELIX_SUCCESS; } -static linked_list_pt manifestParser_parseDelimitedString(const char * value, const char * delim) { - linked_list_pt list; - - if (linkedList_create(&list) == CELIX_SUCCESS) { - if (value != NULL) { - int CHAR = 1; - int DELIMITER = 2; - int STARTQUOTE = 4; - int ENDQUOTE = 8; - - char buffer[512]; - int expecting = (CHAR | DELIMITER | STARTQUOTE); - unsigned int i; - - buffer[0] = '\0'; - - for (i = 0; i < strlen(value); i++) { - char c = value[i]; - - bool isDelimiter = (strchr(delim, c) != NULL); - bool isQuote = (c == '"'); - - if (isDelimiter && ((expecting & DELIMITER) > 0)) { - linkedList_addElement(list, strdup(buffer)); - buffer[0] = '\0'; - expecting = (CHAR | DELIMITER | STARTQUOTE); - } else if (isQuote && ((expecting & STARTQUOTE) > 0)) { - char tmp[2]; - tmp[0] = c; - tmp[1] = '\0'; - strcat(buffer, tmp); - expecting = CHAR | ENDQUOTE; - } else if (isQuote && ((expecting & ENDQUOTE) > 0)) { - char tmp[2]; - tmp[0] = c; - tmp[1] = '\0'; - strcat(buffer, tmp); - expecting = (CHAR | STARTQUOTE | DELIMITER); - } else if ((expecting & CHAR) > 0) { - char tmp[2]; - tmp[0] = c; - tmp[1] = '\0'; - strcat(buffer, tmp); - } else { - linkedList_destroy(list); - return NULL; - } - } - - if (strlen(buffer) > 0) { - linkedList_addElement(list, celix_utils_trim(buffer)); - } - } - } - - return list; -} - -static linked_list_pt manifestParser_parseStandardHeaderClause(const char * clauseString) { - linked_list_pt paths = NULL; - linked_list_pt clause = NULL; - linked_list_pt pieces = NULL; - - if(linkedList_create(&paths) != CELIX_SUCCESS){ - return NULL; - } - - pieces = manifestParser_parseDelimitedString(clauseString, ";"); - - if (pieces != NULL) { - int pathCount = 0; - int pieceIdx; - hash_map_pt dirsMap = NULL; - hash_map_pt attrsMap = NULL; - char * sep; - - for (pieceIdx = 0; pieceIdx < linkedList_size(pieces); pieceIdx++) { - char * piece = linkedList_get(pieces, pieceIdx); - if (strchr(piece, '=') != NULL) { - break; - } else { - linkedList_addElement(paths, strdup(piece)); - pathCount++; - } - } - - if (pathCount != 0) { - - dirsMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - attrsMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - - bool failure = false; - char *key = NULL; - char *value = NULL; - - for (pieceIdx = pathCount; pieceIdx < linkedList_size(pieces) && !failure ; pieceIdx++) { - char * sepPtr; - char * DIRECTIVE_SEP = ":="; - char * ATTRIBUTE_SEP = "="; - char * piece = linkedList_get(pieces, pieceIdx); - if ((sepPtr = strstr(piece, DIRECTIVE_SEP)) != NULL) { - sep = DIRECTIVE_SEP; - } else if ((sepPtr = strstr(piece, ATTRIBUTE_SEP)) != NULL) { - sep = ATTRIBUTE_SEP; - } else { - failure=true; - break; - } - - if (strcmp(sep, DIRECTIVE_SEP) == 0) { - // Not implemented - } - else { - - key = string_ndup(piece, sepPtr - piece); - value = strdup(sepPtr+strlen(sep)); - - if (value[0] == '"' && value[strlen(value) -1] == '"') { - char * oldV = strdup(value); - int len = strlen(oldV) - 2; - value = (char *) realloc(value, (sizeof(char) * len+1)); - value[0] = '\0'; - value = strncpy(value, oldV+1, strlen(oldV) - 2); - value[len] = '\0'; - //check if correct - free(oldV); - } - - attribute_pt attr = NULL; - if (hashMap_containsKey(attrsMap, key)) { - failure=true; - break; - } - - if (attribute_create(key, value, &attr) == CELIX_SUCCESS) { - hashMap_put(attrsMap, key, attr); - } - } - } - - if(linkedList_create(&clause) != CELIX_SUCCESS){ - failure=true; - } - - if(failure){ - hashMap_destroy(dirsMap,false,false); - - hash_map_iterator_pt attrIter = hashMapIterator_create(attrsMap); - while(hashMapIterator_hasNext(attrIter)){ - hash_map_entry_pt entry = hashMapIterator_nextEntry(attrIter); - char *mkey = (char*)hashMapEntry_getKey(entry); - attribute_pt mattr = (attribute_pt)hashMapEntry_getValue(entry); - free(mkey); - attribute_destroy(mattr); - } - hashMapIterator_destroy(attrIter); - hashMap_destroy(attrsMap,false,false); - - if(key!=NULL){ - free(key); - } - if(value!=NULL){ - free(value); - } - - linked_list_iterator_pt piter = linkedListIterator_create(paths,0); - while(linkedListIterator_hasNext(piter)){ - free(linkedListIterator_next(piter)); - } - linkedListIterator_destroy(piter); - linkedList_destroy(paths); - - if(clause!=NULL){ - linkedList_destroy(clause); - clause = NULL; - } - } - else{ - linkedList_addElement(clause, paths); - linkedList_addElement(clause, dirsMap); - linkedList_addElement(clause, attrsMap); - } - - } - else{ - linkedList_destroy(paths); - } - - for(int listIdx = 0; listIdx < linkedList_size(pieces); listIdx++){ - void * element = linkedList_get(pieces, listIdx); - free(element); - } - linkedList_destroy(pieces); - } - else{ - linkedList_destroy(paths); - } - - return clause; -} - -static linked_list_pt manifestParser_parseStandardHeader(const char * header) { - linked_list_pt clauseStrings = NULL; - linked_list_pt completeList = NULL; - - if(header != NULL && strlen(header)==0){ - return NULL; - } - - if (linkedList_create(&completeList) == CELIX_SUCCESS) { - if(header!=NULL){ - char *hdr = strdup(header); - clauseStrings = manifestParser_parseDelimitedString(hdr, ","); - free(hdr); - if (clauseStrings != NULL) { - int i; - for (i = 0; i < linkedList_size(clauseStrings); i++) { - char *clauseString = (char *) linkedList_get(clauseStrings, i); - linkedList_addElement(completeList, manifestParser_parseStandardHeaderClause(clauseString)); - free(clauseString); - } - linkedList_destroy(clauseStrings); - } - } - - } - - return completeList; -} - -static linked_list_pt manifestParser_parseImportHeader(const char * header) { - linked_list_pt clauses = NULL; - linked_list_pt requirements = NULL; - bool failure = false; - - int clauseIdx; - linked_list_iterator_pt iter; - clauses = manifestParser_parseStandardHeader(header); - linkedList_create(&requirements); - - for (clauseIdx = 0; clauseIdx < linkedList_size(clauses) && !failure ; clauseIdx++) { - linked_list_pt clause = linkedList_get(clauses, clauseIdx); - - linked_list_pt paths = linkedList_get(clause, 0); - hash_map_pt directives = linkedList_get(clause, 1); - hash_map_pt attributes = linkedList_get(clause, 2); - - int pathIdx; - for (pathIdx = 0; pathIdx < linkedList_size(paths) && !failure ; pathIdx++) { - attribute_pt name = NULL; - requirement_pt req = NULL; - char * path = (char *) linkedList_get(paths, pathIdx); - if (strlen(path) == 0) { - failure = true; - break; - } - - if (attribute_create(strdup("service"), path, &name) == CELIX_SUCCESS) { - char *key = NULL; - attribute_getKey(name, &key); - hashMap_put(attributes, key, name); - } - - requirement_create(directives, attributes, &req); - linkedList_addElement(requirements, req); - } - } - - if(!failure){ - iter = linkedListIterator_create(clauses, 0); - while(linkedListIterator_hasNext(iter)) { - linked_list_pt clause = linkedListIterator_next(iter); - - linked_list_pt paths = linkedList_get(clause, 0); - linkedList_destroy(paths); - - linkedListIterator_remove(iter); - linkedList_destroy(clause); - } - linkedListIterator_destroy(iter); - } - - linkedList_destroy(clauses); - - return requirements; -} - -static linked_list_pt manifestParser_parseExportHeader(module_pt module, const char * header) { - linked_list_pt clauses = NULL; - linked_list_pt capabilities = NULL; - int clauseIdx; - linked_list_iterator_pt iter; - bool failure = false; - - clauses = manifestParser_parseStandardHeader(header); - linkedList_create(&capabilities); - - for (clauseIdx = 0; clauseIdx < linkedList_size(clauses) && !failure ; clauseIdx++) { - linked_list_pt clause = linkedList_get(clauses, clauseIdx); - - linked_list_pt paths = linkedList_get(clause, 0); - hash_map_pt directives = linkedList_get(clause, 1); - hash_map_pt attributes = linkedList_get(clause, 2); - - int pathIdx; - for (pathIdx = 0; pathIdx < linkedList_size(paths) && !failure ; pathIdx++) { - char * path = (char *) linkedList_get(paths, pathIdx); - attribute_pt name = NULL; - capability_pt cap = NULL; - if (strlen(path) == 0) { - failure=true; - break; - } - - if (attribute_create(strdup("service"), path, &name) == CELIX_SUCCESS) { - char *key = NULL; - attribute_getKey(name, &key); - hashMap_put(attributes, key, name); - } - - capability_create(module, directives, attributes, &cap); - linkedList_addElement(capabilities, cap); - } - } - - if(!failure){ - iter = linkedListIterator_create(clauses, 0); - while(linkedListIterator_hasNext(iter)) { - linked_list_pt clause = linkedListIterator_next(iter); - - linked_list_pt paths = linkedList_get(clause, 0); - linkedList_destroy(paths); - - linkedListIterator_remove(iter); - linkedList_destroy(clause); - } - linkedListIterator_destroy(iter); - } - - linkedList_destroy(clauses); - - return capabilities; -} - static celix_status_t manifestParser_getDuplicateEntry(manifest_parser_pt parser, const char* entryName, char **result) { const char *val = manifest_getValue(parser->manifest, entryName); if (result != NULL && val == NULL) { From 479df32741d06bdd260a09e802dc2ca4da339a2e Mon Sep 17 00:00:00 2001 From: PengZheng Date: Sat, 29 Jul 2023 22:51:01 +0800 Subject: [PATCH 3/4] Remove resolver and related dead codes. --- libs/framework/CMakeLists.txt | 2 +- libs/framework/src/bundle.c | 3 - libs/framework/src/capability.c | 64 +--- libs/framework/src/celix_launcher.c | 2 +- libs/framework/src/framework.c | 90 +---- libs/framework/src/framework_private.h | 2 - libs/framework/src/manifest_parser.c | 30 +- libs/framework/src/manifest_parser.h | 2 - libs/framework/src/module.c | 125 +------ libs/framework/src/requirement.c | 79 +--- libs/framework/src/resolver.c | 499 ------------------------- libs/framework/src/resolver.h | 45 --- 12 files changed, 35 insertions(+), 908 deletions(-) delete mode 100644 libs/framework/src/resolver.c delete mode 100644 libs/framework/src/resolver.h diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt index 3cde38606..31235e1c4 100644 --- a/libs/framework/CMakeLists.txt +++ b/libs/framework/CMakeLists.txt @@ -24,7 +24,7 @@ set(FRAMEWORK_SRC src/bundle_context.c src/bundle_revision.c src/framework.c src/manifest.c src/manifest_parser.c src/module.c - src/requirement.c src/capability.c src/resolver.c src/wire.c + src/requirement.c src/capability.c src/wire.c src/service_reference.c src/service_registration.c src/service_registry.c src/service_tracker.c src/service_tracker_customizer.c src/celix_log.c src/celix_launcher.c diff --git a/libs/framework/src/bundle.c b/libs/framework/src/bundle.c index 083a69447..ad6f73d2e 100644 --- a/libs/framework/src/bundle.c +++ b/libs/framework/src/bundle.c @@ -27,7 +27,6 @@ #include #include "framework_private.h" -#include "resolver.h" #include "utils.h" #include "celix_file_utils.h" #include "bundle_archive_private.h" @@ -286,7 +285,6 @@ celix_status_t bundle_revise(bundle_pt bundle, const char * location, const char celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) { celix_arrayList_add(bundle->modules, module); - resolver_addModule(module); //free previous module info free(bundle->symbolicName); @@ -363,7 +361,6 @@ celix_status_t bundle_closeModules(const_bundle_pt bundle) { unsigned int i = 0; for (i = 0; i < arrayList_size(bundle->modules); i++) { module_pt module = (module_pt) arrayList_get(bundle->modules, i); - resolver_removeModule(module); module_setWires(module, NULL); } diff --git a/libs/framework/src/capability.c b/libs/framework/src/capability.c index 4e8236faa..dcf0acd2c 100644 --- a/libs/framework/src/capability.c +++ b/libs/framework/src/capability.c @@ -30,72 +30,26 @@ #include "attribute.h" #include "celix_log.h" +//LCOV_EXCL_START celix_status_t capability_create(module_pt module, hash_map_pt directives, hash_map_pt attributes, capability_pt *capability) { - celix_status_t status; - *capability = (capability_pt) malloc(sizeof(**capability)); - if (!*capability) { - status = CELIX_ENOMEM; - } else { - (*capability)->module = module; - (*capability)->attributes = attributes; - (*capability)->directives = directives; - (*capability)->version = NULL; - - attribute_pt versionAttribute = NULL; - attribute_pt serviceAttribute = (attribute_pt) hashMap_get(attributes, "service"); - status = attribute_getValue(serviceAttribute, &(*capability)->serviceName); - if (status == CELIX_SUCCESS) { - versionAttribute = (attribute_pt) hashMap_get(attributes, "version"); - if (versionAttribute != NULL) { - char *versionStr = NULL; - attribute_getValue(versionAttribute, &versionStr); - status = version_createVersionFromString(versionStr, &(*capability)->version); - } else { - status = version_createEmptyVersion(&(*capability)->version); - } - } - - } - - framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Failed to create capability"); - - return status; + celix_status_t status = CELIX_FRAMEWORK_EXCEPTION; + framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Failed to create capability"); + return status; } celix_status_t capability_destroy(capability_pt capability) { - hash_map_iterator_pt attrIter = hashMapIterator_create(capability->attributes); - while (hashMapIterator_hasNext(attrIter)) { - attribute_pt attr = hashMapIterator_nextValue(attrIter); - hashMapIterator_remove(attrIter); - attribute_destroy(attr); - } - hashMapIterator_destroy(attrIter); - hashMap_destroy(capability->attributes, false, false); - hashMap_destroy(capability->directives, false, false); - - capability->attributes = NULL; - capability->directives = NULL; - capability->module = NULL; - - version_destroy(capability->version); - capability->version = NULL; - - free(capability); - - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t capability_getServiceName(capability_pt capability, const char **serviceName) { - *serviceName = capability->serviceName; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t capability_getVersion(capability_pt capability, version_pt *version) { - *version = capability->version; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t capability_getModule(capability_pt capability, module_pt *module) { - *module = capability->module; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } +//LCOV_EXCL_STOP diff --git a/libs/framework/src/celix_launcher.c b/libs/framework/src/celix_launcher.c index 7ce3a2932..bd9b61a72 100644 --- a/libs/framework/src/celix_launcher.c +++ b/libs/framework/src/celix_launcher.c @@ -273,7 +273,7 @@ static int celixLauncher_createBundleCache(celix_properties_t* embeddedPropertie return CELIX_LAUNCHER_ERROR_EXIT_CODE; } status = celix_framework_utils_createBundleArchivesCache(fw); - status = CELIX_DO_IF(status, framework_destroy(fw)); + (void)framework_destroy(fw); if (status != CELIX_SUCCESS) { fprintf(stderr, "Failed to create bundle cache\n"); return CELIX_LAUNCHER_ERROR_EXIT_CODE; diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c index 208afa500..bc1d500f2 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -42,7 +42,6 @@ #include "bundle_private.h" #include "framework_private.h" #include "linked_list_iterator.h" -#include "resolver.h" #include "service_reference_private.h" #include "service_registration_private.h" #include "celix_scheduled_event.h" @@ -986,83 +985,6 @@ long framework_getNextBundleId(framework_pt framework) { return nextId; } -celix_status_t framework_markResolvedModules(framework_pt framework, linked_list_pt resolvedModuleWireMap) { - celix_status_t status = CELIX_SUCCESS; - if (resolvedModuleWireMap != NULL) { - // hash_map_iterator_pt iterator = hashMapIterator_create(resolvedModuleWireMap); - linked_list_iterator_pt iterator = linkedListIterator_create(resolvedModuleWireMap, linkedList_size(resolvedModuleWireMap)); - while (linkedListIterator_hasPrevious(iterator)) { - importer_wires_pt iw = linkedListIterator_previous(iterator); - // hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator); - module_pt module = iw->importer; - -// bundle_pt bundle = module_getBundle(module); -// bundle_archive_pt archive = NULL; -// bundle_getArchive(bundle, &archive); -// bundle_revision_pt revision = NULL; -// bundleArchive_getCurrentRevision(archive, &revision); -// char *root = NULL; -// bundleRevision_getRoot(revision, &root); -// manifest_pt manifest = NULL; -// bundleRevision_getManifest(revision, &manifest); -// -// char *private = manifest_getValue(manifest, OSGI_FRAMEWORK_PRIVATE_LIBRARY); -// char *export = manifest_getValue(manifest, OSGI_FRAMEWORK_EXPORT_LIBRARY); -// -// printf("Root %s\n", root); - - // for each library update the reference to the wires, if there are any - - linked_list_pt wires = iw->wires; - -// linked_list_iterator_pt wit = linkedListIterator_create(wires, 0); -// while (linkedListIterator_hasNext(wit)) { -// wire_pt wire = linkedListIterator_next(wit); -// module_pt importer = NULL; -// requirement_pt requirement = NULL; -// module_pt exporter = NULL; -// capability_pt capability = NULL; -// wire_getImporter(wire, &importer); -// wire_getRequirement(wire, &requirement); -// -// wire_getExporter(wire, &exporter); -// wire_getCapability(wire, &capability); -// -// char *importerName = NULL; -// module_getSymbolicName(importer, &importerName); -// -// char *exporterName = NULL; -// module_getSymbolicName(exporter, &exporterName); -// -// version_pt version = NULL; -// char *name = NULL; -// capability_getServiceName(capability, &name); -// capability_getVersion(capability, &version); -// char *versionString = NULL; -// version_toString(version, framework->mp, &versionString); -// -// printf("Module %s imports library %s:%s from %s\n", importerName, name, versionString, exporterName); -// } - - if (status == CELIX_SUCCESS) { - module_setWires(module, wires); - resolver_moduleResolved(module); - const char *mname = NULL; - module_getSymbolicName(module, &mname); - status = framework_markBundleResolved(framework, module); - if (status == CELIX_SUCCESS) { - module_setResolved(module); - } - } - linkedListIterator_remove(iterator); - free(iw); - } - linkedListIterator_destroy(iterator); - linkedList_destroy(resolvedModuleWireMap); - } - return status; -} - static celix_status_t framework_markBundleResolved(framework_pt framework, module_pt module) { celix_status_t status = CELIX_SUCCESS; bundle_pt bundle = module_getBundle(module); @@ -2273,7 +2195,6 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce const char* error = ""; const char* name = ""; module_pt module = NULL; - linked_list_pt wires = NULL; celix_bundle_context_t* context = NULL; celix_bundle_activator_t* activator = NULL; @@ -2303,13 +2224,10 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce bundle_getCurrentModule(bndEntry->bnd, &module); module_getSymbolicName(module, &name); if (!module_isResolved(module)) { - wires = resolver_resolve(module); - if (wires == NULL) { - celixThreadRwlock_unlock(&bndEntry->fsmMutex); - return CELIX_BUNDLE_EXCEPTION; - } - status = framework_markResolvedModules(framework, wires); - if (status != CELIX_SUCCESS) { + status = framework_markBundleResolved(framework, module); + if (status == CELIX_SUCCESS) { + module_setResolved(module); + } else { break; } } diff --git a/libs/framework/src/framework_private.h b/libs/framework/src/framework_private.h index 60930dde2..d379d2fb8 100644 --- a/libs/framework/src/framework_private.h +++ b/libs/framework/src/framework_private.h @@ -281,8 +281,6 @@ celix_status_t fw_removeBundleListener(framework_pt framework, bundle_pt bundle, celix_status_t fw_addFrameworkListener(framework_pt framework, bundle_pt bundle, framework_listener_pt listener); celix_status_t fw_removeFrameworkListener(framework_pt framework, bundle_pt bundle, framework_listener_pt listener); -celix_status_t framework_markResolvedModules(framework_pt framework, linked_list_pt wires); - array_list_pt framework_getBundles(framework_pt framework) __attribute__((deprecated("not thread safe, use celix_framework_useBundles instead"))); long framework_getBundle(framework_pt framework, const char* location); bundle_pt framework_getBundleById(framework_pt framework, long id); diff --git a/libs/framework/src/manifest_parser.c b/libs/framework/src/manifest_parser.c index 46275bed3..51ff53793 100644 --- a/libs/framework/src/manifest_parser.c +++ b/libs/framework/src/manifest_parser.c @@ -39,15 +39,12 @@ #include "linked_list_iterator.h" #include "celix_log.h" -//FIXME the manifest parser has no destroy function and as result contains memory leaks. - struct manifestParser { module_pt owner; manifest_pt manifest; version_pt bundleVersion; - linked_list_pt capabilities; - linked_list_pt requirements; + //TODO: Implement Requirement-Capability-Model using RCM library }; celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, manifest_parser_pt *manifest_parser) { @@ -70,9 +67,6 @@ celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, mani version_createEmptyVersion(&parser->bundleVersion); } - linkedList_create(&parser->capabilities); - linkedList_create(&parser->requirements); - *manifest_parser = parser; status = CELIX_SUCCESS; @@ -86,10 +80,6 @@ celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, mani } celix_status_t manifestParser_destroy(manifest_parser_pt mp) { - linkedList_destroy(mp->capabilities); - mp->capabilities = NULL; - linkedList_destroy(mp->requirements); - mp->requirements = NULL; version_destroy(mp->bundleVersion); mp->bundleVersion = NULL; mp->manifest = NULL; @@ -128,20 +118,4 @@ celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt pars celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, version_pt *version) { return version_clone(parser->bundleVersion, version); -} - -celix_status_t manifestParser_getCapabilities(manifest_parser_pt parser, linked_list_pt *capabilities) { - celix_status_t status; - - status = linkedList_clone(parser->capabilities, capabilities); - - return status; -} - -celix_status_t manifestParser_getRequirements(manifest_parser_pt parser, linked_list_pt *requirements) { - celix_status_t status; - - status = linkedList_clone(parser->requirements, requirements); - - return status; -} +} \ No newline at end of file diff --git a/libs/framework/src/manifest_parser.h b/libs/framework/src/manifest_parser.h index 0acae278b..f19de3567 100644 --- a/libs/framework/src/manifest_parser.h +++ b/libs/framework/src/manifest_parser.h @@ -42,7 +42,5 @@ celix_status_t manifestParser_getAndDuplicateName(manifest_parser_pt parser, cha celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt parser, char **description); celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, version_pt *version); celix_status_t manifestParser_getAndDuplicateGroup(manifest_parser_pt parser, char **group); -celix_status_t manifestParser_getCapabilities(manifest_parser_pt parser, linked_list_pt *capabilities); -celix_status_t manifestParser_getRequirements(manifest_parser_pt parser, linked_list_pt *requirements); #endif /* MANIFEST_PARSER_H_ */ diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index 24d007318..78d2641b7 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -47,11 +47,6 @@ struct module { celix_framework_t* fw; - linked_list_pt capabilities; - linked_list_pt requirements; - linked_list_pt wires; - - array_list_pt dependentImporters; version_pt version; char* symbolicName; @@ -60,7 +55,6 @@ struct module { char* description; bool resolved; - manifest_pt headerMap; char * id; celix_bundle_t *bundle; @@ -79,12 +73,9 @@ module_pt module_create(manifest_pt headerMap, const char * moduleId, bundle_pt if (headerMap != NULL && fw != NULL) { module = (module_pt) calloc(1, sizeof(*module)); module->fw = fw; - module->headerMap = headerMap; module->id = strdup(moduleId); module->bundle = bundle; module->resolved = false; - module->dependentImporters = NULL; - arrayList_create(&module->dependentImporters); celixThreadMutex_create(&module->handlesLock, NULL); module->libraryHandles = celix_arrayList_create(); @@ -105,14 +96,6 @@ module_pt module_create(manifest_pt headerMap, const char * moduleId, bundle_pt module->version = NULL; manifestParser_getBundleVersion(mp, &module->version); - module->capabilities = NULL; - manifestParser_getCapabilities(mp, &module->capabilities); - - module->requirements = NULL; - manifestParser_getRequirements(mp, &module->requirements); - - module->wires = NULL; - manifestParser_destroy(mp); } } @@ -135,12 +118,6 @@ module_pt module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) module->description = celix_utils_strdup("The Celix Framework System Bundle"); module->version = NULL; version_createVersion(1, 0, 0, "", &module->version); - linkedList_create(&module->capabilities); - linkedList_create(&module->requirements); - module->dependentImporters = NULL; - arrayList_create(&module->dependentImporters); - module->wires = NULL; - module->headerMap = NULL; module->resolved = false; module->bundle = bundle; celixThreadMutex_create(&module->handlesLock, NULL); @@ -150,45 +127,8 @@ module_pt module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) } void module_destroy(module_pt module) { - arrayList_destroy(module->dependentImporters); version_destroy(module->version); - - if (module->wires != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(module->wires, 0); - while (linkedListIterator_hasNext(iter)) { - wire_pt next = linkedListIterator_next(iter); - linkedListIterator_remove(iter); - wire_destroy(next); - } - linkedListIterator_destroy(iter); - linkedList_destroy(module->wires); - } - - if (module->requirements != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(module->requirements, 0); - while (linkedListIterator_hasNext(iter)) { - requirement_pt next = linkedListIterator_next(iter); - linkedListIterator_remove(iter); - requirement_destroy(next); - } - linkedListIterator_destroy(iter); - linkedList_destroy(module->requirements); - } - - if (module->capabilities != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(module->capabilities, 0); - while (linkedListIterator_hasNext(iter)) { - capability_pt next = linkedListIterator_next(iter); - linkedListIterator_remove(iter); - capability_destroy(next); - } - linkedListIterator_destroy(iter); - linkedList_destroy(module->capabilities); - } - - module->headerMap = NULL; - free(module->id); free(module->symbolicName); free(module->name); @@ -200,22 +140,7 @@ void module_destroy(module_pt module) { } wire_pt module_getWire(module_pt module, const char * serviceName) { - wire_pt wire = NULL; - if (module->wires != NULL) { - linked_list_iterator_pt iterator = linkedListIterator_create(module->wires, 0); - while (linkedListIterator_hasNext(iterator)) { - const char* name; - wire_pt next = linkedListIterator_next(iterator); - capability_pt cap = NULL; - wire_getCapability(next, &cap); - capability_getServiceName(cap, &name); - if (strcasecmp(name, serviceName) == 0) { - wire = next; - } - } - linkedListIterator_destroy(iterator); - } - return wire; + return NULL; } version_pt module_getVersion(module_pt module) { @@ -267,37 +192,10 @@ char * module_getId(module_pt module) { } linked_list_pt module_getWires(module_pt module) { - return module->wires; + return NULL; } void module_setWires(module_pt module, linked_list_pt wires) { - int i = 0; - for (i = 0; (module->wires != NULL) && (i < linkedList_size(module->wires)); i++) { - wire_pt wire = (wire_pt) linkedList_get(module->wires, i); - module_pt exporter = NULL; - wire_getExporter(wire, &exporter); - module_removeDependentImporter(exporter, module); - } - - if (module->wires != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(module->wires, 0); - while (linkedListIterator_hasNext(iter)) { - wire_pt next = linkedListIterator_next(iter); - linkedListIterator_remove(iter); - wire_destroy(next); - } - linkedListIterator_destroy(iter); - linkedList_destroy(module->wires); - } - - module->wires = wires; - - for (i = 0; (module->wires != NULL) && (i < linkedList_size(module->wires)); i++) { - wire_pt wire = (wire_pt) linkedList_get(module->wires, i); - module_pt exporter = NULL; - wire_getExporter(wire, &exporter); - module_addDependentImporter(exporter, module); - } } bool module_isResolved(module_pt module) { @@ -313,31 +211,27 @@ bundle_pt module_getBundle(module_pt module) { } linked_list_pt module_getRequirements(module_pt module) { - return module->requirements; + return NULL; } linked_list_pt module_getCapabilities(module_pt module) { - return module->capabilities; + return NULL; } array_list_pt module_getDependentImporters(module_pt module) { - return module->dependentImporters; + return NULL; } void module_addDependentImporter(module_pt module, module_pt importer) { - if (!arrayList_contains(module->dependentImporters, importer)) { - arrayList_add(module->dependentImporters, importer); - } } void module_removeDependentImporter(module_pt module, module_pt importer) { - arrayList_removeElement(module->dependentImporters, importer); } //---------------------------------------------------- //TODO add implementation (functions not implemented but already exported) array_list_pt module_getDependentRequirers(module_pt module) { - return NULL; + return NULL; } void module_addDependentRequirer(module_pt module, module_pt requirer) { @@ -348,12 +242,7 @@ void module_removeDependentRequirer(module_pt module, module_pt requirer) { //---------------------------------------------------- array_list_pt module_getDependents(module_pt module) { - array_list_pt dependents = NULL; - arrayList_create(&dependents); - - arrayList_addAll(dependents, module->dependentImporters); - - return dependents; + return NULL; } celix_status_t celix_module_closeLibraries(celix_module_t* module) { diff --git a/libs/framework/src/requirement.c b/libs/framework/src/requirement.c index 84efcaa85..032fed404 100644 --- a/libs/framework/src/requirement.c +++ b/libs/framework/src/requirement.c @@ -31,85 +31,28 @@ #include "attribute.h" #include "celix_log.h" +//LCOV_EXCL_START celix_status_t requirement_create(hash_map_pt directives, hash_map_pt attributes, requirement_pt *requirement) { - celix_status_t status; - - *requirement = (requirement_pt) malloc(sizeof(**requirement)); - if (!*requirement) { - status = CELIX_ENOMEM; - } else { - attribute_pt serviceAttribute = NULL; - attribute_pt versionAttribute = NULL; - - (*requirement)->attributes = attributes; - (*requirement)->directives = directives; - (*requirement)->versionRange = NULL; - - serviceAttribute = (attribute_pt) hashMap_get(attributes, "service"); - status = attribute_getValue(serviceAttribute, &(*requirement)->targetName); - if (status == CELIX_SUCCESS) { - versionAttribute = (attribute_pt) hashMap_get(attributes, "version"); - if (versionAttribute != NULL) { - char *versionStr = NULL; - attribute_getValue(versionAttribute, &versionStr); - status = versionRange_parse(versionStr, &(*requirement)->versionRange); - } else { - status = versionRange_createInfiniteVersionRange(&(*requirement)->versionRange); - } - } - } - - framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot create requirement"); - - return status; + celix_status_t status = CELIX_FRAMEWORK_EXCEPTION; + framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot create requirement"); + return status; } celix_status_t requirement_destroy(requirement_pt requirement) { - hash_map_iterator_pt attrIter = hashMapIterator_create(requirement->attributes); - while (hashMapIterator_hasNext(attrIter)) { - attribute_pt attr = hashMapIterator_nextValue(attrIter); - hashMapIterator_remove(attrIter); - attribute_destroy(attr); - } - hashMapIterator_destroy(attrIter); - hashMap_destroy(requirement->attributes, false, false); - hashMap_destroy(requirement->directives, false, false); - - requirement->attributes = NULL; - requirement->directives = NULL; - - versionRange_destroy(requirement->versionRange); - requirement->versionRange = NULL; - - free(requirement); - - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t requirement_getVersionRange(requirement_pt requirement, celix_version_range_t **range) { - *range = requirement->versionRange; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t requirement_getTargetName(requirement_pt requirement, const char **targetName) { - *targetName = requirement->targetName; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t requirement_isSatisfied(requirement_pt requirement, capability_pt capability, bool *inRange) { - celix_status_t status; - version_pt version = NULL; - version_range_pt range = NULL; - - status = capability_getVersion(capability, &version); - if (status == CELIX_SUCCESS) { - status = requirement_getVersionRange(requirement, &range); - if (status == CELIX_SUCCESS) { - status = versionRange_isInRange(range, version, inRange); - } - } - - framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot check if requirement is satisfied"); - - return status; + celix_status_t status = CELIX_FRAMEWORK_EXCEPTION; + framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot check if requirement is satisfied"); + return status; } +//LCOV_EXCL_STOP diff --git a/libs/framework/src/resolver.c b/libs/framework/src/resolver.c deleted file mode 100644 index 5b68632a9..000000000 --- a/libs/framework/src/resolver.c +++ /dev/null @@ -1,499 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * resolver.c - * - * \date Jul 13, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include -#include - -#include "resolver.h" -#include "linked_list_iterator.h" -#include "bundle.h" -#include "celix_log.h" - -struct capabilityList { - char * serviceName; - linked_list_pt capabilities; -}; - -typedef struct capabilityList * capability_list_pt; - -struct candidateSet { - module_pt module; - requirement_pt requirement; - linked_list_pt candidates; -}; - -typedef struct candidateSet * candidate_set_pt; - -// List containing module_ts -linked_list_pt m_modules = NULL; -// List containing capability_t_LISTs -linked_list_pt m_unresolvedServices = NULL; -// List containing capability_t_LISTs -linked_list_pt m_resolvedServices = NULL; - -int resolver_populateCandidatesMap(hash_map_pt candidatesMap, module_pt targetModule); -capability_list_pt resolver_getCapabilityList(linked_list_pt list, const char* name); -void resolver_removeInvalidCandidate(module_pt module, hash_map_pt candidates, linked_list_pt invalid); -linked_list_pt resolver_populateWireMap(hash_map_pt candidates, module_pt importer, linked_list_pt wireMap); - -linked_list_pt resolver_resolve(module_pt root) { - hash_map_pt candidatesMap = NULL; - linked_list_pt wireMap = NULL; - linked_list_pt resolved = NULL; - hash_map_iterator_pt iter = NULL; - - if (module_isResolved(root)) { - return NULL; - } - - candidatesMap = hashMap_create(NULL, NULL, NULL, NULL); - - if (resolver_populateCandidatesMap(candidatesMap, root) != 0) { - iter = hashMapIterator_create(candidatesMap); - while (hashMapIterator_hasNext(iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); - linked_list_pt value = hashMapEntry_getValue(entry); - hashMapIterator_remove(iter); - if (value != NULL) { - linked_list_iterator_pt candSetIter = linkedListIterator_create(value, 0); - while (linkedListIterator_hasNext(candSetIter)) { - candidate_set_pt set = linkedListIterator_next(candSetIter); - linkedList_destroy(set->candidates); - free(set); - linkedListIterator_remove(candSetIter); - } - linkedListIterator_destroy(candSetIter); - linkedList_destroy(value); - } - } - hashMapIterator_destroy(iter); - hashMap_destroy(candidatesMap, false, false); - return NULL; - } - - linkedList_create(&wireMap); - resolved = resolver_populateWireMap(candidatesMap, root, wireMap); - iter = hashMapIterator_create(candidatesMap); - while (hashMapIterator_hasNext(iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); - linked_list_pt value = hashMapEntry_getValue(entry); - hashMapIterator_remove(iter); - if (value != NULL) { - linked_list_iterator_pt candSetIter = linkedListIterator_create(value, 0); - while (linkedListIterator_hasNext(candSetIter)) { - candidate_set_pt set = linkedListIterator_next(candSetIter); - linkedList_destroy(set->candidates); - free(set); - linkedListIterator_remove(candSetIter); - } - linkedListIterator_destroy(candSetIter); - linkedList_destroy(value); - } - } - hashMapIterator_destroy(iter); - hashMap_destroy(candidatesMap, false, false); - return resolved; -} - -int resolver_populateCandidatesMap(hash_map_pt candidatesMap, module_pt targetModule) { - linked_list_pt candSetList; - linked_list_pt candidates; - linked_list_pt invalid; - - if (hashMap_containsKey(candidatesMap, targetModule)) { - return 0; - } - - hashMap_put(candidatesMap, targetModule, NULL); - - if (linkedList_create(&candSetList) == CELIX_SUCCESS) { - int i; - for (i = 0; i < linkedList_size(module_getRequirements(targetModule)); i++) { - capability_list_pt capList; - requirement_pt req; - const char *targetName = NULL; - req = (requirement_pt) linkedList_get(module_getRequirements(targetModule), i); - requirement_getTargetName(req, &targetName); - capList = resolver_getCapabilityList(m_resolvedServices, targetName); - - if (linkedList_create(&candidates) == CELIX_SUCCESS) { - int c; - for (c = 0; (capList != NULL) && (c < linkedList_size(capList->capabilities)); c++) { - capability_pt cap = (capability_pt) linkedList_get(capList->capabilities, c); - bool satisfied = false; - requirement_isSatisfied(req, cap, &satisfied); - if (satisfied) { - linkedList_addElement(candidates, cap); - } - } - capList = resolver_getCapabilityList(m_unresolvedServices, targetName); - for (c = 0; (capList != NULL) && (c < linkedList_size(capList->capabilities)); c++) { - capability_pt cap = (capability_pt) linkedList_get(capList->capabilities, c); - bool satisfied = false; - requirement_isSatisfied(req, cap, &satisfied); - if (satisfied) { - linkedList_addElement(candidates, cap); - } - } - - if (linkedList_size(candidates) > 0) { - linked_list_iterator_pt iterator = NULL; - for (iterator = linkedListIterator_create(candidates, 0); linkedListIterator_hasNext(iterator);) { - capability_pt candidate = (capability_pt) linkedListIterator_next(iterator); - module_pt module = NULL; - capability_getModule(candidate, &module); - if (!module_isResolved(module)) { - if (resolver_populateCandidatesMap(candidatesMap, module) != 0) { - linkedListIterator_remove(iterator); - } - } - } - linkedListIterator_destroy(iterator); - } - - if (linkedList_size(candidates) == 0) { - if (linkedList_create(&invalid) == CELIX_SUCCESS) { - const char *name = NULL; - resolver_removeInvalidCandidate(targetModule, candidatesMap, invalid); - - module_getSymbolicName(targetModule, &name); - - linkedList_destroy(invalid); - fw_log(celix_frameworkLogger_globalLogger(), CELIX_LOG_LEVEL_INFO, "Unable to resolve: %s, %s\n", name, targetName); - } - linkedList_destroy(candidates); - linkedList_destroy(candSetList); - return -1; - } else if (linkedList_size(candidates) > 0) { - candidate_set_pt cs = (candidate_set_pt) malloc(sizeof(*cs)); - cs->candidates = candidates; - cs->module = targetModule; - cs->requirement = req; - linkedList_addElement(candSetList, cs); - } - - } - } - hashMap_put(candidatesMap, targetModule, candSetList); - } - return 0; -} - -void resolver_removeInvalidCandidate(module_pt invalidModule, hash_map_pt candidates, linked_list_pt invalid) { - hash_map_iterator_pt iterator; - hashMap_remove(candidates, invalidModule); - - for (iterator = hashMapIterator_create(candidates); hashMapIterator_hasNext(iterator);) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator); - linked_list_pt candSetList = (linked_list_pt) hashMapEntry_getValue(entry); - if (candSetList != NULL) { - linked_list_iterator_pt itCandSetList; - for (itCandSetList = linkedListIterator_create(candSetList, 0); linkedListIterator_hasNext(itCandSetList);) { - candidate_set_pt set = (candidate_set_pt) linkedListIterator_next(itCandSetList); - linked_list_iterator_pt candIter; - for (candIter = linkedListIterator_create(set->candidates, 0); linkedListIterator_hasNext(candIter);) { - capability_pt candCap = (capability_pt) linkedListIterator_next(candIter); - module_pt module = NULL; - capability_getModule(candCap, &module); - if (module == invalidModule) { - linkedListIterator_remove(candIter); - if (linkedList_size(set->candidates) == 0) { - linkedListIterator_remove(itCandSetList); - if (module != invalidModule && linkedList_contains(invalid, module)) { - linkedList_addElement(invalid, module); - } - } - break; - } - } - linkedListIterator_destroy(candIter); - } - linkedListIterator_destroy(itCandSetList); - } - } - hashMapIterator_destroy(iterator); - - if (linkedList_size(invalid) > 0) { - while (!linkedList_isEmpty(invalid)) { - module_pt m = (module_pt) linkedList_removeIndex(invalid, 0); - resolver_removeInvalidCandidate(m, candidates, invalid); - } - } -} - -void resolver_addModule(module_pt module) { - - if (m_modules == NULL) { - linkedList_create(&m_modules); - linkedList_create(&m_unresolvedServices); - linkedList_create(&m_resolvedServices); - } - - if (m_modules != NULL && m_unresolvedServices != NULL) { - int i; - - linkedList_addElement(m_modules, module); - - for (i = 0; i < linkedList_size(module_getCapabilities(module)); i++) { - const char *serviceName = NULL; - capability_list_pt list = NULL; - capability_pt cap; - - cap = (capability_pt) linkedList_get(module_getCapabilities(module), i); - capability_getServiceName(cap, &serviceName); - list = resolver_getCapabilityList(m_unresolvedServices, serviceName); - if (list == NULL) { - list = (capability_list_pt) malloc(sizeof(*list)); - if (list != NULL) { - list->serviceName = strdup(serviceName); - if (linkedList_create(&list->capabilities) == CELIX_SUCCESS) { - linkedList_addElement(m_unresolvedServices, list); - } - else{ - free(list->serviceName); - free(list); - list=NULL; - } - } - } - if(list != NULL){ - linkedList_addElement(list->capabilities, cap); - } - } - } -} - -void resolver_removeModule(module_pt module) { - if (m_modules == NULL) { - return; - } - linked_list_pt caps = NULL; - linkedList_removeElement(m_modules, module); - caps = module_getCapabilities(module); - if (caps != NULL) { - int i = 0; - for (i = 0; i < linkedList_size(caps); i++) { - capability_pt cap = (capability_pt) linkedList_get(caps, i); - const char *serviceName = NULL; - capability_list_pt list; - capability_getServiceName(cap, &serviceName); - list = resolver_getCapabilityList(m_unresolvedServices, serviceName); - if (list != NULL) { - linkedList_removeElement(list->capabilities, cap); - - if (linkedList_isEmpty(list->capabilities)) { - linkedList_removeElement(m_unresolvedServices, list); - linkedList_destroy(list->capabilities); - free(list->serviceName); - free(list); - } - } - list = resolver_getCapabilityList(m_resolvedServices, serviceName); - if (list != NULL) { - linkedList_removeElement(list->capabilities, cap); - - if (linkedList_isEmpty(list->capabilities)) { - linkedList_removeElement(m_resolvedServices, list); - linkedList_destroy(list->capabilities); - free(list->serviceName); - free(list); - } - } - } - } - if (linkedList_isEmpty(m_modules)) { - linkedList_destroy(m_modules); - m_modules = NULL; - - if (!linkedList_isEmpty(m_unresolvedServices)) { - // #TODO: Something is wrong, not all modules have been removed from the resolver - fw_log(celix_frameworkLogger_globalLogger(), CELIX_LOG_LEVEL_ERROR, "Unexpected entries in unresolved module list"); - } - linkedList_destroy(m_unresolvedServices); - m_unresolvedServices = NULL; - if (!linkedList_isEmpty(m_resolvedServices)) { - // #TODO: Something is wrong, not all modules have been removed from the resolver - fw_log(celix_frameworkLogger_globalLogger(), CELIX_LOG_LEVEL_ERROR, "Unexpected entries in resolved module list"); - } - linkedList_destroy(m_resolvedServices); - m_resolvedServices = NULL; - } -} - -void resolver_moduleResolved(module_pt module) { - - if (module_isResolved(module)) { - linked_list_pt capsCopy = NULL; - - if (linkedList_create(&capsCopy) == CELIX_SUCCESS) { - linked_list_pt wires = NULL; - int capIdx; - - for (capIdx = 0; (module_getCapabilities(module) != NULL) && (capIdx < linkedList_size(module_getCapabilities(module))); capIdx++) { - capability_pt cap = (capability_pt) linkedList_get(module_getCapabilities(module), capIdx); - const char *serviceName = NULL; - capability_list_pt list; - capability_getServiceName(cap, &serviceName); - list = resolver_getCapabilityList(m_unresolvedServices, serviceName); - if(list != NULL){ - linkedList_removeElement(list->capabilities, cap); - } - - linkedList_addElement(capsCopy, cap); - } - - wires = module_getWires(module); - for (capIdx = 0; (capsCopy != NULL) && (capIdx < linkedList_size(capsCopy)); capIdx++) { - capability_pt cap = linkedList_get(capsCopy, capIdx); - - int wireIdx = 0; - for (wireIdx = 0; (wires != NULL) && (wireIdx < linkedList_size(wires)); wireIdx++) { - wire_pt wire = (wire_pt) linkedList_get(wires, wireIdx); - requirement_pt req = NULL; - bool satisfied = false; - wire_getRequirement(wire, &req); - requirement_isSatisfied(req, cap, &satisfied); - if (satisfied) { - linkedList_set(capsCopy, capIdx, NULL); - break; - } - } - } - - for (capIdx = 0; (capsCopy != NULL) && (capIdx < linkedList_size(capsCopy)); capIdx++) { - capability_pt cap = linkedList_get(capsCopy, capIdx); - - if (cap != NULL) { - const char *serviceName = NULL; - capability_list_pt list = NULL; - capability_getServiceName(cap, &serviceName); - - list = resolver_getCapabilityList(m_resolvedServices, serviceName); - if (list == NULL) { - list = (capability_list_pt) malloc(sizeof(*list)); - if (list != NULL) { - list->serviceName = strdup(serviceName); - if (linkedList_create(&list->capabilities) == CELIX_SUCCESS) { - linkedList_addElement(m_resolvedServices, list); - } - else{ - free(list->serviceName); - free(list); - list=NULL; - } - } - } - if(list != NULL){ - linkedList_addElement(list->capabilities, cap); - } - } - } - - linkedList_destroy(capsCopy); - } - } -} - -capability_list_pt resolver_getCapabilityList(linked_list_pt list, const char * name) { - capability_list_pt capabilityList = NULL; - linked_list_iterator_pt iterator = linkedListIterator_create(list, 0); - while (linkedListIterator_hasNext(iterator)) { - capability_list_pt services = (capability_list_pt) linkedListIterator_next(iterator); - if (strcmp(services->serviceName, name) == 0) { - capabilityList = services; - break; - } - } - linkedListIterator_destroy(iterator); - return capabilityList; -} - -linked_list_pt resolver_populateWireMap(hash_map_pt candidates, module_pt importer, linked_list_pt wireMap) { - linked_list_pt serviceWires; - - if (candidates && importer && wireMap) { - linked_list_pt candSetList = NULL; - bool resolved = false; - - if (module_isResolved(importer)) { - // already resolved - resolved = true; - } - if (!resolved) { - bool self = false; - linked_list_iterator_pt wit = linkedListIterator_create(wireMap, 0); - while (linkedListIterator_hasNext(wit)) { - importer_wires_pt iw = linkedListIterator_next(wit); - if (iw->importer == importer) { - // Do not resolve yourself - self = true; - break; - } - } - linkedListIterator_destroy(wit); - - if (!self) { - candSetList = (linked_list_pt) hashMap_get(candidates, importer); - - if (linkedList_create(&serviceWires) == CELIX_SUCCESS) { -// if (linkedList_create(&emptyWires) == CELIX_SUCCESS) { - int candSetIdx = 0; - - // hashMap_put(wireMap, importer, emptyWires); - - const char *mname = NULL; - module_getSymbolicName(importer, &mname); - - importer_wires_pt importerWires = malloc(sizeof(*importerWires)); - importerWires->importer = importer; - importerWires->wires = NULL; - linkedList_addElement(wireMap, importerWires); - - for (candSetIdx = 0; candSetIdx < linkedList_size(candSetList); candSetIdx++) { - candidate_set_pt cs = (candidate_set_pt) linkedList_get(candSetList, candSetIdx); - - module_pt module = NULL; - capability_getModule(((capability_pt) linkedList_get(cs->candidates, 0)), &module); - if (importer != module) { - wire_pt wire = NULL; - wire_create(importer, cs->requirement, module, ((capability_pt) linkedList_get(cs->candidates, 0)), &wire); - linkedList_addElement(serviceWires, wire); - } - - wireMap = resolver_populateWireMap(candidates, module, wireMap); - } - - importerWires->wires = serviceWires; - // hashMap_put(wireMap, importer, serviceWires); -// } - } - } - } - } - - return wireMap; -} diff --git a/libs/framework/src/resolver.h b/libs/framework/src/resolver.h deleted file mode 100644 index c44bb66c6..000000000 --- a/libs/framework/src/resolver.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * resolver.h - * - * \date Jul 13, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef RESOLVER_H_ -#define RESOLVER_H_ - -#include "module.h" -#include "wire.h" -#include "hash_map.h" - -struct importer_wires { - module_pt importer; - linked_list_pt wires; -}; -typedef struct importer_wires *importer_wires_pt; - -linked_list_pt resolver_resolve(module_pt root); -void resolver_moduleResolved(module_pt module); -void resolver_addModule(module_pt module); -void resolver_removeModule(module_pt module); - -#endif /* RESOLVER_H_ */ From d6637a982fa96569b6ac584bdc858342994af8a2 Mon Sep 17 00:00:00 2001 From: PengZheng Date: Sun, 30 Jul 2023 16:52:33 +0800 Subject: [PATCH 4/4] Remove support for wire. --- libs/framework/src/wire.c | 53 ++++++++++++--------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/libs/framework/src/wire.c b/libs/framework/src/wire.c index 993e91c62..ae13dd8f6 100644 --- a/libs/framework/src/wire.c +++ b/libs/framework/src/wire.c @@ -29,60 +29,39 @@ #include "wire.h" struct wire { - module_pt importer; - requirement_pt requirement; - module_pt exporter; - capability_pt capability; + module_pt importer; + requirement_pt requirement; + module_pt exporter; + capability_pt capability; }; -celix_status_t wire_create(module_pt importer, requirement_pt requirement, - module_pt exporter, capability_pt capability, wire_pt *wire) { - celix_status_t status = CELIX_SUCCESS; +//LCOV_EXCL_START +celix_status_t wire_create( + module_pt importer, requirement_pt requirement, module_pt exporter, capability_pt capability, wire_pt* wire) { + celix_status_t status = CELIX_FRAMEWORK_EXCEPTION; - if (*wire != NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - } else { - (*wire) = (wire_pt) malloc(sizeof(**wire)); - if (!*wire) { - status = CELIX_ENOMEM; - } else { - (*wire)->importer = importer; - (*wire)->requirement = requirement; - (*wire)->exporter = exporter; - (*wire)->capability = capability; - } - } + framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot create wire"); - framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot create wire"); - - return status; + return status; } celix_status_t wire_destroy(wire_pt wire) { - wire->importer = NULL; - wire->requirement = NULL; - wire->exporter = NULL; - wire->capability = NULL; - free(wire); - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t wire_getCapability(wire_pt wire, capability_pt *capability) { - *capability = wire->capability; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t wire_getRequirement(wire_pt wire, requirement_pt *requirement) { - *requirement = wire->requirement; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t wire_getImporter(wire_pt wire, module_pt *importer) { - *importer = wire->importer; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } celix_status_t wire_getExporter(wire_pt wire, module_pt *exporter) { - *exporter = wire->exporter; - return CELIX_SUCCESS; + return CELIX_FRAMEWORK_EXCEPTION; } +//LCOV_EXCL_STOP