~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/scheduler.cc

Merged in changes. 
Edited a the comment test case so deal with our version bump.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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/plugin/registry.h"
23
 
 
24
 
#include "drizzled/gettext.h"
25
 
 
26
 
using namespace std;
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
vector<plugin::Scheduler *> all_schedulers;
32
 
 
33
 
/* Globals (TBK) */
34
 
static plugin::Scheduler *scheduler= NULL;
35
 
 
36
 
 
37
 
class FindSchedulerByName : public unary_function<plugin::Scheduler *, bool>
38
 
{
39
 
  const string *name;
40
 
public:
41
 
  FindSchedulerByName(const string *name_arg)
42
 
    : name(name_arg) {}
43
 
  result_type operator() (argument_type sched)
44
 
  {
45
 
    return (bool)((name->compare(sched->getName()) == 0));
46
 
  }
47
 
};
48
 
 
49
 
 
50
 
bool plugin::Scheduler::addPlugin(plugin::Scheduler *sched)
51
 
{
52
 
  vector<plugin::Scheduler *>::iterator iter=
53
 
    find_if(all_schedulers.begin(), all_schedulers.end(), 
54
 
            FindSchedulerByName(&sched->getName()));
55
 
 
56
 
  if (iter != all_schedulers.end())
57
 
  {
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());
62
 
    return true;
63
 
  }
64
 
 
65
 
  sched->deactivate();
66
 
  all_schedulers.push_back(sched);
67
 
 
68
 
  return false;
69
 
}
70
 
 
71
 
 
72
 
void plugin::Scheduler::removePlugin(plugin::Scheduler *sched)
73
 
{
74
 
  all_schedulers.erase(find(all_schedulers.begin(),
75
 
                            all_schedulers.end(),
76
 
                            sched));
77
 
}
78
 
 
79
 
 
80
 
bool plugin::Scheduler::setPlugin(const string& name)
81
 
{
82
 
  vector<plugin::Scheduler *>::iterator iter=
83
 
    find_if(all_schedulers.begin(), all_schedulers.end(), 
84
 
            FindSchedulerByName(&name));
85
 
 
86
 
  if (iter != all_schedulers.end())
87
 
  {
88
 
    if (scheduler != NULL)
89
 
      scheduler->deactivate();
90
 
    scheduler= *iter;
91
 
    scheduler->activate();
92
 
    return false;
93
 
  }
94
 
 
95
 
  errmsg_printf(ERRMSG_LVL_WARN,
96
 
                _("Attempted to configure %s as the scheduler, which did "
97
 
                  "not exist.\n"), name.c_str());
98
 
  return true;
99
 
}
100
 
 
101
 
 
102
 
plugin::Scheduler *plugin::Scheduler::getScheduler()
103
 
{
104
 
  return scheduler;
105
 
}
106
 
 
107
 
} /* namespace drizzled */