Example #1
0
void filter_destroy(filter_pt filter) {
	if (filter != NULL) {
		if(filter->value!=NULL){
			if (filter->operand == SUBSTRING) {
				int size = arrayList_size(filter->value);
				for (; size > 0; --size) {
					char* operand = (char*) arrayList_remove(filter->value, 0);
					free(operand);
				}
				arrayList_destroy(filter->value);
				filter->value = NULL;
			} else if ( (filter->operand == OR) || (filter->operand == AND) ) {
				int size = arrayList_size(filter->value);
				unsigned int i = 0;
				for (i = 0; i < size; i++) {
					filter_pt f = arrayList_get(filter->value, i);
					filter_destroy(f);
				}
				arrayList_destroy(filter->value);
				filter->value = NULL;
			} else  if (filter->operand == NOT) {
				filter_destroy(filter->value);
				filter->value = NULL;
			} else {
				free(filter->value);
				filter->value = NULL;
			}
		}
		free(filter->attribute);
		filter->attribute = NULL;
		free(filter);
		filter = NULL;
	}
}
int sampleQueue_take(sample_queue_type *sampleQueue, struct sample **out) {
	celix_status_t status = CELIX_ILLEGAL_STATE;
	struct timespec ts;
	int rc = 0;

	clock_gettime(CLOCK_REALTIME, &ts);
	ts.tv_sec += WAIT_TIME_SECONDS;

	pthread_mutex_lock(&sampleQueue->lock);

	while (sampleQueue->queue!=NULL && arrayList_size(sampleQueue->queue) == 0 && rc != ETIMEDOUT) {
		rc = pthread_cond_timedwait(&sampleQueue->listEmpty, &sampleQueue->lock, &ts);
	}

	if (rc == 0 && sampleQueue->queue!=NULL && arrayList_size(sampleQueue->queue)>0)
	{
		struct sample *sample = arrayList_remove(sampleQueue->queue, 0);
		sampleQueue->takeCnt++;
		sampleQueue->currentQueueSize -= 1;
		*out = sample;
		status = CELIX_SUCCESS;
	} else if (arrayList_size(sampleQueue->queue) == 0) {
		*out = NULL;
		status = CELIX_SUCCESS;
	}

	pthread_mutex_unlock(&sampleQueue->lock);


	return (int) status;
}
Example #3
0
celix_status_t driverAttributes_isInUse(driver_attributes_pt driverAttributes, bool *inUse) {
	celix_status_t status = CELIX_SUCCESS;

	array_list_pt references = NULL;
	status = bundle_getServicesInUse(driverAttributes->bundle, &references);
	if (status == CELIX_SUCCESS) {
		if (references == NULL || arrayList_size(references) == 0) {
			*inUse = false;
		} else {
			int i;
			for (i = 0; i < arrayList_size(references); i++) {
				service_reference_pt ref = arrayList_get(references, i);
				char *object = NULL;
				status = serviceReference_getProperty(ref, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &object);

				if (status == CELIX_SUCCESS) {
					char *category = NULL;
					status = serviceReference_getProperty(ref, "DEVICE_CATEGORY", &category);

					if (status == CELIX_SUCCESS) {
						if ((object != NULL && strcmp(object, OSGI_DEVICEACCESS_DEVICE_SERVICE_NAME) == 0) || (category != NULL)) {
							*inUse = true;
						}
					}
				}
			}
		}
	}

	return status;
}
Example #4
0
    /// \TEST_CASE_ID{2}
    /// \TEST_CASE_TITLE{Test scope initialisation}
    /// \TEST_CASE_REQ{REQ-2}
    /// \TEST_CASE_DESC Checks if scopes can be added, but not twice
    static void testScope(void) {
    	int nr_exported;
    	int nr_imported;
    	array_list_pt epList;

    	printf("\nBegin: %s\n", __func__);
        scopeInit("scope.json", &nr_exported, &nr_imported);
        CHECK_EQUAL(1, nr_exported);
        CHECK_EQUAL(0, nr_imported);

        discMock->getEPDescriptors(discMock->handle, &epList);
        // We export two services: Calculator and Calculator2, but only 1 has DFI bundle info
        CHECK_EQUAL(1, arrayList_size(epList));
        for (unsigned int i = 0; i < arrayList_size(epList); i++) {
        	endpoint_description_pt ep = (endpoint_description_pt) arrayList_get(epList, i);
        	properties_pt props = ep->properties;
        	hash_map_entry_pt entry = hashMap_getEntry(props, (void*)"key2");
        	char* value = (char*) hashMapEntry_getValue(entry);
        	STRCMP_EQUAL("inaetics", value);
        	/*
        	printf("Service: %s ", ep->service);
        	hash_map_iterator_pt iter = hashMapIterator_create(props);
        	while (hashMapIterator_hasNext(iter)) {
        		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        		printf("%s - %s\n", (char*)hashMapEntry_getKey(entry),
        						   (char*)hashMapEntry_getValue(entry));
        	}
        	printf("\n");
        	hashMapIterator_destroy(iter);
        	*/
        }
        printf("End: %s\n", __func__);
    }
