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; }
static celix_status_t deviceManager_attachAlgorithm(device_manager_pt manager, service_reference_pt ref, void *service) { celix_status_t status = CELIX_SUCCESS; driver_loader_pt loader = NULL; status = driverLoader_create(manager->context, &loader); if (status == CELIX_SUCCESS) { array_list_pt included = NULL; array_list_pt excluded = NULL; array_list_pt driverIds = NULL; hashMap_put(manager->devices, ref, service); status = arrayList_create(&included); if (status == CELIX_SUCCESS) { status = arrayList_create(&excluded); if (status == CELIX_SUCCESS) { properties_pt properties = properties_create(); unsigned int size = 0; char **keys; serviceReference_getPropertyKeys(ref, &keys, &size); for (int i = 0; i < size; i++) { char* key = keys[i]; const char* value = NULL; serviceReference_getProperty(ref, key, &value); properties_set(properties, key, value); } status = driverLoader_findDrivers(loader, manager->locators, properties, &driverIds); if (status == CELIX_SUCCESS) { hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers); while (hashMapIterator_hasNext(iter)) { driver_attributes_pt driverAttributes = hashMapIterator_nextValue(iter); arrayList_add(included, driverAttributes); // Each driver that already is installed can be removed from the list char *id = NULL; celix_status_t substatus = driverAttributes_getDriverId(driverAttributes, &id); if (substatus == CELIX_SUCCESS) { // arrayList_removeElement(driverIds, id); array_list_iterator_pt idsIter = arrayListIterator_create(driverIds); while (arrayListIterator_hasNext(idsIter)) { char *value = arrayListIterator_next(idsIter); if (strcmp(value, id) == 0) { arrayListIterator_remove(idsIter); } } arrayListIterator_destroy(idsIter); } if(id != NULL){ free(id); } } hashMapIterator_destroy(iter); status = deviceManager_matchAttachDriver(manager, loader, driverIds, included, excluded, service, ref); } arrayList_destroy(driverIds); properties_destroy(properties); arrayList_destroy(excluded); } arrayList_destroy(included); } } driverLoader_destroy(&loader); return status; }