17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
21
#include <drizzled/scheduling.h>
22
#include <drizzled/gettext.h>
23
#include "drizzled/plugin/registry.h"
24
#include "drizzled/registry.h"
27
using namespace drizzled;
29
plugin::SchedulerFactory *scheduler_factory= NULL;
30
Registry<plugin::SchedulerFactory *> all_schedulers;
32
bool add_scheduler_factory(plugin::SchedulerFactory *factory)
34
if (all_schedulers.count(factory->getName()) != 0)
36
errmsg_printf(ERRMSG_LVL_ERROR,
24
#include "drizzled/plugin/scheduler.h"
26
#include "drizzled/gettext.h"
27
#include "drizzled/errmsg_print.h"
32
extern size_t my_thread_stack_size;
34
std::vector<plugin::Scheduler *> all_schedulers;
37
static plugin::Scheduler *scheduler= NULL;
40
class FindSchedulerByName : public std::unary_function<plugin::Scheduler *, bool>
42
const std::string *name;
44
FindSchedulerByName(const std::string *name_arg)
46
result_type operator() (argument_type sched)
48
return (bool)((name->compare(sched->getName()) == 0));
53
bool plugin::Scheduler::addPlugin(plugin::Scheduler *sched)
55
std::vector<plugin::Scheduler *>::iterator iter=
56
std::find_if(all_schedulers.begin(), all_schedulers.end(),
57
FindSchedulerByName(&sched->getName()));
59
if (iter != all_schedulers.end())
61
errmsg_printf(error::ERROR,
37
62
_("Attempted to register a scheduler %s, but a scheduler "
38
63
"has already been registered with that name.\n"),
39
factory->getName().c_str());
42
all_schedulers.add(factory);
47
bool remove_scheduler_factory(plugin::SchedulerFactory *factory)
49
scheduler_factory= NULL;
50
all_schedulers.remove(factory);
55
bool set_scheduler_factory(const string& name)
58
plugin::SchedulerFactory *factory= all_schedulers.find(name);
61
errmsg_printf(ERRMSG_LVL_WARN,
62
_("Attempted to configure %s as the scheduler, which did "
63
"not exist.\n"), name.c_str());
66
scheduler_factory= factory;
71
plugin::Scheduler *get_thread_scheduler()
73
assert(scheduler_factory != NULL);
74
plugin::Scheduler *sched= (*scheduler_factory)();
77
errmsg_printf(ERRMSG_LVL_ERROR, _("Scheduler initialization failed.\n"));
64
sched->getName().c_str());
69
all_schedulers.push_back(sched);
75
void plugin::Scheduler::removePlugin(plugin::Scheduler *sched)
77
all_schedulers.erase(std::find(all_schedulers.begin(),
83
bool plugin::Scheduler::setPlugin(const std::string& name)
85
std::vector<plugin::Scheduler *>::iterator iter=
86
std::find_if(all_schedulers.begin(), all_schedulers.end(),
87
FindSchedulerByName(&name));
89
if (iter != all_schedulers.end())
91
if (scheduler != NULL)
92
scheduler->deactivate();
94
scheduler->activate();
98
errmsg_printf(error::WARN,
99
_("Attempted to configure %s as the scheduler, which did "
100
"not exist.\n"), name.c_str());
105
plugin::Scheduler *plugin::Scheduler::getScheduler()
110
} /* namespace drizzled */