Example #5
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);
	}
int sampleQueue_takeAll(sample_queue_type *sampleQueue, uint32_t min, uint32_t max, struct sample_sequence samples) {
	celix_status_t status = CELIX_ILLEGAL_STATE;
	struct timespec ts;
	unsigned int i = 0;
	int rc = 0;

	clock_gettime(CLOCK_REALTIME, &ts);
	ts.tv_sec += WAIT_TIME_SECONDS;

	pthread_mutex_lock(&sampleQueue->lock);

	/* block, till sufficient elements available */
	while (sampleQueue->queue!=NULL && arrayList_size(sampleQueue->queue) < min && rc != ETIMEDOUT) {
		rc = pthread_cond_timedwait(&sampleQueue->listEmpty, &sampleQueue->lock, &ts);
	}

	if (rc == 0 && sampleQueue->queue!=NULL) {
		status = CELIX_SUCCESS;
		for (i = 0; i < max && arrayList_size(sampleQueue->queue) > 0; i++) {
			struct sample *tmpSample = arrayList_remove(sampleQueue->queue, 0);
			memcpy(&samples.buf[i], tmpSample, sizeof(struct sample));
			free(tmpSample);
		}
	}

	//*samplesSize = i;
	sampleQueue->takeCnt += i;
	sampleQueue->currentQueueSize -= i;


	pthread_mutex_unlock(&sampleQueue->lock);

	return (int) status;
}
Example #7
0
celix_status_t filter_match(filter_pt filter, properties_pt properties, bool *result) {
	switch (filter->operand) {
		case AND: {
			array_list_pt filters = (array_list_pt) filter->value;
			unsigned int i;
			for (i = 0; i < arrayList_size(filters); i++) {
				filter_pt sfilter = (filter_pt) arrayList_get(filters, i);
				bool mresult;
				filter_match(sfilter, properties, &mresult);
				if (!mresult) {
					*result = 0;
					return CELIX_SUCCESS;
				}
			}
			*result = 1;
			return CELIX_SUCCESS;
		}
		case OR: {
			array_list_pt filters = (array_list_pt) filter->value;
			unsigned int i;
			for (i = 0; i < arrayList_size(filters); i++) {
				filter_pt sfilter = (filter_pt) arrayList_get(filters, i);
				bool mresult;
				filter_match(sfilter, properties, &mresult);
				if (mresult) {
					*result = 1;
					return CELIX_SUCCESS;
				}
			}
			*result = 0;
			return CELIX_SUCCESS;
		}
		case NOT: {
			filter_pt sfilter = (filter_pt) filter->value;
			bool mresult;
			filter_match(sfilter, properties, &mresult);
			*result = !mresult;
			return CELIX_SUCCESS;
		}
		case SUBSTRING :
		case EQUAL :
		case GREATER :
        case GREATEREQUAL :
		case LESS :
        case LESSEQUAL :
		case APPROX : {
			char * value = (properties == NULL) ? NULL: (char*)properties_get(properties, filter->attribute);

			return filter_compare(filter->operand, value, filter->value, result);
		}
		case PRESENT: {
			char * value = (properties == NULL) ? NULL: (char*)properties_get(properties, filter->attribute);
			*result = value != NULL;
			return CELIX_SUCCESS;
		}
	}
	*result = 0;
	return CELIX_SUCCESS;
}
Example #8
0
celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, bundle_pt bundle, service_registration_pt registration) {
	// array_list_t clients;
	unsigned int i;
	array_list_pt regs;
	array_list_pt references = NULL;

	celixThreadMutex_lock(&registry->mutex);

	serviceRegistry_removeHook(registry, registration);

	regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
	if (regs != NULL) {
		arrayList_removeElement(regs, registration);
		hashMap_put(registry->serviceRegistrations, bundle, regs);
	}

	celixThreadMutex_unlock(&registry->mutex);

	if (registry->serviceChanged != NULL) {
		registry->serviceChanged(registry->framework, OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING, registration, NULL);
	}

	celixThreadMutex_lock(&registry->mutex);
	// unget service

	serviceRegistration_getServiceReferences(registration, &references);
	for (i = 0; i < arrayList_size(references); i++) {
		service_reference_pt reference = (service_reference_pt) arrayList_get(references, i);
		array_list_pt clients = NULL;
		unsigned int j;

		clients = serviceRegistry_getUsingBundles(registry, reference);
		for (j = 0; (clients != NULL) && (j < arrayList_size(clients)); j++) {
			bundle_pt client = (bundle_pt) arrayList_get(clients, j);
			bool ungetResult = true;
			while (ungetResult) {
				serviceRegistry_ungetService(registry, client, reference, &ungetResult);
			}
		}
		arrayList_destroy(clients);

		serviceReference_invalidate(reference);
	}
	arrayList_destroy(references);

	//TODO not needed, the registration is destroyed, any reference to the registration is invalid and will result in a segfault
	serviceRegistration_invalidate(registration);

	// serviceRegistration_destroy(registration);

	celixThreadMutex_unlock(&registry->mutex);

	return CELIX_SUCCESS;
}
Example #9
0
File: bundle.c Project: jawi/celix
celix_status_t bundle_getCurrentModule(bundle_pt bundle, module_pt *module) {
	celix_status_t status = CELIX_SUCCESS;

	if (bundle == NULL || *module != NULL || arrayList_size(bundle->modules)==0 ) {
		status = CELIX_ILLEGAL_ARGUMENT;
	} else {
		*module = arrayList_get(bundle->modules, arrayList_size(bundle->modules) - 1);
	}


	return status;
}
Example #10
0
celix_status_t deploymentAdmin_processDeploymentPackageResources(deployment_admin_pt admin, deployment_package_pt source) {
	celix_status_t status = CELIX_SUCCESS;

	array_list_pt infos = NULL;
	deploymentPackage_getResourceInfos(source, &infos);
	int i;
	for (i = 0; i < arrayList_size(infos); i++) {
		resource_info_pt info = arrayList_get(infos, i);
		apr_pool_t *tmpPool = NULL;
		array_list_pt services = NULL;
		char *filter = NULL;

		apr_pool_create(&tmpPool, admin->pool);
		filter = apr_pstrcat(tmpPool, "(", OSGI_FRAMEWORK_SERVICE_PID, "=", info->resourceProcessor, ")", NULL);

		status = bundleContext_getServiceReferences(admin->context, DEPLOYMENTADMIN_RESOURCE_PROCESSOR_SERVICE, filter, &services);
		if (status == CELIX_SUCCESS) {
			if (services != NULL && arrayList_size(services) > 0) {
				service_reference_pt ref = arrayList_get(services, 0);
				// In Felix a check is done to assure the processor belongs to the deployment package
				// Is this according to spec?
				void *processorP = NULL;
				status = bundleContext_getService(admin->context, ref, &processorP);
				if (status == CELIX_SUCCESS) {
					bundle_pt bundle = NULL;
					char *entry = NULL;
					char *name = NULL;
					char *packageName = NULL;
					resource_processor_service_pt processor = processorP;

					bundleContext_getBundle(admin->context, &bundle);
					bundle_getEntry(bundle, "/", &entry);
					deploymentPackage_getName(source, &name);

					char *resourcePath = apr_pstrcat(admin->pool, entry, "repo/", name, "/", info->path, NULL);
					deploymentPackage_getName(source, &packageName);

					processor->begin(processor->processor, packageName);
					processor->process(processor->processor, info->path, resourcePath);
				}
			}
		}

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


	}

	return status;
}
Example #11
0
void test_arrayList_clear(void) {
	char * entry = "entry";
	char * entry2 = "entry2";

	arrayList_clear(list);

	arrayList_add(list, entry);
	arrayList_add(list, entry2);

	CU_ASSERT_EQUAL(arrayList_size(list), 2);
	arrayList_clear(list);
	CU_ASSERT_EQUAL(arrayList_size(list), 0);
}
Example #12
0
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {

	struct publisherActivator * act = (struct publisherActivator *) userData;

	int i;

	array_list_pt topic_list = pubsub_getTopicsFromString(PUB_TOPIC);

	if(topic_list !=NULL){

		char filter[128];

		for(i=0; i<arrayList_size(topic_list);i++){
			char* topic = arrayList_get(topic_list,i);
			if(strlen(topic)<MAX_TOPIC_LEN){

				bundle_pt bundle = NULL;
				long bundleId = 0;
				bundleContext_getBundle(context,&bundle);
				bundle_getBundleId(bundle,&bundleId);

				service_tracker_pt tracker = NULL;
				memset(filter,0,128);

				snprintf(filter, 128, "(&(%s=%s)(%s=%s))", (char*) OSGI_FRAMEWORK_OBJECTCLASS, PUBSUB_PUBLISHER_SERVICE_NAME, PUBSUB_PUBLISHER_TOPIC,topic);

				service_tracker_customizer_pt customizer = NULL;

				serviceTrackerCustomizer_create(act->client,NULL,publisher_publishSvcAdded,NULL,publisher_publishSvcRemoved,&customizer);
				serviceTracker_createWithFilter(context, filter, customizer, &tracker);

				arrayList_add(act->trackerList,tracker);
			}
			else{
				printf("Topic %s too long. Skipping publication.\n",topic);
			}
			free(topic);
		}
		arrayList_destroy(topic_list);

	}

	publisher_start(act->client);

	for(i=0;i<arrayList_size(act->trackerList);i++){
		service_tracker_pt tracker = arrayList_get(act->trackerList,i);
		serviceTracker_open(tracker);
	}

	return CELIX_SUCCESS;
}
Example #13
0
    /// \TEST_CASE_ID{1}
    /// \TEST_CASE_TITLE{Test register scope service}
    /// \TEST_CASE_REQ{REQ-1}
    /// \TEST_CASE_DESC Checks if 3 bundles are installed after the framework setup
    static void testBundles(void) {
    	printf("Begin: %s\n", __func__);
            array_list_pt bundles = NULL;

            int rc = bundleContext_getBundles(context, &bundles);
            CHECK_EQUAL(0, rc);
            CHECK_EQUAL(5, arrayList_size(bundles)); //framework, scopeService & calc & rsa

            /*
            int size = arrayList_size(bundles);
            int i;
            for (i = 0; i < size; i += 1) {
                bundle_pt bundle = NULL;
                module_pt module = NULL;
                char *name = NULL;

                bundle = (bundle_pt) arrayList_get(bundles, i);
                bundle_getCurrentModule(bundle, &module);
                module_getSymbolicName(module, &name);
                printf("got bundle with symbolic name '%s'", name);
            }*/

            arrayList_destroy(bundles);
        	printf("End: %s\n", __func__);
    }
