17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/plugin/scheduler.h"
22
#include "drizzled/plugin/registry.h"
24
#include "drizzled/gettext.h"
31
vector<plugin::Scheduler *> all_schedulers;
34
static plugin::Scheduler *scheduler= NULL;
37
class FindSchedulerByName : public unary_function<plugin::Scheduler *, bool>
41
FindSchedulerByName(const string *name_arg)
43
result_type operator() (argument_type sched)
45
return (bool)((name->compare(sched->getName()) == 0));
50
bool plugin::Scheduler::addPlugin(plugin::Scheduler *sched)
52
vector<plugin::Scheduler *>::iterator iter=
53
find_if(all_schedulers.begin(), all_schedulers.end(),
54
FindSchedulerByName(&sched->getName()));
56
if (iter != all_schedulers.end())
58
errmsg_printf(ERRMSG_LVL_ERROR,
59
_("Attempted to register a scheduler %s, but a scheduler "
60
"has already been registered with that name.\n"),
61
sched->getName().c_str());
66
all_schedulers.push_back(sched);
72
void plugin::Scheduler::removePlugin(plugin::Scheduler *sched)
74
all_schedulers.erase(find(all_schedulers.begin(),
80
bool plugin::Scheduler::setPlugin(const string& name)
82
vector<plugin::Scheduler *>::iterator iter=
83
find_if(all_schedulers.begin(), all_schedulers.end(),
84
FindSchedulerByName(&name));
86
if (iter != all_schedulers.end())
88
if (scheduler != NULL)
89
scheduler->deactivate();
91
scheduler->activate();
95
errmsg_printf(ERRMSG_LVL_WARN,
96
_("Attempted to configure %s as the scheduler, which did "
97
"not exist.\n"), name.c_str());
102
plugin::Scheduler *plugin::Scheduler::getScheduler()
107
} /* namespace drizzled */
20
#include <drizzled/server_includes.h>
21
#include <drizzled/scheduling.h>
22
#include <drizzled/gettext.h>
23
#include <drizzled/connect.h>
25
Scheduler *thread_scheduler= NULL;
27
static bool scheduler_inited= false; /* We must insist that only one of these plugins get loaded at a time */
30
extern char *opt_scheduler;
32
Scheduler &get_thread_scheduler()
34
assert(thread_scheduler != NULL);
35
return *thread_scheduler;
38
int scheduling_initializer(st_plugin_int *plugin)
40
if (memcmp(plugin->plugin->name, opt_scheduler, strlen(opt_scheduler)))
45
fprintf(stderr, "You cannot load more then one scheduler plugin\n");
49
assert(plugin->plugin->init); /* Find poorly designed plugins */
51
if (plugin->plugin->init((void *)&thread_scheduler))
54
TRANSLATORS> The leading word "scheduling" is the name
55
of the plugin api, and so should not be translated.
57
errmsg_printf(ERRMSG_LVL_ERROR, _("scheduling plugin '%s' init() failed"),
62
scheduler_inited= true;
63
/* We populate so we can find which plugin was initialized later on */
64
plugin->data= (void *)thread_scheduler;
70
int scheduling_finalizer(st_plugin_int *plugin)
72
/* We know which one we initialized since its data pointer is filled */
73
if (plugin->plugin->deinit && plugin->data)
75
if (plugin->plugin->deinit((void *)thread_scheduler))
77
/* TRANSLATORS: The leading word "scheduling" is the name
78
of the plugin api, and so should not be translated. */
79
errmsg_printf(ERRMSG_LVL_ERROR,
80
_("scheduling plugin '%s' deinit() failed"),