29 #include <boost/format.hpp>
31 #include <boost/tokenizer.hpp>
33 #include "../runtime/ContainerIO.h"
35 #include "../logging/LoggerFactory.h"
39 using namespace boost;
40 using namespace boost::filesystem;
45 Configurator::Configurator(
ManagerPtr manager,
const vector<path>& defaultPath)
46 : logger(logging::LoggerFactory::getInstance()
50 defaultPath(defaultPath) {
57 RSCINFO(this->
logger,
"No searchpath configured; using default: "
63 for (set<string>::const_iterator it = this->
load.begin();
64 it != this->
load.end(); ++it) {
71 set<PluginPtr> matches;
73 matches = this->
manager->getPlugins(boost::regex(pattern));
74 }
catch (
const std::exception& e) {
75 throw runtime_error(str(format(
"Failed to lookup matching plugins for patterns `%1%' as requested via configuration: %2%")
79 RSCDEBUG(this->
logger,
"Found " << matches.size() <<
" match(es)");
82 for (set<PluginPtr>::iterator it = matches.begin();
83 it != matches.end(); ++it) {
87 }
catch (
const std::exception& e) {
88 throw runtime_error(str(format(
"Failed to load plugin `%1%' as requested via configuration: %2%")
97 const string& value) {
98 RSCDEBUG(this->
logger,
"Processing option " << key <<
" = `" << value <<
"'");
101 if (!((key.size() == 3)
102 && (key[0] ==
"plugins")
103 && (key[1] ==
"cpp"))) {
108 if (key[2] ==
"path") {
111 vector<string> paths;
115 }
catch (
const std::exception& e) {
116 throw invalid_argument(str(format(
"Invalid plugin load path (option %1%) value `%2%': %3%")
117 % boost::io::group(std::container_none,
118 std::element_sequence(
".",
""),
126 for (vector<string>::const_iterator it = paths.begin();
127 it != paths.end(); ++it) {
131 path =
"<default path>";
136 }
catch (
const std::exception& e) {
137 throw runtime_error(str(format(
"Failed to add path `%1%' as requested via configuration: %2%")
144 }
else if (key[2] ==
"load") {
145 vector<string> names;
149 }
catch (
const std::exception& e) {
150 throw invalid_argument(str(format(
"Invalid list of plugins (option %1%) to load `%2%': %3%")
151 % boost::io::group(std::container_none,
152 std::element_sequence(
".",
""),
158 copy(names.begin(), names.end(),
159 inserter(this->
load, this->
load.begin()));
161 throw invalid_argument(str(format(
"Invalid option key `%1%'; plugin related option keys are `path' and `load'.")
162 % boost::io::group(std::container_none,
163 std::element_sequence(
".",
""),
169 for (vector<path>::const_iterator it = this->
defaultPath.begin();
176 vector<string> result;
177 boost::escaped_list_separator<char> sep(
'\\',
':');
178 boost::tokenizer< boost::escaped_list_separator<char> > tok(value, sep);
179 copy(tok.begin(), tok.end(), back_inserter(result));
std::vector< boost::filesystem::path > defaultPath
#define RSCDEBUG(logger, msg)
void handleOption(const std::vector< std::string > &key, const std::string &value)
This method is called once for each individual option available from a given ConfigSource.
std::set< std::string > load
#define RSCINFO(logger, msg)
std::vector< std::string > splitValue(const std::string &value) const
logging::LoggerPtr logger
boost::shared_ptr< Manager > ManagerPtr