nitf_PluginRegistry_internalLoadDir(nitf_PluginRegistry * reg, const char *dirName, nitf_Error * error) { const char *name; size_t sizePath; nitf_Directory *dir = NULL; if (!dirName) { nitf_Error_initf(error, NITF_CTXT, NITF_ERR_OPENING_FILE, "Null directory name"); return NITF_FAILURE; } dir = nitf_Directory_construct(error); if (!dir) { return NITF_FAILURE; } sizePath = strlen(dirName); if (nitf_Directory_exists(dirName)) { name = nitf_Directory_findFirstFile(dir, dirName); if (name) { do { char *end; char fullName[NITF_MAX_PATH]; int pathSize = sizePath; memset(fullName, 0, NITF_MAX_PATH); memcpy(fullName, dirName, sizePath); if (!isDelimiter(dirName[pathSize - 1])) fullName[pathSize++] = DIR_DELIMITER; memcpy(fullName + pathSize, name, strlen(name)); /* See if we have .so or .dll extensions */ if ((end = (char *) strstr(name, NITF_DLL_EXTENSION)) != NULL) { if (!nitf_PluginRegistry_loadPlugin(fullName, error)) { #ifdef NITF_DEBUG_PLUGIN_REG printf("Warning: plugin [%s] failed to load!\n", name); #endif } } else { #ifdef NITF_DEBUG_PLUGIN_REG printf("Skipping directory [%s]\n", name); #endif } name = nitf_Directory_findNextFile(dir); } while (name); } else { printf("Error: %s\n", NITF_STRERROR(NITF_ERRNO)); } } else { #ifdef NITF_DEBUG_PLUGIN_REG fprintf(stdout, "Could not open plug-in directory '%s'. " "You may have forgotten to set your NITF_PLUGIN_PATH environment " "variable : continuing without plugins...\n", dirName); #endif } nitf_Directory_destruct(&dir); return NITF_SUCCESS; }
void nitf::PluginRegistry::loadPlugin(std::string path) throw(nitf::NITFException) { nitf_Error error; if (!nitf_PluginRegistry_loadPlugin(path.c_str(), &error)) throw nitf::NITFException(&error); }