Example #1
0
static celix_status_t deviceManager_attachAlgorithm(device_manager_pt manager, service_reference_pt ref, void *service) {
	celix_status_t status = CELIX_SUCCESS;

	driver_loader_pt loader = NULL;
	status = driverLoader_create(manager->context, &loader);
	if (status == CELIX_SUCCESS) {
		array_list_pt included = NULL;
		array_list_pt excluded = NULL;

		array_list_pt driverIds = NULL;

		hashMap_put(manager->devices, ref, service);

		status = arrayList_create(&included);
		if (status == CELIX_SUCCESS) {
			status = arrayList_create(&excluded);
			if (status == CELIX_SUCCESS) {
				properties_pt properties = properties_create();

				unsigned int size = 0;
				char **keys;

				serviceReference_getPropertyKeys(ref, &keys, &size);
				for (int i = 0; i < size; i++) {
					char* key = keys[i];
					const char* value = NULL;
					serviceReference_getProperty(ref, key, &value);
					properties_set(properties, key, value);
				}

				status = driverLoader_findDrivers(loader, manager->locators, properties, &driverIds);
				if (status == CELIX_SUCCESS) {
					hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers);
					while (hashMapIterator_hasNext(iter)) {
						driver_attributes_pt driverAttributes = hashMapIterator_nextValue(iter);
						arrayList_add(included, driverAttributes);

						// Each driver that already is installed can be removed from the list
						char *id = NULL;
						celix_status_t substatus = driverAttributes_getDriverId(driverAttributes, &id);
						if (substatus == CELIX_SUCCESS) {
							// arrayList_removeElement(driverIds, id);
							array_list_iterator_pt idsIter = arrayListIterator_create(driverIds);
							while (arrayListIterator_hasNext(idsIter)) {
								char *value = arrayListIterator_next(idsIter);
								if (strcmp(value, id) == 0) {
									arrayListIterator_remove(idsIter);
								}
							}
							arrayListIterator_destroy(idsIter);
						}
						if(id != NULL){
							free(id);
						}
					}
					hashMapIterator_destroy(iter);

					status = deviceManager_matchAttachDriver(manager, loader, driverIds, included, excluded, service, ref);

				}
				arrayList_destroy(driverIds);
				properties_destroy(properties);
				arrayList_destroy(excluded);
			}
			arrayList_destroy(included);
		}

	}

	driverLoader_destroy(&loader);
	return status;
}
Example #2
0
static celix_status_t deviceManager_attachAlgorithm(device_manager_pt manager, service_reference_pt ref, void *service) {
	celix_status_t status = CELIX_SUCCESS;

	apr_pool_t *attachPool = NULL;
	apr_status_t aprStatus = apr_pool_create(&attachPool, manager->pool);
	if (aprStatus != APR_SUCCESS) {
		status = CELIX_ILLEGAL_STATE;
	} else {
		driver_loader_pt loader = NULL;
		status = driverLoader_create(attachPool, manager->context, &loader);
		if (status == CELIX_SUCCESS) {
			array_list_pt included = NULL;
			array_list_pt excluded = NULL;

			array_list_pt driverIds = NULL;

			hashMap_put(manager->devices, ref, service);

			status = arrayList_create(&included);
			if (status == CELIX_SUCCESS) {
				status = arrayList_create(&excluded);
				if (status == CELIX_SUCCESS) {
					service_registration_pt registration = NULL;
					status = serviceReference_getServiceRegistration(ref, &registration);
					if (status == CELIX_SUCCESS) {
						properties_pt properties = NULL;
						status = serviceRegistration_getProperties(registration, &properties);
						if (status == CELIX_SUCCESS) {
							status = driverLoader_findDrivers(loader, attachPool, manager->locators, properties, &driverIds);
							if (status == CELIX_SUCCESS) {
								hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers);
								while (hashMapIterator_hasNext(iter)) {
									driver_attributes_pt driverAttributes = hashMapIterator_nextValue(iter);
									arrayList_add(included, driverAttributes);

									// Each driver that already is installed can be removed from the list
									char *id = NULL;
									celix_status_t substatus = driverAttributes_getDriverId(driverAttributes, &id);
									if (substatus == CELIX_SUCCESS) {
										// arrayList_removeElement(driverIds, id);
										array_list_iterator_pt idsIter = arrayListIterator_create(driverIds);
										while (arrayListIterator_hasNext(idsIter)) {
											char *value = arrayListIterator_next(idsIter);
											if (strcmp(value, id) == 0) {
												arrayListIterator_remove(idsIter);
											}
										}
										arrayListIterator_destroy(idsIter);
									} else {
										// Ignore
									}
								}
								hashMapIterator_destroy(iter);

								status = deviceManager_matchAttachDriver(manager, attachPool, loader, driverIds, included, excluded, service, ref);
								arrayList_destroy(driverIds);
							}
						}
					}
					arrayList_destroy(excluded);
				}
				arrayList_destroy(included);
			}

		}
		apr_pool_destroy(attachPool);
	}
	return status;
}