Drizzled Public API Documentation

scheduler.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 #include <drizzled/plugin/scheduler.h>
00022 #include <drizzled/errmsg_print.h>
00023 #include <drizzled/gettext.h>
00024 
00025 namespace drizzled {
00026 
00027 typedef std::vector<plugin::Scheduler*> schedulers_t;
00028 
00029 static schedulers_t g_schedulers;
00030 static plugin::Scheduler* g_scheduler= NULL;
00031 
00032 bool plugin::Scheduler::addPlugin(plugin::Scheduler *sched)
00033 {
00034   BOOST_FOREACH(schedulers_t::reference it, g_schedulers)
00035   {
00036     if (it->getName() != sched->getName())
00037       continue;
00038     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());
00039     return true;
00040   }
00041   sched->deactivate();
00042   g_schedulers.push_back(sched);
00043   return false;
00044 }
00045 
00046 void plugin::Scheduler::removePlugin(plugin::Scheduler *sched)
00047 {
00048   g_schedulers.erase(std::find(g_schedulers.begin(), g_schedulers.end(), sched));
00049 }
00050 
00051 bool plugin::Scheduler::setPlugin(const std::string& name)
00052 {
00053   BOOST_FOREACH(schedulers_t::reference it, g_schedulers)
00054   {
00055     if (it->getName() != name)
00056       continue;
00057     if (g_scheduler)
00058       g_scheduler->deactivate();
00059     g_scheduler= it;
00060     g_scheduler->activate();
00061     return false;
00062   }
00063   errmsg_printf(error::WARN, _("Attempted to configure %s as the scheduler, which did not exist.\n"), name.c_str());
00064   return true;
00065 }
00066 
00067 plugin::Scheduler *plugin::Scheduler::getScheduler()
00068 {
00069   return g_scheduler;
00070 }
00071 
00072 } /* namespace drizzled */