drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
scheduler.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <config.h>
21#include <drizzled/plugin/scheduler.h>
22#include <drizzled/errmsg_print.h>
23#include <drizzled/gettext.h>
24
25namespace drizzled {
26
27typedef std::vector<plugin::Scheduler*> schedulers_t;
28
29static schedulers_t g_schedulers;
30static plugin::Scheduler* g_scheduler= NULL;
31
32bool plugin::Scheduler::addPlugin(plugin::Scheduler &sched)
33{
34 for (schedulers_t::reference it : g_schedulers)
35 {
36 if (it->getName() != sched.getName())
37 continue;
38 errmsg_printf(error::ERROR, _("Attempted to register a scheduler %s, but a scheduler has already been registered with that name.\n"), sched.getName().c_str());
39 return true;
40 }
41 sched.deactivate();
42 g_schedulers.push_back(&sched);
43 return false;
44}
45
46void plugin::Scheduler::removePlugin(plugin::Scheduler &sched)
47{
48 g_schedulers.erase(std::find(g_schedulers.begin(), g_schedulers.end(), &sched));
49}
50
51bool plugin::Scheduler::setPlugin(const std::string& name)
52{
53 for (schedulers_t::reference it : g_schedulers)
54 {
55 if (it->getName() != name)
56 continue;
57 if (g_scheduler)
58 g_scheduler->deactivate();
59 g_scheduler= it;
60 g_scheduler->activate();
61 return false;
62 }
63 errmsg_printf(error::WARN, _("Attempted to configure %s as the scheduler, which did not exist.\n"), name.c_str());
64 return true;
65}
66
67plugin::Scheduler *plugin::Scheduler::getScheduler()
68{
69 return g_scheduler;
70}
71
72} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.