/**
 * Destroys and frees up memory for a given endpoint_discovery_poller struct.
 */
celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poller) {
    celix_status_t status;

    poller->running = false;

    celixThread_join(poller->pollerThread, NULL);

    hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
	while (hashMapIterator_hasNext(iterator)) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);

		if ( endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, (char*) hashMapEntry_getKey(entry)) == CELIX_SUCCESS) {
			hashMapIterator_destroy(iterator);
			iterator = hashMapIterator_create(poller->entries);
		}
	}
	hashMapIterator_destroy(iterator);

	status = celixThreadMutex_lock(&poller->pollerLock);

	if (status != CELIX_SUCCESS) {
		return CELIX_BUNDLE_EXCEPTION;
	}

	hashMap_destroy(poller->entries, true, false);

    status = celixThreadMutex_unlock(&poller->pollerLock);

    poller->loghelper = NULL;

    free(poller);

	return status;
}
Esempio n. 2
0
celix_status_t wiringAdmin_stop(wiring_admin_pt admin) {
    celix_status_t status = CELIX_SUCCESS;

    celixThreadMutex_lock(&admin->exportedWiringEndpointLock);

    // stop tracker
    hash_map_iterator_pt iter = hashMapIterator_create(admin->wiringReceiveTracker);

    while (hashMapIterator_hasNext(iter)) {
        service_tracker_pt wiringReceiveTracker = (service_tracker_pt) hashMapIterator_nextValue(iter);

        if (serviceTracker_close(wiringReceiveTracker) == CELIX_SUCCESS) {
            serviceTracker_destroy(wiringReceiveTracker);
        }
    }
    hashMapIterator_destroy(iter);

    hashMap_clear(admin->wiringReceiveTracker, false, false);

    wiringAdmin_stopWebserver(admin);

    iter = hashMapIterator_create(admin->wiringReceiveServices);

    while (hashMapIterator_hasNext(iter)) {
        array_list_pt wiringReceiveServiceList = hashMapIterator_nextValue(iter);
        arrayList_destroy(wiringReceiveServiceList);
    }

    hashMapIterator_destroy(iter);
    hashMap_clear(admin->wiringReceiveServices, false, false);

    celixThreadMutex_unlock(&admin->exportedWiringEndpointLock);

    return status;
}
celix_status_t wiringTopologyManager_waRemoved(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;

    /* check whether one of the exported Wires can be exported here via the newly available wiringAdmin*/
    celixThreadMutex_lock(&manager->exportedWiringEndpointsLock);
    hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedWiringEndpoints);
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        hash_map_pt wiringAdminMap = hashMapEntry_getValue(entry);

        if (hashMap_containsKey(wiringAdminMap, wiringAdminService)) {
            wiring_endpoint_description_pt wEndpoint = (wiring_endpoint_description_pt) hashMap_remove(wiringAdminMap, wiringAdminService);

            status = wiringTopologyManager_notifyListenersWiringEndpointRemoved(manager, wEndpoint);

            if (status == CELIX_SUCCESS) {
                status = wiringAdminService->removeExportedWiringEndpoint(wiringAdminService->admin, wEndpoint);
            } else {
                printf("WTM: failed while removing WiringAdmin.\n");
            }
        }
    }

    hashMapIterator_destroy(iter);

    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 importedWiringEndpointDesc = hashMapEntry_getKey(entry);
        array_list_pt wiringAdminList = hashMapEntry_getValue(entry);

        if (arrayList_contains(wiringAdminList, wiringAdminService)) {
            status = wiringAdminService->removeImportedWiringEndpoint(wiringAdminService->admin, importedWiringEndpointDesc);
            arrayList_removeElement(wiringAdminList, wiringAdminService);
        }

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

    }
    hashMapIterator_destroy(iter);
    celixThreadMutex_unlock(&manager->importedWiringEndpointsLock);

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

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

    return status;
}
Esempio n. 4
0
celix_status_t pubsub_discovery_stop(pubsub_discovery_pt ps_discovery) {
    celix_status_t status = CELIX_SUCCESS;

    const char* fwUUID = NULL;

    bundleContext_getProperty(ps_discovery->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID);
    if (fwUUID == NULL) {
        printf("PSD: Cannot retrieve fwUUID.\n");
        return CELIX_INVALID_BUNDLE_CONTEXT;
    }

    celixThreadMutex_lock(&ps_discovery->watchersMutex);

    hash_map_iterator_pt iter = hashMapIterator_create(ps_discovery->watchers);
    while (hashMapIterator_hasNext(iter)) {
        struct watcher_info * wi = hashMapIterator_nextValue(iter);
        etcdWatcher_stop(wi->watcher);
    }
    hashMapIterator_destroy(iter);

    celixThreadMutex_lock(&ps_discovery->discoveredPubsMutex);

    /* Unexport all publishers for the local framework, and also delete from ETCD publisher belonging to the local framework */

    iter = hashMapIterator_create(ps_discovery->discoveredPubs);
    while (hashMapIterator_hasNext(iter)) {
        array_list_pt pubEP_list = (array_list_pt) hashMapIterator_nextValue(iter);

        int i;
        for (i = 0; i < arrayList_size(pubEP_list); i++) {
            pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt) arrayList_get(pubEP_list, i);
            if (strcmp(pubEP->frameworkUUID, fwUUID) == 0) {
                etcdWriter_deletePublisherEndpoint(ps_discovery->writer, pubEP);
            } else {
                pubsub_discovery_informPublishersListeners(ps_discovery, pubEP, false);
                arrayList_remove(pubEP_list, i);
                pubsubEndpoint_destroy(pubEP);
                i--;
            }
        }
    }

    hashMapIterator_destroy(iter);

    celixThreadMutex_unlock(&ps_discovery->discoveredPubsMutex);
    etcdWriter_destroy(ps_discovery->writer);

    iter = hashMapIterator_create(ps_discovery->watchers);
    while (hashMapIterator_hasNext(iter)) {
        struct watcher_info * wi = hashMapIterator_nextValue(iter);
        etcdWatcher_destroy(wi->watcher);
    }
    hashMapIterator_destroy(iter);
    hashMap_destroy(ps_discovery->watchers, true, true);
    celixThreadMutex_unlock(&ps_discovery->watchersMutex);
    return status;
}
celix_status_t wiringTopologyManager_wiringEndpointListenerAdded(void* handle, service_reference_pt reference, void* service) {
    celix_status_t status = CELIX_SUCCESS;
    wiring_topology_manager_pt manager = handle;
    char *scope = NULL;
    char* wtm = NULL;

    serviceReference_getProperty(reference, (char *) INAETICS_WIRING_ENDPOINT_LISTENER_SCOPE, &scope);
    serviceReference_getProperty(reference, "WTM", &wtm);

    if (wtm != NULL && strcmp(wtm, "true") == 0) {
        printf("WTM: Ignoring own ENDPOINT_LISTENER\n");
    }
    else {
        status = celixThreadMutex_lock(&manager->listenerListLock);

        if (status == CELIX_SUCCESS) {
            hashMap_put(manager->listenerList, reference, NULL);
            celixThreadMutex_unlock(&manager->listenerListLock);
        }

        filter_pt filter = filter_create(scope);
        status = celixThreadMutex_lock(&manager->exportedWiringEndpointsLock);

        if (status == CELIX_SUCCESS) {
            hash_map_iterator_pt propIter = hashMapIterator_create(manager->exportedWiringEndpoints);

            while (hashMapIterator_hasNext(propIter)) {
                hash_map_pt wiringAdminList = hashMapIterator_nextValue(propIter);
                hash_map_iterator_pt waIter = hashMapIterator_create(wiringAdminList);

                while (hashMapIterator_hasNext(waIter)) {
                    wiring_endpoint_description_pt wEndpoint = hashMapIterator_nextValue(waIter);

                    bool matchResult = false;
                    filter_match(filter, wEndpoint->properties, &matchResult);

                    if (matchResult) {
                        wiring_endpoint_listener_pt listener = (wiring_endpoint_listener_pt) service;
                        status = listener->wiringEndpointAdded(listener->handle, wEndpoint, scope);
                    }
                }
                hashMapIterator_destroy(waIter);
            }
            hashMapIterator_destroy(propIter);

            celixThreadMutex_unlock(&manager->exportedWiringEndpointsLock);
        }
        filter_destroy(filter);

    }


    return status;
}
Esempio n. 6
0
int producer_getSampleRate(void* handle) {
    producer_pt producer = (producer_pt) handle;
    int sampleRate = 0;

    pthread_rwlock_rdlock(&producer->queueLock);

    hash_map_iterator_pt iter = hashMapIterator_create(producer->queueServices);

    while (hashMapIterator_hasNext(iter)) {
        producer_thread_data_pt th_data = (producer_thread_data_pt) hashMapIterator_nextValue(iter);

        pthread_rwlock_rdlock(&th_data->sampleRateLock);
        sampleRate += th_data->single_throughput; // + value->burst_throughput
        pthread_rwlock_unlock(&th_data->sampleRateLock);
    }

    hashMapIterator_destroy(iter);

    if (hashMap_size(producer->queueServices) > 0) {
        sampleRate /= hashMap_size(producer->queueServices);
    }

    pthread_rwlock_unlock(&producer->queueLock);

    return sampleRate;
}
Esempio n. 7
0
int producer_getUtilizationStatsValue(producer_pt producer, double* statVal) {

    double total_average = 0;

    pthread_rwlock_rdlock(&producer->queueLock);

    hash_map_iterator_pt iter = hashMapIterator_create(producer->queueServices);

    while (hashMapIterator_hasNext(iter)) {

        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);

        if (entry != NULL) {
            producer_thread_data_pt value = (producer_thread_data_pt) hashMapEntry_getValue(entry);
            if (value != NULL) {
                total_average += (double) (((double) (value->single_throughput + value->burst_throughput)) / ((double) 2.0f));
            }
        }
    }

    hashMapIterator_destroy(iter);

    if (hashMap_size(producer->queueServices) > 0) {
        total_average /= hashMap_size(producer->queueServices);
    }

    pthread_rwlock_unlock(&producer->queueLock);

    (*statVal) = total_average;
    return (int) CELIX_SUCCESS;
}
Esempio n. 8
0
static celix_status_t etcdWatcher_removeEntry(etcd_watcher_pt watcher, char* key, char* value) {
    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
    endpoint_discovery_poller_pt poller = watcher->discovery->poller;

    hash_map_entry_pt entry = hashMap_getEntry(watcher->entries, key);

    if (entry != NULL) {
        void* origKey = hashMapEntry_getKey(entry);
        void* value = hashMap_remove(watcher->entries, key);

        free(origKey);

        // check if there is another entry with the same value
        hash_map_iterator_pt iter = hashMapIterator_create(watcher->entries);
        unsigned int valueFound = 0;

        while (hashMapIterator_hasNext(iter) && valueFound <= 1) {
            if (strcmp(value, hashMapIterator_nextValue(iter)) == 0)
                valueFound++;
        }

        hashMapIterator_destroy(iter);

        if (valueFound == 0)
            status = endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, value);

        free(value);

    }

    return status;

}
Esempio n. 9
0
celix_status_t pubsub_discovery_tmPublisherAnnounceAdded(void * handle, service_reference_pt reference, void * service) {
	celix_status_t status = CELIX_SUCCESS;

	pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt)handle;
	publisher_endpoint_announce_pt listener = (publisher_endpoint_announce_pt)service;

	celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);
	celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);

	/* Notify the PSTM about discovered publisher endpoints */
	hash_map_iterator_pt iter = hashMapIterator_create(pubsub_discovery->discoveredPubs);
	while(hashMapIterator_hasNext(iter)){
		array_list_pt pubEP_list = (array_list_pt)hashMapIterator_nextValue(iter);
		int i;
		for(i=0;i<arrayList_size(pubEP_list);i++){
			pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(pubEP_list,i);
			status += listener->announcePublisher(listener->handle, pubEP);
		}
	}

	hashMapIterator_destroy(iter);

	hashMap_put(pubsub_discovery->listenerReferences, reference, NULL);

	celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);
	celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);

	printf("PSD: pubsub_tm_announce_publisher added.\n");

	return status;
}
Esempio n. 10
0
array_list_pt serviceRegistry_getUsingBundles(service_registry_pt registry, service_reference_pt reference) {
	array_list_pt bundles = NULL;
	hash_map_iterator_pt iter;
	arrayList_create(&bundles);

	celixThreadMutex_lock(&registry->mutex);
	iter = hashMapIterator_create(registry->inUseMap);
	while (hashMapIterator_hasNext(iter)) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
		bundle_pt bundle = hashMapEntry_getKey(entry);
		array_list_pt usages = hashMapEntry_getValue(entry);
		unsigned int i;
		for (i = 0; i < arrayList_size(usages); i++) {
			usage_count_pt usage = arrayList_get(usages, i);
			bool equals = false;
			serviceReference_equals(usage->reference, reference, &equals);
			if (equals) {
				arrayList_add(bundles, bundle);
			}
		}
	}
	hashMapIterator_destroy(iter);
	celixThreadMutex_unlock(&registry->mutex);
	return bundles;
}
Esempio n. 11
0
celix_status_t shell_getCommandReference(shell_pt shell_ptr, char *command_name_str, service_reference_pt *command_reference_ptr) {
	celix_status_t status = CELIX_SUCCESS;

	if (!shell_ptr || !command_name_str || !command_reference_ptr) {
		status = CELIX_ILLEGAL_ARGUMENT;
	}

	if (status == CELIX_SUCCESS) {
		*command_reference_ptr = NULL;
		hash_map_iterator_pt iter = hashMapIterator_create(shell_ptr->command_reference_map_ptr);
		while (hashMapIterator_hasNext(iter)) {
			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
			service_reference_pt reference = hashMapEntry_getKey(entry);
			char *name_str = NULL;
			serviceReference_getProperty(reference, "command.name", &name_str);
			if (strcmp(name_str, command_name_str) == 0) {
				*command_reference_ptr = (service_reference_pt) hashMapEntry_getKey(entry);
				break;
			}
		}
		hashMapIterator_destroy(iter);
	}

	return status;
}
Esempio n. 12
0
celix_status_t deviceManager_getIdleDevices(device_manager_pt manager, array_list_pt *idleDevices) {
	celix_status_t status = CELIX_SUCCESS;

	status = arrayList_create(idleDevices);
	if (status == CELIX_SUCCESS) {
		hash_map_iterator_pt iter = hashMapIterator_create(manager->devices);
		while (hashMapIterator_hasNext(iter)) {
			celix_status_t substatus = CELIX_SUCCESS;
			service_reference_pt ref = hashMapIterator_nextKey(iter);
			const char *bsn = NULL;
			module_pt module = NULL;
			bundle_pt bundle = NULL;
			substatus = serviceReference_getBundle(ref, &bundle);
			if (substatus == CELIX_SUCCESS) {
				substatus = bundle_getCurrentModule(bundle, &module);
				if (substatus == CELIX_SUCCESS) {
					substatus = module_getSymbolicName(module, &bsn);
					if (substatus == CELIX_SUCCESS) {
						logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Check idle device: %s", bsn);
						array_list_pt bundles = NULL;
						substatus = serviceReference_getUsingBundles(ref, &bundles);
						if (substatus == CELIX_SUCCESS) {
							bool inUse = false;
							int i;
							for (i = 0; i < arrayList_size(bundles); i++) {
								bundle_pt bundle = arrayList_get(bundles, i);
								bool isDriver;
								celix_status_t sstatus = deviceManager_isDriverBundle(manager, bundle, &isDriver);
								if (sstatus == CELIX_SUCCESS) {
									if (isDriver) {
										const char *bsn = NULL;
										module_pt module = NULL;
										bundle_getCurrentModule(bundle, &module);
										module_getSymbolicName(module, &bsn);

										logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Not idle, used by driver: %s", bsn);

										inUse = true;
										break;
									}
								}
							}

							if (!inUse) {
								arrayList_add(*idleDevices, ref);
							}
						}

						if(bundles!=NULL){
							arrayList_destroy(bundles);
						}
					}
				}
			}
		}
		hashMapIterator_destroy(iter);
	}

	return status;
}
Esempio n. 13
0
/* Callback to the pubsub_topology_manager */
celix_status_t pubsub_discovery_informPublishersListeners(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP, bool epAdded) {
	celix_status_t status = CELIX_SUCCESS;

	// Inform listeners of new publisher endpoint
	celixThreadMutex_lock(&pubsub_discovery->listenerReferencesMutex);

	if (pubsub_discovery->listenerReferences != NULL) {
		hash_map_iterator_pt iter = hashMapIterator_create(pubsub_discovery->listenerReferences);
		while (hashMapIterator_hasNext(iter)) {
			service_reference_pt reference = hashMapIterator_nextKey(iter);

			publisher_endpoint_announce_pt listener = NULL;

			bundleContext_getService(pubsub_discovery->context, reference, (void**) &listener);
            if (epAdded) {
                listener->announcePublisher(listener->handle, pubEP);
            } else {
                listener->removePublisher(listener->handle, pubEP);
            }
            bundleContext_ungetService(pubsub_discovery->context, reference, NULL);
		}
		hashMapIterator_destroy(iter);
	}

	celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);

	return status;
}
Esempio n. 14
0
celix_status_t shell_getCommands(shell_pt shell_ptr, array_list_pt *commands_ptr) {
	celix_status_t status = CELIX_SUCCESS;

	hash_map_iterator_pt iter = NULL;

	if (!shell_ptr || !commands_ptr) {
		status = CELIX_ILLEGAL_ARGUMENT;
	}

	if (status == CELIX_SUCCESS) {
		iter = hashMapIterator_create(shell_ptr->command_name_map_ptr);
		if (!iter) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
	}

	if (status == CELIX_SUCCESS) {
		arrayList_create(commands_ptr);
		while (hashMapIterator_hasNext(iter)) {
			char *name_str = hashMapIterator_nextKey(iter);
			arrayList_add(*commands_ptr, name_str);
		}
		hashMapIterator_destroy(iter);
	}

	return status;
}
Esempio n. 15
0
celix_status_t serviceRegistry_getServiceReferencesForRegistration(service_registry_pt registry, service_registration_pt registration, array_list_pt *references) {
    celix_status_t status = CELIX_SUCCESS;

    hash_map_values_pt referenceValues = NULL;
    hash_map_iterator_pt iterator = NULL;

    arrayList_create(references);

    celixThreadMutex_lock(&registry->referencesMapMutex);
    referenceValues = hashMapValues_create(registry->serviceReferences);
    iterator = hashMapValues_iterator(referenceValues);
    while (hashMapIterator_hasNext(iterator)) {
        array_list_pt refs = (array_list_pt) hashMapIterator_nextValue(iterator);
        unsigned int refIdx;
        for (refIdx = 0; (refs != NULL) && refIdx < arrayList_size(refs); refIdx++) {
            service_registration_pt reg = NULL;
            service_reference_pt reference = (service_reference_pt) arrayList_get(refs, refIdx);
            bool valid = false;
            serviceRefernce_isValid(reference, &valid);
            if (valid) {
                serviceReference_getServiceRegistration(reference, &reg);
                if (reg == registration) {
                    arrayList_add(*references, reference);
                }
            }
        }
    }
    hashMapIterator_destroy(iterator);
    hashMapValues_destroy(referenceValues);

    celixThreadMutex_unlock(&registry->referencesMapMutex);

    return status;
}
static void *endpointDiscoveryPoller_performPeriodicPoll(void *data) {
	endpoint_discovery_poller_pt poller = (endpoint_discovery_poller_pt) data;

	useconds_t interval = (useconds_t) (poller->poll_interval * 1000000L);

	while (poller->running) {
		usleep(interval);
		celix_status_t status = celixThreadMutex_lock(&poller->pollerLock);

		if (status != CELIX_SUCCESS) {
			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to obtain lock; retrying...");
		} else {
			hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);

			while (hashMapIterator_hasNext(iterator)) {
				hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);

				char *url = hashMapEntry_getKey(entry);
				array_list_pt currentEndpoints = hashMapEntry_getValue(entry);

				endpointDiscoveryPoller_poll(poller, url, currentEndpoints);
			}

			hashMapIterator_destroy(iterator);
		}

		status = celixThreadMutex_unlock(&poller->pollerLock);
		if (status != CELIX_SUCCESS) {
			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to release lock; retrying...");
		}
	}

	return NULL;
}
Esempio n. 17
0
celix_status_t deviceManager_driverRemoved(void * handle, service_reference_pt ref, void * service) {
	celix_status_t status = CELIX_SUCCESS;

	device_manager_pt manager = handle;
	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove driver");

	hashMap_remove(manager->drivers, ref);

	array_list_pt idleDevices = NULL;
	status = deviceManager_getIdleDevices(manager, &idleDevices);
	if (status == CELIX_SUCCESS) {
		int i;
		for (i = 0; i < arrayList_size(idleDevices); i++) {
			celix_status_t forStatus = CELIX_SUCCESS;
			service_reference_pt ref = arrayList_get(idleDevices, i);
			const char *bsn = NULL;
			bundle_pt bundle = NULL;
			forStatus = serviceReference_getBundle(ref, &bundle);
			if (forStatus == CELIX_SUCCESS) {
				module_pt module = NULL;
				forStatus = bundle_getCurrentModule(bundle, &module);
				if (forStatus == CELIX_SUCCESS) {
					forStatus = module_getSymbolicName(module, &bsn);
					if (forStatus == CELIX_SUCCESS) {
						logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: IDLE: %s", bsn);
						// #TODO attachDriver (idle device)
						// #TODO this can result in a loop?
						//		Locate and install a driver
						//		Let the match fail, the device is idle
						//		The driver is removed, idle check is performed
						//		Attach is tried again
						//		.. loop ..
						void *device = hashMap_get(manager->devices, ref);
						forStatus = deviceManager_attachAlgorithm(manager, ref, device);
					}
				}
			}

			if (forStatus != CELIX_SUCCESS) {
				break; //Got error, stop loop and return status
			}
		}


		hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers);
		while (hashMapIterator_hasNext(iter)) {
			hashMapIterator_nextValue(iter);
//			driver_attributes_pt da = hashMapIterator_nextValue(iter);
//			driverAttributes_tryUninstall(da);
		}
		hashMapIterator_destroy(iter);
	}

	if (idleDevices != NULL) {
		arrayList_destroy(idleDevices);
	}

	return status;
}
Esempio n. 18
0
void properties_destroy(properties_pt properties) {
	hash_map_iterator_pt iter = hashMapIterator_create(properties);
	while (hashMapIterator_hasNext(iter)) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
		free(hashMapEntry_getKey(entry));
		free(hashMapEntry_getValue(entry));
	}
	hashMapIterator_destroy(iter);
	hashMap_destroy(properties, false, false);
}
Esempio n. 19
0
celix_status_t serviceRegistry_getServiceReferences(service_registry_pt registry, bundle_pt owner, const char *serviceName, filter_pt filter, array_list_pt *references) {
	celix_status_t status = CELIX_SUCCESS;
	hash_map_values_pt registrations;
	hash_map_iterator_pt iterator;
	arrayList_create(references);

	celixThreadMutex_lock(&registry->mutex);
	registrations = hashMapValues_create(registry->serviceRegistrations);
	iterator = hashMapValues_iterator(registrations);
	while (hashMapIterator_hasNext(iterator)) {
		array_list_pt regs = (array_list_pt) hashMapIterator_nextValue(iterator);
		unsigned int regIdx;
		for (regIdx = 0; (regs != NULL) && regIdx < arrayList_size(regs); regIdx++) {
			service_registration_pt registration = (service_registration_pt) arrayList_get(regs, regIdx);
			properties_pt props = NULL;

			status = serviceRegistration_getProperties(registration, &props);
			if (status == CELIX_SUCCESS) {
				bool matched = false;
				bool matchResult = false;
				if (filter != NULL) {
					filter_match(filter, props, &matchResult);
				}
				if ((serviceName == NULL) && ((filter == NULL) || matchResult)) {
					matched = true;
				} else if (serviceName != NULL) {
					char *className = NULL;
					bool matchResult = false;
					serviceRegistration_getServiceName(registration, &className);
					if (filter != NULL) {
						filter_match(filter, props, &matchResult);
					}
					if ((strcmp(className, serviceName) == 0) && ((filter == NULL) || matchResult)) {
						matched = true;
					}
				}
				if (matched) {
					if (serviceRegistration_isValid(registration)) {
						service_reference_pt reference = NULL;
						serviceRegistry_createServiceReference(registry, owner, registration, &reference);
						arrayList_add(*references, reference);
					}
				}
			}
		}
	}
	hashMapIterator_destroy(iterator);
	hashMapValues_destroy(registrations);
	celixThreadMutex_unlock(&registry->mutex);

	framework_logIfError(logger, status, NULL, "Cannot get service references");

	return status;
}
Esempio n. 20
0
static void process_msg(topic_subscription_pt sub,pubsub_udp_msg_t *msg){

	celixThreadMutex_lock(&sub->ts_lock);
	hash_map_iterator_pt iter = hashMapIterator_create(sub->servicesMap);
	while (hashMapIterator_hasNext(iter)) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
		pubsub_subscriber_pt subsvc = hashMapEntry_getKey(entry);
		hash_map_pt msgTypes = hashMapEntry_getValue(entry);

		pubsub_msg_serializer_t *msgSer = hashMap_get(msgTypes,(void*)(uintptr_t )msg->header.type);
		if (msgSer == NULL) {
			printf("PSA_UDP_MC_TS: Serializer not available for message %d.\n",msg->header.type);
		}
		else{
			void *msgInst = NULL;
			bool validVersion = checkVersion(msgSer->msgVersion,&msg->header);

			if(validVersion){

				celix_status_t status = msgSer->deserialize(msgSer, (const void *) msg->payload, 0, &msgInst);

				if (status == CELIX_SUCCESS) {
					bool release = true;
					pubsub_multipart_callbacks_t mp_callbacks;
					mp_callbacks.handle = sub;
					mp_callbacks.localMsgTypeIdForMsgType = pubsub_localMsgTypeIdForMsgType;
					mp_callbacks.getMultipart = NULL;

					subsvc->receive(subsvc->handle, msgSer->msgName, msg->header.type, msgInst, &mp_callbacks, &release);

					if(release){
						msgSer->freeMsg(msgSer,msgInst);
					}
				}
				else{
					printf("PSA_UDP_MC_TS: Cannot deserialize msgType %s.\n",msgSer->msgName);
				}

			}
			else{
				int major=0,minor=0;
				version_getMajor(msgSer->msgVersion,&major);
				version_getMinor(msgSer->msgVersion,&minor);
				printf("PSA_UDP_MC_TS: Version mismatch for primary message '%s' (have %d.%d, received %u.%u). NOT sending any part of the whole message.\n",
						msgSer->msgName,major,minor,msg->header.major,msg->header.minor);
			}

		}
	}
	hashMapIterator_destroy(iter);
	celixThreadMutex_unlock(&sub->ts_lock);
}
Esempio n. 21
0
apr_status_t driverMatcher_destroy(void *matcherP) {
	driver_matcher_pt matcher = matcherP;
	arrayList_destroy(matcher->matches);
	hash_map_iterator_pt iter = hashMapIterator_create(matcher->attributes);
	while (hashMapIterator_hasNext(iter)) {
		array_list_pt list = hashMapIterator_nextValue(iter);
		if (list != NULL) {
			arrayList_destroy(list);
		}
	}
	hashMapIterator_destroy(iter);
	hashMap_destroy(matcher->attributes, false, false);
	return APR_SUCCESS;
}
Esempio n. 22
0
celix_status_t deviceManager_getIdleDevices_exmaple(device_manager_pt manager, apr_pool_t *pool, array_list_pt *idleDevices) {
	celix_status_t status = CELIX_SUCCESS;

	status = arrayList_create(idleDevices);
	if (status == CELIX_SUCCESS) {
		hash_map_iterator_pt iter = hashMapIterator_create(manager->devices);
		while (hashMapIterator_hasNext(iter)) {
			celix_status_t substatus = CELIX_SUCCESS;
			service_reference_pt ref = hashMapIterator_nextKey(iter);
			char *bsn = NULL;
			module_pt module = NULL;
			bundle_pt bundle = NULL;
			array_list_pt bundles = NULL;
			substatus = serviceReference_getBundle(ref, &bundle);
			substatus = DO_IF_SUCCESS(substatus, bundle_getCurrentModule(bundle, &module));
			substatus = DO_IF_SUCCESS(substatus, module_getSymbolicName(module, &bsn));
			substatus = DO_IF_SUCCESS(substatus, serviceReference_getUsingBundles(ref, &bundles));

			if (substatus == CELIX_SUCCESS) {
				printf("DEVICE_MANAGER: Check idle device: %s\n", bsn);
				bool inUse = false;
				int i;
				for (i = 0; i < arrayList_size(bundles); i++) {
					bundle_pt bundle = arrayList_get(bundles, i);
					bool isDriver;
					celix_status_t sstatus = deviceManager_isDriverBundle(manager, bundle, &isDriver);
					if (sstatus == CELIX_SUCCESS) {
						if (isDriver) {
							char *bsn = NULL;
							module_pt module = NULL;
							bundle_getCurrentModule(bundle, &module);
							module_getSymbolicName(module, &bsn);

							printf("DEVICE_MANAGER: Not idle, used by driver: %s\n", bsn);

							inUse = true;
							break;
						}
					}
				}

				if (!inUse) {
					arrayList_add(*idleDevices, ref);
				}
			}
		}
		hashMapIterator_destroy(iter);
	}
	return status;
}
Esempio n. 23
0
static void importRegistration_clearProxies(import_registration_pt import) {
    if (import != NULL) {
        pthread_mutex_lock(&import->proxiesMutex);
        if (import->proxies != NULL) {
            hash_map_iterator_pt iter = hashMapIterator_create(import->proxies);
            while (hashMapIterator_hasNext(iter)) {
                hash_map_entry_pt  entry = hashMapIterator_nextEntry(iter);
                struct service_proxy *proxy = hashMapEntry_getValue(entry);
                importRegistration_destroyProxy(proxy);
            }
            hashMapIterator_destroy(iter);
        }
        pthread_mutex_unlock(&import->proxiesMutex);
    }
}
Esempio n. 24
0
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);
	}
	hashMapIterator_destroy(attrIter);
	hashMap_destroy(requirement->attributes, false, false);
	hashMap_destroy(requirement->directives, false, false);

	requirement->attributes = NULL;
	requirement->directives = NULL;
	requirement->versionRange = NULL;

	return CELIX_SUCCESS;
}
Esempio n. 25
0
celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) {
    celix_status_t status = CELIX_SUCCESS;

    celixThreadMutex_lock(&admin->exportedServicesLock);

    hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
    while (hashMapIterator_hasNext(iter)) {
        array_list_pt exports = hashMapIterator_nextValue(iter);
        int i;
        for (i = 0; i < arrayList_size(exports); i++) {
            export_registration_pt export = arrayList_get(exports, i);
            if (export != NULL) {
                exportRegistration_stop(export);
                exportRegistration_destroy(export);
            }
        }
        arrayList_destroy(exports);
    }
    hashMapIterator_destroy(iter);
    celixThreadMutex_unlock(&admin->exportedServicesLock);

    celixThreadMutex_lock(&admin->importedServicesLock);
    int i;
    int size = arrayList_size(admin->importedServices);
    for (i = 0; i < size ; i += 1) {
        import_registration_pt import = arrayList_get(admin->importedServices, i);
        if (import != NULL) {
            importRegistration_stop(import);
            importRegistration_destroy(import);
        }
    }
    celixThreadMutex_unlock(&admin->importedServicesLock);

    if (admin->ctx != NULL) {
        logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
        mg_stop(admin->ctx);
        admin->ctx = NULL;
    }

    hashMap_destroy(admin->exportedServices, false, false);
    arrayList_destroy(admin->importedServices);

    logHelper_stop(admin->loghelper);
    logHelper_destroy(&admin->loghelper);

    return status;
}
Esempio n. 26
0
static void disconnectTopicPubSubFromSerializer(pubsub_admin_pt admin,void *topicPubSub,bool isPublication){

	celixThreadMutex_lock(&admin->usedSerializersLock);

	hash_map_pt map = isPublication?admin->topicPublicationsPerSerializer:admin->topicSubscriptionsPerSerializer;
	hash_map_iterator_pt iter = hashMapIterator_create(map);
	while(hashMapIterator_hasNext(iter)){
		array_list_pt list = (array_list_pt)hashMapIterator_nextValue(iter);
		if(arrayList_removeElement(list, topicPubSub)){ //Found it!
			break;
		}
	}
	hashMapIterator_destroy(iter);

	celixThreadMutex_unlock(&admin->usedSerializersLock);

}
celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls) {
    celixThreadMutex_lock(&(poller)->pollerLock);

    hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);

    while(hashMapIterator_hasNext(iterator))  {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
        char* toAdd = strdup((char*) hashMapEntry_getKey(entry));
        arrayList_add(urls, toAdd);
    }

    hashMapIterator_destroy(iterator);

    celixThreadMutex_unlock(&(poller)->pollerLock);

    return CELIX_SUCCESS;
}
Esempio n. 28
0
celix_status_t producer_stop(producer_pt producer)
{
    celix_status_t status = CELIX_SUCCESS;

    printf("PRODUCER: Stopping Producer.\n");

    pthread_rwlock_rdlock(&producer->queueLock);
    hash_map_iterator_pt iter = hashMapIterator_create(producer->queueServices);

    while (hashMapIterator_hasNext(iter)) {
        producer_thread_data_pt th_data = hashMapIterator_nextValue(iter);
        th_data->running = false;
    }

    hashMapIterator_destroy(iter);
    pthread_rwlock_unlock(&producer->queueLock);

    return status;
}
Esempio n. 29
0
celix_status_t driverMatcher_destroy(driver_matcher_pt *matcher) {
    arrayList_destroy((*matcher)->matches);
    hash_map_iterator_pt iter = hashMapIterator_create((*matcher)->attributes);
    while (hashMapIterator_hasNext(iter)) {
        array_list_pt list = hashMapIterator_nextValue(iter);
        if (list != NULL) {
            arrayList_destroy(list);
        }
    }
    hashMapIterator_destroy(iter);
    hashMap_destroy((*matcher)->attributes, false, false);

    logHelper_stop((*matcher)->loghelper);
    logHelper_destroy(&(*matcher)->loghelper);

    free(*matcher);

    return CELIX_SUCCESS;
}
Esempio n. 30
0
void producer_setSampleRate(void* handle, int rate) {
    producer_pt producer = (producer_pt) handle;

    pthread_rwlock_rdlock(&producer->queueLock);

    hash_map_iterator_pt iter = hashMapIterator_create(producer->queueServices);

    while (hashMapIterator_hasNext(iter)) {

        producer_thread_data_pt th_data = (producer_thread_data_pt) hashMapIterator_nextValue(iter);

        pthread_rwlock_wrlock(&th_data->sampleRateLock);
        th_data->sampleRate = rate;
        pthread_rwlock_unlock(&th_data->sampleRateLock);
        msg(0, "PRODUCER: SampleRate set to %d", rate);
    }

    hashMapIterator_destroy(iter);

    pthread_rwlock_unlock(&producer->queueLock);
}