~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/scheduler.cc

Added autoconf tests for location of cstdint and cinttypes. Use those in C++ programs now, so that we don't have to define _STDC_LIMIT_MACROS, etc by hand. Stop, in fact, defining those by hand.

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