celix_status_t dataStore_destroy(data_store_type* dataStore){

	celix_status_t status = CELIX_SUCCESS;


	pthread_mutex_lock(&(dataStore->lock));

	/* Empty the queue */
	array_list_iterator_pt iter = arrayListIterator_create(dataStore->store);

	while (arrayListIterator_hasNext(iter)) {
		free(arrayListIterator_next(iter));
	}

	arrayListIterator_destroy(iter);

	/* Destroy the queue */

	arrayList_destroy(dataStore->store);
	dataStore->store = NULL;

	pthread_mutex_unlock(&(dataStore->lock));
	pthread_mutex_destroy(&(dataStore->lock));

	free(dataStore->utilizationStatsName);
	free(dataStore->name);
	free(dataStore);

	return status;

}
Esempio n. 2
0
	static celix_status_t getSpecifiedBundles(bundle_context_pt context, array_list_pt bundleNames, array_list_pt retrievedBundles) {
		celix_status_t status;
		array_list_pt bundles = NULL;

		status = bundleContext_getBundles(context, &bundles);

		if (status == CELIX_SUCCESS) {
			unsigned int size = arrayList_size(bundles);
			unsigned int i;

			for (i = 0; i < size; i++) {
				module_pt module = NULL;
				const char *name = NULL;

				bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i);

				status = bundle_getCurrentModule(bundle, &module);

				if (status == CELIX_SUCCESS) {
					status = module_getSymbolicName(module, &name);
				}

				if (status == CELIX_SUCCESS) {

					printf("FOUND %s\n", name);

					array_list_iterator_pt iter = arrayListIterator_create(bundleNames);

					while(arrayListIterator_hasNext(iter)) {
						char* bundleName = (char*) arrayListIterator_next(iter);

						if ((strcmp(name, bundleName) == 0)) {

							bundle_archive_pt bundleArchive = NULL;
							long bundleId = -1;

							status = bundle_getArchive(bundle, &bundleArchive);

							if (status == CELIX_SUCCESS) {
								status = bundleArchive_getId(bundleArchive, &bundleId);
							}

							if (status == CELIX_SUCCESS) {
								arrayList_add(retrievedBundles, (void*) bundleId);
								break;
							}
						}
					}

					arrayListIterator_destroy(iter);

				}
			}

			arrayList_destroy(bundles);
		}

		return status;
	}
