Пример #1
0
	static void testProxyRemoval(void) {
		celix_status_t status;
		bundle_pt bundle = NULL;
		array_list_pt bundleNames = NULL;
		array_list_pt proxyBundle = NULL;
		service_reference_pt ref = NULL;

		arrayList_create(&bundleNames);
		arrayList_create(&proxyBundle);

		arrayList_add(bundleNames, (void*) CALCULATOR_PROXY);
		status = getSpecifiedBundles(clientContext, bundleNames, proxyBundle);
		CHECK_EQUAL(CELIX_SUCCESS, status);
		CHECK_EQUAL(arrayList_size(proxyBundle), arrayList_size(bundleNames));

		status = bundleContext_getBundleById(clientContext, (long) arrayList_get(proxyBundle, 0), &bundle);
		CHECK_EQUAL(CELIX_SUCCESS, status);

		status = bundle_stop(bundle);
		CHECK_EQUAL(CELIX_SUCCESS, status);

		status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref);
		CHECK_EQUAL(CELIX_SUCCESS, status);
		CHECK(ref == NULL);

		arrayList_destroy(bundleNames);
		arrayList_destroy(proxyBundle);
	}
Пример #2
0
void test_arrayList_ensureCapacity(void) {
	int i;
	arrayList_create(&list);
	arrayList_clear(list);
	CU_ASSERT_EQUAL(list->capacity, 10);
	CU_ASSERT_EQUAL(list->size, 0);
	for (i = 0; i < 100; i++) {
		arrayList_add(list, "entry");
	}
	CU_ASSERT_EQUAL(list->capacity, 133);
	CU_ASSERT_EQUAL(list->size, 100);
	arrayList_create(&list);
}
celix_status_t dependencyManager_getInfo(dm_dependency_manager_pt manager, dm_dependency_manager_info_pt *out) {
	celix_status_t status = CELIX_SUCCESS;
	int i;
	int size;
	dm_component_info_pt cmpInfo = NULL;
	dm_dependency_manager_info_pt info = calloc(1, sizeof(*info));

	celixThreadMutex_lock(&manager->mutex);

	if (info != NULL) {
		arrayList_create(&info->components);
		size = arrayList_size(manager->components);
		for (i = 0; i < size; i += 1) {
			dm_component_pt cmp = arrayList_get(manager->components, i);
			cmpInfo = NULL;
			component_getComponentInfo(cmp, &cmpInfo);
			arrayList_add(info->components, cmpInfo);
		}
	} else {
		status = CELIX_ENOMEM;
	}

	celixThreadMutex_unlock(&manager->mutex);

	if (status == CELIX_SUCCESS) {
		*out = info;
	}

	return status;
}
Пример #4
0
int main() {
    endpoint_descriptor_writer_pt writer = NULL;
    endpointDescriptorWriter_create(&writer);
    array_list_pt list = NULL;
    arrayList_create(&list);

    properties_pt props = properties_create();
    properties_set(props, "objectClass", "com.acme.Foo");
    properties_set(props, "endpoint.service.id", "3");
    properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz");
    properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96");
    endpoint_description_pt epd = NULL;
    endpointDescription_create(props, &epd);
    arrayList_add(list, epd);

    properties_pt props2 = properties_create();
    properties_set(props2, "objectClass", "com.acme.Bar");
    properties_set(props, "endpoint.service.id", "4");
    properties_set(props, "endpoint.id", "abcdefghijklmnopqrstuvwxyz");
    properties_set(props, "endpoint.framework.uuid", "2983D849-93B1-4C2C-AC6D-5BCDA93ACB96");
    endpoint_description_pt epd2 = NULL;
    endpointDescription_create(props2, &epd2);
    arrayList_add(list, epd2);

    char *buffer = NULL;
    endpointDescriptorWriter_writeDocument(writer, list, &buffer);

    arrayList_destroy(list);
    endpointDescription_destroy(epd);
    endpointDescription_destroy(epd2);
    endpointDescriptorWriter_destroy(writer);

    printf("%s\n", buffer);
}
celix_status_t sampleQueue_create(char *name, sample_queue_type **result) {

	celix_status_t status = CELIX_ENOMEM;
	sample_queue_type *sampleQueue = NULL;

	sampleQueue = calloc(1, sizeof(struct sample_queue));
	if (sampleQueue != NULL) {
		sampleQueue->name = strdup(name);

		/* this needs to be set exaclty to Queue, otherwise the dashboard cannot pick this up */
		sampleQueue->utilizationStatsName = strdup("Queue");

		pthread_mutex_init(&(sampleQueue->lock), NULL);
		pthread_cond_init(&sampleQueue->listEmpty, NULL);

		arrayList_create(&(sampleQueue->queue));

		sampleQueue->putCnt = 0;
		sampleQueue->takeCnt = 0;
		sampleQueue->max_queue_size = MAX_QUEUE_SIZE;
		sampleQueue->currentQueueSize = 0;
		sampleQueue->statisticsRunning = false;

		pthread_create(&sampleQueue->statistics, NULL, printStatistics, sampleQueue);

		(*result) = sampleQueue;
		status = CELIX_SUCCESS;
	}

	return status;
}
Пример #6
0
celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
	celix_status_t status = CELIX_SUCCESS;

	struct publisherActivator * act = malloc(sizeof(*act));

	const char* fwUUID = NULL;

	bundleContext_getProperty(context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
	if(fwUUID == NULL){
		printf("MP_PUBLISHER: Cannot retrieve fwUUID.\n");
		status = CELIX_INVALID_BUNDLE_CONTEXT;
	}

	if (status == CELIX_SUCCESS){
		bundle_pt bundle = NULL;
		long bundleId = 0;
		bundleContext_getBundle(context,&bundle);
		bundle_getBundleId(bundle,&bundleId);

		arrayList_create(&(act->trackerList));
		act->client = publisher_create(act->trackerList,fwUUID,bundleId);
		*userData = act;
	} else {
		free(act);
	}

	return status;
}
Пример #7
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;
}
Пример #8
0
celix_status_t serviceRegistration_createInternal(service_registry_pt registry, bundle_pt bundle, char * serviceName, long serviceId,
        void * serviceObject, properties_pt dictionary, bool isFactory, service_registration_pt *registration) {
    celix_status_t status = CELIX_SUCCESS;

    *registration = malloc(sizeof(**registration));
    if (*registration) {
        (*registration)->services = NULL;
        (*registration)->nrOfServices = 0;
		(*registration)->isServiceFactory = isFactory;
		(*registration)->registry = registry;
		(*registration)->className = strdup(serviceName);
		(*registration)->bundle = bundle;
		(*registration)->references = NULL;
		arrayList_create(&(*registration)->references);

		(*registration)->serviceId = serviceId;
		(*registration)->svcObj = serviceObject;
		if (isFactory) {
			(*registration)->serviceFactory = (service_factory_pt) (*registration)->svcObj;
		} else {
			(*registration)->serviceFactory = NULL;
		}

		//	serviceReference_create(pool, bundle, *registration, &(*registration)->reference);

		(*registration)->isUnregistering = false;
		celixThreadMutex_create(&(*registration)->mutex, NULL);

		serviceRegistration_initializeProperties(*registration, dictionary);
    } else {
    	status = CELIX_ENOMEM;
    }

	return CELIX_SUCCESS;
}
Пример #9
0
celix_status_t deploymentAdmin_readVersions(deployment_admin_pt admin, array_list_pt *versions) {
	celix_status_t status = CELIX_SUCCESS;
	arrayList_create(versions);
	CURL *curl;
	CURLcode res;
	curl = curl_easy_init();
	struct MemoryStruct chunk;
	chunk.memory = calloc(1, sizeof(char));
	chunk.size = 0;
	if (curl) {
		curl_easy_setopt(curl, CURLOPT_URL, admin->pollUrl);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, deploymentAdmin_parseVersions);
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &chunk);
		curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
		res = curl_easy_perform(curl);
		if (res != CURLE_OK) {
			status = CELIX_BUNDLE_EXCEPTION;
		}
		/* always cleanup */
		curl_easy_cleanup(curl);

		char *last;
		char *token = apr_strtok(chunk.memory, "\n", &last);
		while (token != NULL) {
			arrayList_add(*versions, apr_pstrdup(admin->pool, token));
			token = apr_strtok(NULL, "\n", &last);
		}
	}



	return status;
}
celix_status_t dataStore_create(char* name, data_store_type** result){

	celix_status_t status = CELIX_ENOMEM;
	data_store_type* dataStore = calloc(1, sizeof(struct data_store));

	if (dataStore != NULL) {
		dataStore->name = strdup(name);
		dataStore->utilizationStatsName = calloc(1, strlen(name) + strlen(UTILIZATION_NAME_POSTFIX) + 1);
	}

	if (dataStore != NULL && dataStore->name !=NULL && dataStore->utilizationStatsName !=NULL) {

		sprintf(dataStore->utilizationStatsName,"%s%s",dataStore->name,(char*)UTILIZATION_NAME_POSTFIX);

		pthread_mutex_init(&((dataStore)->lock), NULL);
		pthread_cond_init(&(dataStore)->listEmpty, NULL);

		arrayList_create(&((dataStore)->store));

		dataStore->currentStoreSize = 0;
		dataStore->max_store_size = MAX_STORE_SIZE;

		*result=dataStore;

		status = CELIX_SUCCESS;

	}

	return status;

}
Пример #11
0
int setup(void) {
	arrayList_create(&list);
	if (list == NULL) {
		return 1;
	}
	return 0;
}
Пример #12
0
/* Service's functions implementation */
celix_status_t pubsub_discovery_announcePublisher(void *handle, pubsub_endpoint_pt pubEP) {
	celix_status_t status = CELIX_SUCCESS;
	printf("pubsub_discovery_announcePublisher : %s / %s\n", pubEP->topic, pubEP->endpoint);
	pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle;

	celixThreadMutex_lock(&pubsub_discovery->discoveredPubsMutex);

	char *pub_key = createScopeTopicKey(pubEP->scope,pubEP->topic);
	array_list_pt pubEP_list = (array_list_pt)hashMap_get(pubsub_discovery->discoveredPubs,pub_key);

	if(pubEP_list==NULL){
		arrayList_create(&pubEP_list);
		hashMap_put(pubsub_discovery->discoveredPubs,strdup(pub_key),pubEP_list);
	}
	free(pub_key);
	pubsub_endpoint_pt p = NULL;
	pubsubEndpoint_clone(pubEP, &p);

	arrayList_add(pubEP_list,p);

	status = etcdWriter_addPublisherEndpoint(pubsub_discovery->writer,p,true);

	celixThreadMutex_unlock(&pubsub_discovery->discoveredPubsMutex);

	return status;
}
Пример #13
0
celix_status_t serviceRegistry_registerServiceInternal(service_registry_pt registry, bundle_pt bundle, char * serviceName, void * serviceObject, properties_pt dictionary, bool isFactory, service_registration_pt *registration) {
	array_list_pt regs;
	celixThreadMutex_lock(&registry->mutex);

	if (isFactory) {
	    *registration = serviceRegistration_createServiceFactory(registry, bundle, serviceName, ++registry->currentServiceId, serviceObject, dictionary);
	} else {
	    *registration = serviceRegistration_create(registry, bundle, serviceName, ++registry->currentServiceId, serviceObject, dictionary);
	}

	serviceRegistry_addHooks(registry, serviceName, serviceObject, *registration);

	regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
	if (regs == NULL) {
		regs = NULL;
		arrayList_create(&regs);
	}
	arrayList_add(regs, *registration);
	hashMap_put(registry->serviceRegistrations, bundle, regs);

	celixThreadMutex_unlock(&registry->mutex);

	if (registry->serviceChanged != NULL) {
//		service_event_pt event = (service_event_pt) malloc(sizeof(*event));
//		event->type = REGISTERED;
//		event->reference = (*registration)->reference;
		registry->serviceChanged(registry->framework, OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED, *registration, NULL);
//		free(event);
//		event = NULL;
	}

	return CELIX_SUCCESS;
}
Пример #14
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;
}
Пример #15
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;
}
Пример #16
0
celix_status_t serviceRegistry_getRegisteredServices(service_registry_pt registry, bundle_pt bundle, array_list_pt *services) {
	celix_status_t status = CELIX_SUCCESS;

	celixThreadMutex_lock(&registry->mutex);
	array_list_pt regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
	if (regs != NULL) {
		unsigned int i;
		arrayList_create(services);
		
		for (i = 0; i < arrayList_size(regs); i++) {
			service_registration_pt reg = arrayList_get(regs, i);
			if (serviceRegistration_isValid(reg)) {
				service_reference_pt reference = NULL;
				status = serviceRegistry_createServiceReference(registry, bundle, reg, &reference);
				if (status == CELIX_SUCCESS) {
					arrayList_add(*services, reference);
				}
			}
		}
	}
	celixThreadMutex_unlock(&registry->mutex);

	framework_logIfError(logger, status, NULL, "Cannot get registered services");

	return status;
}
Пример #17
0
void test_arrayList_addAll(void) {
    char * entry = "entry";
    char * entry2 = "entry2";
    char * entry3 = "entry3"; 
    char * get;
	array_list_pt toAdd;
	bool changed;
	
	arrayList_clear(list);

	arrayList_create(&toAdd);
    arrayList_add(toAdd, entry);
    arrayList_add(toAdd, entry2);

    arrayList_add(list, entry3);

    get = arrayList_get(list, 0);
    CU_ASSERT_EQUAL(entry3, get);

    changed = arrayList_addAll(list, toAdd);
    CU_ASSERT_TRUE(changed);
    CU_ASSERT_EQUAL(arrayList_size(list), 3);

    get = arrayList_get(list, 1);
    CU_ASSERT_EQUAL(entry, get);

    get = arrayList_get(list, 2);
    CU_ASSERT_EQUAL(entry2, get);
}
Пример #18
0
celix_status_t deviceManager_create(bundle_context_pt context, log_helper_pt logHelper, device_manager_pt *manager) {
	celix_status_t status = CELIX_SUCCESS;

	*manager = calloc(1, sizeof(**manager));
	if (!*manager) {
		status = CELIX_ENOMEM;
	} else {
		(*manager)->context = context;
		(*manager)->devices = NULL;
		(*manager)->drivers = NULL;
		(*manager)->locators = NULL;
		(*manager)->selector = NULL;

		(*manager)->devices = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
		(*manager)->drivers = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);

		(*manager)->loghelper = logHelper;

		status = arrayList_create(&(*manager)->locators);

		logHelper_log((*manager)->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Initialized");
	}


	return status;
}
Пример #19
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;
}
celix_status_t sampleQueue_create(char *name, sample_queue_type **result) {

	celix_status_t status = CELIX_ENOMEM;
	sample_queue_type *sampleQueue = NULL;

	sampleQueue = calloc(1, sizeof(struct sample_queue));
	if (sampleQueue != NULL) {
		sampleQueue->name = strdup(name);
		sampleQueue->utilizationStatsName = calloc(1, strlen(name) + strlen(UTILIZATION_NAME_POSTFIX) + 1);
	}

	if (sampleQueue != NULL && sampleQueue->name != NULL && sampleQueue->utilizationStatsName != NULL) {
		sprintf(sampleQueue->utilizationStatsName, "%s%s", sampleQueue->name, (char*)UTILIZATION_NAME_POSTFIX);

		pthread_mutex_init(&(sampleQueue->lock), NULL);
		pthread_cond_init(&sampleQueue->listEmpty, NULL);

		arrayList_create(&(sampleQueue->queue));

		sampleQueue->putCnt = 0;
		sampleQueue->takeCnt = 0;
		sampleQueue->max_queue_size = MAX_QUEUE_SIZE;
		sampleQueue->currentQueueSize = 0;
		sampleQueue->statisticsRunning = false;

		pthread_create(&sampleQueue->statistics, NULL, printStatistics, sampleQueue);

		(*result) = sampleQueue;
		status = CELIX_SUCCESS;
	}

	return status;
}
Пример #21
0
service_pt serviceComponent_create(bundle_context_pt context, dependency_manager_pt manager) {
    service_pt service;
    apr_pool_t *pool;
	apr_pool_t *mypool;

	bundleContext_getMemoryPool(context, &pool);
	apr_pool_create(&mypool, pool);

	if (mypool) {
        service = (service_pt) apr_pcalloc(mypool, sizeof(*service));
        service->pool = mypool;
        service->impl = NULL;
        service->serviceName = NULL;
        service->serviceRegistration = NULL;
        service->dependencies = NULL;
        arrayList_create(&service->dependencies);

        service->init = service_init;
        service->start= service_start;
        service->stop = service_stop;
        service->destroy = service_destroy;

        service->context = context;
        service->manager = manager;
        service->state = state_create(arrayList_clone(service->dependencies), false);
        service->executor = executor_create(mypool);

		apr_thread_mutex_create(&service->mutex, APR_THREAD_MUTEX_UNNESTED, mypool);
	}

	return service;
}
Пример #22
0
celix_status_t serviceRegistry_create(framework_pt framework, serviceChanged_function_pt serviceChanged, service_registry_pt *registry) {
	celix_status_t status = CELIX_SUCCESS;

	*registry = malloc(sizeof(**registry));
	if (!*registry) {
		status = CELIX_ENOMEM;
	} else {

		(*registry)->serviceChanged = serviceChanged;
		(*registry)->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
		(*registry)->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
		(*registry)->framework = framework;
		(*registry)->currentServiceId = 1l;
		(*registry)->serviceReferences = hashMap_create(NULL, NULL, NULL, NULL);;

		arrayList_create(&(*registry)->listenerHooks);

		status = celixThreadMutexAttr_create(&(*registry)->mutexAttr);
		status = CELIX_DO_IF(status, celixThreadMutexAttr_settype(&(*registry)->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE));
		status = CELIX_DO_IF(status, celixThreadMutex_create(&(*registry)->mutex, &(*registry)->mutexAttr));
		status = CELIX_DO_IF(status, celixThreadMutex_create(&(*registry)->referencesMapMutex, NULL));
	}

	framework_logIfError(logger, status, NULL, "Cannot create service registry");

	return status;
}
Пример #23
0
	static void testExport(void) {
		celix_status_t status;
		array_list_pt bundleNames = NULL;
		array_list_pt bundlePermutations = NULL;
		array_list_pt rsaBundles = NULL;

		unsigned int i, size;

		arrayList_create(&bundleNames);
		arrayList_create(&bundlePermutations);
		arrayList_create(&rsaBundles);

		arrayList_add(bundleNames, (void*) DISCOVERY_CFG_NAME);
		arrayList_add(bundleNames, (void*) RSA_HTTP_NAME);
		arrayList_add(bundleNames, (void*) TOPOLOGY_MANAGER_NAME);

		status = getSpecifiedBundles(serverContext, bundleNames, rsaBundles);
		CHECK_EQUAL(CELIX_SUCCESS, status);
		CHECK_EQUAL(arrayList_size(rsaBundles), arrayList_size(bundleNames));

		status = getPermutations(rsaBundles, 0, arrayList_size(rsaBundles) - 1, bundlePermutations);
		CHECK_EQUAL(CELIX_SUCCESS, status);

		size = arrayList_size(bundlePermutations);

		for (i = 0; i < size; ++i) {
			long* singlePermutation = (long*) arrayList_get(bundlePermutations, i);

			status = stopStartPermutation(serverContext, singlePermutation, arrayList_size(rsaBundles));
			CHECK_EQUAL(CELIX_SUCCESS, status);

			/* we need to sleep here for a bit to ensure
			 * that the client has flushed the old discovery
			 * values
			 */
			sleep(2);

			// check whether calc service is available
			test1();

			free(singlePermutation);
		}

		arrayList_destroy(bundlePermutations);
		arrayList_destroy(bundleNames);
		arrayList_destroy(rsaBundles);
	}
