~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/scheduler.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 09:12:23 UTC
  • mto: (511.1.6 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016091223-17ngih0qu9vssjs3
We pass -Wunused-macros now!

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