Example #14
0
celix_status_t driverMatcher_getBestMatch(driver_matcher_pt matcher, apr_pool_t *pool, service_reference_pt reference, match_pt *match) {
	celix_status_t status = CELIX_SUCCESS;

	if (*match != NULL) {
		status = CELIX_ILLEGAL_ARGUMENT;
	} else {
		service_reference_pt selectorRef = NULL;
		status = bundleContext_getServiceReference(matcher->context, OSGI_DEVICEACCESS_DRIVER_SELECTOR_SERVICE_NAME, &selectorRef);
		if (status == CELIX_SUCCESS) {
			int index = -1;
			if (selectorRef != NULL) {
				driver_selector_service_pt selector = NULL;
				status = bundleContext_getService(matcher->context, selectorRef, (void **) &selector);
				if (status == CELIX_SUCCESS) {
					if (selector != NULL) {
						int size = -1;
						status = selector->driverSelector_select(selector->selector, reference, matcher->matches, &index);
						if (status == CELIX_SUCCESS) {
							size = arrayList_size(matcher->matches);
							if (index != -1 && index >= 0 && index < size) {
								*match = arrayList_get(matcher->matches, index);
							}
						}
					}
				}
			}
			if (status == CELIX_SUCCESS && *match == NULL) {
				status = driverMatcher_getBestMatchInternal(matcher, pool, match);
			}
		}
	}

	return status;
}
Example #15
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);
}
Example #16
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;
}
Example #17
0
celix_status_t etcdWriter_deletePublisherEndpoint(etcd_writer_pt writer, pubsub_endpoint_pt pubEP) {
	celix_status_t status = CELIX_SUCCESS;
	char *key = NULL;

	const char *rootPath = etcdWriter_getRootPath(writer->pubsub_discovery->context);

	asprintf(&key, "%s/%s/%s/%s/%ld", rootPath, pubEP->scope, pubEP->topic, pubEP->frameworkUUID, pubEP->serviceID);

	celixThreadMutex_lock(&writer->localPubsLock);
	for (unsigned int i = 0; i < arrayList_size(writer->localPubs); i++) {
		pubsub_endpoint_pt ep = arrayList_get(writer->localPubs, i);
		if (pubsubEndpoint_equals(ep, pubEP)) {
			arrayList_remove(writer->localPubs, i);
			pubsubEndpoint_destroy(ep);
			break;
		}
	}
	celixThreadMutex_unlock(&writer->localPubsLock);

	if (etcd_del(key)) {
		printf("Failed to remove key %s from ETCD\n",key);
		status = CELIX_ILLEGAL_ARGUMENT;
	}
	FREE_MEM(key);
	return status;
}
Example #18
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;
}
Example #19
0
celix_status_t deploymentAdmin_updateDeploymentPackageBundles(deployment_admin_pt admin, deployment_package_pt source) {
	celix_status_t status = CELIX_SUCCESS;

	array_list_pt infos = NULL;
	deploymentPackage_getBundleInfos(source, &infos);
	int i;
	for (i = 0; i < arrayList_size(infos); i++) {
		bundle_pt bundle = NULL;
		bundle_info_pt info = arrayList_get(infos, i);

		bundleContext_getBundle(admin->context, &bundle);
		char *entry = NULL;
		bundle_getEntry(bundle, "/", &entry);
		char *name = NULL;
		deploymentPackage_getName(source, &name);
		char *bundlePath = apr_pstrcat(admin->pool, entry, "repo/", name, "/", info->path, NULL);
		char *bsn = apr_pstrcat(admin->pool, "osgi-dp:", info->symbolicName, NULL);

		bundle_pt updateBundle = NULL;
		deploymentPackage_getBundle(source, info->symbolicName, &updateBundle);
		if (updateBundle != NULL) {
			//printf("Update bundle from: %s\n", bundlePath);
			bundle_update(updateBundle, bundlePath);
		} else {
			//printf("Install bundle from: %s\n", bundlePath);
			bundleContext_installBundle2(admin->context, bsn, bundlePath, &updateBundle);
		}
	}

	return status;
}
Example #20
0
celix_status_t deviceManager_isDriverBundle(device_manager_pt manager, bundle_pt bundle, bool *isDriver) {
	celix_status_t status = CELIX_SUCCESS;
	(*isDriver) = false;

	array_list_pt refs = NULL;
		status = bundle_getRegisteredServices(bundle, &refs);
		if (status == CELIX_SUCCESS) {
			if (refs != NULL) {
				int i;
				for (i = 0; i < arrayList_size(refs); i++) {
					celix_status_t substatus = CELIX_SUCCESS;
					service_reference_pt ref = arrayList_get(refs, i);
					service_registration_pt registration = NULL;
					substatus = serviceReference_getServiceRegistration(ref, &registration);
					if (substatus == CELIX_SUCCESS) {
						properties_pt properties = NULL;
						substatus = serviceRegistration_getProperties(registration, &properties);
						if (substatus == CELIX_SUCCESS) {
							char *object = properties_get(properties, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
																if (strcmp(object, "driver") == 0) {
																	*isDriver = true;
																	break;
																}
						}

					}
				}
				arrayList_destroy(refs);
			}
		}

	return status;
}
/**
 * Removes an endpoint URL from the list of polled endpoints.
 */
celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url) {
	celix_status_t status = CELIX_SUCCESS;

	if (celixThreadMutex_lock(&poller->pollerLock) != CELIX_SUCCESS) {
		status = CELIX_BUNDLE_EXCEPTION;
	} else {
		hash_map_entry_pt entry = hashMap_getEntry(poller->entries, url);

		if (entry == NULL) {
			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: There was no entry found belonging to url %s - maybe already removed?", url);
		} else {
			char* origKey = hashMapEntry_getKey(entry);

			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: remove discovery endpoint with url %s", url);

			array_list_pt entries = hashMap_remove(poller->entries, url);

			for (unsigned int i = arrayList_size(entries); i > 0; i--) {
				endpoint_description_pt endpoint = arrayList_get(entries, i - 1);
				discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
				arrayList_remove(entries, i - 1);
				endpointDescription_destroy(endpoint);
			}

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

			free(origKey);
		}
		status = celixThreadMutex_unlock(&poller->pollerLock);
	}

	return status;
}
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;
}
Example #23
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;
}
Example #24
0
celix_status_t driverLoader_unloadDrivers(driver_loader_pt loader, driver_attributes_pt finalDriver) {
	celix_status_t status = CELIX_SUCCESS;

	service_reference_pt finalReference = NULL;
	if (finalDriver != NULL) {
		status = driverAttributes_getReference(finalDriver, &finalReference);
	}
	if (status == CELIX_SUCCESS) {
		int i;
		for (i = 0; i < arrayList_size(loader->loadedDrivers); i++) {
			service_reference_pt reference = arrayList_get(loader->loadedDrivers, i);
			bool equal = false;
			status = serviceReference_equals(reference, finalReference, &equal);
			if (status == CELIX_SUCCESS && !equal) {
				bundle_pt bundle = NULL;
				status = serviceReference_getBundle(reference, &bundle);
				if (status == CELIX_SUCCESS) {
					bundle_uninstall(bundle); // Ignore status
				}
			}
		}
	}

	return status;
}
Example #25
0
celix_status_t serviceRegistry_unregisterServices(service_registry_pt registry, bundle_pt bundle) {
	array_list_pt regs = NULL;
	unsigned int i;
	celixThreadMutex_lock(&registry->mutex);
	regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
	celixThreadMutex_unlock(&registry->mutex);
	
	for (i = 0; (regs != NULL) && i < arrayList_size(regs); i++) {
		service_registration_pt reg = arrayList_get(regs, i);
		if (serviceRegistration_isValid(reg)) {
			serviceRegistration_unregister(reg);
		}
	}

	if (regs != NULL && arrayList_isEmpty(regs)) {
	    celixThreadMutex_lock(&registry->mutex);
		array_list_pt removed = hashMap_remove(registry->serviceRegistrations, bundle);
		celixThreadMutex_unlock(&registry->mutex);
		arrayList_destroy(removed);
		removed = NULL;
	}

	celixThreadMutex_lock(&registry->mutex);
	hashMap_remove(registry->serviceRegistrations, bundle);
	celixThreadMutex_unlock(&registry->mutex);

	return CELIX_SUCCESS;
}
Example #26
0
void serviceRegistry_ungetServices(service_registry_pt registry, bundle_pt bundle) {
	array_list_pt fusages;
	array_list_pt usages;
	unsigned int i;

	celixThreadMutex_lock(&registry->mutex);
	usages = hashMap_get(registry->inUseMap, bundle);
	celixThreadMutex_unlock(&registry->mutex);

	if (usages == NULL || arrayList_isEmpty(usages)) {
		return;
	}

	// usage arrays?
	fusages = arrayList_clone(usages);
	
	for (i = 0; i < arrayList_size(fusages); i++) {
		usage_count_pt usage = arrayList_get(fusages, i);
		service_reference_pt reference = usage->reference;
		bool ungetResult = true;
		while (ungetResult) {
			serviceRegistry_ungetService(registry, bundle, reference, &ungetResult);
		}
	}

	arrayList_destroy(fusages);
}
Example #27
0
celix_status_t serviceRegistry_ungetServiceReference(service_registry_pt registry, bundle_pt owner, service_reference_pt reference) {
    celix_status_t status = CELIX_SUCCESS;

    bool valid = false;
    serviceRefernce_isValid(reference, &valid);
    if (valid) {
        bool ungetResult = true;
        while (ungetResult) {
            serviceRegistry_ungetService(registry, owner, reference, &ungetResult);
        }
    }

    celixThreadMutex_lock(&registry->referencesMapMutex);
    array_list_pt references = hashMap_get(registry->serviceReferences, owner);
    if (references != NULL) {
        arrayList_removeElement(references, reference);
        serviceReference_destroy(&reference);
        if (arrayList_size(references) > 0) {
            hashMap_put(registry->serviceReferences, owner, references);
        } else {
            array_list_pt removed = hashMap_remove(registry->serviceReferences, owner);
            arrayList_destroy(removed);
        }
    }
    celixThreadMutex_unlock(&registry->referencesMapMutex);

	return status;
}
Example #28
0
celix_status_t endpointDescriptorWriter_writeDocument(endpoint_descriptor_writer_pt writer, array_list_pt endpoints, char **document) {
    celix_status_t status = CELIX_SUCCESS;
    int rc;

    rc = xmlTextWriterStartDocument(writer->writer, NULL, "UTF-8", NULL);
    if (rc < 0) {
        status = CELIX_BUNDLE_EXCEPTION;
    } else {
        rc = xmlTextWriterStartElementNS(writer->writer, NULL, ENDPOINT_DESCRIPTIONS, XMLNS);
        if (rc < 0) {
            status = CELIX_BUNDLE_EXCEPTION;
        } else {
            unsigned int i;
            for (i = 0; i < arrayList_size(endpoints); i++) {
                endpoint_description_pt endpoint = arrayList_get(endpoints, i);
                status = endpointDescriptorWriter_writeEndpoint(writer, endpoint);
            }
            if (status == CELIX_SUCCESS) {
                rc = xmlTextWriterEndElement(writer->writer);
                if (rc < 0) {
                    status = CELIX_BUNDLE_EXCEPTION;
                } else {
                    rc = xmlTextWriterEndDocument(writer->writer);
                    if (rc < 0) {
                        status = CELIX_BUNDLE_EXCEPTION;
                    } else {
                        *document = (char *) writer->buffer->content;
                    }
                }
            }
        }
    }

    return status;
}
Example #29
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;
}
Example #30
0
celix_status_t serviceTracker_open(service_tracker_pt tracker) {
	service_listener_pt listener;
	array_list_pt initial = NULL;
	celix_status_t status = CELIX_SUCCESS;
	listener = (service_listener_pt) malloc(sizeof(*listener));
	
	status = bundleContext_getServiceReferences(tracker->context, NULL, tracker->filter, &initial);
	if (status == CELIX_SUCCESS) {
		service_reference_pt initial_reference;
		unsigned int i;

		listener->handle = tracker;
		listener->serviceChanged = (void *) serviceTracker_serviceChanged;
		status = bundleContext_addServiceListener(tracker->context, listener, tracker->filter);
		if (status == CELIX_SUCCESS) {
			tracker->listener = listener;

			for (i = 0; i < arrayList_size(initial); i++) {
				initial_reference = (service_reference_pt) arrayList_get(initial, i);
				serviceTracker_track(tracker, initial_reference, NULL);
			}
			arrayList_clear(initial);
			arrayList_destroy(initial);

			initial = NULL;
		}
	}

	framework_logIfError(logger, status, NULL, "Cannot open tracker");

	return status;
}