in libs/framework/src/celix_launcher.c [94:196]
static celix_status_t celix_launcher_createFramework(celix_properties_t* embeddedProps,
const celix_properties_t* runtimeProps,
celix_framework_t** frameworkOut);
/**
* @brief Parse launcher options from the given command line arguments.
*/
static celix_status_t celix_launcher_parseOptions(int argc, char* argv[], celix_launcher_options_t* opts);
/**
* @brief Print the usage of the Celix launcher command arguments.
*/
static void celix_launcher_printUsage(char* progName);
/**
* @brief Print the embedded, runtime and combined properties.
*/
static void celix_launcher_printProperties(const celix_properties_t* embeddedProps,
const celix_properties_t* runtimeProps,
const char* configFile);
/**
* @brief Create the bundle cache using the given embedded and runtime properties.
*
* Will create a framework instance to create the bundle cache and destroy the framework instance afterwards.
*/
static celix_status_t celix_launcher_createBundleCache(celix_properties_t* embeddedProps, const celix_properties_t* runtimeProps);
/**
* @brief Load the runtime properties from the given file.
*
* If no file is given, a check is done for the default file and if it exists, the default file is used.
*/
static celix_status_t celix_launcher_loadRuntimeProperties(const char* configFile, celix_properties_t** outConfigProperties);
/**
* @brief Set the global framework instance.
*/
static celix_status_t celix_launcher_setGlobalFramework(celix_framework_t* fw);
int celix_launcher_launchAndWait(int argc, char* argv[], const char* embeddedConfig) {
celix_autoptr(celix_properties_t) embeddedProps = NULL;
if (embeddedConfig) {
(void)celix_properties_loadFromString(embeddedConfig, 0, &embeddedProps);
} else {
embeddedProps = celix_properties_create();
}
if (embeddedProps == NULL) {
celix_err_printErrors(stderr, "Error creating embedded properties: ", NULL);
return CELIX_LAUNCHER_ERROR_EXIT_CODE;
}
celix_launcher_options_t options;
memset(&options, 0, sizeof(options));
celix_status_t status = celix_launcher_parseOptions(argc, argv, &options);
if (status != CELIX_SUCCESS) {
return CELIX_LAUNCHER_ERROR_EXIT_CODE;
}
celix_autoptr(celix_properties_t) runtimeProps = NULL;
status = celix_launcher_loadRuntimeProperties(options.configFile, &runtimeProps);
if (status != CELIX_SUCCESS) {
return CELIX_LAUNCHER_ERROR_EXIT_CODE;
}
if (options.showHelp) {
celix_launcher_printUsage(argv[0]);
return CELIX_LAUNCHER_OK_EXIT_CODE;
} else if (options.showProps) {
celix_launcher_printProperties(embeddedProps, runtimeProps, options.configFile);
return CELIX_LAUNCHER_OK_EXIT_CODE;
}
if (!celix_launcher_checkFrameworkLaunched()) {
return CELIX_LAUNCHER_ERROR_EXIT_CODE;
}
if (options.createCache) {
status = celix_launcher_createBundleCache(celix_steal_ptr(embeddedProps), runtimeProps);
celix_launcher_resetLauncher();
return status == CELIX_SUCCESS ? CELIX_LAUNCHER_OK_EXIT_CODE : CELIX_LAUNCHER_ERROR_EXIT_CODE;
}
celix_framework_t* framework = NULL;
status = celix_launcher_createFramework(celix_steal_ptr(embeddedProps), runtimeProps, &framework);
if (status != CELIX_SUCCESS) {
celix_launcher_resetLauncher();
return CELIX_LAUNCHER_ERROR_EXIT_CODE;
}
status = celix_launcher_setGlobalFramework(framework);
if (status != CELIX_SUCCESS) {
celix_bundleContext_log(celix_framework_getFrameworkContext(framework), CELIX_LOG_LEVEL_WARNING,
"Failed to schedule celix_shutdown_check");
}
celix_framework_waitForStop(framework);
celix_launcher_resetLauncher();
#ifndef CELIX_NO_CURLINIT
// Cleanup Curl
curl_global_cleanup();
#endif
return CELIX_LAUNCHER_OK_EXIT_CODE;
}