Exemple #1
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;
}
Exemple #2
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;
}
Exemple #3
0
/* Callback to the pubsub_topology_manager */
celix_status_t pubsub_discovery_informPublishersListeners(pubsub_discovery_pt pubsub_discovery, pubsub_endpoint_pt pubEP, bool epAdded) {
	celix_status_t status = CELIX_SUCCESS;

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

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

			publisher_endpoint_announce_pt listener = NULL;

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

	celixThreadMutex_unlock(&pubsub_discovery->listenerReferencesMutex);

	return status;
}
Exemple #4
0
celix_status_t deviceManager_getIdleDevices_exmaple(device_manager_pt manager, apr_pool_t *pool, array_list_pt *idleDevices) {
	celix_status_t status = CELIX_SUCCESS;

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

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

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

							inUse = true;
							break;
						}
					}
				}

				if (!inUse) {
					arrayList_add(*idleDevices, ref);
				}
			}
		}
		hashMapIterator_destroy(iter);
	}
	return status;
}