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; }
celix_status_t inspectCommand_printImportedServices(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_getServicesInUse(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 requires 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); bundle_pt usedBundle = NULL; module_pt usedModule = NULL; char *usedSymbolicName = NULL; long usedBundleId; serviceReference_getBundle(ref, &usedBundle); bundle_getBundleId(usedBundle, &usedBundleId); bundle_getCurrentModule(usedBundle, &usedModule); module_getSymbolicName(usedModule, &usedSymbolicName); fprintf(outStream, "%s [%ld]\n", usedSymbolicName, usedBundleId); 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); } free(keys); // objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS); // sprintf(line, "ObjectClass = %s\n", objectClass); if ((j + 1) < arrayList_size(refs)) { fprintf(outStream, "----\n"); } } } } } } } } } arrayList_destroy(bundles); return status; }
celix_status_t inspectCommand_printImportedServices(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_getServicesInUse(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 requires 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]; bundle_pt usedBundle = NULL; module_pt usedModule = NULL; char *usedSymbolicName = NULL; long usedBundleId; serviceReference_getBundle(ref, &usedBundle); bundle_getBundleId(usedBundle, &usedBundleId); bundle_getCurrentModule(usedBundle, &usedModule); module_getSymbolicName(usedModule, &usedSymbolicName); sprintf(line, "%s [%ld]\n", usedSymbolicName, usedBundleId); out(line); serviceReference_getServiceRegistration(ref, ®); 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; }