Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;

}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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);

}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
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);
}
Ejemplo n.º 17
0
celix_status_t pubsub_discovery_destroy(pubsub_discovery_pt ps_discovery) {
	celix_status_t status = CELIX_SUCCESS;

	celixThreadMutex_lock(&ps_discovery->discoveredPubsMutex);

	hash_map_iterator_pt iter = hashMapIterator_create(ps_discovery->discoveredPubs);

	while (hashMapIterator_hasNext(iter)) {
		array_list_pt pubEP_list = (array_list_pt) hashMapIterator_nextValue(iter);

		for(int i=0; i < arrayList_size(pubEP_list); i++) {
			pubsubEndpoint_destroy(((pubsub_endpoint_pt)arrayList_get(pubEP_list,i)));
		}
		arrayList_destroy(pubEP_list);
	}

	hashMapIterator_destroy(iter);

	hashMap_destroy(ps_discovery->discoveredPubs, true, false);
	ps_discovery->discoveredPubs = NULL;

	celixThreadMutex_unlock(&ps_discovery->discoveredPubsMutex);

	celixThreadMutex_destroy(&ps_discovery->discoveredPubsMutex);


	celixThreadMutex_lock(&ps_discovery->listenerReferencesMutex);

	hashMap_destroy(ps_discovery->listenerReferences, false, false);
	ps_discovery->listenerReferences = NULL;

	celixThreadMutex_unlock(&ps_discovery->listenerReferencesMutex);

	celixThreadMutex_destroy(&ps_discovery->listenerReferencesMutex);

	free(ps_discovery);

	return status;
}
Ejemplo n.º 18
0
static int wiringAdmin_callback(struct mg_connection *conn) {
    int result = 0; // zero means: let civetweb handle it further, any non-zero value means it is handled by us...

    const struct mg_request_info *request_info = mg_get_request_info(conn);

    if (request_info->uri != NULL) {
        wiring_admin_pt admin = request_info->user_data;

        if (hashMap_size(admin->wiringReceiveServices) == 0) {
            printf("%s: No wiringReceiveServices available\n", TAG);
        }

        if (strcmp("POST", request_info->request_method) == 0) {

            celixThreadMutex_lock(&admin->exportedWiringEndpointLock);

            uint64_t datalength = request_info->content_length;
            char* data = malloc(datalength + 1);
            mg_read(conn, data, datalength);
            data[datalength] = '\0';

            char *response = NULL;

            hash_map_iterator_pt iter = hashMapIterator_create(admin->wiringReceiveServices);
            while (hashMapIterator_hasNext(iter)) {
                array_list_pt wiringReceiveServiceList = hashMapIterator_nextValue(iter);

                if (arrayList_size(wiringReceiveServiceList) > 0) {
                    //		printf("WIRING_ADMIN: size of wiringReceiveServiceList is %d\n", arrayList_size(wiringReceiveServiceList));
                    // TODO: we do not support mulitple wiringReceivers?
                    wiring_receive_service_pt wiringReceiveService = (wiring_receive_service_pt) arrayList_get(wiringReceiveServiceList, 0);
                    if (wiringReceiveService->receive(wiringReceiveService->handle, data, &response) != CELIX_SUCCESS) {
                        response = NULL;
                    }

                    break;
                } else {
                    printf("%s: wiringReceiveServiceList is empty\n", TAG);
                }
            }
            hashMapIterator_destroy(iter);

            if (response != NULL) {
                mg_write(conn, data_response_headers, strlen(data_response_headers));
                mg_write(conn, response, strlen(response));

                free(response);
            } else {
                mg_write(conn, no_content_response_headers, strlen(no_content_response_headers));
            }
            result = 1;

            free(data);
        } else {
            printf("%s: Received HTTP Request, but no RSA_Inaetics callback is installed. Discarding request.\n", TAG);
        }

        celixThreadMutex_unlock(&admin->exportedWiringEndpointLock);
    } else {
        printf("%s: Received URI is NULL\n", TAG);
    }

    return result;
}
Ejemplo n.º 19
0
celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin)
{
	celix_status_t status = CELIX_SUCCESS;

	free(admin->ipAddress);

	celixThreadMutex_lock(&admin->pendingSubscriptionsLock);
	hash_map_iterator_pt iter = hashMapIterator_create(admin->pendingSubscriptions);
	while(hashMapIterator_hasNext(iter)){
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
		free((char*)hashMapEntry_getKey(entry));
		arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
	}
	hashMapIterator_destroy(iter);
	hashMap_destroy(admin->pendingSubscriptions,false,false);
	celixThreadMutex_unlock(&admin->pendingSubscriptionsLock);

	celixThreadMutex_lock(&admin->subscriptionsLock);
	hashMap_destroy(admin->subscriptions,false,false);
	celixThreadMutex_unlock(&admin->subscriptionsLock);

	celixThreadMutex_lock(&admin->localPublicationsLock);
	hashMap_destroy(admin->localPublications,true,false);
	celixThreadMutex_unlock(&admin->localPublicationsLock);

	celixThreadMutex_lock(&admin->externalPublicationsLock);
	iter = hashMapIterator_create(admin->externalPublications);
	while(hashMapIterator_hasNext(iter)){
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
		free((char*)hashMapEntry_getKey(entry));
		arrayList_destroy((array_list_pt)hashMapEntry_getValue(entry));
	}
	hashMapIterator_destroy(iter);
	hashMap_destroy(admin->externalPublications,false,false);
	celixThreadMutex_unlock(&admin->externalPublicationsLock);

	celixThreadMutex_lock(&admin->serializerListLock);
	arrayList_destroy(admin->serializerList);
	celixThreadMutex_unlock(&admin->serializerListLock);

	celixThreadMutex_lock(&admin->noSerializerPendingsLock);
	arrayList_destroy(admin->noSerializerSubscriptions);
	arrayList_destroy(admin->noSerializerPublications);
	celixThreadMutex_unlock(&admin->noSerializerPendingsLock);


	celixThreadMutex_lock(&admin->usedSerializersLock);

	iter = hashMapIterator_create(admin->topicSubscriptionsPerSerializer);
	while(hashMapIterator_hasNext(iter)){
		arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
	}
	hashMapIterator_destroy(iter);
	hashMap_destroy(admin->topicSubscriptionsPerSerializer,false,false);

	iter = hashMapIterator_create(admin->topicPublicationsPerSerializer);
	while(hashMapIterator_hasNext(iter)){
		arrayList_destroy((array_list_pt)hashMapIterator_nextValue(iter));
	}
	hashMapIterator_destroy(iter);
	hashMap_destroy(admin->topicPublicationsPerSerializer,false,false);

	celixThreadMutex_unlock(&admin->usedSerializersLock);

	celixThreadMutex_destroy(&admin->usedSerializersLock);
	celixThreadMutex_destroy(&admin->serializerListLock);
	celixThreadMutex_destroy(&admin->pendingSubscriptionsLock);

	celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr);
	celixThreadMutex_destroy(&admin->noSerializerPendingsLock);

	celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr);
	celixThreadMutex_destroy(&admin->subscriptionsLock);

	celixThreadMutex_destroy(&admin->localPublicationsLock);
	celixThreadMutex_destroy(&admin->externalPublicationsLock);

	logHelper_stop(admin->loghelper);

	logHelper_destroy(&admin->loghelper);

