Ejemplo n.º 1
0
    /// \TEST_CASE_ID{1}
    /// \TEST_CASE_TITLE{Test register scope service}
    /// \TEST_CASE_REQ{REQ-1}
    /// \TEST_CASE_DESC Checks if 3 bundles are installed after the framework setup
    static void testBundles(void) {
    	printf("Begin: %s\n", __func__);
            array_list_pt bundles = NULL;

            int rc = bundleContext_getBundles(context, &bundles);
            CHECK_EQUAL(0, rc);
            CHECK_EQUAL(5, arrayList_size(bundles)); //framework, scopeService & calc & rsa

            /*
            int size = arrayList_size(bundles);
            int i;
            for (i = 0; i < size; i += 1) {
                bundle_pt bundle = NULL;
                module_pt module = NULL;
                char *name = NULL;

                bundle = (bundle_pt) arrayList_get(bundles, i);
                bundle_getCurrentModule(bundle, &module);
                module_getSymbolicName(module, &name);
                printf("got bundle with symbolic name '%s'", name);
            }*/

            arrayList_destroy(bundles);
        	printf("End: %s\n", __func__);
    }
Ejemplo n.º 2
0
	static celix_status_t getSpecifiedBundles(bundle_context_pt context, array_list_pt bundleNames, array_list_pt retrievedBundles) {
		celix_status_t status;
		array_list_pt bundles = NULL;

		status = bundleContext_getBundles(context, &bundles);

		if (status == CELIX_SUCCESS) {
			unsigned int size = arrayList_size(bundles);
			unsigned int i;

			for (i = 0; i < size; i++) {
				module_pt module = NULL;
				const char *name = NULL;

				bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i);

				status = bundle_getCurrentModule(bundle, &module);

				if (status == CELIX_SUCCESS) {
					status = module_getSymbolicName(module, &name);
				}

				if (status == CELIX_SUCCESS) {

					printf("FOUND %s\n", name);

					array_list_iterator_pt iter = arrayListIterator_create(bundleNames);

					while(arrayListIterator_hasNext(iter)) {
						char* bundleName = (char*) arrayListIterator_next(iter);

						if ((strcmp(name, bundleName) == 0)) {

							bundle_archive_pt bundleArchive = NULL;
							long bundleId = -1;

							status = bundle_getArchive(bundle, &bundleArchive);

							if (status == CELIX_SUCCESS) {
								status = bundleArchive_getId(bundleArchive, &bundleId);
							}

							if (status == CELIX_SUCCESS) {
								arrayList_add(retrievedBundles, (void*) bundleId);
								break;
							}
						}
					}

					arrayListIterator_destroy(iter);

				}
			}

			arrayList_destroy(bundles);
		}

		return status;
	}
Ejemplo n.º 3
0
celix_status_t deploymentPackage_getBundle(deployment_package_pt package, char *name, bundle_pt *bundle) {
	if (hashMap_containsKey(package->nameToBundleInfo, name)) {
		array_list_pt bundles = NULL;
		bundleContext_getBundles(package->context, &bundles);
		int i;
		for (i = 0; i < arrayList_size(bundles); i++) {
			bundle_pt ibundle = arrayList_get(bundles, i);
			module_pt module = NULL;
			bundle_getCurrentModule(ibundle, &module);
			char *bsn = NULL;
			module_getSymbolicName(module, &bsn);
			if (strcmp(bsn, name) == 0) {
				*bundle = ibundle;
				break;
			}
		}
	}

	return CELIX_SUCCESS;
}
Ejemplo n.º 4
0
/**
 * Loop through all bundles and look for the bundle with the keys inside.
 * If no key bundle found, return NULL
 *
 * Caller is responsible for freeing the object
 */
