void uninstallCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *)) { char delims[] = " "; char * sub = NULL; char *save_ptr = NULL; char outString[256]; sub = strtok_r(line, delims, &save_ptr); sub = strtok_r(NULL, delims, &save_ptr); if (sub == NULL) { err("Incorrect number of arguments.\n"); sprintf(outString, "%s\n", command->usage); out(outString); } else { while (sub != NULL) { long id = atol(sub); bundle_pt bundle = NULL; bundleContext_getBundleById(command->bundleContext, id, &bundle); if (bundle != NULL) { bundle_uninstall(bundle); } else { err("Bundle id is invalid."); } sub = strtok_r(NULL, delims, &save_ptr); } } }
static void testProxyRemoval(void) { celix_status_t status; bundle_pt bundle = NULL; array_list_pt bundleNames = NULL; array_list_pt proxyBundle = NULL; service_reference_pt ref = NULL; arrayList_create(&bundleNames); arrayList_create(&proxyBundle); arrayList_add(bundleNames, (void*) CALCULATOR_PROXY); status = getSpecifiedBundles(clientContext, bundleNames, proxyBundle); CHECK_EQUAL(CELIX_SUCCESS, status); CHECK_EQUAL(arrayList_size(proxyBundle), arrayList_size(bundleNames)); status = bundleContext_getBundleById(clientContext, (long) arrayList_get(proxyBundle, 0), &bundle); CHECK_EQUAL(CELIX_SUCCESS, status); status = bundle_stop(bundle); CHECK_EQUAL(CELIX_SUCCESS, status); status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref); CHECK_EQUAL(CELIX_SUCCESS, status); CHECK(ref == NULL); arrayList_destroy(bundleNames); arrayList_destroy(proxyBundle); }
celix_status_t stopCommand_execute(void *_ptr, char *command_line_str, FILE *out_ptr, FILE *err_ptr) { celix_status_t status = CELIX_SUCCESS; bundle_context_pt context_ptr = _ptr; if (!context_ptr || !command_line_str || !out_ptr || !err_ptr) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { char *sub_str = NULL; char *save_ptr = NULL; strtok_r(command_line_str, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); sub_str = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); if (sub_str == NULL) { fprintf(out_ptr, "Incorrect number of arguments.\n"); } else { while (sub_str != NULL) { celix_status_t sub_status = CELIX_SUCCESS; bundle_pt bundle_ptr = NULL; char *end_str = NULL; long id = strtol(sub_str, &end_str, 10); if (*end_str) { sub_status = CELIX_ILLEGAL_ARGUMENT; fprintf(err_ptr, "Bundle id '%s' is invalid, problem at %s\n", sub_str, end_str); } if (sub_status == CELIX_SUCCESS) { sub_status = bundleContext_getBundleById(context_ptr, id, &bundle_ptr); } if (sub_status == CELIX_SUCCESS) { bundle_stopWithOptions(bundle_ptr, 0); } if (sub_status != CELIX_SUCCESS) { status = sub_status; break; } sub_str = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr); } } } return status; }
void updateCommand_execute(command_pt command, char * line, void (*out)(char *), void (*err)(char *)) { bundle_pt bundle = NULL; char delims[] = " "; char * sub = NULL; char outString[256]; sub = strtok(line, delims); sub = strtok(NULL, delims); if (sub == NULL) { err("Incorrect number of arguments.\n"); sprintf(outString, "%s\n", command->usage); out(outString); } else { long id = atol(sub); bundleContext_getBundleById(command->bundleContext, id, &bundle); if (bundle != NULL) { char inputFile[256]; sub = strtok(NULL, delims); inputFile[0] = '\0'; if (sub != NULL) { char *test = inputFile; printf("URL: %s\n", sub); if (updateCommand_download(command, sub, &test) == CELIX_SUCCESS) { printf("Update bundle with stream\n"); bundle_update(bundle, inputFile); } else { char error[256]; sprintf(error, "Unable to download from %s\n", sub); err(error); } } else { bundle_update(bundle, NULL); } } else { err("Bundle id is invalid.\n"); } } }
static celix_status_t stopStartPermutation(bundle_context_pt context, long* permutation, int size) { celix_status_t status = CELIX_SUCCESS; int y = 0; printf("Test stop/start permutation: "); for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { module_pt module = NULL; const char *name = NULL; status = bundle_getCurrentModule(bundle, &module); if (status == CELIX_SUCCESS) { status = module_getSymbolicName(module, &name); printf("%s (%ld) ", name, permutation[y]); } } } printf("\n"); // stop all bundles if (status == CELIX_SUCCESS) { for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { printf("stop bundle: %ld\n", permutation[y]); status = bundle_stop(bundle); } } } // verify stop state if (status == CELIX_SUCCESS) { for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { bundle_state_e state; status = bundle_getState(bundle, &state); if (state != OSGI_FRAMEWORK_BUNDLE_RESOLVED) { printf("bundle %ld has state %d (should be %d) \n", permutation[y], state, OSGI_FRAMEWORK_BUNDLE_RESOLVED); status = CELIX_ILLEGAL_STATE; } } } } // start all bundles if (status == CELIX_SUCCESS) { for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { printf("start bundle: %ld\n", permutation[y]); status = bundle_start(bundle); } } } // verify started state if (status == CELIX_SUCCESS) { for (y = 0; (y < size) && (status == CELIX_SUCCESS); y++) { bundle_pt bundle = NULL; status = bundleContext_getBundleById(context, permutation[y], &bundle); if (status == CELIX_SUCCESS) { bundle_state_e state; status = bundle_getState(bundle, &state); if (state != OSGI_FRAMEWORK_BUNDLE_ACTIVE) { printf("bundle %ld has state %d (should be %d) \n", permutation[y], state, OSGI_FRAMEWORK_BUNDLE_ACTIVE); status = CELIX_ILLEGAL_STATE; } } } } return status; }
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; }
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; }