#ifdef BUILD_WITH_ZMQ_SECURITY
	if (admin->zmq_auth != NULL){
		zactor_destroy(&(admin->zmq_auth));
	}
#endif

	free(admin);

	return status;
}
Ejemplo n.º 20
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;
}
Ejemplo n.º 21
0
static celix_status_t pubsubAdmin_addAnySubscription(pubsub_admin_pt admin,pubsub_endpoint_pt subEP){
	celix_status_t status = CELIX_SUCCESS;

	celixThreadMutex_lock(&admin->subscriptionsLock);

	topic_subscription_pt any_sub = hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);

	if(any_sub==NULL){

		int i;
		pubsub_serializer_service_t *best_serializer = NULL;
		if( (status=pubsubAdmin_getBestSerializer(admin, subEP, &best_serializer)) == CELIX_SUCCESS){
			status = pubsub_topicSubscriptionCreate(admin->bundle_context, PUBSUB_SUBSCRIBER_SCOPE_DEFAULT, PUBSUB_ANY_SUB_TOPIC, best_serializer, &any_sub);
		}
		else{
			printf("PSA_ZMQ: Cannot find a serializer for subscribing topic %s. Adding it to pending list.\n",subEP->topic);
			celixThreadMutex_lock(&admin->noSerializerPendingsLock);
			arrayList_add(admin->noSerializerSubscriptions,subEP);
			celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
		}

		if (status == CELIX_SUCCESS){

			/* Connect all internal publishers */
			celixThreadMutex_lock(&admin->localPublicationsLock);
			hash_map_iterator_pt lp_iter =hashMapIterator_create(admin->localPublications);
			while(hashMapIterator_hasNext(lp_iter)){
				service_factory_pt factory = (service_factory_pt)hashMapIterator_nextValue(lp_iter);
				topic_publication_pt topic_pubs = (topic_publication_pt)factory->handle;
				array_list_pt topic_publishers = pubsub_topicPublicationGetPublisherList(topic_pubs);

				if(topic_publishers!=NULL){
					for(i=0;i<arrayList_size(topic_publishers);i++){
						pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(topic_publishers,i);
						if(pubEP->endpoint !=NULL){
							status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
						}
					}
					arrayList_destroy(topic_publishers);
				}
			}
			hashMapIterator_destroy(lp_iter);
			celixThreadMutex_unlock(&admin->localPublicationsLock);

			/* Connect also all external publishers */
			celixThreadMutex_lock(&admin->externalPublicationsLock);
			hash_map_iterator_pt extp_iter =hashMapIterator_create(admin->externalPublications);
			while(hashMapIterator_hasNext(extp_iter)){
				array_list_pt ext_pub_list = (array_list_pt)hashMapIterator_nextValue(extp_iter);
				if(ext_pub_list!=NULL){
					for(i=0;i<arrayList_size(ext_pub_list);i++){
						pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(ext_pub_list,i);
						if(pubEP->endpoint !=NULL){
							status += pubsub_topicSubscriptionConnectPublisher(any_sub,pubEP->endpoint);
						}
					}
				}
			}
			hashMapIterator_destroy(extp_iter);
			celixThreadMutex_unlock(&admin->externalPublicationsLock);


			pubsub_topicSubscriptionAddSubscriber(any_sub,subEP);

			status += pubsub_topicSubscriptionStart(any_sub);

		}

		if (status == CELIX_SUCCESS){
			hashMap_put(admin->subscriptions,strdup(PUBSUB_ANY_SUB_TOPIC),any_sub);
			connectTopicPubSubToSerializer(admin, best_serializer, any_sub, false);
		}

	}

	celixThreadMutex_unlock(&admin->subscriptionsLock);

	return status;
}
Ejemplo n.º 22
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;
}