Exemple #1
0
celix_status_t driverLoader_unloadDrivers(driver_loader_pt loader, driver_attributes_pt finalDriver) {
	celix_status_t status = CELIX_SUCCESS;

	service_reference_pt finalReference = NULL;
	if (finalDriver != NULL) {
		status = driverAttributes_getReference(finalDriver, &finalReference);
	}
	if (status == CELIX_SUCCESS) {
		int i;
		for (i = 0; i < arrayList_size(loader->loadedDrivers); i++) {
			service_reference_pt reference = arrayList_get(loader->loadedDrivers, i);
			bool equal = false;
			status = serviceReference_equals(reference, finalReference, &equal);
			if (status == CELIX_SUCCESS && !equal) {
				bundle_pt bundle = NULL;
				status = serviceReference_getBundle(reference, &bundle);
				if (status == CELIX_SUCCESS) {
					bundle_uninstall(bundle); // Ignore status
				}
			}
		}
	}

	return status;
}
Exemple #2
0
celix_status_t driverMatcher_add(driver_matcher_pt matcher, int matchValue, driver_attributes_pt attributes) {
	celix_status_t status = CELIX_SUCCESS;

	array_list_pt da = NULL;
	status = driverMatcher_get(matcher, matchValue, &da);
	if (status == CELIX_SUCCESS) {
		arrayList_add(da, attributes);

		match_pt match = NULL;
		match = apr_palloc(matcher->pool, sizeof(*match));
		if (!match) {
			status = CELIX_ENOMEM;
		} else {
			match->matchValue = matchValue;
			match->reference = NULL;
			driverAttributes_getReference(attributes, &match->reference);
			arrayList_add(matcher->matches, match);
		}
	}

	return status;
}
Exemple #3
0
celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_pt matcher, apr_pool_t *pool, match_pt *match) {
	celix_status_t status = CELIX_SUCCESS;

	if (!hashMap_isEmpty(matcher->attributes)) {
		match_key_t matchKey = NULL;
		hash_map_iterator_pt iter = hashMapIterator_create(matcher->attributes);
		while (hashMapIterator_hasNext(iter)) {
			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
			match_key_t key = hashMapEntry_getKey(entry);
			if (matchKey == NULL || matchKey->matchValue < key->matchValue) {
				matchKey = key;
			}
		}
		hashMapIterator_destroy(iter);

		array_list_pt das = hashMap_get(matcher->attributes, matchKey);
		service_reference_pt best = NULL;
		int i;
		for (i = 0; i < arrayList_size(das); i++) {
			driver_attributes_pt attributes = arrayList_get(das, i);
			service_reference_pt reference = NULL;

			celix_status_t substatus = driverAttributes_getReference(attributes, &reference);
			if (substatus == CELIX_SUCCESS) {
				if (best != NULL) {
					printf("DRIVER_MATCHER: Compare ranking\n");
					char *rank1Str, *rank2Str;
					int rank1, rank2;
					service_registration_pt registration = NULL;
					substatus = serviceReference_getServiceRegistration(reference, &registration);
					if (substatus == CELIX_SUCCESS) {
						properties_pt properties = NULL;
						status = serviceRegistration_getProperties(registration, &properties);
						if (status == CELIX_SUCCESS) {

							rank1Str = properties_getWithDefault(properties, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, "0");
							rank2Str = properties_getWithDefault(properties, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, "0");

							rank1 = atoi(rank1Str);
							rank2 = atoi(rank2Str);

							if (rank1 != rank2) {
								if (rank1 > rank2) {
									best = reference;
								}
							} else {
								printf("DRIVER_MATCHER: Compare id's\n");
								char *id1Str, *id2Str;
								long id1, id2;

								id1Str = properties_get(properties, (char *) OSGI_FRAMEWORK_SERVICE_ID);
								id2Str = properties_get(properties, (char *) OSGI_FRAMEWORK_SERVICE_ID);

								id1 = atol(id1Str);
								id2 = atol(id2Str);

								if (id1 < id2) {
									best = reference;
								}
							}
						}
					}
				} else {
					best = reference;
				}
			}

		}

		*match = apr_palloc(pool, sizeof(**match));
		if (!*match) {
			status = CELIX_ENOMEM;
		} else {
			(*match)->matchValue = matchKey->matchValue;
			(*match)->reference = best;
		}
	}

	return status;
}
Exemple #4
0
celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_pt matcher, match_pt *match) {
    celix_status_t status = CELIX_SUCCESS;

    if (!hashMap_isEmpty(matcher->attributes)) {
        match_key_t matchKey = NULL;
        hash_map_iterator_pt iter = hashMapIterator_create(matcher->attributes);
        while (hashMapIterator_hasNext(iter)) {
            hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
            match_key_t key = hashMapEntry_getKey(entry);
            if (matchKey == NULL || matchKey->matchValue < key->matchValue) {
                matchKey = key;
            }
        }
        hashMapIterator_destroy(iter);

        array_list_pt das = hashMap_get(matcher->attributes, matchKey);
        service_reference_pt best = NULL;
        int i;
        for (i = 0; i < arrayList_size(das); i++) {
            driver_attributes_pt attributes = arrayList_get(das, i);
            service_reference_pt reference = NULL;

            celix_status_t substatus = driverAttributes_getReference(attributes, &reference);
            if (substatus == CELIX_SUCCESS) {
                if (best != NULL) {
                    char *rank1Str, *rank2Str;
                    int rank1, rank2;

                    rank1Str = "0";
                    rank2Str = "0";

                    logHelper_log(matcher->loghelper, OSGI_LOGSERVICE_DEBUG, "DRIVER_MATCHER: Compare ranking");

                    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank1Str);
                    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank2Str);

                    rank1 = atoi(rank1Str);
                    rank2 = atoi(rank2Str);

                    if (rank1 != rank2) {
                        if (rank1 > rank2) {
                            best = reference;
                        }
                    } else {
                        char *id1Str, *id2Str;
                        long id1, id2;

                        id1Str = NULL;
                        id2Str = NULL;

                        logHelper_log(matcher->loghelper, OSGI_LOGSERVICE_DEBUG, "DRIVER_MATCHER: Compare id's");

                        serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_ID, &id1Str);
                        serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_ID, &id2Str);

                        id1 = atol(id1Str);
                        id2 = atol(id2Str);

                        if (id1 < id2) {
                            best = reference;
                        }
                    }
                } else {
                    best = reference;
                }
            }

        }

        *match = calloc(1, sizeof(**match));
        if (!*match) {
            status = CELIX_ENOMEM;
        } else {
            (*match)->matchValue = matchKey->matchValue;
            (*match)->reference = best;
        }
    }

    return status;
}