Esempio n. 3
0
File: bundle.c Progetto: jawi/celix
celix_status_t bundle_isUsed(bundle_pt bundle, bool *used) {
	bool unresolved = true;
	array_list_iterator_pt iter = arrayListIterator_create(bundle->modules);
	while (arrayListIterator_hasNext(iter)) {
		module_pt module = arrayListIterator_next(iter);
		if (module_isResolved(module)) {
			unresolved = false;
		}
	}
	arrayListIterator_destroy(iter);
	*used = false;
	iter = arrayListIterator_create(bundle->modules);
	while (arrayListIterator_hasNext(iter) && !unresolved && !*used) {
		module_pt module = arrayListIterator_next(iter);
		module_getDependents(module);
	}
	arrayListIterator_destroy(iter);
	return CELIX_SUCCESS;
}
Esempio n. 4
0
celix_status_t etcdWatcher_addOwnNode(etcd_watcher_pt watcher) {
    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
    char localNodePath[MAX_LOCALNODE_LENGTH];
    char* ttlStr = NULL;
    int ttl;

    node_discovery_pt node_discovery = watcher->node_discovery;
    bundle_context_pt context = node_discovery->context;
    node_description_pt ownNodeDescription = node_discovery->ownNode;

    // register own framework
    status = etcdWatcher_getLocalNodePath(context, ownNodeDescription, &localNodePath[0]);

    // determine ttl
    if ((bundleContext_getProperty(context, CFG_ETCD_TTL, &ttlStr) != CELIX_SUCCESS) || !ttlStr) {
        ttl = DEFAULT_ETCD_TTL;
    } else {
        char* endptr = ttlStr;
        errno = 0;
        ttl = strtol(ttlStr, &endptr, 10);
        if (*endptr || errno != 0) {
            ttl = DEFAULT_ETCD_TTL;
        }
    }

    // register every wiring endpoint
    array_list_iterator_pt endpointIter = arrayListIterator_create(ownNodeDescription->wiring_ep_descriptions_list);

    while (status == CELIX_SUCCESS && arrayListIterator_hasNext(endpointIter)) {
        wiring_endpoint_description_pt wiringEndpointDesc = arrayListIterator_next(endpointIter);

        if (wiringEndpointDesc == NULL) {
            status = CELIX_ILLEGAL_ARGUMENT;
        } else {
            char etcdKey[MAX_LOCALNODE_LENGTH];
            char etcdValue[MAX_LOCALNODE_LENGTH];
            char* wireId = properties_get(wiringEndpointDesc->properties, WIRING_ENDPOINT_DESCRIPTION_WIRE_ID_KEY);

            wiringEndpoint_properties_store(wiringEndpointDesc->properties, &etcdValue[0]);

            snprintf(etcdKey, MAX_LOCALNODE_LENGTH, "%s/%s", localNodePath, wireId);

            // TODO : implement update
            etcd_set(etcdKey, etcdValue, ttl, false);
        }
    }

    arrayListIterator_destroy(endpointIter);

    return status;
}
Esempio n. 5
0
File: bundle.c Progetto: jawi/celix
celix_status_t bundle_destroy(bundle_pt bundle) {
	array_list_iterator_pt iter = arrayListIterator_create(bundle->modules);
	while (arrayListIterator_hasNext(iter)) {
		module_pt module = arrayListIterator_next(iter);
		module_destroy(module);
	}
	arrayListIterator_destroy(iter);
	arrayList_destroy(bundle->modules);
	celixThreadMutex_destroy(&bundle->lock);

	free(bundle);

	return CELIX_SUCCESS;
}
Esempio n. 6
0
static apr_status_t consumingDriver_cleanup(void *handler) {
	printf("CONSUMING_DRIVER: cleanup\n");
	consuming_driver_pt driver = handler;

	if (driver->references != NULL) {
		array_list_iterator_pt iterator = arrayListIterator_create(driver->references);
		while (arrayListIterator_hasNext(iterator)) {
			service_reference_pt reference = arrayListIterator_next(iterator);
			bool result;
			bundleContext_ungetService(driver->context, reference, &result);
		}
		arrayListIterator_destroy(iterator);

		arrayList_destroy(driver->references);
		driver->references=NULL;
	}


	return APR_SUCCESS;
}
Esempio n. 7
0
static filter_pt filter_parseOr(char * filterString, int * pos) {

	array_list_pt operands = NULL;

	filter_skipWhiteSpace(filterString, pos);
	bool failure = false;

	if (filterString[*pos] != '(') {
		fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error: Missing '('.");
		return NULL;
	}

	arrayList_create(&operands);
	while(filterString[*pos] == '(') {
		filter_pt child = filter_parseFilter(filterString, pos);
		if(child == NULL){
			failure = true;
			break;
		}
		arrayList_add(operands, child);
	}

	if(failure == true){
		array_list_iterator_pt listIt = arrayListIterator_create(operands);
		while(arrayListIterator_hasNext(listIt)){
			filter_pt f = arrayListIterator_next(listIt);
			filter_destroy(f);
		}
		arrayListIterator_destroy(listIt);
		arrayList_destroy(operands);
		operands = NULL;
	}

	filter_pt filter = (filter_pt) malloc(sizeof(*filter));
	filter->operand = OR;
	filter->attribute = NULL;
	filter->value = operands;

	return filter;
}
Esempio n. 8
0
static celix_status_t serviceRegistry_flushUsageCount(service_registry_pt registry, bundle_pt bundle, service_reference_pt reference) {
	array_list_pt usages = hashMap_get(registry->inUseMap, bundle);
	if (usages != NULL) {
		array_list_iterator_pt iter = arrayListIterator_create(usages);
		while (arrayListIterator_hasNext(iter)) {
			usage_count_pt usage = arrayListIterator_next(iter);
			bool equals = false;
			serviceReference_equals(usage->reference, reference, &equals);
			if (equals) {
				arrayListIterator_remove(iter);
				free(usage);
			}
		}
		arrayListIterator_destroy(iter);
		if (arrayList_size(usages) > 0) {
			hashMap_put(registry->inUseMap, bundle, usages);
		} else {
			array_list_pt removed = hashMap_remove(registry->inUseMap, bundle);
			arrayList_destroy(removed);
		}
	}
	return CELIX_SUCCESS;
}
Esempio n. 9
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;
}
Esempio n. 10
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;
}
Esempio n. 11
0
celix_status_t wiringTopologyManager_waAdded(void * handle, service_reference_pt reference, void * service) {
    celix_status_t status = CELIX_SUCCESS;
    wiring_topology_manager_pt manager = handle;
    wiring_admin_service_pt wiringAdminService = (wiring_admin_service_pt) service;

    celixThreadMutex_lock(&manager->waListLock);
    arrayList_add(manager->waList, wiringAdminService);
    celixThreadMutex_unlock(&manager->waListLock);

    /* check whether one of the exported Wires can be exported via the newly available wiringAdmin */
    celixThreadMutex_lock(&manager->exportedWiringEndpointsLock);
    hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedWiringEndpoints);

    // is the properties_match missing here>
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        properties_pt exportedWireProperties = hashMapEntry_getKey(entry);
        hash_map_pt wiringAdminList = hashMapEntry_getValue(entry);
        wiring_endpoint_description_pt wEndpoint = NULL;

        char* serviceId = properties_get(exportedWireProperties, "service.id");

        printf("WTM: wiringTopologyManager_waAdded export Wire for %s \n", serviceId);

        status = wiringTopologyManager_WiringAdminServiceExportWiringEndpoint(manager, wiringAdminService, exportedWireProperties, &wEndpoint);

        if (status == CELIX_SUCCESS) {
            hashMap_put(wiringAdminList, wiringAdminService, wEndpoint);
        } else {
            printf("WTM: Could not export wire with new WA\n");
        }
    }
    hashMapIterator_destroy(iter);

    /* check whether the waiting exports can be exported */

    array_list_iterator_pt waitList = arrayListIterator_create(manager->waitingForExport);

    while (arrayListIterator_hasNext(waitList)) {
        properties_pt srvcProperties = arrayListIterator_next(waitList);
        char* serviceId = properties_get(srvcProperties, "service.id");

        printf("WTM: wiringTopologyManager_waAdded export Wire for %s \n", serviceId);
        wiring_endpoint_description_pt wEndpoint = NULL;

        status = wiringTopologyManager_WiringAdminServiceExportWiringEndpoint(manager, wiringAdminService, srvcProperties, &wEndpoint);

        if (status == CELIX_SUCCESS) {
            arrayListIterator_remove(waitList);

            arrayListIterator_destroy(waitList);
            waitList = arrayListIterator_create(manager->waitingForExport);

            hash_map_pt wiringAdminList = hashMap_create(NULL, NULL, NULL, NULL);
            hashMap_put(wiringAdminList, wiringAdminService, wEndpoint);
            hashMap_put(manager->exportedWiringEndpoints, srvcProperties, wiringAdminList);
        } else {
            printf("WTM: Could not export wire with new WA\n");
        }
    }

    arrayListIterator_destroy(waitList);

    celixThreadMutex_unlock(&manager->exportedWiringEndpointsLock);

    /* Check if the added WA can match one of the imported WiringEndpoints */
    celixThreadMutex_lock(&manager->importedWiringEndpointsLock);
    iter = hashMapIterator_create(manager->importedWiringEndpoints);
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        wiring_endpoint_description_pt wEndpoint = hashMapEntry_getKey(entry);
        array_list_pt wiringAdminList = hashMapEntry_getValue(entry);

        status = wiringTopologyManager_checkWiringAdminForImportWiringEndpoint(manager, wiringAdminService, wEndpoint);

        if (status == CELIX_SUCCESS) {
            arrayList_add(wiringAdminList, wiringAdminService);
        }

    }
    hashMapIterator_destroy(iter);


    /* check wether waiting service can be exported */
    wiringTopologyManager_checkWaitingForImportServices(manager);

    celixThreadMutex_unlock(&manager->importedWiringEndpointsLock);

    printf("WTM: Added WA\n");

    return status;
}