Esempio n. 1
0
celix_status_t driverAttributes_create(service_reference_pt reference, driver_service_pt driver, driver_attributes_pt *attributes) {
	celix_status_t status = CELIX_SUCCESS;

	*attributes = calloc(1, sizeof(**attributes));
	if (!*attributes) {
		status = CELIX_ENOMEM;
	} else {
		bundle_pt bundle = NULL;
		bundle_archive_pt bundleArchive = NULL;
		status = serviceReference_getBundle(reference, &bundle);

		if (status == CELIX_SUCCESS) {
			status = bundle_getArchive(bundle, &bundleArchive);

			if (status == CELIX_SUCCESS) {
				(*attributes)->reference = reference;
				(*attributes)->driver = driver;
				(*attributes)->bundle = bundle;

				char *location;
				status = bundleArchive_getLocation(bundleArchive, &location);
				if (status == CELIX_SUCCESS) {
					(*attributes)->dynamic = strncmp(location, DRIVER_LOCATION_PREFIX, 4) == 0 ? true : false;
				}

			}
		}
	}

	return status;
}
Esempio n. 2
0
File: bundle.c Progetto: jawi/celix
celix_status_t bundle_revise(bundle_pt bundle, char * location, char *inputFile) {
	celix_status_t status = CELIX_SUCCESS;

	bundle_archive_pt archive = NULL;
	status = bundle_getArchive(bundle, &archive);
	if (status == CELIX_SUCCESS) {
		status = bundleArchive_revise(archive, location, inputFile);
		if (status == CELIX_SUCCESS) {
			module_pt module;
			status = bundle_createModule(bundle, &module);
			if (status == CELIX_SUCCESS) {
				status = bundle_addModule(bundle, module);
			} else {
				bool rolledback;
				status = bundleArchive_rollbackRevise(archive, &rolledback);
				if (status == CELIX_SUCCESS) {
					status = CELIX_BUNDLE_EXCEPTION;
				}
			}
		}
	}

	framework_logIfError(bundle->framework->logger, status, NULL, "Failed to revise bundle");

	return status;
}
Esempio n. 3
0
celix_status_t logService_logSr(log_service_data_pt logger, service_reference_pt reference, log_level_t level, char * message) {
    celix_status_t status;
    log_entry_pt entry = NULL;
    bundle_pt bundle = logger->bundle;
    bundle_archive_pt archive = NULL;
    module_pt module = NULL;
    char *symbolicName = NULL;
    long bundleId = -1;

    if (reference != NULL) {
    	serviceReference_getBundle(reference, &bundle);
    }

    status = bundle_getArchive(bundle, &archive);

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

    if (status == CELIX_SUCCESS) {
        status = bundle_getCurrentModule(bundle, &module);

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

    logEntry_create(bundleId, symbolicName, reference, level, message, 0, &entry);
    log_addEntry(logger->log, entry);

    return CELIX_SUCCESS;
}
Esempio n. 4
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;
	}
Esempio n. 5
0
File: bundle.c Progetto: jawi/celix
celix_status_t bundle_getBundleId(bundle_pt bundle, long *id) {
	celix_status_t status = CELIX_SUCCESS;
	bundle_archive_pt archive = NULL;
	status = bundle_getArchive(bundle, &archive);
	if (status == CELIX_SUCCESS) {
		status = bundleArchive_getId(archive, id);
	}

	framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get bundle id");

	return status;
}
Esempio n. 6
0
File: bundle.c Progetto: jawi/celix
celix_status_t bundle_closeAndDelete(bundle_pt bundle) {
	celix_status_t status = CELIX_SUCCESS;

	bundle_archive_pt archive = NULL;

    bundle_closeModules(bundle);
    bundle_closeRevisions(bundle);
    status = bundle_getArchive(bundle, &archive);
    if (status == CELIX_SUCCESS) {
    	bundleArchive_closeAndDelete(archive);
    }

    framework_logIfError(bundle->framework->logger, status, NULL, "Failed to close and delete bundle");

    return status;
}
Esempio n. 7
0
File: bundle.c Progetto: jawi/celix
celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool *systemBundle) {
	celix_status_t status = CELIX_SUCCESS;
	long bundleId;
	bundle_archive_pt archive = NULL;

	status = bundle_getArchive(bundle, &archive);
	if (status == CELIX_SUCCESS) {
		status = bundleArchive_getId(archive, &bundleId);
		if (status == CELIX_SUCCESS) {
			*systemBundle = (bundleId == 0);
		}
	}

	framework_logIfError(bundle->framework->logger, status, NULL, "Failed to check if bundle is the systembundle");

	return status;
}
Esempio n. 8
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;
}
Esempio n. 9
0
File: bundle.c Progetto: jawi/celix
celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) {
	celix_status_t status = CELIX_SUCCESS;
	bundle_archive_pt archive = NULL;
	bundle_revision_pt revision = NULL;
	manifest_pt headerMap = NULL;

	status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
	status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
	status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &headerMap));
	if (status == CELIX_SUCCESS) {
        long bundleId;
        status = bundleArchive_getId(bundle->archive, &bundleId);
        if (status == CELIX_SUCCESS) {
			int revision = 0;
			char moduleId[512];
			char *mId;

			snprintf(moduleId, sizeof(moduleId), "%ld.%d", bundleId, revision);
			mId = strdup(moduleId);
			*module = module_create(headerMap, mId, bundle);
			free(mId);

			if (*module != NULL) {
				version_pt bundleVersion = module_getVersion(*module);
				char * symName = NULL;
				status = module_getSymbolicName(*module, &symName);
				if (status == CELIX_SUCCESS) {
					array_list_pt bundles = framework_getBundles(bundle->framework);
					unsigned int i;
					for (i = 0; i < arrayList_size(bundles); i++) {
						bundle_pt check = (bundle_pt) arrayList_get(bundles, i);

						long id;
						if (bundleArchive_getId(check->archive, &id) == CELIX_SUCCESS) {
							if (id != bundleId) {
								module_pt mod = NULL;
								char * sym = NULL;
								version_pt version;
								int cmp;
								status = bundle_getCurrentModule(check, &mod);
								status = module_getSymbolicName(mod, &sym);

								version = module_getVersion(mod);
								version_compareTo(bundleVersion, version, &cmp);
								if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) &&
										!cmp) {
									char *versionString = NULL;
									version_toString(version, &versionString);
									printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, versionString);
									free(versionString);
									status = CELIX_BUNDLE_EXCEPTION;
									break;
								}
							}
						}
					}
					arrayList_destroy(bundles);
				}
			}
        }
	}

	framework_logIfError(bundle->framework->logger, status, NULL, "Failed to create module");

	return status;
}