char* pubsub_getKeysBundleDir(bundle_context_pt ctx)
{
	array_list_pt bundles = NULL;
	bundleContext_getBundles(ctx, &bundles);
	int nrOfBundles = arrayList_size(bundles);
	long bundle_id = -1;
	char* result = NULL;

	for (int i = 0; i < nrOfBundles; i++){
		bundle_pt b = arrayList_get(bundles, i);

		/* Skip bundle 0 (framework bundle) since it has no path nor revisions */
		bundle_getBundleId(b, &bundle_id);
		if(bundle_id==0){
			continue;
		}

		char* dir = NULL;
		bundle_getEntry(b, ".", &dir);

		char cert_dir[MAX_KEYBUNDLE_LENGTH];
		snprintf(cert_dir, MAX_KEYBUNDLE_LENGTH, "%s/META-INF/keys", dir);

		struct stat s;
		int err = stat(cert_dir, &s);
		if (err != -1){
			if (S_ISDIR(s.st_mode)){
				result = dir;
				break;
			}
		}

		free(dir);
	}

	arrayList_destroy(bundles);

	return result;
}
Ejemplo n.º 5
0
    static void testBundles(void) {
        array_list_pt bundles = NULL;

        int rc = bundleContext_getBundles(context, &bundles);
        CHECK_EQUAL(0, rc);
        CHECK_EQUAL(3, arrayList_size(bundles)); //framework, rsa_dfi & calc

        /*
        int size = arrayList_size(bundles);
        int i;
        for (i = 0; i < size; i += 1) {
            bundle_pt bundle = NULL;
            module_pt module = NULL;
            char *name = NULL;

            bundle = (bundle_pt) arrayList_get(bundles, i);
            bundle_getCurrentModule(bundle, &module);
            module_getSymbolicName(module, &name);
            printf("got bundle with symbolic name '%s'", name);
        }*/

        arrayList_destroy(bundles);
    }
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
celix_status_t psCommand_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;
    array_list_pt bundles_ptr     = NULL;

    bool show_location        = false;
    bool show_symbolic_name   = false;
    bool show_update_location = false;
    char *message_str         = "Name";

    if (!context_ptr || !command_line_str || !out_ptr || !err_ptr) {
        status = CELIX_ILLEGAL_ARGUMENT;
    }

    if (status == CELIX_SUCCESS) {
        status = bundleContext_getBundles(context_ptr, &bundles_ptr);
    }

    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);
        while (sub_str != NULL) {
            if (strcmp(sub_str, "-l") == 0) {
                show_location = true;
                message_str = "Location";
            } else if (strcmp(sub_str, "-s") == 0) {
                show_symbolic_name = true;
                message_str = "Symbolic name";
            } else if (strcmp(sub_str, "-u") == 0) {
                show_update_location = true;
                message_str = "Update location";
            }
            sub_str = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &save_ptr);
        }

        fprintf(out_ptr, "  %-5s %-12s %s\n", "ID", "State", message_str);

        unsigned int size = arrayList_size(bundles_ptr);
        bundle_pt bundles_array_ptr[size];

        for (unsigned int i = 0; i < size; i++) {
            bundles_array_ptr[i] = arrayList_get(bundles_ptr, i);
        }

        for (unsigned int i = 0; i < size - 1; i++) {
            for (unsigned int j = i + 1; j < size; j++) {
                bundle_pt first_ptr = bundles_array_ptr[i];
                bundle_pt second_ptr = bundles_array_ptr[j];

                bundle_archive_pt first_archive_ptr = NULL;
                bundle_archive_pt second_archive_ptr = NULL;

                long first_id;
                long second_id;

                bundle_getArchive(first_ptr, &first_archive_ptr);
                bundle_getArchive(second_ptr, &second_archive_ptr);

                bundleArchive_getId(first_archive_ptr, &first_id);
                bundleArchive_getId(second_archive_ptr, &second_id);

                if (first_id > second_id) {
                    bundle_pt temp_ptr = bundles_array_ptr[i];
                    bundles_array_ptr[i] = bundles_array_ptr[j];
                    bundles_array_ptr[j] = temp_ptr;
                }
            }
        }

        for (unsigned int i = 0; i < size - 1; i++) {
            celix_status_t sub_status;

            bundle_pt bundle_ptr = bundles_array_ptr[i];

            bundle_archive_pt archive_ptr = NULL;
            long id = 0;
            bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
            char *state_str = NULL;
            module_pt module_ptr = NULL;
            char *name_str = NULL;

            sub_status = bundle_getArchive(bundle_ptr, &archive_ptr);
            if (sub_status == CELIX_SUCCESS) {
                sub_status = bundleArchive_getId(archive_ptr, &id);
            }

            if (sub_status == CELIX_SUCCESS) {
                sub_status = bundle_getState(bundle_ptr, &state);
            }

            if (sub_status == CELIX_SUCCESS) {
                state_str = psCommand_stateString(state);

                sub_status = bundle_getCurrentModule(bundle_ptr, &module_ptr);
            }

            if (sub_status == CELIX_SUCCESS) {
                sub_status = module_getSymbolicName(module_ptr, &name_str);
            }

            if (sub_status == CELIX_SUCCESS) {
                if (show_location) {
                    sub_status = bundleArchive_getLocation(archive_ptr, &name_str);
                } else if (show_symbolic_name) {
                    // do nothing
                } else if (show_update_location) {
                    sub_status = bundleArchive_getLocation(archive_ptr, &name_str);
                }
            }

            if (sub_status == CELIX_SUCCESS) {
                fprintf(out_ptr, "  %-5ld %-12s %s\n", id, state_str, name_str);
            }

            if (sub_status != CELIX_SUCCESS) {
                status = sub_status;
                break;
            }
        }

        arrayList_destroy(bundles_ptr);
    }

    return status;
}
Ejemplo n.º 8
0
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, &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;
}