~drizzle-trunk/drizzle/development

520.3.2 by mark
add parser and scheduling plugin files
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1010 by Brian Aker
Replacing Sun employee copyright headers (aka... anything done by a Sun
4
 *  Copyright (C) 2008 Sun Microsystems
520.3.2 by mark
add parser and scheduling plugin files
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
20
#include "config.h"
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
21
22
#include <algorithm>
23
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
24
#include "drizzled/plugin/scheduler.h"
25
26
#include "drizzled/gettext.h"
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
27
#include "drizzled/errmsg_print.h"
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
28
994.2.2 by Monty Taylor
Store a Registry of SchedulerFactories and set one of them at startup for better error messages earlier.
29
using namespace std;
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
30
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
31
namespace drizzled
32
{
1152.1.5 by Brian Aker
Remove Factory/make scheduler work like everything else.
33
1685.5.1 by David Shrewsbury
Fix for bug 532481: fixes OS X crash by support thread_stack option
34
extern size_t my_thread_stack_size;
35
1152.1.5 by Brian Aker
Remove Factory/make scheduler work like everything else.
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
  {
1130.2.15 by Monty Taylor
Merged up with trunk.
50
    return (bool)((name->compare(sched->getName()) == 0));
1152.1.5 by Brian Aker
Remove Factory/make scheduler work like everything else.
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(), 
1130.2.15 by Monty Taylor
Merged up with trunk.
59
            FindSchedulerByName(&sched->getName()));
1152.1.5 by Brian Aker
Remove Factory/make scheduler work like everything else.
60
61
  if (iter != all_schedulers.end())
994.2.2 by Monty Taylor
Store a Registry of SchedulerFactories and set one of them at startup for better error messages earlier.
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"),
1130.2.15 by Monty Taylor
Merged up with trunk.
66
                    sched->getName().c_str());
1152.1.5 by Brian Aker
Remove Factory/make scheduler work like everything else.
67
    return true;
68
  }
69
1192.2.2 by Monty Taylor
Added type name strings to all of the plugin types.
70
  sched->deactivate();
1152.1.5 by Brian Aker
Remove Factory/make scheduler work like everything else.
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
  {
1192.2.2 by Monty Taylor
Added type name strings to all of the plugin types.
93
    if (scheduler != NULL)
94
      scheduler->deactivate();
1152.1.5 by Brian Aker
Remove Factory/make scheduler work like everything else.
95
    scheduler= *iter;
1192.2.2 by Monty Taylor
Added type name strings to all of the plugin types.
96
    scheduler->activate();
1152.1.5 by Brian Aker
Remove Factory/make scheduler work like everything else.
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
}
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
111
112
} /* namespace drizzled */