Пример #24
0
phase3_cmp_t *phase3_create() {
	phase3_cmp_t *cmp = calloc(1, sizeof(*cmp));
	if (cmp != NULL) {
		cmp->currentValue = 0.0;
        cmp->running = false;
        arrayList_create(&cmp->phase2Services);
	}
	return cmp;
}
Пример #25
0
int setup(void) {
	apr_initialize();
	apr_pool_create(&memory_pool, NULL);
	arrayList_create(&list);
	if (list == NULL) {
		return 1;
	}
	return 0;
}
Пример #26
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;
}
Пример #27
0
void * dm_create(bundle_context_pt context) {
	struct data * data = malloc(sizeof(*data));
	data->publishers = NULL;
	arrayList_create(&data->publishers);
	data->context = NULL;
	data->running = false;
	data->sender = 0;
	data->service = NULL;
	data->logger = NULL;
	return data;
}
Пример #28
0
etcd_writer_pt etcdWriter_create(pubsub_discovery_pt disc) {
	etcd_writer_pt writer = calloc(1, sizeof(*writer));
	if(writer) {
		celixThreadMutex_create(&writer->localPubsLock, NULL);
		arrayList_create(&writer->localPubs);
		writer->pubsub_discovery = disc;
		writer->running = true;
		celixThread_create(&writer->writerThread, NULL, etcdWriter_run, writer);
	}
	return writer;
}
Пример #29
0
    static void testServices(void) {
        int rc = 0;
        array_list_pt exported = NULL;
        array_list_pt imported = NULL;
        arrayList_create(&exported);
        arrayList_create(&imported);

        rc = rsa->getExportedServices(rsa->admin, &exported);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK_EQUAL(0, arrayList_size(exported));

        rc = rsa->getImportedEndpoints(rsa->admin, &imported);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK_EQUAL(0, arrayList_size(imported));

        double result = 0;
        rc = calc->add(calc->calculator, 2.0, 5.0, &result);
        CHECK_EQUAL(CELIX_SUCCESS, rc);
        CHECK_EQUAL(7.0, result);
    }
Пример #30
0
array_list_pt serviceTracker_getServices(service_tracker_pt tracker) {
	tracked_pt tracked;
	unsigned int i;
	array_list_pt references = NULL;
	arrayList_create(&references);
	
	for (i = 0; i < arrayList_size(tracker->tracked); i++) {
		tracked = (tracked_pt) arrayList_get(tracker->tracked, i);
		arrayList_add(references, tracked->service);
	}
	return references;
}