示例#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;
}
示例#2
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;
}