#include "src/include/pmix_config.h"
#include "pmix_common.h"
#include <string.h>
#include "src/mca/base/pmix_base.h"
#include "src/mca/mca.h"
#include "src/util/pmix_show_help.h"
#include "src/mca/plog/base/base.h"
int pmix_plog_base_select(void)
{
pmix_mca_base_component_list_item_t *cli = NULL;
pmix_mca_base_component_t *component = NULL;
pmix_mca_base_module_t *module = NULL;
pmix_plog_module_t *nmodule;
pmix_plog_base_active_module_t *newmodule, *mod, *default_mod = NULL;
int rc, priority, n;
bool inserted, default_added, reqd;
pmix_list_t actives;
char *ptr;
size_t len;
if (pmix_plog_globals.selected) {
return PMIX_SUCCESS;
}
pmix_plog_globals.selected = true;
PMIX_CONSTRUCT(&actives, pmix_list_t);
PMIX_LIST_FOREACH (cli, &pmix_plog_base_framework.framework_components,
pmix_mca_base_component_list_item_t) {
component = (pmix_mca_base_component_t *) cli->cli_component;
pmix_output_verbose(5, pmix_plog_base_framework.framework_output,
"mca:plog:select: checking available component %s",
component->pmix_mca_component_name);
if (NULL == component->pmix_mca_query_component) {
pmix_output_verbose(
5, pmix_plog_base_framework.framework_output,
"mca:plog:select: Skipping component [%s]. It does not implement a query function",
component->pmix_mca_component_name);
continue;
}
pmix_output_verbose(5, pmix_plog_base_framework.framework_output,
"mca:plog:select: Querying component [%s]",
component->pmix_mca_component_name);
rc = component->pmix_mca_query_component(&module, &priority);
if (PMIX_SUCCESS != rc || NULL == module) {
pmix_output_verbose(
5, pmix_plog_base_framework.framework_output,
"mca:plog:select: Skipping component [%s]. Query failed to return a module",
component->pmix_mca_component_name);
continue;
}
nmodule = (pmix_plog_module_t *) module;
if (NULL != nmodule->init && PMIX_SUCCESS != nmodule->init()) {
continue;
}
newmodule = PMIX_NEW(pmix_plog_base_active_module_t);
newmodule->pri = priority;
newmodule->module = nmodule;
newmodule->component = (pmix_plog_base_component_t *) cli->cli_component;
inserted = false;
PMIX_LIST_FOREACH (mod, &actives, pmix_plog_base_active_module_t) {
if (priority > mod->pri) {
pmix_list_insert_pos(&actives, (pmix_list_item_t *) mod, &newmodule->super);
inserted = true;
break;
}
}
if (!inserted) {
pmix_list_append(&actives, &newmodule->super);
}
if (0 == strcmp(newmodule->module->name, "default")) {
default_mod = newmodule;
}
}
if (NULL != pmix_plog_globals.channels) {
default_added = false;
for (n = 0; NULL != pmix_plog_globals.channels[n]; n++) {
len = strlen(pmix_plog_globals.channels[n]);
reqd = false;
ptr = strrchr(pmix_plog_globals.channels[n], ':');
if (NULL != ptr) {
len = len - strlen(ptr);
++ptr;
if (0 == strncasecmp(ptr, "req", 3)) {
reqd = true;
}
}
inserted = false;
PMIX_LIST_FOREACH (mod, &actives, pmix_plog_base_active_module_t) {
if (0 == strncasecmp(pmix_plog_globals.channels[n], mod->module->name, len)) {
pmix_list_remove_item(&actives, &mod->super);
pmix_pointer_array_add(&pmix_plog_globals.actives, mod);
mod->reqd = reqd;
inserted = true;
break;
}
}
if (!inserted) {
if (!default_added) {
if (NULL == default_mod && reqd) {
pmix_show_help("help-pmix-plog.txt", "reqd-not-found", true,
pmix_plog_globals.channels[n]);
PMIX_LIST_DESTRUCT(&actives);
return PMIX_ERR_NOT_FOUND;
} else if (NULL != default_mod) {
pmix_pointer_array_add(&pmix_plog_globals.actives, default_mod);
default_added = true;
default_mod->reqd = reqd;
}
} else if (reqd) {
default_mod->reqd = reqd;
}
}
}
PMIX_LIST_DESTRUCT(&actives);
} else {
while (NULL
!= (mod = (pmix_plog_base_active_module_t *) pmix_list_remove_first(&actives))) {
pmix_pointer_array_add(&pmix_plog_globals.actives, mod);
}
PMIX_DESTRUCT(&actives);
}
if (4 < pmix_output_get_verbosity(pmix_plog_base_framework.framework_output)) {
pmix_output(0, "Final plog order");
for (n = 0; n < pmix_plog_globals.actives.size; n++) {
if (NULL
!= (mod = (pmix_plog_base_active_module_t *)
pmix_pointer_array_get_item(&pmix_plog_globals.actives, n))) {
pmix_output(0, "\tplog[%d]: %s", n, mod->component->pmix_mca_component_name);
}
}
}
return PMIX_SUCCESS;
;
}