~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduling.cc

  • Committer: Brian Aker
  • Date: 2009-04-17 19:23:54 UTC
  • mfrom: (994.2.2 mordred)
  • Revision ID: brian@gaz-20090417192354-gyr9nvpuj6vrc2tv
Mergig Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <drizzled/gettext.h>
23
23
#include <drizzled/connect.h>
24
24
#include "drizzled/plugin_registry.h"
 
25
#include "drizzled/registry.h"
25
26
 
 
27
using namespace std;
26
28
 
27
29
SchedulerFactory *scheduler_factory= NULL;
28
 
 
29
 
static bool scheduler_inited= false; /* We must insist that only one of these plugins get loaded at a time */
30
 
 
31
 
 
32
 
extern char *opt_scheduler;
 
30
drizzled::Registry<SchedulerFactory *> all_schedulers;
33
31
 
34
32
bool add_scheduler_factory(SchedulerFactory *factory)
35
33
{
36
 
  if (factory->getName() != opt_scheduler)
37
 
    return true;
38
 
 
39
 
  if (scheduler_inited)
40
 
  {
41
 
    fprintf(stderr, "You cannot load more then one scheduler plugin\n");
42
 
    return(1);
 
34
  if (all_schedulers.count(factory->getName()) != 0)
 
35
  {
 
36
    errmsg_printf(ERRMSG_LVL_ERROR,
 
37
                  _("Attempted to register a scheduler %s, but a scheduler "
 
38
                    "has already been registered with that name.\n"),
 
39
                    factory->getName().c_str());
 
40
    return true;
 
41
  }
 
42
  all_schedulers.add(factory);
 
43
  return false;
 
44
}
 
45
 
 
46
 
 
47
bool remove_scheduler_factory(SchedulerFactory *factory)
 
48
{
 
49
  scheduler_factory= NULL;
 
50
  all_schedulers.remove(factory);
 
51
  return false;
 
52
}
 
53
 
 
54
 
 
55
bool set_scheduler_factory(const string& name)
 
56
{
 
57
   
 
58
  SchedulerFactory *factory= all_schedulers.find(name);
 
59
  if (factory == NULL)
 
60
  {
 
61
    errmsg_printf(ERRMSG_LVL_WARN,
 
62
                  _("Attempted to configure %s as the scheduler, which did "
 
63
                    "not exist.\n"), name.c_str());
 
64
    return true;
43
65
  }
44
66
  scheduler_factory= factory;
45
67
 
46
 
  scheduler_inited= true;
47
 
  return false;
48
 
}
49
 
 
50
 
bool remove_scheduler_factory(SchedulerFactory *)
51
 
{
52
 
  scheduler_factory= NULL;
53
 
  scheduler_inited= false;
54
68
  return false;
55
69
}
56
70
 
60
74
  Scheduler *sched= (*scheduler_factory)();
61
75
  if (sched == NULL)
62
76
  {
63
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Scheduler initialization failed."));
 
77
    errmsg_printf(ERRMSG_LVL_ERROR, _("Scheduler initialization failed.\n"));
64
78
    exit(1);
65
79
  }
66
80
  return *sched;