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 |
||
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
20 |
#include "drizzled/server_includes.h" |
21 |
#include "drizzled/plugin/scheduler.h" |
|
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
22 |
#include "drizzled/plugin/registry.h" |
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
23 |
|
24 |
#include "drizzled/gettext.h" |
|
25 |
||
994.2.2
by Monty Taylor
Store a Registry of SchedulerFactories and set one of them at startup for better error messages earlier. |
26 |
using namespace std; |
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
27 |
|
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
28 |
namespace drizzled |
29 |
{
|
|
1152.1.5
by Brian Aker
Remove Factory/make scheduler work like everything else. |
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 |
{
|
|
1130.2.15
by Monty Taylor
Merged up with trunk. |
45 |
return (bool)((name->compare(sched->getName()) == 0)); |
1152.1.5
by Brian Aker
Remove Factory/make scheduler work like everything else. |
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(), |
|
1130.2.15
by Monty Taylor
Merged up with trunk. |
54 |
FindSchedulerByName(&sched->getName())); |
1152.1.5
by Brian Aker
Remove Factory/make scheduler work like everything else. |
55 |
|
56 |
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. |
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"), |
|
1130.2.15
by Monty Taylor
Merged up with trunk. |
61 |
sched->getName().c_str()); |
1152.1.5
by Brian Aker
Remove Factory/make scheduler work like everything else. |
62 |
return true; |
63 |
}
|
|
64 |
||
65 |
all_schedulers.push_back(sched); |
|
66 |
||
67 |
return false; |
|
68 |
}
|
|
69 |
||
70 |
||
71 |
void plugin::Scheduler::removePlugin(plugin::Scheduler *sched) |
|
72 |
{
|
|
73 |
all_schedulers.erase(find(all_schedulers.begin(), |
|
74 |
all_schedulers.end(), |
|
75 |
sched)); |
|
76 |
}
|
|
77 |
||
78 |
||
79 |
bool plugin::Scheduler::setPlugin(const string& name) |
|
80 |
{
|
|
81 |
vector<plugin::Scheduler *>::iterator iter= |
|
82 |
find_if(all_schedulers.begin(), all_schedulers.end(), |
|
83 |
FindSchedulerByName(&name)); |
|
84 |
||
85 |
if (iter != all_schedulers.end()) |
|
86 |
{
|
|
87 |
scheduler= *iter; |
|
88 |
||
89 |
return false; |
|
90 |
}
|
|
91 |
||
92 |
errmsg_printf(ERRMSG_LVL_WARN, |
|
93 |
_("Attempted to configure %s as the scheduler, which did " |
|
94 |
"not exist.\n"), name.c_str()); |
|
95 |
return true; |
|
96 |
}
|
|
97 |
||
98 |
||
99 |
plugin::Scheduler *plugin::Scheduler::getScheduler() |
|
100 |
{
|
|
101 |
return scheduler; |
|
102 |
}
|
|
1130.3.10
by Monty Taylor
Cleaned up service namespacing. |
103 |
|
104 |
} /* namespace drizzled */ |