This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/511-remove-resolver
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to refs/heads/feature/511-remove-resolver by
this push:
new 479df327 Remove resolver and related dead codes.
479df327 is described below
commit 479df32741d06bdd260a09e802dc2ca4da339a2e
Author: PengZheng <[email protected]>
AuthorDate: Sat Jul 29 22:51:01 2023 +0800
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(-)
diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt
index 3cde3860..31235e1c 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 083a6944..ad6f73d2 100644
--- a/libs/framework/src/bundle.c
+++ b/libs/framework/src/bundle.c
@@ -27,7 +27,6 @@
#include <unistd.h>
#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 4e8236fa..dcf0acd2 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 7ce3a293..bd9b61a7 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 208afa50..bc1d500f 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 60930dde..d379d2fb 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 46275bed..51ff5379 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 0acae278..f19de356 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 24d00731..78d2641b 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 84efcaa8..032fed40 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 5b68632a..00000000
--- 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 <a href="mailto:[email protected]">Apache Celix
Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#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 c44bb66c..00000000
--- 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 <a href="mailto:[email protected]">Apache Celix
Project Team</a>
- * \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_ */