summaryrefslogtreecommitdiff
path: root/lib/module_loader.cpp
diff options
context:
space:
mode:
authorJosh Blum2013-07-27 01:17:46 -0700
committerJosh Blum2013-07-27 01:17:46 -0700
commit7a677f768094fecfbb04e7b803c99cc2787153a2 (patch)
tree347e4bd306307bd0f9c979518f840bab00da5488 /lib/module_loader.cpp
parentb877d078b11cb848b344f4f7534398f70157aa15 (diff)
downloadsandhi-7a677f768094fecfbb04e7b803c99cc2787153a2.tar.gz
sandhi-7a677f768094fecfbb04e7b803c99cc2787153a2.tar.bz2
sandhi-7a677f768094fecfbb04e7b803c99cc2787153a2.zip
gras: work on module loading and python factory
naming convention, path convention, env var convention, And, make a python factory -- but its a little halfassed. You see, we didnt do the swig director thing yet, so C++ cant yet create python blocks from the factory.
Diffstat (limited to 'lib/module_loader.cpp')
-rw-r--r--lib/module_loader.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/module_loader.cpp b/lib/module_loader.cpp
index 00c34ab..d64722d 100644
--- a/lib/module_loader.cpp
+++ b/lib/module_loader.cpp
@@ -45,19 +45,30 @@ static void load_all_modules_in_path(const fs::path &path)
) load_all_modules_in_path(dir_itr->path());
}
-GRAS_STATIC_BLOCK(gras_module_loader)
+static void load_modules_from_paths(const std::string &paths, const fs::path &suffix)
{
- std::string search_paths = "@GRAS_MODULE_PATH@";
- const char *module_path_env = std::getenv("GRAS_MODULE_PATH");
- if (module_path_env != NULL)
- {
- search_paths += SEP;
- search_paths += module_path_env;
- }
- if (search_paths.empty()) return;
- BOOST_FOREACH(const std::string &path, boost::tokenizer<boost::char_separator<char> > (search_paths, boost::char_separator<char>(SEP)))
+ if (paths.empty()) return;
+ BOOST_FOREACH(const std::string &path, boost::tokenizer<boost::char_separator<char> > (paths, boost::char_separator<char>(SEP)))
{
if (path.empty()) continue;
- load_all_modules_in_path(fs::path(path));
+ load_all_modules_in_path(fs::path(path) / suffix);
}
}
+
+static std::string my_get_env(const std::string &name, const std::string &defalt)
+{
+ const char *env_var = std::getenv(name.c_str());
+ return (env_var != NULL)? env_var : defalt;
+}
+
+GRAS_STATIC_BLOCK(gras_module_loader)
+{
+ //!search the GRAS_ROOT directory for this install
+ load_modules_from_paths(my_get_env("GRAS_ROOT", "@GRAS_ROOT@"), fs::path("") / "lib@LIB_SUFFIX@" / "gras" / "modules");
+
+ //!search the GRAS_PATH search directories for modules
+ load_modules_from_paths(my_get_env("GRAS_PATH", ""), fs::path("") / "lib@LIB_SUFFIX@" / "gras" / "modules");
+
+ //!search the explicit module paths
+ load_modules_from_paths(my_get_env("GRAS_MODULE_PATH", ""), fs::path(""));
+}