~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/scheduler.cc

Merge Stewart's dead code removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
22
 
#include <algorithm>
23
 
 
 
20
#include "drizzled/server_includes.h"
24
21
#include "drizzled/plugin/scheduler.h"
 
22
#include "drizzled/plugin/registry.h"
25
23
 
26
24
#include "drizzled/gettext.h"
27
 
#include "drizzled/errmsg_print.h"
 
25
 
 
26
using namespace std;
28
27
 
29
28
namespace drizzled
30
29
{
31
30
 
32
 
extern size_t my_thread_stack_size;
33
 
 
34
 
std::vector<plugin::Scheduler *> all_schedulers;
 
31
vector<plugin::Scheduler *> all_schedulers;
35
32
 
36
33
/* Globals (TBK) */
37
34
static plugin::Scheduler *scheduler= NULL;
38
35
 
39
36
 
40
 
class FindSchedulerByName : public std::unary_function<plugin::Scheduler *, bool>
 
37
class FindSchedulerByName : public unary_function<plugin::Scheduler *, bool>
41
38
{
42
 
  const std::string *name;
 
39
  const string *name;
43
40
public:
44
 
  FindSchedulerByName(const std::string *name_arg)
 
41
  FindSchedulerByName(const string *name_arg)
45
42
    : name(name_arg) {}
46
43
  result_type operator() (argument_type sched)
47
44
  {
52
49
 
53
50
bool plugin::Scheduler::addPlugin(plugin::Scheduler *sched)
54
51
{
55
 
  std::vector<plugin::Scheduler *>::iterator iter=
56
 
    std::find_if(all_schedulers.begin(), all_schedulers.end(), 
 
52
  vector<plugin::Scheduler *>::iterator iter=
 
53
    find_if(all_schedulers.begin(), all_schedulers.end(), 
57
54
            FindSchedulerByName(&sched->getName()));
58
55
 
59
56
  if (iter != all_schedulers.end())
60
57
  {
61
 
    errmsg_printf(error::ERROR,
 
58
    errmsg_printf(ERRMSG_LVL_ERROR,
62
59
                  _("Attempted to register a scheduler %s, but a scheduler "
63
60
                    "has already been registered with that name.\n"),
64
61
                    sched->getName().c_str());
65
62
    return true;
66
63
  }
67
64
 
68
 
  sched->deactivate();
69
65
  all_schedulers.push_back(sched);
70
66
 
71
67
  return false;
74
70
 
75
71
void plugin::Scheduler::removePlugin(plugin::Scheduler *sched)
76
72
{
77
 
  all_schedulers.erase(std::find(all_schedulers.begin(),
 
73
  all_schedulers.erase(find(all_schedulers.begin(),
78
74
                            all_schedulers.end(),
79
75
                            sched));
80
76
}
81
77
 
82
78
 
83
 
bool plugin::Scheduler::setPlugin(const std::string& name)
 
79
bool plugin::Scheduler::setPlugin(const string& name)
84
80
{
85
 
  std::vector<plugin::Scheduler *>::iterator iter=
86
 
    std::find_if(all_schedulers.begin(), all_schedulers.end(), 
 
81
  vector<plugin::Scheduler *>::iterator iter=
 
82
    find_if(all_schedulers.begin(), all_schedulers.end(), 
87
83
            FindSchedulerByName(&name));
88
84
 
89
85
  if (iter != all_schedulers.end())
90
86
  {
91
 
    if (scheduler != NULL)
92
 
      scheduler->deactivate();
93
87
    scheduler= *iter;
94
 
    scheduler->activate();
 
88
 
95
89
    return false;
96
90
  }
97
91
 
98
 
  errmsg_printf(error::WARN,
 
92
  errmsg_printf(ERRMSG_LVL_WARN,
99
93
                _("Attempted to configure %s as the scheduler, which did "
100
94
                  "not exist.\n"), name.c_str());
101
95
  return true;