Beispiel #1
0
celix_status_t driverLoader_loadDriverForLocator(driver_loader_pt loader, driver_locator_service_pt locator, char *driverId, array_list_pt *references) {
	celix_status_t status = CELIX_SUCCESS;
	//The list is created in the bundle_getRegisteredServices chain
	//arrayList_create(references);

	char *filename = NULL;
	status = locator->loadDriver(locator->locator, driverId, &filename);
	if (status == CELIX_SUCCESS) {
		bundle_pt bundle = NULL;
		int length = strlen(DRIVER_LOCATION_PREFIX) + strlen(driverId);
		char location[length];
		snprintf(location, length, "%s%s", DRIVER_LOCATION_PREFIX, driverId);
		status = bundleContext_installBundle2(loader->context, location, filename, &bundle);
		if (status == CELIX_SUCCESS) {
			status = bundle_start(bundle);
			if (status == CELIX_SUCCESS) {
				status = bundle_getRegisteredServices(bundle, references);
				if (status == CELIX_SUCCESS) {
					arrayList_addAll(loader->loadedDrivers, *references);
				}
			}
		}
	}

	return status;
}
Beispiel #2
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;
}
Beispiel #3
0
celix_status_t inspectCommand_printExportedServices(bundle_context_pt context, array_list_pt ids, FILE *outStream, FILE *errStream) {
	celix_status_t status = CELIX_SUCCESS;
	array_list_pt bundles = NULL;

	if (arrayList_isEmpty(ids)) {
		status = bundleContext_getBundles(context, &bundles);
	} else {
		unsigned int i;

		arrayList_create(&bundles);
		for (i = 0; i < arrayList_size(ids); i++) {
			char *idStr = (char *) arrayList_get(ids, i);
			long id = atol(idStr);
			bundle_pt b = NULL;
			celix_status_t st = bundleContext_getBundleById(context, id, &b);
			if (st == CELIX_SUCCESS) {
				arrayList_add(bundles, b);
			} else {
				fprintf(outStream, "INSPECT: Invalid bundle ID: %ld\n", id);
			}
		}
	}

	if (status == CELIX_SUCCESS) {
		unsigned int i = 0;
		for (i = 0; i < arrayList_size(bundles); i++) {
			bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i);

			if (i > 0) {
				fprintf(outStream, "\n");
			}

			if (bundle != NULL) {
				array_list_pt refs = NULL;

				if (bundle_getRegisteredServices(bundle, &refs) == CELIX_SUCCESS) {
					module_pt module = NULL;
					char * name = NULL;
					status = bundle_getCurrentModule(bundle, &module);
					if (status == CELIX_SUCCESS) {
						status = module_getSymbolicName(module, &name);
						if (status == CELIX_SUCCESS) {
							fprintf(outStream, "%s provides services:\n", name);
							fprintf(outStream, "==============\n");

							if (refs == NULL || arrayList_size(refs) == 0) {
								fprintf(outStream, "Nothing\n");
							} else {
								unsigned int j = 0;
								for (j = 0; j < arrayList_size(refs); j++) {
									service_reference_pt ref = (service_reference_pt) arrayList_get(refs, j);
									unsigned int size = 0;
									char **keys;

									serviceReference_getPropertyKeys(ref, &keys, &size);
									for (int k = 0; k < size; k++) {
									    char *key = keys[k];
									    char *value = NULL;
									    serviceReference_getProperty(ref, key, &value);

										fprintf(outStream, "%s = %s\n", key, value);
									}

//									objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
//									sprintf(line, "ObjectClass = %s\n", objectClass);
									if ((j + 1) < arrayList_size(refs)) {
										fprintf(outStream, "----\n");
									}
								}
							}
						}
					}
				}
			}
		}
	}

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

	return status;
}
Beispiel #4
0
celix_status_t inspectCommand_printExportedServices(command_pt command, array_list_pt ids, void (*out)(char *), void (*err)(char *)) {
	celix_status_t status = CELIX_SUCCESS;
	array_list_pt bundles = NULL;

	if (arrayList_isEmpty(ids)) {
		celix_status_t status = bundleContext_getBundles(command->bundleContext, &bundles);
	} else {
		unsigned int i;

		arrayList_create(&bundles);
		for (i = 0; i < arrayList_size(ids); i++) {
			char *idStr = (char *) arrayList_get(ids, i);
			long id = atol(idStr);
			bundle_pt b = NULL;
			celix_status_t st = bundleContext_getBundleById(command->bundleContext, id, &b);
			if (st == CELIX_SUCCESS) {
				arrayList_add(bundles, b);
			} else {
				char line[256];
				sprintf(line, "INSPECT: Invalid bundle ID: %ld\n", id);
				out(line);
			}
		}
	}

	if (status == CELIX_SUCCESS) {
		unsigned int i = 0;
		for (i = 0; i < arrayList_size(bundles); i++) {
			bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i);

			if (i > 0) {
				out("\n");
			}

			if (bundle != NULL) {
				array_list_pt refs = NULL;

				if (bundle_getRegisteredServices(bundle, &refs) == CELIX_SUCCESS) {
					char line[256];
					module_pt module = NULL;
					char * name = NULL;
					status = bundle_getCurrentModule(bundle, &module);
					if (status == CELIX_SUCCESS) {
						status = module_getSymbolicName(module, &name);
						if (status == CELIX_SUCCESS) {
							sprintf(line, "%s provides services:\n", name);
							out(line);
							out("==============\n");

							if (refs == NULL || arrayList_size(refs) == 0) {
								out("Nothing\n");
							} else {
								unsigned int j = 0;
								for (j = 0; j < arrayList_size(refs); j++) {
									service_reference_pt ref = (service_reference_pt) arrayList_get(refs, j);
									service_registration_pt reg = NULL;
									properties_pt props = NULL;
									char line[256];
									char *objectClass = NULL;

									serviceReference_getServiceRegistration(ref, &reg);
									
									serviceRegistration_getProperties(reg, &props);
									hash_map_iterator_pt iter = hashMapIterator_create(props);
									while (hashMapIterator_hasNext(iter)) {
									    hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
									    sprintf(line, "%s = %s\n", hashMapEntry_getKey(entry), hashMapEntry_getValue(entry));
									    out(line);
									}
									hashMapIterator_destroy(iter);

//									objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
//									sprintf(line, "ObjectClass = %s\n", objectClass);
									if ((j + 1) < arrayList_size(refs)) {
										out("----\n");
									}
								}
							}
						}
					}
				}
			}
		}
	}


	return status;
}