celix_status_t versionRange_isInRange(version_range_pt versionRange, version_pt version, bool *inRange) { celix_status_t status; if (versionRange->high == NULL) { int cmp; status = version_compareTo(version, versionRange->low, &cmp); if (status == CELIX_SUCCESS) { *inRange = (cmp >= 0); } } else if (versionRange->isLowInclusive && versionRange->isHighInclusive) { int low, high; status = version_compareTo(version, versionRange->low, &low); if (status == CELIX_SUCCESS) { status = version_compareTo(version, versionRange->high, &high); if (status == CELIX_SUCCESS) { *inRange = (low >= 0) && (high <= 0); } } } else if (versionRange->isHighInclusive) { int low, high; status = version_compareTo(version, versionRange->low, &low); if (status == CELIX_SUCCESS) { status = version_compareTo(version, versionRange->high, &high); if (status == CELIX_SUCCESS) { *inRange = (low > 0) && (high <= 0); } } } else if (versionRange->isLowInclusive) { int low, high; status = version_compareTo(version, versionRange->low, &low); if (status == CELIX_SUCCESS) { status = version_compareTo(version, versionRange->high, &high); if (status == CELIX_SUCCESS) { *inRange = (low >= 0) && (high < 0); } } } else { int low, high; status = version_compareTo(version, versionRange->low, &low); if (status == CELIX_SUCCESS) { status = version_compareTo(version, versionRange->high, &high); if (status == CELIX_SUCCESS) { *inRange = (low > 0) && (high < 0); } } } return status; }
static void checkInterfaceVersion(dyn_interface_type* dynIntf, const char* v) { int status; char *version = NULL; status = dynInterface_getVersionString(dynIntf, &version); CHECK_EQUAL(0, status); STRCMP_EQUAL(v, version); version_pt msgVersion = NULL, localMsgVersion = NULL; int cmpVersion = -1; version_createVersionFromString(version, &localMsgVersion); status = dynInterface_getVersion(dynIntf, &msgVersion); CHECK_EQUAL(0, status); version_compareTo(msgVersion, localMsgVersion, &cmpVersion); CHECK_EQUAL(cmpVersion, 0); version_destroy(localMsgVersion); }
celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) { celix_status_t status = CELIX_SUCCESS; bundle_archive_pt archive = NULL; bundle_revision_pt revision = NULL; manifest_pt headerMap = NULL; status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive)); status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &headerMap)); if (status == CELIX_SUCCESS) { long bundleId; status = bundleArchive_getId(bundle->archive, &bundleId); if (status == CELIX_SUCCESS) { int revision = 0; char moduleId[512]; char *mId; snprintf(moduleId, sizeof(moduleId), "%ld.%d", bundleId, revision); mId = strdup(moduleId); *module = module_create(headerMap, mId, bundle); free(mId); if (*module != NULL) { version_pt bundleVersion = module_getVersion(*module); char * symName = NULL; status = module_getSymbolicName(*module, &symName); if (status == CELIX_SUCCESS) { array_list_pt bundles = framework_getBundles(bundle->framework); unsigned int i; for (i = 0; i < arrayList_size(bundles); i++) { bundle_pt check = (bundle_pt) arrayList_get(bundles, i); long id; if (bundleArchive_getId(check->archive, &id) == CELIX_SUCCESS) { if (id != bundleId) { module_pt mod = NULL; char * sym = NULL; version_pt version; int cmp; status = bundle_getCurrentModule(check, &mod); status = module_getSymbolicName(mod, &sym); version = module_getVersion(mod); version_compareTo(bundleVersion, version, &cmp); if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) && !cmp) { char *versionString = NULL; version_toString(version, &versionString); printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, versionString); free(versionString); status = CELIX_BUNDLE_EXCEPTION; break; } } } } arrayList_destroy(bundles); } } } } framework_logIfError(bundle->framework->logger, status, NULL, "Failed to create module"); return status; }