31
34
#include "drizzled/module/load_list.h"
32
35
#include "drizzled/module/library.h"
33
36
#include "drizzled/module/registry.h"
37
#include "drizzled/module/option_context.h"
34
38
#include "drizzled/sql_parse.h"
35
39
#include "drizzled/show.h"
36
40
#include "drizzled/cursor.h"
1654
1660
Requires that a write-lock is held on LOCK_system_variables_hash
1656
static int test_plugin_options(memory::Root *tmp_root, module::Module *tmp,
1662
static int test_plugin_options(memory::Root *module_root,
1663
module::Module *test_module,
1657
1664
int *argc, char **argv)
1659
1666
struct sys_var_chain chain= { NULL, NULL };
1664
1671
struct st_bookmark *var;
1665
1672
uint32_t len, count= EXTRA_OPTIONS;
1667
for (opt= tmp->getManifest().system_vars; opt && *opt; opt++)
1674
if (test_module->getManifest().init_options != NULL)
1676
cout << "Calling init_options: " << test_module->getName() << endl;
1677
po::options_description module_options("Options used by plugins");
1678
module::option_context opt_ctx(test_module->getName(),
1679
module_options.add_options());
1680
test_module->getManifest().init_options(opt_ctx);
1682
po::variables_map vm;
1684
po::parsed_options parsed= po::command_line_parser(*argc, argv).
1685
options(module_options).allow_unregistered().run();
1687
po::store(parsed, vm);
1689
vector<string> to_pass_further= po::collect_unrecognized(parsed.options,
1690
po::include_positional);
1693
/* Copy the left over options back into argv for further processing.
1694
Once the core is using program options, this whole thing will be done
1697
for (vector<string>::iterator iter= to_pass_further.begin();
1698
iter != to_pass_further.end();
1701
size_t pos= iter-to_pass_further.begin()+1;
1702
memcpy(argv[pos], (*iter).c_str(), (*iter).size()+1);
1703
cout << "arg: *" << argv[pos] << "*" << endl;
1705
*argc= to_pass_further.size() + 1;
1712
for (opt= test_module->getManifest().system_vars; opt && *opt; opt++)
1671
1717
if (count > EXTRA_OPTIONS || (*argc > 1))
1673
if (!(opts= (option*) tmp_root->alloc_root(sizeof(option) * count)))
1719
if (!(opts= (option*) module_root->alloc_root(sizeof(option) * count)))
1675
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory for plugin '%s'."), tmp->getName().c_str());
1721
errmsg_printf(ERRMSG_LVL_ERROR,
1722
_("Out of memory for plugin '%s'."),
1723
test_module->getName().c_str());
1678
1726
memset(opts, 0, sizeof(option) * count);
1680
if (construct_options(tmp_root, tmp, opts))
1728
if (construct_options(module_root, test_module, opts))
1682
errmsg_printf(ERRMSG_LVL_ERROR, _("Bad options for plugin '%s'."), tmp->getName().c_str());
1730
errmsg_printf(ERRMSG_LVL_ERROR,
1731
_("Bad options for plugin '%s'."),
1732
test_module->getName().c_str());
1691
errmsg_printf(ERRMSG_LVL_ERROR, _("Parsing options for plugin '%s' failed."),
1692
tmp->getName().c_str());
1741
errmsg_printf(ERRMSG_LVL_ERROR,
1742
_("Parsing options for plugin '%s' failed."),
1743
test_module->getName().c_str());
1700
for (opt= tmp->getManifest().system_vars; opt && *opt; opt++)
1752
for (opt= test_module->getManifest().system_vars; opt && *opt; opt++)
1703
1755
if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
1706
if ((var= find_bookmark(tmp->getName(), o->name, o->flags)))
1758
if ((var= find_bookmark(test_module->getName(), o->name, o->flags)))
1707
1760
v= new sys_var_pluginvar(var->key + 1, o);
1710
len= tmp->getName().length() + strlen(o->name) + 2;
1711
string vname(tmp->getName());
1764
len= test_module->getName().length() + strlen(o->name) + 2;
1765
string vname(test_module->getName());
1712
1766
vname.push_back('-');
1713
1767
vname.append(o->name);
1714
1768
transform(vname.begin(), vname.end(), vname.begin(), ::tolower);
1737
1791
chain.last->setNext(NULL);
1738
1792
if (mysql_add_sys_var_chain(chain.first, NULL))
1740
errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' has conflicting system variables"),
1741
tmp->getName().c_str());
1794
errmsg_printf(ERRMSG_LVL_ERROR,
1795
_("Plugin '%s' has conflicting system variables"),
1796
test_module->getName().c_str());
1744
tmp->system_vars= chain.first;
1799
test_module->system_vars= chain.first;